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;
/**
*
* 审核年度计划表 前端控制器
*
*
* @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 reportPage = cnasAnnualPlanService.selectAllList(new Page(page, pageSize), planTime);
Map 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 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 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("删除失败");
}
}
}