| | |
| | | import cn.hutool.core.io.FileUtil; |
| | | import cn.hutool.core.io.IoUtil; |
| | | import cn.hutool.core.util.BooleanUtil; |
| | | import cn.hutool.core.util.IdUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.http.HttpRequest; |
| | | import com.alibaba.excel.EasyExcel; |
| | |
| | | import com.chinaztt.mes.plan.util.CustomerOrderClientConfigure; |
| | | import com.chinaztt.mes.plan.util.CustomerOrderUnitWhiteListConfig; |
| | | import com.chinaztt.mes.plan.util.CustomerOrderUtil; |
| | | import com.chinaztt.mes.plan.util.FileSaveUtil; |
| | | import com.chinaztt.mes.plan.vo.CustomerOrderVO1; |
| | | import com.chinaztt.mes.quality.dto.CustomOrderSyncDTO; |
| | | import com.chinaztt.mes.technology.entity.*; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.transaction.interceptor.TransactionAspectSupport; |
| | | import org.springframework.util.Assert; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.math.BigDecimal; |
| | |
| | | |
| | | private Environment environment; |
| | | |
| | | private final static String OTC_MAIN_STATUS_CANCEL = "已取消"; |
| | | |
| | | private final static String OTC_MAIN_STATUS_TRANSMIT = "已下达"; |
| | | |
| | | private final static String AFFILIATED_CONTRACT = "中天注塑厂"; |
| | | |
| | | //private FileSaveUtil fileSaveUtil; |
| | | |
| | | @Override |
| | | public void otcDownload(Long id, HttpServletResponse response) { |
| | | customerOrderUtil.otcDownLoadFiles(id, response); |
| | |
| | | private void changeAudit(CustomerOrder customerOrder, String isAudit) { |
| | | //审核状态 通过 订单状态待计划 |
| | | if (isAudit.equals(AuditStateStringValues.ACCEPTED)) { |
| | | //TODO: 要加零件id参数 |
| | | Document document = documentMapper.selectById(customerOrder.getTechnologyDocumentId()); |
| | | Part part = partMapper.selectOne(Wrappers.<Part>lambdaQuery().eq(Part::getEngChgLevel, "1").eq(Part::getPartNo, customerOrder.getPartNo())); |
| | | Part part = partMapper.selectOne(Wrappers.<Part>lambdaQuery().eq(Part::getEngChgLevel, "1").eq(Part::getId,customerOrder.getPartId() )); |
| | | if (null == part) { |
| | | throw new RuntimeException("根据零件编号 = 【" + customerOrder.getPartNo() + "】MES本地查无匹配零件对象"); |
| | | } |
| | |
| | | |
| | | |
| | | @Override |
| | | public R fullUpdate(CustomerOrderDTO customerOrderDTO) { |
| | | List<String> unitWhitMapList = customerOrderUnitWhiteListConfig.getUnitWhitListMap(); |
| | | String unitConcat = customerOrderDTO.getOtcUnit() + "_" + customerOrderDTO.getIfsSalesUnit(); |
| | | if (!customerOrderDTO.getOtcUnit().equals(customerOrderDTO.getIfsSalesUnit()) && !unitWhitMapList.contains(unitConcat)) { |
| | | //如果销售单位和ifs中销售单位不一样则不给保存A |
| | | return R.failed("订单行销售单位和销售件销售计量单位不一致并且白名单中不存在对应关系"); |
| | | } else { |
| | | if (StringUtils.isNotBlank(customerOrderDTO.getPartNo())) { |
| | | Part part = partMapper.selectOne(Wrappers.<Part>lambdaQuery().eq(Part::getPartNo, customerOrderDTO.getPartNo())); |
| | | if (null == part) { |
| | | throw new RuntimeException("根据零件编号 = 【" + customerOrderDTO.getPartNo() + "】MES本地查无匹配零件对象"); |
| | | } |
| | | } |
| | | if (StringUtils.isNotBlank(customerOrderDTO.getSalesPartNo())) { |
| | | Part part = partMapper.selectOne(Wrappers.<Part>lambdaQuery().eq(Part::getPartNo, customerOrderDTO.getSalesPartNo())); |
| | | if (null == part) { |
| | | throw new RuntimeException("根据销售件编号 = 【" + customerOrderDTO.getSalesPartNo() + "】MES本地查无匹配零件对象"); |
| | | } |
| | | } |
| | | // 如果销售零件号未修改,otc同步状态不需要更新 |
| | | CustomerOrder oriCustomerOrder = customerOrderMapper.selectById(customerOrderDTO.getId()); |
| | | if (!org.apache.commons.lang3.StringUtils.equals(oriCustomerOrder.getSalesPartNo(), |
| | | customerOrderDTO.getSalesPartNo())) { |
| | | customerOrderDTO.setOtcPartSync(false); |
| | | } |
| | | //mes数量 = 订单数量 * 因子 |
| | | Assert.notNull(customerOrderDTO.getIfsConvFactor(), "请选择销售零件号"); |
| | | customerOrderDTO.setBuyQtyDue(customerOrderDTO.getIfsConvFactor().multiply(customerOrderDTO.getOtcQuantity())); |
| | | if (BooleanUtil.isTrue(customerOrderDTO.getIsDocument())) { |
| | | customerOrderDTO.setCoState(CustomerOrderStateStringValues.PLAN); |
| | | } else { |
| | | customerOrderDTO.setCoState(CustomerOrderStateStringValues.TECHNOLOGYUNCHECK); |
| | | } |
| | | updateById(customerOrderDTO); |
| | | return R.ok(); |
| | | } |
| | | public R fullUpdate(CustomerOrderVO1 customerOrderVO1) { |
| | | CustomerOrder customerOrder = new CustomerOrder(); |
| | | BeanUtils.copyProperties(customerOrderVO1,customerOrder); |
| | | customerOrder.setId(customerOrderVO1.getId()); |
| | | customerOrderMapper.updateById(customerOrder); |
| | | |
| | | Customer customer = new Customer(); |
| | | BeanUtils.copyProperties(customerOrderVO1,customer); |
| | | customer.setId(customerOrderMapper.selectById(customerOrderVO1.getId()).getCustomerId()); |
| | | customerMapper.updateById(customer); |
| | | return R.ok("修改成功!"); |
| | | } |
| | | |
| | | @Override |
| | |
| | | // } |
| | | //保存主生产计划 |
| | | MasterProductionSchedule masterProductionSchedule = new MasterProductionSchedule(); |
| | | //主生产计划号 |
| | | masterProductionSchedule.setMpsNo(scheduleNumberGenerator.generateNumberWithPrefix(MasterProductionSchedule.DIGIT, MasterProductionSchedule.PREFIX, MasterProductionSchedule::getMpsNo)); |
| | | masterProductionSchedule.setPartId(customerOrderDTO.getPartId()); |
| | | Part part = partMapper.selectOne(Wrappers.<Part>lambdaQuery().eq(Part::getPartNo, customerOrderDTO.getPartNo())); |
| | | //零件id |
| | | masterProductionSchedule.setPartId(part.getId()); |
| | | //将审核状态和工艺文件的id同步给生产计划 |
| | | masterProductionSchedule.setIsAudit(customerOrderDTO.getIsAudit()); |
| | | masterProductionSchedule.setTechnologyDocumentId(customerOrderDTO.getTechnologyDocumentId()); |
| | | masterProductionSchedule.setManufactureAttr(customerOrderDTO.getManufactureAttr()); |
| | | masterProductionSchedule.setDocNumber(customerOrderDTO.getDocNumber()); |
| | | //需求数量 |
| | | masterProductionSchedule.setQtyRequired(qta); |
| | | //需求日期 |
| | | masterProductionSchedule.setRequiredDate(customerOrderDTO.getDeliveryDate()); |
| | | //备注 |
| | | masterProductionSchedule.setRemark(customerOrderDTO.getRemark()); |
| | | masterProductionSchedule.setQtyRequired(qta); |
| | | masterProductionSchedule.setRequiredDate(customerOrderDTO.getWantedDeliveryDate()); |
| | | masterProductionSchedule.setRemark(customerOrderDTO.getRemark()); |
| | | masterProductionSchedule.setSource("销售订单"); |
| | | masterProductionScheduleMapper.insert(masterProductionSchedule); |
| | | customerOrderDTO.setRequireNumber(customerOrderDTO.getQtyPlaned()); |
| | | |
| | | // if (CollectionUtil.isNotEmpty(operationTaskProduceList)) { |
| | | // for (OperationTaskProduce operationTaskProduce : operationTaskProduceList) { |
| | |
| | | return true; |
| | | } |
| | | |
| | | //多个销售订单创建一个主生产计划 |
| | | @Override |
| | | public MasterProductionSchedule createOneMasterProductionScheduleByCustomerOrders(List<CustomerOrderDTO> customerOrders) { |
| | | List<Long> ids = customerOrders.stream().map(CustomerOrderDTO::getId).collect(Collectors.toList()); |
| | |
| | | return R.failed("工艺文件缺失"); |
| | | } |
| | | List<CustomerOrder> customerOrderList = baseMapper.selectBatchIds(ids); |
| | | customerOrderList.forEach(l->{ |
| | | log.info("关联数据==============================>"+l); |
| | | }); |
| | | String msg = ""; |
| | | for (CustomerOrder customerOrder : customerOrderList) { |
| | | if (BooleanUtil.isTrue(customerOrder.getIsDocument())) { |
| | | msg += customerOrder.getCustomerOrderNo() + "已关联工艺文件!"; |
| | | } |
| | | if (StringUtils.isBlank(customerOrder.getSalesPartNo())) { |
| | | if (StringUtils.isBlank(customerOrder.getPartNo())) { |
| | | msg += customerOrder.getCustomerOrderNo() + "未选择销售件!"; |
| | | } |
| | | if (StringUtils.isBlank(customerOrder.getPartNo())) { |
| | | customerOrder.setPartNo(document.getPartNo()); |
| | | } |
| | | //if (StringUtils.isBlank(customerOrder.getPartNo())) { |
| | | // customerOrder.setPartNo(document.getPartNo()); |
| | | //} |
| | | customerOrder.setIsDocument(true); |
| | | customerOrder.setCoState(CustomerOrderStateStringValues.PLAN); |
| | | customerOrder.setTechnologyDocumentId(docId); |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R otcCustomerOrderSync(String selectTime, String pathCode) { |
| | | try { |
| | | if (StringUtils.isBlank(selectTime)) { |
| | |
| | | .contentType("application/json") |
| | | .header("Authorization", "Bearer " + token).form(map).execute().body(); |
| | | JSONObject result = JSONObject.parseObject(str); |
| | | //JSONArray jsonArray = result.getJSONArray("data"); |
| | | //jsonArray.forEach(); |
| | | //return null; |
| | | //主表参数表 |
| | | List<OrderParam> orderParams = orderParamService.list(); |
| | | if (result.getInteger("code") == 0) { |
| | |
| | | //所属工厂 |
| | | String affiliatedContract=customerJSONObject.getString("affiliatedContract"); |
| | | //只拉取所属公司为中天海洋系统有限公司的数据 |
| | | if (!"中天材料厂".equals(affiliatedContract)){ |
| | | if (!AFFILIATED_CONTRACT.equals(affiliatedContract)){ |
| | | continue; |
| | | } |
| | | // 不在这几个状态中的数据就跳过 |
| | |
| | | customer = new Customer(); |
| | | } |
| | | //如果OTC中主表状态是取消那就跳过或者删除已经同步的数据 |
| | | if ("已取消".equals(otcMainStatus)) { |
| | | if (OTC_MAIN_STATUS_CANCEL.equals(otcMainStatus)) { |
| | | if (customer.getId() != null) { |
| | | customerMapper.deleteById(customer.getId()); |
| | | baseMapper.delete(Wrappers.<CustomerOrder>lambdaQuery().eq(CustomerOrder::getCustomerId, customer.getId())); |
| | | } |
| | | continue; |
| | | } |
| | | if (!"已下达".equals(otcMainStatus)) {//null == affiliatedCompany || !Arrays.asList("已下达").contains(otcMainStatus) /*|| affiliatedCompany.equals("江苏中天科技股份有限公司")*/) { |
| | | if (!OTC_MAIN_STATUS_TRANSMIT.equals(otcMainStatus)) {//null == affiliatedCompany || !Arrays.asList("已下达").contains(otcMainStatus) /*|| affiliatedCompany.equals("江苏中天科技股份有限公司")*/) { |
| | | continue;//只获取OTC中已审核及已下达的订单, |
| | | } |
| | | //客户编号 |
| | |
| | | customerOrder = new CustomerOrder(); |
| | | } |
| | | //如果这个单子在OTC中取消状态 那就删除 |
| | | if (otcOrderStatus.equals("已取消")) { |
| | | if (otcOrderStatus.equals(OTC_MAIN_STATUS_CANCEL)) { |
| | | if (customerOrder.getId() != null) { |
| | | baseMapper.deleteById(customerOrder.getId()); |
| | | } |
| | |
| | | } else { |
| | | customerOrder.setCoState(CustomerOrderStateStringValues.PARTUNCHECKED); |
| | | } |
| | | if (org.apache.commons.lang3.StringUtils.equals("已下达", otcMainStatus)) { |
| | | if (org.apache.commons.lang3.StringUtils.equals(OTC_MAIN_STATUS_TRANSMIT, otcMainStatus)) { |
| | | customerOrder.setCoState(CustomerOrderStateStringValues.TECHNOLOGYUNCHECK); |
| | | customerOrder.setOtcPartSync(Boolean.TRUE); |
| | | } |
| | |
| | | customerOrder.setCoState(CustomerOrderStateStringValues.TECHNOLOGYUNCHECK); |
| | | customerOrder.setOtcPartSync(Boolean.TRUE); |
| | | } |
| | | //审核状态为 01draft 草稿 |
| | | customerOrder.setIsAudit(AuditStateStringValues.DRAFT); |
| | | //审核状态为 03accepted 通过 |
| | | customerOrder.setIsAudit(AuditStateStringValues.ACCEPTED); |
| | | baseMapper.insert(customerOrder); |
| | | } |
| | | addCustomerPara(customerJSONObject, customerOrderJSONObject, customerOrder, orderParamList); |
| | |
| | | |
| | | @Override |
| | | public R uploadProcessConfigFile(MultipartFile file, String orderNumber, String lineNumber) { |
| | | String fileName = IdUtil.simpleUUID() + StrUtil.DOT + FileUtil.extName(file.getOriginalFilename()); |
| | | String fileName = FileUtil.extName(file.getOriginalFilename()); |
| | | try { |
| | | minioTemplate.putObject(ossProperties.getBucketName(), fileName, file.getInputStream()); |
| | | OrderProcessConfigFile configFile = new OrderProcessConfigFile(); |
| | | configFile.setFileName(fileName); |
| | | configFile.setOriginalFileName(file.getOriginalFilename()); |
| | | configFile.setOrderNumber(orderNumber); |
| | | configFile.setLineNumber(lineNumber); |
| | | configFile.setBucketName(ossProperties.getBucketName()); |
| | | configFile.setBucketName(FileSaveUtil.StoreFile(file)); |
| | | orderProcessConfigFileMapper.insert(configFile); |
| | | ProcessConfigFileOrderMapping mapping = ProcessConfigFileOrderMapping.builder().configFileId(configFile.getId()) |
| | | .orderNumber(orderNumber).lineNumber(lineNumber).build(); |
| | |
| | | |
| | | @Override |
| | | public void getFile(String bucket, String fileName, HttpServletResponse response) { |
| | | try (InputStream inputStream = minioTemplate.getObject(bucket, fileName)) { |
| | | try { |
| | | String path = FileSaveUtil.FILE_PATH + bucket; |
| | | InputStream inputStream = new FileInputStream(path); |
| | | response.setContentType("application/octet-stream; charset=UTF-8"); |
| | | IoUtil.copy(inputStream, response.getOutputStream()); |
| | | } catch (Exception e) { |
| | |
| | | public R deleteProcessConfigFile(Long id) { |
| | | try { |
| | | OrderProcessConfigFile configFile = orderProcessConfigFileMapper.selectById(id); |
| | | minioTemplate.removeObject(configFile.getBucketName(), configFile.getFileName()); |
| | | String filePath=FileSaveUtil.FILE_PATH+"//"+configFile.getBucketName(); |
| | | boolean del = FileUtil.del(new File(filePath)); |
| | | //minioTemplate.removeObject(configFile.getBucketName(), configFile.getFileName()); |
| | | orderProcessConfigFileMapper.deleteById(id); |
| | | processConfigFileOrderMappingMapper.delete(Wrappers.<ProcessConfigFileOrderMapping>lambdaQuery().eq(ProcessConfigFileOrderMapping::getConfigFileId, id)); |
| | | return R.ok(); |