package com.yuanchu.limslaboratory.controller; import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.yuanchu.limslaboratory.pojo.Inspection; import com.yuanchu.limslaboratory.pojo.InspectionProductList; import com.yuanchu.limslaboratory.pojo.Product; import com.yuanchu.limslaboratory.service.InspectionProductListService; import com.yuanchu.limslaboratory.service.InspectionService; import com.yuanchu.limslaboratory.service.ProductService; import com.yuanchu.limslaboratory.service.SpecificationsService; import com.yuanchu.limslaboratory.utils.JackSonUtil; import com.yuanchu.limslaboratory.utils.RedisUtil; import com.yuanchu.limslaboratory.vo.Result; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Map; /** *

* 前端控制器 *

* * @author 江苏鵷雏网络科技有限公司 * @since 2023-07-17 */ @ApiModel(value = "检验模块") @RestController @RequestMapping("/inspection") public class InspectionController { @Autowired private InspectionService inspectionService; @Autowired private ProductService productService; @Autowired private SpecificationsService specificationsService; @Autowired private InspectionProductListService inspectionProductListService; @ApiOperation("添加检验申请单") @ApiImplicitParams(value = { @ApiImplicitParam(name = "materialId", value = "物料信息id", dataTypeClass = Integer.class, required = true), }) @PostMapping("/addInspection") @Transactional(rollbackFor = Exception.class) public Result addInspection(@RequestHeader("X-Token") String token, int materialId,int type) throws Exception { List list = productService.selectProductByMaterialId(materialId); Map map = specificationsService.selectSNameSNName(materialId); if (map==null)return Result.fail("找不到该物料信息"); Object object = RedisUtil.get(token); Map unmarshal = JackSonUtil.unmarshal(JackSonUtil.marshal(object), Map.class); Inspection inspection = new Inspection(); inspection.setId(IdWorker.getIdStr()) .setType(type) .setInspectionStatus(0) .setState(1) .setVersion(1) .setUserName("" + unmarshal.get("name")) .setMaterialNum(Integer.valueOf("" + map.get("num"))) .setMaterialSupplier("" + map.get("supplier")) .setMaterialName("" + map.get("m_name")) .setMaterialLocation("" + map.get("location")) .setMaterialBatch("" + map.get("batch")) .setMaterialReelNumber("" + map.get("reel_number")) .setSpecificationsSerialNumber("" + map.get("ss_name")) .setSpecificationsVoltageLevel("" + map.get("voltage_level")) .setSpecificationsCrossSection("" + map.get("cross_section")) .setSpecificationsNumberOfCores("" + map.get("number_of_cores")) .setSpecificationsInstruct("" + map.get("instruct")); int judge1 = 0; int judge2 = 0; try { judge1 = inspectionService.addInspection(inspection); List list2 = new ArrayList<>(); list.forEach(a -> { InspectionProductList inspectionProductList = new InspectionProductList(); inspectionProductList.setName(a.getName()) .setMethod(a.getMethod()) .setUnit(a.getUnit()) .setRequired(a.getRequired()) .setInternal(a.getInternal()) .setState(1) .setVersion(1) .setInspectionId(inspection.getId()) .setUserId(Integer.parseInt("" + unmarshal.get("id"))) .setCreateTime(new Date()) .setUpdateTime(new Date()); list2.add(inspectionProductList); }); judge2 = inspectionProductListService.addInspectionProductList(list2); } catch (Exception e) { e.printStackTrace(); } return Result.success(judge1 > 0 && judge2 > 0 ? "提交成功" : "提交失败", judge1 > 0 && judge2 > 0); } }