| | |
| | | |
| | | 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.LongestMatchColumnWidthStyleStrategy; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.servlet.ServletException; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.net.URLEncoder; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | |
| | | Integer roleId = user.getRoleId(); |
| | | //获取当前人所属实验室id |
| | | String departLimsId = user.getDepartLimsId(); |
| | | String laboratory=null; |
| | | if (ObjectUtils.isNotEmpty(departLimsId) && !departLimsId.equals("")){ |
| | | 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 departLims = baseMapper.seldepLimsId(Integer.parseInt(split[split.length - 1])); |
| | | if (departLims.contains("实验室")) { |
| | | laboratory = departLims; |
| | | } |
| | | } |
| | | //判断是否是全部权限 |
| | |
| | | } |
| | | } |
| | | } |
| | | map.put("body", insOrderMapper.selectInsOrderPage(page, QueryWrappers.queryWrappers(sampleOrderDto),laboratory)); |
| | | map.put("body", insOrderMapper.selectInsOrderPage(page, QueryWrappers.queryWrappers(sampleOrderDto), laboratory)); |
| | | return map; |
| | | } |
| | | |
| | |
| | | //判断热循环项目的添加和温升试验项目的添加 |
| | | else if (product.getInspectionItem().equals("热循环") || product.getInspectionItem().equals("温升试验")) { |
| | | List<InsProduct> insProductess = new ArrayList<>(); |
| | | product.setId(null); |
| | | product.setInsSampleId(sampleId); |
| | | insProductess.add(product); |
| | | List<InsProduct> insProductes = new ArrayList<>(); |
| | | List<InsProduct> insProducts = new ArrayList<>(); |
| | |
| | | insProduct.setInspectionItemType("0"); |
| | | insProduct.setInspectionValueType("1"); |
| | | insProducts.add(insProduct); |
| | | insProductes.add(insProduct); |
| | | insProductess.add(insProduct); |
| | | } |
| | | //热循环才有多次循环次数 |
| | | if (product.getInspectionItem().equals("热循环")) { |
| | |
| | | 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); |
| | | } |
| | | 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 { |
| | | } else { |
| | | if (!is) { |
| | | switch (type) { |
| | | case 1: |
| | |
| | | map.put("head", PrintChina.printChina(CostStatisticsDto.class)); |
| | | Map<String, Integer> map1 = getLook.selectPowerByMethodAndUserId("costStatistics"); |
| | | if (map1.get("look") == 1) costStatisticsDto.setCreateUser(map1.get("userId")); |
| | | map.put("body",insOrderMapper.selectCostStatistics(page, QueryWrappers.queryWrappers(costStatisticsDto).ge("create_time", split[0]).le("create_time", split[1] + " 23:59:59"))); |
| | | 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); |
| | | map.put("body", dtoIPage); |
| | | return map; |
| | | } |
| | | |
| | |
| | | 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()) |
| | | .mapToDouble(value -> value.getPrice().doubleValue() * value.getNum()) |
| | | .sum(); |
| | | map.put("total", totalPrice); |
| | | return map; |
| | |
| | | }).collect(Collectors.toList()); |
| | | return sampleProductDto3s; |
| | | } |
| | | |
| | | @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可以防止中文乱码 当然和easyexcel没有关系 |
| | | String fileName = URLEncoder.encode("样品费用统计导出", "UTF-8"); |
| | | response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx"); |
| | | try { |
| | | // 新建ExcelWriter |
| | | ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()).build(); |
| | | |
| | | WriteSheet mainSheet = EasyExcel.writerSheet( "样品费用统计导出").head(CostStatisticsDto.class).build(); |
| | | excelWriter.write(costStatisticsDtos, mainSheet); |
| | | |
| | | // 关闭流 |
| | | excelWriter.finish(); |
| | | } catch (IOException e) { |
| | | throw new RuntimeException("导出失败"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |