| | |
| | | package com.zy.common.service.erp.task; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.core.common.Cools; |
| | | 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.task.AbstractHandler; |
| | | import com.zy.common.service.erp.ErpService; |
| | | import com.zy.common.service.erp.entity.Goods; |
| | | import lombok.Synchronized; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * erp任务控制器 |
| | |
| | | |
| | | @Autowired |
| | | private ErpService erpService; |
| | | @Autowired |
| | | private TagService tagService; |
| | | @Autowired |
| | | private MatService matService; |
| | | |
| | | @Scheduled(cron = "0/30 * * * * ? ") |
| | | @Scheduled(cron = "0/5 * * * * ? ") |
| | | @Synchronized |
| | | public void syncMat() { |
| | | @Transactional |
| | | public synchronized void syncMat() { |
| | | Tag top = tagService.getTop(); |
| | | List<Goods> goods = erpService.selectGoods(1); |
| | | if (!Cools.isEmpty(goods)) { |
| | | for (Goods good : goods) { |
| | | Mat mat = matService.selectByMatnr(good.getBarCode()); |
| | | if (mat == null) { |
| | | mat = new Mat(); |
| | | mat.setTagId(top.getId()); |
| | | mat.setMatnr(good.getBarCode()); |
| | | mat.setMaktx(good.getMaterialNO()); |
| | | mat.setSpecs(good.getProdSpec()); |
| | | mat.setModel(good.getBatch()); |
| | | mat.setWeight(good.getNWT()); |
| | | mat.setUnits(good.getNumOfBobbins()==null?null:good.getNumOfBobbins().doubleValue()); |
| | | mat.setManuDate(good.getProdDate()); |
| | | |
| | | if (!matService.insert(mat)) { |
| | | throw new CoolException(JSON.toJSONString(good) + "商品同步失败"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |