From b51f37241e4b369718d5e27a3686ca7edadaf69b Mon Sep 17 00:00:00 2001 From: zhuo <2089219845@qq.com> Date: 星期四, 06 三月 2025 16:37:52 +0800 Subject: [PATCH] 新增工时查询接口, 修改配置文件 --- inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderServiceImpl.java | 229 ++++++++++++++++++++++++++------------------------------ 1 files changed, 107 insertions(+), 122 deletions(-) diff --git a/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderServiceImpl.java b/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderServiceImpl.java index abb2686..186e0a1 100644 --- a/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderServiceImpl.java +++ b/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderServiceImpl.java @@ -1,6 +1,8 @@ package com.ruoyi.inspect.service.impl; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.date.DateTime; +import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONUtil; @@ -31,10 +33,14 @@ import com.ruoyi.inspect.mapper.*; import com.ruoyi.inspect.pojo.*; import com.ruoyi.inspect.service.InsOrderService; +import com.ruoyi.inspect.service.InsOrderStateService; import com.ruoyi.inspect.service.InsProductService; import com.ruoyi.inspect.service.InsSampleService; import com.ruoyi.inspect.vo.InsOrderPrintingVo; import com.ruoyi.inspect.vo.SampleDefectsFatherVo; +import com.ruoyi.performance.pojo.AuxiliaryOutputWorkingHours; +import com.ruoyi.performance.pojo.AuxiliaryOutputWorkingHoursTemporary; +import com.ruoyi.performance.service.AuxiliaryOutputWorkingHoursTemporaryService; import com.ruoyi.system.mapper.CustomMapper; import com.ruoyi.system.mapper.UserMapper; import lombok.AllArgsConstructor; @@ -47,6 +53,7 @@ import java.io.IOException; import java.math.BigDecimal; import java.net.URLEncoder; +import java.text.SimpleDateFormat; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.Month; @@ -70,18 +77,17 @@ private InsSampleMapper insSampleMapper; private InsProductService insProductService; private InsProductMapper insProductMapper; - private InsProductUserMapper insProductUserMapper; private InsSampleUserMapper insSampleUserMapper; - private InsOrderStateMapper insOrderStateMapper; + private InsOrderStateService insOrderStateService; private UserMapper userMapper; private IfsInventoryQuantityMapper ifsInventoryQuantityMapper; - private CustomMapper customMapper; private final NumberGenerator<InsOrder> numberGenerator; private InsReportMapper insReportMapper; private InsUnqualifiedRetestProductMapper insUnqualifiedRetestProductMapper; private IfsApiUtils ifsApiUtils; private SpotCheckQuarterItemMapper spotCheckQuarterItemMapper; private StandardProductListMapper standardProductListMapper; + private AuxiliaryOutputWorkingHoursTemporaryService auxiliaryOutputWorkingHoursTemporaryService; @@ -96,11 +102,15 @@ isOrderAll = "1"; sampleOrderDto.setState(null); } - IPage<SampleOrderDto> sampleOrderDtoIPage = insOrderMapper.selectInsOrderPage(page, QueryWrappers.queryWrappers(sampleOrderDto), laboratory, isOrderAll); return insOrderMapper.selectInsOrderPage(page, QueryWrappers.queryWrappers(sampleOrderDto), laboratory, isOrderAll); } + /** + * 鍒嗛厤妫�楠屼汉 + * + * @return + */ @Override @Transactional(rollbackFor = Exception.class) public int upInsOrder(Integer orderId, Integer sampleId, String appointed, Integer userId, String sonLaboratory) { @@ -109,13 +119,15 @@ insOrder.setAppointed(StringUtils.isNotEmpty(appointed) ? LocalDate.parse(appointed) : null); 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<InsSample> insSamples = insSampleMapper.selectList(Wrappers.<InsSample>lambdaQuery().eq(InsSample::getInsOrderId, orderId)); + 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::getState, 1) .select(InsProduct::getSonLaboratory).groupBy(InsProduct::getSonLaboratory)); - for (InsProduct insProduct : insProducts) { + + // 鎵归噺娣诲姞妫�楠屼换鍔$姸鎬佽〃 + List<InsOrderState> insOrderStateList = insProducts.stream().map(insProduct -> { InsOrderState insOrderState = new InsOrderState(); insOrderState.setInsOrderId(orderId); try { @@ -124,8 +136,10 @@ throw new ErrorException("璇ユ楠屽崟鏈夋湭缁存姢瀹為獙瀹ょ殑妫�楠岄」鐩�"); } insOrderState.setInsState(0); - insOrderStateMapper.insert(insOrderState); - } + return insOrderState; + }).collect(Collectors.toList()); + insOrderStateService.saveBatch(insOrderStateList); + if (userId != null) { InsSampleUser insSampleUser = new InsSampleUser(); insSampleUser.setState(0); @@ -145,12 +159,84 @@ spotCheckQuarterItem.setSamplingUser(user.getName()); spotCheckQuarterItemMapper.updateById(spotCheckQuarterItem); } + + + // 鍒涘缓宸ユ椂鏆傚瓨 + // 缂撳瓨鏍峰搧id, 缂栧彿map + Map<Integer, String> sampleMap = insSamples.stream().collect(Collectors.toMap(InsSample::getId, InsSample::getSampleCode)); + List<InsProduct> insProductList = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery() + .in(InsProduct::getInsSampleId, ids) + .eq(InsProduct::getState, 1)); + List<AuxiliaryOutputWorkingHoursTemporary> outputWorkingHours = insProductList.stream().map(insProduct -> { + AuxiliaryOutputWorkingHoursTemporary auxiliaryOutputWorkingHours = new AuxiliaryOutputWorkingHoursTemporary(); + auxiliaryOutputWorkingHours.setInspectionItemClass(insProduct.getInspectionItemClass());//妫�娴嬮」鍒嗙被 + auxiliaryOutputWorkingHours.setInspectionItem(insProduct.getInspectionItem());//妫�娴嬬埗椤� + auxiliaryOutputWorkingHours.setInspectionItemSubclass(insProduct.getInspectionItemSubclass());//妫�娴嬪瓙椤� + auxiliaryOutputWorkingHours.setSample(sampleMap.get(insProduct.getInsSampleId()));//鏍峰搧缂栧彿 + auxiliaryOutputWorkingHours.setOrderId(order.getId());//璁㈠崟id + auxiliaryOutputWorkingHours.setOrderNo(order.getEntrustCode());//闈炲姞鐝鎵樺崟鍙� + auxiliaryOutputWorkingHours.setWorkTime(insProduct.getManHour());//闈炲姞鐝伐鏃� + auxiliaryOutputWorkingHours.setAmount(1);//闈炲姞鐝暟閲� + auxiliaryOutputWorkingHours.setOutputWorkTime((ObjectUtils.isNotEmpty(auxiliaryOutputWorkingHours.getOvertimeWorkTime()) ? auxiliaryOutputWorkingHours.getOvertimeWorkTime() : BigDecimal.ZERO).add(ObjectUtils.isNotEmpty(auxiliaryOutputWorkingHours.getWorkTime()) ? auxiliaryOutputWorkingHours.getWorkTime() : BigDecimal.ZERO));//浜ч噺宸ユ椂 + auxiliaryOutputWorkingHours.setManHourGroup(insProduct.getManHourGroup());//宸ユ椂鍒嗙粍 + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + DateTimeFormatter formatters = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + auxiliaryOutputWorkingHours.setDateTime(LocalDateTime.now().toLocalDate().atStartOfDay().format(formatters));//鏃ユ湡 + LocalDateTime localDateTime = LocalDateTime.now(); + DateTime parse = DateUtil.parse(localDateTime.format(formatter)); + auxiliaryOutputWorkingHours.setWeekDay(getWeek(localDateTime.format(formatters)));//鏄熸湡 + auxiliaryOutputWorkingHours.setWeek(String.valueOf(DateUtil.weekOfYear(DateUtil.offsetDay(parse, 1))));//鍛ㄦ + auxiliaryOutputWorkingHours.setCheck(userId);//妫�娴嬩汉 + auxiliaryOutputWorkingHours.setPrice(insProduct.getPrice());//鍗曚环 + auxiliaryOutputWorkingHours.setSampleId(insProduct.getInsSampleId());//鏍峰搧id + auxiliaryOutputWorkingHours.setInsProductId(insProduct.getId());//妫�楠岄」id + + return auxiliaryOutputWorkingHours; + }).collect(Collectors.toList()); + auxiliaryOutputWorkingHoursTemporaryService.saveBatch(outputWorkingHours); + return 1; + } + + 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 "鏈煡"; + } } @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) { // todo: 涓嬪崟鍒ゆ柇鎶芥牱璁″垝鐨勫敮涓�鎬� if (insOrder.getQuarterItemId() != null) { Long quarterItemCount = insOrderMapper.selectCount(Wrappers.<InsOrder>lambdaQuery() @@ -160,7 +246,6 @@ throw new ErrorException("璇ユ娊鏍疯鍒掑凡琚粦瀹氳繃"); } } - insOrder.setState(0); LocalDate appointed = insOrder.getAppointed(); @@ -286,9 +371,11 @@ .set(IfsInventoryQuantity::getInspectStatus, 0)); } + // 瀹℃牳妫�楠屽崟 upInsOrderOfState(insOrder); - upInsOrder(insOrder.getId(), null, appointed != null ? appointed.toString() : null, SecurityUtils.getUserId().intValue(), "鍘熸潗鏂�"); + // 鍒嗛厤妫�楠屼汉 + upInsOrder(insOrder.getId(), null, appointed != null ? appointed.toString() : null, SecurityUtils.getUserId().intValue(), "鍘熸潗鏂�"); // 鏍规嵁闆朵欢鍙峰垽鏂槸鍚︽槸杈呮潗 boolean isRaw = false; @@ -355,6 +442,9 @@ if (StringUtils.isBlank(product.getAsk()) || StringUtils.isBlank(product.getTell())) { throw new ErrorException("鏈夋楠岄」鐨勮姹傚�兼垨瑕佹眰鎻忚堪涓虹┖, 璇峰厛鍘绘爣鍑嗗簱閰嶇疆瑕佹眰鍊兼垨瑕佹眰鎻忚堪"); } + if (StringUtils.isBlank(product.getSonLaboratory())) { + throw new ErrorException("鏈夋楠岄」鐨勭殑瀛愬疄楠屽涓虹粦瀹�, 璇峰厛缁戝畾瀛愬疄楠屽"); + } insProductMapper.insert(product); } } @@ -379,6 +469,11 @@ return map; } + /** + * 瀹℃牳妫�楠屽崟 + * @param insOrder + * @return + */ @Override public int upInsOrderOfState(InsOrder insOrder) { insOrder.setExamineTime(LocalDateTime.now()); @@ -446,16 +541,6 @@ Map<String, Object> map = new HashMap<>(); InsOrder insOrder = insOrderMapper.selectById(id); List<SampleProductDto> list = insSampleMapper.getInsOrderAndSample(id, laboratory); - for (SampleProductDto sampleProductDto : list) { - 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); //鏌ヨ鎵�鏈夎褰曟ā鐗堝幓閲� @@ -475,112 +560,12 @@ return productDto2IPage; } - @Override - public IPage<CostStatisticsDto> costStatistics(IPage<CostStatisticsDto> page, CostStatisticsDto costStatisticsDto) { - String dates = costStatisticsDto.getDates(); - String[] split = dates.replaceAll("\\[", "").replaceAll("]", "").replaceAll("\"", "").split(","); - costStatisticsDto.setDates(null); - - //todo:浠呯湅鑷繁 - - 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 { - uniqueTags.add(dto.getInspectionItem().split("@")[0]); - } - dto.setInspectionItem(uniqueTags.toString()); - return dto; - }).collect(Collectors.toList()); - dtoIPage.setRecords(collect); - return dtoIPage; - } - - @Override - public Map<String, Object> costStatistics2(CostStatisticsDto costStatisticsDto) { - Map<String, Object> map = new HashMap<>(); - 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")); - double totalPrice = costStatisticsDtos.stream() - .filter(dto -> dto.getPrice() != null) // 杩囨护鎺変环鏍间负 null 鐨勫璞� - .mapToDouble(value -> value.getPrice().doubleValue() * value.getNum()) - .sum(); - map.put("total", totalPrice); - return map; - } - - @Override - public Map<String, Object> selectSampleDefects(Page page, String inspectionItems, String orderNumber) { - List<SampleDefectsFatherVo> sampleDefectsFatherVos = insOrderMapper.selectSampleDefects(page, inspectionItems, orderNumber); - Map<String, Object> map = new HashMap<>(); - map.put("records", sampleDefectsFatherVos); - Long aLong = insOrderMapper.getCount(inspectionItems, orderNumber); - map.put("total", aLong); - return map; - } @Override public int updateStatus(Integer id) { return insOrderMapper.updateStatus(id); } - - @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 { - uniqueTags.add(dto.getInspectionItem().split("@")[0]); - } - dto.setInspectionItem(uniqueTags.toString()); - return dto; - }).collect(Collectors.toList()); - - 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("瀵煎嚭澶辫触"); - } - } /** * 鑾峰彇ifs搴撳瓨淇℃伅 -- Gitblit v1.9.3