| | |
| | | package com.yuanchu.mom.controller; |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.lang.Console; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.json.JSONUtil; |
| | | import cn.hutool.poi.excel.ExcelReader; |
| | | import cn.hutool.poi.excel.ExcelUtil; |
| | | import cn.hutool.poi.excel.sax.handler.RowHandler; |
| | | import com.alibaba.excel.util.StringUtils; |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.yuanchu.mom.annotation.ValueAuth; |
| | | import com.yuanchu.mom.annotation.ValueClassify; |
| | | import com.yuanchu.mom.dto.PageTestObjectDto; |
| | | import com.yuanchu.mom.pojo.Product; |
| | | import com.yuanchu.mom.pojo.StructureItemParameter; |
| | | import com.yuanchu.mom.pojo.StructureTestObject; |
| | | import com.yuanchu.mom.service.CapacityScopeService; |
| | | import com.yuanchu.mom.service.ProductService; |
| | | import com.yuanchu.mom.pojo.*; |
| | | import com.yuanchu.mom.service.*; |
| | | import com.yuanchu.mom.utils.JackSonUtil; |
| | | import com.yuanchu.mom.vo.Result; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.AllArgsConstructor; |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.util.Map; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.time.format.DateTimeParseException; |
| | | import java.util.*; |
| | | import java.util.function.Predicate; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * æ£éªé¡¹ç®åæ°(StructureItemParameter)表æ§å¶å± |
| | |
| | | |
| | | private ProductService productService; |
| | | |
| | | private StructureItemParameterService structureItemParameterService; |
| | | |
| | | private StandardTemplateService standardTemplateService; |
| | | |
| | | @ValueClassify("è½åèå´") |
| | | @ApiOperation(value = "è·åé¡¹ç®æ£éªåæ°å表") |
| | | @PostMapping("/selectItemParameterList") |
| | |
| | | StructureItemParameter itemParameter = JackSonUtil.unmarshal(JackSonUtil.marshal(data.get("entity")), StructureItemParameter.class); |
| | | return Result.success(capacityScopeService.selectItemParameterList(page, itemParameter)); |
| | | } |
| | | |
| | | @ValueClassify("è½åèå´") |
| | | @ApiOperation(value = "æ·»å é¡¹ç®æ£éªåæ°") |
| | | @PostMapping("/addItemParameter") |
| | | public Result addItemParameter(@RequestBody StructureItemParameter itemParameter) { |
| | | return Result.success(capacityScopeService.addItemParameter(itemParameter)); |
| | | } |
| | | |
| | | @ValueClassify(value="è½åèå´") |
| | | @ApiOperation(value = "å é¤é¡¹ç®æ£éªåæ°") |
| | | @PostMapping("/delItemParameter") |
| | | public Result<?> delItemParameter(Integer id) { |
| | | return Result.success(capacityScopeService.delItemParameter(id)); |
| | | } |
| | | |
| | | @ValueClassify(value="è½åèå´") |
| | | @ApiOperation(value = "ä¿®æ¹é¡¹ç®æ£éªåæ°") |
| | | @PostMapping("/upItemParameter") |
| | | public Result<?> upItemParameter(@RequestBody StructureItemParameter itemParameter) { |
| | | return Result.success(capacityScopeService.upItemParameter(itemParameter)); |
| | | } |
| | | |
| | | @ValueClassify(value="è½åèå´") |
| | | @ApiOperation(value = "è·åæ£éªå¯¹è±¡") |
| | | @PostMapping("/selectTestObjectList") |
| | |
| | | PageTestObjectDto pageTestObjectDto = JackSonUtil.unmarshal(JackSonUtil.marshal(data.get("entity")), PageTestObjectDto.class); |
| | | return Result.success(capacityScopeService.selectTestObjectList(page, pageTestObjectDto)); |
| | | } |
| | | |
| | | @ValueClassify(value="è½åèå´") |
| | | @ApiOperation(value = "æ·»å æ£éªå¯¹è±¡") |
| | | @PostMapping("/addTestObject") |
| | | public Result addTestObject(@RequestBody StructureTestObject testObject) { |
| | | return Result.success(capacityScopeService.addTestObject(testObject)); |
| | | } |
| | | |
| | | @ValueClassify(value="è½åèå´") |
| | | @ApiOperation(value = "å 餿£éªå¯¹è±¡") |
| | | @PostMapping("/delTestObject") |
| | | public Result<?> delTestObject(Integer id) { |
| | | return Result.success(capacityScopeService.delTestObject(id)); |
| | | } |
| | | |
| | | @ValueClassify(value="è½åèå´") |
| | | @ApiOperation(value = "ä¿®æ¹æ£éªå¯¹è±¡") |
| | | @PostMapping("/upTestObject") |
| | | public Result upTestObject(@RequestBody StructureTestObject testObject) { |
| | | return Result.success(capacityScopeService.upTestObject(testObject)); |
| | | } |
| | | |
| | | @ValueAuth |
| | | @ApiOperation(value = "è·åæ£éªå¯¹è±¡æä¸¾") |
| | | @GetMapping("/selectTestObjectByName") |
| | | public Result selectTestObjectByName() { |
| | | return Result.success(capacityScopeService.selectTestObjectByName()); |
| | | } |
| | | |
| | | @ValueClassify("设å¤") |
| | | @ApiOperation(value = "设å¤éé¢éæ©æ£éªé¡¹ç®(æ å½¢ç»æ)") |
| | | @PostMapping("/getInsProduction") |
| | | public Result getInsProduction(){ |
| | | return Result.success(capacityScopeService.getInsProduction()); |
| | | } |
| | | |
| | | @ValueClassify(value="è½åèå´") |
| | | @ApiOperation(value = "ç»´æ¤æ£éªå¯¹è±¡ç产å") |
| | | @PostMapping("/selectProductListByObjectId") |
| | |
| | | Product product = JackSonUtil.unmarshal(JackSonUtil.marshal(data.get("entity")), Product.class); |
| | | return Result.success(productService.selectProductListByObjectId(page, product)); |
| | | } |
| | | |
| | | @ValueClassify(value="è½åèå´") |
| | | @ApiOperation(value = "æ·»å 产å") |
| | | @PostMapping("/addProduct") |
| | | public Result addProduct(@RequestBody Product product) { |
| | | return Result.success(productService.addProduct(product)); |
| | | } |
| | | |
| | | @ValueClassify(value="è½åèå´") |
| | | @ApiOperation(value = "ä¿®æ¹äº§å") |
| | | @PostMapping("/upProduct") |
| | | public Result upProduct(@RequestBody Product product) { |
| | | return Result.success(productService.upProduct(product)); |
| | | } |
| | | |
| | | @ValueClassify(value="è½åèå´") |
| | | @ApiOperation(value = "å é¤äº§å") |
| | | @PostMapping("/delProduct") |
| | |
| | | return Result.success(capacityScopeService.getItemTree()); |
| | | } |
| | | |
| | | @Autowired |
| | | private EnumService enumService; |
| | | |
| | | @ValueClassify(value = "è½åèå´") |
| | | @ApiOperation(value = "导å
¥") |
| | | @PostMapping("/importData") |
| | | @Transactional |
| | | public Result importData(@RequestParam("file") MultipartFile file) throws Exception { |
| | | InputStream inputStream = file.getInputStream(); |
| | | ExcelUtil.readBySax(inputStream, 0, (i, l, list1) -> { |
| | | if (i == 0 && l >= 1) { |
| | | StructureItemParameter str = new StructureItemParameter(); |
| | | if (list1.get(1) == null) { |
| | | str.setSample(null); |
| | | } else { |
| | | String brand = (String) list1.get(1); |
| | | StringBuilder builder = new StringBuilder(); |
| | | builder.append("["); |
| | | if (ObjectUtil.isNotEmpty(list1.get(2))){ |
| | | String production = (String) list1.get(2); |
| | | if (!production.contains("ã")){ |
| | | builder.append(String.format("[\"%s\",\"%s\"]",brand,production)); |
| | | }else{ |
| | | Arrays.stream(production.split("ã")).forEach(item->{ |
| | | builder.append(String.format("[\"%s\",\"%s\"],",brand,item)); |
| | | }); |
| | | builder.deleteCharAt(builder.length() - 1); |
| | | } |
| | | }else{ |
| | | builder.append("["); |
| | | builder.append(String.format("\"%s\"",brand)); |
| | | builder.append("]"); |
| | | } |
| | | builder.append("]"); |
| | | str.setSample(builder.toString()); |
| | | } |
| | | str.setInspectionItem(list1.get(4).toString()); |
| | | |
| | | if (list1.get(6) == null) { |
| | | str.setInspectionItemSubclass(null); |
| | | } else { |
| | | str.setInspectionItemSubclass(list1.get(6).toString()); |
| | | } |
| | | StructureItemParameter db_str = null; |
| | | if (StringUtils.isEmpty(str.getInspectionItemSubclass())){ |
| | | // æ¯è¾ä¸¤ä¸ªæ¡ä»¶ |
| | | db_str = structureItemParameterService.getOne(Wrappers.lambdaQuery(StructureItemParameter.class) |
| | | .eq(StructureItemParameter::getInspectionItem, str.getInspectionItem()) |
| | | .eq(StructureItemParameter::getSample, str.getSample()) |
| | | ); |
| | | }else{ |
| | | db_str = structureItemParameterService.getOne(Wrappers.lambdaQuery(StructureItemParameter.class) |
| | | .eq(StructureItemParameter::getInspectionItem, str.getInspectionItem()) |
| | | .eq(StructureItemParameter::getSample, str.getSample()) |
| | | .eq(StructureItemParameter::getInspectionItemSubclass,str.getInspectionItemSubclass()) |
| | | ); |
| | | } |
| | | str.setInspectionItemEn(list1.get(5).toString()); |
| | | |
| | | if (list1.get(7) == null) { |
| | | str.setInspectionItemSubclassEn(null); |
| | | } else { |
| | | str.setInspectionItemSubclassEn(String.valueOf(list1.get(7).toString())); |
| | | } |
| | | |
| | | if (list1.get(8) == null) { |
| | | str.setMethod(null); |
| | | } else { |
| | | StringBuffer buffer = new StringBuffer(); |
| | | String input = list1.get(8).toString(); |
| | | buffer.append("["); |
| | | String[] values = input.split("ã"); |
| | | for (String value : values) { |
| | | buffer.append("[\"").append(value.trim()).append("\"],"); |
| | | } |
| | | buffer.deleteCharAt(buffer.length() - 1); |
| | | buffer.append("]"); |
| | | str.setMethod(buffer.toString()); |
| | | } |
| | | |
| | | if (list1.get(9) == null) { |
| | | str.setLaboratory(null); |
| | | } else { |
| | | str.setLaboratory(list1.get(9).toString()); |
| | | } |
| | | if (list1.get(10) == null) { |
| | | str.setUnit(null); |
| | | } else { |
| | | str.setUnit(list1.get(10).toString()); |
| | | } |
| | | |
| | | if (list1.get(11) == null) { |
| | | str.setAskTell(null); |
| | | } else { |
| | | str.setAskTell(list1.get(11).toString()); |
| | | } |
| | | |
| | | if (list1.get(12) == null) { |
| | | str.setAsk(null); |
| | | } else { |
| | | str.setAsk(list1.get(12).toString()); |
| | | } |
| | | |
| | | if (list1.get(13) == null) { |
| | | str.setPrice(null); |
| | | } else { |
| | | str.setPrice(BigDecimal.valueOf(Long.parseLong((list1.get(13).toString())))); |
| | | } |
| | | |
| | | if (list1.get(14) == null) { |
| | | str.setManHour(null); |
| | | } else { |
| | | str.setManHour(Double.valueOf(list1.get(14).toString())); |
| | | } |
| | | |
| | | if (list1.get(15) == null) { |
| | | str.setManHourGroup(null); |
| | | } else { |
| | | str.setManHourGroup(list1.get(15).toString()); |
| | | } |
| | | |
| | | if (list1.get(16) == null) { |
| | | str.setManDay(null); |
| | | } else { |
| | | str.setManDay(Integer.valueOf(list1.get(16).toString())); |
| | | } |
| | | String jy = "0"; |
| | | if (list1.get(17).toString().equals("éééç±»å")) { |
| | | jy = "0"; |
| | | } else { |
| | | jy = "1"; |
| | | } |
| | | str.setInspectionItemType(jy); |
| | | String validateValueType = list1.get(18).toString(); |
| | | if (StringUtils.isNotBlank(validateValueType)){ |
| | | Enums enums = enumService.getOne(Wrappers.lambdaQuery(Enums.class) |
| | | .eq(Enums::getCategory, "æ£éªå¼ç±»å") |
| | | .eq(Enums::getLabel, validateValueType)); |
| | | str.setInspectionValueType(enums.getValue()); |
| | | } |
| | | int bsm = 0; |
| | | if (list1.get(19).toString().equals("å¦")) { |
| | | bsm = 0; |
| | | } else { |
| | | bsm = 1; |
| | | } |
| | | str.setBsm(bsm + ""); |
| | | StandardTemplate standTempIdByName = standardTemplateService.getStandTempIdByName(String.valueOf(list1.get(20))); |
| | | if (standTempIdByName != null) { |
| | | str.setTemplateId(standTempIdByName.getId()); |
| | | } else { |
| | | str.setTemplateId(null); |
| | | } |
| | | str.setSonLaboratory(list1.get(21).toString()); |
| | | structureItemParameterService.removeNoSample(JSON.toJSONString(list1.get(1))); |
| | | System.out.println(JSON.toJSONString(list1.get(1))); |
| | | // å¦ææ°æ®åºéé¢çæ°æ®åå¨é£ä¹å°±æ§è¡æ´æ°æ·è´æä½ |
| | | try { |
| | | if (ObjectUtils.isNotEmpty(db_str)){ |
| | | str.setId(db_str.getId()); |
| | | // å° str è¿è¡æ´æ° |
| | | structureItemParameterService.updateById(str); |
| | | }else{ |
| | | structureItemParameterService.save(str); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | throw new RuntimeException("æå¡ç«¯æ¥éå¦!!!"); |
| | | } |
| | | } |
| | | }); |
| | | return Result.success(); |
| | | } |
| | | } |