You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

404 lines
18 KiB

package com.spring.ifs.bean;
import com.alibaba.fastjson.JSON;
import com.spring.ifs.api.IfsServer;
import com.spring.ifs.api.TechnicalClassApi;
import com.spring.modules.part.entity.APIEntity.PartIfsCatalogModel;
import com.spring.modules.part.entity.APIEntity.PartIfsCatalogProperty;
import ifs.fnd.ap.APException;
import ifs.fnd.ap.Server;
import org.apache.poi.ss.formula.functions.T;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @description: 技术等级实现类
* @author LR
* @date 2024/12/9 11:49
* @version 1.0
*/
@Component
public class TechnicalClassBean {
@Autowired
private IfsServer ifsServer;
private static final Logger logger = LoggerFactory.getLogger(TechnicalClassBean.class);
/**
* @description: 查询技术等级
* @author LR
* @date 2024/12/16 13:15
* @version 1.0
*/
public Map<String, String> getTechnicalClass(Server srv, PartIfsCatalogModel inData) {
logger.info("Technical Class 查询开始:"+ JSON.toJSONString(inData));
//公共参数
Map<String, String> returnMap = new HashMap<>();
String luName = inData.getLuName(); //
String keyRef = inData.getKeyRef(); //
try{
//查询对象
Map<String, String> resultMap = TechnicalClassApi.getTechnicalClass(srv, luName, keyRef);
//判断查询导数据
if(resultMap == null) {
throw new APException("查无此技术等级的信息!");
}
//设置ifs 信息
inData.setIfsRowId(resultMap.get("IFSROWID"));
inData.setIfsRowVersion(resultMap.get("IFSROWVERSION"));
returnMap.put("resultCode", "200");
returnMap.put("obj", JSON.toJSONString(inData));
} catch(APException e){
returnMap.put("resultCode", "400");
returnMap.put("resultMsg", e.getMessage());
logger.info("异常信息:"+e.getMessage());
}
//打印日志
logger.info("Technical Class 查询结束:"+JSON.toJSONString(inData));
//返回结果集
return returnMap;
}
/**
* @description: 新增
* @author LR
* @date 2024/12/16 13:37
* @version 1.0
*/
public Map<String, String> syncTechnicalClass(Server srv, PartIfsCatalogModel inData) {
logger.info("Technical Class 新增开始:"+JSON.toJSONString(inData));
//公共参数
Map<String, String> returnMap = new HashMap<>();
try{
//调用api同步信息
Map<String, String> resultMap = TechnicalClassApi.insertTechnicalClass(srv, inData);
//设置唯一键和版本
inData.setIfsRowVersion(resultMap.get("OBJVERSION"));
returnMap.put("resultCode", "200");
returnMap.put("obj", JSON.toJSONString(inData));
} catch(APException e){
returnMap.put("resultCode", "400");
returnMap.put("resultMsg", e.getMessage());
logger.info("异常信息:"+e.getMessage());
}
//插入查询的记录数据
logger.info("Technical Class 新增结束:"+JSON.toJSONString(inData));
//返回结果集
return returnMap;
}
/**
* @description: 修改技术等级的数据
* @author LR
* @date 2024/12/16 13:45
* @version 1.0
*/
public Map<String, String> modifyTechnicalClass(Server srv, PartIfsCatalogModel inData) {
logger.info("Technical Class 修改开始:"+JSON.toJSONString(inData));
//公共参数
Map<String, String> returnMap = new HashMap<>();
String luName = inData.getLuName(); //
String keyRef = inData.getKeyRef();
try{
//查询对象
Map<String, String> technicalMap = TechnicalClassApi.getTechnicalClass(srv, luName, keyRef);
//判断查询导数据
if(technicalMap == null || technicalMap.isEmpty()) {
throw new APException("不存在此技术等级的信息!");
}
//设置IFS的信息
inData.setIfsRowId(technicalMap.get("IFSROWID"));
inData.setIfsRowVersion(technicalMap.get("IFSROWVERSION"));
//调用api同步信息
Map<String, String> resultMap = TechnicalClassApi.modifyTechnicalClass(srv, inData);
//设置唯一键和版本
inData.setIfsRowVersion(resultMap.get("OBJVERSION"));
returnMap.put("resultCode", "200");
returnMap.put("obj", JSON.toJSONString(inData));
} catch(APException e){
returnMap.put("resultCode", "400");
returnMap.put("resultMsg", e.getMessage());
logger.info("异常信息:"+e.getMessage());
}
//插入查询的记录数据
logger.info("Technical Class 修改结束:"+JSON.toJSONString(inData));
//返回结果集
return returnMap;
}
/**
* @description: 刪除技术等级的信息
* @author LR
* @date 2024/12/16 13:46
* @version 1.0
*/
public Map<String, String> removeTechnicalClass(Server srv, PartIfsCatalogModel inData) {
logger.info("Technical Class 删除开始:"+JSON.toJSONString(inData));
//公共参数
Map<String, String> returnMap = new HashMap<>();
String luName = inData.getLuName(); //
String keyRef = inData.getKeyRef(); //
try{
//查询对象
Map<String, String> technicalMap = TechnicalClassApi.getTechnicalClass(srv, luName, keyRef);
//判断查询导数据
if(technicalMap == null || technicalMap.isEmpty()) {
throw new APException("不存在此技术等级的信息!");
}
//设置IFS的信息
inData.setIfsRowId(technicalMap.get("IFSROWID"));
inData.setIfsRowVersion(technicalMap.get("IFSROWVERSION"));
//调用api同步信息
TechnicalClassApi.removeTechnicalClass(srv, inData);
returnMap.put("resultCode", "200");
returnMap.put("obj", JSON.toJSONString(inData));
} catch(APException e){
returnMap.put("resultCode", "400");
returnMap.put("resultMsg", e.getMessage());
logger.info("异常信息:"+e.getMessage());
}
//插入查询的记录数据
logger.info("Technical Class 删除结束:"+JSON.toJSONString(inData));
//返回结果集
return returnMap;
}
/**
* @description: 批量同步技术等级属性数据
* @author LR
* @date 2024/12/19 15:02
* @version 1.0
*/
public Map<String, String> modifyTechnicalClassAttributes(Server srv, List<PartIfsCatalogProperty> inDatas) {
logger.info("Technical Class Attributes 批量修改开始:"+JSON.toJSONString(inDatas));
Map<String, String> returnMap = new HashMap<>();
PartIfsCatalogProperty inData = inDatas.get(0);
// 公共参数
String luName = inData.getLuName(); //
String keyRef = inData.getKeyRef(); //
try{
//查询技术等级
Map<String, String> technicalMap = TechnicalClassApi.getTechnicalClass(srv, luName, keyRef);
//判断查询导数据
//判断查询导数据
if(technicalMap == null || technicalMap.isEmpty()) {
throw new APException("不存在此技术等级的信息!");
}
//设置唯一键和版本
String technicalSpecNo = technicalMap.get("TECHNICAL_SPEC_NO");
String technicalClass = inData.getTechnicalClass();
//打印日志
//查询当前技术等级下的所有属性的数据
List<Map<String, String>> resultList = TechnicalClassApi.getTechnicalAttributesMap(srv, technicalSpecNo, technicalClass);
//调用方法 获取需要修改的数据
List<PartIfsCatalogProperty> paramList = this.getAndCheckNeedUpdateList(resultList, inDatas);
//打印日志
logger.info("Technical Class Attributes 最终批量修改:"+JSON.toJSONString(paramList));
logger.info("Technical Class Attributes 最终批量数量:"+JSON.toJSONString(paramList.size()));
//循环设置参数
for(PartIfsCatalogProperty tempData : paramList) {
//设置替代的ifs的key
tempData.setTechnicalSpecNo(technicalSpecNo);
logger.info("属性编码:"+tempData.getAttribute());
//api修改参数
Map<String, String> resultMap = TechnicalClassApi.modifyTechnicalAttribute(srv, tempData);
//设置记录的版本
tempData.setIfsRowVersion(resultMap.get("OBJVERSION"));
}
returnMap.put("resultCode", "200");
returnMap.put("obj", JSON.toJSONString(inDatas));
} catch(APException e){
returnMap.put("resultCode", "400");
returnMap.put("resultMsg", e.getMessage());
logger.info("异常信息:"+e.getMessage());
}
//插入查询的记录数据
logger.info("Technical Class Attributes 批量修改结束:"+JSON.toJSONString(inDatas));
//返回结果集
return returnMap;
}
/**
* @description: 获取需要修改的数据 不需要修改的数据不再放入循环操作中
* @author LR
* @date 2025/4/28 09:45
* @version 1.0
*/
public List<PartIfsCatalogProperty> getAndCheckNeedUpdateList(List<Map<String, String>> resultList, List<PartIfsCatalogProperty> inDatas) {
//数据转Map 键为属性名称
Map<String, PartIfsCatalogProperty> newMap = new HashMap<>();
List<PartIfsCatalogProperty> updateList = new ArrayList<>();
//循环转换
for(PartIfsCatalogProperty bean : inDatas) {
newMap.put(bean.getAttribute(), bean);
}
//循环比较数据是否一直
for (Map<String, String> resultMap : resultList){
String attribute = resultMap.get("ATTRIBUTE"); // 属性编码
String attributeType = resultMap.get("ATTRIBUTETYPE"); // 属性类型
String valueText = resultMap.get("VALUE_TEXT"); // 文本值
String valueNo = resultMap.get("VALUE_NO"); // 数字值
//接口路传过来的新值
if (!newMap.containsKey(attribute)){
continue;
}
PartIfsCatalogProperty tempBean = newMap.get(attribute);
//针对文本和数据使用不同的比较方式
if(attributeType.equals("Alpha")) {
String newValueText = tempBean.getValueText();
//如果都是空字符串 或者都是null 跳过修改
if ((null == newValueText || "NULL".equalsIgnoreCase(newValueText) || newValueText.trim().isEmpty())
&& (null == valueText || "NULL".equalsIgnoreCase(valueText) || valueText.trim().isEmpty())){
continue;
}else if (newValueText.equals(valueText)){
continue;
}
} else if (attributeType.equals("Numeric")) {
String newValueNo = tempBean.getValueNo();
//如果都是空字符串 或者都是null 跳过修改
if ((null == newValueNo || "NULL".equalsIgnoreCase(newValueNo) || newValueNo.trim().isEmpty())
&& (null == valueNo || "NULL".equalsIgnoreCase(valueNo) || valueNo.trim().isEmpty())){
continue;
}else if (!newValueNo.equals(valueNo)){
if ((newValueNo != null && "".equals(newValueNo.trim())) || (valueNo != null && "".equals(valueNo.trim()))){
//添加ifsRowId ifsRowVersion
logger.info("可以放到修改中: 原始值:"+valueNo+",新值:"+newValueNo);
}else {
//判断是否是相同大小的数字
BigDecimal oriValue = new BigDecimal(valueNo);
oriValue = oriValue.setScale(6, BigDecimal.ROUND_HALF_UP);
logger.info("原始值:"+oriValue+",新值:"+newValueNo);
BigDecimal newValue = new BigDecimal(newValueNo);
if(oriValue.compareTo(newValue) == 0) {
continue;
}
}
}
}
//添加ifsRowId ifsRowVersion
String ifsRowId = resultMap.get("IFSROWID");
String ifsRowVersion = resultMap.get("IFSROWVERSION");
tempBean.setIfsRowId(ifsRowId);
tempBean.setIfsRowVersion(ifsRowVersion);
updateList.add(tempBean);
}
//返回需要处理的数据
return updateList;
}
/**
* @description: 批量删除技术等级属性数据
* @author LR
* @date 2024/12/19 15:02
* @version 1.0
*/
public Map<String, String> removeTechnicalClassAttributes(Server srv, List<PartIfsCatalogProperty> inDatas) {
logger.info("Technical Class Attributes 批量删除开始:"+JSON.toJSONString(inDatas));
Map<String, String> returnMap = new HashMap<>();
PartIfsCatalogProperty inData = inDatas.get(0);
// 公共参数
String luName = inData.getLuName(); //
String keyRef = inData.getKeyRef(); //
try{
//查询技术等级
Map<String, String> technicalMap = TechnicalClassApi.getTechnicalClass(srv, luName, keyRef);
logger.info("技术等级查询");
//判断查询导数据
if(technicalMap == null || technicalMap.isEmpty()) {
throw new APException("不存在此技术等级的信息!");
}
//设置唯一键和版本
String technicalSpecNo = technicalMap.get("TECHNICAL_SPEC_NO");
String technicalClass = inData.getTechnicalClass();
//循环设置参数
for(PartIfsCatalogProperty tempData : inDatas) {
String attribute = tempData.getAttribute();
//查询属性信息
Map<String, String> attributeMap = TechnicalClassApi.getTechnicalAttribute(srv, technicalSpecNo, technicalClass, attribute);
if(attributeMap == null || attributeMap.isEmpty()) {
throw new APException("不存在此技术等级的属性信息!");
}
logger.info("技术等级属性查询");
//设置替代的ifs的key
tempData.setIfsRowId(attributeMap.get("IFSROWID"));
tempData.setIfsRowVersion(attributeMap.get("IFSROWVERSION"));
tempData.setAttributeType(attributeMap.get("ATTRIBUTETYPE"));
tempData.setTechnicalSpecNo(technicalSpecNo);
logger.info("技术等级属性删除开始");
//api修改参数
TechnicalClassApi.removeTechnicalAttribute(srv, tempData);
logger.info("技术等级属性删除结束");
}
returnMap.put("resultCode", "200");
returnMap.put("obj", JSON.toJSONString(inDatas));
} catch(APException e){
returnMap.put("resultCode", "400");
returnMap.put("resultMsg", e.getMessage());
logger.info("异常信息:"+e.getMessage());
}
//插入查询的记录数据
logger.info("Technical Class Attributes 批量删除结束:"+JSON.toJSONString(inDatas));
//返回结果集
return returnMap;
}
/**
* @description: 批量删除技术等级的集合数据
* @author DouDou
* @date 2025/9/10 13:28
* @version 1.0
*/
public Map<String, String> removeTechnicalClassAttributesByTechnicalClass(Server srv, PartIfsCatalogModel inData) {
logger.info("Technical Class Attributes 批量删除开始:"+JSON.toJSONString(inData));
Map<String, String> returnMap = new HashMap<>();
// 公共参数
String luName = inData.getLuName(); //
String keyRef = inData.getKeyRef(); //
try{
//查询技术等级
Map<String, String> technicalMap = TechnicalClassApi.getTechnicalClass(srv, luName, keyRef);
//判断查询导数据
if(technicalMap == null || technicalMap.isEmpty()) {
throw new APException("不存在此技术等级的信息!");
}
//设置唯一键和版本
String technicalSpecNo = technicalMap.get("TECHNICAL_SPEC_NO");
String technicalClass = technicalMap.get("TECHNICAL_CLASS");
logger.info("技术等级模版信息:"+JSON.toJSONString(technicalMap));
//查询属性集合批量删除
List<PartIfsCatalogProperty> resultList = TechnicalClassApi.getTechnicalAttributeList(srv, technicalSpecNo, technicalClass);
logger.info("技术等级属性集合信息:"+JSON.toJSONString(resultList));
//循环删除 只删除有数据的对象 ---没有对象的数据 不处理
for(PartIfsCatalogProperty tempData : resultList) {
logger.info("技术等级属性删除开始:"+JSON.toJSONString(tempData));
//api修改参数
TechnicalClassApi.removeTechnicalAttribute(srv, tempData);
logger.info("技术等级属性删除结束:"+JSON.toJSONString(tempData));
}
returnMap.put("resultCode", "200");
returnMap.put("obj", JSON.toJSONString(resultList));
} catch(APException e){
returnMap.put("resultCode", "400");
returnMap.put("resultMsg", e.getMessage());
logger.info("异常信息:"+e.getMessage());
}
//插入查询的记录数据
logger.info("Technical Class Attributes 批量删除结束:"+JSON.toJSONString(inData));
//返回结果集
return returnMap;
}
}