Commit 7fc7713f authored by 刘学辉's avatar 刘学辉

物料/产品主数据修改,采购审批自动发起流程

parent 788fb0f0
...@@ -56,8 +56,8 @@ function loadNonProdApplyListGrid() { ...@@ -56,8 +56,8 @@ function loadNonProdApplyListGrid() {
} }
extendedHandler(result.id,result.matnr);; extendedHandler(result.id,result.matnr);;
} }
}, }
publishHandler: {id: 'publishData', text: '数据发布', img: 'fa-map', className: 'btn-gray', /* publishHandler: {id: 'publishData', text: '数据发布', img: 'fa-map', className: 'btn-gray',
click: function () { click: function () {
let result=DataUtil.getUpdateRow(gridManager); let result=DataUtil.getUpdateRow(gridManager);
...@@ -68,7 +68,7 @@ function loadNonProdApplyListGrid() { ...@@ -68,7 +68,7 @@ function loadNonProdApplyListGrid() {
publishDatas('确实要发布数据吗?', result.id); publishDatas('确实要发布数据吗?', result.id);
} }
} }*/
}); });
gridManager = UICtrl.grid("#nonProdApplyListGrid", { gridManager = UICtrl.grid("#nonProdApplyListGrid", {
columns: [ columns: [
......
...@@ -83,7 +83,7 @@ ...@@ -83,7 +83,7 @@
<x:selectC name="disgr" label="MRP组" labelCol="1" fieldCol="2" dictionary="disgr"/> <x:selectC name="disgr" label="MRP组" labelCol="1" fieldCol="2" dictionary="disgr"/>
<x:selectC name="dismm" label="MRP类型" labelCol="1" fieldCol="2" dictionary="dismm"/> <x:selectC name="dismm" label="MRP类型" labelCol="1" fieldCol="2" dictionary="dismm"/>
<x:hidden name="minbe"/> <x:hidden name="minbe"/>
<x:inputC name="minbeName" label="重订货点" labelCol="1" fieldCol="2" required="true" wrapper="select"/> <x:inputC name="minbeName" label="重订货点" labelCol="1" fieldCol="2" required="false" wrapper="select"/>
<x:selectC name="dispo" label="MRP控制者" labelCol="1" fieldCol="2" required="true" dictionary="dispo"/> <x:selectC name="dispo" label="MRP控制者" labelCol="1" fieldCol="2" required="true" dictionary="dispo"/>
<x:selectC name="disls" label="批量规模" labelCol="1" fieldCol="2" required="true" dictionary="disls"/> <x:selectC name="disls" label="批量规模" labelCol="1" fieldCol="2" required="true" dictionary="disls"/>
<x:inputC name="bstfe" label="固定批量" labelCol="1" fieldCol="2"/> <x:inputC name="bstfe" label="固定批量" labelCol="1" fieldCol="2"/>
......
...@@ -60,7 +60,7 @@ public class BsnMessageApplicationImpl extends BaseApplication implements BsnMes ...@@ -60,7 +60,7 @@ public class BsnMessageApplicationImpl extends BaseApplication implements BsnMes
List<BsnMessageExecute> executes = this.getExecutesByMsId(sponsor.getId()); List<BsnMessageExecute> executes = this.getExecutesByMsId(sponsor.getId());
for (BsnMessageExecute execute :executes) { for (BsnMessageExecute execute :executes) {
execute.setActive(ActiveStatus.UNFINISHED.getValue()); execute.setActive(ActiveStatus.UNFINISHED.getValue());
if ("INIT_DPT".equals(execute.getBusinessCode())){ //是产品的 把待办的去掉 if ("INIT_DPT".equals(execute.getBusinessCode())){ //是产品推送的 把待办去掉
execute.setActive(ActiveStatus.FINISHED.getValue()); execute.setActive(ActiveStatus.FINISHED.getValue());
} }
} }
......
package com.huigou.topsun.sap.nonProdApply.application; package com.huigou.topsun.sap.nonProdApply.application;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.huigou.context.Operator;
import com.huigou.topsun.sap.nonProdApply.domain.NonProdApplyBaseInfo; import com.huigou.topsun.sap.nonProdApply.domain.NonProdApplyBaseInfo;
import com.huigou.topsun.sap.nonProdApply.domain.SapNonProdApplyDept; import com.huigou.topsun.sap.nonProdApply.domain.SapNonProdApplyDept;
import com.huigou.topsun.sap.nonProdApply.domain.query.NonProdApplyBaseInfoQueryRequest; import com.huigou.topsun.sap.nonProdApply.domain.query.NonProdApplyBaseInfoQueryRequest;
...@@ -45,4 +46,6 @@ public interface NonProdApplyDeptApplication { ...@@ -45,4 +46,6 @@ public interface NonProdApplyDeptApplication {
//保存部门分发信息 //保存部门分发信息
void saveDeptStaff(List<Map<String, String>> deptStaffList,String bussinessId,String genericName); void saveDeptStaff(List<Map<String, String>> deptStaffList,String bussinessId,String genericName);
//保存待办消息
void saveBsnMessageData(NonProdApplyBaseInfo baseInfo, SapNonProdApplyDept applyDept, Operator operator,String message);
} }
\ No newline at end of file
...@@ -348,88 +348,10 @@ public class NonProdApplyApplicationImpl extends FlowBroker implements NonProdA ...@@ -348,88 +348,10 @@ public class NonProdApplyApplicationImpl extends FlowBroker implements NonProdA
NonProdApplyBaseInfo nonProdApplyBaseInfo = nonProdApplyBaseInfoRepository.findOne(id); NonProdApplyBaseInfo nonProdApplyBaseInfo = nonProdApplyBaseInfoRepository.findOne(id);
SapNonProdApplyDept applyDept=nonProdApplyDeptApplication.getNonProdApplyDeptByBaseInfoId(nonProdApplyBaseInfo.getId()); SapNonProdApplyDept applyDept=nonProdApplyDeptApplication.getNonProdApplyDeptByBaseInfoId(nonProdApplyBaseInfo.getId());
sendSapData(nonProdApplyBaseInfo,applyDept); // nonProdApplyDeptApplication.sendSapData(nonProdApplyBaseInfo,applyDept);
return ""; return "";
} }
/**
* 远程调用sap接口,传递数据
*/
public void sendSapData(NonProdApplyBaseInfo prodApplyBaseInfo,SapNonProdApplyDept applyDept) {
Map<String, Object> map = new HashMap<>();
BsnMessageSponsor bsnMessageSponsor=bsnMessageSponsorRepository.findByBusinessId(applyDept.getApplyDeptId());
boolean canSended=true;
if (bsnMessageSponsor!=null){
List<BsnMessageExecute> bsnMsgList = bsnMessageExecuteRepository.findAllByMessageSponsorId(bsnMessageSponsor.getId());
for (BsnMessageExecute bsnMessageExecute : bsnMsgList) {
if (!"system".equals(bsnMessageExecute.getBusinessCode())&&bsnMessageExecute.getActive() == 0) {
canSended=false;
break;
}
}
}
if (!canSended){
throw new RuntimeException("业务部门数据没有处理完,暂时不能传输!");
}
ProdApplyToSapVO sapVO=new ProdApplyToSapVO();
ClassHelper.copyProperties(prodApplyBaseInfo,sapVO);
ClassHelper.copyProperties(applyDept,sapVO);
sapVO.setUpdkz("I");
Map<String,Object> unitsaleMap = new HashMap<>();
List<Map<String,Object>> unitMapList = new ArrayList<>();
//销售单位转换
unitsaleMap.put("MEINH",sapVO.getVrkme());
unitsaleMap.put("UMREZ",sapVO.getUmrez());
unitsaleMap.put("UMREN",sapVO.getUmren()); //去掉sale lxh 03.29
unitsaleMap.put("MEINS",sapVO.getMeins());
unitMapList.add(unitsaleMap);
sapVO.setMapList(unitMapList);
ObjectMapper objectMapper = new ObjectMapper();
String url = "bd_mastdata/material";
String busiType="物料主数据推送SAP";
if ("product".equals(prodApplyBaseInfo.getKind())){
url = "bd_mastdata/material02";
busiType="产品主数据推送SAP";
}
List<ProdApplyToSapVO> mapList = new ArrayList<>();
mapList.add(sapVO);
//日志记录
Map<String, Object> resultMap = new HashMap<>();
resultMap.put("businessType", busiType);
resultMap.put("businessId", prodApplyBaseInfo.getId());
resultMap.put("parameter", JSON.toJSONString(map));
resultMap.put("sequence", resultMap.get("row"));
try {
String result = defaultHttpClient.execute(mapList, url);
List<Map<String, Object>> resultList = objectMapper.readValue(result, new TypeReference<List<Map<String, Object>>>() {
});
Map<String, Object> backMap = resultList.get(0);
// resultMap.put("businessType", busiType);
// resultMap.put("parameter", JSON.toJSONString(map));
// resultMap.put("businessId", prodApplyBaseInfo.getId());
if ("S".equals(backMap.get("TYPE"))) {
resultMap.put("type", "S");
resultMap.put("message", applyDept.getMatnr()+":"+backMap.get("MESSAGE"));
if (!"product".equals(prodApplyBaseInfo.getKind())) {
applyDept.setMatnr((String) backMap.get("MESSAGE_V1"));
}
nonProdApplyDeptApplication.save(applyDept);
} else {
//更改分发状态
prodApplyBaseInfo.setDistribute(0);
nonProdApplyBaseInfoRepository.save(prodApplyBaseInfo);
throw new RuntimeException("数据传输失败,请稍后手动重试!" + backMap.get("MESSAGE"));
}
} catch (Exception e) {
resultMap.put("type", "E");
resultMap.put("message",applyDept.getMatnr()+":"+e.getMessage());
//sapMutualEpLogApplication.saveSapMutualEpLog(resultMap);
throw new RuntimeException("数据传输失败请检查数据后重试!" + e.getMessage());
} finally {
sapMutualEpLogApplication.saveSapMutualEpLog(resultMap);
}
}
public Map<String, Object> slicedNonApplyBaseInfoByMatnr(NonProdApplyBaseInfoQueryRequest query){ public Map<String, Object> slicedNonApplyBaseInfoByMatnr(NonProdApplyBaseInfoQueryRequest query){
......
package com.huigou.topsun.sap.nonProdApply.application.impl; package com.huigou.topsun.sap.nonProdApply.application.impl;
import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.huigou.context.Operator;
import com.huigou.topsun.base.bsnMessage.appliction.BsnMessageApplication; import com.huigou.topsun.base.bsnMessage.appliction.BsnMessageApplication;
import com.huigou.topsun.base.bsnMessage.domain.*; import com.huigou.topsun.base.bsnMessage.domain.*;
import com.huigou.topsun.base.bsnMessage.repository.BsnMessageSponsorRepository;
import com.huigou.topsun.sap.common.DefaultHttpClient;
import com.huigou.topsun.sap.common.application.SapMutualEpLogApplication;
import com.huigou.topsun.sap.nonProdApply.application.NonProdApplyDeptApplication; import com.huigou.topsun.sap.nonProdApply.application.NonProdApplyDeptApplication;
import com.huigou.topsun.sap.nonProdApply.domain.NonProdApplyBaseInfo; import com.huigou.topsun.sap.nonProdApply.domain.NonProdApplyBaseInfo;
...@@ -15,12 +20,14 @@ import com.huigou.topsun.sap.nonProdApply.repository.NonProdApplyBaseInfoReposit ...@@ -15,12 +20,14 @@ import com.huigou.topsun.sap.nonProdApply.repository.NonProdApplyBaseInfoReposit
import com.huigou.topsun.sap.nonProdApply.repository.NonProdApplyDeptRepository; import com.huigou.topsun.sap.nonProdApply.repository.NonProdApplyDeptRepository;
import com.huigou.uasp.bmp.common.application.BaseApplication; import com.huigou.uasp.bmp.common.application.BaseApplication;
import com.huigou.uasp.bmp.operator.OperatorApplication;
import com.huigou.util.ClassHelper; import com.huigou.util.ClassHelper;
import com.huigou.util.SDO; import com.huigou.util.SDO;
import com.huigou.util.StringUtil; import com.huigou.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.persistence.Column; import javax.persistence.Column;
import java.util.*; import java.util.*;
...@@ -34,6 +41,17 @@ public class NonProdApplyDeptApplicationImpl extends BaseApplication implements ...@@ -34,6 +41,17 @@ public class NonProdApplyDeptApplicationImpl extends BaseApplication implements
@Autowired @Autowired
NonProdApplyBaseInfoRepository nonProdApplyBaseInfoRepository; NonProdApplyBaseInfoRepository nonProdApplyBaseInfoRepository;
@Autowired
com.huigou.topsun.base.bsnMessage.repository.BsnMessageExecuteRepository bsnMessageExecuteRepository;
@Autowired
BsnMessageSponsorRepository bsnMessageSponsorRepository;
@Autowired
DefaultHttpClient defaultHttpClient;
@Autowired
SapMutualEpLogApplication sapMutualEpLogApplication;
@Resource
private OperatorApplication operatorApplication;
@Override @Override
public Map<String,Object> saveSapNonProdApplyDept(SDO sdo){ public Map<String,Object> saveSapNonProdApplyDept(SDO sdo){
Map<String,Object> map = new HashMap<>(); Map<String,Object> map = new HashMap<>();
...@@ -129,6 +147,21 @@ public class NonProdApplyDeptApplicationImpl extends BaseApplication implements ...@@ -129,6 +147,21 @@ public class NonProdApplyDeptApplicationImpl extends BaseApplication implements
} }
if (active!=null&&active == 1){//各部门提交后,隐藏消息 if (active!=null&&active == 1){//各部门提交后,隐藏消息
bsnMessageApplication.submitTask(meId); bsnMessageApplication.submitTask(meId);
//如果所有的业务部门处理完 ,则推送SAP
BsnMessageSponsor bsnMessageSponsor=bsnMessageSponsorRepository.findByBusinessId(nonProdApplyDept.getApplyDeptId());
boolean canSended=true;
if (bsnMessageSponsor!=null){
List<BsnMessageExecute> bsnMsgList = bsnMessageExecuteRepository.findAllByMessageSponsorId(bsnMessageSponsor.getId());
for (BsnMessageExecute bsnMessageExecute : bsnMsgList) {
if (!"system".equals(bsnMessageExecute.getBusinessCode())&&bsnMessageExecute.getActive() == 0) {
canSended=false;
break;
}
}
}
if (canSended) {
sendSapData(nonProdApplyBaseInfo, nonProdApplyDept);
}
} }
map.put("applyDeptId",nonProdApplyDept.getApplyDeptId()); map.put("applyDeptId",nonProdApplyDept.getApplyDeptId());
return map; return map;
...@@ -219,4 +252,128 @@ public class NonProdApplyDeptApplicationImpl extends BaseApplication implements ...@@ -219,4 +252,128 @@ public class NonProdApplyDeptApplicationImpl extends BaseApplication implements
} }
bsnMessageApplication.rejectTasksByMeId(map,meId); bsnMessageApplication.rejectTasksByMeId(map,meId);
} }
/**
* 远程调用sap接口,传递数据
*/
public void sendSapData(NonProdApplyBaseInfo baseInfo,SapNonProdApplyDept applyDept) {
Map<String, Object> map = new HashMap<>();
ProdApplyToSapVO sapVO=new ProdApplyToSapVO();
ClassHelper.copyProperties(baseInfo,sapVO);
ClassHelper.copyProperties(applyDept,sapVO);
sapVO.setUpdkz("I");
Map<String,Object> unitsaleMap = new HashMap<>();
List<Map<String,Object>> unitMapList = new ArrayList<>();
//销售单位转换
unitsaleMap.put("MEINH",sapVO.getVrkme());
unitsaleMap.put("UMREZ",sapVO.getUmrez());
unitsaleMap.put("UMREN",sapVO.getUmren()); //去掉sale lxh 03.29
unitsaleMap.put("MEINS",sapVO.getMeins());
unitMapList.add(unitsaleMap);
sapVO.setMapList(unitMapList);
ObjectMapper objectMapper = new ObjectMapper();
String url = "bd_mastdata/material";
String busiType="物料主数据推送SAP";
if ("product".equals(baseInfo.getKind())){
url = "bd_mastdata/material02";
busiType="产品主数据推送SAP";
}
List<ProdApplyToSapVO> mapList = new ArrayList<>();
mapList.add(sapVO);
//日志记录
Map<String, Object> backMap = new HashMap<>();
backMap.put("businessType", busiType);
backMap.put("businessId", baseInfo.getId());
backMap.put("parameter", JSON.toJSONString(map));
backMap.put("sequence", backMap.get("row"));
try {
String result = defaultHttpClient.execute(mapList, url);
List<Map<String, Object>> resultList = objectMapper.readValue(result, new TypeReference<List<Map<String, Object>>>() {
});
Map<String, Object> returnMap = resultList.get(0);
mapCopy(backMap,returnMap);
// resultMap.put("businessType", busiType);
// resultMap.put("parameter", JSON.toJSONString(map));
// resultMap.put("businessId", prodApplyBaseInfo.getId());
if ("S".equals(backMap.get("TYPE"))) {
backMap.put("type", "S");
backMap.put("message", applyDept.getMatnr()+":"+backMap.get("MESSAGE"));
if (!"product".equals(baseInfo.getKind())) {
applyDept.setMatnr((String) backMap.get("MESSAGE_V1"));
}
this.nonProdApplyDeptRepository.save(applyDept);
} else {
//更改分发状态
baseInfo.setDistribute(0);
nonProdApplyBaseInfoRepository.save(baseInfo);
throw new RuntimeException("数据传输失败,请稍后手动重试!" + backMap.get("MESSAGE"));
}
} catch (Exception e) {
backMap.put("type", "E");
backMap.put("message",applyDept.getMatnr()+":"+e.getMessage());
//sapMutualEpLogApplication.saveSapMutualEpLog(resultMap);
throw new RuntimeException("数据传输失败请检查数据后重试!" + e.getMessage());
} finally {
sapMutualEpLogApplication.saveSapMutualEpLog(backMap);
// String createdById = "5EEB2DC861694A65933CB4CE9A8D870A@C18E23AAAA6940E09DF7C122332C51E0";
Operator operator = operatorApplication.createOperatorByPersonMemberId(baseInfo.getPersonMemberId());
saveBsnMessageData(baseInfo,applyDept,operator,backMap.get("message").toString());
}
}
final void mapCopy(Map resultMap, Map paramMap) {
if (resultMap==null) resultMap=new HashMap();
if (paramMap==null ) return ;
Iterator it=paramMap.entrySet().iterator();
while (it.hasNext()){
Map.Entry entry=(Map.Entry)it.next();
Object key=entry.getKey();
resultMap.put(key,paramMap.get(key)!=null?paramMap.get(key):"");
}
}
//保存待办的消息
public void saveBsnMessageData(NonProdApplyBaseInfo baseInfo, SapNonProdApplyDept applyDept, Operator operator,String message) {
BsnMessageSponsor bsnMessageSponsor=bsnMessageSponsorRepository.findByBusinessId(applyDept.getApplyDeptId());
if (bsnMessageSponsor==null) {
bsnMessageSponsor = new BsnMessageSponsor();
bsnMessageSponsor.setTaskSponsor(operator.getLoginUser().getId());
bsnMessageSponsor.setTitle(baseInfo.getGenericName());//通用品名
bsnMessageSponsor.setExecutorUrl("sapNonProdApplyNext/forwardNonProdApplyNext.do?prod=1&isReadOnly=false");
bsnMessageSponsor.setBusinessId(applyDept.getApplyDeptId());
bsnMessageSponsor.setCreateDate(new Date());
bsnMessageSponsor.setStatus(0);
}
//List<Map<String, String>> deptStaffList=new ArrayList<>();
//Map <String,String>map=new HashMap<String, String>();
// map.put("");
//deptStaffList.add(map);
// for (Map<String, String> stringMap : deptStaffList) {
BsnMessageExecute messageExecute = new BsnMessageExecute();
String userCode = operator.getPersonMemberId();//stringMap.get("userCode");
String deptName = operator.getDeptName();//stringMap.get("deptName");
String deptCode = operator.getDeptCode();//stringMap.get("deptCode");
String[] split = userCode.split("@");
messageExecute.setTaskExecute(split[0]);
messageExecute.setBusinessCode(deptCode);
messageExecute.setActive(ActiveStatus.UNFINISHED.getValue());
messageExecute.setUpdateDate(new Date());
// if ("product".equals(baseInfo.getKind())) {
// messageExecute.setTaskDescribe(deptName + "产品数据维护");
// } else {
messageExecute.setTaskDescribe("错误"+message);
// }
bsnMessageApplication.saveBsnMessageSponsor(bsnMessageSponsor);
messageExecute.setMessageSponsorId(bsnMessageSponsor.getId());
List<BsnMessageExecute> executes = new ArrayList<>();
executes.add(messageExecute);
bsnMessageApplication.saveBsnMessageExecute(executes);
}
} }
...@@ -230,6 +230,16 @@ public class NonProdApplyNextController extends CommonController { ...@@ -230,6 +230,16 @@ public class NonProdApplyNextController extends CommonController {
this.putAttribute("busiLens",slen); this.putAttribute("busiLens",slen);
String businessCode=circulate.get("deptCode").toString(); String businessCode=circulate.get("deptCode").toString();
switch (businessCode) { switch (businessCode) {
case "INIT_DPT": //推送SAP错误 产生的待办消息
baseInfo.setApplyType("0");
if (baseInfo.getMaintenanceType().equals("modify")) {
baseInfo.setApplyType("1");
} else if (baseInfo.getMaintenanceType().equals("extend")) {
baseInfo.setApplyType("2");
}
this.putAttribute("applyType",baseInfo.getApplyType());
this.putAttribute("active",0);
return forward("nonProdApplyNext", nonProdApplyDept);
case "K": case "K":
this.putAttribute("active",2); //已经分发的 填写基本数据 this.putAttribute("active",2); //已经分发的 填写基本数据
return forward("nonProdApplyNext", nonProdApplyDept); return forward("nonProdApplyNext", nonProdApplyDept);
......
...@@ -115,7 +115,7 @@ public class SapPurchaseApplicationImpl extends FlowBroker implements SapPurchas ...@@ -115,7 +115,7 @@ public class SapPurchaseApplicationImpl extends FlowBroker implements SapPurchas
} }
@Transactional @Transactional
private void updateStatus(String bizId, BizBillStatus status) { protected void updateStatus(String bizId, BizBillStatus status) {
Assert.hasText(bizId, CommonDomainConstants.ID_NOT_BLANK); Assert.hasText(bizId, CommonDomainConstants.ID_NOT_BLANK);
this.commonDomainService.updateStatus(SapPurchase.class, bizId, status.getId()); this.commonDomainService.updateStatus(SapPurchase.class, bizId, status.getId());
} }
......
...@@ -119,7 +119,7 @@ public class SapPurchaseApprovalApplicationImpl extends FlowBroker implements Sa ...@@ -119,7 +119,7 @@ public class SapPurchaseApprovalApplicationImpl extends FlowBroker implements Sa
} }
@Transactional @Transactional
private void updateStatus(String bizId, BizBillStatus status) { protected void updateStatus(String bizId, BizBillStatus status) {
Assert.hasText(bizId, CommonDomainConstants.ID_NOT_BLANK); Assert.hasText(bizId, CommonDomainConstants.ID_NOT_BLANK);
this.commonDomainService.updateStatus(SapPurchaseApproval.class, bizId, status.getId()); this.commonDomainService.updateStatus(SapPurchaseApproval.class, bizId, status.getId());
} }
......
...@@ -5,6 +5,7 @@ import com.fasterxml.jackson.core.type.TypeReference; ...@@ -5,6 +5,7 @@ import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.huigou.context.Operator; import com.huigou.context.Operator;
import com.huigou.context.OrgUnit; import com.huigou.context.OrgUnit;
import com.huigou.context.ThreadLocalUtil;
import com.huigou.data.domain.model.CommonDomainConstants; import com.huigou.data.domain.model.CommonDomainConstants;
import com.huigou.data.query.model.QueryDescriptor; import com.huigou.data.query.model.QueryDescriptor;
import com.huigou.data.query.model.QueryModel; import com.huigou.data.query.model.QueryModel;
...@@ -23,10 +24,17 @@ import com.huigou.topsun.sap.purchaseOrder.repository.SapPurchaseOrderRepository ...@@ -23,10 +24,17 @@ import com.huigou.topsun.sap.purchaseOrder.repository.SapPurchaseOrderRepository
import com.huigou.uasp.bmp.common.BizBillStatus; import com.huigou.uasp.bmp.common.BizBillStatus;
import com.huigou.uasp.bmp.operator.OperatorApplication; import com.huigou.uasp.bmp.operator.OperatorApplication;
import com.huigou.uasp.bpm.FlowBroker; import com.huigou.uasp.bpm.FlowBroker;
import com.huigou.uasp.bpm.ProcessAction;
import com.huigou.uasp.bpm.ProcessStartModel;
import com.huigou.uasp.bpm.engine.application.WorkflowApplication;
import com.huigou.util.ClassHelper; import com.huigou.util.ClassHelper;
import com.huigou.util.Constants;
import com.huigou.util.SDO; import com.huigou.util.SDO;
import org.activiti.engine.delegate.DelegateExecution; import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.DelegateTask; import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.impl.persistence.entity.ExecutionEntity;
import org.activiti.engine.impl.persistence.entity.TaskEntity;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -53,6 +61,10 @@ public class SapPurchaseOrderApplicationImpl extends FlowBroker implements SapPu ...@@ -53,6 +61,10 @@ public class SapPurchaseOrderApplicationImpl extends FlowBroker implements SapPu
@Autowired @Autowired
SapPurchaseApprovalApplicationImpl sapPurchaseApprovalApplication; SapPurchaseApprovalApplicationImpl sapPurchaseApprovalApplication;
@Autowired
private WorkflowApplication workflowApplication;
@Override @Override
protected String saveBizAndApprovalData() { protected String saveBizAndApprovalData() {
super.saveBizAndApprovalData(); super.saveBizAndApprovalData();
...@@ -113,7 +125,7 @@ public class SapPurchaseOrderApplicationImpl extends FlowBroker implements SapPu ...@@ -113,7 +125,7 @@ public class SapPurchaseOrderApplicationImpl extends FlowBroker implements SapPu
} }
@Transactional @Transactional
private void updateStatus(String bizId, BizBillStatus status) { protected void updateStatus(String bizId, BizBillStatus status) {
Assert.hasText(bizId, CommonDomainConstants.ID_NOT_BLANK); Assert.hasText(bizId, CommonDomainConstants.ID_NOT_BLANK);
this.commonDomainService.updateStatus(SapPurchaseOrder.class, bizId, status.getId()); this.commonDomainService.updateStatus(SapPurchaseOrder.class, bizId, status.getId());
} }
...@@ -182,7 +194,7 @@ public class SapPurchaseOrderApplicationImpl extends FlowBroker implements SapPu ...@@ -182,7 +194,7 @@ public class SapPurchaseOrderApplicationImpl extends FlowBroker implements SapPu
SapPurchaseOrder sapPurchaseOrder = new SapPurchaseOrder(); SapPurchaseOrder sapPurchaseOrder = new SapPurchaseOrder();
BeanUtil.copyProperties(sapPurchaseOrderVo, sapPurchaseOrder); BeanUtil.copyProperties(sapPurchaseOrderVo, sapPurchaseOrder);
//初始化用户信息 //初始化用户信息
String createdById = "5EEB2DC861694A65933CB4CE9A8D870A@C18E23AAAA6940E09DF7C122332C51E0"; /* String createdById = "5EEB2DC861694A65933CB4CE9A8D870A@C18E23AAAA6940E09DF7C122332C51E0";
Operator operator = operatorApplication.createOperatorByPersonMemberId(createdById); Operator operator = operatorApplication.createOperatorByPersonMemberId(createdById);
sapPurchaseOrder.setDefaultValues(new OrgUnit(operator.getFullId(), operator.getFullName())); sapPurchaseOrder.setDefaultValues(new OrgUnit(operator.getFullId(), operator.getFullName()));
...@@ -191,9 +203,14 @@ public class SapPurchaseOrderApplicationImpl extends FlowBroker implements SapPu ...@@ -191,9 +203,14 @@ public class SapPurchaseOrderApplicationImpl extends FlowBroker implements SapPu
sapPurchaseOrder.setId(bizId); sapPurchaseOrder.setId(bizId);
//映射双方字段 //映射双方字段
sapPurchaseOrder.setFillinDate(sapPurchaseOrderVo.getAedat()); sapPurchaseOrder.setFillinDate(sapPurchaseOrderVo.getAedat());
*/
sapPurchaseOrder = this.sapPurchaseOrderRepository.save(sapPurchaseOrder); //发起流程
sapPurchaseOrder =mannualStartWorkflow(sapPurchaseOrder);
purchaseOrderId = sapPurchaseOrder.getId(); purchaseOrderId = sapPurchaseOrder.getId();
// sapPurchaseOrder = this.sapPurchaseOrderRepository.save(sapPurchaseOrder);
// purchaseOrderId = sapPurchaseOrder.getId();
} else { } else {
//数据第n次接收覆盖上一次数据 //数据第n次接收覆盖上一次数据
BeanUtil.copyProperties(sapPurchaseOrderVo, purchaseOrder); BeanUtil.copyProperties(sapPurchaseOrderVo, purchaseOrder);
...@@ -212,9 +229,73 @@ public class SapPurchaseOrderApplicationImpl extends FlowBroker implements SapPu ...@@ -212,9 +229,73 @@ public class SapPurchaseOrderApplicationImpl extends FlowBroker implements SapPu
purchaseOrderItems.add(sapPurchaseApprovalItem); purchaseOrderItems.add(sapPurchaseApprovalItem);
}); });
sapPurchaseOrderItemApplication.saveSapPurchaseOrderItems(purchaseOrderId, purchaseOrderItems); sapPurchaseOrderItemApplication.saveSapPurchaseOrderItems(purchaseOrderId, purchaseOrderItems);
} }
/**
* 启动流程
*/
private SapPurchaseOrder mannualStartWorkflow(SapPurchaseOrder purchaseOrder) {
Operator operator = null;
operator = ThreadLocalUtil.getOperator();
if (operator == null) {
String createdById = "5EEB2DC861694A65933CB4CE9A8D870A@C18E23AAAA6940E09DF7C122332C51E0";
operator = operatorApplication.createOperatorByPersonMemberId(createdById);
ThreadLocalUtil.putOperator(operator);
}
// Assert.notNull(operator, "未获取到当前操作用户,无法创建流程");
SDO sdo = ThreadLocalUtil.getVariable(Constants.SDO, SDO.class);
if (sdo == null) {
sdo = new SDO();
}
try {
// 业务数据
Map<String, Object> map = ClassHelper.beanToMap(purchaseOrder);
sdo.setProperties(map);
// 启动流程的必要参数
sdo.putProperty("fullId", operator.getFullId());
sdo.putProperty("organId", operator.getOrgId());
sdo.putProperty("organName", operator.getOrgName());
sdo.putProperty("deptId", operator.getDeptId());
sdo.putProperty("deptName", operator.getDeptName());
sdo.putProperty("positionId", operator.getPositionId());
sdo.putProperty("positionName", operator.getPositionName());
sdo.putProperty("personMemberId", operator.getPersonMemberId());
sdo.putProperty("personMemberName", operator.getPersonMemberName());
sdo.putProperty("processAction", ProcessAction.SAVE);
sdo.putProperty("procUnitId", "");
// sdo.putProperty("bizId", purchaseOrder.getId());
sdo.putProperty("createdDate", new Date());
sdo.putProperty("fillinDate", new Date());
sdo.putProperty("billCode", purchaseOrder.getBillCode());
ThreadLocalUtil.putVariable(Constants.SDO, sdo);
Map<String, Object> variables = new HashMap<>();
variables.put("startModel", ProcessStartModel.MANUAL.getId());
variables.put("executorFullId", operator.getFullId());
variables.put("executorFullName", operator.getFullName());
ThreadLocalUtil.putOperator(operator);
ExecutionEntity pi = (ExecutionEntity) workflowApplication.startProcessInstanceByKey(PROCESS_DEFINITION_KEY, null, variables);
// 业务参数
TaskEntity applyTask = pi.getTasks().get(0);
sdo.putProperty("processAction", ProcessAction.ADVANCE);
sdo.putProperty("bizId", pi.getBusinessKey());
sdo.putProperty("id", pi.getBusinessKey());
sdo.putProperty("statusId", BizBillStatus.APPLYING.getId());
ThreadLocalUtil.removeVariable("_approvalParameter_");
ThreadLocalUtil.putVariable(Constants.SDO, sdo);
workflowApplication.advance(applyTask.getId(), Collections.emptyMap());
return this.sapPurchaseOrderRepository.findOne(pi.getBusinessKey());
}catch(Exception ex){
ex.printStackTrace();
throw ex;
}
}
/** /**
* 远程调用sap接口,传递数据 * 远程调用sap接口,传递数据
*/ */
......
...@@ -12,8 +12,8 @@ ...@@ -12,8 +12,8 @@
LEFT JOIN bsn_message_sponsor t2 ON t2.id = t.message_sponsor_id LEFT JOIN bsn_message_sponsor t2 ON t2.id = t.message_sponsor_id
LEFT JOIN sap_non_prod_apply_dept ad ON ad.apply_dept_id = t2.business_id LEFT JOIN sap_non_prod_apply_dept ad ON ad.apply_dept_id = t2.business_id
left join sap_non_prod_apply_base_info bs on bs.id=ad.base_info_id left join sap_non_prod_apply_base_info bs on bs.id=ad.base_info_id
WHERE t.active IN (0, 3) and (bs.distribute=1 or (t.business_code='INIT_DPT' and bs.kind='product')) WHERE t.active IN (0, 3) and (bs.distribute=1 or t.business_code='INIT_DPT')
and task_execute = :taskExecute and task_execute = :taskExecute order by t.update_date desc
</sql-query> </sql-query>
</query> </query>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment