|
@@ -0,0 +1,253 @@
|
|
|
|
+package cn.ezhizao.project.business.controller;
|
|
|
|
+
|
|
|
|
+import cn.ezhizao.framework.web.controller.BaseController;
|
|
|
|
+import cn.ezhizao.framework.web.domain.AjaxResult;
|
|
|
|
+import cn.ezhizao.project.business.domain.*;
|
|
|
|
+import cn.ezhizao.project.business.service.IBizProductService;
|
|
|
|
+import cn.ezhizao.project.business.service.IBizPullP2TimeService;
|
|
|
|
+import cn.ezhizao.project.business.service.IBizShaftCategoryService;
|
|
|
|
+import cn.ezhizao.project.business.service.IInc10100Service;
|
|
|
|
+import cn.ezhizao.project.system.domain.SysDictData;
|
|
|
|
+import cn.ezhizao.project.system.domain.SysUser;
|
|
|
|
+import cn.ezhizao.project.system.service.ISysDeptService;
|
|
|
|
+import cn.ezhizao.project.system.service.ISysDictDataService;
|
|
|
|
+import cn.ezhizao.project.system.service.ISysUserService;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
+import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
|
+
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.Date;
|
|
|
|
+import java.util.List;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * mrp10201Controller
|
|
|
|
+ *
|
|
|
|
+ * @author ezhizao_zx
|
|
|
|
+ */
|
|
|
|
+@RestController
|
|
|
|
+@RequestMapping("/business/inc10100")
|
|
|
|
+public class Inc10100Controller extends BaseController {
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ private IBizPullP2TimeService pullP2TimeService;
|
|
|
|
+ @Resource
|
|
|
|
+ private IInc10100Service IInc10100Service;
|
|
|
|
+ @Resource
|
|
|
|
+ private IBizProductService productService;
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ private ISysUserService sysUserService;
|
|
|
|
+ @Resource
|
|
|
|
+ private ISysDeptService sysDeptService;
|
|
|
|
+ @Resource
|
|
|
|
+ private ISysDictDataService sysDictDataService;
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ private IBizShaftCategoryService bizShaftCategoryService;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取inc10100详细信息
|
|
|
|
+ * 获取 inc10100 信息传到 biz_product
|
|
|
|
+ */
|
|
|
|
+ @PreAuthorize("@ss.hasPermi('business:product:sync')")
|
|
|
|
+ @GetMapping(value = "/getP2Product")
|
|
|
|
+ public AjaxResult getP2Product() {
|
|
|
|
+ // 先从新系统中的 biz_pull_p2_time 中获取最新数据
|
|
|
|
+ BizPullP2Time pullDetail = new BizPullP2Time();
|
|
|
|
+ pullDetail.setType("product");
|
|
|
|
+ List<BizPullP2Time> pullDetails = pullP2TimeService.getList(pullDetail);
|
|
|
|
+ /*
|
|
|
|
+ * 如果 pullDetails 不为空,则获取最后一条数据,做为查询P2的生产计划明细的条件。
|
|
|
|
+ * 这里有个细节,每次从P2中获取生产计划明细,不能都从头开始,否则随着数据量增加,将会重复拉取大量的数据,性能很差
|
|
|
|
+ * 拉取数据后,存入新系统中,每次拉取前,将新系统中 biz_pull_p2_time 的最后一条数据记录的时间,做为条件传递过去
|
|
|
|
+ * P2中,获取领料时间大于上一次拉取时间的新数据,再存入新系统中。
|
|
|
|
+ */
|
|
|
|
+ BizPullP2Time lastPullDetail = null;
|
|
|
|
+ if (pullDetails.size() > 0) {
|
|
|
|
+ int lastIndex = pullDetails.size() - 1;
|
|
|
|
+ lastPullDetail = pullDetails.get(lastIndex);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ QueryWrapper<Inc10100> queryWrapper = new QueryWrapper<>();
|
|
|
|
+ if (lastPullDetail != null) {
|
|
|
|
+ Date newCondition = lastPullDetail.getPullTime();
|
|
|
|
+ /*
|
|
|
|
+ * 这里应该根据新系统中记录的最大的拉取日期
|
|
|
|
+ * modate:P2中的修改日期,为了避免重复拉取,需要做条件判断。modate必须大于上一次拉取时间
|
|
|
|
+ */
|
|
|
|
+ queryWrapper.apply("modate IS NOT NULL AND modate > {0}", newCondition);
|
|
|
|
+ }
|
|
|
|
+ List<Inc10100> inc10100List = IInc10100Service.getList(queryWrapper);
|
|
|
|
+ List<BizProduct> products = productService.query().list();
|
|
|
|
+ List<BizProduct> newProducts = new ArrayList<>();
|
|
|
|
+ List<BizProduct> changeProducts = new ArrayList<>();
|
|
|
|
+ List<SysUser> userList = sysUserService.getList();
|
|
|
|
+ SysDictData conditions = new SysDictData();
|
|
|
|
+ conditions.setDictType("product_status_code");
|
|
|
|
+ List<SysDictData> dictList = sysDictDataService.selectDictDataList(conditions);
|
|
|
|
+ List<BizShaftCategory> categories = bizShaftCategoryService.query().list();
|
|
|
|
+ inc10100List.forEach(l -> {
|
|
|
|
+ if (products.stream().anyMatch(v -> v.getProductCode().equals(l.getPart().trim()) && v.getPreStock().equals(l.getPrloc().trim()))) {
|
|
|
|
+ // 已插入产品
|
|
|
|
+ BizProduct old = products.stream().filter(v -> v.getProductCode().equals(l.getPart().trim()) && v.getPreStock().equals(l.getPrloc().trim())).findFirst().orElse(null);
|
|
|
|
+ if (old != null) {
|
|
|
|
+ old.setType(l.getType());
|
|
|
|
+ old.setShaftBroadCategoryCode(l.getDtype());
|
|
|
|
+ old.setShaftCategoryCode(l.getZtype());
|
|
|
|
+ if (old.getShaftCategoryCode() != null) {
|
|
|
|
+ BizShaftCategory bizShaftCategory = categories.stream().filter(v -> v.getSubCategoryCode().equals(old.getShaftCategoryCode())).findFirst().orElse(null);
|
|
|
|
+ old.setShaftCategoryId(bizShaftCategory != null ? bizShaftCategory.getId() : null);
|
|
|
|
+ }
|
|
|
|
+ if (old.getShaftBroadCategoryCode() != null) {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ old.setSpecification(l.getSpec());
|
|
|
|
+ old.setDrawingNumber(l.getDraw());
|
|
|
|
+ old.setCompanyAlias(l.getKhjc());
|
|
|
|
+ old.setCompanyCode(l.getCust());
|
|
|
|
+ old.setDescription(l.getDescr());
|
|
|
|
+ old.setProductionTenantId(l.getSfacno() != null ? Long.parseLong(l.getSfacno()) : null);
|
|
|
|
+ old.setDiameter(l.getDzj());
|
|
|
|
+ old.setLenght(l.getLenght());
|
|
|
|
+ old.setThickness(BigDecimal.valueOf(l.getAbbr()));
|
|
|
|
+ old.setDensity(l.getDensity());
|
|
|
|
+ old.setSalesmanCode(l.getXsyno());
|
|
|
|
+ if (old.getSalesmanCode() != null) {
|
|
|
|
+ SysUser user = userList.stream().filter(v -> v.getUserName().equals(old.getSalesmanCode())).findFirst().orElse(null);
|
|
|
|
+ old.setSalesmanId(user != null ? user.getUserId() : null);
|
|
|
|
+ }
|
|
|
|
+ old.setStockKeeperCode(l.getBgyno());
|
|
|
|
+ if (old.getStockKeeperCode() != null) {
|
|
|
|
+ SysUser bgy = userList.stream().filter(v -> v.getUserName().equals(old.getStockKeeperCode())).findFirst().orElse(null);
|
|
|
|
+ old.setStockKeeperId(bgy != null ? bgy.getUserId() : null);
|
|
|
|
+ }
|
|
|
|
+ old.setDispatcherCode(l.getDdyno());
|
|
|
|
+ if (old.getDispatcherCode() != null) {
|
|
|
|
+ SysUser ddy = userList.stream().filter(v -> v.getUserName().equals(old.getDispatcherCode())).findFirst().orElse(null);
|
|
|
|
+ old.setDispatcherId(ddy != null ? ddy.getUserId() : null);
|
|
|
|
+ }
|
|
|
|
+ old.setMaterialCode(l.getPhcode());
|
|
|
|
+ if (old.getMaterialCode() != null) {
|
|
|
|
+ // 目前没有材料表
|
|
|
|
+ }
|
|
|
|
+ old.setProductStatusCode(l.getStatus());
|
|
|
|
+ if (old.getProductStatusCode() != null) {
|
|
|
|
+ SysDictData dictData = dictList.stream().filter(v -> v.getDictValue().equals(old.getProductStatusCode())).findFirst().orElse(null);
|
|
|
|
+ old.setProductStatusId(dictData != null ? dictData.getDictCode() : null);
|
|
|
|
+ }
|
|
|
|
+ old.setTechnicianCode(l.getJsyno());
|
|
|
|
+ if (old.getTechnicianCode() != null) {
|
|
|
|
+ SysUser jsy = userList.stream().filter(v -> v.getUserName().equals(old.getTechnicianCode())).findFirst().orElse(null);
|
|
|
|
+ old.setTechnicianId(jsy != null ? jsy.getUserId() : null);
|
|
|
|
+ }
|
|
|
|
+ old.setRemark(l.getRemark());
|
|
|
|
+ changeProducts.add(old);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ // 新产品
|
|
|
|
+ BizProduct newProduct = new BizProduct();
|
|
|
|
+ newProduct.setProductCode(l.getPart());
|
|
|
|
+ newProduct.setPreStock(l.getPrloc());
|
|
|
|
+ newProduct.setType(l.getType());
|
|
|
|
+ newProduct.setShaftBroadCategoryCode(l.getDtype());
|
|
|
|
+ newProduct.setShaftCategoryCode(l.getZtype());
|
|
|
|
+ if (newProduct.getShaftCategoryCode() != null) {
|
|
|
|
+ BizShaftCategory bizShaftCategory = categories.stream().filter(v -> v.getSubCategoryCode().equals(newProduct.getShaftCategoryCode())).findFirst().orElse(null);
|
|
|
|
+ newProduct.setShaftCategoryId(bizShaftCategory != null ? bizShaftCategory.getId() : null);
|
|
|
|
+ }
|
|
|
|
+ if (newProduct.getShaftBroadCategoryCode() != null) {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ newProduct.setSpecification(l.getSpec());
|
|
|
|
+ newProduct.setDrawingNumber(l.getDraw());
|
|
|
|
+ newProduct.setCompanyAlias(l.getKhjc());
|
|
|
|
+ newProduct.setCompanyCode(l.getCust());
|
|
|
|
+ newProduct.setDescription(l.getDescr());
|
|
|
|
+ newProduct.setProductionTenantId(l.getSfacno() != null ? Long.parseLong(l.getSfacno()) : null);
|
|
|
|
+ newProduct.setDiameter(l.getDzj());
|
|
|
|
+ newProduct.setLenght(l.getLenght());
|
|
|
|
+ newProduct.setThickness(BigDecimal.valueOf(l.getAbbr()));
|
|
|
|
+ newProduct.setDensity(l.getDensity());
|
|
|
|
+ newProduct.setSalesmanCode(l.getXsyno());
|
|
|
|
+ if (newProduct.getSalesmanCode() != null) {
|
|
|
|
+ SysUser user = userList.stream().filter(v -> v.getUserName().equals(newProduct.getSalesmanCode())).findFirst().orElse(null);
|
|
|
|
+ newProduct.setSalesmanId(user != null ? user.getUserId() : null);
|
|
|
|
+ }
|
|
|
|
+ newProduct.setStockKeeperCode(l.getBgyno());
|
|
|
|
+ if (newProduct.getStockKeeperCode() != null) {
|
|
|
|
+ SysUser user = userList.stream().filter(v -> v.getUserName().equals(newProduct.getStockKeeperCode())).findFirst().orElse(null);
|
|
|
|
+ newProduct.setStockKeeperId(user != null ? user.getUserId() : null);
|
|
|
|
+ }
|
|
|
|
+ newProduct.setDispatcherCode(l.getDdyno());
|
|
|
|
+ if (newProduct.getDispatcherCode() != null) {
|
|
|
|
+ SysUser user = userList.stream().filter(v -> v.getUserName().equals(newProduct.getDispatcherCode())).findFirst().orElse(null);
|
|
|
|
+ newProduct.setDispatcherId(user != null ? user.getUserId() : null);
|
|
|
|
+ }
|
|
|
|
+ newProduct.setMaterialCode(l.getPhcode());
|
|
|
|
+ if (newProduct.getMaterialCode() != null) {
|
|
|
|
+ // 目前没有材料表
|
|
|
|
+ }
|
|
|
|
+ newProduct.setProductStatusCode(l.getStatus());
|
|
|
|
+ if (newProduct.getProductStatusCode() != null) {
|
|
|
|
+ SysDictData dictData = dictList.stream().filter(v -> v.getDictValue().equals(newProduct.getProductStatusCode())).findFirst().orElse(null);
|
|
|
|
+ newProduct.setProductStatusId(dictData != null ? dictData.getDictCode() : null);
|
|
|
|
+ }
|
|
|
|
+ newProduct.setTechnicianCode(l.getJsyno());
|
|
|
|
+ if (newProduct.getTechnicianCode() != null) {
|
|
|
|
+ SysUser jsy = userList.stream().filter(v -> v.getUserName().equals(newProduct.getTechnicianCode())).findFirst().orElse(null);
|
|
|
|
+ newProduct.setTechnicianId(jsy != null ? jsy.getUserId() : null);
|
|
|
|
+ }
|
|
|
|
+ newProduct.setRemark(l.getRemark());
|
|
|
|
+ newProducts.add(newProduct);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ if ((newProducts.isEmpty() || productService.saveBatch(newProducts)) && (changeProducts.isEmpty() || productService.updateBatchById(changeProducts))) {
|
|
|
|
+ BizPullP2Time bizPullP2Time = new BizPullP2Time();
|
|
|
|
+ // 将当前时间赋值给 pullTime 属性
|
|
|
|
+ bizPullP2Time.setPullTime(new Date());
|
|
|
|
+ bizPullP2Time.setType("product");
|
|
|
|
+ // 保存数据
|
|
|
|
+ pullP2TimeService.saveOrUpdate(bizPullP2Time);
|
|
|
|
+ return toAjax(true);
|
|
|
|
+ }
|
|
|
|
+ return toAjax(false);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 根据字典类型和字典值,获取字典数据
|
|
|
|
+ *
|
|
|
|
+ * @param type 字典类型
|
|
|
|
+ * @param value 字典值
|
|
|
|
+ * @return 字典数据
|
|
|
|
+ */
|
|
|
|
+ private SysDictData getDictData(String type, String value) {
|
|
|
|
+ SysDictData sysDictData = new SysDictData();
|
|
|
|
+ sysDictData.setDictType(type);
|
|
|
|
+ sysDictData.setDictValue(value);
|
|
|
|
+
|
|
|
|
+ return sysDictDataService.getDictData(sysDictData);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @param userName 用戶名
|
|
|
|
+ * @return 用户信息
|
|
|
|
+ */
|
|
|
|
+ private SysUser getUserByCode(String userName) {
|
|
|
|
+ return sysUserService.getUserByCode(userName.trim());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 根据轴类型编码,获取新系统中的轴类型id【需要进一步实现】
|
|
|
|
+ * @param code 轴类型编码
|
|
|
|
+ * @return 轴类型
|
|
|
|
+ */
|
|
|
|
+ public BizShaftCategory getShaftCode(String code) {
|
|
|
|
+ return bizShaftCategoryService.query().eq("sub_category_code", code).one();
|
|
|
|
+ }
|
|
|
|
+}
|