package restcontroller.system.datafollowup; import beans.datacomment.DataComment; import beans.datacontrllog.DataContrlLog; import beans.dataextend.DataExtend; import beans.datafollowup.Datafollowup; import beans.datateam.DataTeam; import beans.hr.Hr; import beans.salesfees.SalesFees; import beans.user.User; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import common.Controller; import common.YosException; import common.annotation.API; import common.annotation.CACHEING; import common.annotation.CACHEING_CLEAN; import common.data.*; import restcontroller.R; import restcontroller.webmanage.executorService.Executor; import java.math.BigDecimal; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; public class datafollowup extends Controller { public datafollowup(JSONObject content) throws YosException { super(content); } @API(title = "数据跟进日志查询", apiversion = R.ID20220930121501.v1.class) @CACHEING public String queryFollowUp() throws YosException { StringBuffer where = new StringBuffer(" 1=1 "); if (content.containsKey("where")) { JSONObject whereObject = content.getJSONObject("where"); if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) { where.append(" and("); where.append("t1.content like'%").append(whereObject.getString("condition")).append("%' "); where.append("or t1.target like'%").append(whereObject.getString("condition")).append("%' "); where.append("or t1.results like'%").append(whereObject.getString("condition")).append("%' "); where.append("or t1.nextplan like'%").append(whereObject.getString("condition")).append("%' "); where.append("or t1.createby like'%").append(whereObject.getString("condition")).append("%' "); where.append(")"); } } where.append(" and t1.createuserid=").append(userid); int type = content.getIntValue("type"); String ownertable = content.getString("ownertable"); long ownerid = content.getLong("ownerid"); QuerySQL querySQL = SQLFactory.createQuerySQL(dbConnect, "sys_datafollowup", "t1.*").setTableAlias("t1"); querySQL.addJoinTable(JOINTYPE.left, "sa_customers", "t2", "t2.sa_customersid=t1.sa_customersid and t2.siteid=t1.siteid"); querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise", "t21", "t21.sys_enterpriseid=t2.sys_enterpriseid and t21.siteid=t2.siteid"); querySQL.addJoinTable(JOINTYPE.left, "sa_hospitaldep", "t3", "t3.sa_hospitaldepid=t1.sa_hospitaldepid and t3.siteid=t1.siteid", "hospitaldepname"); querySQL.addJoinTable(JOINTYPE.left, "sa_doctor", "t4", "t4.sa_doctorid=t1.sa_doctorid and t4.siteid=t1.siteid", "doctorname"); querySQL.addJoinTable(JOINTYPE.left, "sys_task", "t5", "t5.sys_taskid=t1.sys_taskid and t5.siteid=t1.siteid"); querySQL.addJoinTable(JOINTYPE.left, "sa_agents", "t6", "t6.sa_agentsid=t1.sa_agentsid and t6.siteid=t1.siteid"); querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise", "t61", "t61.sys_enterpriseid=t6.sys_enterpriseid and t61.siteid=t6.siteid"); querySQL.addQueryFields("hospitalname", "t21.enterprisename"); querySQL.addQueryFields("tasktitle", "t5.title"); querySQL.addQueryFields("agentsname", "t61.enterprisename"); querySQL.setSiteid(siteid); querySQL.setWhere(where); switch (ownertable) { case "sa_customers": querySQL.setWhere("t1.sa_customersid", ownerid); break; case "sa_hospitaldep": querySQL.setWhere("t1.sa_hospitaldepid", ownerid); break; case "sa_doctor": querySQL.setWhere("t1.sa_doctorid", ownerid); break; case "sa_agents": querySQL.setWhere("t1.sa_agentsid", ownerid); break; case "sys_task": querySQL.setWhere("t1.sys_taskid", ownerid); break; default: querySQL.setWhere("ownertable", ownertable); querySQL.setWhere("ownerid", ownerid); } querySQL.setPage(pageSize, pageNumber); Rows rows = querySQL.query(); ArrayList sys_datafollowupids = rows.toArrayList("sys_datafollowupid", new ArrayList()); HashMap followupsalefeesHashMap = SalesFees.getfollowupsalefeesamount(this, ownertable, sys_datafollowupids); RowsMap map = getAttachmentUrl("sys_datafollowup", sys_datafollowupids); RowsMap userExtendMsgMap = User.getUserExtendMsg(this, rows.toArrayList("createuserid", new ArrayList<>())); for (Row row : rows) { String sys_datafollowupid = row.getString("sys_datafollowupid"); row.put("headpic", getHeadPic(row.getLong("createuserid"))); row.put("attinfos", map.get(sys_datafollowupid)); row.put("attcount", map.get(sys_datafollowupid).size()); row.put("userextend", userExtendMsgMap.get(row.getString("createuserid"))); if (followupsalefeesHashMap.containsKey(sys_datafollowupid)) { row.put("salesfeesamount", followupsalefeesHashMap.get(sys_datafollowupid)); } else { row.put("salesfeesamount", ""); } } return getSucReturnObject().setData(rows).toString(); } @API(title = "数据跟进日志详情查询", apiversion = R.ID20221026085601.v1.class) public String queryFollowUpMain() throws YosException { Long sys_datafollowupid = content.getLong("sys_datafollowupid"); QuerySQL querySQL = SQLFactory.createQuerySQL(dbConnect, "sys_datafollowup", "t1.*").setTableAlias("t1"); querySQL.addJoinTable(JOINTYPE.left, "sa_customers", "t2", "t2.sa_customersid=t1.sa_customersid and t2.siteid=t1.siteid"); querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise", "t21", "t21.sys_enterpriseid=t2.sys_enterpriseid and t21.siteid=t2.siteid"); querySQL.addJoinTable(JOINTYPE.left, "sa_hospitaldep", "t3", "t3.sa_hospitaldepid=t1.sa_hospitaldepid and t3.siteid=t1.siteid", "hospitaldepname"); querySQL.addJoinTable(JOINTYPE.left, "sa_doctor", "t4", "t4.sa_doctorid=t1.sa_doctorid and t4.siteid=t1.siteid", "doctorname"); querySQL.addJoinTable(JOINTYPE.left, "sys_task", "t5", "t5.sys_taskid=t1.sys_taskid and t5.siteid=t1.siteid"); querySQL.addJoinTable(JOINTYPE.left, "sa_agents", "t6", "t6.sa_agentsid=t1.sa_agentsid and t6.siteid=t1.siteid"); querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise", "t61", "t61.sys_enterpriseid=t6.sys_enterpriseid and t61.siteid=t6.siteid"); querySQL.addQueryFields("hospitalname", "t21.enterprisename"); querySQL.addQueryFields("tasktitle", "t5.title"); querySQL.addQueryFields("agentsname", "t61.enterprisename"); querySQL.setSiteid(siteid); querySQL.setWhere("sys_datafollowupid", sys_datafollowupid); Rows rows = querySQL.query(); RowsMap userExtendMsgMap = User.getUserExtendMsg(this, rows.toArrayList("createuserid", new ArrayList<>())); for (Row row : rows) { String ownertable = row.getString("ownertable"); Rows attachmentUrlRows = getAttachmentUrl("sys_datafollowup", sys_datafollowupid); String salesfeesamount = SalesFees.getfollowupsalefeesamount(this, ownertable, sys_datafollowupid); row.put("headpic", getHeadPic(row.getLong("createuserid"))); row.put("attinfos", attachmentUrlRows); row.put("userextend", userExtendMsgMap.get(row.getString("createuserid"))); row.put("salesfeesamount", salesfeesamount); } return getSucReturnObject().setData(rows.isNotEmpty() ? rows.get(0) : new Row()).toString(); } @API(title = "数据跟进日志新增修改", apiversion = R.ID20220930121601.v1.class) @CACHEING_CLEAN(apiversions = R.ID20220930121501.class) public String insertormodifyFollowUp() throws YosException { long sys_datafollowupid = content.getLongValue("sys_datafollowupid"); String ownertable = content.getString("ownertable"); long ownerid = content.getLong("ownerid"); String contentstr = content.getStringValue("content"); ArrayList sqlList = new ArrayList<>(); if (sys_datafollowupid <= 0) { sys_datafollowupid = createTableID("sys_datafollowup"); InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sys_datafollowup"); insertSQL.setSiteid(siteid); insertSQL.setUniqueid(sys_datafollowupid); insertSQL.setValue("ownertable", ownertable); insertSQL.setValue("ownerid", ownerid); insertSQL.setValue("content", contentstr); insertSQL.setValue("resource", content.getStringValue("resource")); insertSQL.setValue("target", content.getStringValue("target")); insertSQL.setValue("results", content.getStringValue("results")); insertSQL.setValue("nextplan", content.getStringValue("nextplan")); insertSQL.setValue("type", content.getStringValue("type")); insertSQL.setValue("followobj", content.getStringValue("followobj")); insertSQL.setValue("products", content.getStringValue("products")); insertSQL.setValue("sys_taskid", content.getLongValue("sys_taskid")); insertSQL.setValue("sa_agentsid", content.getLongValue("sa_agentsid")); insertSQL.setValue("sa_hospitaldepid", content.getLongValue("sa_hospitaldepid")); insertSQL.setValue("sa_doctorid", content.getLongValue("sa_doctorid")); insertSQL.setValue("sa_customersid", content.getLongValue("sa_customersid")); sqlList.add(insertSQL.getSQL()); sqlList.add(DataContrlLog.createLog(this, ownertable, ownerid, "新增跟进动态", "新增跟进动态【" + contentstr + "】").getSQL()); content.put("sys_datafollowupid", sys_datafollowupid); } else { Rows rows = dbConnect.runSqlQuery("select *from sys_datafollowup where siteid='" + siteid + "' and sys_datafollowupid=" + sys_datafollowupid); if (rows.get(0).getLong("createuserid") != userid) { return getReturnObject().setCode("0134", new String[0]).toString();//非跟进创建人不可进行修改操作 } UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sys_datafollowup"); updateSQL.setSiteid(siteid); updateSQL.setUniqueid(sys_datafollowupid); updateSQL.setValue("content", contentstr); updateSQL.setValue("resource", content.getStringValue("resource")); updateSQL.setValue("target", content.getStringValue("target")); updateSQL.setValue("results", content.getStringValue("results")); updateSQL.setValue("nextplan", content.getStringValue("nextplan")); updateSQL.setValue("type", content.getStringValue("type")); updateSQL.setValue("followobj", content.getStringValue("followobj")); updateSQL.setValue("products", content.getStringValue("products")); updateSQL.setValue("sys_taskid", content.getLongValue("sys_taskid")); updateSQL.setValue("sa_agentsid", content.getLongValue("sa_agentsid")); updateSQL.setValue("sa_hospitaldepid", content.getLongValue("sa_hospitaldepid")); updateSQL.setValue("sa_doctorid", content.getLongValue("sa_doctorid")); updateSQL.setValue("sa_customersid", content.getLongValue("sa_customersid")); sqlList.add(updateSQL.getSQL()); sqlList.add(DataContrlLog.createLog(this, ownertable, ownerid, "编辑跟进动态", "编辑跟进动态【" + contentstr + "】").getSQL()); } dbConnect.runSqlUpdate(sqlList); //更新医院的状态 if (ownertable.equals("sa_customers")) { UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sa_customers"); updateSQL.setSiteid(siteid); updateSQL.setValue("status", "已开发"); updateSQL.setWhere("sa_customersid", ownerid); updateSQL.update(); } return queryFollowUpMain(); } @API(title = "数据跟进日志删除", apiversion = R.ID20220930121701.v1.class) @CACHEING_CLEAN(apiversions = R.ID20220930121501.class) public String deleteFollowUp() throws YosException { long sys_datafollowupid = content.getLongValue("sys_datafollowupid"); Rows rows = dbConnect.runSqlQuery("select *from sys_datafollowup where siteid='" + siteid + "' and sys_datafollowupid=" + sys_datafollowupid); if (rows.isNotEmpty()) { Row row = rows.get(0); if (row.getLong("createuserid") != userid) { return getReturnObject().setCode("0135", new String[0]).toString();//非跟进创建人不可进行删除操作 } ArrayList sqlList = new ArrayList<>(); sqlList.add("update sys_datafollowup set deleted=1 where siteid='" + siteid + "' and sys_datafollowupid=" + sys_datafollowupid); sqlList.add(DataContrlLog.createLog(this, row.getString("ownertable"), row.getLong("ownerid"), "删除跟进动态", "删除跟进动态【" + row.getString("content") + "】").getSQL()); dbConnect.runSqlUpdate(sqlList); if (content.containsKey("deletereason")) { List id = new ArrayList<>(); id.add(sys_datafollowupid); DataExtend.createDeleteReasonSql(this, "sys_datafollowup", id, content.getString("deletereason")); } } return getSucReturnObject().toString(); } }