Merge remote-tracking branch 'origin/main'
This commit is contained in:
commit
49c4b26cd3
|
@ -1,6 +1,6 @@
|
||||||
package nc.bs.mmpac.pmo.pac0002.bp;
|
package nc.bs.mmpac.pmo.pac0002.bp;
|
||||||
|
|
||||||
|
import nc.bs.mmpac.pmo.pac0002.bp.rule.AfterApproveRuleSyncMes;
|
||||||
import nc.bs.mmpac.pmo.pac0002.bp.rule.AfterApproveSyncEpicMesRule;
|
import nc.bs.mmpac.pmo.pac0002.bp.rule.AfterApproveSyncEpicMesRule;
|
||||||
import nc.bs.mmpac.pmo.pac0002.bp.rule.AfterApprovingSynchronizeRuleRZ;
|
import nc.bs.mmpac.pmo.pac0002.bp.rule.AfterApprovingSynchronizeRuleRZ;
|
||||||
import nc.bs.mmpac.pmo.pac0002.bp.rule.AfterUnApproveSyncEpicMesRule;
|
import nc.bs.mmpac.pmo.pac0002.bp.rule.AfterUnApproveSyncEpicMesRule;
|
||||||
|
@ -55,7 +55,7 @@ public class PMOApproveBP {
|
||||||
// 审批后推送到锐制系统
|
// 审批后推送到锐制系统
|
||||||
processer.addAfterRule(new AfterApprovingSynchronizeRuleRZ(true));
|
processer.addAfterRule(new AfterApprovingSynchronizeRuleRZ(true));
|
||||||
// 审批后推送流程生产订单到MES
|
// 审批后推送流程生产订单到MES
|
||||||
// processer.addAfterRule(new AfterApproveRuleSyncMes());
|
processer.addAfterRule(new AfterApproveRuleSyncMes());
|
||||||
// 审批后推送流程生产订单到艾普MES
|
// 审批后推送流程生产订单到艾普MES
|
||||||
processer.addAfterRule(new AfterApproveSyncEpicMesRule());
|
processer.addAfterRule(new AfterApproveSyncEpicMesRule());
|
||||||
|
|
||||||
|
|
|
@ -53,11 +53,15 @@ public class SyncEpicMesUtil {
|
||||||
auditCode = flag;
|
auditCode = flag;
|
||||||
configParams = MyHelper.getConfigParams("Dldz-config", null);
|
configParams = MyHelper.getConfigParams("Dldz-config", null);
|
||||||
if (configParams.isEmpty()) {
|
if (configParams.isEmpty()) {
|
||||||
throw new BusinessException("电力电子的艾普MES接口缺少配置");
|
// throw new BusinessException("电力电子的艾普MES接口缺少配置");
|
||||||
|
logDl.error("电力电子的艾普MES接口缺少配置");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
deptParams = MyHelper.getConfigParams("Dldz-dept", null);
|
deptParams = MyHelper.getConfigParams("Dldz-dept", null);
|
||||||
if (deptParams.isEmpty()) {
|
if (deptParams.isEmpty()) {
|
||||||
throw new BusinessException("电力电子的艾普MES接口缺少部门编码映射配置");
|
// throw new BusinessException("电力电子的艾普MES接口缺少部门编码映射配置");
|
||||||
|
logDl.error("电力电子的艾普MES接口缺少部门编码映射配置");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
String deptRange = String.join(",", deptParams.keySet());
|
String deptRange = String.join(",", deptParams.keySet());
|
||||||
configParams.put("deptRange", deptRange);
|
configParams.put("deptRange", deptRange);
|
||||||
|
|
|
@ -13,8 +13,10 @@ import nc.jdbc.framework.processor.MapProcessor;
|
||||||
import nc.vo.bd.defdoc.DefdocVO;
|
import nc.vo.bd.defdoc.DefdocVO;
|
||||||
import nc.vo.pim.project.ProjectHeadVO;
|
import nc.vo.pim.project.ProjectHeadVO;
|
||||||
import nc.vo.pub.BusinessException;
|
import nc.vo.pub.BusinessException;
|
||||||
|
import nc.vo.pub.lang.UFBoolean;
|
||||||
import nc.vo.pub.lang.UFDateTime;
|
import nc.vo.pub.lang.UFDateTime;
|
||||||
import nc.vo.pubapp.AppContext;
|
import nc.vo.pubapp.AppContext;
|
||||||
|
import nc.vo.pubapp.pattern.pub.SqlBuilder;
|
||||||
import nc.vo.so.m30.entity.SaleOrderBVO;
|
import nc.vo.so.m30.entity.SaleOrderBVO;
|
||||||
import nc.vo.so.m30.entity.SaleOrderHVO;
|
import nc.vo.so.m30.entity.SaleOrderHVO;
|
||||||
import nc.vo.so.m30.entity.SaleOrderVO;
|
import nc.vo.so.m30.entity.SaleOrderVO;
|
||||||
|
@ -110,19 +112,43 @@ public class SaleOrderResource extends NCCPubRestResource {
|
||||||
headdata.put("ccustomervid", headdata.get("ccustomerid"));
|
headdata.put("ccustomervid", headdata.get("ccustomerid"));
|
||||||
String pk_group = AppContext.getInstance().getPkGroup();
|
String pk_group = AppContext.getInstance().getPkGroup();
|
||||||
headdata.put("pk_group", pk_group);
|
headdata.put("pk_group", pk_group);
|
||||||
|
//add by hanwl 20250729 部分组织,表体结算财务组织和应收组织需要取销售业务委托关系
|
||||||
|
//add by hanwl 20250729 根据销售组织编码去视图V_SALEORG_RELATIONS查询数据,如果有数据,
|
||||||
|
// 则取数据中的结算组织,应收组织,否则取销售组织 start
|
||||||
|
String org_code = headdata.get("pk_org_v")+"";
|
||||||
|
Map<String,String> relMap = this.getSaleorgRelations(org_code);
|
||||||
|
String settleorg_code = org_code;//初始化结算组织编码为销售组织编码
|
||||||
|
String arorg_code = org_code;//初始化应收组织编码为销售组织编码
|
||||||
|
if(relMap!=null){
|
||||||
|
String tempsettleorg_code = relMap.get("settleorg_code");
|
||||||
|
if(StringUtils.isNotBlank(tempsettleorg_code)){
|
||||||
|
settleorg_code = tempsettleorg_code;
|
||||||
|
}
|
||||||
|
String temparorg_code = relMap.get("arorg_code");
|
||||||
|
if(StringUtils.isNotBlank(temparorg_code)){
|
||||||
|
arorg_code = temparorg_code;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
//add by hanwl 20250729 根据销售组织编码去视图V_SALEORG_RELATIONS查询数据,如果有数据,
|
||||||
|
// 则取数据中的结算组织,应收组织,否则取销售组织 end
|
||||||
List<Object> bodyArr = (List<Object>) map.get(BODYTABLE);
|
List<Object> bodyArr = (List<Object>) map.get(BODYTABLE);
|
||||||
for (Object body : bodyArr) {
|
for (Object body : bodyArr) {
|
||||||
Map<String, Object> bodydata = (Map<String, Object>) body;
|
Map<String, Object> bodydata = (Map<String, Object>) body;
|
||||||
bodydata.put("pk_group", pk_group);
|
bodydata.put("pk_group", pk_group);
|
||||||
bodydata.put("cprojectid", headdata.get("vdef6"));
|
// bodydata.put("cprojectid", headdata.get("vdef6"));
|
||||||
// bodydata.put("ctrafficorgvid", headdata.get("pk_org_v"));
|
// bodydata.put("ctrafficorgvid", headdata.get("pk_org_v"));
|
||||||
bodydata.put("csendstockorgvid", headdata.get("pk_org_v"));
|
bodydata.put("csendstockorgvid", headdata.get("pk_org_v"));
|
||||||
// bodydata.put("csendstordocid", headdata.get("pk_org_v"));
|
// bodydata.put("csendstordocid", headdata.get("pk_org_v"));
|
||||||
bodydata.put("csendstockorgid", headdata.get("pk_org_v"));
|
bodydata.put("csendstockorgid", headdata.get("pk_org_v"));
|
||||||
bodydata.put("carorgid", headdata.get("pk_org_v"));
|
// bodydata.put("carorgid", headdata.get("pk_org_v"));
|
||||||
bodydata.put("carorgvid", headdata.get("pk_org_v"));
|
// bodydata.put("carorgvid", headdata.get("pk_org_v"));
|
||||||
bodydata.put("csettleorgid", headdata.get("pk_org_v"));
|
bodydata.put("carorgid", arorg_code);
|
||||||
bodydata.put("csettleorgvid", headdata.get("pk_org_v"));
|
bodydata.put("carorgvid", arorg_code);
|
||||||
|
// bodydata.put("csettleorgid", headdata.get("pk_org_v"));
|
||||||
|
// bodydata.put("csettleorgvid", headdata.get("pk_org_v"));
|
||||||
|
bodydata.put("csettleorgid", settleorg_code);
|
||||||
|
bodydata.put("csettleorgvid", settleorg_code);
|
||||||
bodydata.put("ctaxcountryid", "CN");
|
bodydata.put("ctaxcountryid", "CN");
|
||||||
bodydata.put("crececountryid", "CN");
|
bodydata.put("crececountryid", "CN");
|
||||||
bodydata.put("csendcountryid", "CN");
|
bodydata.put("csendcountryid", "CN");
|
||||||
|
@ -135,21 +161,46 @@ public class SaleOrderResource extends NCCPubRestResource {
|
||||||
SaleOrderVO[] salevos = OpenAPIParaUtil.changeVO(paramList, HEADTABLE, BODYTABLE);
|
SaleOrderVO[] salevos = OpenAPIParaUtil.changeVO(paramList, HEADTABLE, BODYTABLE);
|
||||||
log.error("销售订单根据自定义项创建档案开始-----------------------");
|
log.error("销售订单根据自定义项创建档案开始-----------------------");
|
||||||
List<DefdocVO> defdocVOS = genDef(salevos);
|
List<DefdocVO> defdocVOS = genDef(salevos);
|
||||||
|
List<ProjectHeadVO> projectList = genProject(salevos);
|
||||||
for (Map<String, Object> map : paramList) {
|
|
||||||
BaseDAO baseDAO = new BaseDAO();
|
|
||||||
Map<String, Object> headdata = (Map<String, Object>) map.get(HEADTABLE);
|
|
||||||
List<Object> bodyArr = (List<Object>) map.get(BODYTABLE);
|
|
||||||
for (Object body : bodyArr) {
|
|
||||||
Map<String, Object> bodydata = (Map<String, Object>) body;
|
|
||||||
String sql = " select pk_project from bd_project where project_code='" + headdata.get("vdef6") + "' and nvl(dr,0)=0 ";
|
|
||||||
String o_pk_project = (String) baseDAO.executeQuery(sql, new ColumnProcessor());
|
|
||||||
bodydata.put("cprojectid", o_pk_project);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 参数形式转换为vo并翻译
|
// 参数形式转换为vo并翻译
|
||||||
List<SaleOrderVO> vosList = TransferMapToVOTool.transferMapToAggVO(paramList, SaleOrderVO.class);
|
List<SaleOrderVO> vosList = TransferMapToVOTool.transferMapToAggVO(paramList, SaleOrderVO.class);
|
||||||
|
//根据返回的projectList先行翻译
|
||||||
|
if(projectList!=null && projectList.size()>0){
|
||||||
|
Map<String,ProjectHeadVO> code_projectMap = new HashMap<>();
|
||||||
|
for(ProjectHeadVO projectHeadVO : projectList){
|
||||||
|
String code = projectHeadVO.getProject_code();
|
||||||
|
String pkProject = projectHeadVO.getPk_project();
|
||||||
|
log.error("销售订单保存接口:项目编号【"+code+"】,项目主键【"+pkProject+"】");
|
||||||
|
if(code_projectMap.containsKey(code)){
|
||||||
|
|
||||||
|
}else{
|
||||||
|
code_projectMap.put(code, projectHeadVO);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//翻译
|
||||||
|
for(SaleOrderVO saleOrderVO : vosList) {
|
||||||
|
SaleOrderHVO parentVO = saleOrderVO.getParentVO();
|
||||||
|
SaleOrderBVO[] childrenVOs = saleOrderVO.getChildrenVO();
|
||||||
|
String vdef22 = parentVO.getVdef22();
|
||||||
|
if(vdef22!=null && vdef22.trim().length()>0){
|
||||||
|
ProjectHeadVO projectHeadVO = code_projectMap.get(vdef22);
|
||||||
|
if(projectHeadVO!=null){
|
||||||
|
parentVO.setVdef22(projectHeadVO.getPk_project());
|
||||||
|
parentVO.setVdef23(projectHeadVO.getProject_name());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(SaleOrderBVO bvo:childrenVOs){
|
||||||
|
String cprojectid = bvo.getCprojectid();
|
||||||
|
if(cprojectid!=null && cprojectid.trim().length()>0){
|
||||||
|
ProjectHeadVO projectHeadVO = code_projectMap.get(cprojectid);
|
||||||
|
if(projectHeadVO!=null){
|
||||||
|
bvo.setCprojectid(projectHeadVO.getPk_project());
|
||||||
|
bvo.setVbdef10(projectHeadVO.getProject_name());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
//根据返回的defdocVOS先行翻译
|
//根据返回的defdocVOS先行翻译
|
||||||
if(defdocVOS!=null && defdocVOS.size()>0){
|
if(defdocVOS!=null && defdocVOS.size()>0){
|
||||||
Map<String,Map<String,String>> deflist_map = new HashMap<>();
|
Map<String,Map<String,String>> deflist_map = new HashMap<>();
|
||||||
|
@ -245,7 +296,7 @@ public class SaleOrderResource extends NCCPubRestResource {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<DefdocVO> genDef(SaleOrderVO[] salevos) throws BusinessException {
|
private List<ProjectHeadVO> genProject(SaleOrderVO[] salevos) throws BusinessException {
|
||||||
BaseDAO baseDAO = new BaseDAO();
|
BaseDAO baseDAO = new BaseDAO();
|
||||||
List<DefdocVO> allDefDoc = new ArrayList<DefdocVO>();
|
List<DefdocVO> allDefDoc = new ArrayList<DefdocVO>();
|
||||||
ArrayList<String> arrhth = new ArrayList<String>();
|
ArrayList<String> arrhth = new ArrayList<String>();
|
||||||
|
@ -259,17 +310,82 @@ public class SaleOrderResource extends NCCPubRestResource {
|
||||||
}
|
}
|
||||||
String o = (String) map.get("pk_org");
|
String o = (String) map.get("pk_org");
|
||||||
|
|
||||||
String cprocode = salevos[0].getChildrenVO()[0].getCprojectid();
|
//遍历明细去重
|
||||||
String cproname = salevos[0].getChildrenVO()[0].getVbdef10();
|
List<ProjectHeadVO> result=new ArrayList<>();
|
||||||
if (!BFPubTools.getString_TrimAsNull(cprocode).equals("")) {
|
for(SaleOrderVO saleOrderVO:salevos){
|
||||||
sql = " select pk_project from bd_project where project_code='" + cprocode + "' and pk_duty_org='" + o + "' and nvl(dr,0)=0 ";
|
Map<String,String > code_name =new HashMap<>();
|
||||||
String o_pk_project = (String) baseDAO.executeQuery(sql, new ColumnProcessor());
|
//上级项目名称
|
||||||
if (o_pk_project == null) {
|
String vdef23 = saleOrderVO.getParentVO().getVdef23();
|
||||||
// ÐÂÔöÏîÄ¿µµ°¸
|
//上级项目编码
|
||||||
createPro(cprocode, cproname, map);
|
String vdef22 = saleOrderVO.getParentVO().getVdef22();
|
||||||
|
if(vdef23 !=null &&vdef23.trim().length()>0&&vdef22 !=null &&vdef22.trim().length()>0){
|
||||||
|
code_name.put(vdef22,vdef23);
|
||||||
|
}
|
||||||
|
SaleOrderBVO[] childrenVO = saleOrderVO.getChildrenVO();
|
||||||
|
for(SaleOrderBVO saleOrderBVO:childrenVO){
|
||||||
|
String cprojectid = saleOrderBVO.getCprojectid();
|
||||||
|
String vbdef10 = saleOrderBVO.getVbdef10();
|
||||||
|
if(cprojectid ==null ||cprojectid.trim().length()==0||vbdef10 ==null ||vbdef10.trim().length()==0){
|
||||||
|
continue;
|
||||||
|
}else {
|
||||||
|
if(code_name.containsKey(cprojectid)){
|
||||||
|
//存在编码相同的行,比较名称---不同则报错
|
||||||
|
if(!code_name.get(cprojectid).equals(vbdef10)){
|
||||||
|
throw new BusinessException("销售订单,项目编码相同但是名称不同,请检查!!!");
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
code_name.put(cprojectid,vbdef10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
UFBoolean is_hth = UFBoolean.FALSE;
|
||||||
|
ProjectHeadVO headDOCVO=null;
|
||||||
|
//查询是否重复
|
||||||
|
if(!code_name.isEmpty()){
|
||||||
|
SqlBuilder projectSql=new SqlBuilder();
|
||||||
|
projectSql.append(" project_code",code_name.keySet().toArray(new String[0]));
|
||||||
|
projectSql.append(" and pk_duty_org",o);
|
||||||
|
projectSql.append(" and nvl(dr,0)=0 ");
|
||||||
|
List<ProjectHeadVO> projectHeadVOList = (List<ProjectHeadVO>) dao.retrieveByClause(ProjectHeadVO.class, projectSql.toString());
|
||||||
|
if (projectHeadVOList != null && projectHeadVOList.size() > 0) {
|
||||||
|
for(ProjectHeadVO projectHeadVO:projectHeadVOList){
|
||||||
|
result.add(projectHeadVO);
|
||||||
|
String projectCode = projectHeadVO.getProject_code();
|
||||||
|
if(projectCode.equals(vdef22)){
|
||||||
|
is_hth=UFBoolean.TRUE;
|
||||||
|
headDOCVO=projectHeadVO;
|
||||||
|
}
|
||||||
|
if (code_name.containsKey(projectCode)) {
|
||||||
|
code_name.remove(projectCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(code_name!=null && code_name.size()>0){
|
||||||
|
//存在需要新增的档案明细
|
||||||
|
createPro(code_name, is_hth, headDOCVO, vdef22, vdef23, map,result);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
//存在需要新增的档案明细
|
||||||
|
createPro(code_name, is_hth, headDOCVO, vdef22, vdef23, map,result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<DefdocVO> genDef(SaleOrderVO[] salevos) throws BusinessException {
|
||||||
|
BaseDAO baseDAO = new BaseDAO();
|
||||||
|
List<DefdocVO> allDefDoc = new ArrayList<DefdocVO>();
|
||||||
|
ArrayList<String> arrhth = new ArrayList<String>();
|
||||||
|
ArrayList<String> arrxmh = new ArrayList<String>();
|
||||||
|
ArrayList<String> arrxsddh = new ArrayList<String>();
|
||||||
|
String sql = " select pk_org,pk_vid from org_orgs where org_orgs.code='" + salevos[0].getParentVO().getPk_org() + "' and nvl(dr,0)=0 and isbusinessunit='Y' ";
|
||||||
|
|
||||||
|
Map map = (Map) baseDAO.executeQuery(sql, new MapProcessor());
|
||||||
|
if (map == null) {
|
||||||
|
throw new BusinessException("采购组织档案未查到");
|
||||||
|
}
|
||||||
|
String o = (String) map.get("pk_org");
|
||||||
for (int i = 0; i < salevos.length; i++) {
|
for (int i = 0; i < salevos.length; i++) {
|
||||||
String vdef6 = BFPubTools.getString_TrimAsNull(salevos[i].getParentVO().getVdef6());
|
String vdef6 = BFPubTools.getString_TrimAsNull(salevos[i].getParentVO().getVdef6());
|
||||||
if (vdef6 != "" && !arrhth.contains(vdef6)) {
|
if (vdef6 != "" && !arrhth.contains(vdef6)) {
|
||||||
|
@ -346,13 +462,46 @@ public class SaleOrderResource extends NCCPubRestResource {
|
||||||
return allDefDoc;
|
return allDefDoc;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createPro(String cprocode, String cproname, Map map) throws BusinessException {
|
private void createPro(Map<String,String > code_name, UFBoolean is_hth, ProjectHeadVO headDOCVO, String vdef22, String vdef23, Map map,List<ProjectHeadVO> new_list) throws BusinessException {
|
||||||
|
//code_name里全是需要新增的明细项目
|
||||||
|
Set<String> strings = code_name.keySet();
|
||||||
|
if(is_hth.booleanValue()==true){
|
||||||
|
//表头项目已经存在,无需创建父项目
|
||||||
|
for (String code : strings) {
|
||||||
|
ProjectHeadVO hvo = new ProjectHeadVO();
|
||||||
|
hvo.setProject_code(code);
|
||||||
|
hvo.setProject_name(code_name.get(code));
|
||||||
|
hvo.setPk_parentpro(headDOCVO.getPk_project());
|
||||||
|
fillheadVOValue(hvo,map);
|
||||||
|
ProjectHeadVO projectHeadVO = NCLocator.getInstance().lookup(IProject.class).insertProject(hvo);
|
||||||
|
new_list.add(projectHeadVO);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
//表头项目不存在,需要创建父项目
|
||||||
|
ProjectHeadVO headProjectVO = new ProjectHeadVO();
|
||||||
|
headProjectVO.setProject_code(vdef22);
|
||||||
|
headProjectVO.setProject_name(vdef23);
|
||||||
|
fillheadVOValue(headProjectVO,map);
|
||||||
|
ProjectHeadVO projectHeadVO = NCLocator.getInstance().lookup(IProject.class).insertProject(headProjectVO);
|
||||||
|
new_list.add(projectHeadVO);
|
||||||
|
code_name.remove(vdef22);
|
||||||
|
if(code_name!=null&& code_name.size()>0){
|
||||||
|
for (String code : strings) {
|
||||||
|
ProjectHeadVO hvo = new ProjectHeadVO();
|
||||||
|
hvo.setProject_code(code);
|
||||||
|
hvo.setProject_name(code_name.get(code));
|
||||||
|
hvo.setPk_parentpro(projectHeadVO.getPk_project());
|
||||||
|
fillheadVOValue(hvo,map);
|
||||||
|
ProjectHeadVO itemprojectHeadVO = NCLocator.getInstance().lookup(IProject.class).insertProject(hvo);
|
||||||
|
new_list.add(itemprojectHeadVO);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fillheadVOValue(ProjectHeadVO hvo, Map map) {
|
||||||
String pk_org = (String) map.get("pk_org");
|
String pk_org = (String) map.get("pk_org");
|
||||||
String pk_org_v = (String) map.get("pk_vid");
|
String pk_org_v = (String) map.get("pk_vid");
|
||||||
|
|
||||||
ProjectHeadVO hvo = new ProjectHeadVO();
|
|
||||||
hvo.setProject_code(cprocode);
|
|
||||||
hvo.setProject_name(cproname);
|
|
||||||
hvo.setPk_org(pk_org);
|
hvo.setPk_org(pk_org);
|
||||||
hvo.setPk_org_v(pk_org_v);
|
hvo.setPk_org_v(pk_org_v);
|
||||||
|
|
||||||
|
@ -366,7 +515,6 @@ public class SaleOrderResource extends NCCPubRestResource {
|
||||||
hvo.setPk_eps("1001A110000000004K64");
|
hvo.setPk_eps("1001A110000000004K64");
|
||||||
hvo.setPk_duty_dept_v(pk_org_v);
|
hvo.setPk_duty_dept_v(pk_org_v);
|
||||||
hvo.setEnablestate(2);
|
hvo.setEnablestate(2);
|
||||||
NCLocator.getInstance().lookup(IProject.class).insertProject(hvo);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private DefdocVO[] createDefVO(List<String> newhth, String defdoclistcode, String pk_org) throws BusinessException {
|
private DefdocVO[] createDefVO(List<String> newhth, String defdoclistcode, String pk_org) throws BusinessException {
|
||||||
|
@ -419,6 +567,18 @@ public class SaleOrderResource extends NCCPubRestResource {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据销售组织代码获取销售组织关系信息
|
||||||
|
* @param saleorg 销售组织代码
|
||||||
|
* @return 返回包含结算组织代码和应收组织代码的Map集合,key为settleorg_code和arorg_code
|
||||||
|
* @throws BusinessException 业务异常
|
||||||
|
*/
|
||||||
|
private Map<String,String> getSaleorgRelations(String saleorg) throws BusinessException{
|
||||||
|
String sql = "select settleorg_code,arorg_code from V_SALEORG_RELATIONS where saleorg_code='"+saleorg+"'";
|
||||||
|
Map map = (Map<String,String>) getDao().executeQuery(sql, new MapProcessor());
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("update")
|
@Path("update")
|
||||||
@Consumes({"application/json"})
|
@Consumes({"application/json"})
|
||||||
|
|
|
@ -0,0 +1,299 @@
|
||||||
|
package nc.bs.uapbd.util;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import nc.bs.dao.DAOException;
|
||||||
|
import nc.bs.logging.Log;
|
||||||
|
import nc.bs.trade.business.HYSuperDMO;
|
||||||
|
import nc.vo.bd.defdoc.DefdocVO;
|
||||||
|
import nc.vo.cmp.util.StringUtils;
|
||||||
|
import nc.vo.pub.BusinessException;
|
||||||
|
import nccloud.framework.core.io.WebFile;
|
||||||
|
import org.apache.http.client.config.CookieSpecs;
|
||||||
|
import org.apache.http.client.config.RequestConfig;
|
||||||
|
import org.apache.http.client.methods.HttpGet;
|
||||||
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
|
import org.apache.http.impl.client.HttpClients;
|
||||||
|
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
||||||
|
import org.apache.http.util.EntityUtils;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.zip.ZipEntry;
|
||||||
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取PLM图纸的工具类
|
||||||
|
*
|
||||||
|
* @author mzr
|
||||||
|
* @date 2025/8/1
|
||||||
|
*/
|
||||||
|
public class GetPlmFileUtil {
|
||||||
|
private static final String LOG_INFO_NAME = "dldzlog";
|
||||||
|
private static final Log logger = Log.getInstance(LOG_INFO_NAME);
|
||||||
|
private String plmBaseUrl = "";
|
||||||
|
private String plmUser = "";
|
||||||
|
private String token = "";
|
||||||
|
private static final String tokenUrl = "/sipmweb/api/oauth";
|
||||||
|
// 根据物料编码获取零部件ID
|
||||||
|
private String materialIdUrl = "/sipmweb/api/{rid}/search/{t}?key={key}&start={start}&size={size}";
|
||||||
|
// 根据零部件ID获取二维图档ID及信息
|
||||||
|
private String materialFileIdUrl = "/sipmweb/api/{rid}/relation/{t}/{id}/data?re={re}&start={start}&item={item}";
|
||||||
|
// 下载文件
|
||||||
|
private String downlownUrl = "/sipmweb/web/download?rid={rid}&id={id}&t={t}&type={type}";
|
||||||
|
// http请求
|
||||||
|
private static final PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
|
||||||
|
private static final CloseableHttpClient httpClient;
|
||||||
|
|
||||||
|
static {
|
||||||
|
connectionManager.setMaxTotal(5000);
|
||||||
|
connectionManager.setDefaultMaxPerRoute(500);
|
||||||
|
|
||||||
|
RequestConfig globalConfig = RequestConfig.custom()
|
||||||
|
.setConnectionRequestTimeout(50000)
|
||||||
|
.setConnectTimeout(50000)
|
||||||
|
.setSocketTimeout(200000)
|
||||||
|
.setCookieSpec(CookieSpecs.IGNORE_COOKIES)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
httpClient = HttpClients.custom()
|
||||||
|
.setConnectionManager(connectionManager)
|
||||||
|
.setDefaultRequestConfig(globalConfig)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public WebFile getPlmFiles(String[] materialCodeArr) throws Exception {
|
||||||
|
WebFile file = null;
|
||||||
|
if (materialCodeArr == null || materialCodeArr.length == 0) {
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
// 获取PLM的参数
|
||||||
|
Map<String, String> configParams = getConfigParams("Dldz-config");
|
||||||
|
if (configParams == null || configParams.isEmpty()) {
|
||||||
|
throw new BusinessException("未配置PLM参数");
|
||||||
|
}
|
||||||
|
plmBaseUrl = configParams.get("plmBaseUrl");
|
||||||
|
plmUser = configParams.get("plmUser");
|
||||||
|
token = getToken();
|
||||||
|
if (materialCodeArr.length == 1) {
|
||||||
|
String materialCode = materialCodeArr[0];
|
||||||
|
JSONObject plmFileJson = this.getPlmFile(materialCode);
|
||||||
|
String objId = plmFileJson.getString("objId");
|
||||||
|
String fname = plmFileJson.getString("fname");
|
||||||
|
InputStream ins = this.doDownloadPlmFile(objId);
|
||||||
|
file = new WebFile(fname, ins);
|
||||||
|
} else {
|
||||||
|
// 多个物料合并成zip文件输出文件流
|
||||||
|
// 创建内存中的 ZIP 输出流
|
||||||
|
ByteArrayOutputStream zipOut = new ByteArrayOutputStream();
|
||||||
|
ZipOutputStream zipStream = new ZipOutputStream(zipOut);
|
||||||
|
try {
|
||||||
|
for (String materialCode : materialCodeArr) {
|
||||||
|
JSONObject plmFileJson = this.getPlmFile(materialCode);
|
||||||
|
String objId = plmFileJson.getString("objId");
|
||||||
|
String fname = plmFileJson.getString("fname");
|
||||||
|
InputStream ins = this.doDownloadPlmFile(objId);
|
||||||
|
try {
|
||||||
|
byte[] bytes = parseFileStream(ins);
|
||||||
|
zipStream.putNextEntry(new ZipEntry(fname));
|
||||||
|
zipStream.write(bytes);
|
||||||
|
zipStream.closeEntry();
|
||||||
|
} finally {
|
||||||
|
if (ins != null) {
|
||||||
|
try {
|
||||||
|
ins.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.error("Failed to close input stream: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
zipStream.finish();
|
||||||
|
} finally {
|
||||||
|
zipStream.close();
|
||||||
|
}
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
|
||||||
|
String zipName = "物料图纸下载_" + sdf.format(new Date());
|
||||||
|
// 构造 WebFile 返回 ZIP 文件
|
||||||
|
InputStream ins = new ByteArrayInputStream(zipOut.toByteArray());
|
||||||
|
file = new WebFile(zipName + ".zip", ins);
|
||||||
|
}
|
||||||
|
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JSONObject getPlmFile(String materialCode) throws Exception {
|
||||||
|
String materialId = getMaterialId(materialCode);
|
||||||
|
return getFileId(materialId);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取token
|
||||||
|
*/
|
||||||
|
private String getToken() throws IOException, BusinessException {
|
||||||
|
Map<String, String> tokenMap = new HashMap<>();
|
||||||
|
tokenMap.put("uname", plmUser);
|
||||||
|
tokenMap.put("f", "true");
|
||||||
|
String tokenStr = doGet(plmBaseUrl + tokenUrl, tokenMap);
|
||||||
|
logger.error("GetPlmFileUtil-getToken-tokenStr = " + tokenStr);
|
||||||
|
JSONObject jsonObject = JSONObject.parseObject(tokenStr);
|
||||||
|
String token = jsonObject.getString("errmsg");
|
||||||
|
if (token == null || token.isEmpty()) {
|
||||||
|
throw new BusinessException("PLM鉴权失败");
|
||||||
|
}
|
||||||
|
return token;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据物料编码获取零部件ID
|
||||||
|
*/
|
||||||
|
private String getMaterialId(String materialCode) throws IOException, BusinessException {
|
||||||
|
String fileUrl = plmBaseUrl + materialIdUrl;
|
||||||
|
fileUrl = fileUrl.replace("{rid}", token);
|
||||||
|
// 对象表名 MPART(零部件)
|
||||||
|
fileUrl = fileUrl.replace("{t}", "MPART");
|
||||||
|
Map<String, String> map = new HashMap<>();
|
||||||
|
map.put("key", materialCode);// 搜索关键字
|
||||||
|
map.put("start", "0");// 偏移量
|
||||||
|
map.put("size", "10");// 数量
|
||||||
|
String result = doGet(fileUrl, map);
|
||||||
|
logger.error("GetPlmFileUtil-getMaterialId-result = " + result);
|
||||||
|
JSONObject jsonObject = JSONObject.parseObject(result);
|
||||||
|
String objId = jsonObject.getString("objId");
|
||||||
|
if (objId == null || objId.isEmpty()) {
|
||||||
|
throw new BusinessException("获取PLM物料id失败");
|
||||||
|
}
|
||||||
|
return objId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据零部件ID获取文件ID
|
||||||
|
*/
|
||||||
|
private JSONObject getFileId(String materialId) throws IOException, BusinessException {
|
||||||
|
String fileUrl = plmBaseUrl + materialFileIdUrl;
|
||||||
|
fileUrl = fileUrl.replace("{rid}", token);
|
||||||
|
// 对象表名 MPART(零部件)
|
||||||
|
fileUrl = fileUrl.replace("{t}", "MPART");
|
||||||
|
// 对象id
|
||||||
|
fileUrl = fileUrl.replace("{id}", materialId);
|
||||||
|
Map<String, String> map = new HashMap<>();
|
||||||
|
map.put("re", "MPART_SIPM1");// 关系ID 二维图档:MPART_SIPM1
|
||||||
|
map.put("start", "0");// 偏移量
|
||||||
|
map.put("item", "SIPM1");// 关联对象表名
|
||||||
|
String result = doGet(fileUrl, map);
|
||||||
|
logger.error("GetPlmFileUtil-getFileId-result = " + result);
|
||||||
|
JSONObject jsonObject = JSONObject.parseObject(result);
|
||||||
|
String objId = jsonObject.getString("objId");
|
||||||
|
if (objId == null || objId.isEmpty()) {
|
||||||
|
throw new BusinessException("获取PLM物料的文件信息失败");
|
||||||
|
}
|
||||||
|
return jsonObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 调用PLM的下载文件接口
|
||||||
|
*/
|
||||||
|
private InputStream doDownloadPlmFile(String fileId) throws IOException {
|
||||||
|
String fileUrl = plmBaseUrl + downlownUrl;
|
||||||
|
Map<String, String> map = new HashMap<>();
|
||||||
|
map.put("rid", token);
|
||||||
|
map.put("id", fileId);// 对象id
|
||||||
|
map.put("t", "SIPM1");// 对象表名
|
||||||
|
map.put("type", "D");// 文件类别(BD,D)(D是文件本身的文件,BD是PDF图)
|
||||||
|
return getFileFromPlm(fileUrl, map);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, String> getConfigParams(String code) {
|
||||||
|
Map<String, String> map = new HashMap<>();
|
||||||
|
String strWhere = " pk_defdoclist in (select pk_defdoclist from bd_defdoclist where code='[code]' and dr=0 ) and dr=0";
|
||||||
|
strWhere = strWhere.replace("[code]", code);
|
||||||
|
try {
|
||||||
|
DefdocVO[] defdocVOs = (DefdocVO[]) new HYSuperDMO().queryByWhereClause(DefdocVO.class, strWhere);
|
||||||
|
if (defdocVOs != null) {
|
||||||
|
for (DefdocVO defdocVO : defdocVOs) {
|
||||||
|
String value = StringUtils.isEmpty(defdocVO.getMemo()) ? defdocVO.getName() : defdocVO.getMemo();
|
||||||
|
map.put(defdocVO.getCode().trim(), value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (DAOException e) {
|
||||||
|
logger.error("Failed to get config parameters for code: " + code, e);
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private String doGet(String requestUrl, Map<String, String> paramMap) throws IOException {
|
||||||
|
StringBuilder param = new StringBuilder("?");
|
||||||
|
if (paramMap != null) {
|
||||||
|
for (Map.Entry<String, String> entry : paramMap.entrySet()) {
|
||||||
|
param.append(entry.getKey());
|
||||||
|
param.append("=");
|
||||||
|
param.append(entry.getValue());
|
||||||
|
param.append("&");
|
||||||
|
}
|
||||||
|
param.deleteCharAt(param.length() - 1);
|
||||||
|
}
|
||||||
|
String url = requestUrl + param;
|
||||||
|
HttpGet get = new HttpGet(url);
|
||||||
|
String responseString = httpClient.execute(get, response -> EntityUtils.toString(response.getEntity()));
|
||||||
|
get.releaseConnection();
|
||||||
|
return responseString;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 调用第三方文件接口并接收文件流
|
||||||
|
*
|
||||||
|
* @param requestUrl 文件接口URL
|
||||||
|
* @return 文件流
|
||||||
|
*/
|
||||||
|
private InputStream getFileFromPlm(String requestUrl, Map<String, String> paramMap) throws IOException {
|
||||||
|
StringBuilder param = new StringBuilder("?");
|
||||||
|
if (paramMap != null) {
|
||||||
|
for (Map.Entry<String, String> entry : paramMap.entrySet()) {
|
||||||
|
param.append(entry.getKey());
|
||||||
|
param.append("=");
|
||||||
|
param.append(entry.getValue());
|
||||||
|
param.append("&");
|
||||||
|
}
|
||||||
|
param.deleteCharAt(param.length() - 1);
|
||||||
|
}
|
||||||
|
String url = requestUrl + param;
|
||||||
|
HttpGet httpGet = new HttpGet(url);
|
||||||
|
|
||||||
|
// 执行请求并返回文件流
|
||||||
|
return httpClient.execute(httpGet, response -> {
|
||||||
|
// 检查响应状态
|
||||||
|
int statusCode = response.getStatusLine().getStatusCode();
|
||||||
|
if (statusCode >= 200 && statusCode < 300) {
|
||||||
|
return response.getEntity().getContent();
|
||||||
|
} else {
|
||||||
|
throw new IOException("HTTP request failed with status code: " + statusCode);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析文件流
|
||||||
|
*
|
||||||
|
* @param inputStream 文件流
|
||||||
|
* @return 解析结果
|
||||||
|
*/
|
||||||
|
private byte[] parseFileStream(InputStream inputStream) throws IOException {
|
||||||
|
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||||
|
int nRead;
|
||||||
|
byte[] data = new byte[1024];
|
||||||
|
while ((nRead = inputStream.read(data, 0, data.length)) != -1) {
|
||||||
|
buffer.write(data, 0, nRead);
|
||||||
|
}
|
||||||
|
byte[] byteArray = buffer.toByteArray();
|
||||||
|
buffer.close();
|
||||||
|
return byteArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue