WorkflowAction.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. package com.happy.action;
  2. import com.google.gson.Gson;
  3. import com.google.gson.reflect.TypeToken;
  4. import com.happy.Model.Booking;
  5. import com.happy.Model.BookingComment;
  6. import com.happy.Model.FileInfo;
  7. import com.happy.Model.Workflow;
  8. import com.happy.Until.GetHttpParam;
  9. import com.happy.Until.ResUtil;
  10. import com.happy.Until.UUIDUtil;
  11. import com.happy.dto.IPage;
  12. import com.happy.service.BookingCommentService;
  13. import com.happy.service.FileService;
  14. import com.happy.service.WorkflowService;
  15. import com.opensymphony.xwork2.ActionSupport;
  16. import net.sf.json.JSONObject;
  17. import org.apache.struts2.ServletActionContext;
  18. import org.apache.struts2.interceptor.ServletRequestAware;
  19. import javax.annotation.Resource;
  20. import javax.servlet.http.HttpServletRequest;
  21. import javax.servlet.http.HttpServletResponse;
  22. import java.util.ArrayList;
  23. import java.util.List;
  24. public class WorkflowAction extends ActionSupport implements ServletRequestAware {
  25. private HttpServletRequest request;
  26. public HttpServletResponse response;
  27. public String id;//流程id
  28. public String hotelId;//民宿id
  29. public Integer status; //状态 1、正在审批 2、审批通过3、拒绝
  30. public Integer page = 1; // 当前页
  31. public Integer rows = 10;// 每页显示的行数rows
  32. @Resource
  33. public WorkflowService workflowService;
  34. @Resource
  35. public FileService fileService;
  36. @Resource(name = "BookingCommentService")
  37. private BookingCommentService bookingCommentService;
  38. public HttpServletRequest getRequest() {
  39. return request;
  40. }
  41. public void setRequest(HttpServletRequest request) {
  42. this.request = request;
  43. }
  44. public void setServletRequest(HttpServletRequest request) {
  45. this.request = request;
  46. }
  47. public HttpServletResponse getResponse() {
  48. return response;
  49. }
  50. public void setResponse(HttpServletResponse response) {
  51. this.response = response;
  52. }
  53. /**
  54. * 民宿审批接口
  55. * @return
  56. */
  57. public String workflow(){
  58. JSONObject resultJson = new JSONObject();
  59. Gson gson = new Gson();
  60. com.alibaba.fastjson.JSONObject json = GetHttpParam.getRequestParameters(request);
  61. if (json == null) {
  62. resultJson.put("message", "请传入参数");
  63. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  64. return null;
  65. }
  66. Workflow workflow = new Workflow();
  67. try{
  68. workflow = gson.fromJson(json.toString(), new TypeToken<Workflow>() {}.getType());
  69. if(workflow==null){
  70. resultJson.put("message", "数据为空");
  71. resultJson.put("code", 500);
  72. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  73. return null;
  74. }
  75. if(workflow.getId()==null){
  76. resultJson.put("message", "流程id不能为空!");
  77. resultJson.put("code", 500);
  78. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  79. return null;
  80. }
  81. if(workflow.getStatus()==null){
  82. resultJson.put("message", "流程状态不能为空!");
  83. resultJson.put("code", 500);
  84. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  85. return null;
  86. }
  87. if(workflow.getType()==null){
  88. resultJson.put("message", "流程类型不能为空!");
  89. resultJson.put("code", 500);
  90. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  91. return null;
  92. }
  93. if(workflow.getWorkflowRemark()==null){
  94. resultJson.put("message", "审批备注不能为空!");
  95. resultJson.put("code", 500);
  96. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  97. return null;
  98. }
  99. int m = 0;
  100. Workflow workflow1 = workflowService.queryById(workflow.getId());
  101. workflow1.setWorkflowRemark(workflow.getWorkflowRemark());//审批备注
  102. workflow1.setWorkflowDate(UUIDUtil.getNewDate());//审批时间
  103. workflow1.setWorkflowName("admin");//审批人名称
  104. switch (workflow.getType()){
  105. //民宿信息修改流程审批
  106. case 1 : {
  107. if (workflow.getStatus() == 2){//审批通过
  108. // 新的酒店图片
  109. List<FileInfo> fileInfoList = fileService.queryList("and link_id ='"+workflow1.getId()+"'");
  110. if(fileInfoList == null){
  111. resultJson.put("message", "附件为空!");
  112. resultJson.put("code", 500);
  113. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  114. return null;
  115. }
  116. fileService.delLinkFile(String.valueOf(workflow1.getLinkId()));
  117. fileInfoList.forEach(file -> {
  118. file.setLinkId(workflow1.getLinkId());
  119. fileService.updateFile(file);
  120. });
  121. workflow1.setStatus(2);//审批通过
  122. }else {//审批拒绝
  123. workflow1.setStatus(3); //拒绝审批
  124. }
  125. m = workflowService.update(workflow1);
  126. } break;
  127. case 2: {
  128. BookingComment bookingComment = bookingCommentService.queryById(workflow1.getLinkId());
  129. if (workflow.getStatus() == 2){//审批通过
  130. workflow1.setStatus(2);
  131. bookingComment.setStatus("1");
  132. }else {//审批拒绝
  133. workflow1.setStatus(3);
  134. bookingComment.setStatus("2");
  135. }
  136. int n = bookingCommentService.update(bookingComment);
  137. m = workflowService.update(workflow1);
  138. } break;
  139. }
  140. if (m > 0) {
  141. resultJson.put("message", "审批成功");
  142. resultJson.put("code", 200);
  143. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  144. return null;
  145. } else {
  146. resultJson.put("message", "审批失败");
  147. resultJson.put("code", 502);
  148. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  149. return null;
  150. }
  151. }catch (Exception e){
  152. e.printStackTrace();
  153. resultJson.put("message", "未知异常:"+ e);
  154. resultJson.put("code", 205);
  155. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  156. }
  157. return null;
  158. }
  159. public String queryById(){
  160. JSONObject resultJson = new JSONObject();
  161. if (id == null){
  162. resultJson.put("message", "流程id不能为空!");
  163. resultJson.put("code", 500);
  164. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  165. return null;
  166. }
  167. Workflow workflow = workflowService.queryById(id);
  168. if (workflow != null){
  169. //民宿信息维护流程
  170. List<FileInfo> fileInfoList;
  171. if (workflow.getStatus() == 2 && workflow.getType() == 1){
  172. fileInfoList = fileService.queryList("and link_id = '"+workflow.getLinkId()+"'");
  173. }else {
  174. fileInfoList = fileService.queryList("and link_id = '"+workflow.getId()+"'");
  175. }
  176. workflow.setFileInfoList(fileInfoList);
  177. resultJson.put("message", "查询成功");
  178. resultJson.put("code", 200);
  179. resultJson.put("data", workflow);
  180. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  181. return null;
  182. }
  183. resultJson.put("message", "未查询到流程信息!");
  184. resultJson.put("code", 205);
  185. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  186. return null;
  187. }
  188. /**
  189. * 商户查看接口
  190. */
  191. public String hotelWorkflowList(){
  192. JSONObject resultJson = new JSONObject();
  193. StringBuilder s1 = new StringBuilder("");
  194. if (id == null){
  195. resultJson.put("message", "酒店id不能为空!");
  196. resultJson.put("code", 500);
  197. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  198. return null;
  199. }
  200. s1.append(" and a.link_id = ").append(id).append(" ");
  201. if (status != null){
  202. s1.append(" and a.status = ").append(status).append(" ");
  203. }
  204. IPage<Workflow> list = workflowService.queryList(s1.toString(), page, rows);
  205. resultJson.put("message", "查询成功");
  206. resultJson.put("code", 200);
  207. resultJson.put("data", list);
  208. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  209. return null;
  210. }
  211. /**
  212. * 管理端代办接口
  213. */
  214. public String queryWorkflow(){
  215. JSONObject resultJson = new JSONObject();
  216. StringBuilder s1 = new StringBuilder("");
  217. s1.append(" and a.status = 1 ");
  218. IPage<Workflow> list = workflowService.queryList(s1.toString(), page, rows);
  219. resultJson.put("message", "查询成功");
  220. resultJson.put("code", 200);
  221. resultJson.put("data", list);
  222. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  223. return null;
  224. }
  225. /**
  226. * 管理端已审核接口
  227. */
  228. public String queryApprovedWorkflow(){
  229. JSONObject resultJson = new JSONObject();
  230. StringBuilder s1 = new StringBuilder("");
  231. s1.append(" and a.status != 1 ");
  232. IPage<Workflow> list = workflowService.queryList(s1.toString(), page, rows);
  233. resultJson.put("message", "查询成功");
  234. resultJson.put("code", 200);
  235. resultJson.put("data", list);
  236. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  237. return null;
  238. }
  239. }