|
|
@@ -0,0 +1,341 @@
|
|
|
+package restcontroller.webmanage.sale.salestarget2;
|
|
|
+
|
|
|
+import beans.datacontrllog.DataContrlLog;
|
|
|
+import beans.parameter.Parameter;
|
|
|
+import beans.salearea.SaleArea;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import common.Controller;
|
|
|
+import common.YosException;
|
|
|
+import common.annotation.API;
|
|
|
+import common.data.*;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
+import restcontroller.R;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashSet;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 目标编制
|
|
|
+ */
|
|
|
+public class salestargetbill extends Controller {
|
|
|
+ /**
|
|
|
+ * 构造函数
|
|
|
+ *
|
|
|
+ * @param content
|
|
|
+ */
|
|
|
+ public salestargetbill(JSONObject content) throws YosException {
|
|
|
+ super(content);
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "新建或编辑", apiversion = R.ID2025122414005202.v1.class)
|
|
|
+ public String insertOrUpdate() throws YosException {
|
|
|
+ Long sa_salestargetbillid = content.getLongValue("sa_salestargetbillid");
|
|
|
+ Long year = content.getLongValue("year");
|
|
|
+ Long sa_customersid = content.getLongValue("sa_customersid");
|
|
|
+
|
|
|
+ ArrayList<String> sqlList = new ArrayList<>();
|
|
|
+
|
|
|
+ if (sa_salestargetbillid <= 0) {
|
|
|
+
|
|
|
+ if (dbConnect.runSqlQuery("SELECT * from sa_salestargetbill WHERE createuserid=" + userid + " and year='" + year + "' and sa_customersid=" + sa_customersid + " and siteid='" + siteid + "'").isNotEmpty()) {
|
|
|
+ throw new YosException("数据已存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ sa_salestargetbillid = createTableID("sa_salestargetbill");
|
|
|
+ InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sa_salestargetbill");
|
|
|
+ insertSQL.setSiteid(siteid);
|
|
|
+ insertSQL.setUniqueid(sa_salestargetbillid);
|
|
|
+ insertSQL.setValue("billno", createBillCode("salestargetbill"));
|
|
|
+ insertSQL.setValue("year", year);
|
|
|
+ insertSQL.setValue("sa_customersid", sa_customersid);
|
|
|
+ insertSQL.setValue("remarks", content.getStringValue("remarks"));
|
|
|
+ sqlList.add(insertSQL.getSQL());
|
|
|
+ sqlList.add(DataContrlLog.createLog(this, "sa_salestargetbill", sa_salestargetbillid, "新建", "新建成功").getSQL());
|
|
|
+ content.put("sa_salestargetbillid", sa_salestargetbillid);
|
|
|
+ } else {
|
|
|
+ UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sa_salestargetbill");
|
|
|
+ updateSQL.setSiteid(siteid);
|
|
|
+ updateSQL.setUniqueid(sa_salestargetbillid);
|
|
|
+ updateSQL.setValue("remarks", content.getStringValue("remarks"));
|
|
|
+ sqlList.add(updateSQL.getSQL());
|
|
|
+ sqlList.add(DataContrlLog.createLog(this, "sa_salestargetbill", sa_salestargetbillid, "编辑", "编辑成功").getSQL());
|
|
|
+ }
|
|
|
+ dbConnect.runSqlUpdate(sqlList);
|
|
|
+
|
|
|
+ return detail();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "详细", apiversion = R.ID2025122414022702.v1.class)
|
|
|
+ public String detail() throws YosException {
|
|
|
+
|
|
|
+ Long sa_salestargetbillid = content.getLongValue("sa_salestargetbillid");
|
|
|
+
|
|
|
+ QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_salestargetbill", "*").setTableAlias("t1");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.inner, "sa_customers", "t2", "t1.sa_customersid=t2.sa_customersid");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise", "t3", "t3.sys_enterpriseid=t2.sys_enterpriseid and t3.siteid=t2.siteid");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "sa_salearea", "t4", "t4.sa_saleareaid=t2.sa_saleareaid and t4.siteid=t2.siteid",
|
|
|
+ "areaname", "sa_saleareaid");
|
|
|
+ querySQL.addQueryFields("hospitalname", "t3.enterprisename");
|
|
|
+ querySQL.setSiteid(siteid);
|
|
|
+ querySQL.setUniqueid(sa_salestargetbillid);
|
|
|
+ Rows rows = querySQL.query();
|
|
|
+
|
|
|
+ for (Row row : rows) {
|
|
|
+ row.putIfAbsent("targetnum", 0);
|
|
|
+ row.putIfAbsent("rejectdate", "");
|
|
|
+ row.putIfAbsent("checkdate", "");
|
|
|
+ row.putIfAbsent("submitdate", "");
|
|
|
+ }
|
|
|
+
|
|
|
+ return getSucReturnObject().setData(rows).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "列表", apiversion = R.ID2025122414030002.v1.class)
|
|
|
+ public String list() throws YosException {
|
|
|
+
|
|
|
+ StringBuffer where = new StringBuffer(" 1=1 ");
|
|
|
+ if (content.containsKey("where")) {
|
|
|
+ JSONObject whereObject = content.getJSONObject("where");
|
|
|
+ if (whereObject.containsKey("startdate") && !"".equals(whereObject.getString("startdate"))) {
|
|
|
+ where.append(" and(");
|
|
|
+ where.append("t1.createdate >='").append(whereObject.getString("startdate")).append(" 00:00:00' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+ if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) {
|
|
|
+ where.append(" and(");
|
|
|
+ where.append("t1.createdate <='").append(whereObject.getString("enddate")).append(" 23:59:59' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+ if (whereObject.containsKey("startdate2") && !"".equals(whereObject.getString("startdate2"))) {
|
|
|
+ where.append(" and(");
|
|
|
+ where.append("t1.checkdate >='").append(whereObject.getString("startdate2")).append(" 00:00:00' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+ if (whereObject.containsKey("enddate2") && !"".equals(whereObject.getString("enddate2"))) {
|
|
|
+ where.append(" and(");
|
|
|
+ where.append("t1.checkdate <='").append(whereObject.getString("enddate2")).append(" 23:59:59' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+ //年度
|
|
|
+ if (whereObject.containsKey("year") && !"".equals(whereObject.getString("year"))) {
|
|
|
+ where.append(" and(");
|
|
|
+ where.append("t1.year ='").append(whereObject.getString("year")).append("' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+ //状态
|
|
|
+ if (whereObject.containsKey("status") && !"".equals(whereObject.getString("status"))) {
|
|
|
+ where.append(" and(");
|
|
|
+ where.append("t1.status ='").append(whereObject.getString("status")).append("' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+ //营销区域
|
|
|
+ if (whereObject.containsKey("sa_saleareaid") && !"".equals(whereObject.getString("sa_saleareaid"))) {
|
|
|
+ Long sa_saleareaid = whereObject.getLong("sa_saleareaid");
|
|
|
+ ArrayList<Long> sa_saleareaids = SaleArea.getSubSaleAreaIds(this, sa_saleareaid);
|
|
|
+ sa_saleareaids.add(sa_saleareaid);
|
|
|
+ Rows rows = dbConnect.runSqlQuery("SELECT DISTINCT t2.userid from sa_salearea_hr t1 " +
|
|
|
+ "inner join sys_hr t2 ON t2.hrid=t1.hrid and t2.siteid=t1.siteid " +
|
|
|
+ "WHERE t1.siteid='" + siteid + "' and t1.sa_saleareaid in(" + StringUtils.join(sa_saleareaids, ",") + ") and t2.userid>0");
|
|
|
+ HashSet<Long> userIds = new HashSet<>(rows.toArrayList("userid", new ArrayList<>()));
|
|
|
+ userIds.add(-1L);
|
|
|
+ where.append(" and(");
|
|
|
+ where.append(" t1.createuserid in ").append(userIds.toString().replace("[", "(").replace("]", ")"));
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_salestargetbill", "*").setTableAlias("t1");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.inner, "sa_customers", "t2", "t1.sa_customersid=t2.sa_customersid");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise", "t3", "t3.sys_enterpriseid=t2.sys_enterpriseid and t3.siteid=t2.siteid");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "sa_salearea", "t4", "t4.sa_saleareaid=t2.sa_saleareaid and t4.siteid=t2.siteid",
|
|
|
+ "areaname", "sa_saleareaid");
|
|
|
+ querySQL.addQueryFields("hospitalname", "t3.enterprisename");
|
|
|
+ querySQL.setSiteid(siteid);
|
|
|
+ querySQL.setWhere(where);
|
|
|
+
|
|
|
+ querySQL.setCondition("t1.year", "t3.enterprisename");
|
|
|
+ if (pageSorting.equals("''")) {
|
|
|
+ pageSorting = "CASE WHEN t1.STATUS='提交' THEN 1 WHEN t1.STATUS='新建' THEN 2 ELSE 3 END,t1.submitdate DESC,t1.createdate DESC";
|
|
|
+ }
|
|
|
+ querySQL.setPage(pageSize, pageNumber);
|
|
|
+ Rows rows = querySQL.query();
|
|
|
+
|
|
|
+ for (Row row : rows) {
|
|
|
+ row.putIfAbsent("targetnum", 0);
|
|
|
+ row.putIfAbsent("rejectdate", "");
|
|
|
+ row.putIfAbsent("checkdate", "");
|
|
|
+ row.putIfAbsent("submitdate", "");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return getSucReturnObject().setData(rows).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "提交", apiversion = R.ID2025122414032102.v1.class)
|
|
|
+ public String submit() throws YosException {
|
|
|
+ Long sa_salestargetbillid = content.getLongValue("sa_salestargetbillid");
|
|
|
+
|
|
|
+ Rows rows = dbConnect.runSqlQuery("SELECT * from sa_salestargetbill WHERE sa_salestargetbillid=" + sa_salestargetbillid + " and siteid='" + siteid + "'");
|
|
|
+ if (rows.isEmpty()) {
|
|
|
+ throw new YosException("数据不存在");
|
|
|
+ }
|
|
|
+ if (!rows.get(0).getString("status").equals("新建")) {
|
|
|
+ throw new YosException("数据已提交");
|
|
|
+ }
|
|
|
+
|
|
|
+ UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sa_salestargetbill");
|
|
|
+ updateSQL.setSiteid(siteid);
|
|
|
+ updateSQL.setUniqueid(sa_salestargetbillid);
|
|
|
+ updateSQL.setValue("status", "提交");
|
|
|
+ updateSQL.setValue("submitdate", getDateTime_Str());
|
|
|
+ updateSQL.setValue("submitby", username);
|
|
|
+ updateSQL.update();
|
|
|
+
|
|
|
+ DataContrlLog.createLog(this, "sa_salestargetbill", sa_salestargetbillid, "提交", "提交成功");
|
|
|
+
|
|
|
+ return getSucReturnObject().toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "删除", apiversion = R.ID2025122414034502.v1.class)
|
|
|
+ public String delete() throws YosException {
|
|
|
+ Long sa_salestargetbillid = content.getLongValue("sa_salestargetbillid");
|
|
|
+
|
|
|
+ Rows rows = dbConnect.runSqlQuery("SELECT * from sa_salestargetbill WHERE sa_salestargetbillid=" + sa_salestargetbillid + " and siteid='" + siteid + "'");
|
|
|
+ if (rows.isEmpty()) {
|
|
|
+ throw new YosException("数据不存在");
|
|
|
+ }
|
|
|
+ if (!rows.get(0).getString("status").equals("新建")) {
|
|
|
+ throw new YosException("数据非新建状态不可删除");
|
|
|
+ }
|
|
|
+
|
|
|
+ DeleteSQL updateSQL = SQLFactory.createDeleteSQL(this, "sa_salestargetbill");
|
|
|
+ updateSQL.setSiteid(siteid);
|
|
|
+ updateSQL.setUniqueid(sa_salestargetbillid);
|
|
|
+ updateSQL.delete();
|
|
|
+
|
|
|
+ DataContrlLog.createLog(this, "sa_salestargetbill", sa_salestargetbillid, "删除", "删除成功");
|
|
|
+
|
|
|
+ return getSucReturnObject().toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "审核", apiversion = R.ID2025122414035302.v1.class)
|
|
|
+ public String check() throws YosException {
|
|
|
+
|
|
|
+ JSONArray sa_salestargetbillids = content.getJSONArray("sa_salestargetbillids");
|
|
|
+
|
|
|
+ for (Object sa_salestargetbillid : sa_salestargetbillids) {
|
|
|
+ Rows rows = dbConnect.runSqlQuery("SELECT * from sa_salestargetbill WHERE sa_salestargetbillid=" + sa_salestargetbillid + " and siteid='" + siteid + "'");
|
|
|
+ if (rows.isEmpty()) {
|
|
|
+ throw new YosException("数据不存在");
|
|
|
+ }
|
|
|
+ if (!rows.get(0).getString("status").equals("提交")) {
|
|
|
+ throw new YosException("存在非提交状态的数据");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sa_salestargetbill");
|
|
|
+ updateSQL.setSiteid(siteid);
|
|
|
+ updateSQL.setWhere("sa_salestargetbillid", sa_salestargetbillids);
|
|
|
+ updateSQL.setValue("status", "审核");
|
|
|
+ updateSQL.setValue("checkdate", getDateTime_Str());
|
|
|
+ updateSQL.setValue("checkby", username);
|
|
|
+ updateSQL.update();
|
|
|
+ for (Object sa_salestargetbillid : sa_salestargetbillids) {
|
|
|
+ DataContrlLog.createLog(this, "sa_salestargetbill", Long.parseLong(sa_salestargetbillid.toString()), "审核", "审核成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ return getSucReturnObject().toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "反审核", apiversion = R.ID2025122415333402.v1.class)
|
|
|
+ public String uncheck() throws YosException {
|
|
|
+ JSONArray sa_salestargetbillids = content.getJSONArray("sa_salestargetbillids");
|
|
|
+
|
|
|
+ for (Object sa_salestargetbillid : sa_salestargetbillids) {
|
|
|
+ Rows rows = dbConnect.runSqlQuery("SELECT * from sa_salestargetbill WHERE sa_salestargetbillid=" + sa_salestargetbillid + " and siteid='" + siteid + "'");
|
|
|
+ if (rows.isEmpty()) {
|
|
|
+ throw new YosException("数据不存在");
|
|
|
+ }
|
|
|
+ if (!rows.get(0).getString("status").equals("审核")) {
|
|
|
+ throw new YosException("存在非审核状态的数据");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sa_salestargetbill");
|
|
|
+ updateSQL.setSiteid(siteid);
|
|
|
+ updateSQL.setWhere("sa_salestargetbillid", sa_salestargetbillids);
|
|
|
+ updateSQL.setValue("status", "新建");
|
|
|
+ updateSQL.setValue("checkdate", "null");
|
|
|
+ updateSQL.setValue("checkby", "null");
|
|
|
+ updateSQL.setValue("submitdate", "null");
|
|
|
+ updateSQL.setValue("submitby", "null");
|
|
|
+ updateSQL.update();
|
|
|
+ for (Object sa_salestargetbillid : sa_salestargetbillids) {
|
|
|
+ DataContrlLog.createLog(this, "sa_salestargetbill", Long.parseLong(sa_salestargetbillid.toString()), "反审核", "反审核成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ return getSucReturnObject().toString();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @API(title = "驳回", apiversion = R.ID2025122414040102.v1.class)
|
|
|
+ public String reject() throws YosException {
|
|
|
+ JSONArray sa_salestargetbillids = content.getJSONArray("sa_salestargetbillids");
|
|
|
+
|
|
|
+ for (Object sa_salestargetbillid : sa_salestargetbillids) {
|
|
|
+ Rows rows = dbConnect.runSqlQuery("SELECT * from sa_salestargetbill WHERE sa_salestargetbillid=" + sa_salestargetbillid + " and siteid='" + siteid + "'");
|
|
|
+ if (rows.isEmpty()) {
|
|
|
+ throw new YosException("目标编制不存在");
|
|
|
+ }
|
|
|
+ if (!rows.get(0).getString("status").equals("提交")) {
|
|
|
+ throw new YosException("存在目标编制非提交状态的数据");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sa_salestargetbill");
|
|
|
+ updateSQL.setSiteid(siteid);
|
|
|
+ updateSQL.setWhere("sa_salestargetbillid", sa_salestargetbillids);
|
|
|
+ updateSQL.setValue("status", "新建");
|
|
|
+ updateSQL.setValue("submitdate", "null");
|
|
|
+ updateSQL.setValue("submitby", "null");
|
|
|
+ updateSQL.setValue("reject", content.getStringValue("reject"));
|
|
|
+ updateSQL.setValue("rejectdate", getDateTime_Str());
|
|
|
+ updateSQL.setValue("rejectby", username);
|
|
|
+ updateSQL.update();
|
|
|
+ for (Object sa_salestargetbillid : sa_salestargetbillids) {
|
|
|
+ DataContrlLog.createLog(this, "sa_salestargetbill", Long.parseLong(sa_salestargetbillid.toString()), "驳回", "驳回成功:" + content.getStringValue("reject"));
|
|
|
+ }
|
|
|
+ return getSucReturnObject().toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "设置下一年度是否开启", apiversion = R.ID2025122416320802.v1.class)
|
|
|
+ public String setNextyear() throws YosException {
|
|
|
+
|
|
|
+ boolean isnextyear = content.getBooleanValue("isnextyear");
|
|
|
+ UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sys_site_parameter");
|
|
|
+ updateSQL.setSiteid(siteid);
|
|
|
+ updateSQL.setValue("isnextyear", isnextyear);
|
|
|
+ updateSQL.update();
|
|
|
+ return queryNextYear();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "查询下一年度信息", apiversion = R.ID2025122416321402.v1.class)
|
|
|
+ public String queryNextYear() throws YosException {
|
|
|
+ Rows rows = dbConnect.runSqlQuery("SELECT isnextyear from sys_site_parameter WHERE siteid='" + siteid + "'");
|
|
|
+
|
|
|
+ return getSucReturnObject().setData(rows.get(0)).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "查询年份", apiversion = R.ID2025122416395602.v1.class)
|
|
|
+ public String queryYears() throws YosException {
|
|
|
+
|
|
|
+ Rows rows = dbConnect.runSqlQuery("SELECT DISTINCT year from sa_salestargetbill WHERE siteid='" + siteid + "' order by year desc");
|
|
|
+
|
|
|
+ ArrayList<Long> years = rows.toArrayList("year",new ArrayList<>());
|
|
|
+
|
|
|
+ return getSucReturnObject().setData(years).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|