You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
udisyncdl-java/src/main/java/com/glxp/udidl/admin/thread/UdiTransferUtils.java

308 lines
16 KiB
Java

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.glxp.udidl.admin.thread;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.glxp.udidl.admin.entity.udi.CountProductEntity;
import com.glxp.udidl.admin.entity.udi.ProductClassify;
import com.glxp.udidl.admin.entity.udi.ProductInfoEntity;
import com.glxp.udidl.admin.entity.udi.UdiCompanyEntity;
import com.glxp.udidl.admin.entity.udid.Contactlist;
import com.glxp.udidl.admin.entity.udid.DeviceEntity;
import com.glxp.udidl.admin.entity.udid.Devicepackage;
import com.glxp.udidl.admin.req.ProductInfoFilterRequest;
import com.glxp.udidl.admin.req.UdiCompanyRequest;
import com.glxp.udidl.admin.service.inout.DeviceService;
import com.glxp.udidl.admin.service.inout.ProductInfoService;
import com.glxp.udidl.admin.service.udi.ProductClassifyService;
import com.glxp.udidl.admin.service.udi.UdiCompanyService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
@Service
public class UdiTransferUtils {
@Resource
DeviceService deviceService;
@Resource
ProductInfoService productInfoService;
@Resource
UdiCompanyService udiCompanyService;
@Resource
ProductClassifyService productClassifyService;
public void transUdi(String key) {
DeviceEntity deviceEntity = deviceService.searchById(key);
String di = deviceEntity.getZxxsdycpbs();
ProductInfoEntity productInfoEntity = new ProductInfoEntity();
BeanUtils.copyProperties(deviceEntity, productInfoEntity);
productInfoEntity.setUuid(key);
productInfoEntity.setDeviceRecordKey(deviceEntity.getDevicerecordkey());
productInfoEntity.setNameCode(deviceEntity.getZxxsdycpbs());
productInfoEntity.setCpmctymc(deviceEntity.getCpmctymc());
productInfoEntity.setCplb(deviceEntity.getCplb());
productInfoEntity.setFlbm(deviceEntity.getFlbm());
productInfoEntity.setGgxh(deviceEntity.getGgxh());
productInfoEntity.setQxlb(deviceEntity.getQxlb());
productInfoEntity.setTyshxydm(deviceEntity.getTyshxydm());
productInfoEntity.setYlqxzcrbarmc(deviceEntity.getYlqxzcrbarmc());
productInfoEntity.setZczbhhzbapzbh(deviceEntity.getZczbhhzbapzbh());
productInfoEntity.setScbssfbhph(deviceEntity.getScbssfbhph());
productInfoEntity.setScbssfbhscrq(deviceEntity.getScbssfbhscrq());
productInfoEntity.setScbssfbhsxrq(deviceEntity.getScbssfbhsxrq());
productInfoEntity.setScbssfbhxlh(deviceEntity.getScbssfbhxlh());
productInfoEntity.setBhxjsl(0);
productInfoEntity.setPackLevel(1 + "");
productInfoEntity.setBhxjcpbm("");
productInfoEntity.setBhzxxsbzsl(0);
productInfoEntity.setZxxsbzbhsydysl(0);
productInfoEntity.setScbssfbhxlh(deviceEntity.getScbssfbhxlh());
productInfoEntity.setYbbm(deviceEntity.getYbbm());
productInfoEntity.setSpmc(deviceEntity.getSpmc());
productInfoEntity.setCphhhbh(deviceEntity.getCphhhbh());
productInfoEntity.setCpms(deviceEntity.getCpms());
productInfoEntity.setCpbsbmtxmc(deviceEntity.getCpbsbmtxmc());
productInfoEntity.setCplx(deviceEntity.getCplx());
productInfoEntity.setHchzsb(deviceEntity.getHchzsb());
if (StrUtil.trimToEmpty(productInfoEntity.getSfwblztlcp()).equals("1")) {
productInfoEntity.setSfwblztlcp("是");
} else if (StrUtil.trimToEmpty(productInfoEntity.getSfwblztlcp()).equals("0")) {
productInfoEntity.setSfwblztlcp("否");
}
if (StrUtil.trimToEmpty(productInfoEntity.getCgzmraqxgxx()).equals("0")) {
productInfoEntity.setCgzmraqxgxx("安全");
} else if (StrUtil.trimToEmpty(productInfoEntity.getCgzmraqxgxx()).equals("1")) {
productInfoEntity.setCgzmraqxgxx("条件安全");
} else if (StrUtil.trimToEmpty(productInfoEntity.getCgzmraqxgxx()).equals("2")) {
productInfoEntity.setCgzmraqxgxx("说明书或标签上面不包括 MR 安全信息");
}
if (StrUtil.trimToEmpty(productInfoEntity.getSfwwjbz()).equals("1")) {
productInfoEntity.setSfwwjbz("是");
} else if (StrUtil.trimToEmpty(productInfoEntity.getSfwwjbz()).equals("0")) {
productInfoEntity.setSfwwjbz("否");
}
if (StrUtil.trimToEmpty(productInfoEntity.getSyqsfxyjxmj()).equals("1")) {
productInfoEntity.setSyqsfxyjxmj("是");
} else if (StrUtil.trimToEmpty(productInfoEntity.getSyqsfxyjxmj()).equals("0")) {
productInfoEntity.setSyqsfxyjxmj("否");
}
ProductClassify productClassifyEntity = productClassifyService.findByCode(productInfoEntity.getFlbm(), productInfoEntity.getCplx());
productInfoEntity.setCategoryName(productClassifyEntity.getName());
productInfoEntity.setVersionNumber(Integer.parseInt(deviceEntity.getVersionnumber()));
if (deviceEntity.getSydycpbs() != null && !deviceEntity.getSydycpbs().equals("")) {
productInfoEntity.setBhxjcpbm("");
productInfoEntity.setBhxjsl(0);
productInfoEntity.setBzcj("");
productInfoEntity.setBhzxxsbzsl(0);
productInfoEntity.setPackLevel(1 + "");
productInfoEntity.setAddType(1 + "");
productInfoEntity.setZxxsbzbhsydysl(0);
productInfoEntity.setDiType(2);
productInfoEntity.setNameCode(deviceEntity.getSydycpbs());
productInfoEntity.setSjcpbm(deviceEntity.getZxxsdycpbs());
productInfoEntity.setUpdateTime(new Date());
productInfoService.insertProductInfo(productInfoEntity);
productInfoEntity.setBhxjcpbm(deviceEntity.getSydycpbs());
productInfoEntity.setBhxjsl(1);
productInfoEntity.setPackLevel(2 + "");
productInfoEntity.setZxxsbzbhsydysl(1);
} else if (deviceEntity.getBtcpbs() != null && !deviceEntity.getBtcpbs().equals("")) {
productInfoEntity.setBhxjcpbm("");
productInfoEntity.setBhxjsl(0);
productInfoEntity.setBzcj("");
productInfoEntity.setBhzxxsbzsl(0);
productInfoEntity.setPackLevel(1 + "");
productInfoEntity.setAddType(1 + "");
productInfoEntity.setZxxsbzbhsydysl(0);
productInfoEntity.setDiType(3);
productInfoEntity.setSjcpbm(deviceEntity.getZxxsdycpbs());
productInfoEntity.setNameCode(deviceEntity.getBtcpbs());
productInfoEntity.setUpdateTime(new Date());
productInfoService.insertProductInfo(productInfoEntity);
productInfoEntity.setBhxjcpbm(deviceEntity.getBtcpbs());
productInfoEntity.setBhxjsl(1);
productInfoEntity.setPackLevel(2 + "");
productInfoEntity.setZxxsbzbhsydysl(1);
}
productInfoEntity.setDiType(1);
productInfoEntity.setBzcj("");
productInfoEntity.setAddType(1 + "");
productInfoEntity.setNameCode(deviceEntity.getZxxsdycpbs());
if (deviceEntity.getZxxsdyzsydydsl() != null && !deviceEntity.getZxxsdyzsydydsl().equals("") && Integer.parseInt(deviceEntity.getZxxsdyzsydydsl()) > 1) {
productInfoEntity.setZxxsbzbhsydysl(Integer.parseInt(deviceEntity.getZxxsdyzsydydsl()));
productInfoEntity.setBhxjsl(Integer.parseInt(deviceEntity.getZxxsdyzsydydsl()));
}
List<Devicepackage> devicepackages = deviceEntity.getDevicepackages();
productInfoEntity.setSjcpbm(getSjcpbm(devicepackages, productInfoEntity.getNameCode()));
productInfoEntity.setUpdateTime(new Date());
productInfoService.insertProductInfo(productInfoEntity);
List<CountProductEntity> countProductEntities = new ArrayList<>();
int curLevel = Integer.parseInt(productInfoEntity.getPackLevel()) + 1;
if (devicepackages != null && devicepackages.size() > 0) {
HashMap<String, String> packRation = new HashMap<>();
for (Devicepackage devicepackage : devicepackages) {
CountProductEntity countProductEntity = new CountProductEntity();
Devicepackage head = devicepackage;
//包装层级初始为2最小销售单元为1
int level = curLevel;
int zxbsCount = devicepackage.getBznhxyjcpbssl(); //最小销售单元数量
int count = 1; //计数,如果计数超过包装标识层级,就是死循环,包装标识有误
while (!head.getBznhxyjbzcpbs().equals(deviceEntity.getZxxsdycpbs())) {
head = getNext(devicepackages, head);
if (head == null) {
break;
}
count++;
if (count > devicepackages.size()) {
break;
}
level++;
zxbsCount = zxbsCount * head.getBznhxyjcpbssl();
}
packRation.put(level - 1 + "", devicepackage.getBznhxyjcpbssl() + "");
countProductEntity.setLevel(level);
countProductEntity.setZxbsCount(zxbsCount);
countProductEntities.add(countProductEntity);
}
CountProductEntity max = getMaxLevel(countProductEntities);
packRation.put(max.getLevel() + "", max.getZxbsCount() + "");
for (int i = 0; i < devicepackages.size(); i++) {
Devicepackage devicepackage = devicepackages.get(i);
CountProductEntity countProductEntity = countProductEntities.get(i);
productInfoEntity.setNameCode(devicepackage.getBzcpbs());
productInfoEntity.setBhxjcpbm(devicepackage.getBznhxyjbzcpbs());
productInfoEntity.setBhxjsl(devicepackage.getBznhxyjcpbssl());
productInfoEntity.setBzcj(devicepackage.getCpbzjb());
productInfoEntity.setBhzxxsbzsl(countProductEntity.getZxbsCount());
productInfoEntity.setPackLevel(countProductEntity.getLevel() + "");
productInfoEntity.setSjcpbm(getSjcpbm(devicepackages, productInfoEntity.getNameCode()));
productInfoEntity.setDiType(4);
productInfoEntity.setUpdateTime(new Date());
productInfoEntity.setIsNewest(true);
productInfoService.insertProductInfo(productInfoEntity);
}
}
// //更新为最新版本
ProductInfoFilterRequest filterRequest1 = new ProductInfoFilterRequest();
filterRequest1.setNameCode(di);
List<ProductInfoEntity> updateEntitys = productInfoService.filterUdi(filterRequest1);
if (updateEntitys != null && updateEntitys.size() > 0) {
ProductInfoFilterRequest filterRequest = new ProductInfoFilterRequest();
filterRequest.setDeviceRecordKey(productInfoEntity.getDeviceRecordKey());
List<ProductInfoEntity> temps = productInfoService.filterProductInfo(filterRequest);
if (CollUtil.isNotEmpty(temps)) {
for (ProductInfoEntity change : temps) {
change.setIsNewest(false);
change.setUpdateTime(new Date());
}
for (ProductInfoEntity change : temps) {
if (productInfoEntity.getUuid().equals(change.getUuid())) {
change.setIsNewest(true);
change.setUpdateTime(new Date());
}
productInfoService.updateProductInfo(change);
}
}
}
//更新厂家信息,
UdiCompanyRequest udiCompanyRequest = new UdiCompanyRequest();
udiCompanyRequest.setTyshxydm(productInfoEntity.getTyshxydm());
if (StrUtil.isNotEmpty(udiCompanyRequest.getTyshxydm())) {
List<UdiCompanyEntity> udiCompanyEntitys = udiCompanyService.filterUdiCompany(udiCompanyRequest);
if (udiCompanyEntitys == null || udiCompanyEntitys.size() == 0) {
UdiCompanyEntity udiCompanyEntity = new UdiCompanyEntity();
udiCompanyEntity.setTyshxydm(productInfoEntity.getTyshxydm());
udiCompanyEntity.setUpdateTime(new Date());
udiCompanyEntity.setYlqxzcrbarywmc(productInfoEntity.getYlqxzcrbarywmc());
udiCompanyEntity.setYlqxzcrbarmc(productInfoEntity.getYlqxzcrbarmc());
List<Contactlist> contactlists = udiCompanyService.selectContactBykey(productInfoEntity.getDeviceRecordKey());
if (contactlists != null && contactlists.size() > 0) {
udiCompanyEntity.setQylxrcz(contactlists.get(0).getQylxrcz());
udiCompanyEntity.setQylxrdh(contactlists.get(0).getQylxrdh());
udiCompanyEntity.setQylxryx(contactlists.get(0).getQylxryx());
}
udiCompanyEntity.setUpdateTime(new Date());
udiCompanyService.insertUdiCompany(udiCompanyEntity);
}
}
}
public void updateUdi(DeviceService deviceService, ProductInfoService productInfoService, String key) {
DeviceEntity deviceEntity = deviceService.searchById(key);
ProductInfoEntity productInfoEntity = new ProductInfoEntity();
BeanUtils.copyProperties(deviceEntity, productInfoEntity);
productInfoEntity.setUuid(key);
productInfoEntity.setScbssfbhph(deviceEntity.getScbssfbhph());
productInfoEntity.setScbssfbhscrq(deviceEntity.getScbssfbhscrq());
productInfoEntity.setScbssfbhsxrq(deviceEntity.getScbssfbhsxrq());
productInfoEntity.setScbssfbhxlh(deviceEntity.getScbssfbhxlh());
productInfoEntity.setYbbm(deviceEntity.getYbbm());
productInfoEntity.setSpmc(deviceEntity.getSpmc());
productInfoEntity.setCphhhbh(deviceEntity.getCphhhbh());
productInfoEntity.setCpms(deviceEntity.getCpms());
productInfoEntity.setCpbsbmtxmc(deviceEntity.getCpbsbmtxmc());
productInfoEntity.setUpdateTime(new Date());
productInfoService.updateProductByUuid(productInfoEntity);
}
public Devicepackage getNext(List<Devicepackage> devicepackages, Devicepackage devicepackage) {
if (devicepackages != null && devicepackages.size() > 0) {
for (int i = 0; i < devicepackages.size(); i++) {
Devicepackage temp = devicepackages.get(i);
if (temp.getBzcpbs().equals(devicepackage.getBznhxyjbzcpbs())) {
return temp;
}
}
}
return null;
}
public CountProductEntity getMaxLevel(List<CountProductEntity> countProductEntities) {
int index = 0;
int max = 0;
for (int i = 0; i < countProductEntities.size(); i++) {
CountProductEntity countProductEntity = countProductEntities.get(i);
if (countProductEntity.getZxbsCount() > max) {
max = countProductEntity.getZxbsCount();
index = i;
}
}
return countProductEntities.get(index);
}
public String getSjcpbm(List<Devicepackage> devicepackages, String nameCode) {
String sjcpbs = "";
if (devicepackages != null && devicepackages.size() > 0) {
for (Devicepackage devicepackage : devicepackages) {
if (devicepackage.getBznhxyjbzcpbs() != null && devicepackage.getBznhxyjbzcpbs().equals(nameCode)) {
sjcpbs = sjcpbs + "," + devicepackage.getBzcpbs();
}
}
}
if (sjcpbs.length() > 1)
return sjcpbs.substring(1);
return sjcpbs;
}
}