| | |
| | | package com.zy.common.service.erp.task; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.core.common.Cools; |
| | | import com.core.common.DateUtils; |
| | | import com.core.common.SnowflakeIdWorker; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.entity.Mat; |
| | | import com.zy.asrs.entity.Tag; |
| | | import com.zy.asrs.service.MatService; |
| | | import com.zy.asrs.service.TagService; |
| | | import com.zy.asrs.entity.*; |
| | | import com.zy.asrs.service.*; |
| | | import com.zy.asrs.task.AbstractHandler; |
| | | import com.zy.common.service.erp.ErpService; |
| | | import com.zy.common.service.erp.dto.VoucherDto; |
| | | import com.zy.common.service.erp.entity.Goods; |
| | | import com.zy.common.service.erp.entity.Voucher; |
| | | import com.zy.common.service.erp.entity.VoucherDetail; |
| | | import lombok.Synchronized; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | | |
| | | /** |
| | | * erp任务控制器 |
| | |
| | | private TagService tagService; |
| | | @Autowired |
| | | private MatService matService; |
| | | |
| | | |
| | | @Scheduled(cron = "0/5 * * * * ? ") |
| | | @Synchronized |
| | | @Transactional |
| | | public synchronized void syncMat1() { |
| | | erpService.updateStateForGoods("PL0122231401176", 1); |
| | | } |
| | | @Autowired |
| | | private OrderService orderService; |
| | | @Autowired |
| | | private DocTypeService docTypeService; |
| | | @Autowired |
| | | private OrderDetlService orderDetlService; |
| | | @Autowired |
| | | private SnowflakeIdWorker snowflakeIdWorker; |
| | | |
| | | @Scheduled(cron = "0/5 * * * * ? ") |
| | | @Synchronized |
| | |
| | | @Transactional |
| | | public synchronized void syncOrder() { |
| | | List<VoucherDto> list = erpService.selectOrder(0); |
| | | System.out.println(JSON.toJSONString(list)); |
| | | for (VoucherDto dto : list) { |
| | | Voucher voucher = dto.getVoucher(); |
| | | Order order = orderService.selectByNo(voucher.getVoucherID()); |
| | | if (Cools.isEmpty(order)) { |
| | | |
| | | String regEx = "[^0-9]"; |
| | | Pattern compile = Pattern.compile(regEx); |
| | | Matcher matcher = compile.matcher(voucher.getMT()); |
| | | String docTypeVal = matcher.replaceAll("").trim(); |
| | | |
| | | DocType docType = docTypeService.selectOrAdd(docTypeVal, null); |
| | | Date now = new Date(); |
| | | // 单据主档 |
| | | order = new Order( |
| | | String.valueOf(snowflakeIdWorker.nextId()), // 编号[非空] |
| | | voucher.getVoucherID(), // 订单编号 |
| | | DateUtils.convert(now), // 单据日期 |
| | | docType.getDocId(), // 单据类型 |
| | | null, // 项目编号 |
| | | null, // |
| | | null, // 调拨项目编号 |
| | | voucher.getBatch(), // 初始票据号 |
| | | voucher.getMaterialNO(), // 票据号 |
| | | null, // 客户编号 |
| | | voucher.getCustomer(), // 客户 |
| | | voucher.getCenterID(), // 联系方式 |
| | | voucher.getPlant(), // 操作人员 |
| | | voucher.getTotalNum(), // 合计金额 ******************** |
| | | null, // 优惠率 |
| | | null, // 优惠金额 |
| | | null, // 销售或采购费用合计 |
| | | null, // 实付金额 |
| | | null, // 付款类型 |
| | | voucher.getLoc(), // 业务员 |
| | | voucher.getTotalCount(), // 结算天数 ******************** |
| | | null, // 邮费支付类型 |
| | | null, // 邮费 |
| | | null, // 付款时间 |
| | | null, // 发货时间 |
| | | null, // 物流名称 |
| | | null, // 物流单号 |
| | | 1L, // 订单状态 |
| | | 1, // 状态 |
| | | 9527L, // 添加人员 |
| | | now, // 添加时间 |
| | | 9527L, // 修改人员 |
| | | now, // 修改时间 |
| | | null // 备注 |
| | | ); |
| | | if (!orderService.insert(order)) { |
| | | throw new CoolException(order.getOrderNo() + "生成单据主档失败,请联系管理员"); |
| | | } |
| | | for (VoucherDetail detail : dto.getDetails()) { |
| | | |
| | | Mat mat = matService.selectByMatnr(detail.getBarcode()); |
| | | if (mat == null) { |
| | | throw new CoolException(detail.getBarcode() + "单据号不存在"); |
| | | } |
| | | |
| | | OrderDetl orderDetl = new OrderDetl(); |
| | | orderDetl.sync(mat); |
| | | // orderDetl.setBatch(detlDto.getBatch()); |
| | | orderDetl.setAnfme(1.0D); |
| | | orderDetl.setOrderId(order.getId()); |
| | | orderDetl.setOrderNo(order.getOrderNo()); |
| | | orderDetl.setCreateBy(9527L); |
| | | orderDetl.setCreateTime(now); |
| | | orderDetl.setUpdateBy(9527L); |
| | | orderDetl.setUpdateTime(now); |
| | | orderDetl.setStatus(1); |
| | | orderDetl.setQty(0.0D); |
| | | if (!orderDetlService.insert(orderDetl)) { |
| | | throw new CoolException(order.getOrderNo() + "生成单据明细失败,请联系管理员"); |
| | | } |
| | | } |
| | | |
| | | // erp 同步 |
| | | int state = 1; |
| | | if (!erpService.updateStateForVoucher(voucher.getVoucherID(), 1)) { |
| | | throw new CoolException(voucher.getVoucherID() + "订单修改State为"+state+"失败"); |
| | | } else { |
| | | erpService.updateTimeForVoucherDetail(voucher.getVoucherID()); |
| | | } |
| | | |
| | | } else { |
| | | log.warn("{}订单已存在", voucher.getVoucherID()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |