serviceorder.java 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. package restcontroller.sale.serviceorder;
  2. import beans.datacontrllog.DataContrlLog;
  3. import beans.dataextend.DataExtend;
  4. import com.alibaba.fastjson.JSONObject;
  5. import common.Controller;
  6. import common.YosException;
  7. import common.annotation.API;
  8. import common.annotation.CACHEING;
  9. import common.annotation.CACHEING_CLEAN;
  10. import common.data.*;
  11. import org.apache.commons.lang.StringUtils;
  12. import restcontroller.R;
  13. import restcontroller.webmanage.executorService.Executor;
  14. import utility.sms.Sms;
  15. import java.util.ArrayList;
  16. /**
  17. * 服务申请单
  18. */
  19. @API(title = "服务申请单业务端")
  20. public class serviceorder extends Controller {
  21. public serviceorder(JSONObject arg0) throws YosException {
  22. super(arg0);
  23. // TODO Auto-generated constructor stub
  24. }
  25. @API(title = "查询服务申请单列表", apiversion = R.ID20230206101303.v1.class)
  26. @CACHEING
  27. public String queryserviceorderList() throws YosException {
  28. StringBuffer where = new StringBuffer(" 1=1 ");
  29. if (content.containsKey("where")) {
  30. JSONObject whereObject = content.getJSONObject("where");
  31. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  32. where.append(" and(");
  33. where.append("t1.billno like'%").append(whereObject.getString("condition")).append("%' ");
  34. where.append("or t3.sonum like'%").append(whereObject.getString("condition")).append("%' ");
  35. where.append("or t2.enterprisename like'%").append(whereObject.getString("condition")).append("%' ");
  36. where.append("or t1.reason like'%").append(whereObject.getString("condition")).append("%' ");
  37. where.append(")");
  38. }
  39. if (whereObject.containsKey("status") && !"".equals(whereObject.getString("status"))) {
  40. where.append(" and t1.status ='").append(whereObject.getString("status")).append("' ");
  41. }
  42. if (whereObject.containsKey("begindate") && !"".equals(whereObject.getString("begindate"))) {
  43. where.append(" and t1.submitdate >='").append(whereObject.getString("begindate")).append("' ");
  44. }
  45. if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) {
  46. where.append(" and t1.submitdate <='").append(whereObject.getString("enddate")).append("' ");
  47. }
  48. }
  49. // SQLFactory sqlFactory = new SQLFactory(this, "服务申请单列表查询", pageSize, pageNumber, pageSorting);
  50. // sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
  51. // sqlFactory.addParameter("siteid", siteid);
  52. // sqlFactory.addParameter_SQL("where", where);
  53. // Rows rows = dbConnect.runSqlQuery(sqlFactory);
  54. QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_serviceorder", "*");
  55. querySQL.setTableAlias("t1");
  56. querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise", "t2", "t1.sys_enterpriseid = t2.sys_enterpriseid AND t1.siteid = t2.siteid","enterprisename","abbreviation","phonenumber");
  57. querySQL.addJoinTable(JOINTYPE.left, "sa_agents", "t3", "t2.sys_enterpriseid = t3.sys_enterpriseid AND t2.siteid = t3.siteid","agentnum");
  58. querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise", "t4", "t1.sys_enterpriseid_service = t4.sys_enterpriseid AND t1.siteid = t4.siteid","enterprisename","abbreviation","phonenumber");
  59. querySQL.addJoinTable(JOINTYPE.left, "sa_agents", "t5", "t4.sys_enterpriseid = t5.sys_enterpriseid AND t4.siteid = t5.siteid","agentnum");
  60. querySQL.addJoinTable(JOINTYPE.left, "(SELECT * FROM (SELECT *,ROW_NUMBER() OVER (PARTITION BY sa_serviceorderid ORDER BY sa_serviceorderitemsid ASC) AS rowno FROM sa_serviceorderitems) t WHERE rowno = 1)",
  61. "t8", "t8.sa_serviceorderid=t1.sa_serviceorderid and t8.siteid=t1.siteid","itemid","sku","cardno");
  62. querySQL.addJoinTable(JOINTYPE.left, "plm_item", "t9", "t9.itemid=t8.itemid and t9.siteid=t8.siteid","itemno","itemname","model","spec");
  63. querySQL.addQueryFields("serviceenterprisename","t4.enterprisename");
  64. querySQL.addQueryFields("serviceabbreviation","t4.abbreviation");
  65. querySQL.addQueryFields("servicephonenumber","t4.phonenumber");
  66. querySQL.addQueryFields("serviceagentnum","t5.agentnum");
  67. querySQL.setSiteid(siteid);
  68. querySQL.setWhere("(t1.sys_enterpriseid="+sys_enterpriseid+" or t1.sys_enterpriseid_service="+sys_enterpriseid+")");
  69. querySQL.setWhere(where.toString());
  70. querySQL.setPage(pageSize, pageNumber);
  71. querySQL.setOrderBy(pageSorting);
  72. Rows rows = querySQL.query();
  73. return getSucReturnObject().setData(rows).toString();
  74. }
  75. @API(title = "提交", apiversion = R.ID20230206101403.v1.class)
  76. @CACHEING_CLEAN(apiversions = {R.ID20230206091603.v1.class, R.ID20230206091703.v1.class,
  77. R.ID20230206101303.v1.class, R.ID20230217100703.v1.class, R.ID20230217133003.v1.class})
  78. public String sumbit() throws YosException {
  79. Long sa_serviceorderid = content.getLong("sa_serviceorderid");
  80. boolean issumbit = true;
  81. Rows rows = dbConnect
  82. .runSqlQuery("select sa_serviceorderid,status,billno,sys_enterpriseid,province,city,county from sa_serviceorder where sa_serviceorderid ='"
  83. + sa_serviceorderid + "' and siteid='" + siteid + "'");
  84. for (Row row : rows) {
  85. if (issumbit) {
  86. if (!row.getString("status").equals("新建")) {
  87. return getErrReturnObject().setErrMsg("单号为:【" + row.getString("billno") + "】的服务申请单为非新建状态,无法提交")
  88. .toString();
  89. }
  90. } else {
  91. if (StringUtils.isBlank(content.getString("backreason"))) {
  92. return getErrReturnObject().setErrMsg("退回原因为空不可退回").toString();
  93. }
  94. if (!row.getString("status").equals("待指派")) {
  95. return getErrReturnObject().setErrMsg("单号为:【" + row.getString("billno") + "】的服务申请单为非待指派状态,无法退回")
  96. .toString();
  97. }
  98. }
  99. }
  100. ArrayList<String> sqlList = new ArrayList<>();
  101. SQLFactory sqlFactoryupdate;
  102. if (issumbit) {
  103. sqlFactoryupdate = new SQLFactory(this, "服务申请单提交");
  104. sqlList.add(
  105. DataContrlLog.createLog(this, "sa_serviceorder", sa_serviceorderid, "提交", "服务申请单提交成功").getSQL());
  106. } else {
  107. sqlFactoryupdate = new SQLFactory(this, "服务申请单反提交");
  108. sqlList.add(
  109. DataContrlLog.createLog(this, "sa_serviceorder", sa_serviceorderid, "反提交", "服务申请单退回成功").getSQL());
  110. // 退回原因
  111. ArrayList<Long> sa_serviceorderids = new ArrayList<>();
  112. sa_serviceorderids.add(sa_serviceorderid);
  113. DataExtend.createBackReasonSql(this, "sa_serviceorder", sa_serviceorderids,
  114. content.getStringValue("backreason"));
  115. }
  116. sqlFactoryupdate.addParameter("siteid", siteid);
  117. sqlFactoryupdate.addParameter("sa_serviceorderid", sa_serviceorderid);
  118. sqlFactoryupdate.addParameter("submitby", username);
  119. sqlList.add(sqlFactoryupdate.getSQL());
  120. if (issumbit) {
  121. Rows agents = dbConnect.runSqlQuery("select * from sa_agents where siteid='"+siteid+"' and sys_enterpriseid="+ rows.get(0).getLong("sys_enterpriseid"));
  122. if(agents.isNotEmpty()){
  123. if(agents.get(0).getBoolean("isservice")){
  124. sqlList.add("update sa_serviceorder set status='待受理',sys_enterpriseid_service="+agents.get(0).getLong("sys_enterpriseid")+" where sa_serviceorderid="+sa_serviceorderid);
  125. }else{
  126. Rows serviceagents = dbConnect.runSqlQuery("select t1.sys_enterpriseid,t2.province,t2.city,t2.county from sa_agents t1 inner join sa_agents_salescope t2 on t1.sa_agentsid=t2.sa_agentsid and t1.siteid=t2.siteid where t1.siteid='"+siteid+"'");
  127. System.out.println(serviceagents.get(0).getString("city"));
  128. System.out.println(rows.get(0).getString("city"));
  129. RowsMap countyRowsMap=serviceagents.toRowsMap("county");
  130. RowsMap cityRowsMap=serviceagents.toRowsMap("city");
  131. RowsMap provinceRowsMap=serviceagents.toRowsMap("province");
  132. if(countyRowsMap.containsKey(rows.get(0).getString("county"))){
  133. UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sa_serviceorder");
  134. updateSQL.setUniqueid(sa_serviceorderid);
  135. updateSQL.setSiteid(siteid);
  136. updateSQL.setValue("status", "待受理");
  137. updateSQL.setValue("sys_enterpriseid_service", countyRowsMap.get(rows.get(0).getString("county")).get(0).getLong("sys_enterpriseid"));
  138. updateSQL.setDateValue("allocationdate");
  139. updateSQL.setValue("allocationby", username);
  140. sqlList.add(updateSQL.getSQL());
  141. }else if(cityRowsMap.containsKey(rows.get(0).getString("city"))){
  142. UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sa_serviceorder");
  143. updateSQL.setUniqueid(sa_serviceorderid);
  144. updateSQL.setSiteid(siteid);
  145. updateSQL.setValue("status", "待受理");
  146. updateSQL.setValue("sys_enterpriseid_service", cityRowsMap.get(rows.get(0).getString("city")).get(0).getLong("sys_enterpriseid"));
  147. updateSQL.setDateValue("allocationdate");
  148. updateSQL.setValue("allocationby", username);
  149. sqlList.add(updateSQL.getSQL());
  150. }else if(provinceRowsMap.containsKey(rows.get(0).getString("province"))){
  151. UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sa_serviceorder");
  152. updateSQL.setUniqueid(sa_serviceorderid);
  153. updateSQL.setSiteid(siteid);
  154. updateSQL.setValue("status", "待受理");
  155. updateSQL.setValue("sys_enterpriseid_service", provinceRowsMap.get(rows.get(0).getString("province")).get(0).getLong("sys_enterpriseid"));
  156. updateSQL.setDateValue("allocationdate");
  157. updateSQL.setValue("allocationby", username);
  158. sqlList.add(updateSQL.getSQL());
  159. }
  160. }
  161. }
  162. Rows workersRows = dbConnect.runSqlQuery(
  163. "select t3.phonenumber from sys_hr t1 left join sys_users t3 on t1.userid = t3.userid left join sys_hr t4 on t1.siteid = t4.siteid and t1.reporthrid = t4.hrid where t1.siteid = '"
  164. + siteid + "' and t1.isworker=1 and t1.isleader=1");
  165. Rows serviceorderRows = dbConnect.runSqlQuery(
  166. "select t2.enterprisename,t1.billno,t1.submitby,t1.remarks from sa_serviceorder t1 left join sys_enterprise t2 on t1.sys_enterpriseid=t2.sys_enterpriseid and t1.siteid=t2.siteid where t1.sa_serviceorderid ='"
  167. + sa_serviceorderid + "' and t1.siteid='" + siteid + "'");
  168. if (!workersRows.isEmpty()) {
  169. for (Row row : workersRows) {
  170. Sms sms = new Sms();
  171. if (StringUtils.isNotBlank(row.getString("phonenumber"))) {
  172. sms.sendout(Sms.SmsType.Notice,siteid, row.getString("phonenumber"),
  173. "服务单号:" + serviceorderRows.get(0).getString("billno") + "已指派请处理,客户名称:"
  174. + (StringUtils.isBlank(serviceorderRows.get(0).getString("enterprisename")) ? ""
  175. : serviceorderRows.get(0).getString("enterprisename"))
  176. + ",提交人:" + serviceorderRows.get(0).getString("submitby") + ",备注:"
  177. + serviceorderRows.get(0).getString("remarks"));
  178. }
  179. }
  180. }
  181. Executor.sendEml(this, "serviceordersub", sa_serviceorderid,siteid);
  182. }
  183. dbConnect.runSqlUpdate(sqlList);
  184. return getSucReturnObject().toString();
  185. }
  186. @API(title = "手工分配服务商", apiversion = R.ID2025071710525303.v1.class)
  187. public String assignserviceagentbyhand() throws YosException {
  188. Long sa_serviceorderid = content.getLong("sa_serviceorderid");
  189. sys_enterpriseid = content.getLong("sys_enterpriseid");
  190. Rows rows = dbConnect
  191. .runSqlQuery("select sa_serviceorderid,status,billno,sys_enterpriseid from sa_serviceorder where sa_serviceorderid ='"
  192. + sa_serviceorderid + "' and siteid='" + siteid + "'");
  193. if(rows.isEmpty()){
  194. return getErrReturnObject().setErrMsg("该服务申请单不存在").toString();
  195. }
  196. if(!rows.get(0).getString("status").equals("待分配")){
  197. return getErrReturnObject().setErrMsg("非待分配的服务申请单无法分配服务商").toString();
  198. }
  199. UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sa_serviceorder");
  200. updateSQL.setUniqueid(sa_serviceorderid);
  201. updateSQL.setSiteid(siteid);
  202. updateSQL.setValue("status", "待受理");
  203. updateSQL.setValue("sys_enterpriseid_service", sys_enterpriseid);
  204. updateSQL.setDateValue("allocationdate");
  205. updateSQL.setValue("allocationby", username);
  206. dbConnect.runSqlUpdate(updateSQL.getSQL());
  207. return getSucReturnObject().toString();
  208. }
  209. @API(title = "拒绝受理", apiversion = R.ID2025072409011703.v1.class)
  210. @CACHEING_CLEAN(apiversions = {serviceorder.class, restcontroller.webmanage.sale.serviceorder.serviceorder.class})
  211. public String refuse() throws YosException {
  212. Long sa_serviceorderid = content.getLong("sa_serviceorderid");
  213. Rows rows = dbConnect
  214. .runSqlQuery("select sa_serviceorderid,status,billno,sys_enterpriseid,province,city,county from sa_serviceorder where sa_serviceorderid ='"
  215. + sa_serviceorderid + "' and siteid='" + siteid + "'");
  216. for (Row row : rows) {
  217. if (!row.getString("status").equals("待受理")) {
  218. return getErrReturnObject().setErrMsg("单号为:【" + row.getString("billno") + "】的服务申请单为非待受理状态,无法拒绝受理")
  219. .toString();
  220. }
  221. }
  222. ArrayList<String> sqlList = new ArrayList<>();
  223. UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sa_serviceorder");
  224. updateSQL.setUniqueid(sa_serviceorderid);
  225. updateSQL.setSiteid(siteid);
  226. updateSQL.setValue("status", "拒绝受理");
  227. updateSQL.setValue("changeby", username);
  228. updateSQL.setDateValue("changedate");
  229. sqlList.add(updateSQL.getSQL());
  230. sqlList.add(
  231. DataContrlLog.createLog(this, "sa_serviceorder", sa_serviceorderid, "拒绝受理", "服务申请单拒绝受理成功").getSQL());
  232. dbConnect.runSqlUpdate(sqlList);
  233. return getSucReturnObject().toString();
  234. }
  235. @API(title = "完结服务单", apiversion = R.ID2025072409161803.v1.class)
  236. @CACHEING_CLEAN(apiversions = {serviceorder.class, restcontroller.webmanage.sale.serviceorder.serviceorder.class})
  237. public String wanjie() throws YosException {
  238. Long sa_serviceorderid = content.getLong("sa_serviceorderid");
  239. Rows rows = dbConnect
  240. .runSqlQuery("select sa_serviceorderid,status,billno,sys_enterpriseid,province,city,county from sa_serviceorder where sa_serviceorderid ='"
  241. + sa_serviceorderid + "' and siteid='" + siteid + "'");
  242. for (Row row : rows) {
  243. if (!row.getString("status").equals("待分配") && !row.getString("status").equals("拒绝受理")) {
  244. return getErrReturnObject().setErrMsg("单号为:【" + row.getString("billno") + "】的服务申请单为非待受理状态,无法拒绝受理")
  245. .toString();
  246. }
  247. if (StringUtils.isBlank(content.getString("backreason"))) {
  248. return getErrReturnObject().setErrMsg("完结原因(拒绝原因)为空不可完结").toString();
  249. }
  250. }
  251. ArrayList<String> sqlList = new ArrayList<>();
  252. UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sa_serviceorder");
  253. updateSQL.setUniqueid(sa_serviceorderid);
  254. updateSQL.setSiteid(siteid);
  255. updateSQL.setValue("status", "已完结");
  256. updateSQL.setValue("changeby", username);
  257. updateSQL.setDateValue("changedate");
  258. sqlList.add(updateSQL.getSQL());
  259. sqlList.add(
  260. DataContrlLog.createLog(this, "sa_serviceorder", sa_serviceorderid, "完结", "服务申请单完结成功").getSQL());
  261. // 退回原因
  262. ArrayList<Long> sa_serviceorderids = new ArrayList<>();
  263. sa_serviceorderids.add(sa_serviceorderid);
  264. DataExtend.createBackReasonSql(this, "sa_serviceorder", sa_serviceorderids,
  265. content.getStringValue("backreason"));
  266. dbConnect.runSqlUpdate(sqlList);
  267. return getSucReturnObject().toString();
  268. }
  269. }