package com.yuanchu.limslaboratory.controller; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 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.enums.InterfaceType; import com.yuanchu.limslaboratory.enums.MenuEnums; import com.yuanchu.limslaboratory.mapper.ProductMapper; import com.yuanchu.limslaboratory.pojo.Material; import com.yuanchu.limslaboratory.pojo.Product; import com.yuanchu.limslaboratory.pojo.RawMaterial; import com.yuanchu.limslaboratory.pojo.vo.InspectionVo; import com.yuanchu.limslaboratory.service.*; 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.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; /** *

* 前端控制器 *

* * @author 江苏鵷雏网络科技有限公司 * @since 2023-07-28 */ @Api(tags = "报检管理-->原材料报检-->页面版本表") @RestController @RequestMapping("/raw-material") public class RawMaterialController { @Autowired private RawMaterialService rawMaterialService; @Autowired private StandardService standardService; @Autowired private MaterialService materialService; @Resource private ProductMapper productMapper; @Resource private InspectionService inspectionService; @ApiOperation("查询所有检验计划分配") @ApiImplicitParams(value = { @ApiImplicitParam(name = "pageNo", value = "起始页", dataTypeClass = Integer.class, required = true), @ApiImplicitParam(name = "pageSize", value = "每一页数量", dataTypeClass = Integer.class, required = true), @ApiImplicitParam(name = "materialCoding", value = "材料编码", dataTypeClass = String.class), @ApiImplicitParam(name = "materialName", value = "材料名称", dataTypeClass = String.class), @ApiImplicitParam(name = "type", value = "状态", dataTypeClass = Integer.class), @ApiImplicitParam(name = "createTime", value = "来料日期", dataTypeClass = String.class) }) @GetMapping("/selectAll") @AuthHandler public Result selectRawMaterial(Integer pageSize, Integer pageNo, String materialCoding, String materialName, Integer type, String createTime) { IPage iPage = rawMaterialService.selectRawMaterial(materialCoding, materialName, type, createTime, new Page(pageNo, pageSize)); Map map = new HashMap<>(); map.put("row", iPage.getRecords()); map.put("total", iPage.getTotal()); return Result.success(map); } @ApiOperation("原材料报检添加") @PostMapping("/add") @AuthHandler(type = InterfaceType.ADD,menuId = MenuEnums.reportForInspection,isAdd = true) public Result insertRawMaterial(@Validated @RequestBody RawMaterial rawMaterial) { Integer integer = rawMaterialService.insertRawMaterial(rawMaterial); if (integer >= 1) { return Result.success("添加成功"); } return Result.fail("添加失败"); } @ApiOperation("原材料报检删除") @PostMapping("/delete") @AuthHandler(type = InterfaceType.DELETE,menuId = MenuEnums.reportForInspection,isAdd = true) public Result deleteRawMaterial(String deleteId) { Integer integer = rawMaterialService.deleteRawMaterial(deleteId); if (integer >= 1) { return Result.success("删除成功"); } return Result.fail("删除失败"); } @ApiOperation("获取物料名称") @GetMapping("/getMaterielName") @AuthHandler(type = InterfaceType.SELECT,menuId = MenuEnums.reportForInspection,isAdd = true) public Result getMaterielName(){ LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.select(Material::getId, Material::getName, Material::getCode) .eq(Material::getType,0).eq(Material::getState,1); List> maps = materialService.listMaps(wrapper); return Result.success(maps); } @ApiOperation("获取规格型号") @GetMapping("/specification") @AuthHandler(type = InterfaceType.SELECT,menuId = MenuEnums.reportForInspection,isAdd = true) public Result getSpecificationIdAndName(String materialId) { List> specificationIdAndName = standardService.getSpecificationIdAndName(materialId); return Result.success(specificationIdAndName); } @ApiOperation("选择版本") @GetMapping("/chooseVer") @ApiImplicitParams(value = { @ApiImplicitParam(name = "name", value = "产品名称", dataTypeClass = String.class, required = true), @ApiImplicitParam(name = "mcode", value = "产品编号", dataTypeClass = String.class, required = true), @ApiImplicitParam(name = "specifications", value = "规格型号", dataTypeClass = String.class, required = true) }) @AuthHandler(type = InterfaceType.SELECT,menuId = MenuEnums.reportForInspection,isAdd = true) public Result chooseVer(String name, String mcode, String specifications) { return Result.success(inspectionService.chooseVer(name, mcode, specifications)); } @ApiOperation(value = "查看该版本下我们要做的项目要求") @ApiImplicitParams(value = { @ApiImplicitParam(name = "name", value = "产品名称", dataTypeClass = String.class, required = true), @ApiImplicitParam(name = "mcode", value = "产品编号", dataTypeClass = String.class, required = true), @ApiImplicitParam(name = "specifications", value = "规格型号", dataTypeClass = String.class, required = true), @ApiImplicitParam(name = "version", value = "版本(默认最新版本)", dataTypeClass = Integer.class,required = true ), }) @GetMapping("/lookProByVer") @AuthHandler(type = InterfaceType.SELECT,menuId = MenuEnums.reportForInspection,isAdd = true) public Result lookProByVer(String name, String mcode, String specifications,Integer version) { return Result.success(inspectionService.lookProByVer(name, mcode, specifications,version,null)); } @ApiOperation(value = "原材料生成报检单") @PostMapping("/addInspect") @AuthHandler(type = InterfaceType.ADD,menuId = MenuEnums.reportForInspection,isAdd = true) public Result addInspect(@RequestHeader("X-Token") String token, @Validated @RequestBody InspectionVo inspectionVo) throws Exception { Object object = RedisUtil.get(token); Map unmarshal = JackSonUtil.unmarshal(JackSonUtil.marshal(object), Map.class); return Result.success(inspectionService.addInspect((Integer) unmarshal.get("id"), inspectionVo)); } }