package com.crunii.micro.service.sysmgr.controller;

import com.crunii.micro.common.dto.PageReq;
import com.crunii.micro.common.dto.PageRsp;
import com.crunii.micro.common.dto.Result;
import com.crunii.micro.domain.dto.Worker;
import com.crunii.micro.service.sysmgr.api.domain.dto.YcqMessageTemplateDTO;
import com.crunii.micro.service.sysmgr.api.domain.dto.YcqPageMessageTemplateDTO;
import com.crunii.micro.service.sysmgr.api.domain.vo.YcqMessageTemplateVO;
import com.crunii.micro.service.sysmgr.api.domain.vo.YcqTemplateCodeVO;
import com.crunii.micro.service.sysmgr.service.YcqMessageTemplateService;
import com.crunii.micro.web.mvc.CurrWorker;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.List;

/**
 * 消息模板
 * @author 15294
 */
@Api(value = "消息模板")
@Slf4j
@RestController
@RequestMapping("/auth/YcqMessageTemplateController")
public class YcqMessageTemplateController {

    @Resource
    private YcqMessageTemplateService service;

    /**
     * 新增
     * @param req
     * @return
     */
    @PostMapping("/insert")
    public Result<YcqMessageTemplateVO> insert(@RequestBody YcqMessageTemplateDTO req, @CurrWorker @ApiIgnore Worker worker){
        return Result.ofSuccess(service.insert(req, worker));
    }

    @PostMapping("/pageTemplateCode")
    public Result<List<YcqTemplateCodeVO>> pageTemplateCode(){
        // 分页查询数据
        return Result.ofSuccess(service.pageTemplateCode());
    }
    /**
     * 修改
     * @param req
     * @return
     */
    @PostMapping("/update")
    public Result<YcqMessageTemplateVO> update(@RequestBody YcqMessageTemplateDTO req, @CurrWorker @ApiIgnore Worker worker){
        return Result.ofSuccess(service.update(req, worker.getLoginId()));
    }

    /**
     * 修改状态
     * @param req
     * @return
     */
    @PostMapping("/updateStatus")
    public Result<YcqMessageTemplateVO> updateStatus(@RequestBody YcqMessageTemplateDTO req, @CurrWorker @ApiIgnore Worker worker){
        return Result.ofSuccess(service.updateStatus(req, worker.getLoginId()));
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @PostMapping("/deleteBatch")
    public Result<Boolean> deleteBatch(@RequestBody List<Long> ids, @CurrWorker @ApiIgnore Worker worker){
        return Result.ofSuccess(service.deleteBatch(ids, worker.getLoginId()));
    }

    /**
     * 分页查询
     * @param req
     * @return
     */
    @PostMapping("/pageByCondition")
    public Result<PageRsp<YcqMessageTemplateVO>> pageByCondition(@RequestBody PageReq<YcqPageMessageTemplateDTO> req, @CurrWorker @ApiIgnore Worker worker){
        // 分页查询数据
        return Result.ofSuccess(service.pageByCondition(req, worker.getLoginId()));
    }

}
