From a5b1bad21ba279ade3954852a5e281e9086042f0 Mon Sep 17 00:00:00 2001 From: zss <zss@example.com> Date: 星期二, 26 十一月 2024 15:22:52 +0800 Subject: [PATCH] 前端联调修改2.0 --- inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderServiceImpl.java | 773 +++++++++++++++++++++++++++++++++-------------------------- 1 files changed, 431 insertions(+), 342 deletions(-) diff --git a/inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderServiceImpl.java b/inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderServiceImpl.java index 103b180..add542c 100644 --- a/inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderServiceImpl.java +++ b/inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderServiceImpl.java @@ -1,9 +1,16 @@ package com.yuanchu.mom.service.impl; +import cn.hutool.core.lang.UUID; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; +import com.alibaba.excel.EasyExcel; +import com.alibaba.excel.ExcelWriter; +import com.alibaba.excel.write.metadata.WriteSheet; +import com.alibaba.excel.write.style.column.SimpleColumnWidthStyleStrategy; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; 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; @@ -14,25 +21,34 @@ import com.yuanchu.mom.exception.ErrorException; import com.yuanchu.mom.mapper.*; import com.yuanchu.mom.pojo.*; +import com.yuanchu.mom.service.InformationNotificationService; +import com.yuanchu.mom.service.InsOrderPlanService; import com.yuanchu.mom.service.InsOrderService; import com.yuanchu.mom.service.InsProductService; import com.yuanchu.mom.utils.GiveCode; +import com.yuanchu.mom.utils.QYWXApi; import com.yuanchu.mom.utils.QueryWrappers; import com.yuanchu.mom.vo.SampleDefectsFatherVo; import lombok.AllArgsConstructor; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.multipart.MultipartFile; +import javax.annotation.Resource; +import javax.servlet.http.HttpServletResponse; +import java.io.File; +import java.io.IOException; +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.net.URLEncoder; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.*; -import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicInteger; -import java.util.function.Function; -import java.util.function.Predicate; import java.util.stream.Collectors; /** @@ -41,36 +57,45 @@ * @createDate 2024-03-12 16:17:55 */ @Service -@AllArgsConstructor -public class InsOrderServiceImpl extends ServiceImpl<InsOrderMapper, InsOrder> - implements InsOrderService { +@Transactional(rollbackFor = Exception.class) +public class InsOrderServiceImpl extends ServiceImpl<InsOrderMapper, InsOrder> implements InsOrderService { + @Resource private GetLook getLook; - + @Resource + private RoleMapper roleMapper; + @Resource private InsOrderMapper insOrderMapper; + @Value("${file.path}") + private String imgUrl; + + @Value("${wordUrl}") + private String wordUrl; + @Resource + private InsOrderFileMapper insOrderFileMapper; + @Resource private InsSampleMapper insSampleMapper; - + @Resource + InsProductResult2Mapper insProductResult2Mapper; + @Resource + InsProductResultMapper insProductResultMapper; + @Resource private InsProductMapper insProductMapper; - private InsProductService insProductService; - + @Resource + private InsProductUserMapper insProductUserMapper; + @Resource private GiveCode giveCode; - - private InsSampleUserMapper insSampleUserMapper; - - private InsOrderStateMapper insOrderStateMapper; - + @Resource UserMapper userMapper; - + @Resource + InformationNotificationService informationNotificationService; + @Resource PowerMapper powerMapper; - - private InsBushingMapper insBushingMapper; - - private InsFibersMapper insFibersMapper; - - private InsFiberMapper insFiberMapper; - + @Resource CustomMapper customMapper; + @Resource + QYWXApi qywxApi; //鑾峰彇妫�楠屼笅鍗曟暟鎹� @@ -82,19 +107,9 @@ Map<String, Integer> map1 = getLook.selectPowerByMethodAndUserId("selectInsOrderParameter"); User user = userMapper.selectById(map1.get("userId"));//褰撳墠鐧诲綍鐨勪汉 Integer roleId = user.getRoleId(); - //鑾峰彇褰撳墠浜烘墍灞炲疄楠屽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; - } - } + String laboratory = null; //鍒ゆ柇鏄惁鏄叏閮ㄦ潈闄� - Power power = powerMapper.selectOne(Wrappers.<Power>lambdaQuery().eq(Power::getRoleId, roleId).eq(Power::getMenuMethod, "selectAllInsOrder")); + Power power = powerMapper.selectOne(Wrappers.<Power>lambdaQuery().eq(Power::getRoleId, roleId).eq(Power::getMenuMethod, "selectAllInsOrderParameter")); if (ObjectUtils.isEmpty(power)) { if (map1.get("look") == 1) { //涓汉 @@ -108,90 +123,60 @@ } } } - map.put("body", insOrderMapper.selectInsOrderPage(page, QueryWrappers.queryWrappers(sampleOrderDto),laboratory)); + IPage<SampleOrderDto> sampleOrderDtoIPage = insOrderMapper.selectInsOrderPage(page, QueryWrappers.queryWrappers(sampleOrderDto), laboratory); + sampleOrderDtoIPage.getRecords().forEach(i -> { + if (ObjectUtils.isNotEmpty(i.getSampleCode()) && i.getSampleCode().contains("锛�")) { + String[] split = i.getSampleCode().split("锛�"); + i.setSampleCode(split[0]); + } + }); + map.put("body", sampleOrderDtoIPage); return map; } @Override @Transactional(rollbackFor = Exception.class) - public int upInsOrder(Integer orderId, Integer sampleId, String appointed, Integer userId) { - InsOrder insOrder = new InsOrder(); - insOrder.setId(orderId); - insOrder.setAppointed(LocalDate.parse(appointed)); - insOrder.setSendTime(LocalDateTime.now()); - insOrderMapper.updateById(insOrder); - 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::getState, 1).isNull(InsProduct::getInsFibersId).isNull(InsProduct::getInsFiberId).select(InsProduct::getSonLaboratory).groupBy(InsProduct::getSonLaboratory)); - for (InsProduct insProduct : insProducts) { - InsOrderState insOrderState = new InsOrderState(); - insOrderState.setInsOrderId(orderId); - try { - insOrderState.setLaboratory(insProduct.getSonLaboratory()); - } catch (NullPointerException e) { - throw new ErrorException("璇ユ楠屽崟鏈夋湭缁存姢瀹為獙瀹ょ殑妫�楠岄」鐩�"); - } - insOrderState.setInsState(0); - insOrderStateMapper.insert(insOrderState); - } - if (userId != null) { - InsSampleUser insSampleUser = new InsSampleUser(); - insSampleUser.setState(0); - insSampleUser.setUserId(userId); - insSampleUser.setInsSampleId(orderId); - insSampleUserMapper.insert(insSampleUser); - } - return 1; - } - - @Override - @Transactional(rollbackFor = Exception.class) - public int addInsOrder(List<SampleProductDto> list, InsOrder insOrder, List<List<Integer>> pairing) { + public int addInsOrder(List<SampleProductDto> list, InsOrder insOrder, List<List<Integer>> pairing, List<MultipartFile> files) { insOrder.setState(0); - String code = customMapper.selectById(insOrder.getCompanyId()).getCode2(); - //insOrder.setEntrustCode(giveCode.giveCode("JCZX-" + code + "-", "ins_order", "", "yyMMdd")); - String giveCode = this.giveCode.giveCode("JCZX-" + code + "-", "ins_order", "", "yyMMdd"); + //鍒ゆ柇閫夋嫨鐨勫鎵樺崟浣嶄笌鍒跺崟浜虹殑濮旀墭鍗曚綅鏄惁涓�鑷� + Integer userId = getLook.selectPowerByMethodAndUserId(null).get("userId"); + String company = userMapper.selectById(userId).getCompany(); + if (!company.equals(insOrder.getCompanyId() + "")) { + //濡傛灉涓嶄竴鑷撮偅涔堝鎵樹汉瀛楁蹇呭~ + if (ObjectUtils.isEmpty(insOrder.getPrepareUser())) { + throw new ErrorException("濮旀墭浜轰笉鑳戒负绌�"); + } + } else { + //濡傛灉涓�鑷�,閭d箞鍒跺崟浜哄氨鏄鎵樹汉 + insOrder.setPrepareUser(insOrder.getCustom()); + } + //瀹㈡埛浠e彿 + Custom custom = customMapper.selectById(insOrder.getCompanyId()); + String code = custom.getCode2(); + if (!custom.getCompany().equals(insOrder.getCompany())) { + Custom one = customMapper.selectOne(Wrappers.<Custom>lambdaQuery().eq(Custom::getCompany, insOrder.getCompany())); + insOrder.setCompanyId(one.getId()); + code = one.getCode2(); + } + //澶栭儴濮旀墭缂栧彿 + insOrder.setOutEntrustCode(giveCode.giveCode("WT-", "ins_order", "-", "yyMMdd")); + String giveCode = this.giveCode.giveCode("JCZX-" + code + "-", "ins_sample", "", "yyMMdd"); insOrderMapper.insert(insOrder); AtomicInteger count = new AtomicInteger(); list.forEach(a -> { count.getAndIncrement(); a.setId(null); a.setInsOrderId(insOrder.getId()); + //鏍峰搧缂栧彿 if (StrUtil.isEmpty(a.getSampleCode())) { - a.setSampleCode(giveCode.split("-")[2] + "-" + count.get()); + a.setSampleCode("YP-" + a.getModel() + "-" + giveCode.split("-")[2] + "-" + count.get()); } insSampleMapper.insert(a); + //鏍峰搧鐨勬楠岄」鐩� if (ObjectUtil.isNotEmpty(a.getInsProduct())) { - addInsProductMethod(a.getId(), a.getInsProduct(), null, 0, false); - if (ObjectUtil.isNotEmpty(a.getBushing())) { - for (BushingDto bushingDto : a.getBushing()) { - bushingDto.setInsSampleId(a.getId()); - insBushingMapper.insert(bushingDto); - if (bushingDto.getFiber().size() != 0) { - for (FiberDto fiberDto : bushingDto.getFiber()) { - fiberDto.setInsBushingId(bushingDto.getId()); - insFiberMapper.insert(fiberDto); - addInsProductMethod(a.getId(), a.getInsProduct(), fiberDto.getId(), 2, true); - addInsProductMethod(a.getId(), fiberDto.getProductList(), fiberDto.getId(), 2, false); - } - } else { - for (FibersDto fibersDto : bushingDto.getFibers()) { - fibersDto.setInsBushingId(bushingDto.getId()); - fibersDto.setCode(this.giveCode.giveCode("", "ins_fibers", "", "yyMMdd")); - insFibersMapper.insert(fibersDto); - for (FiberDto fiberDto : fibersDto.getFiber()) { - fiberDto.setInsFibersId(fibersDto.getId()); - insFiberMapper.insert(fiberDto); - addInsProductMethod(a.getId(), a.getInsProduct(), fiberDto.getId(), 2, true); - addInsProductMethod(a.getId(), fiberDto.getProductList(), fiberDto.getId(), 2, false); - } - //addInsProductMethod(a.getId(), a.getInsProduct(), fibersDto.getId(), 1); - addInsProductMethod(a.getId(), fibersDto.getProductList(), fibersDto.getId(), 1, false); - } - } - } - } + addInsProductMethod(a.getId(), a.getInsProduct()); } + //鏍峰搧鐨勬楠屾爣鍑� if (ObjectUtil.isNotEmpty(a.getInsulating())) { List<InsProduct> ip2 = new ArrayList<>(); for (Integer i = 0; i < a.getInsulating().getNum(); i++) { @@ -200,14 +185,16 @@ for (InsProduct product : ip2) { product.setStandardMethodListId(a.getInsulating().getStandardMethodListId()); } - addInsProductMethod(a.getId(), ip2, null, 0, false); + addInsProductMethod(a.getId(), ip2); } + //鏍峰搧鐨勬楠屾爣鍑� if (ObjectUtil.isNotEmpty(a.getSheath())) { for (InsProduct product : a.getSheath().getInsProduct()) { product.setStandardMethodListId(a.getSheath().getStandardMethodListId()); } - addInsProductMethod(a.getId(), a.getSheath().getInsProduct(), null, 0, false); + addInsProductMethod(a.getId(), a.getSheath().getInsProduct()); } + //瀛愭牱鍝侀厤缃� if (ObjectUtil.isNotEmpty(a.getChildSampleList())) { for (SampleProductDto b : a.getChildSampleList()) { for (int i = 0; i < b.getNum(); i++) { @@ -219,201 +206,163 @@ } insSampleMapper.insert(b); if (ObjectUtil.isNotEmpty(b.getInsProduct())) { - addInsProductMethod(b.getId(), b.getInsProduct(), null, 0, false); + addInsProductMethod(b.getId(), b.getInsProduct()); } } } } - if (ObjectUtil.isEmpty(a.getInsProduct()) && ObjectUtil.isNotEmpty(a.getBushing())) { - for (BushingDto bushingDto : a.getBushing()) { - bushingDto.setInsSampleId(a.getId()); - insBushingMapper.insert(bushingDto); - if (bushingDto.getFiber().size() != 0) { - for (FiberDto fiberDto : bushingDto.getFiber()) { - fiberDto.setInsBushingId(bushingDto.getId()); - insFiberMapper.insert(fiberDto); - addInsProductMethod(a.getId(), fiberDto.getProductList(), fiberDto.getId(), 2, false); - } - } else { - for (FibersDto fibersDto : bushingDto.getFibers()) { - fibersDto.setInsBushingId(bushingDto.getId()); - fibersDto.setCode(this.giveCode.giveCode("", "ins_fibers", "", "yyMMdd")); - insFibersMapper.insert(fibersDto); - for (FiberDto fiberDto : fibersDto.getFiber()) { - fiberDto.setInsFibersId(fibersDto.getId()); - insFiberMapper.insert(fiberDto); - addInsProductMethod(a.getId(), fiberDto.getProductList(), fiberDto.getId(), 2, false); - } - addInsProductMethod(a.getId(), fibersDto.getProductList(), fibersDto.getId(), 1, false); - } - } - } - } + }); - for (List<Integer> i : pairing) { - SampleProductDto sample = JSON.parseObject(JSON.toJSONString(list.get(i.get(0) - 1)), SampleProductDto.class); - sample.setSampleCode(list.get(i.get(0) - 1).getSampleCode() + "/" + list.get(i.get(1) - 1).getSampleCode()); - sample.setId(null); - insSampleMapper.insert(sample); - try { - List<InsProduct> insProducts = sample.getInsProduct().stream().filter(a -> Objects.equals(a.getInspectionItem(), "鍏夌氦鎺ュご鎹熻��")).collect(Collectors.toList()); - for (InsProduct insProduct : insProducts) { - insProduct.setId(null); - insProduct.setInsSampleId(sample.getId()); - insProductMapper.insert(insProduct); - } - } catch (Exception e) { + List<User> users1 = userMapper.getUserByRole("妫�娴嬩腑蹇冧富浠�"); + List<User> users2 = userMapper.getUserByRole("鐮斿彂閮ㄧ粡鐞�"); + List<User> users3 = userMapper.getUserByRole("鎶�鏈礋璐d汉"); + //閫氫俊:濡傛灉鏄疌绫昏鍗曟棤闇�瀹℃牳鐩存帴閫氳繃 + if (insOrder.getOrderType().equals("C")) { + insOrder.setState(1); + upInsOrderOfState(insOrder); + } else if (insOrder.getOrderType().equals("A")) { + //甯歌澶栭儴鍗曢渶娑堟伅鎻愰啋妫�楠屼腑蹇冧富浠诲拰鐮斿彂閮ㄧ粡鐞� + //todo 浼佷笟寰俊鎺ㄩ�� + users1.addAll(users2); + String account = users1.stream().map(User::getAccount).collect(Collectors.joining("|")); + HashMap<String, Object> map = new HashMap<>(); + map.put("touser", account);//鎺ユ敹娑堟伅鎴愬憳鐨勮处鍙�'ZT-031292'杩欑绫诲瀷(濡傛灉鏈夊涓敤'|'鍒嗛殧) + map.put("msgtype", "text");//娑堟伅绫诲瀷 text:鏂囨湰 + map.put("agentid", 1000517);//搴旂敤id + HashMap<String, Object> hashMap = new HashMap<>(); + hashMap.put("content", "鎮ㄦ湁涓�鏉℃楠岃鍗曢渶瑕佸鏍�,璇峰墠寰�LIMS绯荤粺鏌ョ湅銆傚閮ㄨ鍗曞彿鏄細" + insOrder.getOutEntrustCode() + ",璇峰墠寰�LIMS绯荤粺鏌ョ湅銆�<a href=\"https://ztwxlims.ztt.cn:7443/enter\">涓ぉ閫氫俊LIMS绯荤粺 </a>"); + map.put("text", hashMap);//娑堟伅鍐呭 + map.put("safe", 0);//鏄惁淇濆瘑娑堟伅.0鍚� + map.put("enable_id_trans", 0);//鏄惁寮�鍚痠d杞瘧.0鍚� + map.put("enable_duplicate_check", 0);//鏄惁寮�鍚噸澶嶆秷鎭鏌�.0鍚� + qywxApi.send(map); + //lims娑堟伅鎻愰啋 + ArrayList<InformationNotification> notificationArrayList = new ArrayList<>(); + for (User user : users1) { + InformationNotification info = new InformationNotification(); + info.setCreateUser(userMapper.selectById(userId).getName()); + info.setMessageType("2"); + info.setTheme("瀹℃牳閫氱煡"); + info.setContent("鎮ㄦ湁涓�鏉℃楠岃鍗曞緟瀹℃牳娑堟伅,璁㈠崟鐨勫閮ㄧ紪鍙锋槸:" + insOrder.getOutEntrustCode()); + info.setSenderId(userId); + info.setViewStatus(false); + info.setJumpPath("b1-inspection-order"); + info.setConsigneeId(user.getId()); + notificationArrayList.add(info); } + informationNotificationService.saveBatch(notificationArrayList); + } else if (insOrder.getOrderType().equals("B")) { + //闈炲父瑙勫閮ㄥ崟闇�娑堟伅鎻愰啋妫�楠屼腑蹇冧富浠�,鐮斿彂閮ㄧ粡鐞嗗拰鎶�鏈礋璐d汉 + //todo 浼佷笟寰俊鎺ㄩ�� + users1.addAll(users2); + users1.addAll(users3); + String account = users1.stream().map(User::getAccount).collect(Collectors.joining("|")); + HashMap<String, Object> map = new HashMap<>(); + map.put("touser", account);//鎺ユ敹娑堟伅鎴愬憳鐨勮处鍙�'ZT-031292'杩欑绫诲瀷(濡傛灉鏈夊涓敤'|'鍒嗛殧) + map.put("msgtype", "text");//娑堟伅绫诲瀷 text:鏂囨湰 + map.put("agentid", 1000517);//搴旂敤id + HashMap<String, Object> hashMap = new HashMap<>(); + hashMap.put("content", "鎮ㄦ湁涓�鏉℃楠岃鍗曢渶瑕佸鏍�,璇峰墠寰�LIMS绯荤粺鏌ョ湅銆傚閮ㄨ鍗曞彿鏄細" + insOrder.getOutEntrustCode() + ",璇峰墠寰�LIMS绯荤粺鏌ョ湅銆�<a href=\"https://ztwxlims.ztt.cn:7443/enter\">涓ぉ閫氫俊LIMS绯荤粺 </a>"); + map.put("text", hashMap);//娑堟伅鍐呭 + map.put("safe", 0);//鏄惁淇濆瘑娑堟伅.0鍚� + map.put("enable_id_trans", 0);//鏄惁寮�鍚痠d杞瘧.0鍚� + map.put("enable_duplicate_check", 0);//鏄惁寮�鍚噸澶嶆秷鎭鏌�.0鍚� + qywxApi.send(map); + //lims娑堟伅鎻愰啋 + ArrayList<InformationNotification> notificationArrayList = new ArrayList<>(); + for (User user : users1) { + InformationNotification info = new InformationNotification(); + info.setCreateUser(userMapper.selectById(userId).getName()); + info.setMessageType("2"); + info.setTheme("瀹℃牳閫氱煡"); + info.setContent("鎮ㄦ湁涓�鏉℃楠岃鍗曞緟瀹℃牳娑堟伅,璁㈠崟鐨勫閮ㄧ紪鍙锋槸:" + insOrder.getOutEntrustCode()); + info.setSenderId(userId); + info.setViewStatus(false); + info.setJumpPath("b1-inspection-order"); + info.setConsigneeId(user.getId()); + notificationArrayList.add(info); + } + informationNotificationService.saveBatch(notificationArrayList); + } + //濡傛灉鏈変笂浼犵殑闄勪欢 + if (CollectionUtils.isNotEmpty(files)) { + for (MultipartFile file : files) { + String urlString; + String pathName; + String path; + String filename = file.getOriginalFilename(); + String contentType = file.getContentType(); + InsOrderFile insOrderFile = new InsOrderFile(); + insOrderFile.setInsOrderId(insOrder.getId()); + 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().replace("#", "&"); + urlString = realpath + "/" + pathName; + file.transferTo(new File(urlString)); + insOrderFile.setFileUrl(pathName); + insOrderFileMapper.insert(insOrderFile); + } catch (Exception e) { + e.printStackTrace(); + System.err.println("闄勪欢涓婁紶閿欒"); + } + } + } + //todo 鏍规嵁璁㈠崟绫诲瀷鍒ゆ柇鏄惁闇�瑕佹帹閫佷紒涓氬井淇� @zss + if (!insOrder.getFormType().equals("鍏朵粬鎴愬搧")) { + String account = userMapper.selectById(insOrder.getIssueUser()).getAccount(); + HashMap<String, Object> map = new HashMap<>(); + map.put("touser", account);//鎺ユ敹娑堟伅鎴愬憳鐨勮处鍙�'ZT-031292'杩欑绫诲瀷(濡傛灉鏈夊涓敤'|'鍒嗛殧) + map.put("msgtype", "text");//娑堟伅绫诲瀷 text:鏂囨湰 + map.put("agentid", 1000517);//搴旂敤id + HashMap<String, Object> hashMap = new HashMap<>(); + hashMap.put("content", "鎮ㄦ湁涓�鏉¤鍗曢渶瑕佸畬鎴�,璇峰墠寰�LIMS绯荤粺鏌ョ湅銆傚閮ㄨ鍗曞彿鏄細" + insOrder.getOutEntrustCode() + ",璇峰墠寰�LIMS绯荤粺鏌ョ湅銆�<a href=\"https://ztwxlims.ztt.cn:7443/enter\">涓ぉ閫氫俊LIMS绯荤粺 </a>"); + map.put("text", hashMap);//娑堟伅鍐呭 + map.put("safe", 0);//鏄惁淇濆瘑娑堟伅.0鍚� + map.put("enable_id_trans", 0);//鏄惁寮�鍚痠d杞瘧.0鍚� + map.put("enable_duplicate_check", 0);//鏄惁寮�鍚噸澶嶆秷鎭鏌�.0鍚� + qywxApi.send(map); + + //LIMS绯荤粺娑堟伅鎺ㄩ�� + InformationNotification info = new InformationNotification(); + info.setCreateUser(insProductMapper.selectUserById(userId).get("name")); + info.setMessageType("1"); + info.setTheme("鏍锋満鍛橀�氱煡"); + info.setContent("鎮ㄦ湁涓�鏉℃楠岃鍗曠殑鏍锋満寰呭畬鎴愭秷鎭�,澶栭儴璁㈠崟鍙锋槸锛�" + insOrder.getOutEntrustCode() + ",璇峰墠寰�LIMS绯荤粺鏌ョ湅銆�"); + info.setSenderId(userId); + info.setConsigneeId(insOrder.getIssueUser()); + info.setViewStatus(false); + info.setJumpPath("b1-inspection-order"); + informationNotificationService.addInformationNotification(info); } return insOrder.getId(); } - private void addInsProductMethod(Integer sampleId, List<InsProduct> productList, Integer id, Integer type, Boolean is) { - InsOrder insOrder = insOrderMapper.selectById(insSampleMapper.selectById(sampleId).getInsOrderId()); + private void addInsProductMethod(Integer sampleId, List<InsProduct> productList) { for (InsProduct product : productList) { - if (product.getState() == 1 && !product.getInspectionItem().equals("鍏夌氦鎺ュご鎹熻��")) { - //鍒ゆ柇鍏夌紗鐨勬俯搴﹀惊鐜」鐩坊鍔� - if (insOrder.getSampleType().equals("鍏夌紗") && product.getInspectionItem().equals("娓╁害寰幆") && type != 0) { - List<InsProduct> insProductes = new ArrayList<>(); - List<InsProduct> insProducts = new ArrayList<>(); - String[] strings = product.getAsk().split(";"); - - for (int i = 0; i < strings.length; i++) { - int count = Integer.parseInt(strings[strings.length - 1]); - if (i != strings.length - 1) { - InsProduct insProduct = new InsProduct(); - switch (type) { - case 1: - insProduct.setInsFibersId(id); - break; - case 2: - insProduct.setInsFiberId(id); - break; - } - String[] split = strings[i].split(","); - if (split[0].equals("20鈩�")) { - insProduct.setInspectionItem(count + "");//妫�楠岄」--寰幆娆℃暟 - } else { - insProduct.setInspectionItem("1");//妫�楠岄」--寰幆娆℃暟 - } - insProduct.setInspectionItemSubclass(split[0]);//妫�楠岄」--娓╁害 - insProduct.setInspectionItemClass(split[1]);//妫�楠岄」--鍏夌氦椤圭洰 - insProduct.setAsk(split[2]);//妫�楠岃姹� - insProduct.setTell(strings[i]);//妫�楠屾弿杩� - insProduct.setInsSampleId(sampleId); - insProduct.setState(1); - insProduct.setFactory(product.getFactory()); - insProduct.setLaboratory(product.getLaboratory()); - insProduct.setSampleType(product.getSampleType()); - insProduct.setSample(product.getSample()); - insProduct.setModel(product.getModel()); - insProduct.setSonLaboratory(product.getSonLaboratory()); - insProduct.setUnit(product.getUnit()); - insProduct.setManHourGroup(product.getManHourGroup()); - insProduct.setInspectionItemType("0"); - insProduct.setInspectionValueType("1"); - insProducts.add(insProduct); - insProductes.add(insProduct); - } else { - //鏈�鍚庝竴涓暟鎹槸璇存槑浼氬惊鐜灏戞 - if (count > 1) { - //寰幆瓒呰繃1娆� - for (int j = 2; j <= count; j++) { - for (InsProduct insProduct : insProducts) { - if (!insProduct.getInspectionItemSubclass().equals("20鈩�") && !insProduct.getInspectionItemSubclass().equals("20鈩�(甯告俯)")) { - InsProduct insProduct1 = new InsProduct(); - BeanUtils.copyProperties(insProduct, insProduct1); - insProduct1.setInspectionItem(j + ""); - insProductes.add(insProduct1); - } - } - } - } - } - } - insProductService.saveBatch(insProductes); + if (product.getState() == 1) { + product.setId(null); + product.setCreateTime(null); + product.setCreateUser(null); + product.setUpdateTime(null); + product.setUpdateUser(null); + product.setInsSampleId(sampleId); + if (product.getInspectionItemSubclass() == null) { + product.setInspectionItemSubclass(""); } - //鍒ゆ柇鐑惊鐜」鐩殑娣诲姞鍜屾俯鍗囪瘯楠岄」鐩殑娣诲姞 - else if (product.getInspectionItem().equals("鐑惊鐜�") || product.getInspectionItem().equals("娓╁崌璇曢獙")) { - List<InsProduct> insProductess = new ArrayList<>(); - insProductess.add(product); - List<InsProduct> insProductes = new ArrayList<>(); - List<InsProduct> insProducts = new ArrayList<>(); - String[] strings = product.getAsk().split(";"); - //寰幆娆℃暟 - int count = Integer.parseInt(strings[strings.length - 1]); - for (int i = 0; i < strings.length - 1; i++) { - String[] split = strings[i].split(","); - InsProduct insProduct = new InsProduct(); - insProduct.setInspectionItem("1");//妫�楠岀埗椤�--寰幆娆℃暟 - insProduct.setInspectionItemSubclass(split[0]);//妫�楠屽瓙椤�--鐜娓╁害/瀵肩嚎娓╁害/鑰愬紶娓╁害/鎺ョ画娓╁害 - insProduct.setInspectionItemSubclassEn(split[1]);//妫�楠屽瓙椤硅嫳鏂�--鐜娓╁害/瀵肩嚎娓╁害/鑰愬紶娓╁害/鎺ョ画娓╁害 - insProduct.setAsk(null);//妫�楠岃姹� - insProduct.setTell(null);//妫�楠屾弿杩� - insProduct.setInsSampleId(sampleId); - insProduct.setState(1); - insProduct.setFactory(product.getFactory()); - insProduct.setLaboratory(product.getLaboratory()); - insProduct.setSampleType(product.getSampleType()); - insProduct.setSample(product.getSample()); - insProduct.setModel(product.getModel()); - insProduct.setSonLaboratory(product.getSonLaboratory()); - insProduct.setUnit("鈩�");//鍗曚綅 - insProduct.setManHourGroup(product.getManHourGroup()); - insProduct.setInspectionItemType("0"); - insProduct.setInspectionValueType("1"); - insProducts.add(insProduct); - insProductes.add(insProduct); - insProductess.add(insProduct); - } - //鐑惊鐜墠鏈夊娆″惊鐜鏁� - if (product.getInspectionItem().equals("鐑惊鐜�")) { - //鐑惊鐜繕瑕佸姞涓婄洿娴佺數闃� - for (InsProduct insProduct : insProducts) { - InsProduct insProduct1 = new InsProduct(); - BeanUtils.copyProperties(insProduct, insProduct1); - insProduct1.setInspectionItemClass("鐩存祦鐢甸樆");//妫�楠屽瓙瀛愰」--鐩存祦鐢甸樆 - insProduct1.setInspectionItemClassEn("DC resistance");//妫�楠屽瓙瀛愰」鑻辨枃--鐩存祦鐢甸樆 - insProduct1.setUnit("惟/km");//鍗曚綅 - insProductes.add(insProduct1); - insProductess.add(insProduct1); - } - } - if (count > 1) { - //寰幆瓒呰繃1娆� - for (int j = 2; j <= count; j++) { - for (InsProduct insProduct : insProductes) { - InsProduct insProduct1 = new InsProduct(); - BeanUtils.copyProperties(insProduct, insProduct1); - insProduct1.setInspectionItem(j + "");//寰幆娆℃暟 - insProductess.add(insProduct1); - } - } - } - insProductService.saveBatch(insProductess); - } - else { - if (!is) { - switch (type) { - case 1: - product.setInsFibersId(id); - break; - case 2: - product.setInsFiberId(id); - break; - } - product.setId(null); - product.setCreateTime(null); - product.setUpdateTime(null); - product.setUpdateTime(null); - product.setUpdateUser(null); - product.setInsSampleId(sampleId); - if (product.getInspectionItemSubclass() == null) { - product.setInspectionItemSubclass(""); - } - insProductMapper.insert(product); - } - } + insProductMapper.insert(product); } } } @@ -423,6 +372,9 @@ Map<String, Object> map = new HashMap<>(); InsOrder insOrder = insOrderMapper.selectById(id); List<SampleProductDto> list = insSampleMapper.selectSampleProductListByOrderId2(id); + if (list.size() == 0) { + list = insSampleMapper.selectSampleProductListByOrder2Id2(id); + } map.put("insOrder", insOrder); map.put("sampleProduct", list); return map; @@ -430,28 +382,102 @@ @Override public int upInsOrderOfState(InsOrder insOrder) { + InsOrder order = insOrderMapper.selectById(insOrder.getId()); + insOrder.setCompany(order.getCompany()); insOrder.setExamineTime(LocalDateTime.now()); if (insOrder.getState() == 1) { //瀹℃牳閫氳繃鎵嶄細鐢熸垚濮旀墭缂栧彿 - String code = baseMapper.selLaboratoryCode(insOrder.getLaboratory()); - if (StringUtils.isEmpty(code)) { - code = ""; - } - String code2 = customMapper.selectById(insOrder.getCompanyId()).getCode2(); - insOrder.setEntrustCode(giveCode.giveCode2("JCZX/" + code + "-" + code2 + "-", insOrder.getCompanyId(), insOrder.getLaboratory(), "ins_order", "", "yyMM")); + insOrder.setEntrustCode(giveCode.giveCode2("WT-", "ins_order", "-", "yyMMdd")); + insOrder.setSendTime(LocalDateTime.now()); } return insOrderMapper.updateById(insOrder); } @Override - public Map<String, Object> getInsOrderAndSample(Integer id, String laboratory) { + public int upInsOrderOfState2(InsOrder insOrder) { + InsOrder order = insOrderMapper.selectById(insOrder.getId()); + //鑾峰彇褰撳墠浜� + Integer userId = getLook.selectPowerByMethodAndUserId(null).get("userId"); + //鑾峰彇褰撳墠浜虹殑瑙掕壊 + String roleName = roleMapper.selectById(userMapper.selectById(userId).getRoleId()).getName(); + //鍒ゆ柇鏄娴嬩腑蹇冧富浠�/鐮斿彂閮ㄧ粡鐞�/鎶�鏈礋璐d汉 + switch (roleName) { + case "妫�娴嬩腑蹇冧富浠�": + order.setCheckState1(insOrder.getState()); + order.setCheckState1User(userId); + break; + case "鐮斿彂閮ㄧ粡鐞�": + order.setCheckState2(insOrder.getState()); + order.setCheckState2User(userId); + break; + case "鎶�鏈礋璐d汉": + order.setCheckState3(insOrder.getState()); + order.setCheckState3User(userId); + break; + default: + throw new ErrorException("褰撳墠鐧诲綍鐢ㄦ埛鐨勮鑹蹭笉鏄娴嬩腑蹇冧富浠�/鐮斿彂閮ㄧ粡鐞�/鎶�鏈礋璐d汉,鏃犳硶杩涜瀹℃牳"); + } + insOrderMapper.updateById(order); + //鏌ヨ璇ヨ鍗曟槸A绫昏繕鏄疊绫� + if (order.getOrderType().equals("B")) { + //濡傛灉鏄疊绫�,1鍜�2鍜�3閮藉鏍搁�氳繃杩欎釜鍗曞瓙灏卞鏍搁�氳繃 + if (order.getCheckState1() == 1 && order.getCheckState2() == 1 && order.getCheckState3() == 1) { + order.setState(1); + upInsOrderOfState(order); + } else if (order.getCheckState1() == 2 || order.getCheckState2() == 2 || order.getCheckState3() == 2) { + order.setState(2); + upInsOrderOfState(order); + } + } else if (order.getOrderType().equals("A")) { + //濡傛灉鏄疉绫�,1鍜�2瀹℃牳閫氳繃鍚庤繖涓崟瀛愬氨瀹℃牳閫氳繃 + if (order.getCheckState1() == 1 && order.getCheckState2() == 1) { + order.setState(1); + upInsOrderOfState(order); + } else if (order.getCheckState1() == 2 || order.getCheckState2() == 2) { + order.setState(2); + upInsOrderOfState(order); + } + } + return 1; + } + + @Override + public Map<String, Object> getInsOrderAndSample(Integer sampleId, String laboratory) { + InsSample insSample = insSampleMapper.selectById(sampleId); Map<String, Object> map = new HashMap<>(); - InsOrder insOrder = insOrderMapper.selectById(id); - List<SampleProductDto> list = insSampleMapper.getInsOrderAndSample(id, laboratory); + InsOrder insOrder = insOrderMapper.selectById2(insSample.getInsOrderId()); + SampleProductDto sampleProductDto = insSampleMapper.getInsOrderAndSample(sampleId, laboratory); + //鍐嶆璇曢獙浼氬嚭鐜颁负绌虹殑鎯呭喌 + if (ObjectUtils.isEmpty(sampleProductDto)) { + List<InsProduct> insProducts = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery() + .eq(InsProduct::getInsSampleId, insSample.getId()) + .eq(InsProduct::getState, 1) + .eq(InsProduct::getSonLaboratory, laboratory)); + for (InsProduct insProduct : insProducts) { + List<InsProductResult2> insProductResult2List = insProductResult2Mapper.selectList(Wrappers.<InsProductResult2>lambdaQuery() + .eq(InsProductResult2::getInsProductId, insProduct.getId()).isNull(InsProductResult2::getNum)); + insProduct.setInsProductResult2(insProductResult2List); + InsProductResult insProductResult = insProductResultMapper.selectOne(Wrappers.<InsProductResult>lambdaQuery() + .eq(InsProductResult::getInsProductId, insProduct.getId()).isNull(InsProductResult::getNum)); + insProduct.setInsProductResult(insProductResult); + } + SampleProductDto dto = new SampleProductDto(); + dto.setInsProduct(insProducts); + BeanUtils.copyProperties(insSample,dto); + sampleProductDto=dto; + } + List<Integer> ids = sampleProductDto.getInsProduct().stream().map(InsProduct::getId).collect(Collectors.toList()); + List<InsProductUser> insProductUsers = insProductUserMapper.selectList(Wrappers.<InsProductUser>lambdaQuery() + .in(InsProductUser::getInsProductId, ids)); + if (CollectionUtils.isNotEmpty(insProductUsers)) { + List<Integer> userIds = insProductUsers.stream().map(InsProductUser::getCreateUser).distinct().collect(Collectors.toList()); + String collect = userMapper.selectBatchIds(userIds).stream().map(User::getName).collect(Collectors.joining(",")); + sampleProductDto.setCheckName(collect); + } map.put("insOrder", insOrder); - map.put("sampleProduct", list); + map.put("sampleProduct", sampleProductDto); //鏌ヨ鎵�鏈夎褰曟ā鐗堝幓閲� - List<Map<Integer, Object>> list2 = insOrderMapper.selectReportModelByOrderId(id, laboratory); + List<Map<Integer, Object>> list2 = insOrderMapper.selectReportModelByOrderId(insSample.getInsOrderId(), laboratory); map.put("reportModel", list2); return map; } @@ -460,7 +486,19 @@ public Map<String, Object> selectSampleAndProductByOrderId(IPage<SampleProductDto2> page, SampleProductDto2 sampleProductDto) { Map<String, Object> map = new HashMap<>(); map.put("head", PrintChina.printChina(SampleProductDto2.class)); - map.put("body", insOrderMapper.selectSampleAndProductByOrderId(page, QueryWrappers.queryWrappers(sampleProductDto))); + IPage<SampleProductDto2> productDto2IPage = insOrderMapper.selectSampleAndProductByOrderId(page, QueryWrappers.queryWrappers(sampleProductDto).orderByAsc("inspection_item"), sampleProductDto.getId()); + for (SampleProductDto2 record : productDto2IPage.getRecords()) { + InsProductUser insProductUser = insProductUserMapper.selectOne(Wrappers.<InsProductUser>lambdaQuery() + .eq(InsProductUser::getInsProductId, record.getInsProductId()) + .orderByDesc(InsProductUser::getCreateTime) + .last("limit 1")); + if (ObjectUtils.isNotEmpty(insProductUser)) { + record.setCheckName(userMapper.selectById(insProductUser.getCreateUser()).getName()); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + record.setCheckTime(insProductUser.getCreateTime().format(formatter)); + } + } + map.put("body", productDto2IPage); return map; } @@ -473,34 +511,22 @@ map.put("head", PrintChina.printChina(CostStatisticsDto.class)); Map<String, Integer> map1 = getLook.selectPowerByMethodAndUserId("costStatistics"); if (map1.get("look") == 1) costStatisticsDto.setCreateUser(map1.get("userId")); - IPage<CostStatisticsDto> costStatisticsDtoIPage = insOrderMapper.selectCostStatistics(page, QueryWrappers.queryWrappers(costStatisticsDto).ge("create_time", split[0]).le("create_time", split[1] + " 23:59:59")); - List<CostStatisticsDto> costStatisticsDtoList = costStatisticsDtoIPage.getRecords(); - for (CostStatisticsDto statisticsDto : costStatisticsDtoList) { - statisticsDto.setNum(1); - } - List<CostStatisticsDto> costStatisticsDtoList1 = deduplicateAndSumCounts(costStatisticsDtoList); - costStatisticsDtoIPage.setRecords(costStatisticsDtoList1); - map.put("body", costStatisticsDtoIPage); - return map; - } - private static List<CostStatisticsDto> deduplicateAndSumCounts(List<CostStatisticsDto> list) { - // 浣跨敤涓�涓� Map 鏉ュ瓨鏀惧凡缁忓嚭鐜拌繃鐨� inspectionItem + entrustCode + sample 鐨勭粍鍚� - Map<String, CostStatisticsDto> map = new HashMap<>(); - // 閬嶅巻鍒楄〃杩涜鍘婚噸鍜岃鏁� - for (CostStatisticsDto dto : list) { - String key = dto.getInspectionItem() + dto.getEntrustCode() + dto.getSample(); - if (map.containsKey(key)) { - // 濡傛灉宸茬粡瀛樺湪锛屽垯绱姞鏁伴噺 - CostStatisticsDto existingDto = map.get(key); - existingDto.setNum(existingDto.getNum() + dto.getNum()); - existingDto.setPrice(existingDto.getPrice().add(dto.getPrice())); + IPage<CostStatisticsDto> dtoIPage = insOrderMapper.selectCostStatistics(page, QueryWrappers.queryWrappers(costStatisticsDto).ge("create_time", split[0]).le("create_time", split[1] + " 23:59:59")); + List<CostStatisticsDto> collect = dtoIPage.getRecords().stream().map(dto -> { + Set<String> uniqueTags = new HashSet<>(); + if (dto.getInspectionItem().contains(",")) { + for (String s : dto.getInspectionItem().split(",")) { + uniqueTags.add(s.split("@")[0]); + } } else { - // 濡傛灉涓嶅瓨鍦紝鍒欐斁鍏� Map 涓� - map.put(key, dto); + uniqueTags.add(dto.getInspectionItem().split("@")[0]); } - } - // 灏� Map 涓殑鍊艰浆涓� List 杩斿洖 - return new ArrayList<>(map.values()); + dto.setInspectionItem(uniqueTags.toString()); + return dto; + }).collect(Collectors.toList()); + dtoIPage.setRecords(collect); + map.put("body", dtoIPage); + return map; } @Override @@ -511,16 +537,13 @@ costStatisticsDto.setDates(null); List<CostStatisticsDto> costStatisticsDtos = insOrderMapper.selectCostStatistics2(QueryWrappers.queryWrappers(costStatisticsDto).ge("create_time", split[0]).le("create_time", split[1] + " 23:59:59")); double totalPrice = costStatisticsDtos.stream() - .filter(distinctByKey(dto -> Arrays.asList(dto.getEntrustCode(), dto.getSample(), dto.getCost()))) .filter(dto -> dto.getPrice() != null) // 杩囨护鎺変环鏍间负 null 鐨勫璞� - .mapToDouble(value -> value.getPrice().doubleValue()) + .mapToDouble(value -> value.getPrice().doubleValue() * value.getNum()) .sum(); - map.put("total", totalPrice); + BigDecimal bd = new BigDecimal(totalPrice).setScale(2, RoundingMode.HALF_UP); + double roundedTotalPrice = bd.doubleValue(); + map.put("total", roundedTotalPrice); return map; - } - public static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) { - Map<Object, Boolean> seen = new ConcurrentHashMap<>(); - return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null; } @Override @@ -543,20 +566,86 @@ public List<SampleProductDto3> labelPrinting(String ids) { List<Integer> list = Arrays.stream(ids.split(",")).map(Integer::parseInt).collect(Collectors.toList()); List<SampleProductDto3> sampleProductDtos = insSampleMapper.selectSampleProductListByOrderId3(list); - Set<String> processedCodes = new HashSet<>(); - //濡傛灉鏄厜绾ゆ垨鑰呮槸鍏夌氦甯﹂粯璁ゅ彧鎵撳嵃绗竴涓� - List<SampleProductDto3> sampleProductDto3s = sampleProductDtos.stream().filter(sampleProductDto3 -> { - if (!"鍏夌氦".equals(sampleProductDto3.getIoSampleType()) && !"鍏夌氦甯�".equals(sampleProductDto3.getIoSampleType())) { - return true; + return sampleProductDtos; + } + + //鏍¢獙鐢垫満缂栧彿 + @Override + public Map<String, List<InsSample>> checkNumber(String ids) { + List<InsSample> samples = new ArrayList<>(); + List<Integer> list = Arrays.stream(ids.split(",")).map(Integer::parseInt).collect(Collectors.toList()); + List<InsSample> sampleDtos = insSampleMapper.selectInsSample(list); + //鍒ゆ柇鏍峰搧鍨嬪彿鏄惁鏄疊Z + for (InsSample sampleDto : sampleDtos) { + if (sampleDto.getModel().contains("BZ")) { + if (ObjectUtils.isEmpty(sampleDto.getMotorNumber())) { + samples.add(sampleDto); + } } - if (processedCodes.contains(sampleProductDto3.getCode())) { - return false; + } + if (CollectionUtils.isNotEmpty(samples)) { + Map<String, List<InsSample>> collect = samples.stream().collect(Collectors.groupingBy(InsSample::getEntrustCode)); + return collect; + } else return null; + } + + @Override + public void export(CostStatisticsDto costStatisticsDto, HttpServletResponse response) throws IOException { + //鏌ヨ瀵煎嚭鐨勮垂鐢ㄧ粺璁℃暟鎹� + String dates = costStatisticsDto.getDates(); + String[] split = dates.replaceAll("\\[", "").replaceAll("]", "").replaceAll("\"", "").split(","); + costStatisticsDto.setDates(null); + List<CostStatisticsDto> costStatisticsDtos = insOrderMapper.selectCostStatistics2(QueryWrappers.queryWrappers(costStatisticsDto).ge("create_time", split[0]).le("create_time", split[1] + " 23:59:59")); + costStatisticsDtos = costStatisticsDtos.stream().map(dto -> { + Set<String> uniqueTags = new HashSet<>(); + if (dto.getInspectionItem().contains(",")) { + for (String s : dto.getInspectionItem().split(",")) { + uniqueTags.add(s.split("@")[0]); + } } else { - processedCodes.add(sampleProductDto3.getCode()); - return true; + uniqueTags.add(dto.getInspectionItem().split("@")[0]); } + dto.setInspectionItem(uniqueTags.toString()); + return dto; }).collect(Collectors.toList()); - return sampleProductDto3s; + + response.setContentType("application/vnd.ms-excel"); + response.setCharacterEncoding("UTF-8"); + // 杩欓噷URLEncoder.encode鍙互闃叉涓枃涔辩爜 褰撶劧鍜宔asyexcel娌℃湁鍏崇郴 + String fileName = URLEncoder.encode("鏍峰搧璐圭敤缁熻瀵煎嚭", "UTF-8"); + response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx"); + Map<String, List<CostStatisticsDto>> groupByCompany = + costStatisticsDtos.stream().filter(e -> StrUtil.isNotEmpty(e.getCompany())) + .collect(Collectors.groupingBy(CostStatisticsDto::getCompany)); + try { + // 鏂板缓ExcelWriter + // 鏂板缓ExcelWriter + ExcelWriter excelWriter = + EasyExcel.write(response.getOutputStream()) + .registerWriteHandler(new SimpleColumnWidthStyleStrategy(25)) + .build(); + for (Map.Entry<String, List<CostStatisticsDto>> companyDataEntry : groupByCompany.entrySet()) { + String sheetName = companyDataEntry.getKey(); + List<CostStatisticsDto> dataList = companyDataEntry.getValue(); + WriteSheet mainSheet = EasyExcel.writerSheet(sheetName) + .head(CostStatisticsDto.class) + .registerWriteHandler(new SimpleColumnWidthStyleStrategy(25)) + .build(); + excelWriter.write(dataList, mainSheet); + } + // 鍏抽棴娴� + excelWriter.finish(); + } catch (IOException e) { + throw new RuntimeException("瀵煎嚭澶辫触"); + } + } + + @Override + public int addNumber(List<InsSample> insSamples) { + for (InsSample insSample : insSamples) { + insSampleMapper.updateById(insSample); + } + return 0; } } -- Gitblit v1.9.3