|
|
@@ -0,0 +1,326 @@
|
|
|
+package com.yw.bpm.client.action;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+import org.springframework.context.ApplicationContext;
|
|
|
+
|
|
|
+import com.yw.bpm.client.service.BpmClientFlowSubProcessService;
|
|
|
+import com.yw.bpm.core.model.ProcessResult;
|
|
|
+import com.yw.bpm.core.service.CoreService;
|
|
|
+import com.yw.bpm.flow.model.FlowModel;
|
|
|
+import com.yw.bpm.instance.model.FileInfo;
|
|
|
+import com.yw.bpm.instance.model.FlowInstance;
|
|
|
+import com.yw.bpm.instance.model.TacheInstance;
|
|
|
+import com.yw.bpm.instance.service.FlowService;
|
|
|
+import com.yw.bpm.path.model.PathModel;
|
|
|
+import com.yw.bpm.system.model.SystemGroupUser;
|
|
|
+import com.yw.bpm.system.util.StringUtil;
|
|
|
+import com.yw.bpm.system.util.SystemUtil;
|
|
|
+import com.yw.bpm.tache.model.TacheModel;
|
|
|
+import com.yw.bpm.task.model.Task;
|
|
|
+import com.yw.bpm.zxlc.service.ZxlcLinkUserService;
|
|
|
+import com.yw.contract.contract.model.ContractPurchaseDetail;
|
|
|
+import com.yw.contract.contract.model.ContractPurchaseForm;
|
|
|
+import com.yw.contract.contract.service.ContractPurchaseService;
|
|
|
+import com.yw.core.clientImpl.model.ResultVo;
|
|
|
+import com.yw.core.clientImpl.service.RequestAbs;
|
|
|
+import com.yw.core.framework.util.StringUtils;
|
|
|
+import com.yw.core.session.AppSession;
|
|
|
+import com.yw.core.utils.DateUtil;
|
|
|
+import com.yw.core.utils.RegisterCodeImpl;
|
|
|
+import com.yw.core.utils.SpringUtil;
|
|
|
+import com.yw.eu.base.code.service.CodeRuleService;
|
|
|
+import com.yw.eu.base.user.dao.GroupXUserDao;
|
|
|
+import com.yw.eu.base.user.dao.UserDao;
|
|
|
+import com.yw.eu.base.user.model.GroupXUser;
|
|
|
+import com.yw.eu.base.user.model.User;
|
|
|
+import com.yw.eu.base.user.service.UserService;
|
|
|
+
|
|
|
+import net.sf.json.JSONArray;
|
|
|
+import net.sf.json.JSONObject;
|
|
|
+import net.sf.json.JsonConfig;
|
|
|
+
|
|
|
+/**
|
|
|
+ * mes发起流程接口
|
|
|
+ *
|
|
|
+ * @ClassName: BpmClientFlowStartAction
|
|
|
+ * @Description:
|
|
|
+ * @author ouyj
|
|
|
+ *
|
|
|
+ */
|
|
|
+public class BpmClientFlowStartFromMesAction extends RequestAbs {
|
|
|
+
|
|
|
+ public final String serviceId = "bpm_FlowStartFromMes";
|
|
|
+
|
|
|
+ private ApplicationContext cxt = null;
|
|
|
+ @Override
|
|
|
+ public String getResult() {
|
|
|
+ // 获取请求的参数
|
|
|
+ String param = getParameters();
|
|
|
+ JSONObject json = JSONObject.fromObject(param);
|
|
|
+ String userName = json.getString("userName");
|
|
|
+ String unitId = json.getString("unitId");
|
|
|
+ String modelId = json.getString("modelId");
|
|
|
+ JSONObject formInfo = JSONObject.fromObject(json.get("formInfo"));
|
|
|
+ if (null == cxt) {
|
|
|
+ cxt = AppSession.getApplicationContext();
|
|
|
+ }
|
|
|
+ ResultVo rv = null;
|
|
|
+
|
|
|
+ UserService userService = (UserService) SpringUtil.getApplicationContext().getBean("userService");
|
|
|
+ FlowService flowService = (FlowService) cxt.getBean("bpmFlowService");
|
|
|
+ BpmClientFlowSubProcessService bpmClientFlowSubProcessService = (BpmClientFlowSubProcessService) cxt
|
|
|
+ .getBean("bpmClientFlowSubProcessService");
|
|
|
+ CoreService bpmCoreService = (CoreService) cxt.getBean("bpmCoreService");
|
|
|
+ CodeRuleService codeRuleService = (CodeRuleService) cxt.getBean("codeRuleService");
|
|
|
+ UserDao userDao = (UserDao) cxt.getBean("userDao");
|
|
|
+ GroupXUserDao groupXUserDao = (GroupXUserDao) cxt.getBean("groupXUserDao");
|
|
|
+ ContractPurchaseService contractPurchaseService = (ContractPurchaseService) cxt.getBean("contractPurchaseService");
|
|
|
+ User user = userDao.loadUserByUserName(userName, unitId);
|
|
|
+ user.setGroupXUsers(userService.loadFollowGroupXuser(user.getUseId()));
|
|
|
+ if(user != null){
|
|
|
+ try {
|
|
|
+ GroupXUser gxuser = groupXUserDao.loadOwnGroupXuser(user.getUseId(), false);
|
|
|
+ //流程信息
|
|
|
+ Map<String, Object> result = flowService.toStart(modelId);
|
|
|
+
|
|
|
+ Map<String, Object> flowMap = new HashMap<String, Object>();
|
|
|
+ List<Map<String, String>> nextTmodelsList = new ArrayList<Map<String, String>>();
|
|
|
+ List<Map<String, String>> nextHandTmodelsList = new ArrayList<Map<String, String>>();
|
|
|
+
|
|
|
+ FlowModel fmodel = (FlowModel) result.get("fmodel");
|
|
|
+ flowMap.put("modelId", fmodel.getModelId());
|
|
|
+ flowMap.put("formId", fmodel.getFormId().getFormId());
|
|
|
+
|
|
|
+ TacheModel tmodel = (TacheModel) result.get("tmodel");
|
|
|
+ flowMap.put("tmodelId", tmodel.getTmodelId());
|
|
|
+ flowMap.put("isMoreIns", tmodel.getIsMoreIns().getValue());
|
|
|
+ flowMap.put("pathJudgeType", tmodel.getPathJudgeType().getValue());
|
|
|
+ flowMap.put("reqOffice", tmodel.getReqOffice());
|
|
|
+
|
|
|
+ if (result.get("nextTmodels") != null && !"{}".equals(result.get("nextTmodels").toString())) {
|
|
|
+ List<PathModel> list = (List<PathModel>) (result.get("nextTmodels"));
|
|
|
+ if (list.size() > 0) {
|
|
|
+ for (PathModel pm : list) {
|
|
|
+ Map<String, String> map = new HashMap<String, String>();
|
|
|
+ map.put("nextTmodelId", pm.getNextTmodelId().getTmodelId());
|
|
|
+ map.put("nextTmodelName", pm.getNextTmodelId().getTmodelName());
|
|
|
+ nextTmodelsList.add(map);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (result.get("nextHandTmodels") != null && !"{}".equals(result.get("nextHandTmodels").toString())) {
|
|
|
+ List<PathModel> list = (List<PathModel>) (result.get("nextHandTmodels"));
|
|
|
+ if (list.size() > 0) {
|
|
|
+ for (PathModel pm : list) {
|
|
|
+ Map<String, String> map = new HashMap<String, String>();
|
|
|
+ map.put("nextTmodelId", pm.getNextTmodelId().getTmodelId());
|
|
|
+ map.put("nextTmodelName", pm.getNextTmodelId().getTmodelName());
|
|
|
+ nextHandTmodelsList.add(map);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //提交流程
|
|
|
+
|
|
|
+ String creator = String.valueOf(user.getUseId());
|
|
|
+ String name = user.getName();
|
|
|
+
|
|
|
+ String groupid = user.getGroupid();
|
|
|
+ String gxid = String.valueOf(gxuser.getId());
|
|
|
+
|
|
|
+ String formInsId = SystemUtil.getSeq(); // 表单实例id
|
|
|
+ String insId = SystemUtil.getSeq(); // 流程实例id
|
|
|
+
|
|
|
+
|
|
|
+ String formId = fmodel.getFormId().getFormId();
|
|
|
+
|
|
|
+ if (!"".equals(formId)) {
|
|
|
+ //提交表单
|
|
|
+ String initiator = name;
|
|
|
+ String department = gxuser.getGroupName();
|
|
|
+ String depid = groupid;
|
|
|
+ String applyDate = DateUtil.getCurrDate("yyyy-MM-dd");
|
|
|
+
|
|
|
+ if("200001".equals(formId)){
|
|
|
+ ContractPurchaseForm contractPurchaseForm = new ContractPurchaseForm();
|
|
|
+ contractPurchaseForm.setInitiator(initiator);
|
|
|
+ contractPurchaseForm.setDepartment(department);
|
|
|
+ contractPurchaseForm.setDepid(depid);
|
|
|
+ contractPurchaseForm.setApplyDate(applyDate);
|
|
|
+
|
|
|
+ contractPurchaseForm.setUniversalid(Long.valueOf(formInsId));
|
|
|
+ contractPurchaseForm.setlFormInsId(Long.valueOf(formInsId));
|
|
|
+ contractPurchaseForm.setIsValid(9);
|
|
|
+ contractPurchaseForm.setCreateTime(new Date());
|
|
|
+ contractPurchaseForm.setCreator(user.getUseId());
|
|
|
+ contractPurchaseForm.setUnitId(Long.valueOf(unitId));
|
|
|
+
|
|
|
+ contractPurchaseForm.setContractPurchaseNumber(formInfo.optString("applyCode", null));
|
|
|
+ contractPurchaseForm.setContractPurchaseName(formInfo.optString("applyName", null));
|
|
|
+ // 映射明细列表
|
|
|
+ JSONArray lineItems = formInfo.optJSONArray("wmPurchaseApplyLineList");
|
|
|
+ if (lineItems != null && !lineItems.isEmpty()) {
|
|
|
+ contractPurchaseForm.setDetails(convertLineItems(lineItems));
|
|
|
+ }
|
|
|
+ int i = 0;
|
|
|
+ i = contractPurchaseService.addContractPurchaseForm(contractPurchaseForm);
|
|
|
+ if (i < 0) {
|
|
|
+ rv.setReturnCode("-1");
|
|
|
+ rv.setReturnMsg("failed");
|
|
|
+ rv.setReturnParams("表单提交失败!!");
|
|
|
+ return JSONObject.fromObject(rv, config).toString();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ formId = "0";
|
|
|
+ }
|
|
|
+
|
|
|
+ FlowInstance finstance = new FlowInstance();
|
|
|
+ finstance.getCreator().setUserId(creator);
|
|
|
+ finstance.getCreator().setUsername(name);
|
|
|
+ finstance.getGroupid().setGroupId(groupid);
|
|
|
+ finstance.setInsId(insId);
|
|
|
+ finstance.setInsName(name+"的"+fmodel.getModelName());
|
|
|
+ finstance.getModelId().setModelId(fmodel.getModelId());
|
|
|
+ finstance.setFormInsId(formInsId);
|
|
|
+ finstance.getFormId().setFormId(formId);
|
|
|
+ finstance.getState().setValue("1");
|
|
|
+ finstance.getGroupxuserid().setId(gxid);
|
|
|
+
|
|
|
+ String tinsId = SystemUtil.getSeq(); // 环节实例id
|
|
|
+
|
|
|
+ TacheInstance tinstance = new TacheInstance();
|
|
|
+ tinstance.getGroupid().setGroupId(groupid);
|
|
|
+ tinstance.setTinsId(tinsId);
|
|
|
+ tinstance.getModelId().setModelId(fmodel.getModelId());
|
|
|
+ tinstance.setRemark("");
|
|
|
+ tinstance.getUser().setUserId(creator);
|
|
|
+ tinstance.getGroupxuserid().setId(gxid);
|
|
|
+ tinstance.getInsId().setInsId(finstance.getInsId());
|
|
|
+ tinstance.getTmodelId().setTmodelId(tmodel.getTmodelId());
|
|
|
+ tinstance.getState().setValue("2");
|
|
|
+ tinstance.getSe().setValue("1");
|
|
|
+ tinstance.setHasNext("0");
|
|
|
+ tinstance.setParallel("0");
|
|
|
+
|
|
|
+ tinstance.getAuthorizedUser().setUserId("0");
|
|
|
+
|
|
|
+ List<TacheModel> manualTacheModels = new ArrayList<TacheModel>();
|
|
|
+
|
|
|
+ Task task = new Task();
|
|
|
+ task.setInsId(finstance.getInsId());
|
|
|
+ task.setTinsId(tinstance.getTinsId());
|
|
|
+ task.setTaskType("8");
|
|
|
+
|
|
|
+ task.setDistributedUser(String.valueOf(creator));
|
|
|
+
|
|
|
+ List<FileInfo> fileList = new ArrayList<FileInfo>();
|
|
|
+
|
|
|
+ JSONArray jsonusesNames = JSONArray.fromObject("[]");
|
|
|
+ List<Map<String, String>> usesNamesList = JSONArray.toList(jsonusesNames, new HashMap<String, String>(),
|
|
|
+ new JsonConfig());
|
|
|
+
|
|
|
+ List<TacheInstance> nextTinstanceList = new ArrayList<TacheInstance>();
|
|
|
+ if (usesNamesList.size() > 0) {
|
|
|
+ for (Map<String, String> userMap : usesNamesList) {
|
|
|
+ if (userMap != null) {
|
|
|
+ String userid = userMap.get("username");
|
|
|
+ String[] userIdArr = userid.split(",");
|
|
|
+ if (userIdArr.length > 0) {
|
|
|
+ for (String uid : userIdArr) {
|
|
|
+ TacheInstance tache = new TacheInstance();
|
|
|
+ String nextTmodelId = userMap.get("nextTmodelId");
|
|
|
+ tache.getTmodelId().setTmodelId(nextTmodelId);
|
|
|
+ if (!StringUtils.isEmpty(nextTmodelId) && !StringUtils.isEmpty(uid)) {
|
|
|
+ tache.getUser().setUserId(uid.replace("-", ""));
|
|
|
+ tache.getGroupxuserid().setId(uid.replace("-", ""));
|
|
|
+ }
|
|
|
+ nextTinstanceList.add(tache);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ String noticeUsers = "";
|
|
|
+
|
|
|
+ ProcessResult pr = bpmCoreService.preProcess(finstance, tinstance, manualTacheModels,
|
|
|
+ nextTinstanceList);
|
|
|
+
|
|
|
+ // 获取下一环节
|
|
|
+ List<Map<String, Object>> nextTacheInstances = pr.getNextTacheInstances();
|
|
|
+
|
|
|
+ if (nextTinstanceList.size() == 0) {
|
|
|
+ for (Map<String, Object> nextTacheInstance : nextTacheInstances) {
|
|
|
+ TacheModel tacheModel = (TacheModel) nextTacheInstance.get("tacheModel");
|
|
|
+ List<SystemGroupUser> users = (List<SystemGroupUser>) nextTacheInstance.get("users");
|
|
|
+ String nextTmodelId = tacheModel.getTmodelId();
|
|
|
+ for (SystemGroupUser userSg : users) {
|
|
|
+ TacheInstance tache = new TacheInstance();
|
|
|
+ tache.getTmodelId().setTmodelId(nextTmodelId);
|
|
|
+ tache.getGroupxuserid().setId(userSg.getId());
|
|
|
+ nextTinstanceList.add(tache);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ pr = bpmCoreService.start(finstance, tinstance, nextTinstanceList, fileList, noticeUsers, task, "");
|
|
|
+
|
|
|
+ rv = new ResultVo();
|
|
|
+ rv.setReturnCode("1");
|
|
|
+ rv.setReturnMsg("success");
|
|
|
+ return JSONObject.fromObject(rv, config).toString();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ rv.setReturnCode("-1");
|
|
|
+ rv.setReturnMsg("failed");
|
|
|
+ rv.setReturnParams("用户不存在!");
|
|
|
+ return JSONObject.fromObject(rv, config).toString();
|
|
|
+ }
|
|
|
+ rv = new ResultVo();
|
|
|
+ rv.setReturnCode("-1");
|
|
|
+ rv.setReturnMsg("failed");
|
|
|
+ rv.setReturnParams("发起流程失败");
|
|
|
+ return JSONObject.fromObject(rv,config).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getServiceId() {
|
|
|
+ return serviceId;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<ContractPurchaseDetail> convertLineItems(JSONArray lineItems) {
|
|
|
+ List<ContractPurchaseDetail> details = new ArrayList<>();
|
|
|
+ for (int i = 0; i < lineItems.size(); i++) {
|
|
|
+ JSONObject lineJson = lineItems.getJSONObject(i);
|
|
|
+ ContractPurchaseDetail detail = new ContractPurchaseDetail();
|
|
|
+ // 映射明细字段
|
|
|
+ detail.setMaterialCode(lineJson.optString("itemCode", null));
|
|
|
+ detail.setMaterialName(lineJson.optString("itemName", null));
|
|
|
+ detail.setMaterialModel(lineJson.optString("specification", null));
|
|
|
+ detail.setMeasureName(lineJson.optString("measureName", null));
|
|
|
+ detail.setQty(BigDecimal.valueOf(lineJson.optDouble("quantityPurchase", 0.0)));
|
|
|
+ detail.setPrice(BigDecimal.valueOf(lineJson.optDouble("price", 0.0)));
|
|
|
+ detail.setCess(BigDecimal.valueOf(lineJson.optDouble("cess", 0.0)));
|
|
|
+ details.add(detail);
|
|
|
+ }
|
|
|
+ return details;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[] args) throws Exception {
|
|
|
+ String url = "http://localhost:8080/ynet/clientServices.do?iscrypt=1";
|
|
|
+ String param = "{\"serviceId\":\"contract_purchaseUpdate\"," + "\"params\":{\"purchaseNumber\":\"CG20250711002\",\"purchaseStatus\":\"2\"}}";
|
|
|
+ String rs = RegisterCodeImpl.requestPage(url, param);
|
|
|
+ System.out.println(rs);
|
|
|
+ }
|
|
|
+}
|