New file |
| | |
| | | package com.zy.third.erp.task; |
| | | |
| | | import com.zy.common.service.erp.ErpSqlServer; |
| | | import com.zy.third.erp.entity.ItemTB; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 物料档案 |
| | | */ |
| | | @Slf4j |
| | | @Component |
| | | public class ERPItemScheduler { |
| | | @Value("${erp.enabled}") |
| | | private Boolean erpEnabled; |
| | | |
| | | @Autowired |
| | | private ERPItemService erpItemService; |
| | | |
| | | @Autowired |
| | | private ErpSqlServer erpSqlServer; |
| | | |
| | | |
| | | |
| | | @Transactional(rollbackFor = Throwable.class) |
| | | @Scheduled(cron = "${erp.refreshtime}") |
| | | public void ItemScheduler() { |
| | | log.info("ItemScheduler开始了"); |
| | | if (!erpEnabled) return; |
| | | String sqlItemTB = "select * from erp_ItemTB where LKName='中扬二期'"; |
| | | List<ItemTB> itemTBS = erpSqlServer.select(sqlItemTB, ItemTB.class); |
| | | if (itemTBS != null && itemTBS.size() > 0) { |
| | | for (ItemTB itemTB : itemTBS) { |
| | | System.out.println(itemTB); |
| | | //00代表新增 |
| | | if (itemTB.getFlag().equals("00")) { |
| | | erpItemService.addToMainDatabase(itemTB); |
| | | } |
| | | //22代表删除 |
| | | if (itemTB.getFlag().equals("22")) { |
| | | erpItemService.deleteFromMainDatabase(itemTB); |
| | | } |
| | | moveToBak(itemTB); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 数据库里有触发器,当item表的数据被删除时,会自动向item_bak添加,不用卸载代码里 |
| | | * |
| | | * @param itemTB |
| | | */ |
| | | //将数据从主表移动到bak表里 |
| | | private void moveToBak(ItemTB itemTB) { |
| | | erpSqlServer.update("delete from erp_ItemTB where LKName='中扬二期' and ItemId = '" + itemTB.getItemId() + "'"); |
| | | } |
| | | } |