package com.ruoyi.inspect.service.impl;
|
|
import cn.hutool.core.bean.BeanUtil;
|
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.style.HorizontalCellStyleStrategy;
|
import com.alibaba.excel.write.style.column.SimpleColumnWidthStyleStrategy;
|
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.TypeReference;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
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.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
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.numgen.NumberGenerator;
|
import com.ruoyi.common.utils.EasyExcelUtils;
|
import com.ruoyi.common.utils.QueryWrappers;
|
import com.ruoyi.common.utils.SecurityUtils;
|
import com.ruoyi.framework.exception.ErrorException;
|
import com.ruoyi.inspect.comparater.CustomComparator;
|
import com.ruoyi.inspect.dto.*;
|
import com.ruoyi.inspect.excel.FiberRibboGeometricalParameterExcelData;
|
import com.ruoyi.inspect.mapper.*;
|
import com.ruoyi.inspect.pojo.*;
|
import com.ruoyi.inspect.service.InsOrderService;
|
import com.ruoyi.inspect.service.InsProductService;
|
import com.ruoyi.inspect.vo.ExportInsProductVO;
|
import com.ruoyi.inspect.vo.SampleDefectsFatherVo;
|
import com.ruoyi.system.mapper.CustomMapper;
|
import com.ruoyi.system.mapper.UserMapper;
|
import com.ruoyi.system.service.ISysDictTypeService;
|
import lombok.AllArgsConstructor;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.security.core.Authentication;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Isolation;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import javax.servlet.http.HttpServletResponse;
|
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.LocalTime;
|
import java.time.format.DateTimeFormatter;
|
import java.util.*;
|
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.regex.Matcher;
|
import java.util.regex.Pattern;
|
import java.util.stream.Collectors;
|
|
/**
|
* @author gaoaoy
|
* @description 针对表【ins_order(检验下单)】的数据库操作Service实现
|
* @createDate 2024-03-12 16:17:55
|
*/
|
@Service
|
@Slf4j
|
@AllArgsConstructor
|
public class InsOrderServiceImpl extends ServiceImpl<InsOrderMapper, InsOrder>
|
implements InsOrderService {
|
|
private InsOrderMapper insOrderMapper;
|
|
private InsSampleMapper insSampleMapper;
|
|
private InsProductMapper insProductMapper;
|
|
private InsProductService insProductService;
|
|
private InsProductUserMapper insProductUserMapper;
|
|
private NumberGenerator<InsOrder> numberGenerator;
|
|
private NumberGenerator<InsSample> sampleCodeGenerator;
|
|
private NumberGenerator<InsFibers> fibersCodeGenerator;
|
|
private InsSampleUserMapper insSampleUserMapper;
|
|
private InsOrderStateMapper insOrderStateMapper;
|
|
UserMapper userMapper;
|
|
private InsBushingMapper insBushingMapper;
|
|
private InsFibersMapper insFibersMapper;
|
|
private InsFiberMapper insFiberMapper;
|
|
private InsProductResultMapper insProductResultMapper;
|
|
CustomMapper customMapper;
|
|
private ISysDictTypeService dictTypeService;
|
|
private ProcessOrder1Mapper processOrderMapper;
|
|
|
//获取检验下单数据
|
@Override
|
public IPage<SampleOrderDto> selectInsOrderParameter(Page<InsOrder> page, SampleOrderDto sampleOrderDto) {
|
page.setOptimizeCountSql(false);
|
List<String> startAndEndTime = sampleOrderDto.getStartAndEndTime();
|
String startTime = "";
|
String endTime = "";
|
if (CollectionUtils.isNotEmpty(startAndEndTime)) {
|
startTime = startAndEndTime.get(0) + " 00:00:00";
|
endTime = startAndEndTime.get(1) + " 23:59:59";
|
}
|
//// map.put("head", PrintChina.printChina(SampleOrderDto.class));
|
// //判断全部,个人,组织的权限
|
// Map<String, Integer> map1 = getLook.selectPowerByMethodAndUserId("selectInsOrderParameter");
|
User user = userMapper.selectById(SecurityUtils.getUserId());;//当前登录的人
|
// //获取当前人所属实验室id
|
String departLimsId = user.getDepartLimsId();
|
String laboratory = "";
|
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;
|
}
|
}
|
// //判断是否是全部权限
|
// SecurityUtils.hasPermi("");
|
// Power power = powerMapper.selectOne(Wrappers.<Power>lambdaQuery().eq(Power::getRoleId, roleId).eq(Power::getMenuMethod, "selectAllInsOrderParameter"));
|
// if (ObjectUtils.isEmpty(power)) {
|
// if (map1.get("look") == 1) {
|
// //个人
|
// sampleOrderDto.setCreateUser(map1.get("userId"));
|
// } else {
|
// //组织
|
// try {
|
// sampleOrderDto.setCompany(customMapper.selectById(user.getCompany()).getCompany());
|
// } catch (NullPointerException e) {
|
// throw new ErrorException("找不到所属单位");
|
// }
|
// }
|
// }
|
Integer state = sampleOrderDto.getState();
|
sampleOrderDto.setState(null);
|
IPage<SampleOrderDto> sampleOrderDtoIPage = insOrderMapper.selectInsOrderPage(page, QueryWrappers.queryWrappers(sampleOrderDto), laboratory, startTime, endTime, String.valueOf(state), null);
|
if (sampleOrderDtoIPage.getRecords().isEmpty() && (StringUtils.isNotBlank(sampleOrderDto.getEntrustCode()) || StringUtils.isNotBlank(sampleOrderDto.getOutEntrustCode()))) {
|
QueryWrapper<SampleOrderDto> wrapper = QueryWrappers.queryWrappers(sampleOrderDto);
|
IPage<InsOrder> orderPage = new Page<>();
|
BeanUtil.copyProperties(page, orderPage);
|
IPage<SampleOrderDto> otherPage = insOrderMapper.selectInsOrderPage(orderPage, wrapper, laboratory, startTime, endTime, null, String.valueOf(state));
|
if (1 == otherPage.getRecords().size()) {
|
sampleOrderDtoIPage = otherPage;
|
}
|
}
|
sampleOrderDtoIPage.getRecords().parallelStream().forEach(i -> {
|
if (ObjectUtils.isNotEmpty(i.getSampleCode()) && i.getSampleCode().contains(",")) {
|
String[] split = i.getSampleCode().split(",");
|
i.setSampleCode(split[0]);
|
}
|
});
|
return sampleOrderDtoIPage;
|
}
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public int upInsOrder(UpInsOrderDTO upInsOrderDTO) {
|
InsOrder insOrder = new InsOrder();
|
insOrder.setId(upInsOrderDTO.getOrderId());
|
insOrder.setAppointed(LocalDate.parse(upInsOrderDTO.getAppointed()));
|
insOrder.setSendTime(LocalDateTime.now());
|
insOrderMapper.updateById(insOrder);
|
List<InsSample> insSamples = insSampleMapper.selectList(Wrappers.<InsSample>lambdaQuery().eq(InsSample::getInsOrderId, upInsOrderDTO.getOrderId()).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::getState, 1)
|
// .isNull(InsProduct::getInsFibersId)
|
// .isNull(InsProduct::getInsFiberId)
|
.select(InsProduct::getSonLaboratory).groupBy(InsProduct::getSonLaboratory));
|
//查询ins_order_state,没有才新增
|
long count = insOrderStateMapper.selectCount(Wrappers.<InsOrderState>lambdaQuery().eq(InsOrderState::getInsOrderId, upInsOrderDTO.getOrderId()));
|
if (count == 0) {
|
for (InsProduct insProduct : insProducts) {
|
InsOrderState insOrderState = new InsOrderState();
|
insOrderState.setInsOrderId(upInsOrderDTO.getOrderId());
|
try {
|
insOrderState.setLaboratory(insProduct.getSonLaboratory());
|
} catch (NullPointerException e) {
|
throw new ErrorException("该检验单有未维护实验室的检验项目");
|
}
|
insOrderState.setInsState(0);
|
insOrderStateMapper.insert(insOrderState);
|
}
|
}
|
//添加样品检验人员
|
if (CollectionUtils.isNotEmpty(upInsOrderDTO.getUserIdList())) {
|
upInsOrderDTO.getUserIdList().forEach(userId -> {
|
InsSampleUser insSampleUser = new InsSampleUser();
|
insSampleUser.setState(0);
|
insSampleUser.setUserId(userId);
|
insSampleUser.setInsSampleId(upInsOrderDTO.getOrderId());
|
insSampleUser.setSonLaboratory(upInsOrderDTO.getSonLaboratory());
|
insSampleUserMapper.insert(insSampleUser);
|
});
|
}
|
return 1;
|
}
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public int addInsOrder(List<SampleProductDto> list, InsOrder insOrder, List<List<Integer>> pairing, List<List<Integer>> fiberPairing) {
|
insOrder.setState(0);
|
//判断选择的委托单位与制单人的委托单位是否一致
|
Integer userId = 1;
|
String company = userMapper.selectById(userId).getCompany();
|
if (!company.equals(insOrder.getCompanyId() + "")) {
|
//如果不一致那么委托人字段必填
|
if (ObjectUtils.isEmpty(insOrder.getPrepareUser())) {
|
throw new ErrorException("委托人不能为空");
|
}
|
} else {
|
//如果一致,那么制单人就是委托人
|
insOrder.setPrepareUser(insOrder.getCustom());
|
}
|
//客户代号
|
Custom custom = customMapper.selectById(insOrder.getCompanyId());
|
String customCode = custom.getCode2();
|
if (!custom.getCompany().equals(insOrder.getCompany())) {
|
Custom one = customMapper.selectOne(Wrappers.<Custom>lambdaQuery().eq(Custom::getCompany, insOrder.getCompany()));
|
insOrder.setCompanyId(one.getId());
|
customCode = one.getCode2();
|
}
|
//实验室编号
|
String laboratoryCode = baseMapper.selLaboratoryCode(insOrder.getLaboratory());
|
if (StringUtils.isEmpty(laboratoryCode)) {
|
laboratoryCode = "";
|
}
|
//外部委托编号
|
String outEntrustCodePrefix = getOutEntrustCodePrefix(customCode, laboratoryCode);
|
String outEntrustCode = numberGenerator.generateNumberWithPrefix(5, outEntrustCodePrefix, InsOrder::getOutEntrustCode);
|
insOrder.setOutEntrustCode(outEntrustCode);
|
insOrderMapper.insert(insOrder);
|
//生成样品编号
|
String currentDay = LocalDate.now().format(DateTimeFormatter.ofPattern("yyMMdd"));
|
String generatedSampleCode = sampleCodeGenerator.generateNumberWithPrefix(3, currentDay, InsSample::getSampleCode);
|
AtomicInteger count = new AtomicInteger();
|
List<FiberDto> fiberList = new ArrayList<>();
|
list.forEach(a -> {
|
count.getAndIncrement();
|
a.setId(null);
|
a.setInsOrderId(insOrder.getId());
|
if (StrUtil.isEmpty(a.getSampleCode())) {
|
a.setSampleCode(generatedSampleCode + "-" + count.get());
|
} else {
|
//去除手输的样品编号中首尾可能包含的空格
|
a.setSampleCode(a.getSampleCode().trim());
|
}
|
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().isEmpty()) {
|
fiberList.addAll(bushingDto.getFiber());
|
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);
|
}
|
}
|
//光纤带不为空
|
if (!bushingDto.getFibers().isEmpty()) {
|
for (FibersDto fibersDto : bushingDto.getFibers()) {
|
fibersDto.setInsBushingId(bushingDto.getId());
|
if (StringUtils.isBlank(fibersDto.getCode())) {
|
fibersDto.setCode(fibersCodeGenerator.generateNumberWithPrefix(3, currentDay, InsFibers::getCode));
|
}
|
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);
|
}
|
}
|
//都为空 只配置了套管 这种情况只限于项目或子项是含有松套管的
|
if (StringUtils.isNotBlank(bushingDto.getColor())) {
|
//检验项拼接字符
|
String insItem = a.getInsProduct().stream().map(InsProduct::getInspectionItem).distinct().collect(Collectors.joining(","));
|
//检验子项拼接字符
|
String insItemSubclass = a.getInsProduct().stream().map(InsProduct::getInspectionItemSubclass).distinct().collect(Collectors.joining(","));
|
if (insItem.contains("松套管") || insItemSubclass.contains("松套管")) {
|
//获取检验项目合或子项中包含松套管的检验项目
|
List<InsProduct> products = a.getInsProduct().stream()
|
.filter(insProduct -> insProduct.getInspectionItem().contains("松套管") ||
|
insProduct.getInspectionItemSubclass().contains("松套管"))
|
.collect(Collectors.toList());
|
for (InsProduct product : products) {
|
product.setInsBushId(bushingDto.getId());
|
product.setId(null);
|
product.setCreateTime(null);
|
product.setCreateUser(null);
|
product.setUpdateTime(null);
|
product.setUpdateUser(null);
|
product.setInsSampleId(a.getId());
|
if (product.getInspectionItemSubclass() == null) {
|
product.setInspectionItemSubclass("");
|
}
|
insProductMapper.insert(product);
|
}
|
}
|
}
|
}
|
}
|
}
|
if (ObjectUtil.isNotEmpty(a.getInsulating())) {
|
List<InsProduct> ip2 = new ArrayList<>();
|
for (int i = 0; i < a.getInsulating().getNum(); i++) {
|
ip2.addAll(a.getInsulating().getInsProduct());
|
}
|
for (InsProduct product : ip2) {
|
product.setStandardMethodListId(a.getInsulating().getStandardMethodListId());
|
}
|
addInsProductMethod(a.getId(), ip2, null, 0, false);
|
}
|
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);
|
}
|
if (ObjectUtil.isNotEmpty(a.getChildSampleList())) {
|
for (SampleProductDto b : a.getChildSampleList()) {
|
for (int i = 0; i < b.getNum(); i++) {
|
b.setId(null);
|
b.setInsOrderId(insOrder.getId());
|
b.setParentId(a.getId());
|
if (StrUtil.isEmpty(b.getSampleCode())) {
|
b.setSampleCode(sampleCodeGenerator.generateNumberWithPrefix(3, currentDay, InsSample::getSampleCode));
|
}
|
insSampleMapper.insert(b);
|
if (ObjectUtil.isNotEmpty(b.getInsProduct())) {
|
addInsProductMethod(b.getId(), b.getInsProduct(), null, 0, false);
|
}
|
}
|
}
|
}
|
if (ObjectUtil.isEmpty(a.getInsProduct()) && ObjectUtil.isNotEmpty(a.getBushing())) {
|
for (BushingDto bushingDto : a.getBushing()) {
|
bushingDto.setInsSampleId(a.getId());
|
insBushingMapper.insert(bushingDto);
|
if (!bushingDto.getFiber().isEmpty()) {
|
fiberList.addAll(bushingDto.getFiber());
|
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(fibersCodeGenerator.generateNumberWithPrefix(3, currentDay, InsFibers::getCode));
|
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);
|
List<InsProduct> insProducts = sample.getInsProduct().stream().filter(a -> Objects.equals(a.getInspectionItem(), "光纤接头损耗")).collect(Collectors.toList());
|
if (!insProducts.isEmpty()) {
|
sample.setSampleCode(list.get(i.get(0) - 1).getSampleCode() + "/" + list.get(i.get(1) - 1).getSampleCode());
|
sample.setId(null);
|
sample.setIsPairing("1");
|
insSampleMapper.insert(sample);
|
try {
|
for (InsProduct insProduct : insProducts) {
|
insProduct.setId(null);
|
insProduct.setInsSampleId(sample.getId());
|
insProductMapper.insert(insProduct);
|
}
|
} catch (Exception e) {
|
}
|
}
|
}
|
//光纤配置的熔接配对
|
if (!fiberPairing.isEmpty()) {
|
for (List<Integer> integers : fiberPairing) {
|
StringBuilder code1 = new StringBuilder(list.get(0).getSampleCode() + "-");
|
StringBuilder code2 = new StringBuilder(list.get(1).getSampleCode() + "-");
|
//配对的两个光纤色标
|
FiberDto fiberDto1 = fiberList.get(integers.get(0) - 1);
|
code1.append(fiberDto1.getBushColor()).append("-").append(fiberDto1.getColor());
|
FiberDto fiberDto2 = fiberList.get(integers.get(1) - 1);
|
code2.append(fiberDto2.getBushColor()).append("-").append(fiberDto2.getColor());
|
//勾选的光纤接头损耗检验项
|
//List<InsProduct> insProducts = fiberDto1.getProductList().stream().filter(a -> Objects.equals(a.getInspectionItem(), "光纤接头损耗")).collect(Collectors.toList());
|
|
//配对后的样品
|
InsSample insSample = new InsSample();
|
BeanUtil.copyProperties(list.get(0), insSample);
|
insSample.setSampleCode(code1 + "/" + code2);
|
insSample.setId(null);
|
insSample.setIsPairing("1");
|
insSampleMapper.insert(insSample);
|
|
|
// 如果是光纤配置的熔接配对,只需要获取list的bushing就行,生成的样品个数与下单界面样品个数无关
|
// 一个样品下面只需要添加一次product 只添加光纤接头损耗的检验项
|
// 添加套管
|
List<BushingDto> bushing = list.get(0).getBushing();
|
if (CollectionUtils.isNotEmpty(bushing)) {
|
for (int j = 0; j < bushing.size(); j++) {
|
bushing.get(j).setId(null);
|
bushing.get(j).setInsSampleId(insSample.getId());
|
insBushingMapper.insert(bushing.get(j));
|
Integer bushingId = bushing.get(j).getId();
|
// 添加光纤带
|
List<FibersDto> fibers = bushing.get(j).getFibers();
|
if (CollectionUtils.isNotEmpty(fibers)) {
|
fibers.forEach(item -> {
|
item.setId(null);
|
item.setInsBushingId(bushingId); // 套管id
|
insFibersMapper.insert(item);
|
// 将检验项的光纤带id赋值
|
if (CollectionUtils.isNotEmpty(item.getProductList())) {
|
item.getProductList().forEach(insProduct -> {
|
if (insProduct.getInspectionItem().equals("光纤接头损耗")) {
|
insProduct.setInsFibersId(item.getId()); // 光纤带id
|
insProduct.setInsSampleId(insSample.getId()); // 样品id
|
insProduct.setId(null);
|
insProductMapper.insert(insProduct);
|
}
|
});
|
}
|
// 是否含有光纤
|
if (CollectionUtils.isNotEmpty(item.getFiber())) {
|
List<FiberDto> fiber = item.getFiber();
|
fiber.forEach(f -> {
|
f.setId(null);
|
f.setInsBushingId(bushingId); // 套管id
|
insFiberMapper.insert(f);
|
f.getProductList().forEach(insProduct -> {
|
if (insProduct.getInspectionItem().equals("光纤接头损耗")) {
|
insProduct.setInsFiberId(f.getId()); // 光纤id
|
insProduct.setInsSampleId(insSample.getId()); // 样品id
|
insProduct.setId(null);
|
insProductMapper.insert(insProduct);
|
}
|
});
|
});
|
}
|
|
});
|
}
|
// 只有光纤的情况下
|
else {
|
bushing.get(j).getFiber().forEach(f -> {
|
f.setInsBushingId(bushingId); // 套管id
|
f.setId(null);
|
insFiberMapper.insert(f);
|
f.getProductList().forEach(insProduct -> {
|
if (insProduct.getInspectionItem().equals("光纤接头损耗")) {
|
insProduct.setInsFiberId(f.getId()); // 光纤id
|
insProduct.setInsSampleId(insSample.getId()); // 样品id
|
insProduct.setId(null);
|
insProductMapper.insert(insProduct);
|
}
|
});
|
});
|
}
|
}
|
}
|
}
|
}
|
return insOrder.getId();
|
}
|
|
/**
|
* 生成外部委托编号前缀:ZT/TX-01-2411XXXXX
|
*
|
* @param customCode 客户代号
|
* @param labCode 试验室代号
|
* @return
|
*/
|
private static String getOutEntrustCodePrefix(String customCode, String labCode) {
|
String currentMonth = LocalDate.now().format(DateTimeFormatter.ofPattern("yyMM"));
|
return "ZT/" + labCode + "-" + customCode + "-" + currentMonth;
|
}
|
|
/**
|
* 生成检测中心委托编号前缀:JCZX/TX-01-2411XXXXX
|
*
|
* @param customCode 客户代号
|
* @param labCode 试验室代号
|
* @return
|
*/
|
private static String getEntrustCodePrefix(String customCode, String labCode) {
|
String currentMonth = LocalDate.now().format(DateTimeFormatter.ofPattern("yyMM"));
|
return "JCZX/" + labCode + "-" + customCode + "-" + currentMonth;
|
}
|
|
private void addInsProductMethod(Integer sampleId, List<InsProduct> productList, Integer id, Integer type, Boolean is) {
|
InsOrder insOrder = insOrderMapper.selectById(insSampleMapper.selectById(sampleId).getInsOrderId());
|
String name = insSampleMapper.selMethodById(sampleId);
|
for (InsProduct product : productList) {
|
if (product.getInspectionItem().contains("松套管") || (!Objects.isNull(product.getInspectionItemSubclass()) && product.getInspectionItemSubclass().contains("松套管"))) {
|
continue;
|
}
|
if (product.getState() == 1 && !product.getInspectionItem().equals("光纤接头损耗")) {
|
//判断光缆的温度循环项目添加
|
if (insOrder.getSampleType().equals("光缆") && product.getInspectionItem().equals("温度循环") && type != 0) {
|
//判断选择的标准方法是委托要求还是其他标准方法
|
if (!name.equals("委托要求")) {
|
//判断标准方法的温度循环的要求描述是否有填写
|
if (ObjectUtils.isEmpty(product.getTell()) || product.getTell().isEmpty()) {
|
throw new ErrorException("光缆的温度循环的要求描述为空,需要在标准库配置要求描述!!!");
|
} else {
|
//解析(温度范围:20℃,-40℃,65℃;保温时间:12h; 循环次数:2次; 光纤(1310nm,1550nm)附加衰减不大于0.03dB/km)
|
String tell = product.getTell().replace(")", ")")
|
.replace("(", "(")
|
.replace(")", ")")
|
.replace(",", ",")
|
.replace(":", ":")
|
.replace(";", ";")
|
.replace("不大于", "≤")
|
.replace("不小于", "≥")
|
.replace("大于", ">")
|
.replace("小于", "<")
|
.replace("等于", "=");
|
String[] message = null;
|
String[] nm = null;
|
String ask = null;
|
String count = null;
|
try {
|
String[] strings = tell.split(";");
|
//温度
|
String temperature = strings[0];
|
String[] split = temperature.split(":");
|
message = split[1].split(",");
|
//循环次数
|
count = strings[2].split(":")[1].split("次")[0];
|
//光纤项目和要求值
|
String string = strings[3];
|
nm = string.split("(")[1].split(")")[0].split(",");
|
ask = string.split("衰减")[1].split("dB")[0];
|
} catch (Exception e) {
|
throw new ErrorException("温度循环的要求描述格式异常,请参照温度范围:20℃,-40℃,65℃;保温时间:12h; 循环次数:2次; 光纤(1310nm,1550nm)附加衰减不大于0.03dB/km");
|
}
|
//拼接
|
String s = "";
|
for (int i = 0; i < nm.length; i++) {
|
s += "20℃(常温)," + nm[i] + ",null;";
|
for (int j = 0; j < message.length; j++) {
|
s += message[j] + "," + nm[i] + "," + ask + ";";
|
}
|
}
|
s += count;
|
product.setAsk(s);
|
insProductMapper.updateById(product);
|
dealWithTemperatureLoop(type, id, sampleId, product);
|
}
|
} else {
|
//20℃(常温),1310nm,null;-40℃,1310nm,≤0.2;75℃,1310nm,<0.3;20℃,1310nm,≤0.1;20℃(常温),1550nm,null;-40℃,1550nm,≤0.2;75℃,1550nm,<0.3;20℃,1550nm,≤0.1;3
|
dealWithTemperatureLoop(type, id, sampleId, product);
|
}
|
}
|
//判断热循环项目的添加和温升试验项目的添加
|
else if (product.getInspectionItem().equals("热循环") || product.getInspectionItem().equals("温升试验")) {
|
List<InsProduct> insProductess = new ArrayList<>();
|
product.setId(null);
|
product.setInsSampleId(sampleId);
|
insProductMapper.insert(product);
|
// 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.setManHour(product.getManHour());//工时
|
insProduct.setManHourGroup(product.getManHourGroup());
|
insProduct.setInspectionItemType("0");
|
insProduct.setInspectionValueType("1");
|
insProduct.setTemplateId(product.getTemplateId());//添加模板id
|
insProduct.setSpecialItemParentId(product.getId());//特殊项父id
|
if (product.getInspectionItem().equals("热循环")) {
|
insProduct.setInspectionItemClass("直流电阻");//检验子子项--直流电阻
|
insProduct.setInspectionItemClassEn("DC resistance");//检验子子项英文--直流电阻
|
insProduct.setUnit("Ω/km");//单位
|
}
|
insProducts.add(insProduct);
|
insProductes.add(insProduct);
|
insProductess.add(insProduct);
|
}
|
//热循环才有多次循环次数
|
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 (product.getInspectionItem().contains("弧垂")) {
|
product.setId(null);
|
product.setInsSampleId(sampleId);
|
insProductMapper.insert(product);
|
//需要添加的子项
|
List<Map<String, Object>> childrenMapList = initChildrenList();
|
//子项
|
List<InsProduct> childrenProducts = new ArrayList<>();
|
for (Map<String, Object> map : childrenMapList) {
|
InsProduct insProduct = new InsProduct();
|
insProduct.setInspectionItem(product.getInspectionItem());
|
insProduct.setInspectionItemSubclass(map.get("inspectionItem").toString());
|
insProduct.setUnit(map.get("unit").toString());
|
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.setManHour(product.getManHour());//工时
|
insProduct.setManHourGroup(product.getManHourGroup());
|
insProduct.setInspectionItemType("0");
|
insProduct.setInspectionValueType("1");
|
insProduct.setTemplateId(product.getTemplateId());//添加模板id
|
insProduct.setSpecialItemParentId(product.getId());//特殊项父id
|
childrenProducts.add(insProduct);
|
}
|
insProductService.saveBatch(childrenProducts);
|
} else {
|
if (!is) {
|
switch (type) {
|
case 1:
|
product.setInsFibersId(id);
|
break;
|
case 2:
|
product.setInsFiberId(id);
|
break;
|
}
|
product.setId(null);
|
product.setCreateTime(null);
|
product.setCreateUser(null);
|
product.setUpdateTime(null);
|
product.setUpdateUser(null);
|
product.setInsSampleId(sampleId);
|
if (product.getInspectionItemSubclass() == null) {
|
product.setInspectionItemSubclass("");
|
}
|
// 普通项目 如果ask包含了 % 就去除
|
if(product.getAsk().contains("%")) {
|
String ask = product.getAsk().replace("%", "").trim();
|
product.setAsk(ask);
|
}
|
insProductMapper.insert(product);
|
}
|
}
|
}
|
|
|
}
|
}
|
|
/**
|
* 初始化弧垂特殊项目子项
|
* 固定子项:额定拉断力,跨距长度,载荷,高度,弧垂,导线温度,室温,张力
|
*
|
* @return
|
*/
|
private List<Map<String, Object>> initChildrenList() {
|
List<Map<String, Object>> maps = new ArrayList<>();
|
Map<String, Object> map1 = new HashMap<>();
|
map1.put("inspectionItem", "额定拉断力");
|
map1.put("unit", "kN");
|
Map<String, Object> map2 = new HashMap<>();
|
map2.put("inspectionItem", "跨距长度");
|
map2.put("unit", "m");
|
Map<String, Object> map3 = new HashMap<>();
|
map3.put("inspectionItem", "载荷");
|
map3.put("unit", "kN");
|
Map<String, Object> map5 = new HashMap<>();
|
map5.put("inspectionItem", "弧垂");
|
map5.put("unit", "mm");
|
Map<String, Object> map6 = new HashMap<>();
|
map6.put("inspectionItem", "导线温度");
|
map6.put("unit", "℃");
|
Map<String, Object> map7 = new HashMap<>();
|
map7.put("inspectionItem", "室温");
|
map7.put("unit", "℃");
|
Map<String, Object> map8 = new HashMap<>();
|
map8.put("inspectionItem", "张力");
|
map8.put("unit", "kN");
|
|
maps.add(map1);
|
maps.add(map2);
|
maps.add(map3);
|
maps.add(map5);
|
maps.add(map6);
|
maps.add(map7);
|
maps.add(map8);
|
|
return maps;
|
}
|
|
//温度循环的处理
|
private void dealWithTemperatureLoop(Integer type, Integer id, Integer sampleId, InsProduct product) {
|
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.setManHour(product.getManHour());
|
insProduct.setInspectionItemType("0");
|
insProduct.setInspectionValueType("1");
|
insProduct.setTemplateId(product.getTemplateId());//添加模板id
|
insProduct.setSpecialItemParentId(product.getId());//特殊项父id
|
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);
|
}
|
|
@Override
|
public Map<String, Object> getInsOrder(Integer id) {
|
Map<String, Object> map = new HashMap<>();
|
InsOrder insOrder = insOrderMapper.selectById(id);
|
List<SampleProductDto> list = insSampleMapper.selectSampleProductListByOrderId2(id);
|
// 如果是光纤配置接头损耗只需展示A端、B端、平均值
|
if (CollectionUtils.isNotEmpty(list)) {
|
for (SampleProductDto dto : list) {
|
// 获取检验项目
|
List<InsProduct> insProducts = dto.getInsProduct();
|
if (CollectionUtils.isNotEmpty(insProducts)) {
|
// 过滤出光纤配置的光纤接头损耗检验项目
|
List<InsProduct> productList = insProducts.stream().filter(item -> item.getInspectionItem().equals("光纤接头损耗")
|
&& (!Objects.isNull(item.getInsFiberId()) || !Objects.isNull(item.getInsFibersId()))).collect(Collectors.toList());
|
if (CollectionUtils.isNotEmpty(productList)) {
|
// 只返回光纤街头损耗检验项目 且 只展示一次
|
// 根据检验项进行分组
|
Map<String, List<InsProduct>> collect = productList.stream().collect(Collectors.groupingBy(InsProduct::getInspectionItemSubclass));
|
List<InsProduct> productList2 = new ArrayList<>();
|
Iterator<Map.Entry<String, List<InsProduct>>> iterator = collect.entrySet().iterator();
|
while (iterator.hasNext()) {
|
Map.Entry<String, List<InsProduct>> entry = iterator.next();
|
productList2.add(entry.getValue().get(0));
|
}
|
dto.setInsProduct(productList2);
|
}
|
|
}
|
}
|
}
|
map.put("insOrder", insOrder);
|
map.put("sampleProduct", list);
|
return map;
|
}
|
|
@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 laboratoryCode = baseMapper.selLaboratoryCode(insOrder.getLaboratory());
|
if (StringUtils.isEmpty(laboratoryCode)) {
|
laboratoryCode = "";
|
}
|
Custom custom = customMapper.selectById(order.getCompanyId());
|
// System.out.println("============="+custom.getCompany());
|
// System.out.println("-------------"+order.getCompany());
|
String customCode = custom.getCode2();
|
if (!custom.getCompany().equals(order.getCompany())) {
|
Custom one = customMapper.selectOne(Wrappers.<Custom>lambdaQuery().eq(Custom::getCompany, order.getCompany()));
|
insOrder.setCompanyId(one.getId());
|
customCode = one.getCode2();
|
}
|
String entrustCodePrefix = getEntrustCodePrefix(customCode, laboratoryCode);
|
String entrustCode = numberGenerator.generateNumberWithPrefix(4, entrustCodePrefix, InsOrder::getEntrustCode);
|
insOrder.setEntrustCode(entrustCode);
|
// insOrder.setEntrustCode(giveCode.giveCode2("JCZX/" + code + "-" + code2 + "-", insOrder.getCompanyId(), insOrder.getLaboratory(), "ins_order", "", "yyMM"));
|
/*审核通过还需要新增一条cnas要求、标书和合同评审*/
|
ProcessOrder processOrder = new ProcessOrder();
|
processOrder.setInsOrderId(insOrder.getId());
|
processOrderMapper.insert(processOrder);
|
}
|
return insOrderMapper.updateById(insOrder);
|
}
|
|
@Override
|
public Map<String, Object> getInsOrderAndSample(Integer id, String laboratory) {
|
Map<String, Object> map = new HashMap<>();
|
InsOrder insOrder = insOrderMapper.selectById(id);
|
Integer insState = insOrderStateMapper.selectOne(new LambdaQueryWrapper<InsOrderState>().eq(InsOrderState::getLaboratory, laboratory).eq(InsOrderState::getInsOrderId, id)).getInsState();
|
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);
|
map.put("insState", insState);
|
//查询所有记录模版去重
|
List<Map<Integer, Object>> list2 = insOrderMapper.selectReportModelByOrderId(id, laboratory);
|
map.put("reportModel", list2);
|
return map;
|
}
|
|
@Override
|
public List<SampleProductDto2> selectSampleAndProductByOrderId(SampleProductDto2 sampleProductDto) {
|
List<SampleProductDto2> SampleProductDto2S = null;
|
if (!Objects.isNull(sampleProductDto.getId())) {
|
String laboratory = insOrderMapper.selectById(sampleProductDto.getId()).getLaboratory();
|
if (laboratory.equals("电力产品实验室")) {
|
//电力试验室的数据查看,删除光纤配置相关字段
|
SampleProductDto2S = insOrderMapper.selectSampleAndProductByOrderId(
|
QueryWrappers.queryWrappers(sampleProductDto).orderByAsc("ins_product_id"),
|
sampleProductDto.getId());
|
} else {
|
SampleProductDto2S = insOrderMapper.selectSampleAndProductByOrderId(
|
QueryWrappers.queryWrappers(sampleProductDto)
|
.orderByAsc("son_laboratory"),
|
// .orderByAsc("inspection_item")
|
// .orderByAsc("inspection_item_subclass"),
|
sampleProductDto.getId());
|
List<SampleProductDto2> collect = SampleProductDto2S
|
.stream()
|
.filter(item -> item.getInspectionItem().contains("松套管") || item.getInspectionItemSubclass()
|
.contains("松套管")).collect(Collectors.toList());
|
// 样品下的松套管
|
Map<String, List<SampleProductDto2>> collect1 = collect
|
.stream()
|
.collect(Collectors.groupingBy(item -> item.getSampleCode() + '@' + item.getInspectionItemSubclass() + '@' + item.getInspectionItem()));
|
Iterator<Map.Entry<String, List<SampleProductDto2>>> iterator = collect1.entrySet().iterator();
|
ArrayList<SampleProductDto2> list = new ArrayList<>();
|
while (iterator.hasNext()) {
|
SampleProductDto2 sampleProductDto2 = new SampleProductDto2();
|
double avg = 0.0;
|
double count = 0.0;
|
boolean flag = true;
|
Map.Entry<String, List<SampleProductDto2>> next = iterator.next();
|
for (SampleProductDto2 s : next.getValue()) {
|
if (StringUtils.isNotEmpty(s.getLastValue()) && (NumberUtil.isNumber(s.getLastValue()))) {
|
count += Double.parseDouble(s.getLastValue());
|
} else if (!NumberUtil.isNumber(s.getLastValue()) && StringUtils.isNotEmpty(s.getLastValue())) {
|
flag = false;
|
}
|
}
|
BeanUtil.copyProperties(next.getValue().get(0), sampleProductDto2);
|
sampleProductDto2.setBushColor("");
|
List<SampleProductDto2> collect2 = next.getValue().stream().filter(item -> Objects.nonNull(item.getInsResult()) && item.getInsResult().equals(0)).collect(Collectors.toList()); // 不合格
|
List<SampleProductDto2> collect3 = next.getValue().stream().filter(item -> Objects.nonNull(item.getInsResult()) && item.getInsResult().equals(3)).collect(Collectors.toList()); // 不判定
|
List<SampleProductDto2> collect4 = next.getValue().stream().filter(item -> StringUtils.isNotEmpty(item.getLastValue())).collect(Collectors.toList()); // 不判定
|
if (CollectionUtils.isNotEmpty(collect2)) {
|
sampleProductDto2.setInsResult(0);
|
sampleProductDto2.setLastValue(collect2.get(0).getLastValue());
|
} else if (CollectionUtils.isNotEmpty(collect3)) {
|
sampleProductDto2.setInsResult(3);
|
} else if (CollectionUtils.isNotEmpty(collect4)) {
|
sampleProductDto2.setInsResult(1);
|
} else {
|
sampleProductDto2.setInsResult(null);
|
}
|
if (flag) {
|
avg = BigDecimal.valueOf(count).divide(BigDecimal.valueOf(next.getValue().size()), 4, RoundingMode.HALF_UP).doubleValue();
|
if (avg == 0.0) {
|
sampleProductDto2.setLastValue("");
|
} else {
|
sampleProductDto2.setLastValue(String.valueOf(avg));
|
}
|
}
|
sampleProductDto2.setInspectionItem(next.getKey().split("@")[2]);
|
sampleProductDto2.setInspectionItemSubclass(next.getKey().split("@")[1]);
|
list.add(sampleProductDto2);
|
}
|
// 过滤出不包含为松套管且不为光纤接头损耗的数据
|
List<SampleProductDto2> collect2 = SampleProductDto2S
|
.stream()
|
.filter(item -> !item.getInspectionItem().contains("松套管") && !item.getInspectionItemSubclass()
|
.contains("松套管") && !item.getInspectionItem().equals("光纤接头损耗")).collect(Collectors.toList());
|
// 如果是光纤接头损耗 一个样品只取其中一个的A端、B端、平均值
|
Map<String, List<SampleProductDto2>> fiberMap = SampleProductDto2S
|
.stream()
|
.filter(item -> item.getInspectionItem().equals("光纤接头损耗"))
|
.collect(Collectors.groupingBy(e -> e.getSampleCode() + e.getInspectionItem() + e.getInspectionItemSubclass()));
|
Iterator<Map.Entry<String, List<SampleProductDto2>>> iterator1 = fiberMap.entrySet().iterator();
|
while (iterator1.hasNext()) {
|
Map.Entry<String, List<SampleProductDto2>> entry = iterator1.next();
|
list.add(entry.getValue().get(0));
|
}
|
collect2.addAll(list);
|
SampleProductDto2S = collect2;
|
SampleProductDto2S.sort(new CustomComparator(dictTypeService));
|
}
|
}
|
for (SampleProductDto2 record : SampleProductDto2S) {
|
List<String> values = new ArrayList<>();
|
//光纤带编号不为空&&检验过程值不为空
|
if (StringUtils.isNotBlank(record.getCode()) && (StringUtils.isNotBlank(record.getInsValue()) || Objects.equals(record.getInsValue(), "[]"))) {
|
JSONArray insValueJsonArray = JSON.parseArray(record.getInsValue());
|
for (Object o : insValueJsonArray) {
|
JSONObject insValue = JSON.parseObject(JSON.toJSONString(o));
|
if (StringUtils.isNotBlank(insValue.get("v").toString())) {
|
values.add(insValue.get("v").toString());
|
}
|
}
|
record.setLastValue(String.join(",", values));
|
}
|
}
|
return SampleProductDto2S;
|
}
|
|
@Override
|
public List<Map<String, Object>> viewDetails(Map<String, Object> map) {
|
List<Map<String, Object>> list = new ArrayList<>();
|
String inspectionItem = map.get("inspectionItem").toString(); // 检验项
|
String inspectionItemSubclass = map.get("inspectionItemSubclass").toString(); // 检验子项
|
if (inspectionItem.equals("单根垂直燃烧")) {
|
ArrayList<Integer> numbers = new ArrayList<>();
|
InsProduct insProduct = insProductMapper.selectById(Integer.parseInt(map.get("insProductId").toString()));
|
String[] split = insProduct.getTell().split(",");
|
Pattern pattern = Pattern.compile("-?\\d+");
|
Matcher matcher = pattern.matcher(split[1]);
|
while (matcher.find()) {
|
String numberStr = matcher.group();
|
numbers.add(Integer.parseInt(numberStr));
|
}
|
InsProductResult result = insProductResultMapper.selectOne(new LambdaQueryWrapper<InsProductResult>()
|
.eq(InsProductResult::getInsProductId, Integer.parseInt(map.get("insProductId").toString())));
|
|
|
for (int i = 0; i < numbers.get(0); i++) {
|
HashMap<String, Object> map1 = new HashMap<>();
|
map1.put("entrustCode", map.get("entrustCode")); // 委托编号
|
map1.put("sampleCode", map.get("sampleCode")); // 样品编号
|
map1.put("color", ""); // 套管
|
map1.put("inspectionItem", inspectionItem); // 检验项
|
if (!Objects.isNull(result)) {
|
List<Map> maps = JSONArray.parseArray(result.getInsValue(), Map.class);
|
if (maps.size() - 1 < i) {
|
map1.put("insValue", ""); // 检验结果
|
} else {
|
map1.put("insValue", maps.get(i).get("v")); // 检验结果
|
}
|
}
|
list.add(map1);
|
}
|
} else if (inspectionItem.equals("抗拉强度")) {
|
InsProduct insProduct = insProductMapper.selectById(Integer.parseInt(map.get("insProductId").toString()));
|
InsProductResult insProductResult = insProductResultMapper.selectOne(new LambdaQueryWrapper<InsProductResult>()
|
.eq(InsProductResult::getInsProductId, insProduct.getId()));
|
if(Objects.isNull(insProductResult)) {
|
return list;
|
}
|
List<Map<String, Object>> values = JSON.parseObject(insProductResult.getInsValue(), new TypeReference<List<Map<String, Object>>>() {
|
});
|
// 进行排序 根据坐标
|
values.sort((o1, o2) -> {
|
int i = Integer.parseInt(o1.get("r").toString());
|
int i1 = Integer.parseInt(o2.get("r").toString());
|
return Integer.compare(i,i1);
|
});
|
// 将得到的宽度、厚度、检验值分别进行存储
|
Map<Object, List<Map<String, Object>>> group = values.stream().collect(Collectors.groupingBy(item -> item.get("r")));
|
Iterator<Map.Entry<Object, List<Map<String, Object>>>> iterator = group.entrySet().iterator();
|
List<String> widths = new ArrayList<>();
|
List<String> thickness = new ArrayList<>();
|
List<String> testValue = new ArrayList<>();
|
Integer count = 0;
|
while (iterator.hasNext()) {
|
Map.Entry<Object, List<Map<String, Object>>> entry = iterator.next();
|
List<Map<String, Object>> value = entry.getValue();
|
for(Map<String,Object> m : value) {
|
if(count == 0) {
|
widths.add(m.get("v").toString());
|
}else if(count == 1) {
|
thickness.add(m.get("v").toString());
|
}else {
|
testValue.add(m.get("v").toString());
|
}
|
}
|
count++;
|
}
|
// 进行封装返回
|
// 找到最长的那个集合
|
List<Integer> list1 = Arrays.asList(widths.size(), thickness.size(), testValue.size());
|
list1.sort((a1, a2) -> {
|
return Integer.compare(a2,a1);
|
});
|
for (int i = 0; i < list1.get(0); i++) {
|
HashMap<String, Object> map1 = new HashMap<>();
|
map1.put("inspectionItem",insProduct.getInspectionItem()); // 检验项
|
map1.put("inspectionItemSubclass",insProduct.getInspectionItemSubclass()); // 检验子项
|
map1.put("width",""); // 宽度
|
map1.put("thickness",""); // 厚度
|
map1.put("testValue",""); // 检验值
|
if(i < widths.size() ) {
|
map1.put("width",widths.get(i));
|
}
|
if(i < thickness.size()) {
|
map1.put("thickness",thickness.get(i));
|
}
|
if(i < testValue.size()) {
|
map1.put("testValue",testValue.get(i));
|
}
|
list.add(map1);
|
}
|
|
} else if(inspectionItem.equals("断裂伸长率")) {
|
InsProduct insProduct = insProductMapper.selectById(Integer.parseInt(map.get("insProductId").toString()));
|
InsProductResult insProductResult = insProductResultMapper.selectOne(new LambdaQueryWrapper<InsProductResult>()
|
.eq(InsProductResult::getInsProductId, insProduct.getId()));
|
if(Objects.isNull(insProductResult)) {
|
return list;
|
}
|
List<Map<String, Object>> values = JSON.parseObject(insProductResult.getInsValue(), new TypeReference<List<Map<String, Object>>>() {
|
});
|
HashMap<String, Object> map1 = new HashMap<>();
|
map1.put("inspectionItem",insProduct.getInspectionItem()); // 检项项
|
map1.put("inspectionItemSubclass",insProduct.getInspectionItemSubclass()); // 检项子项
|
ArrayList<Map<String, Object>> tableHeader = new ArrayList<>();
|
for (int i = 0; i < values.size(); i++) {
|
HashMap<String, Object> map2 = new HashMap<>();
|
map2.put("testValue" + i,values.get(i).get("v")); // 检项值 表头
|
tableHeader.add(map2);
|
map1.put("testValue" + i,values.get(i).get("v"));
|
}
|
map1.put("tableHeader",tableHeader);
|
list.add(map1);
|
} else {
|
// 松套管 过滤出检验项名称一致的数据
|
List<InsProduct> productList = insProductMapper.selectList(new LambdaQueryWrapper<InsProduct>()
|
.eq(InsProduct::getInspectionItem, inspectionItem)
|
.eq(StringUtils.isNotEmpty(inspectionItemSubclass),InsProduct::getInspectionItemSubclass, inspectionItemSubclass)
|
.eq(InsProduct::getInsSampleId, Integer.parseInt(map.get("insSampleId").toString())));
|
for (InsProduct product : productList) {
|
HashMap<String, Object> map2 = new HashMap<>();
|
map2.put("entrustCode", map.get("entrustCode")); // 委托编号
|
map2.put("sampleCode", map.get("sampleCode")); // 样品编号
|
map2.put("inspectionItem", product.getInspectionItem()); // 检验项
|
map2.put("insValue", product.getLastValue()); // 检验结果
|
// 拿到相应的套管
|
String color = "";
|
if (!Objects.isNull(product.getInsBushId())) {
|
color = insBushingMapper.selectById(product.getInsBushId()).getColor(); // 套管
|
}
|
map2.put("color", color); // 套管颜色
|
list.add(map2);
|
}
|
}
|
return list;
|
}
|
|
/**
|
* 导出已检委托单
|
*
|
* @param data
|
* @param response
|
*/
|
@Override
|
public void exportChecked(Map<String, Object> data, HttpServletResponse response) {
|
// Integer userId = getLook.selectPowerByMethodAndUserId(null).get("userId");
|
User user = userMapper.selectById(SecurityUtils.getLoginUser().getUserId());
|
List<String> names = null;
|
String startTime = "";
|
String endTime = "";
|
if (data.containsKey("startTime")) {
|
startTime = data.get("startTime").toString() + " 00:00:00";
|
}
|
if (data.containsKey("endTime")) {
|
endTime = data.get("endTime").toString() + " 23:59:59";
|
}
|
List<ExcelChecked> list = new ArrayList<>();
|
|
// 如果是检测中心人员可以导入所有客户下的单 , 如果是客户,可以导出该单位所有的单
|
if (user.getIsCustom().equals(0)) {
|
names = new ArrayList<>();
|
} else {
|
String company = user.getCompany();
|
List<User> users = userMapper.selectList(new LambdaQueryWrapper<User>()
|
.eq(User::getCompany, company)
|
.eq(User::getIsCustom, 1)
|
.eq(User::getStatus, 0));
|
if (CollectionUtils.isNotEmpty(users)) {
|
names = users.stream().map(item -> item.getName()).collect(Collectors.toList());
|
}
|
}
|
//总的检验结果
|
List<ExportInsProductVO> exportInsProductVOS = insOrderMapper.exportChecked(names, startTime, endTime);
|
//排除光纤带几何参数(尺寸参数),温度循环的检验结果
|
// List<ExcelChecked> excelCheckeds = exportInsProductVOS.stream().map(e -> {
|
// ExcelChecked excelChecked = new ExcelChecked();
|
// BeanUtil.copyProperties(e, excelChecked);
|
// return excelChecked;
|
// }).collect(Collectors.toList());
|
// 排除光纤带几何参数(尺寸参数),温度循环的检验结果
|
List<ExportInsProductVO> excelCheckeds = exportInsProductVOS.stream().filter(e -> !e.getInspectionItem().equals("温度循环")
|
&& !(NumberUtil.isInteger(e.getInspectionItem()) && Objects.nonNull(e.getSpecialItemParentId()))
|
&& !(e.getInspectionItem().equals("尺寸参数")
|
&& e.getSampleType().equals("光纤带")))
|
.collect(Collectors.toList());
|
if (CollectionUtils.isNotEmpty(excelCheckeds)) {
|
for (ExportInsProductVO a : excelCheckeds) {
|
ExcelChecked excelChecked = new ExcelChecked();
|
BeanUtil.copyProperties(a, excelChecked);
|
list.add(excelChecked);
|
}
|
}
|
//过滤出光纤带几何参数的检验结果
|
List<ExportInsProductVO> sizeParameter = exportInsProductVOS.stream().filter(e ->
|
e.getInspectionItem().equals("尺寸参数")
|
&& e.getSampleType().equals("光纤带"))
|
.collect(Collectors.toList());
|
List<FiberRibboGeometricalParameterExcelData> fiberList = new ArrayList<>();
|
if (CollectionUtils.isNotEmpty(sizeParameter)) {
|
// 根据委托单号、样品编号、套管、光纤带编号进行分组
|
Map<String, List<ExportInsProductVO>> groupData = sizeParameter.stream().sorted(Comparator.comparing(ExportInsProductVO::getSampleCode))
|
.collect(Collectors.toMap(e ->
|
e.getEntrustCode() + '@' + e.getSampleCode() + '@' + e.getBushColor() + '@' + e.getCode(),
|
Collections::singletonList,
|
(left, right) -> {
|
ArrayList<ExportInsProductVO> list1 = new ArrayList<>(left);
|
list1.addAll(right);
|
return list1;
|
},
|
TreeMap::new));
|
Iterator<Map.Entry<String, List<ExportInsProductVO>>> iterator = groupData.entrySet().iterator();
|
while (iterator.hasNext()) {
|
Map.Entry<String, List<ExportInsProductVO>> entry = iterator.next();
|
FiberRibboGeometricalParameterExcelData fiber = new FiberRibboGeometricalParameterExcelData();
|
ExportInsProductVO exportInsProductVO = entry.getValue().get(0);
|
fiber.setEntrustCode(exportInsProductVO.getEntrustCode()); // 委托单号
|
fiber.setSampleCode(exportInsProductVO.getSampleCode()); // 样品编号
|
fiber.setBushColor(exportInsProductVO.getBushColor()); // 套管色标
|
fiber.setCode(exportInsProductVO.getCode()); // 光纤带编号
|
fiber.setInspectionItemType("光纤几何参数"); // 检验项
|
fiber.setInspector(exportInsProductVO.getCheckName()); // 检验人
|
|
for (ExportInsProductVO a : entry.getValue()) {
|
if (Objects.isNull(fiber.getInsTime())) {
|
if (Objects.nonNull(a.getCheckTime())) {
|
String format = a.getCheckTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
fiber.setInsTime(LocalDate.parse(format)); // 检验时间
|
}
|
}
|
switch (a.getInspectionItemSubclass()) {
|
case "宽度":
|
List<Map> maps1 = getInsValueList(a.getInsValue());
|
if (CollectionUtils.isNotEmpty(maps1)) {
|
if (maps1.size() >= 2) {
|
fiber.setWidthA(maps1.get(0).get("v").toString());
|
fiber.setWidthB(maps1.get(1).get("v").toString());
|
} else {
|
fiber.setWidthA(maps1.get(0).get("v").toString());
|
}
|
}
|
break;
|
case "厚度":
|
List<Map> maps2 = getInsValueList(a.getInsValue());
|
if (CollectionUtils.isNotEmpty(maps2)) {
|
if (maps2.size() >= 2) {
|
fiber.setThicknessA(maps2.get(0).get("v").toString());
|
fiber.setThicknessB(maps2.get(1).get("v").toString());
|
} else {
|
fiber.setThicknessA(maps2.get(0).get("v").toString());
|
}
|
}
|
break;
|
case "相邻光纤水平间距":
|
List<Map> maps3 = getInsValueList(a.getInsValue());
|
if (CollectionUtils.isNotEmpty(maps3)) {
|
if (maps3.size() >= 2) {
|
fiber.setAdjacentSpacingA(maps3.get(0).get("v").toString());
|
fiber.setAdjacentSpacingB(maps3.get(1).get("v").toString());
|
} else {
|
fiber.setAdjacentSpacingA(maps3.get(0).get("v").toString());
|
}
|
}
|
break;
|
case "两侧光纤水平间距":
|
List<Map> maps4 = getInsValueList(a.getInsValue());
|
if (CollectionUtils.isNotEmpty(maps4)) {
|
if (maps4.size() >= 2) {
|
fiber.setSideSpacingA(maps4.get(0).get("v").toString());
|
fiber.setSideSpacingB(maps4.get(1).get("v").toString());
|
} else {
|
fiber.setSideSpacingA(maps4.get(0).get("v").toString());
|
}
|
}
|
break;
|
case "平整度":
|
List<Map> maps5 = getInsValueList(a.getInsValue());
|
if (CollectionUtils.isNotEmpty(maps5)) {
|
if (maps5.size() >= 2) {
|
fiber.setEvennessA(maps5.get(0).get("v").toString());
|
fiber.setEvennessB(maps5.get(1).get("v").toString());
|
} else {
|
fiber.setEvennessA(maps5.get(0).get("v").toString());
|
}
|
}
|
break;
|
}
|
}
|
fiberList.add(fiber);
|
}
|
}
|
|
//过滤出温度循环
|
List<ExportInsProductVO> temperatureCycling = exportInsProductVOS.stream().filter(e ->
|
NumberUtil.isInteger(e.getInspectionItem()) && Objects.nonNull(e.getSpecialItemParentId()) && e.getSonLaboratory().equals("光纤试验室"))
|
.collect(Collectors.toList());
|
|
List<TemperatureCycling> temperatureCyclingList = getTemList(temperatureCycling);
|
try {
|
String fileName = URLEncoder.encode("已检委托单", "UTF-8");
|
response.setContentType("application/vnd.ms-excel");
|
response.setCharacterEncoding("UTF-8");
|
response.setHeader("content-disposition", "attachment;filename=" + fileName + ".xlsx");
|
HorizontalCellStyleStrategy arveStyleStrategy = EasyExcelUtils.getStyleStrategy();
|
ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).registerWriteHandler(arveStyleStrategy).build();
|
WriteSheet build = EasyExcel.writerSheet().sheetName("Sheet1").head(ExcelChecked.class).build();
|
excelWriter.write(list, build);
|
if (CollectionUtils.isNotEmpty(fiberList)) {
|
WriteSheet build1 = EasyExcel.writerSheet().sheetName("光纤几何参数").head(FiberRibboGeometricalParameterExcelData.class).build();
|
excelWriter.write(fiberList, build1);
|
}
|
if (CollectionUtils.isNotEmpty(temperatureCycling)) {
|
WriteSheet build2 = EasyExcel.writerSheet().sheetName("温度循环").head(TemperatureCycling.class).build();
|
excelWriter.write(temperatureCyclingList, build2);
|
}
|
excelWriter.finish();
|
} catch (Exception e) {
|
e.printStackTrace();
|
System.out.println("导出失败" + e.getMessage());
|
}
|
}
|
|
@Override
|
public List<Map<String, Object>> getInsOrderTemList(Map<String, Object> data) {
|
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.selectByCreaterUser(createUser);
|
}
|
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<ExportInsProductVO> insOrderTemList = insOrderMapper.getInsOrderTemList(entrustCode, sampleCode, startTime, endTime,name);
|
List<TemperatureCycling> temList = getTemList(insOrderTemList);;
|
// if (StringUtils.isEmpty(name)) {
|
// temList = getTemList(insOrderTemList);
|
// } else {
|
// temList = getTemList(insOrderTemList).stream()
|
// .filter(tl -> name.equals(tl.getCheckName()))
|
// .collect(Collectors.toList());
|
// }
|
maps = new ArrayList<>(temList.size());
|
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("attenuationCoefficient1550", map.getAttenuationCoefficient1550());
|
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);
|
}
|
} catch (JsonProcessingException e) {
|
throw new RuntimeException(e);
|
}
|
return maps;
|
}
|
|
@Override
|
public Map<String,Object> permute(Integer num,Boolean isValue) {
|
HashMap<String, Object> map = new HashMap<>();
|
ArrayList<Integer> integers = new ArrayList<>();
|
for (int i = 1; i <= num; i++) { // 使用较小的数字范围进行测试
|
integers.add(i);
|
}
|
List<List<Integer>> result = permutes(integers);
|
if(isValue) {
|
map.put("resultData",result);
|
}else {
|
map.put("resultData",result.size());
|
}
|
return map;
|
}
|
|
private static List<List<Integer>> permutes(List<Integer> nums) {
|
List<List<Integer>> result = new ArrayList<>();
|
backtrack(new ArrayList<>(), nums, result);
|
return result;
|
}
|
|
private static void backtrack(List<Integer> temp, List<Integer> nums, List<List<Integer>> result) {
|
if (temp.size() == 2) {
|
result.add(new ArrayList<>(temp)); // 添加当前组合到结果列表
|
return;
|
}
|
|
for (int i = 0; i < nums.size(); i++) {
|
// 规定顺序,避免重复组合
|
if (temp.size() > 0 && nums.get(i) < temp.get(temp.size() - 1)) continue;
|
temp.add(nums.get(i)); // 添加当前数字到临时组合
|
backtrack(temp, nums, result); // 递归调用
|
temp.remove(temp.size() - 1); // 恢复状态
|
}
|
}
|
|
public List<TemperatureCycling> getTemList(List<ExportInsProductVO> temperatureCycling) {
|
List<TemperatureCycling> temperatureCyclingList = new ArrayList<>();
|
List<TemperatureCycling> newTemperatureCyclingList = new ArrayList<>(); // 返回的温度循环数据
|
if (CollectionUtils.isNotEmpty(temperatureCycling)) {
|
// 根据委托单号、样品编号、套管、光线色标、循环的次数进行分组
|
List<ExportInsProductVO> collect = temperatureCycling.stream()
|
.sorted(Comparator.comparing(ExportInsProductVO::getInspectionItem)).collect(Collectors.toList());
|
Map<String, List<ExportInsProductVO>> temperatureGroup = collect.stream()
|
.sorted(Comparator.comparing(t -> getInspectionItemSubclassOrder(t.getInspectionItemSubclass()))).collect(Collectors.groupingBy(e ->
|
e.getEntrustCode() + "@" + e.getSampleCode() + "@" + e.getBushColor() + "@" + e.getColor() + "@" + e.getInspectionItem() + "@" + e.getInspectionItemSubclass(),
|
TreeMap::new,
|
Collectors.toList()));
|
// 获取20℃的数据 来进行差值的运算 只获取第一次的20℃常温的数据,根据单号、样品编号好、套管和光纤来(会存在多个单子多个样品)
|
Map<String, BigDecimal> map = new HashMap<>();
|
for (ExportInsProductVO a : collect) {
|
if (a.getInspectionItem().equals("1") && a.getInspectionItemSubclass().equals("20℃(常温)")) {
|
switch (a.getInspectionItemClass()) {
|
case "1310nm":
|
List<Map> insValue = getInsValueList(a.getComValue());
|
BigDecimal decay1310 = BigDecimal.ZERO;
|
if (CollectionUtils.isNotEmpty(insValue)) {
|
decay1310 = new BigDecimal(isNumber(insValue.get(0).get("v").toString()));
|
|
}
|
map.put(a.getEntrustCode() + a.getSampleCode() + a.getBushColor() + a.getColor() + a.getInspectionItemClass(), decay1310);
|
break;
|
case "1550nm":
|
List<Map> insValue1 = getInsValueList(a.getComValue());
|
BigDecimal decay1550 = BigDecimal.ZERO;
|
if (CollectionUtils.isNotEmpty(insValue1)) {
|
decay1550 = new BigDecimal(isNumber(insValue1.get(0).get("v").toString()));
|
}
|
map.put(a.getEntrustCode() + a.getSampleCode() + a.getBushColor() + a.getColor() + a.getInspectionItemClass(), decay1550);
|
break;
|
case "1625nm":
|
List<Map> insValue2 = getInsValueList(a.getComValue());
|
BigDecimal decay1625 = BigDecimal.ZERO;
|
if (CollectionUtils.isNotEmpty(insValue2)) {
|
decay1625 = new BigDecimal(isNumber(insValue2.get(0).get("v").toString()));
|
}
|
map.put(a.getEntrustCode() + a.getSampleCode() + a.getBushColor() + a.getColor() + a.getInspectionItemClass(), decay1625);
|
break;
|
case "1383nm":
|
List<Map> insValue3 = getInsValueList(a.getComValue());
|
BigDecimal decay1383 = BigDecimal.ZERO;
|
if (CollectionUtils.isNotEmpty(insValue3)) {
|
decay1383 = new BigDecimal(isNumber(insValue3.get(0).get("v").toString()));
|
}
|
map.put(a.getEntrustCode() + a.getSampleCode() + a.getBushColor() + a.getColor() + a.getInspectionItemClass(), decay1383);
|
break;
|
case "1490nm":
|
List<Map> insValue4 = getInsValueList(a.getComValue());
|
BigDecimal decay1490 = BigDecimal.ZERO;
|
if (CollectionUtils.isNotEmpty(insValue4)) {
|
decay1490 = new BigDecimal(isNumber(insValue4.get(0).get("v").toString()));
|
}
|
map.put(a.getEntrustCode() + a.getSampleCode() + a.getBushColor() + a.getColor() + a.getInspectionItemClass(), decay1490);
|
break;
|
}
|
}
|
}
|
|
// 根据委托编号、样品编号、循环次数、温度点进行分组
|
Map<String, List<ExportInsProductVO>> collect1 = temperatureCycling.stream()
|
.collect(Collectors.groupingBy(e -> e.getEntrustCode() + "@" + e.getSampleCode() + "@" + e.getInspectionItem() + "@" + e.getInspectionItemSubclass()));
|
|
|
// 将差值保存
|
Map<String, List<BigDecimal>> map1 = new HashMap<>();
|
Set<String> strings = new HashSet<>();
|
Iterator<Map.Entry<String, List<ExportInsProductVO>>> iterator1 = collect1.entrySet().iterator();
|
while (iterator1.hasNext()) {
|
Map.Entry<String, List<ExportInsProductVO>> entry = iterator1.next();
|
for (ExportInsProductVO a : entry.getValue()) {
|
// 将得到的衰减系数保存 后面要用到
|
strings.add(a.getInspectionItemClass());
|
switch (a.getInspectionItemClass()) {
|
case "1310nm":
|
case "1490nm":
|
case "1383nm":
|
case "1550nm":
|
case "1625nm":
|
List<Map> insValue = getInsValueList(a.getComValue());
|
if (CollectionUtils.isNotEmpty(insValue)) {
|
ArrayList<BigDecimal> bigDecimals = new ArrayList<>();
|
BigDecimal bigDecimal = new BigDecimal(isNumber(insValue.get(0).get("v").toString()));// 当前衰减值
|
BigDecimal bigDecimal1 = map.get(a.getEntrustCode() + a.getSampleCode() + a.getBushColor() + a.getColor() + a.getInspectionItemClass());// 20℃的衰减值
|
BigDecimal v = bigDecimal.subtract(bigDecimal1);
|
bigDecimals.add(v.abs());
|
if (map1.containsKey(a.getEntrustCode() + a.getSampleCode() + a.getInspectionItemSubclass() + a.getInspectionItemClass())) {
|
map1.get(a.getEntrustCode() + a.getSampleCode() + a.getInspectionItemSubclass() + a.getInspectionItemClass()).addAll(bigDecimals);
|
} else {
|
map1.put(a.getEntrustCode() + a.getSampleCode() + a.getInspectionItemSubclass() + a.getInspectionItemClass(), bigDecimals);
|
}
|
} else {
|
if (!map1.containsKey(a.getEntrustCode() + a.getSampleCode() + a.getInspectionItemSubclass() + a.getInspectionItemClass())) {
|
map1.put(a.getEntrustCode() + a.getSampleCode() + a.getInspectionItemSubclass() + a.getInspectionItemClass(), new ArrayList<>());
|
}
|
}
|
break;
|
}
|
}
|
}
|
|
|
Iterator<Map.Entry<String, List<ExportInsProductVO>>> iterator = temperatureGroup.entrySet().iterator();
|
while (iterator.hasNext()) {
|
Map.Entry<String, List<ExportInsProductVO>> entry = iterator.next();
|
TemperatureCycling temperature = new TemperatureCycling();
|
for (ExportInsProductVO a : entry.getValue()) {
|
BeanUtils.copyProperties(a, temperature);
|
// 时间格式化
|
if (Objects.nonNull(a.getCheckTime())) {
|
String format = a.getCheckTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
LocalDate parse = LocalDate.parse(format);
|
temperature.setInsTime(parse);
|
}
|
// 衰减系数获取计算值
|
List<Map> insValue = getInsValueList(a.getComValue());
|
if (CollectionUtils.isNotEmpty(insValue)) {
|
switch (a.getInspectionItemClass()) {
|
case "1310nm":
|
temperature.setAttenuationCoefficient1310(isNumber(insValue.get(0).get("v").toString()));
|
// 20℃(常温)的是没有差值的
|
if (!a.getInspectionItemSubclass().contains("20℃(常温)")) {
|
BigDecimal v = new BigDecimal(isNumber(insValue.get(0).get("v").toString())).subtract(map.get(a.getEntrustCode() + a.getSampleCode() + a.getBushColor() + a.getColor() + a.getInspectionItemClass()));
|
String attenuationDifference = v.abs().toString();
|
temperature.setAttenuationDifference1(attenuationDifference);
|
}
|
break;
|
case "1550nm":
|
temperature.setAttenuationCoefficient1550(isNumber(insValue.get(0).get("v").toString()));
|
// 20℃(常温)的是没有差值的
|
if (!a.getInspectionItemSubclass().contains("20℃(常温)")) {
|
BigDecimal v = new BigDecimal(isNumber(insValue.get(0).get("v").toString())).subtract(map.get(a.getEntrustCode() + a.getSampleCode() + a.getBushColor() + a.getColor() + a.getInspectionItemClass()));
|
String attenuationDifference = v.abs().toString();
|
temperature.setAttenuationDifference2(attenuationDifference);
|
}
|
break;
|
case "1625nm":
|
temperature.setAttenuationCoefficient1625(isNumber(insValue.get(0).get("v").toString()));
|
// 20℃(常温)的是没有差值的
|
if (!a.getInspectionItemSubclass().contains("20℃(常温)")) {
|
BigDecimal v = new BigDecimal(isNumber(insValue.get(0).get("v").toString())).subtract(map.get(a.getEntrustCode() + a.getSampleCode() + a.getBushColor() + a.getColor() + a.getInspectionItemClass()));
|
String attenuationDifference = v.abs().toString();
|
temperature.setAttenuationDifference3(attenuationDifference);
|
}
|
break;
|
case "1383nm":
|
temperature.setAttenuationCoefficient1383(isNumber(insValue.get(0).get("v").toString()));
|
// 20℃(常温)的是没有差值的
|
if (!a.getInspectionItemSubclass().contains("20℃(常温)")) {
|
BigDecimal v = new BigDecimal(isNumber(insValue.get(0).get("v").toString())).subtract(map.get(a.getEntrustCode() + a.getSampleCode() + a.getBushColor() + a.getColor() + a.getInspectionItemClass()));
|
String attenuationDifference = v.abs().toString();
|
temperature.setAttenuationDifference4(attenuationDifference);
|
}
|
break;
|
case "1490nm":
|
temperature.setAttenuationCoefficient1490(isNumber(insValue.get(0).get("v").toString()));
|
// 20℃(常温)的是没有差值的
|
if (!a.getInspectionItemSubclass().contains("20℃(常温)")) {
|
BigDecimal v = new BigDecimal(isNumber(insValue.get(0).get("v").toString())).subtract(map.get(a.getEntrustCode() + a.getSampleCode() + a.getBushColor() + a.getColor() + a.getInspectionItemClass()));
|
String attenuationDifference = v.abs().toString();
|
temperature.setAttenuationDifference5(attenuationDifference);
|
}
|
break;
|
}
|
// 进行衰减差值的最大值赋值
|
StringBuffer value = new StringBuffer();
|
if (strings.contains("1310nm")) {
|
BigDecimal bigDecimal = BigDecimal.ZERO;
|
if (map1.containsKey(a.getEntrustCode() + a.getSampleCode() + a.getInspectionItemSubclass() + "1310nm")) {
|
bigDecimal = Optional.ofNullable(map1.get(a.getEntrustCode() + a.getSampleCode() + a.getInspectionItemSubclass() + "1310nm"))
|
.orElse(Collections.emptyList()) // 如果值为 null,返回空列表
|
.stream()
|
.sorted(Comparator.reverseOrder()) // 降序排序
|
.findFirst() // 获取第一个元素(最大值)
|
.orElse(BigDecimal.ZERO); // 如果列表为空,返回默认值(例如 BigDecimal.ZERO)
|
}
|
if (bigDecimal.abs().compareTo(BigDecimal.ZERO) > 0) {
|
value.append("|∆ɑ|1310nm max").append(bigDecimal.abs()).append("dB/km");
|
}
|
}
|
if (strings.contains("1550nm")) {
|
BigDecimal bigDecimal = BigDecimal.ZERO;
|
if (map1.containsKey(a.getEntrustCode() + a.getSampleCode() + a.getInspectionItemSubclass() + "1550nm")) {
|
List<BigDecimal> valuesList = map1.get(a.getEntrustCode() + a.getSampleCode() + a.getInspectionItemSubclass() + "1550nm").stream().sorted(Comparator.reverseOrder()).collect(Collectors.toList());
|
bigDecimal = valuesList.isEmpty() ? BigDecimal.ZERO : valuesList.get(0);
|
}
|
if (bigDecimal.abs().compareTo(BigDecimal.ZERO) > 0) {
|
value.append("|∆ɑ|1550nm max").append(bigDecimal.abs()).append("dB/km");
|
}
|
}
|
if (strings.contains("1625nm")) {
|
BigDecimal bigDecimal = BigDecimal.ZERO;
|
if (map1.containsKey(a.getEntrustCode() + a.getSampleCode() + a.getInspectionItemSubclass() + "1625nm")) {
|
bigDecimal = map1.get(a.getEntrustCode() + a.getSampleCode() + a.getInspectionItemSubclass() + "1625nm").stream().sorted(Comparator.reverseOrder()).collect(Collectors.toList()).get(0);
|
}
|
if (bigDecimal.abs().compareTo(BigDecimal.ZERO) > 0) {
|
value.append("|∆ɑ|1625nm max").append(bigDecimal.abs()).append("dB/km");
|
}
|
}
|
|
if (strings.contains("1383nm")) {
|
BigDecimal bigDecimal = BigDecimal.ZERO;
|
if (map1.containsKey(a.getEntrustCode() + a.getSampleCode() + a.getInspectionItemSubclass() + "1383nm")) {
|
bigDecimal = map1.get(a.getEntrustCode() + a.getSampleCode() + a.getInspectionItemSubclass() + "1383nm").stream().sorted(Comparator.reverseOrder()).collect(Collectors.toList()).get(0);
|
}
|
if (bigDecimal.abs().compareTo(BigDecimal.ZERO) > 0) {
|
value.append("|∆ɑ|1383nm max").append(bigDecimal.abs()).append("dB/km");
|
}
|
}
|
|
if (strings.contains("1490nm")) {
|
BigDecimal bigDecimal = BigDecimal.ZERO;
|
if (map1.containsKey(a.getEntrustCode() + a.getSampleCode() + a.getInspectionItemSubclass() + "1490nm")) {
|
bigDecimal = map1.get(a.getEntrustCode() + a.getSampleCode() + a.getInspectionItemSubclass() + "1490nm").stream().sorted(Comparator.reverseOrder()).collect(Collectors.toList()).get(0);
|
}
|
if (bigDecimal.abs().compareTo(BigDecimal.ZERO) > 0) {
|
value.append("|∆ɑ|1490nm max").append(bigDecimal.abs()).append("dB/km");
|
}
|
}
|
if (StringUtils.isNotEmpty(value.toString())) {
|
value.insert(0, a.getInspectionItemSubclass() + " ");
|
}
|
temperature.setAttenuationDifferenceMax(value.toString());
|
}
|
temperatureCyclingList.add(temperature);
|
}
|
}
|
}
|
temperatureCyclingList = temperatureCyclingList.stream().distinct().collect(Collectors.toList());
|
//查询全色谱,过滤色标并排序
|
List<String> colorList = dictTypeService.selectDictDataByType("fiber_color_type").stream()
|
.sorted(Comparator.comparing(SysDictData::getDictSort))
|
.map(SysDictData::getDictLabel)
|
.collect(Collectors.toList());
|
Map<String, List<TemperatureCycling>> collect = temperatureCyclingList.stream().collect(Collectors.groupingBy(TemperatureCycling::getEntrustCode));
|
Iterator<Map.Entry<String, List<TemperatureCycling>>> iterator = collect.entrySet().iterator();
|
while (iterator.hasNext()) {
|
Map.Entry<String, List<TemperatureCycling>> entry = iterator.next();
|
//温度循环根据色标排序
|
entry.getValue().sort((o1, o2) -> {
|
//根据套管色标以及光纤色标排序
|
if (StringUtils.isNotBlank(o1.getBushColor()) && StringUtils.isNotBlank(o2.getBushColor())) {
|
//先按样品编号升序
|
if (!Objects.equals(o1.getSampleCode(), o2.getSampleCode())) {
|
if (containsOnlyDigits(o1.getSampleCode()) && containsOnlyDigits(o2.getSampleCode())) {
|
Long o1Num = Long.parseLong(o1.getSampleCode());
|
Long o2Num = Long.parseLong(o2.getSampleCode());
|
return o1Num.compareTo(o2Num);
|
}
|
return o1.getSampleCode().compareTo(o2.getSampleCode());
|
}
|
//循环次数排序
|
if (StringUtils.isNotBlank(o1.getInspectionItem()) && StringUtils.isNotBlank(o2.getInspectionItem())) {
|
if (!Objects.equals(o1.getInspectionItem(), o2.getInspectionItem())) {
|
Integer o1Index = Integer.parseInt(o1.getInspectionItem());
|
Integer o2Index = Integer.parseInt(o2.getInspectionItem());
|
return o1Index.compareTo(o2Index);
|
}
|
}
|
//套管色标排序
|
if (!Objects.equals(o1.getBushColor(), o2.getBushColor())) {
|
Integer o1Index = colorList.indexOf(o1.getBushColor());
|
Integer o2Index = colorList.indexOf(o2.getBushColor());
|
return o1Index.compareTo(o2Index);
|
}
|
//光纤带排序
|
if (StringUtils.isNotBlank(o1.getCode()) && StringUtils.isNotBlank(o2.getCode())) {
|
if (!Objects.equals(o1.getCode(), o2.getCode())) {
|
return o1.getCode().compareTo(o2.getCode());
|
}
|
}
|
//光纤色标排序
|
if (StringUtils.isNotBlank(o1.getColor()) && StringUtils.isNotBlank(o2.getColor())) {
|
if (!Objects.equals(o1.getColor(), o2.getColor())) {
|
Integer o1Index = colorList.indexOf(o1.getColor());
|
Integer o2Index = colorList.indexOf(o2.getColor());
|
return o1Index.compareTo(o2Index);
|
}
|
}
|
}
|
return 0;
|
});
|
newTemperatureCyclingList.addAll(entry.getValue());
|
}
|
//温度循环根据色标排序
|
// temperatureCyclingList.sort((o1, o2) -> {
|
// // 处理 null 值
|
// if (o1 == null && o2 == null) return 0;
|
// if (o1 == null) return -1;
|
// if (o2 == null) return 1;
|
//
|
// // ---------------------- 1. 按样品编号排序 ----------------------
|
// int sampleCodeCompare = compareSampleCode(o1.getSampleCode(), o2.getSampleCode());
|
// if (sampleCodeCompare != 0) return sampleCodeCompare;
|
//
|
// // ---------------------- 2. 按套管色标排序 ----------------------
|
// int bushColorCompare = compareColor(o1.getBushColor(), o2.getBushColor(), colorList);
|
// if (bushColorCompare != 0) return bushColorCompare;
|
//
|
// // ---------------------- 3. 按光纤带排序 ----------------------
|
// int codeCompare = compareNullableString(o1.getCode(), o2.getCode());
|
// if (codeCompare != 0) return codeCompare;
|
//
|
// // ---------------------- 4. 按光纤色标排序 ----------------------
|
// return compareColor(o1.getColor(), o2.getColor(), colorList);
|
// });
|
return newTemperatureCyclingList;
|
}
|
|
//1: 样品编号比较(支持数字和字符串混合排序)
|
private static int compareSampleCode(String code1, String code2) {
|
if (Objects.equals(code1, code2)) return 0;
|
|
boolean isCode1Numeric = containsOnlyDigits(code1);
|
boolean isCode2Numeric = containsOnlyDigits(code2);
|
|
// 如果都是数字,转为 Long 比较
|
if (isCode1Numeric && isCode2Numeric) {
|
return Long.compare(Long.parseLong(code1), Long.parseLong(code2));
|
}
|
|
// 如果一个是数字,另一个不是,数字优先
|
if (isCode1Numeric != isCode2Numeric) {
|
return isCode1Numeric ? -1 : 1;
|
}
|
|
// 其他情况按字符串比较
|
return code1.compareTo(code2);
|
}
|
|
//2: 色标比较(处理不在 colorList 中的情况)
|
private static int compareColor(String color1, String color2, List<String> colorList) {
|
if (Objects.equals(color1, color2)) return 0;
|
|
// 处理 colorList 中的索引
|
int index1 = colorList.indexOf(color1);
|
int index2 = colorList.indexOf(color2);
|
|
// 将不在列表中的色标统一排序到最后(赋予最大值)
|
index1 = index1 == -1 ? Integer.MAX_VALUE : index1;
|
index2 = index2 == -1 ? Integer.MAX_VALUE : index2;
|
|
return Integer.compare(index1, index2);
|
}
|
|
//3: 处理可能为空的字符串比较
|
private static int compareNullableString(String str1, String str2) {
|
if (Objects.equals(str1, str2)) return 0;
|
|
// 空字符串视为较小值
|
boolean isStr1Blank = StringUtils.isBlank(str1);
|
boolean isStr2Blank = StringUtils.isBlank(str2);
|
|
if (isStr1Blank && isStr2Blank) return 0;
|
if (isStr1Blank) return -1;
|
if (isStr2Blank) return 1;
|
|
// 非空时按自然顺序比较
|
return str1.compareTo(str2);
|
}
|
|
public List<Map> getInsValueList(String insValue) {
|
List<Map> list = new ArrayList<>();
|
if (StringUtils.isNotBlank(insValue)) {
|
List<Map> maps = JSONArray.parseArray(insValue, Map.class);
|
list.addAll(maps);
|
}
|
return list;
|
}
|
|
/**
|
* 判断是否可以转数字
|
*/
|
public String isNumber(String str) {
|
if (NumberUtil.isDouble(str)) {
|
return str;
|
} else {
|
return "0";
|
}
|
}
|
|
/**
|
* 排序规格
|
*
|
* @param t
|
* @return
|
*/
|
public Integer getInspectionItemSubclassOrder(String t) {
|
switch (t) {
|
case "20℃(常温)":
|
return 1;
|
case "20℃":
|
return 2;
|
case "-40℃":
|
return 3;
|
case "65℃":
|
return 4;
|
default:
|
return 5; // 未知温度点
|
}
|
}
|
|
|
@Override
|
public IPage<CostStatisticsDto> costStatistics(IPage<CostStatisticsDto> page, CostStatisticsDto costStatisticsDto) {
|
String dates = costStatisticsDto.getDates();
|
String[] split = dates.replaceAll("\\[", "").replaceAll("]", "").replaceAll("\"", "").split(",");
|
costStatisticsDto.setDates(null);
|
// 获取当前人所在实验室
|
Integer userId = Integer.parseInt(SecurityUtils.getLoginUser().getUser().getUserId().toString());
|
String departLimsId = userMapper.selectById(userId).getDepartLimsId();
|
String laboratory = "";
|
if (StringUtils.isNotBlank(departLimsId)) {
|
String[] split1 = departLimsId.split(",");
|
for (String s : split1) {
|
if (StringUtils.isNotBlank(s) && (!Arrays.asList("1", "22").contains(s))) {
|
laboratory = insOrderMapper.getDepartment(Integer.parseInt(s));
|
}
|
}
|
}
|
LocalDate today = LocalDate.parse(split[1]);
|
LocalTime end = LocalTime.of(23, 59, 59);
|
IPage<CostStatisticsDto> dtoIPage = insOrderMapper.selectCostStatistics(page, QueryWrappers.queryWrappers(costStatisticsDto), split[0], today.atTime(end).toString(), laboratory);
|
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);
|
// 获取当前人所在实验室
|
Integer userId = 1;
|
String departLimsId = userMapper.selectById(userId).getDepartLimsId();
|
String laboratory = "";
|
if (StringUtils.isNotBlank(departLimsId)) {
|
String[] split1 = departLimsId.split(",");
|
for (String s : split1) {
|
if (StringUtils.isNotBlank(s) && (!Arrays.asList("1", "22").contains(s))) {
|
laboratory = insOrderMapper.getDepartment(Integer.parseInt(s));
|
}
|
}
|
}
|
LocalDate today = LocalDate.parse(split[1]);
|
LocalTime end = LocalTime.of(23, 59, 59);
|
List<CostStatisticsDto> costStatisticsDtos = insOrderMapper.selectCostStatistics2(QueryWrappers.queryWrappers(costStatisticsDto), split[0], today.atTime(end).toString(), laboratory);
|
BigDecimal total = BigDecimal.ZERO;
|
for (CostStatisticsDto dto : costStatisticsDtos) {
|
if (Objects.isNull(dto.getPrice()) || dto.getPrice().compareTo(BigDecimal.ZERO) == 0) {
|
dto.setPrice(new BigDecimal(0));
|
}
|
total = total.add(dto.getPrice());
|
}
|
map.put("total", total);
|
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
|
@Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
|
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()) &&
|
!"钢绞线".equals(sampleProductDto3.getIoSampleType()) &&
|
sampleProductDto3.getInsProduct().stream().noneMatch(i -> StringUtils.equals("光纤接头损耗", i.getInspectionItem()))
|
) {
|
return true;
|
}
|
if (processedCodes.contains(sampleProductDto3.getCode())) {
|
return false;
|
} else {
|
processedCodes.add(sampleProductDto3.getCode());
|
return true;
|
}
|
}).collect(Collectors.toList());
|
return sampleProductDto3s;
|
}
|
|
@Override
|
public void export(CostStatisticsDto costStatisticsDto, HttpServletResponse response) throws IOException {
|
// 判断当前人属于电力 还是 通信 过滤掉为1
|
List<String> dept = new ArrayList<>();
|
Map<String, Integer> map1 = new HashMap<>();
|
User user = userMapper.selectById(map1.get("userId"));//当前登录的人
|
String departLimsId = user.getDepartLimsId();
|
String laboratory = "";
|
if (StringUtils.isNotBlank(departLimsId) && Objects.nonNull(departLimsId)) {
|
String[] split = departLimsId.split(",");
|
for (int i = 0; i < split.length; i++) {
|
if (StringUtils.isNotBlank(split[i])) {
|
if (split[i].equals("1") || split[i].equals("22")) {
|
continue;
|
}
|
laboratory = insOrderMapper.getDepartment(Integer.parseInt(split[i]));
|
dept.add(insOrderMapper.getDepartment(Integer.parseInt(split[i])));
|
}
|
}
|
}
|
//查询导出的费用统计数据
|
String dates = costStatisticsDto.getDates();
|
String[] split = dates.replaceAll("\\[", "").replaceAll("]", "").replaceAll("\"", "").split(",");
|
costStatisticsDto.setDates(null);
|
|
|
LocalDate today = LocalDate.parse(split[1]);
|
LocalTime end = LocalTime.of(23, 59, 59);
|
List<CostStatisticsDto> costStatisticsDtos = insOrderMapper.selectCostStatistics2(QueryWrappers.queryWrappers(costStatisticsDto), split[0], today.atTime(end).toString(), laboratory);
|
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");
|
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();
|
List<CostStatisticsDto> costStatisticsDtos1 = new ArrayList<>();
|
for (Map.Entry<String, List<CostStatisticsDto>> companyDataEntry : groupByCompany.entrySet()) {
|
String sheetName = companyDataEntry.getKey();
|
List<CostStatisticsDto> dataList = companyDataEntry.getValue();
|
// 根据该单子的实验室 来判断是否属于当前登录人的部门
|
for (CostStatisticsDto costStatisticsDto1 : dataList) {
|
if (StringUtils.isNotBlank(costStatisticsDto1.getLaboratory()) && Objects.nonNull(costStatisticsDto1.getLaboratory())) {
|
if (dept.contains(costStatisticsDto1.getLaboratory())) {
|
costStatisticsDtos1.add(costStatisticsDto1);
|
}
|
}
|
}
|
WriteSheet mainSheet = EasyExcel.writerSheet(sheetName)
|
.head(CostStatisticsDto.class)
|
.registerWriteHandler(new SimpleColumnWidthStyleStrategy(25))
|
.build();
|
excelWriter.write(costStatisticsDtos1, mainSheet);
|
costStatisticsDtos1.clear();
|
}
|
// 关闭流
|
excelWriter.finish();
|
} catch (IOException e) {
|
throw new RuntimeException("导出失败");
|
}
|
}
|
|
public static boolean containsOnlyDigits(String str) {
|
String regex = "\\d+"; // 匹配一个或多个数字
|
return Pattern.matches(regex, str);
|
}
|
|
@Override
|
@Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
|
public Boolean hasSendUrgentOrder() {
|
Integer userId = 1;
|
//查询当前客户的紧急额度
|
Map<String, Object> quotaMap = baseMapper.selectCurrentCompanyUrgentQuota(userId);
|
if (quotaMap == null) {
|
return false;
|
}
|
//查询当天客户已创建的紧急订单
|
long count = baseMapper.selectCount(Wrappers.<InsOrder>lambdaQuery()
|
.eq(InsOrder::getCompany, quotaMap.get("company"))
|
.eq(InsOrder::getType, 2)
|
.gt(InsOrder::getCreateTime, LocalDateTime.of(LocalDate.now(), LocalTime.MIN))
|
.lt(InsOrder::getCreateTime, LocalDateTime.of(LocalDate.now(), LocalTime.MAX)));
|
int quota = Integer.parseInt(quotaMap.get("quota").toString());
|
return quota > count;
|
}
|
}
|