Fixiaobai
2023-08-28 1865de1cd0255f7c42a326018a8cc3b5a1ee5253
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
package com.yuanchu.limslaboratory.controller;
 
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;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
 
import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
 
/**
 * <p>
 * 审核年度计划表 前端控制器
 * </p>
 *
 * @author 江苏鵷雏网络科技有限公司
 * @since 2023-08-10 11:50:11
 */
@Api(tags = "CNAS管理-->审核年度计划")
@RestController
@RequestMapping("/cnasAnnualPlan")
public class CnasAnnualPlanController {
 
    @Resource
    private CnasAnnualPlanService cnasAnnualPlanService;
 
    @ApiOperation(value = "查询审查计划")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "page", value = "初始页", dataTypeClass = Integer.class, required = true),
            @ApiImplicitParam(name = "pageSize", value = "每一页数量", dataTypeClass = Integer.class, required = true),
            @ApiImplicitParam(name = "planTime", value = "检验开始时间", dataTypeClass = Date.class),
    })
    @GetMapping("/selectAllList")
    @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());
        return Result.success(map);
    }
 
    @ApiOperation(value = "新增审查计划")
    @PostMapping("/addCnasAnnualPlan")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "CnasAnnualPlan", value = "审查对象", dataTypeClass = Integer.class, required = true)
    })
    @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("删除失败");
        }
    }
}