PlanTaskController.java 5.5 KB
Newer Older
苗卫卫 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
package com.boco.nbd.wios.flow.controller;

import com.boco.nbd.cams.core.util.LambdaUtils;
import com.boco.nbd.framework.common.PageData;
import com.boco.nbd.framework.common.ResponseMessage2;
import com.boco.nbd.framework.common.util.IdUtil;
import com.boco.nbd.framework.parent.microservice.exception.ErrorInfoException;
import com.boco.nbd.wios.flow.entity.po.PlanTaskPO;
import com.boco.nbd.wios.flow.service.IPlanTaskService;
import com.boco.nbd.wios.flow.util.ProcessUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.ihidea.core.support.session.SessionInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import tk.mybatis.mapper.entity.Example;

import java.util.List;


/**
 * @Description: TODO
 * @Author: ZQY
 * @Date: 2022/8/11
 **/
@RestController
@Slf4j
@RequestMapping("planTask")
@Api(tags = "计划任务配置")
public class PlanTaskController {


    @Autowired
    private IPlanTaskService planTaskService;


    /**
     * 新增计划任务
     *
     * @param po
     * @return
     */
    @ApiOperation(value = "新增计划任务")
    @PostMapping(value = "/addPlanTask")
    public ResponseMessage2 savePlanTask(PlanTaskPO po) {
        try {
            Example example = new Example(PlanTaskPO.class);
            Example.Criteria criteria = example.createCriteria();
            criteria.andEqualTo(LambdaUtils.getFieldName(PlanTaskPO::getYear), po.getYear());
            criteria.andEqualTo(LambdaUtils.getFieldName(PlanTaskPO::getOemName), po.getOemName());
            List<PlanTaskPO> planTaskPOList = planTaskService.selectByExample(example);
            if (planTaskPOList.size() > 0) {
                throw new ErrorInfoException("存在(" + po.getYear() + "+" + po.getOemName() + ")重复数据!");
            }
            po.setId(IdUtil.getLongUUID() + "");
            SessionInfo user = ProcessUtil.getUserInfo();
            po.setCreateUser(user == null ? "" : user.getUserId());
            planTaskService.insertSelective(po);
            return ResponseMessage2.Success();
        } catch (Exception e) {
            e.printStackTrace();
            log.error("新增计划任务", e.getMessage());
            return ResponseMessage2.Failed(e.getMessage());


        }

    }


    /**
     * 修改计划任务
     *
     * @param po
     * @return
     */
    @ApiOperation(value = "修改计划任务")
    @PostMapping(value = "/updatePlanTask")
    public ResponseMessage2 updatePlanTask(PlanTaskPO po) {
        try {
            Example example = new Example(PlanTaskPO.class);
            Example.Criteria criteria = example.createCriteria();
            criteria.andEqualTo(LambdaUtils.getFieldName(PlanTaskPO::getYear), po.getYear());
            criteria.andEqualTo(LambdaUtils.getFieldName(PlanTaskPO::getOemName), po.getOemName());
            planTaskService.updateByPrimaryKeySelective(po);
            return ResponseMessage2.Success();
        } catch (Exception e) {
            e.printStackTrace();
            log.error("修改计划任务", e.getMessage());
            return ResponseMessage2.Failed(e.getMessage());


        }

    }


    /**
     * 删除计划任务
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "删除计划任务")
    @PostMapping(value = "/deletePlanTask")
    public ResponseMessage2 deletePlanTask(@RequestParam("id") String id) {

        try {
            Example example = new Example(PlanTaskPO.class);
            Example.Criteria criteria = example.createCriteria();
            criteria.andEqualTo(LambdaUtils.getFieldName(PlanTaskPO::getId), id);
            planTaskService.deleteByExample(example);
            return ResponseMessage2.Success();
        } catch (Exception e) {
            e.printStackTrace();
            log.error("删除计划任务", e.getMessage());
            return ResponseMessage2.Failed(e.getMessage());


        }
    }


    /**
     * 获取计划任务列表
     *
     * @param
     * @return
     */
    @ApiOperation(value = "获取计划任务列表")
    @GetMapping(value = "/getList")
    public ResponseMessage2<PageData<PlanTaskPO>> getList(int pageIndex, int pageSize) {

        Page<PlanTaskPO> result = PageHelper.startPage(pageIndex, pageSize);
        planTaskService.selectAll();
        return ResponseMessage2.Success2(PageData.create2(result.getTotal(), result.getResult()));
    }


    /**
     * 导入计划任务列表
     *
     * @param excel
     * @return
     */
    @ApiOperation(value = "导入计划任务配置")
    @PostMapping("/importExcel")
    public ResponseMessage2 importExcel(@RequestParam("file") MultipartFile excel) {
        return planTaskService.importExcel(excel);
    }


    @ApiOperation(value = "根据年份和主机厂查询计划任务")
    @PostMapping("/getPlanTaskByYearAndOemId")
    @ApiImplicitParams({@ApiImplicitParam(name = "year", value = "年份", dataType = "String", paramType = "query", required = true),
            @ApiImplicitParam(name = "oemId", value = "主机厂ID", dataType = "String", paramType = "query", required = false)})
    public ResponseMessage2 getPlanTaskByYearAndOemId(String year, Integer oemId) {
        return ResponseMessage2.Success2(planTaskService.getPlanTaskByYearAndOemId(year, oemId));
    }


}