| | |
| | | |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.poi.excel.ExcelUtil; |
| | | import com.alibaba.excel.EasyExcel; |
| | | import com.alibaba.excel.util.StringUtils; |
| | | 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.excel.StructureTestObjectData; |
| | | import com.yuanchu.mom.excel.StructureTestObjectListener; |
| | | import com.yuanchu.mom.exception.ErrorException; |
| | | import com.yuanchu.mom.pojo.*; |
| | | import com.yuanchu.mom.service.*; |
| | | import com.yuanchu.mom.utils.JackSonUtil; |
| | |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | |
| | | InputStream inputStream = file.getInputStream(); |
| | | List<StructureItemParameter> lists = new ArrayList<>(); |
| | | AtomicReference<String> sample = new AtomicReference<>(); |
| | | ExcelUtil.readBySax(inputStream, 0, (i, l, list1) -> { |
| | | if(i == 0 && l == 1){ |
| | | sample.set(list1.get(1)+""); |
| | | ExcelUtil.readBySax(inputStream, -1, (i, l, list1) -> { |
| | | if (l == 1) { |
| | | sample.set(list1.get(1) + ""); |
| | | } |
| | | if (i == 0 && l >= 1) { |
| | | if (l >= 1) { |
| | | StructureItemParameter str = new StructureItemParameter(); |
| | | if (list1.get(1) == null) { |
| | | str.setSample(null); |
| | |
| | | String brand = (String) list1.get(1); |
| | | StringBuilder builder = new StringBuilder(); |
| | | builder.append("["); |
| | | if (ObjectUtil.isNotEmpty(list1.get(2))){ |
| | | 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)); |
| | | 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{ |
| | | } else { |
| | | builder.append("["); |
| | | builder.append(String.format("\"%s\"",brand)); |
| | | builder.append(String.format("\"%s\"", brand)); |
| | | builder.append("]"); |
| | | } |
| | | builder.append("]"); |
| | | str.setSample(builder.toString()); |
| | | } |
| | | str.setInspectionItem(list1.get(4).toString()); |
| | | str.setInspectionItemEn(list1.get(5).toString()); |
| | | if (list1.get(5) != null) { |
| | | str.setInspectionItemEn(list1.get(5).toString()); |
| | | } |
| | | if (list1.get(6) == null) { |
| | | str.setInspectionItemSubclass(null); |
| | | } else { |
| | |
| | | str.setInspectionItemSubclassEn(String.valueOf(list1.get(7).toString())); |
| | | } |
| | | StructureItemParameter db_str; |
| | | if (StringUtils.isEmpty(str.getInspectionItemSubclass())){ |
| | | 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()) |
| | | ); |
| | | try { |
| | | db_str = structureItemParameterService.getOne(Wrappers.lambdaQuery(StructureItemParameter.class) |
| | | .eq(StructureItemParameter::getInspectionItem, str.getInspectionItem()) |
| | | .eq(StructureItemParameter::getSample, str.getSample()) |
| | | .last("limit 1") |
| | | ); |
| | | } catch (Exception e) { |
| | | throw new ErrorException("重复查询:" + str.getInspectionItem()); |
| | | } |
| | | } else { |
| | | try { |
| | | db_str = structureItemParameterService.getOne(Wrappers.lambdaQuery(StructureItemParameter.class) |
| | | .eq(StructureItemParameter::getInspectionItem, str.getInspectionItem()) |
| | | .eq(StructureItemParameter::getSample, str.getSample()) |
| | | .eq(StructureItemParameter::getInspectionItemSubclass, str.getInspectionItemSubclass()) |
| | | .last("limit 1") |
| | | ); |
| | | } catch (Exception e) { |
| | | throw new ErrorException("重复查询:" + str.getInspectionItem() + " " + str.getInspectionItemSubclass()); |
| | | } |
| | | } |
| | | if (ObjectUtils.isNotEmpty(db_str)){ |
| | | if (ObjectUtils.isNotEmpty(db_str)) { |
| | | str.setId(db_str.getId()); |
| | | } |
| | | if (list1.get(8) == null) { |
| | |
| | | if (list1.get(13) == null) { |
| | | str.setPrice(null); |
| | | } else { |
| | | str.setPrice(BigDecimal.valueOf(Long.parseLong((list1.get(13).toString())))); |
| | | str.setPrice(list1.get(13) + ""); |
| | | } |
| | | |
| | | if (list1.get(14) == null) { |
| | |
| | | } |
| | | str.setInspectionItemType(jy); |
| | | String validateValueType = list1.get(18).toString(); |
| | | if (StringUtils.isNotBlank(validateValueType)){ |
| | | if (StringUtils.isNotBlank(validateValueType)) { |
| | | Enums enums = enumService.getOne(Wrappers.lambdaQuery(Enums.class) |
| | | .eq(Enums::getCategory, "检验值类型") |
| | | .eq(Enums::getLabel, validateValueType)); |
| | |
| | | } else { |
| | | str.setTemplateId(null); |
| | | } |
| | | try { |
| | | if (list1.get(22) != null && list1.get(22) != "") { |
| | | str.setInspectionItemClass(list1.get(22) + ""); |
| | | } else { |
| | | str.setInspectionItemClass(null); |
| | | } |
| | | } catch (Exception e) { |
| | | } |
| | | try { |
| | | if (list1.get(23) != null && list1.get(23) != "") { |
| | | str.setInspectionItemClassEn(list1.get(23) + ""); |
| | | } else { |
| | | str.setInspectionItemClassEn(null); |
| | | } |
| | | } catch (Exception e) { |
| | | } |
| | | try { |
| | | if (list1.get(24) != null) { |
| | | str.setLaboratory(list1.get(24) + ""); |
| | | } |
| | | } catch (Exception e) { |
| | | } |
| | | lists.add(str); |
| | | } |
| | | }); |
| | | structureItemParameterService.removeNoSample(sample.get()); |
| | | // 如果数据库里面的数据存在那么就执行更新拷贝操作 |
| | | try { |
| | | structureItemParameterService.saveBatch(lists); |
| | | structureItemParameterService.saveOrUpdateBatch(lists); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | throw new RuntimeException("服务端报错啦!!!"); |
| | | } |
| | | return Result.success(); |
| | | } |
| | | |
| | | @ValueClassify(value = "能力范围") |
| | | @ApiOperation(value = "导入检验对象") |
| | | @PostMapping("/importExcel") |
| | | public Result importExcel(@RequestParam("file") MultipartFile file) { |
| | | try { |
| | | EasyExcel.read(file.getInputStream(), StructureTestObjectData.class, new StructureTestObjectListener(productService)).sheet().doRead(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return Result.success(); |
| | | } |
| | | } |