datafollowup.java 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. package restcontroller.system.datafollowup;
  2. import beans.datacomment.DataComment;
  3. import beans.datacontrllog.DataContrlLog;
  4. import beans.dataextend.DataExtend;
  5. import beans.datafollowup.Datafollowup;
  6. import beans.datateam.DataTeam;
  7. import beans.hr.Hr;
  8. import beans.salesfees.SalesFees;
  9. import beans.user.User;
  10. import com.alibaba.fastjson.JSONArray;
  11. import com.alibaba.fastjson.JSONObject;
  12. import common.Controller;
  13. import common.YosException;
  14. import common.annotation.API;
  15. import common.annotation.CACHEING;
  16. import common.annotation.CACHEING_CLEAN;
  17. import common.data.*;
  18. import restcontroller.R;
  19. import restcontroller.webmanage.executorService.Executor;
  20. import java.math.BigDecimal;
  21. import java.util.ArrayList;
  22. import java.util.HashMap;
  23. import java.util.HashSet;
  24. import java.util.List;
  25. public class datafollowup extends Controller {
  26. public datafollowup(JSONObject content) throws YosException {
  27. super(content);
  28. }
  29. @API(title = "数据跟进日志查询", apiversion = R.ID20220930121501.v1.class)
  30. @CACHEING
  31. public String queryFollowUp() throws YosException {
  32. StringBuffer where = new StringBuffer(" 1=1 ");
  33. if (content.containsKey("where")) {
  34. JSONObject whereObject = content.getJSONObject("where");
  35. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  36. where.append(" and(");
  37. where.append("t1.content like'%").append(whereObject.getString("condition")).append("%' ");
  38. where.append("or t1.target like'%").append(whereObject.getString("condition")).append("%' ");
  39. where.append("or t1.results like'%").append(whereObject.getString("condition")).append("%' ");
  40. where.append("or t1.nextplan like'%").append(whereObject.getString("condition")).append("%' ");
  41. where.append("or t1.createby like'%").append(whereObject.getString("condition")).append("%' ");
  42. where.append(")");
  43. }
  44. }
  45. where.append(" and t1.createuserid=").append(userid);
  46. int type = content.getIntValue("type");
  47. String ownertable = content.getString("ownertable");
  48. long ownerid = content.getLong("ownerid");
  49. QuerySQL querySQL = SQLFactory.createQuerySQL(dbConnect, "sys_datafollowup", "t1.*").setTableAlias("t1");
  50. querySQL.addJoinTable(JOINTYPE.left, "sa_customers", "t2", "t2.sa_customersid=t1.sa_customersid and t2.siteid=t1.siteid");
  51. querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise", "t21", "t21.sys_enterpriseid=t2.sys_enterpriseid and t21.siteid=t2.siteid");
  52. querySQL.addJoinTable(JOINTYPE.left, "sa_hospitaldep", "t3", "t3.sa_hospitaldepid=t1.sa_hospitaldepid and t3.siteid=t1.siteid",
  53. "hospitaldepname");
  54. querySQL.addJoinTable(JOINTYPE.left, "sa_doctor", "t4", "t4.sa_doctorid=t1.sa_doctorid and t4.siteid=t1.siteid",
  55. "doctorname");
  56. querySQL.addJoinTable(JOINTYPE.left, "sys_task", "t5", "t5.sys_taskid=t1.sys_taskid and t5.siteid=t1.siteid");
  57. querySQL.addJoinTable(JOINTYPE.left, "sa_agents", "t6", "t6.sa_agentsid=t1.sa_agentsid and t6.siteid=t1.siteid");
  58. querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise", "t61", "t61.sys_enterpriseid=t6.sys_enterpriseid and t61.siteid=t6.siteid");
  59. querySQL.addQueryFields("hospitalname", "t21.enterprisename");
  60. querySQL.addQueryFields("tasktitle", "t5.title");
  61. querySQL.addQueryFields("agentsname", "t61.enterprisename");
  62. querySQL.setSiteid(siteid);
  63. querySQL.setWhere(where);
  64. switch (ownertable) {
  65. case "sa_customers":
  66. querySQL.setWhere("t1.sa_customersid", ownerid);
  67. break;
  68. case "sa_hospitaldep":
  69. querySQL.setWhere("t1.sa_hospitaldepid", ownerid);
  70. break;
  71. case "sa_doctor":
  72. querySQL.setWhere("t1.sa_doctorid", ownerid);
  73. break;
  74. case "sa_agents":
  75. querySQL.setWhere("t1.sa_agentsid", ownerid);
  76. break;
  77. case "sys_task":
  78. querySQL.setWhere("t1.sys_taskid", ownerid);
  79. break;
  80. default:
  81. querySQL.setWhere("ownertable", ownertable);
  82. querySQL.setWhere("ownerid", ownerid);
  83. }
  84. querySQL.setPage(pageSize, pageNumber);
  85. Rows rows = querySQL.query();
  86. ArrayList<Long> sys_datafollowupids = rows.toArrayList("sys_datafollowupid", new ArrayList<Long>());
  87. HashMap<String, BigDecimal> followupsalefeesHashMap = SalesFees.getfollowupsalefeesamount(this, ownertable, sys_datafollowupids);
  88. RowsMap map = getAttachmentUrl("sys_datafollowup", sys_datafollowupids);
  89. RowsMap userExtendMsgMap = User.getUserExtendMsg(this, rows.toArrayList("createuserid", new ArrayList<>()));
  90. for (Row row : rows) {
  91. String sys_datafollowupid = row.getString("sys_datafollowupid");
  92. row.put("headpic", getHeadPic(row.getLong("createuserid")));
  93. row.put("attinfos", map.get(sys_datafollowupid));
  94. row.put("attcount", map.get(sys_datafollowupid).size());
  95. row.put("userextend", userExtendMsgMap.get(row.getString("createuserid")));
  96. if (followupsalefeesHashMap.containsKey(sys_datafollowupid)) {
  97. row.put("salesfeesamount", followupsalefeesHashMap.get(sys_datafollowupid));
  98. } else {
  99. row.put("salesfeesamount", "");
  100. }
  101. }
  102. return getSucReturnObject().setData(rows).toString();
  103. }
  104. @API(title = "数据跟进日志详情查询", apiversion = R.ID20221026085601.v1.class)
  105. public String queryFollowUpMain() throws YosException {
  106. Long sys_datafollowupid = content.getLong("sys_datafollowupid");
  107. QuerySQL querySQL = SQLFactory.createQuerySQL(dbConnect, "sys_datafollowup", "t1.*").setTableAlias("t1");
  108. querySQL.addJoinTable(JOINTYPE.left, "sa_customers", "t2", "t2.sa_customersid=t1.sa_customersid and t2.siteid=t1.siteid");
  109. querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise", "t21", "t21.sys_enterpriseid=t2.sys_enterpriseid and t21.siteid=t2.siteid");
  110. querySQL.addJoinTable(JOINTYPE.left, "sa_hospitaldep", "t3", "t3.sa_hospitaldepid=t1.sa_hospitaldepid and t3.siteid=t1.siteid",
  111. "hospitaldepname");
  112. querySQL.addJoinTable(JOINTYPE.left, "sa_doctor", "t4", "t4.sa_doctorid=t1.sa_doctorid and t4.siteid=t1.siteid",
  113. "doctorname");
  114. querySQL.addJoinTable(JOINTYPE.left, "sys_task", "t5", "t5.sys_taskid=t1.sys_taskid and t5.siteid=t1.siteid");
  115. querySQL.addJoinTable(JOINTYPE.left, "sa_agents", "t6", "t6.sa_agentsid=t1.sa_agentsid and t6.siteid=t1.siteid");
  116. querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise", "t61", "t61.sys_enterpriseid=t6.sys_enterpriseid and t61.siteid=t6.siteid");
  117. querySQL.addQueryFields("hospitalname", "t21.enterprisename");
  118. querySQL.addQueryFields("tasktitle", "t5.title");
  119. querySQL.addQueryFields("agentsname", "t61.enterprisename");
  120. querySQL.setSiteid(siteid);
  121. querySQL.setWhere("sys_datafollowupid", sys_datafollowupid);
  122. Rows rows = querySQL.query();
  123. RowsMap userExtendMsgMap = User.getUserExtendMsg(this, rows.toArrayList("createuserid", new ArrayList<>()));
  124. for (Row row : rows) {
  125. String ownertable = row.getString("ownertable");
  126. Rows attachmentUrlRows = getAttachmentUrl("sys_datafollowup", sys_datafollowupid);
  127. String salesfeesamount = SalesFees.getfollowupsalefeesamount(this, ownertable, sys_datafollowupid);
  128. row.put("headpic", getHeadPic(row.getLong("createuserid")));
  129. row.put("attinfos", attachmentUrlRows);
  130. row.put("userextend", userExtendMsgMap.get(row.getString("createuserid")));
  131. row.put("salesfeesamount", salesfeesamount);
  132. }
  133. return getSucReturnObject().setData(rows.isNotEmpty() ? rows.get(0) : new Row()).toString();
  134. }
  135. @API(title = "数据跟进日志新增修改", apiversion = R.ID20220930121601.v1.class)
  136. @CACHEING_CLEAN(apiversions = R.ID20220930121501.class)
  137. public String insertormodifyFollowUp() throws YosException {
  138. long sys_datafollowupid = content.getLongValue("sys_datafollowupid");
  139. String ownertable = content.getString("ownertable");
  140. long ownerid = content.getLong("ownerid");
  141. String contentstr = content.getStringValue("content");
  142. ArrayList<String> sqlList = new ArrayList<>();
  143. if (sys_datafollowupid <= 0) {
  144. sys_datafollowupid = createTableID("sys_datafollowup");
  145. InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sys_datafollowup");
  146. insertSQL.setSiteid(siteid);
  147. insertSQL.setUniqueid(sys_datafollowupid);
  148. insertSQL.setValue("ownertable", ownertable);
  149. insertSQL.setValue("ownerid", ownerid);
  150. insertSQL.setValue("content", contentstr);
  151. insertSQL.setValue("resource", content.getStringValue("resource"));
  152. insertSQL.setValue("target", content.getStringValue("target"));
  153. insertSQL.setValue("results", content.getStringValue("results"));
  154. insertSQL.setValue("nextplan", content.getStringValue("nextplan"));
  155. insertSQL.setValue("type", content.getStringValue("type"));
  156. insertSQL.setValue("followobj", content.getStringValue("followobj"));
  157. insertSQL.setValue("products", content.getStringValue("products"));
  158. insertSQL.setValue("sys_taskid", content.getLongValue("sys_taskid"));
  159. insertSQL.setValue("sa_agentsid", content.getLongValue("sa_agentsid"));
  160. insertSQL.setValue("sa_hospitaldepid", content.getLongValue("sa_hospitaldepid"));
  161. insertSQL.setValue("sa_doctorid", content.getLongValue("sa_doctorid"));
  162. insertSQL.setValue("sa_customersid", content.getLongValue("sa_customersid"));
  163. sqlList.add(insertSQL.getSQL());
  164. sqlList.add(DataContrlLog.createLog(this, ownertable, ownerid, "新增跟进动态", "新增跟进动态【" + contentstr + "】").getSQL());
  165. content.put("sys_datafollowupid", sys_datafollowupid);
  166. } else {
  167. Rows rows = dbConnect.runSqlQuery("select *from sys_datafollowup where siteid='" + siteid + "' and sys_datafollowupid=" + sys_datafollowupid);
  168. if (rows.get(0).getLong("createuserid") != userid) {
  169. return getReturnObject().setCode("0134", new String[0]).toString();//非跟进创建人不可进行修改操作
  170. }
  171. UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sys_datafollowup");
  172. updateSQL.setSiteid(siteid);
  173. updateSQL.setUniqueid(sys_datafollowupid);
  174. updateSQL.setValue("content", contentstr);
  175. updateSQL.setValue("resource", content.getStringValue("resource"));
  176. updateSQL.setValue("target", content.getStringValue("target"));
  177. updateSQL.setValue("results", content.getStringValue("results"));
  178. updateSQL.setValue("nextplan", content.getStringValue("nextplan"));
  179. updateSQL.setValue("type", content.getStringValue("type"));
  180. updateSQL.setValue("followobj", content.getStringValue("followobj"));
  181. updateSQL.setValue("products", content.getStringValue("products"));
  182. updateSQL.setValue("sys_taskid", content.getLongValue("sys_taskid"));
  183. updateSQL.setValue("sa_agentsid", content.getLongValue("sa_agentsid"));
  184. updateSQL.setValue("sa_hospitaldepid", content.getLongValue("sa_hospitaldepid"));
  185. updateSQL.setValue("sa_doctorid", content.getLongValue("sa_doctorid"));
  186. updateSQL.setValue("sa_customersid", content.getLongValue("sa_customersid"));
  187. sqlList.add(updateSQL.getSQL());
  188. sqlList.add(DataContrlLog.createLog(this, ownertable, ownerid, "编辑跟进动态", "编辑跟进动态【" + contentstr + "】").getSQL());
  189. }
  190. dbConnect.runSqlUpdate(sqlList);
  191. //更新医院的状态
  192. if (ownertable.equals("sa_customers")) {
  193. UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sa_customers");
  194. updateSQL.setSiteid(siteid);
  195. updateSQL.setValue("status", "已开发");
  196. updateSQL.setWhere("sa_customersid", ownerid);
  197. updateSQL.update();
  198. }
  199. return queryFollowUpMain();
  200. }
  201. @API(title = "数据跟进日志删除", apiversion = R.ID20220930121701.v1.class)
  202. @CACHEING_CLEAN(apiversions = R.ID20220930121501.class)
  203. public String deleteFollowUp() throws YosException {
  204. long sys_datafollowupid = content.getLongValue("sys_datafollowupid");
  205. Rows rows = dbConnect.runSqlQuery("select *from sys_datafollowup where siteid='" + siteid + "' and sys_datafollowupid=" + sys_datafollowupid);
  206. if (rows.isNotEmpty()) {
  207. Row row = rows.get(0);
  208. if (row.getLong("createuserid") != userid) {
  209. return getReturnObject().setCode("0135", new String[0]).toString();//非跟进创建人不可进行删除操作
  210. }
  211. ArrayList<String> sqlList = new ArrayList<>();
  212. sqlList.add("update sys_datafollowup set deleted=1 where siteid='" + siteid + "' and sys_datafollowupid=" + sys_datafollowupid);
  213. sqlList.add(DataContrlLog.createLog(this, row.getString("ownertable"), row.getLong("ownerid"), "删除跟进动态", "删除跟进动态【" + row.getString("content") + "】").getSQL());
  214. dbConnect.runSqlUpdate(sqlList);
  215. if (content.containsKey("deletereason")) {
  216. List<Long> id = new ArrayList<>();
  217. id.add(sys_datafollowupid);
  218. DataExtend.createDeleteReasonSql(this, "sys_datafollowup", id, content.getString("deletereason"));
  219. }
  220. }
  221. return getSucReturnObject().toString();
  222. }
  223. }