From 11af23e0c7976eed1211ba2ca0beae3a12e19310 Mon Sep 17 00:00:00 2001 From: lxp <1928192722@qq.com> Date: 星期三, 12 三月 2025 15:37:47 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/dev' into dev --- cnas-require/src/main/java/com/ruoyi/requier/service/impl/InsOrderPlanServiceImpl.java | 2784 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 2,784 insertions(+), 0 deletions(-) diff --git a/cnas-require/src/main/java/com/ruoyi/requier/service/impl/InsOrderPlanServiceImpl.java b/cnas-require/src/main/java/com/ruoyi/requier/service/impl/InsOrderPlanServiceImpl.java new file mode 100644 index 0000000..5430bc1 --- /dev/null +++ b/cnas-require/src/main/java/com/ruoyi/requier/service/impl/InsOrderPlanServiceImpl.java @@ -0,0 +1,2784 @@ +package com.ruoyi.requier.service.impl; + +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.lang.UUID; +import cn.hutool.core.util.NumberUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import cn.hutool.json.JSONUtil; +import com.alibaba.excel.EasyExcel; +import com.alibaba.excel.ExcelWriter; +import com.alibaba.excel.write.metadata.WriteSheet; +import com.alibaba.excel.write.metadata.style.WriteCellStyle; +import com.alibaba.excel.write.metadata.style.WriteFont; +import com.alibaba.excel.write.style.HorizontalCellStyleStrategy; +import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; +import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.deepoove.poi.XWPFTemplate; +import com.deepoove.poi.config.Configure; +import com.deepoove.poi.config.ConfigureBuilder; +import com.deepoove.poi.data.*; +import com.deepoove.poi.data.style.Style; +import com.deepoove.poi.util.TableTools; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.ruoyi.basic.mapper.StandardProductListMapper; +import com.ruoyi.basic.service.StandardTemplateService; +import com.ruoyi.basic.vo.StandardProductVO; +import com.ruoyi.common.constant.ExchangeConstants; +import com.ruoyi.common.constant.RouterKeyConstants; +import com.ruoyi.common.core.domain.entity.Custom; +import com.ruoyi.common.core.domain.entity.SysDictData; +import com.ruoyi.common.core.domain.entity.User; +import com.ruoyi.common.utils.DictUtils; +import com.ruoyi.common.utils.JackSonUtil; +import com.ruoyi.common.utils.QueryWrappers; +import com.ruoyi.common.utils.SecurityUtils; +import com.ruoyi.framework.exception.ErrorException; +import com.ruoyi.framework.util.MatrixToImageWriter; +import com.ruoyi.framework.util.RedisUtil; +import com.ruoyi.inspect.dto.*; +import com.ruoyi.inspect.mapper.*; +import com.ruoyi.inspect.pojo.*; +import com.ruoyi.inspect.service.InsBushingService; +import com.ruoyi.inspect.service.InsOrderService; +import com.ruoyi.inspect.service.InsUnPassService; +import com.ruoyi.inspect.service.impl.InsOrderServiceImpl; +import com.ruoyi.framework.util.SheetWriteHandlerUtil; +import com.ruoyi.inspect.vo.*; +import com.ruoyi.performance.mapper.AuxiliaryOutputWorkingHoursMapper; +import com.ruoyi.performance.mapper.PerformanceShiftMapper; +import com.ruoyi.performance.mapper.ShiftTimeMapper; +import com.ruoyi.requier.handler.*; +import com.ruoyi.requier.pojo.InformationNotification; +import com.ruoyi.requier.service.InformationNotificationService; +import com.ruoyi.requier.service.InsOrderPlanService; +import com.ruoyi.system.mapper.CustomMapper; +import com.ruoyi.system.mapper.UserMapper; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.logging.log4j.util.Strings; +import org.apache.poi.openxml4j.util.ZipSecureFile; +import org.apache.poi.ss.usermodel.FillPatternType; +import org.apache.poi.ss.usermodel.IndexedColors; +import org.apache.poi.xwpf.usermodel.*; +import org.springframework.amqp.rabbit.core.RabbitTemplate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Isolation; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.multipart.MultipartFile; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.*; +import java.net.URLEncoder; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.text.SimpleDateFormat; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.format.DateTimeFormatter; +import java.time.temporal.TemporalAdjusters; +import java.util.*; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicReference; +import java.util.concurrent.locks.ReentrantLock; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; + + +/** + * 妫�楠屼换鍔�-涓氬姟瀹炵幇灞� + */ +@Service +@Slf4j +public class InsOrderPlanServiceImpl extends ServiceImpl<InsOrderMapper, InsOrder> implements InsOrderPlanService { + + // 鎶ュ憡鎵爜璺緞 + @Value("${phoneQrCode}") + private String phoneQrCode; + + @Resource + private InsReportServiceImpl insReportService; + @Resource + private InsSampleMapper insSampleMapper; + @Resource + private InsSampleUserMapper insSampleUserMapper; + @Resource + private InsOrderMapper insOrderMapper; + @Resource + private InsOrderService insOrderService; + + @Resource + private InsOrderServiceImpl insOrderServiceImpl; + + @Resource + private StandardTemplateService standardTemplateService; + @Resource + private InsOrderStateMapper insOrderStateMapper; + @Resource + private InsProductMapper insProductMapper; + @Resource + private ShiftTimeMapper shiftTimeMapper; + @Resource + private PerformanceShiftMapper performanceShiftMapper; + + @Resource + private StandardProductListMapper standardProductListMapper; + + @Value("${wordUrl}") + private String wordUrl; + + @Value("${twoCode}") + private String twoCode; + + @Resource + private InsReportMapper insReportMapper; + + @Resource + private InsProductResultMapper insProductResultMapper; + + @Resource + private InsProductUserMapper insProductUserMapper; + + @Resource + private InsUnPassService insUnPassService; + + @Resource + AuxiliaryOutputWorkingHoursMapper auxiliaryOutputWorkingHoursMapper; + + @Resource + private InformationNotificationService informationNotificationService; + + @Resource + private UserMapper userMapper; + + @Resource + private CustomMapper customMapper; + + @Value("${file.path}") + private String imgUrl; + + @Resource + private InsBushingService insBushingService; + + @Resource + private InsBushingMapper insBushingMapper; + + @Resource + private InsFiberMapper insFiberMapper; + + @Resource + private InsFibersMapper insFibersMapper; + + @Resource + private InsOrderFileMapper insOrderFileMapper; + + @Resource + private InsReportApproveConfigMapper insReportApproveConfigMapper; + + @Autowired + private RabbitTemplate rabbitTemplate; + + + + private ReentrantLock lock = new ReentrantLock(); + + @Resource + private ThreadPoolTaskExecutor threadPoolTaskExecutor; + + @Override + public void exportInsOrderPlanResult(Map<String, Object> data, HttpServletResponse response) { + List<Map<String,Object>> dataList = new ArrayList<>(); + ObjectMapper objectMapper = new ObjectMapper(); + try { + Object o = getTabHeader(data.get("sonLaboratory").toString(), data.get("samples").toString()).get("tableHeader");// 鑾峰彇鍔ㄦ�佽〃澶� + List<Map<String, Object>> tableHeader = objectMapper.readValue(JSONUtil.toJsonStr(o), new TypeReference<List<Map<String, Object>>>() { + });// 琛ㄥご鏁版嵁 + Map<String, Object> table = objectMapper.readValue(JSONUtil.toJsonStr(data.get("trendsTable")), new TypeReference<Map<String, Object>>() { + }); + List<Map<String, Object>> trendsTable = getInsOrderPlanList(table); // 琛ㄦ牸鏁版嵁 + for (Map<String, Object> trend : trendsTable) { + Map<String, Object> addMap = new HashMap<>(); + addMap.put("濮旀墭鍗曞彿", trend.get("entrustCode")); + addMap.put("鏍峰搧缂栧彿", trend.get("sampleCode")); + addMap.put("绠¤壊鏍�", trend.get("bushing")); + addMap.put("鍏夌氦甯﹁壊鏍�", trend.get("fibers")); + addMap.put("鍏夌氦鑹叉爣", trend.get("fiber")); + addMap.put("妫�楠岄」鐩垎绫�", trend.get("inspectionItem")); + addMap.put("鍒涘缓浜�", trend.get("userName")); + addMap.put("妫�娴嬫椂闂�", trend.get("insTime")); + addMap.put("涓嬪彂鏃堕棿", trend.get("sendTime")); + for (Map<String, Object> map : tableHeader) { + if(Objects.isNull(trend.get(map.get("prop").toString())) || Objects.equals(trend.get(map.get("prop").toString()),"null")) { + addMap.put(map.get("label").toString(), ""); + }else { + addMap.put(map.get("label").toString(), trend.get(map.get("prop").toString())); + } + } + dataList.add(addMap); + } + List<List<String>> head = head(tableHeader); + response.setContentType("application/vnd.ms-excel"); + response.setCharacterEncoding("UTF-8"); + String fileName = URLEncoder.encode("妫�楠岀粨鏋�", "UTF-8"); + response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx"); + HorizontalCellStyleStrategy horizontalCellStyleStrategy = + new HorizontalCellStyleStrategy(getHeadStyle((short) 12),new WriteCellStyle()); + + ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()) + .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) + .registerWriteHandler(new SheetWriteHandlerUtil(data.get("samples").toString(),head.size())) + .useDefaultStyle(true).relativeHeadRowIndex(1) + .registerWriteHandler(horizontalCellStyleStrategy) + .build(); + WriteSheet mainSheet = EasyExcel.writerSheet("Sheet0").head(head).build(); + excelWriter.write(dataList(head,dataList), mainSheet); + // 鍏抽棴娴� + excelWriter.finish(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + /** + * 鍔ㄦ�佽〃澶� + * @param tableHeader + * @return + */ + private List<List<String>> head(List<Map<String, Object>> tableHeader) { + List<List<String>> list = new ArrayList<>(); + List<String> head0 = new ArrayList<>(); + head0.add("濮旀墭鍗曞彿"); + List<String> head1 = new ArrayList<>(); + head1.add("鏍峰搧缂栧彿"); + List<String> head2 = new ArrayList<>(); + head2.add("妫�楠岄」鐩垎绫�"); + List<String> head3 = new ArrayList<>(); + head3.add("鍒涘缓浜�"); + List<String> head4 = new ArrayList<>(); + head4.add("妫�娴嬫椂闂�"); + List<String> head5 = new ArrayList<>(); + head5.add("涓嬪彂鏃堕棿"); + List<String> head6 = new ArrayList<>(); + head6.add("绠¤壊鏍�"); + List<String> head7 = new ArrayList<>(); + head7.add("鍏夌氦甯﹁壊鏍�"); + List<String> head8 = new ArrayList<>(); + head8.add("鍏夌氦鑹叉爣"); + + list.add(head0); + list.add(head1); + list.add(head6); + list.add(head7); + list.add(head8); + list.add(head2); + list.add(head3); + list.add(head4); + list.add(head5); + for (Map<String, Object> map : tableHeader) { + List<String> head = new ArrayList<>(); + head.add(map.get("label").toString()); + list.add(head); + } + return list.stream().distinct().collect(Collectors.toList()); + } + + /** + * excel瀵煎嚭鏁版嵁 + * @param head + * @param dataList + * @return + */ + private List<List<Object>> dataList(List<List<String>> head,List<Map<String,Object>> dataList) { + List<List<Object>> list = new ArrayList<>(); + for(Map<String, Object> map : dataList) { + List<Object> addList = new ArrayList<>(); + for(List<String> k : head) { + if(map.containsKey(k.get(0))) { + addList.add(map.get(k.get(0))); + } + } + list.add(addList); + } + return list; + } + + /** + * 澶寸殑绛栫暐 + * @return + */ + public WriteCellStyle getHeadStyle(Short size){ + // 澶寸殑绛栫暐 + WriteCellStyle headWriteCellStyle = new WriteCellStyle(); + // 鑳屾櫙棰滆壊 + headWriteCellStyle.setFillForegroundColor(IndexedColors.WHITE.getIndex()); + headWriteCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND); + // 瀛椾綋 + WriteFont headWriteFont = new WriteFont(); + headWriteFont.setFontName("榛戜綋");//璁剧疆瀛椾綋鍚嶅瓧 + headWriteFont.setFontHeightInPoints(size);//璁剧疆瀛椾綋澶у皬 + headWriteFont.setBold(true);//瀛椾綋鍔犵矖 + headWriteCellStyle.setWriteFont(headWriteFont); //鍦ㄦ牱寮忕敤搴旂敤璁剧疆鐨勫瓧浣�; + + return headWriteCellStyle; + } + @Override + public List<Map<String, Object>> getInsOrderPlanList(Map<String,Object> data) { + String sampleType = data.get("sampleType").toString(); + String sonLaboratory = data.get("sonLaboratory").toString(); + String entrustCode = data.get("entrustCode").toString(); + Integer createUser = null; + String name = ""; + if(StringUtils.isNotBlank(data.get("createUser").toString())) { + createUser = Integer.parseInt(data.get("createUser").toString()); + name = userMapper.selectById(createUser).getName(); + } + String sampleCode = data.get("sampleCode").toString(); + String startTime = ""; + String endTime = ""; + List<Map<String, Object>> maps = new ArrayList<>(); + ObjectMapper objectMapper = new ObjectMapper(); + try { + if(StringUtils.isNotBlank(data.get("insTime").toString()) && !Objects.isNull(data.get("insTime"))) { + List insTime = objectMapper.readValue(JSONUtil.toJsonStr(data.get("insTime")), List.class); + startTime = insTime.get(0).toString(); + endTime = insTime.get(1).toString(); + } + // 琛ㄥご淇℃伅 + List<Map<String, Object>> headerS = objectMapper.readValue(JSONUtil.toJsonStr(data.get("headerS")), new TypeReference<List<Map<String, Object>>>() { + }); + // 鍒ゆ柇鏄惁鏄俯搴﹀惊鐜� + if(sampleType.equals("娓╁害寰幆")) { + List<ExportInsProductVO> insOrderTemList = insOrderMapper.getInsOrderTemList(entrustCode, sampleCode, startTime, endTime,name); + List<TemperatureCycling> temList = insOrderServiceImpl.getTemList(insOrderTemList); + for (TemperatureCycling map : temList) { + Map<String, Object> resultMap = new HashMap<>(); + resultMap.put("entrustCode", map.getEntrustCode()); //濮旀墭鍗曞彿 + resultMap.put("sampleCode", map.getSampleCode()); //鏍峰搧缂栧彿 + resultMap.put("bushing", map.getBushColor()); //濂楃 + resultMap.put("fiber", map.getColor()); //鍏夌氦 + resultMap.put("fibers", map.getCode()); //鍏夌氦甯� + resultMap.put("userName", map.getCheckName()); //妫�楠屼汉 + resultMap.put("insTime", map.getInsTime()); //妫�娴嬫椂闂� + resultMap.put("sendTime", map.getSendTime()); //涓嬪彂鏃堕棿 + resultMap.put("inspectionItem", map.getSample()); //妫�楠岄」鐩� + //娓╁害寰幆瀛愰」 + resultMap.put("inspectionItems", map.getInspectionItem()); + resultMap.put("inspectionItemSubclass", map.getInspectionItemSubclass()); + resultMap.put("attenuationCoefficient1310", map.getAttenuationCoefficient1310()); + resultMap.put("attenuationDifference1", map.getAttenuationDifference1()); + resultMap.put("attenuationDifference2", map.getAttenuationDifference2()); + resultMap.put("attenuationCoefficient1625", map.getAttenuationCoefficient1625()); + resultMap.put("attenuationDifference3", map.getAttenuationDifference3()); + resultMap.put("attenuationCoefficient1383", map.getAttenuationCoefficient1383()); + resultMap.put("attenuationDifference4", map.getAttenuationDifference4()); + resultMap.put("attenuationCoefficient1490", map.getAttenuationCoefficient1490()); + resultMap.put("attenuationDifference5", map.getAttenuationDifference5()); + resultMap.put("attenuationDifferenceMax", map.getAttenuationDifferenceMax()); + resultMap.put("insResult", map.getInsResult()); + maps.add(resultMap); + } + } + else { + List<Map<String, Object>> insOrderPlanList = baseMapper.getInsOrderPlanList(sonLaboratory, entrustCode, sampleCode, createUser, startTime, endTime,sampleType); + for (Map<String, Object> map : insOrderPlanList) { + Map<String, Object> resultMap = new HashMap<>(); + resultMap.put("entrustCode", map.get("entrustCode")); //濮旀墭鍗曞彿 + resultMap.put("sampleCode", map.get("sampleCode")); //鏍峰搧缂栧彿 + resultMap.put("bushing", map.get("bushing")); //濂楃 + resultMap.put("fiber", map.get("fiber")); //鍏夌氦 + resultMap.put("fibers", map.get("fibers")); //鍏夌氦甯� + resultMap.put("userName", map.get("userName")); //鍒涘缓浜� + resultMap.put("insTime", map.get("insTime")); //妫�娴嬫椂闂� + resultMap.put("sendTime", map.get("sendTime")); //涓嬪彂鏃堕棿 + resultMap.put("inspectionItem", map.get("inspectionItem")); //妫�楠岄」鐩� + // 鏌ョ湅琛ㄥご鏄惁瀛樺湪瀛愰」 + List<Map<String, Object>> collect = headerS.stream().filter(item -> + item.get("label").toString().equals(map.get("inspectionItemSubclass").toString())) + .collect(Collectors.toList()); + // 鏈夊氨鍙栧瓙椤� 娌℃湁灏卞彇鐖堕」 + if(!collect.isEmpty() && !Objects.isNull(collect)) { + resultMap.put(collect.get(0).get("prop").toString(), map.get("lastValue"));//妫�楠屽瓙椤圭洰 妫�楠岀粨鏋� + }else { + List<Map<String, Object>> collect1 = headerS.stream().filter(item -> + item.get("label").toString().equals(map.get("inspectionItem").toString())) + .collect(Collectors.toList()); + if(!collect1.isEmpty() && !Objects.isNull(collect1)) { + resultMap.put(collect1.get(0).get("prop").toString(), map.get("lastValue"));//妫�楠岄」鐩� 妫�楠岀粨鏋� + } + } + maps.add(resultMap); + } + + } + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + return maps.stream().distinct().collect(Collectors.toList()); + } + + /** + * 鑾峰彇褰撳墠鐢ㄦ埛鐨勫疄楠屽 + * @return + */ + private String getCurrentUserLaboratory(){ + // 鑾峰彇褰撳墠浜烘墍鍦ㄥ疄楠屽 + Integer userId = SecurityUtils.getUserId().intValue(); + String departLimsId = userMapper.selectById(userId).getDepartLimsId(); + String laboratory = ""; + if(StringUtils.isNotBlank(departLimsId)) { + String[] split = departLimsId.split(","); + for (String s : split) { + if (StringUtils.isNotBlank(s) && (!Arrays.asList("1","22").contains(s))) { + laboratory = insOrderMapper.getDepartment(Integer.parseInt(s)); + } + } + } + return laboratory; + } + + /** + * 瀵煎嚭濮旀墭璐圭敤 + * @param data 鏁版嵁 + */ + @Override + public void exportCommissionFees(Map<String, Object> data,HttpServletResponse response) { + String laboratory = getCurrentUserLaboratory(); + // 鏃ユ湡鏍煎紡鍖� + DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + String start = LocalDateTime.of( + LocalDate.parse(data.get("startTime").toString(), + dateTimeFormatter),LocalTime.of(00, 00, 00) + ).toString(); + String end = LocalDateTime.of( + LocalDate.parse(data.get("endTime").toString(), + dateTimeFormatter),LocalTime.of(23, 59, 59) + ).toString(); + // 鑾峰彇鏁版嵁 + String company = data.get("company").toString(); + List<CommissionFeesDto> list = insOrderMapper.selectCommissionFees(laboratory,company, start, end); + list = list.stream().map(dto -> { + Set<String> uniqueTags = new HashSet<>(); + if (dto.getInsItem().contains(",")) { + for (String s : dto.getInsItem().split(",")) { + uniqueTags.add(s.split("@")[0]); + } + } else { + uniqueTags.add(dto.getInsItem().split("@")[0]); + } + dto.setInsItem(uniqueTags.toString()); + return dto; + }).collect(Collectors.toList()); + try { + String fileName = URLEncoder.encode(laboratory+"濮旀墭璐圭敤缁熻", "UTF-8"); + response.setContentType("application/vnd.ms-excel"); + response.setCharacterEncoding("UTF-8"); + response.setHeader("content-disposition", "attachment;filename=" + fileName + ".xlsx"); + // 鏂板缓ExcelWriter + ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream(),CommissionFeesDto.class).build(); + // 鏍规嵁濮旀墭鍗曚綅杩涜sheet鍒嗙被 + Map<String, List<CommissionFeesDto>> collect = list.stream().collect(Collectors.groupingBy(CommissionFeesDto::getCompany)); + Iterator<Map.Entry<String, List<CommissionFeesDto>>> iterator = collect.entrySet().iterator(); + int i = 0; + while(iterator.hasNext()) { + Map.Entry<String, List<CommissionFeesDto>> entry = iterator.next(); + WriteSheet writeSheet = EasyExcel.writerSheet(i, entry.getKey()).build(); + excelWriter.write(entry.getValue(), writeSheet); + i++; + } +// WriteSheet writeSheet = EasyExcel.writerSheet().head(CommissionFeesDto.class).build(); +// excelWriter.write(list, writeSheet); + + // 灏嗘暟鎹啓鍏� + excelWriter.finish(); + } catch (Exception e) { + throw new RuntimeException(e); + } + + } + + @Override + public void exportUnInsProducts(UnInsProductsDTO unInsProductsDTO, HttpServletResponse response) { + String laboratory = getCurrentUserLaboratory(); + //鏃ユ湡鏍煎紡鍖� + DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + LocalDateTime startDateTime = LocalDateTime.of(LocalDate.parse(unInsProductsDTO.getStartDate(),dateTimeFormatter),LocalTime.MIN); + LocalDateTime endDateTime = LocalDateTime.of(LocalDate.parse(unInsProductsDTO.getEndDate(),dateTimeFormatter),LocalTime.MAX); + + // 鑾峰彇鏁版嵁 + List<UnInsProductsVO> list = baseMapper.selectUnInsProducts(laboratory, startDateTime, endDateTime,unInsProductsDTO); + try { + String fileName = URLEncoder.encode(laboratory+"寰呮浠诲姟缁熻", "UTF-8"); + response.setContentType("application/vnd.ms-excel"); + response.setCharacterEncoding("UTF-8"); + response.setHeader("content-disposition", "attachment;filename=" + fileName + ".xlsx"); + // 鏂板缓ExcelWriter + ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).build(); + WriteSheet writeSheet = EasyExcel.writerSheet().head(UnInsProductsVO.class).build(); + excelWriter.write(list, writeSheet); + // 鍏抽棴娴� + excelWriter.finish(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + @Override + public IPage<TasksShowDto> tasksShow(Page page, String sonLaboratory) { + IPage tasksShow = insOrderMapper.getTasksShow(page, sonLaboratory); + return tasksShow; + } + + @Override + public int getCurrentMonthPlanTotalBySonLaboratory(String sonLaboratory,LocalDateTime startTime, LocalDateTime endTime) { + if(StringUtils.isNotBlank(sonLaboratory)){ + if(Objects.isNull(startTime) || Objects.isNull(endTime)) { + //鑾峰彇褰撴湀鐨勫紑濮嬪拰缁撴潫鏃堕棿 + // 褰撴湀鐨勫紑濮嬫椂闂达紙绗竴澶� 00:00:00锛� + startTime = LocalDate.now() + .withDayOfMonth(1) + .atStartOfDay(); + + // 褰撴湀鐨勭粨鏉熸椂闂达紙鏈�鍚庝竴澶� 23:59:59.999999999锛� + endTime = LocalDate.now() + .with(TemporalAdjusters.lastDayOfMonth()) + .atTime(LocalTime.MAX); + } + //鏌ヨ褰撴湀璇ュ瓙璇曢獙瀹ょ殑鎬讳换鍔℃潯鏁� + return baseMapper.selectPlanCountBySonLaboratory(sonLaboratory,startTime,endTime); + } + return 0; + } + + @Override + public Map<String, Object> getTabHeader(String sonLaboratory,String samples) { + Map<String, Object> resultMap = new HashMap<>(); + List<String> list = new ArrayList<>(); + List<Map<String, Object>> maps = new ArrayList<>(); + if(StringUtils.isNotBlank(samples)) { + samples = "[" + "\"" + samples + "\""; + } + List<Map<String, Object>> tabHeader = baseMapper.getTabHeader(sonLaboratory,samples); + ObjectMapper objectMapper = new ObjectMapper(); + Long count = 1l; + for (Map<String, Object> map : tabHeader) { + try { + List<List<String>> sample = objectMapper.readValue(JSONUtil.toJsonStr(map.get("sample").toString()), new TypeReference<List<List<String>>>() { + }); + // 鑾峰彇tab椤佃〃澶� + for (List<String> strings : sample) { + list.add(strings.get(0)); + } + // 鑾峰彇琛ㄦ牸琛ㄥご + if(StringUtils.isNotBlank(samples)) { + if(map.containsKey("inspectionItemSubclass")) { + if(StringUtils.isNotBlank(map.get("inspectionItemSubclass").toString())) { + HashMap<String, Object> map1 = new HashMap<>(); + map1.put("label", map.get("inspectionItemSubclass").toString()); // label + map1.put("prop","lastValue"+count); // prop + maps.add(map1); + }else { + HashMap<String, Object> map1 = new HashMap<>(); + map1.put("label", map.get("inspectionItem").toString()); // label + map1.put("prop","lastValue"+count); // prop + maps.add(map1); + } + }else { + HashMap<String, Object> map1 = new HashMap<>(); + map1.put("label", map.get("inspectionItem").toString()); // label + map1.put("prop","lastValue"+count); // prop + maps.add(map1); + } + count++; + } + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + } + + if (samples.contains("娓╁害寰幆")){ + addElementToMaps(maps, "寰幆娆℃暟", "inspectionItems"); + addElementToMaps(maps, "娓╁害鐐�", "inspectionItemSubclass"); + addElementToMaps(maps, "琛板噺绯绘暟1310", "attenuationCoefficient1310"); + addElementToMaps(maps, "琛板噺宸�1", "attenuationDifference1"); + addElementToMaps(maps, "琛板噺绯绘暟1550", "attenuationCoefficient1550"); + addElementToMaps(maps, "琛板噺宸�2", "attenuationDifference2"); + addElementToMaps(maps, "琛板噺绯绘暟1625", "attenuationCoefficient1625"); + addElementToMaps(maps, "琛板噺宸�3", "attenuationDifference3"); + addElementToMaps(maps, "琛板噺1383", "attenuationCoefficient1383"); + addElementToMaps(maps, "琛板噺宸�4", "attenuationDifference4"); + addElementToMaps(maps, "琛板噺1490", "attenuationCoefficient1490"); + addElementToMaps(maps, "琛板噺宸�5", "attenuationDifference5"); + addElementToMaps(maps, "琛板噺宸甅ax", "attenuationDifferenceMax"); + addElementToMaps(maps, "鏄惁鍚堟牸", "insResult"); + } + + Map<String, Map<String, Object>> uniqueByLabel = maps.stream() + .collect(Collectors.toMap( + map -> (String) map.get("label"), + map -> map, + (existing, replacement) -> existing, // 淇濈暀绗竴涓亣鍒扮殑Map + LinkedHashMap::new + )); + // 灏嗙粨鏋滆浆鎹㈠洖List<Map<String, Object>> + List<Map<String, Object>> collect1 = new ArrayList<>(uniqueByLabel.values()); +// List<Map<String, Object>> collect1 = maps.stream().distinct().collect(Collectors.toList()); + List<String> collect = list.stream().distinct().collect(Collectors.toList()); + collect.add("娓╁害寰幆"); + resultMap.put("tabHeader", collect); + resultMap.put("tableHeader", collect1); + return resultMap; + } + + private static void addElementToMaps(List<Map<String, Object>> maps, String label, String prop) { + Map<String, Object> map = new HashMap<>(); + map.put("label", label); + map.put("prop", prop); + maps.add(map); + } + + @Override + public IPage<InsOrderPlanVO> selectInsOrderPlanList(Page page, InsOrderPlanDTO insOrderPlanDTO) { + User user = userMapper.selectById(SecurityUtils.getUserId());//褰撳墠鐧诲綍鐨勪汉 + //鑾峰彇褰撳墠浜烘墍灞炲疄楠屽id + String departLimsId = user.getDepartLimsId(); + String laboratory = null; + if (ObjectUtils.isNotEmpty(departLimsId) && !departLimsId.isEmpty()) { + String[] split = departLimsId.split(","); + //鏌ヨ瀵瑰簲鏋舵瀯鍚嶇О(閫氫俊瀹為獙瀹�,鐢靛姏瀹為獙瀹�,妫�娴嬪姙) + String departLims = baseMapper.seldepLimsId(Integer.parseInt(split[split.length - 1])); + if (departLims.contains("瀹為獙瀹�")) { + laboratory = departLims; + } + } + + String checkName = null; + String userName = null; + if (ObjectUtil.isNotEmpty(insOrderPlanDTO.getUserId())) { + userName = userMapper.selectById(SecurityUtils.getUserId()).getName(); + if(Objects.equals(insOrderPlanDTO.getInsState(),"3")) { + userName = ""; + checkName = userMapper.selectById(SecurityUtils.getUserId()).getName(); + } + insOrderPlanDTO.setUserId(null); + } + InsOrderPlanDTO planDTO = new InsOrderPlanDTO(); + QueryWrapper<InsOrderPlanDTO> wrappers = QueryWrappers.queryWrappers(planDTO); + IPage<InsOrderPlanVO> insOrderPage = insSampleMapper.findInsSampleAndOrder( + page, + userName, + checkName, + insOrderPlanDTO.getSonLaboratory(), + insOrderPlanDTO.getSample(), + insOrderPlanDTO.getSampleCode(), + laboratory, + insOrderPlanDTO.getEntrustCode(), + insOrderPlanDTO.getInsState(), + wrappers, + insOrderPlanDTO.getSendTimeRange() + ); + return insOrderPage; + } + + @Override + public IPage<InsOrderPlanTaskSwitchVo> inspectionOrderDetailsTaskSwitching(Page page, InsOrderPlanDTO insOrderPlanDTO) { + Integer userId = SecurityUtils.getUserId().intValue(); + User user = userMapper.selectById(userId);//褰撳墠鐧诲綍鐨勪汉 + + //鑾峰彇褰撳墠浜烘墍灞炲疄楠屽id + String departLimsId = user.getDepartLimsId(); + String laboratory = null; + if (ObjectUtils.isNotEmpty(departLimsId) && !departLimsId.equals("")) { + String[] split = departLimsId.split(","); + //鏌ヨ瀵瑰簲鏋舵瀯鍚嶇О(閫氫俊瀹為獙瀹�,鐢靛姏瀹為獙瀹�,妫�娴嬪姙) + String departLims = baseMapper.seldepLimsId(Integer.parseInt(split[split.length - 1])); + if (departLims.contains("瀹為獙瀹�")) { + laboratory = departLims; + } + } + if (ObjectUtil.isNotEmpty(insOrderPlanDTO.getUserId())) { + insOrderPlanDTO.setUserId(userId.longValue()); + } + String sonLaboratory = insOrderPlanDTO.getSonLaboratory();//璇曢獙瀹� + IPage<InsOrderPlanTaskSwitchVo> insOrderPage = insSampleMapper.inspectionOrderDetailsTaskSwitching(page, QueryWrappers.queryWrappers(insOrderPlanDTO), userId, sonLaboratory, laboratory); + return insOrderPage; + } + + //璁ら浠诲姟 + @Override + public boolean claimInsOrderPlan(InsOrderPlanDTO entity) { + if (Objects.isNull(entity)) { + return false; + } + Integer userId = SecurityUtils.getUserId().intValue(); + InsSampleUser insSampleUser = new InsSampleUser(entity.getInsSampleId().intValue(), userId, 0, entity.getSonLaboratory()); + return insSampleUserMapper.insert(insSampleUser) > 0; + } + + @Override + public Map<String, Object> doInsOrder(Integer id, String laboratory) { +// InsOrder insOrder = new InsOrder(); +// insOrder.setId(id); + + InsOrder order = insOrderMapper.selectById(id); + InsOrderState insOrderState = insOrderStateMapper.selectOne(new LambdaQueryWrapper<InsOrderState>() + .eq(InsOrderState::getInsOrderId, id) + .eq(InsOrderState::getLaboratory, laboratory)); + + if (BeanUtil.isEmpty(insOrderState.getInsTime())) { + order.setInsTime(LocalDateTime.now()); + insOrderMapper.updateById(order); + insOrderStateMapper.update(null, Wrappers.<InsOrderState>lambdaUpdate().eq(InsOrderState::getInsOrderId, id).eq(InsOrderState::getLaboratory, laboratory).set(InsOrderState::getInsTime, LocalDateTime.now()).set(InsOrderState::getInsState, 1)); + } + Map<String, Object> map = insOrderService.getInsOrderAndSample(id, laboratory); + List<SampleProductDto> list = JSON.parseArray(JSON.toJSONString(map.get("sampleProduct")), SampleProductDto.class); + for (SampleProductDto samples : list) { + if (BeanUtil.isEmpty(samples.getInsProduct())) continue; + samples.setBushing(insBushingService.selectBushingBySampleId(samples.getId())); + } + map.put("sampleProduct", list.stream().sorted(Comparator.comparing(SampleProductDto::getId)).collect(Collectors.toList())); + return map; + } + + @Override + public List<InsProduct> getInsProduct(Integer id, Integer type, String laboratory, HttpServletRequest request) { + List<InsProduct> insProducts = new ArrayList<>(); + switch (type) { + case 0: + //鏍峰搧 + insProducts = insSampleMapper.getInsProduct1(id, laboratory); + if(!insProducts.isEmpty()) { + boolean flag = false; + for(InsProduct insProduct : insProducts) { + if("娓╁害寰幆".equals(insProduct.getInspectionItem())) { + flag = true; + break; + } + } + if(flag) { + insProducts = insSampleMapper.getInsProduct5(id, laboratory); + } + } + break; + case 1: + //鍏夌氦甯� + insProducts = insSampleMapper.getInsProduct2(id, laboratory); + break; + case 2: + //鍏夌氦 + insProducts = insSampleMapper.getInsProduct3(id, laboratory); + break; + case 3: + //濂楃 + insProducts = insSampleMapper.getInsProduct4(id, laboratory); + break; + } + + //濡傛灉鏄ぇ鏍峰搧涓嬬殑椤圭洰涓虹┖,閭d箞鏌ヨ绗竴涓厜绾ょ殑椤圭洰 + if (ObjectUtils.isEmpty(insProducts) && type == 0) { + //鏌ヨ绗竴涓厜绾ょ殑id + List<InsFiber> insFibers = insFiberMapper.selectList(Wrappers.<InsFiber>lambdaQuery() + .eq(InsFiber::getInsBushingId, insBushingMapper.selectList(Wrappers.<InsBushing>lambdaQuery() + .eq(InsBushing::getInsSampleId, id) + .isNotNull(InsBushing::getStandNum) + .isNotNull(InsBushing::getTestNum)).get(0).getId())); + if(CollectionUtils.isNotEmpty(insFibers)) { + insProducts = insSampleMapper.getInsProduct3(insFibers.get(0).getId(),laboratory); + } + // 濡傛灉鍏夌氦涓嬬殑椤圭洰涓虹┖,閭d箞鏌ヨ绗竴涓厜绾ゅ甫鐨勯」鐩� + else { + List<InsFibers> insFibersS = insFibersMapper.selectList(Wrappers.<InsFibers>lambdaQuery() + .eq(InsFibers::getInsBushingId, insBushingMapper.selectList(Wrappers.<InsBushing>lambdaQuery() + .eq(InsBushing::getInsSampleId, id) + .isNotNull(InsBushing::getTestNum) + ).get(0).getId())); + //濡傛灉鍏夌氦甯︿笉涓虹┖锛屾煡璇㈠厜绾ゅ甫涓嬫槸鍚﹂厤鏈夊厜绾� + if(!insFibersS.isEmpty()){ + List<InsFiber> insFiberList = insFiberMapper.selectList(Wrappers.<InsFiber>lambdaQuery().eq(InsFiber::getInsFibersId, insFibersS.get(0).getId())); + if(!insFiberList.isEmpty()){ + insProducts = insSampleMapper.getInsProduct3(insFiberList.get(0).getId(),laboratory); + }else{ + insProducts = insSampleMapper.getInsProduct6(insFibersS.get(0).getId(),laboratory); + } + } + } + } + Set<Integer> set = new HashSet<>(); + Map<Integer, String> map2 = new HashMap<>(); + if (BeanUtil.isEmpty(insProducts)) return null; + getTemplateThing(set, map2, insProducts); + return insProducts; + } + + @Override + public List<String> checkSubmitPlan(Integer orderId, String laboratory,String temperature,String humidity) { + List<String> collect = new ArrayList<>(); + List<InsSample> insSamples = insSampleMapper.selectList(Wrappers.<InsSample>lambdaQuery().eq(InsSample::getInsOrderId, orderId).select(InsSample::getId)); + List<Integer> ids = insSamples.stream().map(InsSample::getId).collect(Collectors.toList()); + List<InsProduct> insProducts = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery() + .in(InsProduct::getInsSampleId, ids) + .eq(InsProduct::getSonLaboratory, laboratory) + .eq(InsProduct::getState, 1) + .eq(InsProduct::getInsResult, 0)); + if (insProducts.size() > 0) { + collect = insProducts.stream().map(insProduct -> { + return insProduct.getInspectionItem() + "-" + insProduct.getInspectionItemSubclass(); + }).collect(Collectors.toList()); + insProductMapper.update(null,new LambdaUpdateWrapper<InsProduct>() + .set(InsProduct::getTemperature,temperature) + .set(InsProduct::getHumidity,humidity) + .in(InsProduct::getInsSampleId,ids)); + } + return collect; + } + + @Override + public IPage<InsOrderFile> getFileList(Page page, InsOrderFile insOrderFile) { + Integer insOrderId = insOrderFile.getInsOrderId(); + insOrderFile.setInsOrderId(null); + IPage<InsOrderFile> insOrderFileIPage = insOrderFileMapper.getFileList(page, QueryWrappers.queryWrappers(insOrderFile),insOrderId); + return insOrderFileIPage; + } + + @Override + public int uploadFile(Integer orderId, MultipartFile file) { + String urlString; + String pathName; + String path; + String filename = file.getOriginalFilename(); + String contentType = file.getContentType(); + InsOrderFile insOrderFile = new InsOrderFile(); + insOrderFile.setInsOrderId(orderId); + insOrderFile.setFileName(filename); + if (contentType != null && contentType.startsWith("image/")) { + // 鏄浘鐗� + path = imgUrl; + insOrderFile.setType(1); + } else { + // 鏄枃浠� + path = wordUrl; + insOrderFile.setType(2); + } + try { + File realpath = new File(path); + if (!realpath.exists()) { + realpath.mkdirs(); + } + pathName = UUID.randomUUID() + "_" + file.getOriginalFilename(); + urlString = realpath + "/" + pathName; + file.transferTo(new File(urlString)); + insOrderFile.setFileUrl(pathName); + return insOrderFileMapper.insert(insOrderFile); + } catch (Exception e) { + e.printStackTrace(); + System.err.println("闄勪欢涓婁紶閿欒"); + return 0; + } + } + + //鍒囨崲璁板綍妯$増鏌ヨ妫�楠屽唴瀹� + @Override + public Map<String, Object> getReportModel(Integer sampleId, String sonLaboratory) { + Map<String, Object> map = new HashMap<>(); + //鍏堟煡鍑哄绠� + List<InsBushing> insBushings = insBushingMapper.selectList(Wrappers.<InsBushing>lambdaQuery().eq(InsBushing::getInsSampleId, sampleId)); + List<InsFibersVO> fibers = new ArrayList<>(); + List<InsFiber> fiber = new ArrayList<>(); + List<InsBushing> bush = new ArrayList<>(); + for (InsBushing insBushing : insBushings) { + //淇濆瓨濂楃(鏉惧绠�) + List<InsProduct> insProductsByBush = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery() + .eq(InsProduct::getInsBushId, insBushing.getId()) + .eq(InsProduct::getSonLaboratory,sonLaboratory) + .eq(InsProduct::getState,1) + .and(i->i.like(InsProduct::getInspectionItem,"鏉惧绠�") + .or() + .like(InsProduct::getInspectionItemSubclass,"鏉惧绠�")) + ); + List<Integer> collectByBush = insProductsByBush.stream() + .map(InsProduct::getInsResult) + .filter(sm -> ObjectUtils.isNotEmpty(sm) && sm != 2).collect(Collectors.toList()); + //1锛氬凡妫�楠岋紝0锛氭湭妫�楠�,2:鍦ㄦ + int bushState = 0; + if(insProductsByBush.size() == collectByBush.size()){ + bushState = 1; + }else if(!collectByBush.isEmpty() && collectByBush.size()<insProductsByBush.size()){ + bushState = 2; + } + insBushing.setState(bushState); + if(!insProductsByBush.isEmpty()){ + bush.add(insBushing); + } + //鍐嶆煡璇㈠嚭鎵�鏈夌殑鍏夌氦甯� + List<InsFibers> insFibers = insFibersMapper.selectList(Wrappers.<InsFibers>lambdaQuery().eq(InsFibers::getInsBushingId, insBushing.getId())); + + List<InsFiber> insFiberList = insFiberMapper.selectList(Wrappers.<InsFiber>lambdaQuery().eq(InsFiber::getInsBushingId, insBushing.getId())); + if (CollectionUtils.isNotEmpty(insFibers)) { + for (InsFibers insFiberS : insFibers) { + //鏌ヨ鍏夌氦甯︿笅鐨勫厜绾ら厤缃� + List<InsFiber> fiberList = insFiberMapper.selectList(Wrappers.<InsFiber>lambdaQuery().eq(InsFiber::getInsFibersId, insFiberS.getId())); + if(fiberList.isEmpty()){ + List<InsProduct> insProducts = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery() + .eq(InsProduct::getState,1) + .eq(InsProduct::getSonLaboratory,sonLaboratory) + .eq(InsProduct::getInsFibersId, insFiberS.getId())); + // 杩囨护鍏夌氦鎺ュご鎹熻�� + if(CollectionUtils.isNotEmpty(insProducts)) { + insProducts = insProducts.stream().filter(item -> !item.getInspectionItem().equals("鍏夌氦鎺ュご鎹熻��")).collect(Collectors.toList()); + } + //璁剧疆濂楃鐨勬楠岀姸鎬� + insFiberS.setState(getInsState(insProducts)); + InsFibersVO insFibersVO = new InsFibersVO(); + BeanUtil.copyProperties(insFiberS,insFibersVO); + insFibersVO.setIsExistProduct(!insProducts.isEmpty());//鏄惁瀛樺湪妫�楠岄」 + insFibersVO.setBushingColor(insBushing.getColor()); + //濡傛灉鍏夌氦甯︿笅鐨勯」鐩病鏈夊厜绾ゆ帴澶存崯鑰楅」鐩紝鎵嶆坊鍔犲厜绾ゅ甫淇℃伅 + if(CollectionUtils.isNotEmpty(insProducts)) { + fibers.add(insFibersVO); + } + }else{ + InsFibersVO insFibersVO = new InsFibersVO(); + BeanUtil.copyProperties(insFiberS,insFibersVO); + insFibersVO.setBushingColor(insBushing.getColor()); + //鏌ヨ鍏夌氦甯︿笅鐨勬楠岄」 + List<InsProduct> fibersProducts = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery() + .eq(InsProduct::getState,1) + .eq(InsProduct::getSonLaboratory,sonLaboratory) + .eq(InsProduct::getInsFibersId, insFiberS.getId())); + insFibersVO.setIsExistProduct(!fibersProducts.isEmpty());//鏄惁瀛樺湪妫�楠岄」 + if(!fibersProducts.isEmpty()){ + //璁剧疆鍏夌氦甯﹁壊鏍囩殑妫�楠岀姸鎬� + insFibersVO.setState(getInsState(fibersProducts)); + } + //娣诲姞鍏夌氦甯︿俊鎭� + fibers.add(insFibersVO); + for (InsFiber insFiber : fiberList) { + List<InsProduct> insProducts = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery() + .eq(InsProduct::getState,1) + .eq(InsProduct::getSonLaboratory,sonLaboratory) + .eq(InsProduct::getInsFiberId, insFiber.getId())); + // 杩囨护鍏夌氦鎺ュご鎹熻�� + if(CollectionUtils.isNotEmpty(insProducts)) { + insProducts = insProducts.stream().filter(item -> !item.getInspectionItem().equals("鍏夌氦鎺ュご鎹熻��")).collect(Collectors.toList()); + } + //璁剧疆鍏夌氦鑹叉爣鐨勬楠岀姸鎬� + insFiber.setState(getInsState(insProducts)); + //濡傛灉鍏夌氦涓嬬殑椤圭洰娌℃湁鍏夌氦鎺ュご鎹熻�楅」鐩紝鎵嶆坊鍔犲厜绾や俊鎭� + if(CollectionUtils.isNotEmpty(insProducts)) { + fiber.add(insFiber); + } + } + } + } + } + //濡傛灉濂楃涓嬫病鏈夊厜绾ゅ甫灏卞彧鏈夊厜绾や簡 + else if (CollectionUtils.isNotEmpty(insFiberList)) { + for (InsFiber insFiber : insFiberList) { + List<InsProduct> insProducts = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery() + .eq(InsProduct::getState,1) + .eq(InsProduct::getSonLaboratory,sonLaboratory) + .eq(InsProduct::getInsFiberId, insFiber.getId())); + // 杩囨护鍏夌氦鎺ュご鎹熻�� + if(CollectionUtils.isNotEmpty(insProducts)) { + insProducts = insProducts.stream().filter(item -> !item.getInspectionItem().equals("鍏夌氦鎺ュご鎹熻��")).collect(Collectors.toList()); + } + //璁剧疆鍏夌氦鑹叉爣鐨勬楠岀姸鎬� + insFiber.setState(getInsState(insProducts)); + if(CollectionUtils.isNotEmpty(insProducts)){ + fiber.add(insFiber); + } + } + } + } + map.put("鍏夌氦甯�", fibers); + map.put("鍏夌氦", fiber); + map.put("濂楃", bush); + return map; + } + + /** + * 鍒ゆ柇妫�楠岄」鏄惁妫�娴嬪畬锛岃繑鍥炴娴嬬姸鎬� + * @param insProducts + * @return + */ + private Integer getInsState(List<InsProduct> insProducts){ + List<Integer> collect = insProducts.stream().map(InsProduct::getInsResult) + .filter(sm -> ObjectUtils.isNotEmpty(sm) && sm != 2).collect(Collectors.toList()); + if (insProducts.size() == collect.size()) { + return 1;//宸叉楠� + } else if(!collect.isEmpty() && collect.size()<insProducts.size()){ + return 2;//鍦ㄦ楠� + } + return 0;//鏈楠� + } + + //娓╁害寰幆鏌ョ湅鍒楄〃鏁版嵁(鍖呮嫭閫氳繃鏍峰搧id,寰幆娆℃暟,娓╁害,寰幆娆℃暟杩涜绛涢��) + @Override + public Map<String, Object> temCycle(Integer sampleId, String inspectionItem, String inspectionItemSubclass) { + Map<String, Object> map = new HashMap<>(); + //鏍峰搧淇℃伅 + SampleVo sampleVo = insSampleMapper.getDetailById(sampleId); + map.put("sampleVo", sampleVo); + List<ProductVo> productVos = new ArrayList<>(); + //鍏堟煡鍑鸿繖涓牱鍝佷笅鏈夊摢浜涚鑹叉爣,鍏夌氦甯�,鍏夌氦鑹叉爣 + //鍏堟煡鍑哄绠� + List<InsBushing> insBushings = insBushingMapper.selectList(Wrappers.<InsBushing>lambdaQuery().eq(InsBushing::getInsSampleId, sampleId)); + if (insBushings.size() > 0) { + //閫氫俊--娓╁害寰幆 + for (InsBushing insBushing : insBushings) { + //鍐嶆煡璇㈠嚭鎵�鏈夌殑鍏夌氦甯� + List<InsFibers> insFibers = insFibersMapper.selectList(Wrappers.<InsFibers>lambdaQuery().eq(InsFibers::getInsBushingId, insBushing.getId())); + if (CollectionUtils.isNotEmpty(insFibers)) { + for (InsFibers insFiber : insFibers) { + //鏌ュ嚭鍏夌氦甯︿笅鎵�鏈夌殑鍏夌氦 + List<InsFiber> fiberList = insFiberMapper.selectList(Wrappers.<InsFiber>lambdaQuery().eq(InsFiber::getInsFibersId, insFiber.getId())); + for (InsFiber fiber : fiberList) { + //鍐嶆牴鎹叧鑱旂殑鍏夌氦閰嶇疆鐨刬d鍜屽惊鐜鏁板拰娓╁害鍜屾牱鍝乮d杩涜鏌ヨ妫�楠岄」鐩� + List<InsProduct> insProducts = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery() + .eq(InsProduct::getInsSampleId, sampleId) + .eq(InsProduct::getInspectionItem, inspectionItem) + .eq(InsProduct::getInspectionItemSubclass, inspectionItemSubclass) + .eq(InsProduct::getInsFiberId, fiber.getId())); + for (InsProduct insProduct : insProducts) { + InsProductResult insProductResult = insProductResultMapper.selectOne(Wrappers.<InsProductResult>lambdaQuery() + .eq(InsProductResult::getInsProductId, insProduct.getId())); + ProductVo productVo = new ProductVo(); + productVo.setCode(insFiber.getCode()); + productVo.setColor(fiber.getColor()); + productVo.setBushColor(insBushing.getColor()); + if (ObjectUtils.isNotEmpty(insProductResult)) { + insProduct.setInsProductResult(insProductResult); + } + //姹傚悓绛夋潯浠朵笅1娆″惊鐜�20搴﹀父娓╃殑璁$畻鍊� + InsProductResult insProductResult1 = insProductResultMapper.selectOne(Wrappers.<InsProductResult>lambdaQuery().eq(InsProductResult::getInsProductId, insProductMapper.selectOne(Wrappers.<InsProduct>lambdaQuery() + .eq(InsProduct::getInsSampleId, sampleId) + .eq(InsProduct::getInspectionItem, "1") + .eq(InsProduct::getInspectionItemSubclass, "20鈩�(甯告俯)") + .eq(InsProduct::getInspectionItemClass, insProduct.getInspectionItemClass()) + .eq(InsProduct::getInsFiberId, fiber.getId())).getId())); + if (ObjectUtils.isNotEmpty(insProductResult1) && !insProductResult1.getComValue().equals("[]")) { + String[] splitStr = insProductResult1.getComValue().split(":"); + insProduct.setComplue(splitStr[splitStr.length-1].split("\"")[1]); + } + productVo.setInsProduct(insProduct); + productVos.add(productVo); + } + } + } + } else { + //濡傛灉濂楃涓嬫病鏈夊厜绾ゅ甫灏卞彧鏈夊厜绾や簡 + List<InsFiber> insFiberList = insFiberMapper.selectList(Wrappers.<InsFiber>lambdaQuery().eq(InsFiber::getInsBushingId, insBushing.getId())); + for (InsFiber fiber : insFiberList) { + //鍐嶆牴鎹叧鑱旂殑鍏夌氦閰嶇疆鐨刬d鍜屽惊鐜鏁板拰娓╁害鍜屾牱鍝乮d杩涜鏌ヨ妫�楠岄」鐩� + List<InsProduct> insProducts = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery() + .eq(InsProduct::getInsSampleId, sampleId) + .eq(InsProduct::getInspectionItem, inspectionItem) + .eq(InsProduct::getInspectionItemSubclass, inspectionItemSubclass) + .eq(InsProduct::getInsFiberId, fiber.getId())); + for (InsProduct insProduct : insProducts) { + InsProductResult insProductResult = insProductResultMapper.selectOne(Wrappers.<InsProductResult>lambdaQuery().eq(InsProductResult::getInsProductId, insProduct.getId())); + ProductVo productVo = new ProductVo(); + productVo.setCode("-"); + productVo.setColor(fiber.getColor()); + productVo.setBushColor(fiber.getBushColor()); + insProduct.setInsProductResult(insProductResult); + //姹傚悓绛夋潯浠朵笅1娆″惊鐜�20搴﹀父娓╃殑璁$畻鍊� + InsProductResult insProductResult1 = insProductResultMapper.selectOne(Wrappers.<InsProductResult>lambdaQuery().eq(InsProductResult::getInsProductId, insProductMapper.selectOne(Wrappers.<InsProduct>lambdaQuery() + .eq(InsProduct::getInsSampleId, sampleId) + .eq(InsProduct::getInspectionItem, "1") + .eq(InsProduct::getInspectionItemSubclass, "20鈩�(甯告俯)") + .eq(InsProduct::getInspectionItemClass, insProduct.getInspectionItemClass()) + .eq(InsProduct::getInsFiberId, fiber.getId())).getId())); + if (ObjectUtils.isNotEmpty(insProductResult1) && !insProductResult1.getComValue().equals("[]")) { + String[] splitStr = insProductResult1.getComValue().split(":"); + insProduct.setComplue(splitStr[splitStr.length-1].split("\"")[1]); + } + productVo.setInsProduct(insProduct); + productVos.add(productVo); + } + } + } + } + productVos = productVos.stream().sorted(Comparator.comparing(productVo -> productVo.getInsProduct().getInspectionItemClass())).collect(Collectors.toList()); + } else { + //鐢靛姏--鐑惊鐜拰娓╁崌璇曢獙 + List<InsProduct> insProducts = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery() + .eq(InsProduct::getInsSampleId, sampleId) + .eq(InsProduct::getInspectionItem, inspectionItem)); + for (InsProduct insProduct : insProducts) { + InsProductResult insProductResult = insProductResultMapper.selectOne(Wrappers.<InsProductResult>lambdaQuery().eq(InsProductResult::getInsProductId, insProduct.getId())); + ProductVo productVo = new ProductVo(); + if (ObjectUtils.isNotEmpty(insProductResult)) { + insProduct.setInsProductResult(insProductResult); + } + productVo.setInsProduct(insProduct); + productVos.add(productVo); + } + } + map.put("productVos", productVos); + return map; + } + + @Override + public List<String> upPlanUser2(Integer orderId) { + List<Integer> sampleId = insSampleMapper.selectList(Wrappers.<InsSample>lambdaQuery().eq(InsSample::getInsOrderId, orderId)).stream().map(InsSample::getId).collect(Collectors.toList()); + List<String> sonLaboratory = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery().eq(InsProduct::getState, 1).in(InsProduct::getInsSampleId, sampleId)).stream().map(InsProduct::getSonLaboratory).distinct().collect(Collectors.toList()); + return sonLaboratory; + } + + @Override + public Map<String, Object> getSagTemperatureProducts(Integer sampleId) { + Map<String, Object> map = new HashMap<>(); + //鏍峰搧淇℃伅 + SampleVo sampleVo = insSampleMapper.getDetailById(sampleId); + map.put("sampleVo", sampleVo); + //鐢靛姏:寮у瀭-娓╁害鐗规畩椤� + List<ProductVo> productVos = new ArrayList<>(); + List<InsProduct> insProducts = insProductMapper.findSagTemperatureProducts(sampleId,"寮у瀭-娓╁害"); + for (InsProduct insProduct : insProducts) { + InsProductResult insProductResult = insProductResultMapper.selectOne(Wrappers.<InsProductResult>lambdaQuery().eq(InsProductResult::getInsProductId, insProduct.getId())); + ProductVo productVo = new ProductVo(); + if (ObjectUtils.isNotEmpty(insProductResult)) { + insProduct.setInsProductResult(insProductResult); + } + productVo.setInsProduct(insProduct); + productVos.add(productVo); + } + map.put("productVos", productVos); + return map; + } + + @Override + public Map<String, Object> getSampleInfoByOrderId(Integer orderId,String sonLaboratory) { + Map<String, Object> map = new HashMap<>(); + if(!Objects.isNull(orderId)){ + //妫�楠屽唴瀹瑰璞� + List<InsProductVO> insProductVOS = insProductMapper.selectProductByOrderId(orderId,sonLaboratory); + //鏍规嵁鏍峰搧id鍒嗙粍 + Map<Integer, List<InsProductVO>> groupMap = insProductVOS.stream().collect(Collectors.groupingBy(InsProductVO::getSampleId)); + List<InsProductVO> sampleList = new ArrayList<>(); + for (Integer key : groupMap.keySet()) { + AtomicInteger insSum = new AtomicInteger(0); + List<String> inspectNameList = new ArrayList<>(); + InsProductVO insProductVO = new InsProductVO(); + groupMap.get(key).forEach(k->{ + if(StringUtils.isNotBlank(k.getInspectName())){ + insSum.getAndIncrement(); + inspectNameList.add(k.getInspectName()); + } + insProductVO.setId(k.getSampleId()); + insProductVO.setSampleCode(k.getSampleCode()); + }); + if(CollectionUtils.isEmpty(inspectNameList)){ + insProductVO.setState(0); + }else if(inspectNameList.size() < groupMap.get(key).size()){ + insProductVO.setState(1); + }else if(inspectNameList.size() == groupMap.get(key).size()){ + insProductVO.setState(2); + } + insProductVO.setInspectName(inspectNameList.stream().distinct().collect(Collectors.joining(","))); + sampleList.add(insProductVO); + } + map.put("insSamples",sampleList); + map.put("insProductVOS",insProductVOS); + } + return map; + } + + @Override + @Transactional(rollbackFor = Exception.class,isolation = Isolation.READ_COMMITTED) + public void saveInsContext(Map<String, Object> insContext, Integer currentTable, Integer currentSampleId, Integer orderId, String sonLaboratory, Boolean isDelete) { + try{ + if(lock.tryLock(10,TimeUnit.SECONDS)){ + Integer userId = SecurityUtils.getUserId().intValue(); + insContext.forEach((k, v) -> { + JSONObject jo = JSON.parseObject(JSON.toJSONString(v)); + InsProduct insProduct = new InsProduct(); + insProduct.setId(Integer.parseInt(k)); + InsProduct product = insProductMapper.selectById(insProduct.getId()); + if (currentTable.equals(product.getTemplateId()) && currentSampleId.equals(product.getInsSampleId())) { + List<InsProductResult> oldResults = insProductResultMapper.selectList(Wrappers.<InsProductResult>lambdaQuery() + .eq(InsProductResult::getInsProductId, insProduct.getId())); + + InsProductResult newResult = new InsProductResult(); + if (CollectionUtils.isNotEmpty(oldResults)) { + BeanUtil.copyProperties(oldResults.get(0), newResult); + } + newResult.setInsProductId(Integer.parseInt(k)); + /*鏍¢獙涓�涓媟esult琛�*/ + if (oldResults.size() > 1) { + for (int i = 1; i < oldResults.size(); i++) { + insProductResultMapper.deleteById(oldResults.get(i)); + } + } + // 淇濆瓨鐨勬暟鎹皬鏁颁綅鏁板繀椤诲ぇ浜庣瓑浜巘ell鏈�澶х殑灏忔暟浣嶆暟 + String tells = product.getTell(); + Integer digit = null; + if(StringUtils.isEmpty(tells)) { + digit = -1; + }else { + // 鎵惧埌灏忔暟浣嶆暟鏈�澶氱殑鏁板�� + Map<String, Object> stringObjectMap = maxDecimalNumber(tells); + digit = Integer.parseInt(stringObjectMap.get("maxNumber").toString()); + } + if (!Arrays.asList("搴斿姏搴斿彉","鎸姩鐤插姵").contains(product.getInspectionItem())) { + //妫�楠屽�� + if (jo.get("insValue") != null) { + JSONArray jsonArray = JSON.parseArray(JSON.toJSONString(jo.get("insValue"))); + List<Map<String, Object>> iv = new ArrayList<>(); + for (Object o : jsonArray) { + JSONObject insValue = JSON.parseObject(JSON.toJSONString(o)); + Map<String, Object> map = new HashMap<>(); + String val = ""; + if(Objects.nonNull(JSON.parseObject(JSON.toJSONString(insValue.get("v"))).get("v"))){ + val = JSON.parseObject(JSON.toJSONString(insValue.get("v"))).get("v").toString(); + } + // 濡傛灉鍙互杞崲涓烘暟瀛楋紝灏辫杩涜浣嶆暟鐨勬瘮杈� + map.put("v", completion(val, digit)); + map.put("r", JSON.toJSONString(insValue.get("r"))); + map.put("c", JSON.toJSONString(insValue.get("c"))); + map.put("w", insValue.get("w")); + try { + if ((insValue.get("u") == null || insValue.get("u").equals("")) && StrUtil.isNotEmpty(val)) { + map.put("u", userId + ""); + } else { + map.put("u", insValue.get("u")); + } + iv.add(map); + } catch (Exception e) { + } + } + newResult.setInsValue(JSON.toJSONString(iv)); + } + } + if (!Arrays.asList("搴斿姏搴斿彉","鎸姩鐤插姵").contains(product.getInspectionItem())) { + //璁$畻鍊� + if (jo.get("comValue") != null && !Objects.equals(jo.get("comValue"), "")) { + JSONArray jsonArray2 = JSON.parseArray(JSON.toJSONString(jo.get("comValue"))); + List<Map<String, Object>> cv = new ArrayList<>(); + for (Object o : jsonArray2) { + JSONObject comValue = JSON.parseObject(JSON.toJSONString(o)); + Map<String, Object> map = new HashMap<>(); + map.put("r", JSON.toJSONString(comValue.get("r"))); + map.put("c", JSON.toJSONString(comValue.get("c"))); + // 濡傛灉鍙互杞崲涓烘暟瀛楋紝灏辫杩涜浣嶆暟鐨勬瘮杈� + map.put("v", completion(JSON.parseObject(JSON.toJSONString(comValue.get("v"))).get("v").toString(), digit)); + cv.add(map); + } + newResult.setComValue(JSON.toJSONString(cv)); + } + } + //鏈�缁堝�� + try { + JSONObject resValue = JSON.parseObject(JSON.toJSONString(jo.get("resValue"))); + if (resValue.get("v") != null) { + Object o = JSON.parseObject(JSON.toJSONString(resValue.get("v"))).get("v"); + // 濡傛灉鍙互杞崲涓烘暟瀛楋紝灏辫杩涜浣嶆暟鐨勬瘮杈� + insProduct.setLastValue(completion(o.equals("") ? null : (o.toString()), digit)); + } + } catch (Exception e) { + insProduct.setLastValue("");//'' + } + //璁惧缂栧彿 + if (jo.get("equipValue") != null) { + JSONArray jsonArray2 = JSON.parseArray(JSON.toJSONString(jo.get("equipValue"))); + List<Map<String, Object>> ev = new ArrayList<>(); + for (Object o : jsonArray2) { + JSONObject equipValue = JSON.parseObject(JSON.toJSONString(o)); + Map<String, Object> map = new HashMap<>(); + map.put("v", JSON.parseObject(JSON.toJSONString(equipValue.get("v"))).get("v")); + ev.add(map); + } + newResult.setEquipValue(JSON.toJSONString(ev)); + } + //璁惧鍚嶇О + if (jo.get("equipName") != null) { + JSONArray jsonArray2 = JSON.parseArray(JSON.toJSONString(jo.get("equipName"))); + List<Map<String, Object>> ev = new ArrayList<>(); + for (Object o : jsonArray2) { + JSONObject equipValue = JSON.parseObject(JSON.toJSONString(o)); + Map<String, Object> map = new HashMap<>(); + map.put("v", JSON.parseObject(JSON.toJSONString(equipValue.get("v"))).get("v")); + ev.add(map); + } + newResult.setEquipName(JSON.toJSONString(ev)); + } + //缁撹 + try { + JSONObject insResult = JSON.parseObject(JSON.toJSONString(jo.get("insResult"))); + String ir = JSON.parseObject(JSON.toJSONString(insResult.get("v"))).get("v") + ""; + insProduct.setInsResult(Integer.parseInt(ir)); + if (product.getInspectionItem().equals("鐑惊鐜�") || product.getInspectionItem().equals("娓╁崌璇曢獙")) { + List<Integer> collect = insProductMapper.selectList(new LambdaQueryWrapper<InsProduct>() + .eq(InsProduct::getSpecialItemParentId, product.getId())).stream() + .map(InsProduct::getInsResult) + .collect(Collectors.toList()); + if (collect.contains(null)) { + insProduct.setInsResult(2); + } else if (collect.contains(0)) { + insProduct.setInsResult(0); + } else { + insProduct.setInsResult(1); + } + + } + } catch (Exception e) { + insProduct.setInsResult(2);//寰呭畾 + if (product.getInspectionItem().equals("搴斿姏搴斿彉") && product.getInspectionItemSubclass().equals("寮规�фā閲�") + && Arrays.asList("/", "-").contains(product.getAsk())) { + insProduct.setInsResult(3);// 涓嶅垽瀹� + } + // 濡傛灉鏄姬鍨傜殑缁撹涔熸敼涓轰笉鍒ゅ畾 + if(product.getInspectionItem().equals("寮у瀭-娓╁害")) { + insProduct.setInsResult(3);// 涓嶅垽瀹� + } + } + if (Objects.isNull(newResult.getId())) { + newResult.setCreateUser(userId); + newResult.setUpdateUser(userId); + insProductResultMapper.insert(newResult); + } else { + newResult.setUpdateUser(userId); + newResult.setUpdateTime(LocalDateTime.now()); + insProductResultMapper.updateById(newResult); + } + /*濡傛灉鏄涓�娆¢�夋嫨璁惧淇℃伅,涓旇繕鏈夊叾浣欐牱鍝佷篃鏈夊悓涓�涓楠岄」鐩�,閭d箞鎵�鏈夋牱鍝佺殑璇ラ」鐩兘鐢ㄨ繖涓澶囦俊鎭�*/ + //鍏堟煡璇㈡槸鍚﹁繕鏈夊叾浣欐牱鍝� + Integer insSampleId = product.getInsSampleId(); + List<InsSample> insSamples = insSampleMapper.selectList(Wrappers.<InsSample>lambdaQuery().eq(InsSample::getInsOrderId, insSampleMapper.selectById(insSampleId).getInsOrderId())); + //濡傛灉鏈夊涓牱鍝佹垨鑰呮槸涓嶆槸閲囬泦绫诲瀷灏卞悓涓�涓澶� + if (insSamples.size() > 1 && !product.getInspectionItemType().equals("1")) { + //瀛樺湪鍏朵綑鏍峰搧,鏌ヨ鏄惁鏈夊悓涓�绉嶆楠岄」鐩� + for (InsSample sample : insSamples.stream().filter(insSample -> !insSample.getId().equals(insSampleId)).collect(Collectors.toList())) { + InsProduct product1 = insProductMapper.selectOne(Wrappers.<InsProduct>lambdaQuery() + .eq(InsProduct::getState, 1) + .eq(InsProduct::getInsSampleId, sample.getId()) + .eq(InsProduct::getInspectionItem, product.getInspectionItem()) + .eq(InsProduct::getInspectionItemEn, product.getInspectionItemEn()) + .eq(InsProduct::getInspectionItemSubclass, product.getInspectionItemSubclass()) + .eq(InsProduct::getInspectionItemSubclassEn, product.getInspectionItemSubclassEn()) + .eq(InsProduct::getTemplateId, product.getTemplateId()) + .eq(InsProduct::getStandardMethodListId, product.getStandardMethodListId()) + .eq(InsProduct::getInsBushId, product.getInsBushId()) + .eq(InsProduct::getInsFibersId, product.getInsFibersId()) + .eq(InsProduct::getInsFiberId, product.getInsFiberId()) + ); + if (ObjectUtils.isNotEmpty(product1)) { + //濡傛灉瀛樺湪椤圭洰,鏌ヨ鏄惁鏈夎〃 + InsProductResult productResult = insProductResultMapper.selectOne(Wrappers.<InsProductResult>lambdaQuery() + .eq(InsProductResult::getInsProductId, product1.getId())); + if (ObjectUtils.isEmpty(productResult)) { + //娌℃湁琛ㄦ柊寤鸿〃 + productResult = new InsProductResult(); + productResult.setInsProductId(product1.getId()); + productResult.setEquipValue(newResult.getEquipValue()); + productResult.setEquipName(newResult.getEquipValue()); + productResult.setCreateUser(userId); + productResult.setUpdateUser(userId); + insProductResultMapper.insert(productResult); + } else if (ObjectUtils.isEmpty(productResult.getEquipValue())) { + //鏈夎〃鍒ゆ柇鏄惁鏈夎澶� + productResult.setEquipValue(newResult.getEquipValue()); + productResult.setEquipName(newResult.getEquipValue()); + productResult.setUpdateUser(userId); + productResult.setUpdateTime(LocalDateTime.now()); + insProductResultMapper.updateById(productResult); + } + } + } + + } + insProduct.setUpdateUser(userId); + insProductMapper.updateById(insProduct); + // 褰撳墠鏍峰搧鏄惁鏄厜绾ら厤缃殑鍏夌氦鎺ュご鎹熻�� + if ((!Objects.isNull(product.getInsFiberId()) || !Objects.isNull(product.getInsFibersId())) && product.getInspectionItem().equals("鍏夌氦鎺ュご鎹熻��")) { + // 鏌ユ壘鍚屾牱鍝佷笅鐨勫厜绾ゆ垨鍏夌氦甯︾殑鍏夌氦鎺ュご鎹熻�� + List<InsProduct> insProducts = insProductMapper.selectList(new LambdaQueryWrapper<InsProduct>() + .eq(InsProduct::getInsSampleId, product.getInsSampleId()) + .eq(InsProduct::getInspectionItem, product.getInspectionItem()) + .eq(InsProduct::getInspectionItemSubclass, product.getInspectionItemSubclass()) + .and(item -> item + .isNotNull(InsProduct::getInsFiberId) + .or() + .isNotNull(InsProduct::getInsFibersId))); + // 瑕佸鍒剁殑result + InsProductResult copyResult = insProductResultMapper.selectOne(new LambdaQueryWrapper<InsProductResult>() + .eq(InsProductResult::getInsProductId, product.getId())); + + for (InsProduct insProduct1 : insProducts) { + InsProduct copyInsProduct = insProductMapper.selectById(product.getId()); // 澶嶅埗鐨刬nsProduct + if (!insProduct1.getId().equals(copyInsProduct.getId())) { + copyInsProduct.setId(insProduct1.getId()); // 灏嗗鍒剁殑insProduct鐨刬d璁剧疆涓鸿澶嶅埗鐨刬d + copyInsProduct.setInsFibersId(insProduct1.getInsFibersId()); // 鍏夌氦甯d + copyInsProduct.setInsFiberId(insProduct1.getInsFiberId()); // 鍏夌氦id + copyInsProduct.setInsBushId(insProduct1.getInsBushId()); // 濂楃id + insProductMapper.updateById(copyInsProduct); + // 璧嬪�糹nsProductResult + InsProductResult insProductResult = insProductResultMapper.selectOne(new LambdaQueryWrapper<InsProductResult>() + .eq(InsProductResult::getInsProductId, insProduct1.getId())); + if (Objects.isNull(insProductResult)) { + copyResult.setId(null); + copyResult.setInsProductId(insProduct1.getId()); + insProductResultMapper.insert(copyResult); + } else { + copyResult.setId(insProductResult.getId()); + copyResult.setInsProductId(insProduct1.getId()); + insProductResultMapper.updateById(copyResult); + } + } + } + } + insProductUserMapper.insert(new InsProductUser(null, userId, LocalDateTime.now(), insProduct.getId())); + + insProduct = insProductMapper.selectById(insProduct); + //鏌ヨ妫�楠屽崟淇℃伅 + InsSample insSample = insSampleMapper.selectById(insProduct.getInsSampleId()); + InsOrder insOrder = insOrderMapper.selectById(insSample.getInsOrderId()); + //鏌ヨ鐖舵楠岄」 + InsProduct parentInsProduct; + if (ObjectUtil.isNotNull(insProduct.getSpecialItemParentId())) { + parentInsProduct = insProductMapper.selectById(insProduct.getSpecialItemParentId()); + } else { + parentInsProduct = null; + } + if (!Objects.isNull(parentInsProduct)) { + if ("娓╁崌璇曢獙".equals(parentInsProduct.getInspectionItem()) || "鐑惊鐜�".equals(parentInsProduct.getInspectionItem())) { + // 娓╁崌璇曢獙浠ュ強鐑惊鐜殑鍒犻櫎 + if (isDelete) { + String inspectionItem = insProduct.getInspectionItem(); + List<InsProduct> insProducts = insProductMapper.selectList(new LambdaQueryWrapper<InsProduct>() + .eq(InsProduct::getSpecialItemParentId, parentInsProduct.getId())) + .stream() + .filter(item -> item.getInspectionItem().equals(inspectionItem)).collect(Collectors.toList()); + for (InsProduct insProduct1 : insProducts) { + InsProductResult insProductResult = insProductResultMapper.selectOne(new LambdaQueryWrapper<InsProductResult>() + .eq(InsProductResult::getInsProductId, insProduct1.getId())); + if (!Objects.isNull(insProductResult)) { + if (insProductResult.getInsProductId().equals(Integer.parseInt(k))) { + continue; + } + String insValue = insProductResult.getInsValue(); + List<Map> maps = com.alibaba.fastjson2.JSON.parseArray(insValue, Map.class); + if (maps.size() > 1) { + maps.remove(maps.size() - 1); + insProductResult.setInsValue(com.alibaba.fastjson2.JSON.toJSONString(maps)); + insProductResultMapper.updateById(insProductResult); + } + } + } + } + // 娓╁崌璇曢獙浠ュ強鐑惊鐜煡璇� + // 鐑惊鐜墍鏈夊瓙椤� + List<InsProduct> c = insProductMapper.selectList(new LambdaQueryWrapper<InsProduct>() + .eq(InsProduct::getSpecialItemParentId, parentInsProduct.getId())); + //閫氳繃inspectionItem鍒嗙粍 + Map<String, List<InsProduct>> collect1 = c.stream().collect(Collectors.groupingBy(InsProduct::getInspectionItem)); + HashMap<Integer, InsProductResult> map1 = new HashMap<>(); + Integer maxKey = Integer.MIN_VALUE; + for (Map.Entry<String, List<InsProduct>> m : collect1.entrySet()) { + List<InsProduct> thermalCycleCollect = m.getValue(); + if (!thermalCycleCollect.isEmpty()) { + for (InsProduct product1 : thermalCycleCollect) { + InsProductResult insProductResult = insProductResultMapper.selectOne(Wrappers.<InsProductResult>lambdaQuery() + .eq(InsProductResult::getInsProductId, product1.getId())); + if (!Objects.isNull(insProductResult)) { + List<Map> maps = com.alibaba.fastjson2.JSON.parseArray(insProductResult.getInsValue(), Map.class); + map1.put(maps.size(), insProductResult); + } + if (!map1.isEmpty()) { + for (Map.Entry<Integer, InsProductResult> entry : map1.entrySet()) { + if (entry.getKey() > maxKey) { + maxKey = entry.getKey(); + } + } + } + } + if (maxKey != Integer.MIN_VALUE) { + InsProductResult insProductResult = map1.get(maxKey); + List<Map> maps = com.alibaba.fastjson2.JSON.parseArray(insProductResult.getInsValue(), Map.class); + maps.get(maps.size() - 1).put("v", "");//鏈�鍚庝竴涓�间负绌� + if (maps.get(maps.size() - 1).containsKey("w")) { + maps.get(maps.size() - 1).put("w", ""); + } + for (InsProduct product1 : thermalCycleCollect) { + InsProductResult insProductResult1 = insProductResultMapper.selectOne(Wrappers.<InsProductResult>lambdaQuery() + .eq(InsProductResult::getInsProductId, product1.getId())); + if (!Objects.isNull(insProductResult1)) { + if (!insProductResult1.getInsProductId().equals(insProductResult.getInsProductId())) { + List<Map> maps1 = com.alibaba.fastjson2.JSON.parseArray(insProductResult1.getInsValue(), Map.class); + if (maps1.size() < maxKey) { + int number = maxKey - maps1.size(); + for (int i = 0; i < number; i++) { + maps1.add(maps.get(maps.size() - 1)); + } + insProductResult1.setInsValue(com.alibaba.fastjson2.JSON.toJSONString(maps1)); + insProductResultMapper.updateById(insProductResult1); + } + } + } else { + if (maxKey != Integer.MIN_VALUE) { + InsProductResult insProductResult2 = map1.get(maxKey); + List<Map> maps1 = com.alibaba.fastjson2.JSON.parseArray(insProductResult2.getInsValue(), Map.class); + for (Map map : maps1) { + map.put("v", ""); + if (map.containsKey("w")) { + map.put("w", ""); + } + } + insProductResult2.setInsValue(com.alibaba.fastjson2.JSON.toJSONString(maps1)); + insProductResult2.setId(null); + insProductResult2.setInsProductId(product1.getId()); + insProductResultMapper.insert(insProductResult2); + } + } + } + maxKey = Integer.MIN_VALUE; + map1.clear(); + } + } + } + // 濡傛灉鏄绾挎俯搴︾殑鍊兼洿鏂帮紝閭d箞灏辫鍒ゆ柇鑰愬紶鍜屾帴缁槸鍚﹀悎鏍� + InsProduct insProduct1 = insProductMapper.selectById(Integer.parseInt(k)); + if (insProduct1.getInspectionItemSubclass().equals("瀵肩嚎娓╁害")) { + // 鏍规嵁鐖秈d浠ュ強妫�楠岄」鏉ユ煡鎵惧悓涓�寰幆涓嬬殑鑰愬紶鍜屾帴缁� + List<InsProduct> insProducts2 = insProductMapper.selectList(new LambdaQueryWrapper<InsProduct>() + .eq(InsProduct::getSpecialItemParentId, parentInsProduct.getId()) + .eq(InsProduct::getInspectionItem, insProduct1.getInspectionItem())); + List<Double> wire = new ArrayList<>(); // 瀵肩嚎娓╁害鐨勫�� + List<Double> strain = new ArrayList<>(); // 鑰愬紶鐨勫�� + List<Double> joint = new ArrayList<>(); // 鎺ョ画鐨勫�� + + boolean strainFlag = true; // 鑰愬紶鏄惁鍚堟牸 + boolean jointFlag = true; // 鎺ョ画鏄惁鍚堟牸 + boolean strainPending = false; // 鏄惁鏈夊緟瀹� + boolean jointPending = false; // 鏄惁鏈夊緟瀹� + for (InsProduct insProduct2 : insProducts2) { + if (insProduct2.getInspectionItemSubclass().equals("瀵肩嚎娓╁害")) { + String insValue = ""; + InsProductResult insProductResult = insProductResultMapper.selectOne(new LambdaQueryWrapper<InsProductResult>() + .eq(InsProductResult::getInsProductId, insProduct2.getId())); + if (!Objects.isNull(insProductResult)) { + insValue = insProductResult.getInsValue(); + List<Map> maps = com.alibaba.fastjson2.JSON.parseArray(insValue, Map.class); + if (maps.size() > 0) { + for (Map map : maps) { + if (Strings.isNotEmpty(map.get("v").toString())) { + wire.add(Double.parseDouble(map.get("v").toString())); + } else { + wire.add(-1.0); + } + } + } + } + } + if (insProduct2.getInspectionItemSubclass().equals("鑰愬紶娓╁害")) { + String insValue = ""; + InsProductResult insProductResult = insProductResultMapper.selectOne(new LambdaQueryWrapper<InsProductResult>() + .eq(InsProductResult::getInsProductId, insProduct2.getId())); + if (!Objects.isNull(insProductResult)) { + insValue = insProductResult.getInsValue(); + List<Map> maps = com.alibaba.fastjson2.JSON.parseArray(insValue, Map.class); + if (maps.size() > 0) { + for (Map map : maps) { + if (Strings.isNotEmpty(map.get("v").toString())) { + strain.add(Double.parseDouble(map.get("v").toString())); + } else { + strain.add(-1.0); + } + } + } + } else { + strain.add(-1.0); + } + } + if (insProduct2.getInspectionItemSubclass().equals("鎺ョ画娓╁害")) { + String insValue = ""; + InsProductResult insProductResult = insProductResultMapper.selectOne(new LambdaQueryWrapper<InsProductResult>() + .eq(InsProductResult::getInsProductId, insProduct2.getId())); + if (!Objects.isNull(insProductResult)) { + insValue = insProductResult.getInsValue(); + List<Map> maps = com.alibaba.fastjson2.JSON.parseArray(insValue, Map.class); + if (maps.size() > 0) { + for (Map map : maps) { + if (Strings.isNotEmpty(map.get("v").toString())) { + joint.add(Double.parseDouble(map.get("v").toString())); + } else { + joint.add(-1.0); + } + } + } + } else { + joint.add(-1.0); + } + } + } + // 濡傛灉瀵肩嚎娓╁害鐨勫�煎ぇ浜庤�愬紶鍜屾帴缁殑鍊硷紝閭d箞灏辨槸鍚堟牸 + if (!strain.isEmpty() && !wire.isEmpty() && (strain.size() == wire.size())) { + if (wire.contains(-1.0) || strain.contains(-1.0)) { + insProductMapper.update(null, new LambdaUpdateWrapper<InsProduct>() + .set(InsProduct::getInsResult, 2) + .eq(InsProduct::getSpecialItemParentId, parentInsProduct.getId()) + .eq(InsProduct::getInspectionItem, insProduct1.getInspectionItem()) + .eq(InsProduct::getInspectionItemSubclass, "鑰愬紶娓╁害")); + strainPending = true; + } else { + for (int i = 0; i < wire.size(); i++) { + if (wire.get(i) <= strain.get(i)) { + strainFlag = false; + break; + } + } + } + } + + if (joint.size() > 0 && wire.size() > 0 && (joint.size() == wire.size())) { + if (wire.contains(-1.0) || joint.contains(-1.0)) { + insProductMapper.update(null, new LambdaUpdateWrapper<InsProduct>() + .set(InsProduct::getInsResult, 2) + .eq(InsProduct::getSpecialItemParentId, parentInsProduct.getId()) + .eq(InsProduct::getInspectionItem, insProduct1.getInspectionItem()) + .eq(InsProduct::getInspectionItemSubclass, "鎺ョ画娓╁害")); + jointPending = true; + } else { + for (int i = 0; i < wire.size(); i++) { + if (wire.get(i) <= joint.get(i)) { + jointFlag = false; + break; + } + } + } + } + if (!strainPending) { + if (strainFlag) { + insProductMapper.update(null, new LambdaUpdateWrapper<InsProduct>() + .set(InsProduct::getInsResult, 1) + .eq(InsProduct::getSpecialItemParentId, parentInsProduct.getId()) + .eq(InsProduct::getInspectionItem, insProduct1.getInspectionItem()) + .eq(InsProduct::getInspectionItemSubclass, "鑰愬紶娓╁害")); + } else { + insProductMapper.update(null, new LambdaUpdateWrapper<InsProduct>() + .set(InsProduct::getInsResult, 0) + .eq(InsProduct::getSpecialItemParentId, parentInsProduct.getId()) + .eq(InsProduct::getInspectionItem, insProduct1.getInspectionItem()) + .eq(InsProduct::getInspectionItemSubclass, "鑰愬紶娓╁害")); + } + } + if (!jointPending) { + if (jointFlag) { + insProductMapper.update(null, new LambdaUpdateWrapper<InsProduct>() + .set(InsProduct::getInsResult, 1) + .eq(InsProduct::getSpecialItemParentId, parentInsProduct.getId()) + .eq(InsProduct::getInspectionItem, insProduct1.getInspectionItem()) + .eq(InsProduct::getInspectionItemSubclass, "鎺ョ画娓╁害")); + } else { + insProductMapper.update(null, new LambdaUpdateWrapper<InsProduct>() + .set(InsProduct::getInsResult, 0) + .eq(InsProduct::getSpecialItemParentId, parentInsProduct.getId()) + .eq(InsProduct::getInspectionItem, insProduct1.getInspectionItem()) + .eq(InsProduct::getInspectionItemSubclass, "鎺ョ画娓╁害")); + } + } + } + // 鏌ユ壘鏄惁鏈夋湭妫�娴嬬殑娆℃暟 + List<Integer> insResult = Arrays.asList(0, 1, 3); + List<InsProduct> insProducts = insProductMapper.selectList(new LambdaQueryWrapper<InsProduct>() + .eq(InsProduct::getSpecialItemParentId, parentInsProduct.getId()) + .and(w -> w.notIn(InsProduct::getInsResult, insResult) + .or() + .isNull(InsProduct::getInsResult))); + if (insProducts.isEmpty()) { + List<InsProduct> insProducts1 = insProductMapper.selectList(new LambdaQueryWrapper<InsProduct>() + .eq(InsProduct::getSpecialItemParentId, parentInsProduct.getId()) + .eq(InsProduct::getInsResult, 0)); + if (!insProducts1.isEmpty()) { + insProductMapper.update(null, new LambdaUpdateWrapper<InsProduct>() + .set(InsProduct::getInsResult, 0) + .eq(InsProduct::getId, parentInsProduct.getId())); + } else { + insProductMapper.update(null, new LambdaUpdateWrapper<InsProduct>() + .set(InsProduct::getInsResult, 1) + .eq(InsProduct::getId, parentInsProduct.getId())); + } + + } + } + } + //娣诲姞宸ユ椂璁板綍 + InsProduct finalInsProduct = insProduct; + WorkTimeDTO workTimeDTO = new WorkTimeDTO(userId, insOrder, insSample, finalInsProduct, parentInsProduct, currentSampleId, k, oldResults, newResult); + String jsonStr; + try { + jsonStr = JackSonUtil.marshal(workTimeDTO); + } catch (Exception e) { + throw new RuntimeException(e); + } + String routerKey; + switch (sonLaboratory){ + case "鏉愭枡璇曢獙瀹�": + routerKey = RouterKeyConstants.CL_KEY; + break; + case "鏈烘鎬ц兘璇曢獙瀹�": + routerKey = RouterKeyConstants.JX_KEY; + break; + case "鐢靛姏璇曢獙瀹�": + routerKey = RouterKeyConstants.DL_KEY; + break; + default: + routerKey = RouterKeyConstants.GX_KEY; + break; + } + sendQueueMessage(ExchangeConstants.WORK_TIME_EXCHANGE,routerKey,jsonStr); + + insSample.setInsState(1); + //鏈楠岀殑妫�楠岄」鏁伴噺 + Long unInsCount = insProductMapper.selectCount(Wrappers.<InsProduct>lambdaQuery() + .eq(InsProduct::getInsSampleId, insSample.getId()) + .and(wrapper -> wrapper + .isNull(InsProduct::getInsResult) + .or() + .eq(InsProduct::getInsResult, 2) + )); + if (0 == unInsCount) { + insSample.setInsState(2); + } + insSampleMapper.updateById(insSample); + /*鏍¢獙涓�涓媟esult琛�*/ + List<InsProductResult> insProductResults = insProductResultMapper.selectList(Wrappers.<InsProductResult>lambdaQuery() + .eq(InsProductResult::getInsProductId, insProduct.getId())); + if (insProductResults.size() > 1) { + for (int i = 1; i < insProductResults.size(); i++) { + insProductResultMapper.deleteById(insProductResults.get(i)); + } + } + } + }); + String sampleIdStr = insContext.keySet().stream().findFirst().orElse(null); + if (sampleIdStr != null) { + int count = insProductMapper.selectInsProductCountByOrderId(orderId); + if (count == 0) { + insOrderStateMapper.update(new InsOrderState(), Wrappers.<InsOrderState>lambdaUpdate() + .eq(InsOrderState::getInsOrderId, orderId) + .eq(InsOrderState::getLaboratory, sonLaboratory) + .set(InsOrderState::getInsState, 2)); + insOrderMapper.update(null, new LambdaUpdateWrapper<InsOrder>() + .set(InsOrder::getState, 4) + .eq(InsOrder::getId, orderId)); + } else { + insOrderStateMapper.update(new InsOrderState(), Wrappers.<InsOrderState>lambdaUpdate() + .eq(InsOrderState::getInsOrderId, orderId) + .eq(InsOrderState::getLaboratory, sonLaboratory) + .set(InsOrderState::getInsState, 1)); + insOrderMapper.update(null, new LambdaUpdateWrapper<InsOrder>() + .set(InsOrder::getInsState, 1) + .eq(InsOrder::getId, orderId)); + } + } + } + }catch (Exception e){ + log.error("宸ユ椂璁$畻澶辫触-->褰撳墠鏍峰搧ID:{},妫�楠岃鎯�:{}",currentSampleId,insContext); + throw new RuntimeException(e); + }finally { + if(lock.isLocked())lock.unlock(); + } + } + + + /** + * 鏌ユ壘灏忔暟浣嶆暟鏈�澶氱殑鏁板�� + */ + public Map<String,Object> maxDecimalNumber(String tells) { + HashMap<String, Object> map = new HashMap<>(); + Pattern pattern = Pattern.compile("[-+]?\\d*\\.?\\d+"); + Matcher matcher = pattern.matcher(tells); + String tell = ""; + Integer maxNumber = 0; + while (matcher.find()) { + String group = matcher.group(); + Integer length = 0; + if(group.contains(".")) { + length = group.split("\\.")[1].length(); + }else { + length = 0; + } + if(length > maxNumber) { + maxNumber = length; + tell = group; + } + } + map.put("tell",tell); + map.put("maxNumber",maxNumber); + return map; + } + + /** + * 灏忔暟浣嶆暟鐨勮ˉ鍏� + */ + public String completion(String value, Integer digit) { + if(NumberUtil.isDouble(value)) { + int length = 0; + String[] splits = value.split("\\."); + if(splits.length>1){ + length = splits[1].length(); + } + if(digit > length) { + int difference = digit - length; + for (int i = 0; i < difference; i++) { + value += "0"; + } + } + } + return value; + } + + //浜ゆ帴 + @Override + public int upPlanUser(Integer userId, Integer orderId, String sonLaboratory) { + InsSampleUser insSampleUser = new InsSampleUser(); + insSampleUser.setUserId(userId); + insSampleUser.setInsSampleId(orderId); + insSampleUser.setState(0); + insSampleUser.setSonLaboratory(sonLaboratory); + return insSampleUserMapper.insert(insSampleUser); + } + + //鏍规嵁鍗曞厓鏍肩殑鏂囨湰鍐呭璁$畻瀹為檯琛岄珮 + private int estimateCellHeight(CellRenderData cellRenderData) { + // 鍋囪榛樿琛岄珮鏄�40 + int defaultHeight = 40; + // 鑾峰彇鍗曞厓鏍间腑鐨勬墍鏈夋钀� + List<ParagraphRenderData> paragraphs = cellRenderData.getParagraphs(); + int estimatedHeight = 0; + try { + // 閬嶅巻娈佃惤锛屼及绠楁瘡涓钀界殑楂樺害 + for (ParagraphRenderData paragraph : paragraphs) { + List<RenderData> contents = paragraph.getContents(); + for (RenderData content : contents) { + if (content instanceof TextRenderData) { + TextRenderData text = (TextRenderData) content; + Style style = text.getStyle(); + // 鍋囪姣忚鏂囨湰鐨勯珮搴︿负瀛椾綋澶у皬鐨�1.2鍊� + Double fontSize = Objects.isNull(style.getFontSize()) ? 12.0 : style.getFontSize(); + int lines = (int) Math.ceil(text.getText().length() / 15.0); // 鍋囪姣忚绾�15涓瓧绗� + int textHeight = (int) (fontSize * 1.2 * lines); + // 绱姞娈佃惤鐨勯珮搴� + estimatedHeight += textHeight; + } + } + } + }catch (Exception ignored){} + // 杩斿洖鏈�澶у�硷紝纭繚楂樺害涓嶄綆浜庨粯璁ら珮搴� + return Math.max(estimatedHeight, defaultHeight); + } + + /** + * 鍙戦�侀槦鍒楁秷鎭� + * @param exchange 浜ゆ崲鏈哄悕绉� + * @param routerKey 璺敱涓婚敭 + * @param jsonStr 娑堟伅鍐呭 + */ + public void sendQueueMessage(String exchange,String routerKey,String jsonStr){ + rabbitTemplate.convertAndSend(exchange,routerKey,jsonStr); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public int verifyPlan(Integer orderId, String laboratory, Integer type, String tell) { + int num = (type == 1 ? 5 : 4); + LocalDateTime now = LocalDateTime.now(); + insOrderStateMapper.update(null, Wrappers.<InsOrderState>lambdaUpdate().eq(InsOrderState::getInsOrderId, orderId).eq(InsOrderState::getLaboratory, laboratory).set(InsOrderState::getInsTime, now).set(InsOrderState::getInsState, num).set(InsOrderState::getVerifyTell, tell).set(InsOrderState::getVerifyUser, SecurityUtils.getUserId())); + Long count = insOrderStateMapper.selectCount(Wrappers.<InsOrderState>lambdaQuery().eq(InsOrderState::getInsOrderId, orderId).ne(InsOrderState::getInsState, 5)); + if (count == 0 && num == 5) { + List<InsUnPass> insUnPasses = new ArrayList<>(); + /*鏍峰搧涓嬬殑椤圭洰鍙鏈変竴涓」鐩笉鍚堟牸鍒欐楠岀粨鏋滀负0,鍚﹀垯涓�1*/ + //杩欓噷鐨刬nsSamples鏄鍗曚笅鐨勬墍鏈夋牱鍝佸寘鎷�("/") + List<InsSample> insSamples = insSampleMapper.selectList(Wrappers.<InsSample>lambdaQuery().eq(InsSample::getInsOrderId, orderId)); + for (InsSample insSample : insSamples) { + List<InsProduct> insProducts = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery().eq(InsProduct::getInsSampleId, insSample.getId()).eq(InsProduct::getState, 1)); + List<Integer> results = insProducts.stream().map(InsProduct::getInsResult).filter(Objects::nonNull).collect(Collectors.toList()); + if (results.contains(0)) { + insSample.setInsResult(0); + } else { + insSample.setInsResult(1); + } + insSampleMapper.updateById(insSample); + /*澶嶆牳閫氳繃鍚庯紝灏嗕笉鍚堟牸鐨勯」鐩俊鎭坊鍔犲埌ins_un_pass琛ㄤ腑*/ + for (InsProduct insProduct : insProducts) { + if (insProduct.getInsResult() == 0) { + InsUnPass insUnPass = new InsUnPass(); + insUnPass.setId(null); + insUnPass.setModel(insSample.getModel()); + insUnPass.setSample(insSample.getSample()); + insUnPass.setInspectionItem(insProduct.getInspectionItem()); + insUnPass.setInspectionItemSubclass(insProduct.getInspectionItemSubclass()); + insUnPass.setLastValue(insProduct.getLastValue()); + insUnPass.setEntrustCode(insOrderMapper.selectById(orderId).getEntrustCode()); + List<Integer> userIds = insProductUserMapper.selectList(Wrappers.<InsProductUser>lambdaQuery().eq(InsProductUser::getInsProductId, insProduct.getId())).stream().map(InsProductUser::getCreateUser).distinct().collect(Collectors.toList()); + if(!userIds.isEmpty()){ + String name = userMapper.selectBatchIds(userIds).stream().map(User::getName).collect(Collectors.joining(",")); + insUnPass.setName(name); + insUnPasses.add(insUnPass); + } + } + } + } + insUnPassService.saveBatch(insUnPasses); + InsOrder insOrder = insOrderMapper.selectById(orderId); + String oldSampleStr = insOrder.getSample(); + //samples鏄繃婊ゆ帀娌℃湁妫�楠岄」鐩殑鏍峰搧 + List<SampleProductDto> samples = insSampleMapper.selectSampleProductListByOrderId(orderId); + //鏌ヨ璁㈠崟涓嬬殑鍘婚噸鍚庣殑鏍峰搧鍚嶇О + List<String> unqeSampleList = samples.stream().map(InsSample::getSample).distinct().collect(Collectors.toList()); + if(unqeSampleList.size()==1){ + insOrder.setSample(unqeSampleList.get(0)); + } + InsReport insReport = new InsReport(); + insReport.setCode(insOrder.getEntrustCode()); + insReport.setInsOrderId(orderId); + List<Map<String, Object>> tables = new ArrayList<>(); + Set<String> standardMethod = new HashSet<>(); + Set<String> deviceSet = new HashSet<>(); + Set<String> models = new HashSet<>(); + AtomicReference<Integer> productSize = new AtomicReference<>(0); + String[] monthNames = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; + Set<String> resultCh = new HashSet<>(); + Set<String> resultEn = new HashSet<>(); + //鑾峰彇妫�楠岄」鐩暟閲� + Set<String> unEqualSet = new HashSet<>(); + //鐢靛姏璇曢獙瀹わ細閽㈡潗/閾濇潗鏍峰搧鍨嬪彿 + List<String> modelDl = new ArrayList<>(); + /*鍩虹鎶ュ憡(鏍规嵁缁樺埗鐨勫師濮嬭褰曟ā鐗堝舰鎴�)*/ + BasicReportHandler basicReportHandler = new BasicReportHandler(baseMapper, this,insSampleMapper); + basicReportHandler.doWrite(samples,insReport,tables,standardMethod,models,unEqualSet,modelDl,deviceSet); + productSize.getAndSet(unEqualSet.size()); + String sampleStr = insOrder.getSample(); + if(!modelDl.isEmpty()){ + String model = modelDl.stream().distinct().findFirst().orElse(""); + sampleStr += model; + } + /*鍏夌氦鎺ュご鎹熻�楃殑鎶ュ憡鏍峰紡*/ + //鏌ヨ璁㈠崟涓嬫墍鏈夋牱鍝佺殑妫�楠岄」鐩�,濡傛灉鏈夊厜绾ゆ帴澶存崯鑰楀垯閲嶆柊鏋勫缓琛ㄦ牸 + List<Map<String, Object>> tables4 = new ArrayList<>(); + //褰撳墠璁㈠崟涓嬬殑鎵�鏈夋楠岄」 + List<InsProduct> insProducts0 = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery() + .eq(InsProduct::getState, 1) + .in(InsProduct::getInsSampleId, insSamples.stream().map(InsSample::getId).distinct().collect(Collectors.toList()))); + if (insProducts0.stream().map(InsProduct::getInspectionItem).collect(Collectors.toList()).contains("鍏夌氦鎺ュご鎹熻��")){ + //澶勭悊鍏夌氦鎺ュご鎹熻�楁姤鍛� + FiberOpticConnectorLossReportHandler lossReportHandler = new FiberOpticConnectorLossReportHandler(insProductMapper); + lossReportHandler.doWrite(insProducts0,insSamples,insReport,tables4); + } + String url; + try { + InputStream inputStream = this.getClass().getResourceAsStream("/static/report-template.docx"); + File file = File.createTempFile("temp", ".tmp"); + OutputStream outputStream = new FileOutputStream(file); + IOUtils.copy(inputStream, outputStream); + url = file.getAbsolutePath(); + } catch (FileNotFoundException e) { + throw new ErrorException("鎵句笉鍒版ā鏉挎枃浠�"); + } catch (IOException e) { + throw new RuntimeException(e); + } + StringBuilder standardMethod2 = new StringBuilder(); + for (String s : standardMethod) { + standardMethod2.append("銆�").append(s); + } + standardMethod2.replace(0, 1, ""); + tables.forEach(table -> { + table.put("tableSize", tables.size() + 1); + }); + List<DeviceVO> deviceList = new ArrayList<>(); + if (!deviceSet.isEmpty()) { + deviceSet.forEach(d->deviceList.add(insOrderMapper.selectDeviceList(d))); + } + Map<String, String> codeStr = new HashMap<>(); + codeStr.put("鎶ュ憡缂栧彿", insReport.getCode()); + codeStr.put("鏍峰搧鍚嶇О", insOrder.getSample()); + codeStr.put("瑙勬牸鍨嬪彿", samples.get(0).getModel()); + codeStr.put("鍙戞斁鏃ユ湡", now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); + String codePath; + try { + String content = phoneQrCode+ insOrder.getEntrustCode() + "&type=word"; + codePath = new MatrixToImageWriter().code(content, twoCode); + } catch (Exception e) { + throw new RuntimeException(e); + } + String modelStr = ""; + for (String model : models) { + modelStr += "," + model; + } + String finalModelStr = modelStr; + String sampleEn = insSampleMapper.getSampleEn(insOrder.getSample()); + insOrder.setSample(sampleStr); + String orderType = insOrderMapper.getEnumLabelByValue(insOrder.getOrderType()); + String formType = insOrderMapper.getEnumLabelByValue(insOrder.getFormType()); + ConfigureBuilder builder = Configure.builder(); + builder.useSpringEL(true); + List<DeviceVO> finalDeviceList = deviceList; + Integer userId = insSampleUserMapper.selectOne(Wrappers.<InsSampleUser>lambdaQuery() + .eq(InsSampleUser::getInsSampleId, orderId) + .eq(InsSampleUser::getState,0) + .orderByDesc(InsSampleUser::getCreateTime) + .last("limit 1")).getUserId(); + String signatureUrl; + try { + signatureUrl = userMapper.selectById(userId).getSignatureUrl(); + } catch (Exception e) { + throw new ErrorException("鎵句笉鍒版楠屼汉鐨勭鍚�"); + } + if (ObjectUtils.isEmpty(signatureUrl) || signatureUrl.isEmpty()) { + throw new ErrorException("鎵句笉鍒版楠屼汉鐨勭鍚�"); + } + //濡傛灉鏄腑澶╃鎶�杞井缂嗗巶(02)锛屾姤鍛婂睍绀哄鎵樺崟浣嶄负涓ぉ绉戞妧鍏夌紗鎬诲巶(01) + Custom custom = customMapper.selectById(insOrder.getCompanyId()); + if(!Objects.isNull(custom) && Objects.equals("涓ぉ绉戞妧杞井缂嗗巶",custom.getCompany())){ + //涓ぉ绉戞妧鍏夌紗鎬诲巶瀹㈡埛淇℃伅 + custom = customMapper.selectOne(Wrappers.<Custom>lambdaQuery() + .eq(Custom::getCompany,"涓ぉ绉戞妧鍏夌紗鎬诲巶") + .eq(Custom::getCode2,"01").last("limit 1")); + } + //鍚堟牸鏁伴噺 + long qualifiedCount = insProducts0.stream().filter(f->f.getInsResult()==1).count(); + //鏍煎紡鍖栦笉鍚堟牸椤圭洰 + joinUnqualifiedItemChars(resultCh,resultEn,insProducts0); + String resultChStr = "渚濇嵁濮旀墭瑕佹眰锛屾墍妫�椤圭洰鍧囩鍚堣姹傘��"; + String resultEnStr = "According to commissioned requirements, all the tested items meet the requirements."; + if (!resultCh.isEmpty() && qualifiedCount>0) { + resultChStr = "渚濇嵁濮旀墭瑕佹眰锛�" + String.join("銆�",resultCh) + "鎵�妫�椤圭洰涓嶇鍚堣姹傦紝鍏朵綑鎵�妫�椤圭洰鍧囩鍚堣姹傘��"; + resultEnStr = "According to commissioned requirements," + String.join("銆�",resultEn) + " these inspected items do not meet the requirements, all other inspected items meet the requirements."; + }else if(!resultCh.isEmpty() && qualifiedCount==0){ + resultChStr = "渚濇嵁濮旀墭瑕佹眰锛屾墍妫�椤圭洰鍧囦笉绗﹀悎瑕佹眰銆�"; + resultEnStr = "According to commissioned requirements, all the tested items do not meet the requirements."; + } + + //鍏夌氦闄勪欢琛ㄦ牸鏁版嵁 + List<Map<String, Object>> tables2 = new ArrayList<>(); + //鏉惧绠¢檮浠惰〃鏍兼暟鎹� + List<Map<String, Object>> tables5 = new ArrayList<>(); + //灏哄鍙傛暟闄勪欢琛ㄦ牸鏁版嵁 + List<Map<String, Object>> tables6 = new ArrayList<>(); + /*鍏夌氦閰嶇疆鐨勬楠屾姤鍛�*/ + //鍏堝垽鏂槸鍚︽湁鍏夌氦閰嶇疆 + List<InsProduct> insProducts = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery() + .eq(InsProduct::getState, 1) + .in(InsProduct::getInsSampleId, insSamples.stream().map(InsSample::getId).distinct().collect(Collectors.toList())) + .and(i->i.isNull(InsProduct::getInspectionItemClass).or().eq(InsProduct::getInspectionItemClass,"")) + );//鐢ㄦ楠屽垎椤瑰瓧娈靛尯鍒厜绾ら厤缃笌娓╁害寰幆 + //鏌ヨ鍏ㄨ壊璋憋紝杩囨护鑹叉爣骞舵帓搴� + List<String> colorList = DictUtils.getDictCache("鑹叉爣").stream() + .sorted(Comparator.comparing(SysDictData::getDictSort)) + .map(SysDictData::getDictValue) + .collect(Collectors.toList()); + //鏉惧绠¢檮浠跺鐞� + long piperCount = insProducts.stream().filter(f->!Objects.isNull(f.getInsBushId())).count(); + if(piperCount>0){ + PiperConfigReportHandler piperConfigReportHandler = new PiperConfigReportHandler(insProductMapper); + piperConfigReportHandler.doWrite(samples,insReport,tables5,colorList); + } + //杩囨护鏈夊厜绾ら厤缃殑椤圭洰 + long fiberCount = insProducts.stream().filter(f->!Objects.isNull(f.getInsFiberId())).count(); + FiberConfigReportHandler lossReportHandler = new FiberConfigReportHandler(insProductMapper,insSampleMapper); + if (fiberCount>0) { + lossReportHandler.doWrite(samples,insReport,tables2,colorList); + } else{ + //鎺掗櫎鍏夌氦鎺ュご鎹熻�楀拰灏哄鍙傛暟 + List<InsProduct> filterLists = insProducts.stream() + .filter(f->!Arrays.asList("鍏夌氦鎺ュご鎹熻��","灏哄鍙傛暟","娓╁害寰幆").contains(f.getInspectionItem())&&f.getSonLaboratory().equals("鍏夌氦璇曢獙瀹�")).collect(Collectors.toList()); + lossReportHandler.writeFiberEnclosureTableRow(filterLists,tables2,insReport); + } + //杩囨护鏈夊厜绾ゅ甫閰嶇疆鐨勯」鐩� + long fibersCount = insProducts.stream().filter(f->!Objects.isNull(f.getInsFibersId())).count(); + FiberOpticRibbonReportHandler fiberOpticRibbonReportHandler = new FiberOpticRibbonReportHandler(insProductMapper,insSampleMapper); + if (fibersCount>0) { + fiberOpticRibbonReportHandler.doWrite(samples,insReport,tables6,colorList); + } else{ + //杩囨护灏哄鍙傛暟椤圭洰 + List<InsProductFiberVO> productList = new ArrayList<>(); + insSamples.stream() + .map(InsSample::getId).distinct() + .forEach(id->productList.addAll(insProductMapper.selectProductBySampleId(id))); + List<InsProductFiberVO> vos = productList.stream().filter(f->f.getInspectionItem().equals("灏哄鍙傛暟")).collect(Collectors.toList()); + if(!vos.isEmpty()){ + fiberOpticRibbonReportHandler.writeFiberOpticRibbonEnclosureTableRow(vos,tables6,insReport); + } + } + tables2.forEach(table2 -> table2.put("tableSize2", tables2.size())); + tables5.forEach(table5 -> table5.put("tableSize5", tables5.size())); + tables6.forEach(table6 -> table6.put("tableSize6", tables6.size())); + + /*娓╁害寰幆鐨勬楠屾姤鍛�*/ + //鍏堝垽鏂槸鍚︽湁娓╁害寰幆 + List<InsProduct> insProducts3 = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery() + .eq(InsProduct::getState, 1) + .in(InsProduct::getInsSampleId, insSamples.stream().map(InsSample::getId).distinct().collect(Collectors.toList())) + .isNotNull(InsProduct::getSpecialItemParentId) //鍖哄垎甯歌椤圭洰 + .isNotNull(InsProduct::getInspectionItemClass)//鐢ㄦ楠屽垎椤瑰瓧娈靛尯鍒厜绾ら厤缃笌娓╁害寰幆 + .isNotNull(InsProduct::getInsFiberId)); //鐢ㄥ厜绾ゅ尯鍒儹寰幆鍜屾俯搴﹀惊鐜� + List<Map<String, Object>> tables3 = new ArrayList<>(); + if (!insProducts3.isEmpty()) { + //澶勭悊娓╁害寰幆鎶ュ憡 + TemperatureCyclingReportHandler1 cyclingReportHandler = new TemperatureCyclingReportHandler1(insProductMapper, insFiberMapper, insProductResultMapper); + cyclingReportHandler.doWrite(samples,insReport,tables3); + } + + /*娓╁崌璇曢獙鐨勬楠屾姤鍛�*/ + List<InsProduct> insProducts1 = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery() + .eq(InsProduct::getState, 1) + .in(InsProduct::getInsSampleId, insSamples.stream().map(InsSample::getId).distinct().collect(Collectors.toList())) + .isNotNull(InsProduct::getSpecialItemParentId) //鍖哄垎甯歌椤圭洰 + .isNull(InsProduct::getInspectionItemClass)//鐢ㄦ楠屽垎椤瑰瓧娈靛尯鍒俯鍗囪瘯楠屼笌鐑惊鐜� + .isNull(InsProduct::getInsFiberId) //鐢ㄥ厜绾ゅ尯鍒俯鍗囪瘯楠屽拰娓╁害寰幆 + .eq(InsProduct::getInspectionItem, "1")); //娓╁崌璇曢獙鐨勫惊鐜彧鏈�1娆� + if (!insProducts1.isEmpty()) { + //澶勭悊娓╁崌璇曢獙鎶ュ憡 + TemperatureTestReportHandler testReportHandler = new TemperatureTestReportHandler(insProductMapper, insProductResultMapper); + testReportHandler.doWrite(samples,insReport,tables3); + } + + /*鐑惊鐜殑妫�楠屾姤鍛�*/ + List<InsProduct> insProducts2 = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery() + .eq(InsProduct::getState, 1) + .in(InsProduct::getInsSampleId, insSamples.stream().map(InsSample::getId).distinct().collect(Collectors.toList())) + .isNotNull(InsProduct::getSpecialItemParentId) //鍖哄垎甯歌椤圭洰 + .isNotNull(InsProduct::getInspectionItemClass)//鐢ㄦ楠屽垎椤瑰瓧娈靛尯鍒俯鍗囪瘯楠屼笌鐑惊鐜� + .isNull(InsProduct::getInsFiberId)); //鐢ㄥ厜绾ゅ尯鍒儹寰幆鍜屾俯搴﹀惊鐜� + if (!insProducts2.isEmpty()) { + //澶勭悊鐑惊鐜姤鍛� + ThermalCycleReportHandler cycleReportHandler = new ThermalCycleReportHandler(insProductMapper, insProductResultMapper); + cycleReportHandler.doWrite(samples,insReport,tables3); + } + //鍗曟牴鍨傜洿鐕冪儳鐨勬楠屾姤鍛� + tables3.forEach(table3 -> { + table3.put("tableSize3", tables3.size()); + }); + /*鑾峰彇闄勪欢鍥剧墖绫诲瀷*/ + List<Map<String, Object>> images = new ArrayList<>(); + List<InsOrderFile> insOrderFiles = insOrderFileMapper.selectList(Wrappers.<InsOrderFile>lambdaQuery().eq(InsOrderFile::getType, 1).eq(InsOrderFile::getInsOrderId, orderId)); + if (CollectionUtils.isNotEmpty(insOrderFiles)) { + insOrderFiles.forEach(insOrderFile -> { + Map<String, Object> image = new HashMap<>(); + PictureRenderData pictureRenderData = Pictures.ofLocal(imgUrl + "/" + insOrderFile.getFileUrl()).sizeInCm(17, 20).create(); + image.put("url", pictureRenderData); + image.put("report", insReport); + images.add(image); + }); + } + //濮旀墭浜哄拰鐢佃瘽瀛楁鍒ゆ柇 + if (ObjectUtils.isEmpty(insOrder.getPrepareUser())) { + insOrder.setPrepareUser("/"); + } + if (ObjectUtils.isEmpty(insOrder.getPhone())) { + insOrder.setPhone("/"); + } + //鏌ヨ瀹℃壒绛惧悕閰嶇疆 + Map<String,Object> urlMap = insReportApproveConfigMapper.selectApprovalConfigByLaboratory(insOrder.getLaboratory()); + String writeUrl = imgUrl + "/" + (Objects.isNull(urlMap.get("writeUrl"))?"":urlMap.get("writeUrl").toString());//缂栧埗浜虹鍚島rl + String examineUrl = imgUrl + "/" + (Objects.isNull(urlMap.get("examineUrl"))?"":urlMap.get("examineUrl").toString());//瀹℃牳浜虹鍚島rl + String ratifyUrl = imgUrl + "/" + (Objects.isNull(urlMap.get("ratifyUrl"))?"":urlMap.get("ratifyUrl").toString());//鎵瑰噯浜虹鍚島rl + //鑾峰彇鍦烘墍鐨勬姤鍛婁笓鐢ㄧ珷 + String sealUrl; + try { + sealUrl = insReportMapper.getLaboratoryByName(insOrder.getLaboratory()); + } catch (Exception e) { + throw new ErrorException("鎵句笉鍒版姤鍛婁笓鐢ㄧ珷"); + } + + //妫�楠岄」鐩殑鐜 + InsProduct insProduct = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery().eq(InsProduct::getState, 1).eq(InsProduct::getInsSampleId, samples.get(0).getId())).get(0); + String environment = ""; + environment = (ObjectUtils.isNotEmpty(insProduct.getTemperature()) ? insProduct.getTemperature() + "鈩� " : "") + (ObjectUtils.isNotEmpty(insProduct.getHumidity()) ? insProduct.getHumidity() + "%" : ""); + String finalEnvironment = environment; + Custom finalCustom = custom; + String finalSealUrl = imgUrl + "/" +sealUrl; + String finalResultChStr = resultChStr; + String finalResultEnStr = resultEnStr; + ZipSecureFile.setMinInflateRatio(0.001); + XWPFTemplate template = XWPFTemplate.compile(url, builder.build()).render( + new HashMap<String, Object>() {{ + put("order", insOrder); + put("report", insReport); + put("environment", finalEnvironment); + put("custom", finalCustom); + put("sampleSize", samples.size()); + put("tables", tables); + put("tableSize", tables.size() + 1); + put("tables2", tables2.isEmpty()?null:tables2); + put("tableSize2", tables2.size()); + put("tables3", tables3.isEmpty()?null:tables3); + put("tableSize3", tables3.size()); + put("tables4", tables4.isEmpty()?null:tables4); + put("tableSize4", tables4.size()); + put("tables5", tables5.isEmpty()?null:tables5); + put("tableSize5", tables5.size()); + put("tables6", tables6.isEmpty()?null:tables6); + put("tableSize6", tables6.size()); + put("standardMethod", (standardMethod2.toString().equals("null") ? "" : standardMethod2)); + put("deviceList", finalDeviceList); + put("twoCode", Pictures.ofLocal(codePath).create()); + put("models", finalModelStr.replace(",", "")); + put("productSize", productSize); + put("createTime", now.format(DateTimeFormatter.ofPattern("yyyy骞碝M鏈坉d鏃�"))); + put("createTimeEn", monthNames[now.getMonthValue() - 1] + " " + now.getDayOfMonth() + ", " + now.getYear()); + put("insTime", insOrder.getInsTime().format(DateTimeFormatter.ofPattern("yyyy骞碝M鏈坉d鏃�"))); + put("insTimeEn", monthNames[insOrder.getInsTime().getMonthValue() - 1] + " " + insOrder.getInsTime().getDayOfMonth() + ", " + insOrder.getInsTime().getYear()); + put("writeUrl", new FilePictureRenderData(100,50, writeUrl)); + put("insUrl", new FilePictureRenderData(100,50,imgUrl + "/" + signatureUrl)); + put("images", images.isEmpty()?null:images); + put("examineUrl", new FilePictureRenderData(100,50,examineUrl)); + put("ratifyUrl", new FilePictureRenderData(100,50,ratifyUrl)); + put("sampleEn", sampleEn); + put("orderType", orderType); + put("getTime", insOrder.getExamineTime().format(DateTimeFormatter.ofPattern("yyyy骞碝M鏈坉d鏃�"))); + put("getTimeEn", monthNames[insOrder.getExamineTime().getMonthValue() - 1] + " " + insOrder.getExamineTime().getDayOfMonth() + ", " + insOrder.getExamineTime().getYear()); + put("seal1", new FilePictureRenderData(600,600, finalSealUrl)); + put("seal2", new FilePictureRenderData(600,600, finalSealUrl)); + put("formTypeCh", formType); + put("formTypeEn", insOrder.getFormType()); + put("resultCh", finalResultChStr); + put("resultEn", finalResultEnStr); + }}); + // 鏇存柊鏁版嵁搴撲腑鐨勭鍙戞棩鏈� + insOrderService.update(Wrappers.<InsOrder>lambdaUpdate() + .eq(InsOrder::getId, insOrder.getId()) + .set(InsOrder::getIssuingDate, now)); + try { + String name = insReport.getCode().replace("/", "") + ".docx"; + template.writeAndClose(Files.newOutputStream(Paths.get(wordUrl + "/" + name))); + insReport.setUrl("/word/" + name); + insReport.setIsExamine(-9);//鏈鏍哥姸鎬佷负-9 + insReport.setIsRatify(-9);//鏈壒鍑嗙姸鎬佷负-9 + insReportMapper.insert(insReport); + insOrder.setInsState(5); + insOrder.setSample(oldSampleStr); + insOrderMapper.updateById(insOrder); + } catch (IOException e) { + throw new RuntimeException(e); + } + // 澶勭悊鍚堝苟鍗曞厓鏍肩殑闂 + String path = wordUrl + "/" + insReport.getCode().replace("/", "") + ".docx"; + // word 杞� pdf + String tempUrlPdf = insReportService.wordToPdfTemp((StrUtil.isBlank(insReport.getUrlS()) ? insReport.getUrl() : insReport.getUrlS()).replace("/word", wordUrl)); + insReportMapper.update(null,new LambdaUpdateWrapper<InsReport>() + .set(InsReport::getTempUrlPdf,tempUrlPdf) + .eq(InsReport::getId,insReport.getId())); + try { + ZipSecureFile.setMinInflateRatio(0.0001);//瑙e喅闄勪欢鏂囦欢杩囧ぇ寮曞彂鐨刏ipBom寮傚父 + FileInputStream stream = new FileInputStream(path); + XWPFDocument document = new XWPFDocument(stream); + List<XWPFTable> xwpfTables = document.getTables(); + for (int i = 0; i < xwpfTables.size(); i++) { + Set<String> set1 = new HashSet<>(); + Map<String, Map<String, Integer>> maps = new HashMap<>(); + for (int j = 0; j < xwpfTables.get(i).getRows().size(); j++) { + for (int k = 0; k < xwpfTables.get(i).getRows().get(j).getTableCells().size(); k++) { + if (xwpfTables.get(i).getRows().get(j).getTableCells().get(k).getText().indexOf("鈭�") > -1) { + String[] split = xwpfTables.get(i).getRows().get(j).getTableCells().get(k).getText().split("鈭�"); + if (set1.add(split[1])) { + Map<String, Integer> map = new HashMap<>(); + map.put("sr", j); + map.put("sc", k); + map.put("er", j + 0); + map.put("ec", k + 0); + maps.put(split[1], map); + } else { + Map<String, Integer> map1 = maps.get(split[1]); + if (j == map1.get("sr")) { + map1.put("ec", map1.get("ec") + 1); + } else if (k == map1.get("sc")) { + map1.put("er", map1.get("er") + 1); + } + } + String str = xwpfTables.get(i).getRows().get(j).getTableCells().get(k).getText().split("鈭�")[0]; + xwpfTables.get(i).getRows().get(j).getTableCells().get(k).removeParagraph(0); + xwpfTables.get(i).getRows().get(j).getTableCells().get(k).setText(str); + xwpfTables.get(i).getRows().get(j).getTableCells().get(k).setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER); + xwpfTables.get(i).getRows().get(j).getTableCells().get(k).getParagraphArray(0).setAlignment(ParagraphAlignment.CENTER); + } + } + } + + // 鍗曞厓鏍兼帓搴�, 閬垮厤鏍煎紡閿欎贡 + List<Map.Entry<String, Map<String, Integer>>> entries = new ArrayList<>(maps.entrySet()); + entries.sort((o1, o2) -> o1.getValue().get("sc") - o2.getValue().get("sc")); + + // 鎸夌収椤哄簭娣诲姞杩涢泦鍚� + List<String> list = new ArrayList<>(); + for (Map.Entry<String, Map<String, Integer>> entry : entries) { + list.add(entry.getKey()); + } + /*List<String> list = new ArrayList<>(); + for (String s : maps.keySet()) { + list.add(s); + }*/ + for (int a = list.size() - 1; a >= 0; a--) { + Map<String, Integer> v = maps.get(list.get(a)); + for (int j = 0; j < v.get("er") - v.get("sr") + 1; j++) { + if (v.get("ec") > v.get("sc")) { + try { + TableTools.mergeCellsHorizonal(xwpfTables.get(i), v.get("sr") + j, v.get("sc"), v.get("ec")); + } catch (Exception e) { + } + } + } + if (v.get("er") > v.get("sr")) { + try { + TableTools.mergeCellsVertically(xwpfTables.get(i), v.get("sc"), v.get("sr"), v.get("er")); + } catch (Exception e) { + } + } + } + } + FileOutputStream fileOutputStream = new FileOutputStream(path); + document.write(fileOutputStream); + fileOutputStream.close(); + } catch (FileNotFoundException e) { + throw new RuntimeException(e); + } catch (IOException e) { + throw new RuntimeException(e); + } + //澶勭悊涓嫳鏂囨崲琛岀殑闂 + try { + FileInputStream stream1 = new FileInputStream(path); + XWPFDocument document1 = new XWPFDocument(stream1); + List<XWPFTable> xwpfTables1 = document1.getTables(); + for (int i = 1; i < xwpfTables1.size() - (deviceList == null ? 1 : 2); i++) { + for (int j = 0; j < xwpfTables1.get(i).getRows().size(); j++) { + for (int k = 0; k < xwpfTables1.get(i).getRows().get(j).getTableCells().size(); k++) { + if (xwpfTables1.get(i).getRows().get(j).getTableCells().get(k).getText().contains("@")) { + String text = xwpfTables1.get(i).getRows().get(j).getTableCells().get(k).getText(); + String[] split = text.split("@"); + xwpfTables1.get(i).getRows().get(j).getTableCells().get(k).removeParagraph(0); + XWPFParagraph xwpfParagraph = xwpfTables1.get(i).getRows().get(j).getTableCells().get(k).addParagraph(); + XWPFRun run = xwpfParagraph.createRun(); + run.setText(split.length>0?split[0]:""); + if (split.length>1 && ObjectUtils.isNotNull(split[1])) { + run.addBreak(); + run.setText(split[1]); + } + xwpfParagraph.setAlignment(ParagraphAlignment.CENTER); + } + } + } + } + FileOutputStream fileOutputStream1 = new FileOutputStream(path); + document1.write(fileOutputStream1); + fileOutputStream1.close(); + } catch (FileNotFoundException e) { + throw new RuntimeException(e); + } catch (IOException e) { + throw new RuntimeException(e); + } + } else if(num != 5) { + //澶嶆牳涓嶉�氳繃灏嗘妸澶嶆牳鐨勮礋璐d汉鍘绘帀 + Integer id = insSampleUserMapper.selectOne(Wrappers.<InsSampleUser>lambdaQuery().eq(InsSampleUser::getInsSampleId, orderId).orderByDesc(InsSampleUser::getId).last("limit 1")).getId(); + insSampleUserMapper.deleteById(id); + } + return 1; + } + + /** + * 鏍煎紡鍖栦笉鍚堟牸椤圭洰瀛楃涓� + * @param resultCh 涓嶅悎鏍奸」鐩腑鏂囧垪琛� + * @param resultEn 涓嶅悎鏍奸」鐩嫳鏂囧垪琛� + * @param insProducts0 妫�楠岄」鍒楄〃 + */ + private void joinUnqualifiedItemChars(Set<String> resultCh, Set<String> resultEn, List<InsProduct> insProducts0) { + if(!insProducts0.isEmpty()){ + insProducts0.stream().filter(f->f.getInsResult()==0).forEach(e->{ + String chinaStr = String.join("-",e.getInspectionItem(),e.getInspectionItemSubclass()); + String englishStr = String.join("-",e.getInspectionItemEn(),e.getInspectionItemSubclassEn()); + resultCh.add(chinaStr); + resultEn.add(englishStr); + }); + } + } + + public void getTemplateThing + (Set<Integer> set, Map<Integer, String> map2, List<InsProduct> insProducts) { + for (InsProduct product : insProducts) { + if (product.getSpecialItemParentId()!=null) { + product.setTemplate(new ArrayList<>()); + continue; + } + String thing = null; + if (product.getSpecialItemParentId() == null && set.add(product.getTemplateId())) { + map2.put(product.getTemplateId(), standardTemplateService.getStandTempThingById(product.getTemplateId()) + ""); + thing = map2.get(product.getTemplateId()); + } + if (StrUtil.isNotEmpty(thing)) { + JSONObject sheet = JSON.parseObject(JSON.toJSONString(JSON.parseArray(JSON.toJSONString(JSON.parseObject(thing).get("data"))).get(0))); + JSONObject config = JSON.parseObject(JSON.toJSONString(sheet.get("config"))); + List<JSONObject> cellData = JSON.parseArray(JSON.toJSONString(sheet.get("celldata")), JSONObject.class); + Map<String, Object> style = new HashMap<>(); + style.put("rowlen", config.get("rowlen")); + style.put("columnlen", config.get("columnlen")); + product.setTemplate(cellData); + product.setStyle(style); + product.setTemplateName(standardTemplateService.getStandTempNameById(product.getTemplateId())); + } + } + } + + @Override + public int submitPlan(Integer orderId, String laboratory, Integer verifyUser, String entrustCode) { + List<InsSample> insSamples = insSampleMapper.selectList(Wrappers.<InsSample>lambdaQuery().eq(InsSample::getInsOrderId, orderId).select(InsSample::getId)); + List<Integer> ids = insSamples.stream().map(a -> a.getId()).collect(Collectors.toList()); + List<InsProduct> insProducts = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery() + .in(InsProduct::getInsSampleId, ids) + .eq(InsProduct::getSonLaboratory, laboratory) + .eq(InsProduct::getState, 1) + .and(wrapper -> wrapper + .isNull(InsProduct::getInsResult) + .or() + .eq(InsProduct::getInsResult, 2) + ) + .isNull(InsProduct::getInsFiberId) + .isNull(InsProduct::getInsFibersId)); + insProducts.addAll(insProductMapper.selectFiberInsProduct(ids, laboratory)); + if (insProducts.size() > 0) { + String str = ""; + HashSet<String> set = new HashSet<>(); + int count = 0; + for (InsProduct product : insProducts) { + //濡傛灉鏄厜缂嗙殑娓╁害寰幆 + if (product.getInspectionItem().equals("娓╁害寰幆") && insOrderMapper.selectById(orderId).getSampleType().equals("鍏夌紗")) { + //鏌ヨ閭d簺寰幆娓╁害鐨勬楠岄」鐩殑缁撹鏄惁鍏ㄩ儴妫�楠� + List<InsProduct> insProductList = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery().eq(InsProduct::getInsSampleId, product.getInsSampleId()) + .isNotNull(InsProduct::getInsFiberId).like(InsProduct::getInspectionItemSubclass, "鈩�")); + List<Integer> collect = insProductList.stream().filter(insProduct -> insProduct.getInsResult() != null).map(InsProduct::getInsResult).collect(Collectors.toList()); + List<Integer> tt = new ArrayList<>(); + tt.add(1); + if (collect.contains(0)) { + product.setLastValue("涓嶅悎鏍�"); + product.setInsResult(0); + } else if (collect.size() == insProductList.size() && collect.stream().distinct().collect(Collectors.toList()).containsAll(tt)) { + product.setLastValue("鍚堟牸"); + product.setInsResult(1); + } + insProductMapper.updateById(product); + } + //濡傛灉鏄儹寰幆鎴栬�呮槸娓╁崌璇曢獙 + else if (product.getInspectionItem().equals("鐑惊鐜�") || product.getInspectionItem().equals("娓╁崌璇曢獙")) { + //鏌ヨ杩欎簺椤圭洰涓嬬殑鍏朵粬妫�楠岄」鐩槸鍚﹀叏閮ㄦ楠� + List<InsProduct> insProductList = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery() + .eq(InsProduct::getInsSampleId, product.getInsSampleId()) + .like(InsProduct::getInspectionItemSubclass, "娓╁害")); + List<Integer> collect = insProductList.stream().filter(insProduct -> insProduct.getInsResult() != null).map(InsProduct::getInsResult).collect(Collectors.toList()); + List<Integer> tt = new ArrayList<>(); + tt.add(1); + if (collect.contains(0)) { + product.setLastValue("涓嶅悎鏍�"); + product.setInsResult(0); + } else if (collect.size() == insProductList.size() && collect.stream().distinct().collect(Collectors.toList()).containsAll(tt)) { + product.setLastValue("鍚堟牸"); + product.setInsResult(1); + } + insProductMapper.updateById(product); + } + //濡傛灉鏄數鍔涚殑搴斿姏搴斿彉妫�楠岄」鐩垨鑰呮槸鐤插姵璇曢獙,缁撹鏀规垚涓嶅垽瀹� + else if (product.getInspectionItem().equals("搴斿姏搴斿彉") || product.getInspectionItem().contains("鐤插姵璇曢獙")){ + product.setInsResult(3); + insProductMapper.updateById(product); + } + //濡傛灉鏄槻鎸敜鍔熺巼鐗规�ц瘯楠� + else if (product.getInspectionItem().equals("闃叉尟閿ゅ姛鐜囩壒鎬ц瘯楠�")){ + product.setInsResult(1);//榛樿鍚堟牸 + //闇�瑕佸幓鍒ゆ柇濉啓鐨勬楠屾暟鎹槸鍚︽湁涓嶅悎鏍� + InsProductResult insProductResult = insProductResultMapper.selectOne(Wrappers.<InsProductResult>lambdaQuery().eq(InsProductResult::getInsProductId, product.getId())); + cn.hutool.json.JSONObject jsonObject = new cn.hutool.json.JSONObject(insProductResult.getComValue()); + // 妫�鏌� arr2 + cn.hutool.json.JSONArray arr2 = jsonObject.getJSONArray("arr2"); + for (int i = 0; i < arr2.size(); i++) { + cn.hutool.json.JSONObject obj = arr2.getJSONObject(i); + if (obj.getInt("state") == 2) { + product.setInsResult(0); + break; + } + } + // 妫�鏌� arr3 + cn.hutool.json.JSONArray arr3 = jsonObject.getJSONArray("arr3"); + for (int i = 0; i < arr3.size(); i++) { + cn.hutool.json.JSONObject obj = arr3.getJSONObject(i); + if (obj.getInt("state") == 2) { + product.setInsResult(0); + break; + } + } + insProductMapper.updateById(product); + } + else { + String notDetected = product.getInspectionItem() + " " + product.getInspectionItemSubclass(); + if(!set.contains(notDetected)) { + count++; + str += "<br/>" + count + "锛�" + product.getInspectionItem() + " " + product.getInspectionItemSubclass() + "<br/>"; + set.add(notDetected); + } + + } + } + if (ObjectUtils.isNotEmpty(str)) { + throw new ErrorException("<strong>瀛樺湪寰呮楠岀殑椤圭洰锛�</strong><br/>" + str); + } + } + insOrderStateMapper.update(null, Wrappers.<InsOrderState>lambdaUpdate().eq(InsOrderState::getInsOrderId, orderId).eq(InsOrderState::getLaboratory, laboratory).set(InsOrderState::getInsTime, LocalDateTime.now()).set(InsOrderState::getInsState, 3).set(InsOrderState::getVerifyUser, verifyUser)); + Integer userId = SecurityUtils.getUserId().intValue(); + InformationNotification info = new InformationNotification(); + info.setCreateUser(insProductMapper.selectUserById(userId).get("name")); + info.setMessageType("2"); + info.setTheme("澶嶆牳閫氱煡"); + info.setContent("鎮ㄦ湁涓�鏉℃楠屼换鍔″緟澶嶆牳娑堟伅"); + info.setSenderId(userId); + info.setConsigneeId(verifyUser); + info.setViewStatus(false); + info.setJumpPath("b1-inspect-order-plan"); + informationNotificationService.addInformationNotification(info); + //澶嶆牳浜�--妫�楠屽崟鐩稿叧璐熻矗浜� + InsSampleUser insSampleUser = new InsSampleUser(); + insSampleUser.setUserId(verifyUser); + insSampleUser.setInsSampleId(orderId); + insSampleUser.setState(1); + insSampleUser.setSonLaboratory(laboratory); + insSampleUserMapper.insert(insSampleUser); + /*鏍¢獙涓�涓媟esult琛�*/ + CompletableFuture.supplyAsync(() -> { + List<Integer> ips = insProducts.stream().map(InsProduct::getId).distinct().collect(Collectors.toList()); + for (Integer ip : ips) { + List<InsProductResult> insProductResults = insProductResultMapper.selectList(Wrappers.<InsProductResult>lambdaQuery() + .eq(InsProductResult::getInsProductId, ip)); + if (insProductResults.size() > 1) { + for (int i = 1; i < insProductResults.size(); i++) { + insProductResultMapper.deleteById(insProductResults.get(i)); + } + } + } + return null; + }); + // 鍒犻櫎鏁伴噰閲囬泦娆℃暟 + String key = "frequency" + ":" + entrustCode + ":*"; + RedisUtil.delsLike(key); + return 1; + } + + @Override + public List<String> getEquipName(Integer orderId,String sonLaboratory) { + List<Integer> ids = insSampleMapper.selectList(new LambdaQueryWrapper<InsSample>() + .eq(InsSample::getInsOrderId, orderId)) + .stream() + .map(InsSample::getId) + .collect(Collectors.toList()); + // 鏌ョ湅鍗曞瓙鏄惁閫夋嫨浜嗚澶� + List<String> strList = new ArrayList<>(); + HashSet<String> set = new HashSet<>(); + List<InsProduct> productList = insProductMapper.selectList(new LambdaQueryWrapper<InsProduct>() + .in(InsProduct::getInsSampleId, ids) + .eq(InsProduct::getSonLaboratory, sonLaboratory) + .eq(InsProduct::getState, 1)); + if (CollectionUtils.isNotEmpty(productList)) { + List<InsProduct> collect = productList.stream() + .filter(item -> Objects.isNull(item.getSpecialItemParentId()) || StringUtils.isEmpty(item.getSpecialItemParentId()+"")) + .collect(Collectors.toList()); + for (InsProduct product : collect) { + InsProductResult insProductResult = insProductResultMapper.selectOne(new LambdaQueryWrapper<InsProductResult>() + .eq(InsProductResult::getInsProductId, product.getId())); + if(Objects.nonNull(insProductResult)){ + if(Objects.isNull(insProductResult.getEquipName()) || StringUtils.isEmpty(insProductResult.getEquipName())) { + strList.add(product.getInspectionItem() + " " + product.getInspectionItemSubclass()); + }else { + List<Map> maps = JSONArray.parseArray(insProductResult.getEquipName(), Map.class); + if(CollectionUtils.isNotEmpty(maps)) { + List<Map> mapList = maps.stream().filter(item -> StringUtils.isEmpty(item.get("v") + "")).collect(Collectors.toList()); + if(mapList.size() == maps.size()) { + strList.add(product.getInspectionItem() + " " + product.getInspectionItemSubclass()); + } +// for (Map map : maps) { +// if(StringUtils.isEmpty(map.get("v")+"")){ +// strList.add(product.getInspectionItem() + " " + product.getInspectionItemSubclass()); +// } +// } + }else { + strList.add(product.getInspectionItem() + " " + product.getInspectionItemSubclass()); + } + } + } + } + } + + return strList.stream().distinct().collect(Collectors.toList()); + } + + @Override + @Transactional(rollbackFor = Exception.class,isolation = Isolation.READ_COMMITTED) + public int saveInsContext2(InsProductResultDTO insProductResult) { + Integer userId = SecurityUtils.getUserId().intValue(); + try { + //妫�楠岀粨鏋� + Map<String,Object> insValueMap = JackSonUtil.unmarshal(insProductResult.getInsValue(), Map.class); + //saveInsContext2鏂规硶鏈夊涓ā鏉胯皟鐢紝闇�鏍规嵁妯℃澘鍚嶇О鍒嗗紑澶勭悊 + switch (insProductResult.getTemplateName()){ + case "鏋剁┖鍦扮嚎搴斿姏搴斿彉": + //淇濆瓨寮规�фā閲忓拰妫�楠岀粨璁� + if(Objects.nonNull(insValueMap.get("elasticityModulus"))){ + String elasticityModulus = insValueMap.get("elasticityModulus").toString(); + insProductMapper.update(null,Wrappers.<InsProduct>lambdaUpdate() + .set(InsProduct::getInsResult,3)//缁撹璁句负涓嶅垽瀹� + .set(InsProduct::getElasticityModulus,elasticityModulus) + .eq(InsProduct::getId,insProductResult.getInsProductId()) + ); + } + //鍒犻櫎寮规�фā閲弅ey + insValueMap.remove("elasticityModulus"); + insProductResult.setInsValue(JackSonUtil.marshal(insValueMap)); + break; + case "鐤插姵璇曢獙": + //淇濆瓨妫�楠岀粨鏋� + if(Objects.nonNull(insValueMap.get("damage"))){ + String damage = insValueMap.get("damage").toString(); + Integer insResult = "绗﹀悎".equals(damage)?1:0; + insProductMapper.update(null,Wrappers.<InsProduct>lambdaUpdate() + .set(InsProduct::getInsResult,insResult) + .set(InsProduct::getLastValue,damage) + .eq(InsProduct::getId,insProductResult.getInsProductId()) + ); + } + break; + } + List<InsProductResult> oldResults = new ArrayList<>(); + InsProductResult insProductResult1 = insProductResultMapper.selectOne(new LambdaQueryWrapper<InsProductResult>().eq(InsProductResult::getInsProductId, insProductResult.getInsProductId())); + //鏂板鎴栨洿鏂版楠岃褰� + if (ObjectUtils.isNull(insProductResult1)){ + insProductResultMapper.insert(insProductResult); + }else { + insProductResult.setId(insProductResult1.getId()); + oldResults.add(insProductResult1); + insProductResultMapper.updateById(insProductResult); + } + //娣诲姞宸ユ椂璁板綍 + InsOrder insOrder = insOrderMapper.selectById(insProductResult.getOrderId()); + InsSample insSample = insSampleMapper.selectById(insProductResult.getSampleId()); + InsProduct insProduct = insProductMapper.selectById(insProductResult.getInsProductId()); + InsProductResult newInsResult = new InsProductResult(); + BeanUtil.copyProperties(insProductResult,newInsResult); + WorkTimeDTO workTimeDTO = new WorkTimeDTO(userId,insOrder,insSample,insProduct,null,insProductResult.getSampleId(), String.valueOf(insProductResult.getInsProductId()),oldResults ,newInsResult); + String jsonStr = JackSonUtil.marshal(workTimeDTO); + //璁$畻宸ユ椂 + //TODO:璇ユ柟娉曠洰鍓嶅彧鏈夌數鍔涚敤锛岄粯璁よ矾鐢变娇鐢ㄧ數鍔涚殑 + sendQueueMessage(ExchangeConstants.WORK_TIME_EXCHANGE,RouterKeyConstants.DL_KEY,jsonStr); + }catch (Exception e){ + throw new RuntimeException(e); + } + return 0; + } + + // 鑾峰彇涓や釜localDateTime鐨勬瘡涓�澶� + public static List<LocalDateTime> getLocalDateTimesBetween(LocalDateTime start, LocalDateTime end) { + List<LocalDateTime> localDateTimes = new ArrayList<>(); + LocalDate currentDate = start.toLocalDate(); + LocalDateTime currentLocalDateTime = start; + while (!currentDate.isAfter(end.toLocalDate())) { + localDateTimes.add(currentLocalDateTime); + currentLocalDateTime = currentLocalDateTime.plusDays(1); + currentDate = currentDate.plusDays(1); + } + return localDateTimes; + } + + /** + * 鏌ヨ妫�楠岄」瀵瑰簲鏍囧噯搴撻厤缃殑宸ユ椂淇℃伅 + * @param insProduct + * @return + */ + public StandardProductVO getInspectWorkHourAndGroup(InsProduct insProduct){ + StandardProductVO standardProductVO = new StandardProductVO(); + if(!Objects.isNull(insProduct)){ + //鏌ヨ瀵瑰簲鏍囧噯搴� + List<StandardProductVO> productVO = standardProductListMapper.getStandardProductByInsProduct( + insProduct.getLaboratory(), + insProduct.getSampleType(), + insProduct.getSample(), + insProduct.getModel(), + insProduct.getInspectionItem(), + insProduct.getInspectionItemSubclass(), + insProduct.getSonLaboratory(), + insProduct.getStandardMethodListId()); + if(!productVO.isEmpty()){ + standardProductVO = productVO.get(0); + } + //鏈夊尯闂寸殑妫�楠岄」锛屽彇妫�楠岄」瀛樼殑宸ユ椂淇℃伅 + if(StringUtils.isNotBlank(insProduct.getSection()) && StringUtils.isNotBlank(standardProductVO.getSection())){ + try { + ObjectMapper objectMapper = new ObjectMapper(); + //鍖洪棿璁剧疆 + List<String> sectionList = (List<String>)objectMapper.readValue(standardProductVO.getSection(), List.class); + //閫変腑鍖洪棿鐨勪笅鏍� + int i = sectionList.indexOf(insProduct.getSection()); + //鑾峰彇瀵瑰簲涓嬫爣鐨勫伐鏃跺拰宸ユ椂鍒嗙粍 + List<Double> hourList = (List<Double>)objectMapper.readValue(standardProductVO.getManHour(), List.class); + standardProductVO.setManHour(String.valueOf(hourList.get(i))); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + } + } + return standardProductVO; + } + + public static String getWeek(String dayStr) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + try { + Date date = sdf.parse(dayStr); + Calendar calendar = Calendar.getInstance(); + calendar.setTime(date); + int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); + int day = calendar.get(Calendar.DAY_OF_MONTH); + return getWeekDay(dayOfWeek); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + + public static String getWeekDay(int dayOfWeek) { + switch (dayOfWeek) { + case Calendar.MONDAY: + return "鍛ㄤ竴"; + case Calendar.TUESDAY: + return "鍛ㄤ簩"; + case Calendar.WEDNESDAY: + return "鍛ㄤ笁"; + case Calendar.THURSDAY: + return "鍛ㄥ洓"; + case Calendar.FRIDAY: + return "鍛ㄤ簲"; + case Calendar.SATURDAY: + return "鍛ㄥ叚"; + case Calendar.SUNDAY: + return "鍛ㄦ棩"; + default: + return "鏈煡"; + } + } + +} -- Gitblit v1.9.3