| | |
| | | package com.yuanchu.mom.service.impl; |
| | | |
| | | import cn.hutool.core.lang.UUID; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.alibaba.excel.EasyExcel; |
| | |
| | | import com.yuanchu.mom.exception.ErrorException; |
| | | import com.yuanchu.mom.mapper.*; |
| | | import com.yuanchu.mom.pojo.*; |
| | | import com.yuanchu.mom.service.InsOrderPlanService; |
| | | import com.yuanchu.mom.service.InsOrderService; |
| | | import com.yuanchu.mom.service.InsProductService; |
| | | import com.yuanchu.mom.utils.GiveCode; |
| | |
| | | import lombok.AllArgsConstructor; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.net.URLEncoder; |
| | | import java.time.LocalDate; |
| | |
| | | * @createDate 2024-03-12 16:17:55 |
| | | */ |
| | | @Service |
| | | @AllArgsConstructor |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public class InsOrderServiceImpl extends ServiceImpl<InsOrderMapper, InsOrder> |
| | | implements InsOrderService { |
| | | public class InsOrderServiceImpl extends ServiceImpl<InsOrderMapper, InsOrder> implements InsOrderService { |
| | | |
| | | @Resource |
| | | private GetLook getLook; |
| | | |
| | | @Resource |
| | | private RoleMapper roleMapper; |
| | | |
| | | @Resource |
| | | private InsOrderMapper insOrderMapper; |
| | | |
| | | @Value("${file.path}") |
| | | private String imgUrl; |
| | | |
| | | @Value("${wordUrl}") |
| | | private String wordUrl; |
| | | @Resource |
| | | private InsOrderFileMapper insOrderFileMapper; |
| | | @Resource |
| | | private InsSampleMapper insSampleMapper; |
| | | @Resource |
| | | private WarehouseHistoryMapper warehouseHistoryMapper; |
| | | |
| | | @Resource |
| | | private InsProductMapper insProductMapper; |
| | | @Resource |
| | | private InsProductService insProductService; |
| | | |
| | | @Resource |
| | | private InsProductUserMapper insProductUserMapper; |
| | | |
| | | @Resource |
| | | private GiveCode giveCode; |
| | | |
| | | @Resource |
| | | private InsSampleUserMapper insSampleUserMapper; |
| | | |
| | | @Resource |
| | | private InsOrderStateMapper insOrderStateMapper; |
| | | |
| | | @Resource |
| | | UserMapper userMapper; |
| | | |
| | | @Resource |
| | | PowerMapper powerMapper; |
| | | |
| | | @Resource |
| | | CustomMapper customMapper; |
| | | |
| | | @Resource |
| | | QYWXApi qywxApi; |
| | | |
| | | |
| | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int addInsOrder(List<SampleProductDto> list, InsOrder insOrder, List<List<Integer>> pairing) { |
| | | public int addInsOrder(List<SampleProductDto> list, InsOrder insOrder, List<List<Integer>> pairing, List<MultipartFile> files) { |
| | | insOrder.setState(0); |
| | | //判断选择的委托单位与制单人的委托单位是否一致 |
| | | Integer userId = getLook.selectPowerByMethodAndUserId(null).get("userId"); |
| | |
| | | a.setInsOrderId(insOrder.getId()); |
| | | //样品编号 |
| | | if (StrUtil.isEmpty(a.getSampleCode())) { |
| | | a.setSampleCode("YP-" + a.getModel()+"-" + giveCode.split("-")[2] + "-" + count.get()); |
| | | a.setSampleCode("YP-" + a.getModel() + "-" + giveCode.split("-")[2] + "-" + count.get()); |
| | | } |
| | | insSampleMapper.insert(a); |
| | | //样品的检验项目 |
| | |
| | | if (insOrder.getOrderType().equals("C")) { |
| | | insOrder.setState(1); |
| | | upInsOrderOfState(insOrder); |
| | | } |
| | | //如果有上传的附件 |
| | | if (CollectionUtils.isNotEmpty(files)) { |
| | | for (MultipartFile file : files ) { |
| | | String urlString; |
| | | String pathName; |
| | | String path; |
| | | String filename = file.getOriginalFilename(); |
| | | String contentType = file.getContentType(); |
| | | InsOrderFile insOrderFile = new InsOrderFile(); |
| | | insOrderFile.setInsOrderId(insOrder.getId()); |
| | | insOrderFile.setFileName(filename); |
| | | if (contentType != null && contentType.startsWith("image/")) { |
| | | // 是图片 |
| | | path = imgUrl; |
| | | insOrderFile.setType(1); |
| | | } else { |
| | | // 是文件 |
| | | path = wordUrl; |
| | | insOrderFile.setType(2); |
| | | } |
| | | try { |
| | | File realpath = new File(path); |
| | | if (!realpath.exists()) { |
| | | realpath.mkdirs(); |
| | | } |
| | | pathName = UUID.randomUUID() + "_" + file.getOriginalFilename(); |
| | | urlString = realpath + "/" + pathName; |
| | | file.transferTo(new File(urlString)); |
| | | insOrderFile.setFileUrl(pathName); |
| | | insOrderFileMapper.insert(insOrderFile); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | System.err.println("附件上传错误"); |
| | | } |
| | | } |
| | | } |
| | | return insOrder.getId(); |
| | | } |
| | |
| | | List<Integer> list = Arrays.stream(ids.split(",")).map(Integer::parseInt).collect(Collectors.toList()); |
| | | List<SampleProductDto3> sampleProductDtos = insSampleMapper.selectSampleProductListByOrderId3(list); |
| | | Set<String> processedCodes = new HashSet<>(); |
| | | //如果是光纤或者是光纤带默认只打印第一个 |
| | | List<SampleProductDto3> sampleProductDto3s = sampleProductDtos.stream().filter(sampleProductDto3 -> { |
| | | if (!"光纤".equals(sampleProductDto3.getIoSampleType()) && !"光纤带".equals(sampleProductDto3.getIoSampleType())) { |
| | | return true; |
| | | } |
| | | if (processedCodes.contains(sampleProductDto3.getCode())) { |
| | | return false; |
| | | } else { |
| | |
| | | } |
| | | }).collect(Collectors.toList()); |
| | | return sampleProductDto3s; |
| | | } |
| | | |
| | | //校验电机编号 |
| | | @Override |
| | | public Map<String, List<InsSample>> checkNumber(String ids) { |
| | | List<InsSample> samples = new ArrayList<>(); |
| | | List<Integer> list = Arrays.stream(ids.split(",")).map(Integer::parseInt).collect(Collectors.toList()); |
| | | List<InsSample> sampleDtos = insSampleMapper.selectInsSample(list); |
| | | //判断样品型号是否是BZ |
| | | for (InsSample sampleDto : sampleDtos) { |
| | | if (sampleDto.getModel().contains("BZ")) { |
| | | if (ObjectUtils.isEmpty(sampleDto.getMotorNumber())) { |
| | | samples.add(sampleDto); |
| | | } |
| | | } |
| | | } |
| | | if (CollectionUtils.isNotEmpty(samples)) { |
| | | Map<String, List<InsSample>> collect = samples.stream().collect(Collectors.groupingBy(InsSample::getEntrustCode)); |
| | | return collect; |
| | | } else return null; |
| | | } |
| | | |
| | | @Override |
| | |
| | | throw new RuntimeException("导出失败"); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public int addNumber(List<InsSample> insSamples) { |
| | | for (InsSample insSample : insSamples) { |
| | | insSampleMapper.updateById(insSample); |
| | | } |
| | | return 0; |
| | | } |
| | | } |
| | | |
| | | |