BatchApproveServiceEx.java 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. package com.kingdee.eas.custom.flow.osf;
  2. import com.kingdee.bos.BOSException;
  3. import com.kingdee.bos.Context;
  4. import com.kingdee.bos.dao.IObjectPK;
  5. import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
  6. import com.kingdee.bos.util.BOSUuid;
  7. import com.kingdee.bos.workflow.ActivityInstInfo;
  8. import com.kingdee.bos.workflow.AssignmentInfo;
  9. import com.kingdee.bos.workflow.define.ManpowerActivityDef;
  10. import com.kingdee.bos.workflow.define.extended.ApproveActivityDef;
  11. import com.kingdee.bos.workflow.metas.WfAssignmentState;
  12. import com.kingdee.bos.workflow.service.ormrpc.EnactmentServiceFactory;
  13. import com.kingdee.bos.workflow.service.ormrpc.IEnactmentService;
  14. import com.kingdee.eas.base.message.AssignReadFactory;
  15. import com.kingdee.eas.base.message.AssignReadInfo;
  16. import com.kingdee.eas.base.message.IAssignRead;
  17. import com.kingdee.eas.base.message.URLInfo;
  18. import com.kingdee.eas.base.message.util.ProcessCenterUtil;
  19. import com.kingdee.eas.base.multiapprove.*;
  20. import com.kingdee.eas.common.EASBizException;
  21. import com.kingdee.eas.hr.service.app.service.BatchApproveService;
  22. import com.kingdee.eas.util.app.ContextUtil;
  23. import com.kingdee.shr.base.syssetting.ml.SHRWebResource;
  24. import com.kingdee.util.StringUtils;
  25. import com.kingdee.util.UuidException;
  26. import org.apache.log4j.Logger;
  27. import java.io.UnsupportedEncodingException;
  28. import java.net.URLDecoder;
  29. import java.util.ArrayList;
  30. import java.util.HashMap;
  31. import java.util.List;
  32. import java.util.Map;
  33. /**
  34. * @Description 批量审批接口扩展
  35. * @Date 2024/12/19 10:37
  36. * @Created by Heyuan
  37. */
  38. public class BatchApproveServiceEx extends BatchApproveService {
  39. private static Logger logger = Logger.getLogger(BatchApproveServiceEx.class);
  40. @Override
  41. public Object process(Context ctx, Map param)
  42. throws EASBizException, BOSException {
  43. List<Map<String, String>> results = new ArrayList();
  44. String assignmentIds = (String) param.get("assignmentIds");
  45. String opinion = (String) param.get("opinion");
  46. StringBuilder errorMsg = new StringBuilder();
  47. if (StringUtils.isEmpty(assignmentIds)) {
  48. errorMsg.append("工作流任务id不能为空!").append(System.lineSeparator());
  49. } else {
  50. try {
  51. assignmentIds = URLDecoder.decode(assignmentIds, "utf-8");
  52. } catch (UnsupportedEncodingException e) {
  53. e.printStackTrace();
  54. errorMsg.append("工作流任务id数据错误, " + e.getMessage());
  55. }
  56. }
  57. if (StringUtils.isEmpty(opinion)) {
  58. errorMsg.append("审批意见不能为空!");
  59. } else {
  60. logger.error("opinion_>1 " + opinion);
  61. try {
  62. opinion = URLDecoder.decode(opinion, "utf-8");
  63. logger.error("opinion_>2 " + opinion);
  64. } catch (UnsupportedEncodingException e) {
  65. e.printStackTrace();
  66. errorMsg.append("审批意见数据错误, " + e.getMessage());
  67. }
  68. }
  69. logger.error("assignmentIds>2 " + assignmentIds);
  70. if (errorMsg.length() > 0) {
  71. Map<String, String> result = new HashMap();
  72. result.put("code", "0");
  73. result.put("msg", errorMsg.toString());
  74. results.add(result);
  75. }
  76. String[] assignmentIdArray = assignmentIds.split("[,,]");
  77. for (int i = 0; i < assignmentIdArray.length; ++i) {
  78. results.add(this.handle(ctx, assignmentIdArray[i], opinion));
  79. }
  80. return results;
  81. }
  82. private Map<String, String> handle(Context ctx,
  83. String assignmentId,
  84. String opinion) {
  85. Map<String, String> result = new HashMap();
  86. result.put("assignmentId", assignmentId);
  87. try {
  88. String bosType = BOSUuid.read(assignmentId).getType().toString();
  89. if ("9623EB51".equals(bosType)) {
  90. //任务阅读id
  91. try {
  92. IAssignRead assignReadIns = AssignReadFactory.getLocalInstance(ctx);
  93. AssignReadInfo assignReadInfo = assignReadIns.getAssignReadInfo(new ObjectUuidPK(assignmentId));
  94. if (assignReadInfo != null) {
  95. assignmentId = assignReadInfo.getAssignID().toString();
  96. } else {
  97. throw new BOSException("任务阅读数据不存在: " + assignmentId);
  98. }
  99. } catch (Exception e) {
  100. e.printStackTrace();
  101. throw new BOSException("获取任务阅读数据报错: " + assignmentId);
  102. }
  103. }
  104. //校验流程状态
  105. String errorMessage = this.verifyData(ctx, assignmentId);
  106. if (!StringUtils.isEmpty(errorMessage)) {
  107. throw new BOSException(errorMessage);
  108. } else {
  109. this.doApprove(ctx, assignmentId, opinion);
  110. result.put("code", "1");
  111. result.put("msg", "成功");
  112. }
  113. } catch (Exception e) {
  114. e.printStackTrace();
  115. result.put("code", "0");
  116. String error = e.getMessage();
  117. if (e instanceof IllegalArgumentException) {
  118. result.put("msg", "流程id无效 " + assignmentId);
  119. } else {
  120. result.put("msg", error);
  121. }
  122. }
  123. return result;
  124. }
  125. /**
  126. * 校验数据
  127. *
  128. * @param ctx
  129. * @param assignmentId
  130. * @return
  131. * @throws BOSException
  132. */
  133. private String verifyData(Context ctx,
  134. String assignmentId)
  135. throws BOSException {
  136. IEnactmentService service = EnactmentServiceFactory.createEnactService(ctx);
  137. Map map = service.getActivityDefAndActivityInstInfo(assignmentId);
  138. Object act = map.get("ACTIVITYDEF");
  139. if (!(act instanceof ApproveActivityDef) && act instanceof ManpowerActivityDef) {
  140. return SHRWebResource.getString("com.kingdee.shr.base.syssetting.CommonserviceResource", "labor_node_not_supported");
  141. } else {
  142. AssignmentInfo assignmentInfo = service.getAssignmentById(assignmentId);
  143. ActivityInstInfo actInstInfo = null;
  144. if (null != assignmentInfo) {
  145. actInstInfo = service.getActivityInstByActInstId(assignmentInfo.getActInstId());
  146. }
  147. if (actInstInfo != null && (actInstInfo.getState().equalsIgnoreCase("open.not_running.suspended") || actInstInfo.getState().equalsIgnoreCase("open.not_running.blocked"))) {
  148. return (new MultiApproveException(MultiApproveException.FLOW_NOT_RUNNING)).getMessage();
  149. } else if (assignmentInfo == null) {
  150. return (new MultiApproveException(MultiApproveException.ASSIGNMENTINFO_NULL)).getMessage();
  151. } else if (assignmentInfo.getState().equals(WfAssignmentState.CANCELED)) {
  152. return (new MultiApproveException(MultiApproveException.ASSIGNMENTSTATE_CANCELED)).getMessage();
  153. } else if (assignmentInfo.getState().equals(WfAssignmentState.COMPLETED)) {
  154. return (new MultiApproveException(MultiApproveException.ASSIGNMENTSTATE_COMPLETED)).getMessage();
  155. } else if (assignmentInfo.getState().equals(WfAssignmentState.REJECTED)) {
  156. return (new MultiApproveException(MultiApproveException.ASSIGNMENTSTATE_REJECTED)).getMessage();
  157. } else {
  158. return assignmentInfo.getState().equals(WfAssignmentState.PROCESSING) ? (new MultiApproveException(MultiApproveException.ASSIGNMENTSTATE_COMPLETED)).getMessage() : null;
  159. }
  160. }
  161. }
  162. /**
  163. * 审批
  164. *
  165. * @param ctx
  166. * @param assignmentId
  167. * @param opinion
  168. * @return
  169. * @throws BOSException
  170. * @throws EASBizException
  171. */
  172. private IObjectPK doApprove(Context ctx, String assignmentId, String opinion)
  173. throws BOSException, EASBizException {
  174. IMultiApprove multiApprove = MultiApproveFactory.getLocalInstance(ctx);
  175. MultiApproveInfo mInfo = new MultiApproveInfo();
  176. mInfo.setAssignment(assignmentId);
  177. URLInfo info = ProcessCenterUtil.getUrlInfos(assignmentId, ctx);
  178. String billID = info.getBillID();
  179. mInfo.setBillId(BOSUuid.read(billID));
  180. mInfo.setIsPass(ApproveResult.PASS);
  181. mInfo.setHandlerOpinion(0);
  182. mInfo.setOpinion(opinion);
  183. mInfo.setCreator(ContextUtil.getCurrentUserInfo(ctx));
  184. mInfo.setHandlerContent("同意");
  185. mInfo.setExtendedProperty("isAddNew", "isAddNew");
  186. mInfo.setExtendedProperty("assignmentID", assignmentId);
  187. mInfo.setExtendedProperty("businuessObjectId", billID);
  188. IObjectPK pk = multiApprove.submit(mInfo);
  189. return pk;
  190. }
  191. }