Fixiaobai
2023-08-28 1865de1cd0255f7c42a326018a8cc3b5a1ee5253
cnas-server/src/main/java/com/yuanchu/limslaboratory/controller/CnasAnnualPlanController.java
@@ -2,9 +2,12 @@
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuanchu.limslaboratory.annotation.AuthHandler;
import com.yuanchu.limslaboratory.pojo.CnasAnnualPlan;
import com.yuanchu.limslaboratory.pojo.vo.CnasAnnualPlanVo;
import com.yuanchu.limslaboratory.service.CnasAnnualPlanService;
import com.yuanchu.limslaboratory.utils.JackSonUtil;
import com.yuanchu.limslaboratory.utils.RedisUtil;
import com.yuanchu.limslaboratory.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
@@ -12,7 +15,7 @@
import io.swagger.annotations.ApiOperation;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.util.Date;
@@ -39,12 +42,12 @@
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "page", value = "初始页", dataTypeClass = Integer.class, required = true),
            @ApiImplicitParam(name = "pageSize", value = "每一页数量", dataTypeClass = Integer.class, required = true),
            @ApiImplicitParam(name = "beginTime", value = "检验开始时间", dataTypeClass = Date.class),
            @ApiImplicitParam(name = "endTime", value = "检验结束时间", dataTypeClass = Date.class),
            @ApiImplicitParam(name = "planTime", value = "检验开始时间", dataTypeClass = Date.class),
    })
    @GetMapping("/selectAllList")
    public Result selectAllList(Integer page, Integer pageSize, @DateTimeFormat(pattern = "yyyy-MM-dd") Date beginTime, @DateTimeFormat(pattern = "yyyy-MM-dd") Date endTime) {
        IPage<CnasAnnualPlanVo> reportPage = cnasAnnualPlanService.selectAllList(new Page(page, pageSize), beginTime, endTime);
    @AuthHandler
    public Result selectAllList(Integer page, Integer pageSize, @DateTimeFormat(pattern = "yyyy-MM") Date planTime) {
        IPage<CnasAnnualPlanVo> reportPage = cnasAnnualPlanService.selectAllList(new Page(page, pageSize), planTime);
        Map<String, Object> map = new HashMap<>();
        map.put("total", reportPage.getTotal());
        map.put("row", reportPage.getRecords());
@@ -56,9 +59,46 @@
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "CnasAnnualPlan", value = "审查对象", dataTypeClass = Integer.class, required = true)
    })
    public Result addCnasAnnualPlan(@RequestBody CnasAnnualPlan cnasAnnualPlan) {
    @AuthHandler
    public Result addCnasAnnualPlan(@RequestHeader("X-Token") String token, @RequestBody CnasAnnualPlan cnasAnnualPlan) throws Exception {
        Object object = RedisUtil.get(token);
        Map<String, Object> unmarshal = JackSonUtil.unmarshal(JackSonUtil.marshal(object), Map.class);
        String name = (String) unmarshal.get("name");
        cnasAnnualPlan.setKeyboarder(name);
        //todo:获取name有问题
        cnasAnnualPlanService.save(cnasAnnualPlan);
        return Result.success();
    }
    @ApiOperation(value = "上传附件")
    @PostMapping("/addAccessory")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "auditTime", value = "审核日期", dataTypeClass = Date.class, required = true),
            @ApiImplicitParam(name = "file", value = "附件文件", dataTypeClass = MultipartFile.class, required = true)
    })
    @AuthHandler
    public Result addAccessory(@RequestHeader("X-Token") String token, Date auditTime, MultipartFile file) throws Exception {
        //解析当前登录用户
        Object object = RedisUtil.get(token);
        Map<String, Object> unmarshal = JackSonUtil.unmarshal(JackSonUtil.marshal(object), Map.class);
        String name = (String) unmarshal.get("name");
        cnasAnnualPlanService.addAccessory(name, auditTime, file);
        return Result.success();
    }
    @ApiOperation(value = "删除年度计划")
    @GetMapping("/deleteCnasAnnualPlan")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "planId", value = "审核日期", dataTypeClass = Integer.class, required = true)
    })
    @AuthHandler
    public Result deleteCnasAnnualPlan(Integer planId) {
        Integer isDeleteSuccess = cnasAnnualPlanService.deleteCnasAnnualPlan(planId);
        if (isDeleteSuccess == 1){
            return Result.success("删除成功");
        } else {
            return Result.fail("删除失败");
        }
    }
}