package restcontroller.common.task; import beans.datacontrllog.DataContrlLog; import beans.salearea.SaleArea; import com.alibaba.fastjson.JSONObject; import common.Controller; import common.YosException; import common.annotation.API; import common.data.*; import restcontroller.R; import java.time.LocalDate; import java.time.YearMonth; import java.time.temporal.ChronoUnit; import java.util.ArrayList; import java.util.List; public class task2 extends Controller { /** * 构造函数 * * @param content */ public task2(JSONObject content) throws YosException { super(content); } @API(title = "创建任务", apiversion = R.ID2025122209075802.v1.class) public String insertTask() throws YosException { String begindate = content.getStringValueForDate("begindate", "yyyy-MM-dd", ""); String enddate = content.getStringValueForDate("enddate", "yyyy-MM-dd", ""); if (begindate.isEmpty()) { begindate = getDate_Str(); } if (enddate.isEmpty()) { enddate = getDate_Str(); } ArrayList sqlList = new ArrayList<>(); for (String date : getAlldates(begindate, enddate)) { InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sys_task"); insertSQL.setSiteid(siteid); insertSQL.setUniqueid(createTableID("sys_task")); insertSQL.setValue("taskdate", date); insertSQL.setValue("title", content.getStringValue("title")); insertSQL.setValue("contenttext", content.getStringValue("contenttext")); insertSQL.setValue("begindate", begindate); insertSQL.setValue("enddate", enddate); sqlList.add(insertSQL.getSQL()); sqlList.add(DataContrlLog.createLog(this, "sys_task", insertSQL.getUniqueid(), "新建", "新建成功").getSQL()); } dbConnect.runSqlUpdate(sqlList); return getSucReturnObject().toString(); } //返回2个日期间的所有日期 public ArrayList getAlldates(String begindate, String enddate) { LocalDate start = LocalDate.parse(begindate); LocalDate end = LocalDate.parse(enddate); ArrayList dates = new ArrayList<>(); long daysBetween = ChronoUnit.DAYS.between(start, end); for (long i = 0; i <= daysBetween; i++) { dates.add(start.plusDays(i).toString()); } return dates; } @API(title = "任务详情", apiversion = R.ID2025122210022002.v1.class) public String taskDetail() throws YosException { Long sys_taskid = content.getLongValue("sys_taskid"); QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sys_task", "t1.*").setTableAlias("t1"); querySQL.setSiteid(siteid); querySQL.setWhere("sys_taskid", sys_taskid); Rows row = querySQL.query(); Row detailRow = row.get(0); return getSucReturnObject().setData(detailRow).toString(); } @API(title = "获取指定的月份的任务列表", apiversion = R.ID2025122210193402.v1.class) public String list() throws YosException { int year = content.getIntValue("year"); int month = content.getIntValue("month"); Long taskUserid = content.getLongValue("taskUserid"); //指定的日期数据 List dates = getAllDatesInMonth(year, month); //任务数据 QuerySQL taskquerySQL = SQLFactory.createQuerySQL(this, "sys_task", "t1.*").setTableAlias("t1"); taskquerySQL.setSiteid(siteid); taskquerySQL.setWhere("createuserid", taskUserid); taskquerySQL.setWhere("year(taskdate)=" + year); taskquerySQL.setWhere("month(taskdate)=" + month); taskquerySQL.setCondition("t1.title"); Rows taskrows = taskquerySQL.query(); RowsMap taskRowsMap = taskrows.toRowsMap("taskdate"); //跟进数据 QuerySQL followquerySQL = SQLFactory.createQuerySQL(dbConnect, "sys_datafollowup", "t1.*").setTableAlias("t1"); followquerySQL.addJoinTable(JOINTYPE.left, "sa_customers", "t2", "t2.sa_customersid=t1.sa_customersid and t2.siteid=t1.siteid"); followquerySQL.addJoinTable(JOINTYPE.left, "sys_enterprise", "t21", "t21.sys_enterpriseid=t2.sys_enterpriseid and t21.siteid=t2.siteid"); followquerySQL.addJoinTable(JOINTYPE.left, "sa_hospitaldep", "t3", "t3.sa_hospitaldepid=t1.sa_hospitaldepid and t3.siteid=t1.siteid", "hospitaldepname"); followquerySQL.addJoinTable(JOINTYPE.left, "sa_doctor", "t4", "t4.sa_doctorid=t1.sa_doctorid and t4.siteid=t1.siteid", "doctorname"); followquerySQL.addJoinTable(JOINTYPE.left, "sys_task", "t5", "t5.sys_taskid=t1.sys_taskid and t5.siteid=t1.siteid"); followquerySQL.addJoinTable(JOINTYPE.left, "sa_agents", "t6", "t6.sa_agentsid=t1.sa_agentsid and t6.siteid=t1.siteid"); followquerySQL.addJoinTable(JOINTYPE.left, "sys_enterprise", "t61", "t61.sys_enterpriseid=t6.sys_enterpriseid and t61.siteid=t6.siteid"); followquerySQL.addQueryFields("hospitalname", "t21.enterprisename"); followquerySQL.addQueryFields("tasktitle", "t5.title"); followquerySQL.addQueryFields("agentsname", "t61.enterprisename"); followquerySQL.setSiteid(siteid); followquerySQL.addQueryFields("followdate", "DATE_FORMAT(t1.createdate,'%Y-%m-%d')"); followquerySQL.setWhere("t1.createuserid", taskUserid); followquerySQL.setWhere("year(t1.createdate)=" + year); followquerySQL.setWhere("month(t1.createdate)=" + month); Rows followrows = followquerySQL.query(); RowsMap followRowsMap = followrows.toRowsMap("followdate"); Row row = new Row(); for (String date : dates) { //任务 Rows taskRows = taskRowsMap.getOrDefault(date, new Rows()); //跟进 Rows followRows = followRowsMap.getOrDefault(date, new Rows()); Row subrow = new Row(); subrow.put("task", taskRows); subrow.put("follow", followRows); row.put(date, subrow); } return getSucReturnObject().setData(row).toString(); } public static List getAllDatesInMonth(int year, int month) { YearMonth yearMonth = YearMonth.of(year, month); int daysInMonth = yearMonth.lengthOfMonth(); // 获取该月天数 List dateStrings = new ArrayList<>(); for (int day = 1; day <= daysInMonth; day++) { LocalDate date = LocalDate.of(year, month, day); dateStrings.add(date.toString()); // 默认格式 "yyyy-MM-dd" } return dateStrings; } @API(title = "获取当前账号的下级信息", apiversion = R.ID2025122211095302.v1.class) public String usertask() throws YosException { Rows salearearows = dbConnect.runSqlQuery("SELECT sa_saleareaid from sa_salearea_hr WHERE hrid=" + hrid + " and siteid='" + siteid + "'"); ArrayList saleareaids = salearearows.toArrayList("sa_saleareaid", new ArrayList<>()); saleareaids.add(-1L); ArrayList subsaleareaids = SaleArea.getSubSaleAreaIds(this, saleareaids); QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_salearea_hr", "hrid"); querySQL.setSiteid(siteid); querySQL.setWhere("sa_saleareaid", subsaleareaids); ArrayList hrids = querySQL.query().toArrayList("hrid", new ArrayList<>()); hrids.add(-1L); // hrids.add(hrid); querySQL = SQLFactory.createQuerySQL(this, "sys_hr", "userid", "hrid", "name") .setTableAlias("t1"); querySQL.setSiteid(siteid); querySQL.setWhere("status=0 and userid>0"); querySQL.setWhere("t1.hrid", hrids); querySQL.setPage(pageSize, pageNumber); querySQL.setCondition("t1.name"); Rows rows = querySQL.query(); return getSucReturnObject().setData(rows).toString(); } @API(title = "查询任务", apiversion = R.ID2025122309161202.v1.class) public String tasklist() throws YosException { //任务数据 QuerySQL taskquerySQL = SQLFactory.createQuerySQL(this, "sys_task", "t1.*").setTableAlias("t1"); taskquerySQL.setSiteid(siteid); taskquerySQL.setWhere("createuserid", userid); taskquerySQL.setWhere("week(CURRENT_DATE)=WEEK(t1.taskdate)"); taskquerySQL.setCondition("t1.title", "t1.contenttext"); if (pageSorting.equals("''")) { pageSorting = "t1.createdate desc"; } Rows rows = taskquerySQL.query(); return getSucReturnObject().setData(rows).toString(); } }