工艺路线接口优化_V1

This commit is contained in:
李正@用友 2025-05-08 15:43:09 +08:00
parent bc870473e2
commit 0d16cd4860
1 changed files with 565 additions and 459 deletions

View File

@ -1,17 +1,15 @@
package nccloud.openapi.mmbd.routing;
import com.alibaba.fastjson.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import nc.bs.dao.BaseDAO;
import nc.bs.dao.DAOException;
import nc.bs.framework.common.InvocationInfoProxy;
import nc.bs.framework.common.NCLocator;
import nc.itf.bd.rt.rt0008.IRtQuery;
@ -26,11 +24,14 @@ import nc.vo.bd.rt.rt0008.entity.RtHeadVO;
import nc.vo.bd.rt.rt0008.entity.RtItemVO;
import nc.vo.bd.rt.rt0008.entity.RtOpacVO;
import nc.vo.pub.BusinessException;
import nc.vo.pub.CircularlyAccessibleValueObject;
import nc.vo.pub.ISuperVO;
import nc.vo.pubapp.pattern.exception.ExceptionUtils;
import nc.vo.pubapp.pattern.pub.SqlBuilder;
import nc.ws.opm.pub.utils.result.APIErrCodeEnum;
import nccloud.api.mmbd.routing.IAPIRoutingBusinessService;
import nccloud.api.rest.utils.ResultMessageUtil;
import nccloud.pubitf.mapub.costtype.IOrgQueryService;
import nccloud.ws.rest.resource.AbstractNCCRestResource;
import org.json.JSONString;
@ -58,9 +59,10 @@ public class RoutingResource extends AbstractNCCRestResource {
@POST
@Path("operation/save")
@Consumes({ "application/json" })
@Produces({ "application/json" })
@Consumes({"application/json"})
@Produces({"application/json"})
public JSONString saveRouting(JSONObject para) {
try {
List<Map<String, Object>> paramList = (List) para.get("data");
AggRtVO[] retVos = null;
for (Map<String, Object> map : paramList) {
@ -77,7 +79,7 @@ public class RoutingResource extends AbstractNCCRestResource {
AggRtVO[] aggVos = (AggRtVO[]) getAggRtVO(paramList).get(AGG);
IAPIRoutingBusinessService service = (IAPIRoutingBusinessService) NCLocator.getInstance()
.lookup(IAPIRoutingBusinessService.class);
try {
retVos = service.save(aggVos);
return ResultMessageUtil.toJSON(retVos, "工艺路线保存成功");
} catch (BusinessException e) {
@ -87,10 +89,11 @@ public class RoutingResource extends AbstractNCCRestResource {
@POST
@Path("save")
@Consumes({ "application/json" })
@Produces({ "application/json" })
@Consumes({"application/json"})
@Produces({"application/json"})
public JSONString saveRouting(List<Map<String, Object>> paramList) {
AggRtVO[] retVos = null;
try {
for (Map<String, Object> map : paramList) {
if (!map.containsKey(PD_RT_B) || !map.containsKey(PD_RT)) {
return ResultMessageUtil.exceptionToJSON("传入数据异常,参数要包含表头信息和表体信息",
@ -105,7 +108,7 @@ public class RoutingResource extends AbstractNCCRestResource {
AggRtVO[] aggVos = (AggRtVO[]) getAggRtVO(paramList).get(AGG);
IAPIRoutingBusinessService service = (IAPIRoutingBusinessService) NCLocator.getInstance()
.lookup(IAPIRoutingBusinessService.class);
try {
retVos = service.save(aggVos);
return ResultMessageUtil.toJSON(retVos, "工艺路线保存成功");
} catch (BusinessException e) {
@ -115,9 +118,10 @@ public class RoutingResource extends AbstractNCCRestResource {
@POST
@Path("operation/update")
@Consumes({ "application/json" })
@Produces({ "application/json" })
@Consumes({"application/json"})
@Produces({"application/json"})
public JSONString updateRouting(JSONObject para) {
try {
List<Map<String, Object>> paramList = (List) para.get("data");
AggRtVO[] retVos = null;
for (Map<String, Object> map : paramList) {
@ -134,7 +138,7 @@ public class RoutingResource extends AbstractNCCRestResource {
AggRtVO[] aggVos = (AggRtVO[]) getAggRtVO(paramList).get(AGG);
IAPIRoutingBusinessService service = (IAPIRoutingBusinessService) NCLocator.getInstance()
.lookup(IAPIRoutingBusinessService.class);
try {
retVos = service.update(aggVos);
return ResultMessageUtil.toJSON(retVos, "工艺路线修改成功");
} catch (BusinessException e) {
@ -144,9 +148,10 @@ public class RoutingResource extends AbstractNCCRestResource {
@POST
@Path("update")
@Consumes({ "application/json" })
@Produces({ "application/json" })
@Consumes({"application/json"})
@Produces({"application/json"})
public JSONString updateRouting(List<Map<String, Object>> paramList) {
try {
AggRtVO[] retVos = null;
for (Map<String, Object> map : paramList) {
if (!map.containsKey(PD_RT_B) || !map.containsKey(PD_RT_ASSORG)) {
@ -162,7 +167,7 @@ public class RoutingResource extends AbstractNCCRestResource {
AggRtVO[] aggVos = (AggRtVO[]) getAggRtVO(paramList).get(AGG);
IAPIRoutingBusinessService service = (IAPIRoutingBusinessService) NCLocator.getInstance()
.lookup(IAPIRoutingBusinessService.class);
try {
retVos = service.update(aggVos);
return ResultMessageUtil.toJSON(retVos, "工艺路线修改成功");
} catch (BusinessException e) {
@ -172,8 +177,8 @@ public class RoutingResource extends AbstractNCCRestResource {
@POST
@Path("query")
@Consumes({ "application/json" })
@Produces({ "application/json" })
@Consumes({"application/json"})
@Produces({"application/json"})
public JSONString queryRouting(Map<String, Object> paramMap) {
AggRtVO[] retVos = null;
IAPIRoutingBusinessService service = (IAPIRoutingBusinessService) NCLocator.getInstance()
@ -204,7 +209,7 @@ public class RoutingResource extends AbstractNCCRestResource {
return hvos;
}
private Map<String, Object> getAggRtVO(List<Map<String, Object>> paramList) {
private Map<String, Object> getAggRtVO(List<Map<String, Object>> paramList) throws BusinessException {
List<AggRtVO> aggVoList = new ArrayList<AggRtVO>();
Map<String, AggRtVO> pkmap = new HashMap<String, AggRtVO>();
List<String> pklist = new ArrayList<String>();
@ -462,7 +467,10 @@ public class RoutingResource extends AbstractNCCRestResource {
markword = "您有必输项未输," + exceptionMessage;
}
}
//2025年5月8日13点41分--重新翻译工序 --start
Map<String, Set<String>> queryParamList = getQueryParamList(aggVos);
reTranslateCrcIdByCode(aggVos, queryParamList);
//2025年5月8日13点41分--重新翻译工序 --end
BillFieldsCodeToPkUtil.doTranslateVOFields(aggVos);
Map<String, Object> map = new HashMap<String, Object>();
map.put(AGG, aggVos);
@ -470,6 +478,104 @@ public class RoutingResource extends AbstractNCCRestResource {
return map;
}
private void reTranslateCrcIdByCode(AggRtVO[] aggVos, Map<String, Set<String>> queryParamMap) throws BusinessException {
//根据map里的参数查询出对应的ID,判空,
Set<String> bpkorgs = queryParamMap.get("bpkorg");
Set<String> hpkorgs = queryParamMap.get("hpkorg");
Set<String> crcids = queryParamMap.get("crcid");
if (isNotNull(bpkorgs) && isNotNull(crcids)) {
List<Map<String, Object>> maps = queryIDAndCode(bpkorgs, crcids);
Map<String, String> key_crcMap = new HashMap<>();
for (Map<String, Object> map : maps) {
String crcid = (String) map.getOrDefault("crcid", "");
String vrccode = (String) map.getOrDefault("vrccode", "");
String orgcode = (String) map.getOrDefault("orgcode", "");
key_crcMap.put(orgcode + "_" + vrccode, crcid);
}
for (AggRtVO aggVo : aggVos) {
RtItemVO[] itemVos = (RtItemVO[]) aggVo.getChildren(RtItemVO.class);
for (RtItemVO itemVo : itemVos) {
String crcid = itemVo.getCrcid();
String orgcode = itemVo.getPk_org();
String crcid_new = key_crcMap.get(orgcode + "_" + crcid);
if (crcid_new != null) {
itemVo.setCrcid(crcid_new);
}
}
}
} else if (!isNotNull(bpkorgs) && isNotNull(crcids) && isNotNull(hpkorgs)) {
//保险
List<Map<String, Object>> maps = queryIDAndCode(hpkorgs, crcids);
Map<String, String> key_crcMap = new HashMap<>();
for (Map<String, Object> map : maps) {
String crcid = (String) map.getOrDefault("crcid", "");
String vrccode = (String) map.getOrDefault("vrccode", "");
String orgcode = (String) map.getOrDefault("orgcode", "");
key_crcMap.put(orgcode + "_" + vrccode, crcid);
}
for (AggRtVO aggVo : aggVos) {
RtHeadVO parentVO = (RtHeadVO) aggVo.getParent();
RtItemVO[] itemVos = (RtItemVO[]) aggVo.getChildren(RtItemVO.class);
String orgcode = parentVO.getPk_org();
for (RtItemVO itemVo : itemVos) {
String crcid = itemVo.getCrcid();
String crcid_new = key_crcMap.get(orgcode + "_" + crcid);
if (crcid_new != null) {
itemVo.setCrcid(crcid_new);
}
}
}
}
}
private List<Map<String, Object>> queryIDAndCode(Set<String> bpkorgs, Set<String> crcids) throws BusinessException {
SqlBuilder sql = new SqlBuilder();
sql.append(" SELECT rc.crcid,rc.vrccode,orgs.code orgcode FROM pd_rc rc ");
sql.append(" LEFT JOIN org_orgs orgs ON rc.PK_ORG =orgs.PK_ORG ");
sql.append(" WHERE ");
sql.append(" rc.dr=0 and orgs.dr=0 and ");
sql.append(" rc.vrccode ", crcids.toArray(new String[0]));
sql.append(" AND ");
sql.append(" orgs.CODE ", bpkorgs.toArray(new String[0]));
List<Map<String, Object>> remain = (List<Map<String, Object>>) new BaseDAO().executeQuery(sql.toString(), new nc.jdbc.framework.processor.MapListProcessor());
if (remain == null || remain.size() < 1) {
throw new BusinessException("工序查询为空sql【" + sql.toString() + "");
}
return remain;
}
private boolean isNotNull(Set<String> set) {
return set == null || set.size() < 1 ? false : true;
}
public Map<String, Set<String>> getQueryParamList(AggRtVO[] aggVos) {
Map<String, Set<String>> queryParamMap = new HashMap<>();
Set<String> bOrgList = new HashSet<>();
Set<String> hOrgList = new HashSet<>();
Set<String> crcIdList = new HashSet<>();
for (AggRtVO aggVo : aggVos) {
RtHeadVO hvo = (RtHeadVO) aggVo.getParentVO();
hOrgList.add(hvo.getPk_org());
RtItemVO[] itemVos = (RtItemVO[]) aggVo.getChildren(RtItemVO.class);
if (MMValueCheck.isNotEmpty(itemVos)) {
for (RtItemVO itemVo : itemVos) {
String pkOrg = itemVo.getPk_org();
String crcId = itemVo.getCrcid();
if (pkOrg != null) {
bOrgList.add(pkOrg);
}
if (crcId != null) {
crcIdList.add(crcId);
}
}
}
}
queryParamMap.put("bpkorg", bOrgList);
queryParamMap.put("hpkorg", hOrgList);
queryParamMap.put("crcid", crcIdList);
return queryParamMap;
}
private String getHeadInputField(RtHeadVO[] hvos) {
String retstr = "";
for (RtHeadVO hvo : hvos) {