|
|
@@ -0,0 +1,245 @@
|
|
|
+package com.happy.action;
|
|
|
+
|
|
|
+import com.google.gson.Gson;
|
|
|
+import com.google.gson.reflect.TypeToken;
|
|
|
+import com.happy.Model.Booking;
|
|
|
+import com.happy.Model.FileInfo;
|
|
|
+import com.happy.Model.Workflow;
|
|
|
+import com.happy.Until.GetHttpParam;
|
|
|
+import com.happy.Until.ResUtil;
|
|
|
+import com.happy.Until.UUIDUtil;
|
|
|
+import com.happy.service.FileService;
|
|
|
+import com.happy.service.WorkflowService;
|
|
|
+import com.opensymphony.xwork2.ActionSupport;
|
|
|
+import net.sf.json.JSONObject;
|
|
|
+import org.apache.struts2.ServletActionContext;
|
|
|
+import org.apache.struts2.interceptor.ServletRequestAware;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+public class WorkflowAction extends ActionSupport implements ServletRequestAware {
|
|
|
+
|
|
|
+ private HttpServletRequest request;
|
|
|
+ public HttpServletResponse response;
|
|
|
+
|
|
|
+ public String id;//流程id
|
|
|
+ public String hotelId;//民宿id
|
|
|
+ public Integer status; //状态 1、正在审批 2、审批通过3、拒绝
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ public WorkflowService workflowService;
|
|
|
+ @Resource
|
|
|
+ public FileService fileService;
|
|
|
+
|
|
|
+ public HttpServletRequest getRequest() {
|
|
|
+ return request;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setRequest(HttpServletRequest request) {
|
|
|
+ this.request = request;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setServletRequest(HttpServletRequest request) {
|
|
|
+ this.request = request;
|
|
|
+ }
|
|
|
+
|
|
|
+ public HttpServletResponse getResponse() {
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setResponse(HttpServletResponse response) {
|
|
|
+ this.response = response;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 民宿审批接口
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String workflow(){
|
|
|
+ JSONObject resultJson = new JSONObject();
|
|
|
+ Gson gson = new Gson();
|
|
|
+ com.alibaba.fastjson.JSONObject json = GetHttpParam.getRequestParameters(request);
|
|
|
+ if (json == null) {
|
|
|
+ resultJson.put("message", "请传入参数");
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ Workflow workflow = new Workflow();
|
|
|
+ try{
|
|
|
+ workflow = gson.fromJson(json.toString(), new TypeToken<Workflow>() {}.getType());
|
|
|
+ if(workflow==null){
|
|
|
+ resultJson.put("message", "数据为空");
|
|
|
+ resultJson.put("code", 500);
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if(workflow.getId()==null){
|
|
|
+ resultJson.put("message", "流程id不能为空!");
|
|
|
+ resultJson.put("code", 500);
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if(workflow.getStatus()==null){
|
|
|
+ resultJson.put("message", "流程状态不能为空!");
|
|
|
+ resultJson.put("code", 500);
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if(workflow.getType()==null){
|
|
|
+ resultJson.put("message", "流程类型不能为空!");
|
|
|
+ resultJson.put("code", 500);
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if(workflow.getWorkflowRemark()==null){
|
|
|
+ resultJson.put("message", "审批备注不能为空!");
|
|
|
+ resultJson.put("code", 500);
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ int m = 0;
|
|
|
+ Workflow workflow1 = workflowService.queryById(workflow.getId());
|
|
|
+ workflow1.setWorkflowRemark(workflow.getWorkflowRemark());//审批备注
|
|
|
+ workflow1.setWorkflowDate(UUIDUtil.getNewDate());//审批时间
|
|
|
+ workflow1.setWorkflowName("admin");//审批人名称
|
|
|
+ switch (workflow.getType()){
|
|
|
+ //民宿信息修改流程审批
|
|
|
+ case 1 : {
|
|
|
+ if (workflow.getStatus() == 2){//审批通过
|
|
|
+ // 新的酒店图片
|
|
|
+ List<FileInfo> fileInfoList = fileService.queryList("and link_id ='"+workflow1.getId()+"'");
|
|
|
+ fileService.delLinkFile(String.valueOf(workflow1.getLinkId()));
|
|
|
+ fileInfoList.forEach(file -> {
|
|
|
+ file.setLinkId(workflow1.getLinkId());
|
|
|
+ fileService.updateFile(file);
|
|
|
+ });
|
|
|
+ workflow1.setStatus(2);//审批通过
|
|
|
+ m = workflowService.update(workflow1);
|
|
|
+ }else {//审批拒绝
|
|
|
+ workflow1.setStatus(3);
|
|
|
+ m = workflowService.update(workflow1);
|
|
|
+ }
|
|
|
+ } break;
|
|
|
+ case 2: {
|
|
|
+ if (workflow.getStatus() == 2){//审批通过
|
|
|
+ //TODO 评价流程审批通过
|
|
|
+
|
|
|
+
|
|
|
+ }else {//审批拒绝
|
|
|
+ //TODO 评价流程审批通过
|
|
|
+ workflow1.setStatus(3);
|
|
|
+ m = workflowService.update(workflow1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (m > 0) {
|
|
|
+ resultJson.put("message", "审批成功");
|
|
|
+ resultJson.put("code", 200);
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ return null;
|
|
|
+ } else {
|
|
|
+ resultJson.put("message", "审批失败");
|
|
|
+ resultJson.put("code", 502);
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ resultJson.put("message", "未知异常:"+ e);
|
|
|
+ resultJson.put("code", 205);
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String queryById(){
|
|
|
+ JSONObject resultJson = new JSONObject();
|
|
|
+ if (id == null){
|
|
|
+ resultJson.put("message", "流程id不能为空!");
|
|
|
+ resultJson.put("code", 500);
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ Workflow workflow = workflowService.queryById(id);
|
|
|
+ if (workflow != null){
|
|
|
+ //民宿信息维护流程
|
|
|
+ List<FileInfo> fileInfoList;
|
|
|
+ if (workflow.getStatus() == 2){
|
|
|
+ fileInfoList = fileService.queryList("and link_id = '"+workflow.getLinkId()+"'");
|
|
|
+ }else {
|
|
|
+ fileInfoList = fileService.queryList("and link_id = '"+workflow.getId()+"'");
|
|
|
+ }
|
|
|
+ workflow.setFileInfoList(fileInfoList);
|
|
|
+ resultJson.put("message", "查询成功");
|
|
|
+ resultJson.put("code", 200);
|
|
|
+ resultJson.put("data", workflow);
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ resultJson.put("message", "未查询到流程信息!");
|
|
|
+ resultJson.put("code", 205);
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 商户查看接口
|
|
|
+ */
|
|
|
+ public String hotelWorkflowList(){
|
|
|
+ JSONObject resultJson = new JSONObject();
|
|
|
+ StringBuilder s1 = new StringBuilder("");
|
|
|
+ if (id == null){
|
|
|
+ resultJson.put("message", "酒店id不能为空!");
|
|
|
+ resultJson.put("code", 500);
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ s1.append(" and a.link_id = ").append(id).append(" ");
|
|
|
+ if (status != null){
|
|
|
+ s1.append(" and a.status = ").append(status).append(" ");
|
|
|
+ }
|
|
|
+ List<Workflow> list = workflowService.queryList(s1.toString());
|
|
|
+ resultJson.put("message", "查询成功");
|
|
|
+ resultJson.put("code", 200);
|
|
|
+ resultJson.put("data", list);
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 管理端代办接口
|
|
|
+ */
|
|
|
+ public String queryWorkflow(){
|
|
|
+ JSONObject resultJson = new JSONObject();
|
|
|
+ StringBuilder s1 = new StringBuilder("");
|
|
|
+ s1.append(" and a.status = 1 ");
|
|
|
+ List<Workflow> list = workflowService.queryList(s1.toString());
|
|
|
+ resultJson.put("message", "查询成功");
|
|
|
+ resultJson.put("code", 200);
|
|
|
+ resultJson.put("data", list);
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 管理端已审核接口
|
|
|
+ */
|
|
|
+ public String queryApprovedWorkflow(){
|
|
|
+ JSONObject resultJson = new JSONObject();
|
|
|
+ StringBuilder s1 = new StringBuilder("");
|
|
|
+ s1.append(" and a.status != 1 ");
|
|
|
+ List<Workflow> list = workflowService.queryList(s1.toString());
|
|
|
+ resultJson.put("message", "查询成功");
|
|
|
+ resultJson.put("code", 200);
|
|
|
+ resultJson.put("data", list);
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|