对比新文件 |
| | |
| | | package com.gk.firework.Scheduls.GenerateCode; |
| | | |
| | | import com.gk.firework.Domain.ContractLogInfo; |
| | | import com.gk.firework.Domain.ContractOrderInfo; |
| | | import com.gk.firework.Domain.ProductCodeInfo; |
| | | import com.gk.firework.Domain.ProductLocusInfo; |
| | | import com.gk.firework.Domain.Vo.ContractStatus; |
| | | import com.gk.firework.Domain.Vo.GenerateCode; |
| | | import com.gk.firework.Domain.Vo.ProductVo; |
| | | import com.gk.firework.Service.*; |
| | | import org.apache.log4j.LogManager; |
| | | import org.apache.log4j.Logger; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.scheduling.annotation.EnableScheduling; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | |
| | | @Configuration |
| | | @EnableScheduling |
| | | @ConditionalOnProperty(prefix = "scheduling",name = "enabled",havingValue = "true") |
| | | public class GenerateCodeTask { |
| | | private Logger logger = LogManager.getLogger(GenerateCodeTask.class); |
| | | @Autowired |
| | | ContractDetailService contractDetailService; |
| | | @Autowired |
| | | ContractOrderService contractOrderService; |
| | | @Autowired |
| | | ContractLogService contractLogService; |
| | | @Autowired |
| | | ProductService productService; |
| | | @Autowired |
| | | ProductCodeService productCodeService; |
| | | @Autowired |
| | | ProductLocusService productLocusService; |
| | | |
| | | |
| | | @Scheduled(cron = "0/5 * * * * ?") //每隔5秒执行一次 |
| | | private void GenerateCode() throws Exception { |
| | | SimpleDateFormat sdfnow = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | List<ContractOrderInfo> orderInfoList = contractOrderService.selectByStatus(ContractStatus.Confirm_Product,sdfnow.format(new Date())); |
| | | for (ContractOrderInfo contractOrderInfo : orderInfoList) { |
| | | //生成电子标签号码 |
| | | List<ProductVo> productVoList = contractDetailService.selectByOrder(contractOrderInfo.getOrdercode()); |
| | | for (ProductVo productVo : productVoList) { |
| | | //查询最新的箱码 |
| | | String directionCode = productVo.getDirectionCode(); |
| | | String four = GenerateCode.generateProduct(); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
| | | ProductCodeInfo productCodeInfo = productCodeService.selectByFourteen(directionCode + four,sdf.format(new Date())); |
| | | |
| | | List<ProductCodeInfo> productCodeInfoList = new ArrayList<>(); |
| | | Date now = new Date(); |
| | | for (int i = 0; i < productVo.getNum(); i++) { |
| | | int serial = 1; |
| | | if (productCodeInfoList.size() > 0){ |
| | | serial = Integer.parseInt(productCodeInfoList.get(productCodeInfoList.size()-1).getOriginalcode().substring(14,19)) |
| | | + productCodeInfoList.get(productCodeInfoList.size()-1).getBoxnumber(); |
| | | }else if (productCodeInfo != null) { |
| | | serial = Integer.parseInt(productCodeInfo.getOriginalcode().substring(14,19)) |
| | | + productCodeInfo.getBoxnumber(); |
| | | } |
| | | String serialNum = String.format("%05d", serial); |
| | | |
| | | String boxNum = String.format("%03d", productVo.getBoxNumber()); |
| | | ProductCodeInfo productCode = new ProductCodeInfo(); |
| | | productCode.setOrdercode(contractOrderInfo.getOrdercode()); |
| | | productCode.setOriginalcode(directionCode + four + serialNum + boxNum); |
| | | productCode.setItemname(productVo.getName()); |
| | | productCode.setManufacturer(productVo.getManufacturer()); |
| | | |
| | | BigDecimal explosiveContent = productVo.getExplosiveContent(); |
| | | Integer boxNumber = productVo.getBoxNumber(); |
| | | BigDecimal sum = explosiveContent.multiply(new BigDecimal(boxNumber)); |
| | | if (sum.compareTo(new BigDecimal(1000)) > 0) { |
| | | BigDecimal explosive = sum.divide(new BigDecimal(1000),2, RoundingMode.HALF_UP); |
| | | productCode.setExplosivecontent(explosive + "kg"); |
| | | } else { |
| | | productCode.setExplosivecontent(sum + "g"); |
| | | } |
| | | productCode.setBoxnumber(productVo.getBoxNumber()); |
| | | productCode.setType(productVo.getType()); |
| | | productCode.setLevel(productVo.getLevel()); |
| | | productCode.setCreatedby("自动生成"); |
| | | productCode.setCreateddate(new Date()); |
| | | productCode.setPrice(productVo.getPrice()); |
| | | productCodeInfoList.add(productCode); |
| | | //电子合同生成电子标签号插入流向轨迹表 |
| | | ProductLocusInfo productLocusInfo = new ProductLocusInfo(); |
| | | productLocusInfo.setDirectioncode(productCode.getOriginalcode()); |
| | | productLocusInfo.setCreateddate(now); |
| | | productLocusInfo.setModifieddate(now); |
| | | //生产单位 |
| | | productLocusInfo.setContent(productCode.getManufacturer()); |
| | | productLocusInfo.setType(ProductLocusInfo.ELECTRONIC_LABEL_STATUS); |
| | | productLocusInfo.setBoxcode(Integer.valueOf(productCode.getOriginalcode().substring(19,22)).toString()); |
| | | productLocusService.insertProductLocus(productLocusInfo); |
| | | } |
| | | productCodeService.insertBatch(productCodeInfoList); |
| | | } |
| | | |
| | | contractOrderInfo.setStatus(ContractStatus.Generated); |
| | | contractOrderInfo.setModifieddate(new Date()); |
| | | contractOrderService.updateById(contractOrderInfo); |
| | | |
| | | ContractLogInfo contractLogInfo = new ContractLogInfo(); |
| | | contractLogInfo.setOptlog("生成电子标签"); |
| | | contractLogInfo.setOperator("后台生成"); |
| | | contractLogInfo.setOrdercode(contractOrderInfo.getOrdercode()); |
| | | contractLogInfo.setOperatordate(new Date()); |
| | | contractLogService.save(contractLogInfo); |
| | | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | } |