task2.java 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. package restcontroller.common.task;
  2. import beans.datacontrllog.DataContrlLog;
  3. import beans.salearea.SaleArea;
  4. import com.alibaba.fastjson.JSONObject;
  5. import common.Controller;
  6. import common.YosException;
  7. import common.annotation.API;
  8. import common.data.*;
  9. import restcontroller.R;
  10. import java.time.LocalDate;
  11. import java.time.YearMonth;
  12. import java.time.temporal.ChronoUnit;
  13. import java.util.ArrayList;
  14. import java.util.List;
  15. public class task2 extends Controller {
  16. /**
  17. * 构造函数
  18. *
  19. * @param content
  20. */
  21. public task2(JSONObject content) throws YosException {
  22. super(content);
  23. }
  24. @API(title = "创建任务", apiversion = R.ID2025122209075802.v1.class)
  25. public String insertTask() throws YosException {
  26. String begindate = content.getStringValueForDate("begindate", "yyyy-MM-dd", "");
  27. String enddate = content.getStringValueForDate("enddate", "yyyy-MM-dd", "");
  28. if (begindate.isEmpty()) {
  29. begindate = getDate_Str();
  30. }
  31. if (enddate.isEmpty()) {
  32. enddate = getDate_Str();
  33. }
  34. ArrayList<String> sqlList = new ArrayList<>();
  35. for (String date : getAlldates(begindate, enddate)) {
  36. InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sys_task");
  37. insertSQL.setSiteid(siteid);
  38. insertSQL.setUniqueid(createTableID("sys_task"));
  39. insertSQL.setValue("taskdate", date);
  40. insertSQL.setValue("title", content.getStringValue("title"));
  41. insertSQL.setValue("contenttext", content.getStringValue("contenttext"));
  42. insertSQL.setValue("begindate", begindate);
  43. insertSQL.setValue("enddate", enddate);
  44. sqlList.add(insertSQL.getSQL());
  45. sqlList.add(DataContrlLog.createLog(this, "sys_task", insertSQL.getUniqueid(), "新建", "新建成功").getSQL());
  46. }
  47. dbConnect.runSqlUpdate(sqlList);
  48. return getSucReturnObject().toString();
  49. }
  50. //返回2个日期间的所有日期
  51. public ArrayList<String> getAlldates(String begindate, String enddate) {
  52. LocalDate start = LocalDate.parse(begindate);
  53. LocalDate end = LocalDate.parse(enddate);
  54. ArrayList<String> dates = new ArrayList<>();
  55. long daysBetween = ChronoUnit.DAYS.between(start, end);
  56. for (long i = 0; i <= daysBetween; i++) {
  57. dates.add(start.plusDays(i).toString());
  58. }
  59. return dates;
  60. }
  61. @API(title = "任务详情", apiversion = R.ID2025122210022002.v1.class)
  62. public String taskDetail() throws YosException {
  63. Long sys_taskid = content.getLongValue("sys_taskid");
  64. QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sys_task", "t1.*").setTableAlias("t1");
  65. querySQL.setSiteid(siteid);
  66. querySQL.setWhere("sys_taskid", sys_taskid);
  67. Rows row = querySQL.query();
  68. Row detailRow = row.get(0);
  69. return getSucReturnObject().setData(detailRow).toString();
  70. }
  71. @API(title = "获取指定的月份的任务列表", apiversion = R.ID2025122210193402.v1.class)
  72. public String list() throws YosException {
  73. int year = content.getIntValue("year");
  74. int month = content.getIntValue("month");
  75. Long taskUserid = content.getLongValue("taskUserid");
  76. //指定的日期数据
  77. List<String> dates = getAllDatesInMonth(year, month);
  78. //任务数据
  79. QuerySQL taskquerySQL = SQLFactory.createQuerySQL(this, "sys_task", "t1.*").setTableAlias("t1");
  80. taskquerySQL.setSiteid(siteid);
  81. taskquerySQL.setWhere("createuserid", taskUserid);
  82. taskquerySQL.setWhere("year(taskdate)=" + year);
  83. taskquerySQL.setWhere("month(taskdate)=" + month);
  84. taskquerySQL.setCondition("t1.title");
  85. Rows taskrows = taskquerySQL.query();
  86. RowsMap taskRowsMap = taskrows.toRowsMap("taskdate");
  87. //跟进数据
  88. QuerySQL followquerySQL = SQLFactory.createQuerySQL(dbConnect, "sys_datafollowup", "t1.*").setTableAlias("t1");
  89. followquerySQL.addJoinTable(JOINTYPE.left, "sa_customers", "t2", "t2.sa_customersid=t1.sa_customersid and t2.siteid=t1.siteid");
  90. followquerySQL.addJoinTable(JOINTYPE.left, "sys_enterprise", "t21", "t21.sys_enterpriseid=t2.sys_enterpriseid and t21.siteid=t2.siteid");
  91. followquerySQL.addJoinTable(JOINTYPE.left, "sa_hospitaldep", "t3", "t3.sa_hospitaldepid=t1.sa_hospitaldepid and t3.siteid=t1.siteid",
  92. "hospitaldepname");
  93. followquerySQL.addJoinTable(JOINTYPE.left, "sa_doctor", "t4", "t4.sa_doctorid=t1.sa_doctorid and t4.siteid=t1.siteid",
  94. "doctorname");
  95. followquerySQL.addJoinTable(JOINTYPE.left, "sys_task", "t5", "t5.sys_taskid=t1.sys_taskid and t5.siteid=t1.siteid");
  96. followquerySQL.addJoinTable(JOINTYPE.left, "sa_agents", "t6", "t6.sa_agentsid=t1.sa_agentsid and t6.siteid=t1.siteid");
  97. followquerySQL.addJoinTable(JOINTYPE.left, "sys_enterprise", "t61", "t61.sys_enterpriseid=t6.sys_enterpriseid and t61.siteid=t6.siteid");
  98. followquerySQL.addQueryFields("hospitalname", "t21.enterprisename");
  99. followquerySQL.addQueryFields("tasktitle", "t5.title");
  100. followquerySQL.addQueryFields("agentsname", "t61.enterprisename");
  101. followquerySQL.setSiteid(siteid);
  102. followquerySQL.addQueryFields("followdate", "DATE_FORMAT(t1.createdate,'%Y-%m-%d')");
  103. followquerySQL.setWhere("t1.createuserid", taskUserid);
  104. followquerySQL.setWhere("year(t1.createdate)=" + year);
  105. followquerySQL.setWhere("month(t1.createdate)=" + month);
  106. Rows followrows = followquerySQL.query();
  107. RowsMap followRowsMap = followrows.toRowsMap("followdate");
  108. Row row = new Row();
  109. for (String date : dates) {
  110. //任务
  111. Rows taskRows = taskRowsMap.getOrDefault(date, new Rows());
  112. //跟进
  113. Rows followRows = followRowsMap.getOrDefault(date, new Rows());
  114. Row subrow = new Row();
  115. subrow.put("task", taskRows);
  116. subrow.put("follow", followRows);
  117. row.put(date, subrow);
  118. }
  119. return getSucReturnObject().setData(row).toString();
  120. }
  121. public static List<String> getAllDatesInMonth(int year, int month) {
  122. YearMonth yearMonth = YearMonth.of(year, month);
  123. int daysInMonth = yearMonth.lengthOfMonth(); // 获取该月天数
  124. List<String> dateStrings = new ArrayList<>();
  125. for (int day = 1; day <= daysInMonth; day++) {
  126. LocalDate date = LocalDate.of(year, month, day);
  127. dateStrings.add(date.toString()); // 默认格式 "yyyy-MM-dd"
  128. }
  129. return dateStrings;
  130. }
  131. @API(title = "获取当前账号的下级信息", apiversion = R.ID2025122211095302.v1.class)
  132. public String usertask() throws YosException {
  133. Rows salearearows = dbConnect.runSqlQuery("SELECT sa_saleareaid from sa_salearea_hr WHERE hrid=" + hrid + " and siteid='" + siteid + "'");
  134. ArrayList<Long> saleareaids = salearearows.toArrayList("sa_saleareaid", new ArrayList<>());
  135. saleareaids.add(-1L);
  136. ArrayList<Long> subsaleareaids = SaleArea.getSubSaleAreaIds(this, saleareaids);
  137. QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_salearea_hr", "hrid");
  138. querySQL.setSiteid(siteid);
  139. querySQL.setWhere("sa_saleareaid", subsaleareaids);
  140. ArrayList<Long> hrids = querySQL.query().toArrayList("hrid", new ArrayList<>());
  141. hrids.add(-1L);
  142. // hrids.add(hrid);
  143. querySQL = SQLFactory.createQuerySQL(this, "sys_hr", "userid", "hrid", "name")
  144. .setTableAlias("t1");
  145. querySQL.setSiteid(siteid);
  146. querySQL.setWhere("status=0 and userid>0");
  147. querySQL.setWhere("t1.hrid", hrids);
  148. querySQL.setPage(pageSize, pageNumber);
  149. querySQL.setCondition("t1.name");
  150. Rows rows = querySQL.query();
  151. return getSucReturnObject().setData(rows).toString();
  152. }
  153. @API(title = "查询任务", apiversion = R.ID2025122309161202.v1.class)
  154. public String tasklist() throws YosException {
  155. //任务数据
  156. QuerySQL taskquerySQL = SQLFactory.createQuerySQL(this, "sys_task", "t1.*").setTableAlias("t1");
  157. taskquerySQL.setSiteid(siteid);
  158. taskquerySQL.setWhere("createuserid", userid);
  159. taskquerySQL.setWhere("week(CURRENT_DATE)=WEEK(t1.taskdate)");
  160. taskquerySQL.setCondition("t1.title", "t1.contenttext");
  161. if (pageSorting.equals("''")) {
  162. pageSorting = "t1.createdate desc";
  163. }
  164. Rows rows = taskquerySQL.query();
  165. return getSucReturnObject().setData(rows).toString();
  166. }
  167. }