orderclue.java 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. package restcontroller.webmanage.saletool.orderclue;
  2. import com.alibaba.fastjson2.JSONArray;
  3. import com.alibaba.fastjson2.JSONObject;
  4. import common.Controller;
  5. import common.YosException;
  6. import common.annotation.API;
  7. import common.data.*;
  8. import org.apache.commons.lang.StringUtils;
  9. import org.apache.poi.xssf.usermodel.*;
  10. import restcontroller.R;
  11. import java.util.ArrayList;
  12. import java.util.HashMap;
  13. /**
  14. * 销售线索
  15. */
  16. public class orderclue extends Controller {
  17. public orderclue(JSONObject content) throws YosException {
  18. super(content);
  19. }
  20. /**
  21. * 下载线索导入单模板
  22. *
  23. * @return
  24. */
  25. @API(title = "销售线索-下载线索导入单模板", apiversion = R.ID2026020914501501.v1.class)
  26. public String downloadOrderclueuploadbillExcel() throws YosException {
  27. ExcelFactory excelFactory = new ExcelFactory("ImportTemplateForOrderclue");
  28. XSSFSheet sheet = excelFactory.getXssfWorkbook().createSheet("Sheet1");
  29. XSSFWorkbook xssfFWorkbook = excelFactory.getXssfWorkbook();
  30. ExportExcel.setBatchDetailSheetColumn1(sheet);// 设置工作薄列宽
  31. XSSFCellStyle titleCellStyle1 = ExportExcel.createTitleCellStyle1(xssfFWorkbook);
  32. XSSFCellStyle titleCellStyle2 = ExportExcel.createTitleCellStyle2(xssfFWorkbook);
  33. XSSFCellStyle titleCellStyle3 = ExportExcel.createBodyCellStyle(xssfFWorkbook);
  34. ExportExcel.batchDetail(sheet, titleCellStyle1, titleCellStyle2, titleCellStyle3, xssfFWorkbook);// 写入标题
  35. Rows aa = saveToExcelAttachment(excelFactory);
  36. String url = "";
  37. if (!aa.isEmpty()) {
  38. url = aa.get(0).getString("url");
  39. }
  40. return getSucReturnObject().setData(url).toString();
  41. }
  42. /**
  43. * 下载线索导入单模板
  44. *
  45. * @return
  46. */
  47. @API(title = "销售线索-下载线索导入单模板", apiversion = R.ID2026020914503001.v1.class)
  48. public String downloadOrderclueuploadbillExcelByPlatform() throws YosException {
  49. ExcelFactory excelFactory = new ExcelFactory("ImportTemplateForOrderclue");
  50. XSSFSheet sheet = excelFactory.getXssfWorkbook().createSheet("Sheet1");
  51. XSSFWorkbook xssfFWorkbook = excelFactory.getXssfWorkbook();
  52. ExportExcel.setBatchDetailSheetColumn1(sheet);// 设置工作薄列宽
  53. XSSFCellStyle titleCellStyle1 = ExportExcel.createTitleCellStyle1(xssfFWorkbook);
  54. XSSFCellStyle titleCellStyle2 = ExportExcel.createTitleCellStyle2(xssfFWorkbook);
  55. XSSFCellStyle titleCellStyle3 = ExportExcel.createBodyCellStyle(xssfFWorkbook);
  56. ExportExcel.batchDetailByPlatform(sheet, titleCellStyle1, titleCellStyle2, titleCellStyle3, xssfFWorkbook);// 写入标题
  57. Rows aa = saveToExcelAttachment(excelFactory);
  58. String url = "";
  59. if (!aa.isEmpty()) {
  60. url = aa.get(0).getString("url");
  61. }
  62. return getSucReturnObject().setData(url).toString();
  63. }
  64. /**
  65. * 更新线索导入单
  66. *
  67. * @return
  68. */
  69. @API(title = "销售线索-导入线索导入单", apiversion = R.ID2026020914505001.v1.class)
  70. public String uploadOrderclueuploadbillByExcel() throws YosException {
  71. long sat_orderclueuploadbillid = createTableID("sat_orderclueuploadbill");
  72. InsertSQL insertorderclueuploadbill = SQLFactory.createInsertSQL(this, "sat_orderclueuploadbill");
  73. insertorderclueuploadbill.setValue("status", "待审核");
  74. insertorderclueuploadbill.setValue("uploadbillnum", createBillCode("default"));
  75. insertorderclueuploadbill.setValue("cluetype", content.getString("cluetype"));
  76. insertorderclueuploadbill.setUniqueid(sat_orderclueuploadbillid);
  77. insertorderclueuploadbill.insert();
  78. this.createFileLink("sat_orderclueuploadbill", sat_orderclueuploadbillid, "default", content.getLong("attachmentid"));
  79. ExcelFactory e;
  80. try {
  81. e = getExcelAttachment(content.getLong("attachmentid"));
  82. ArrayList<String> keys = new ArrayList<>();
  83. SQLDump sqlDump = new SQLDump();
  84. keys.add("name");
  85. keys.add("phonenumber");
  86. keys.add("province");
  87. keys.add("city");
  88. keys.add("county");
  89. keys.add("address");
  90. keys.add("cluesource");
  91. keys.add("notes");
  92. Rows rows = e.getSheetRows(0, keys, 2);
  93. int i = 0;
  94. boolean iserr = false;
  95. Rows rowserr = new Rows();
  96. Rows rowssuc = new Rows();
  97. for (Row row : rows) {
  98. if (StringUtils.isEmpty(row.getString("phonenumber")) || StringUtils.isEmpty(row.getString("province")) || StringUtils.isEmpty(row.getString("city")) || StringUtils.isEmpty(row.getString("county")) || StringUtils.isEmpty(row.getString("cluesource"))) {
  99. iserr = true;
  100. row.put("msg", "错误信息:手机号,省市县及来源不能为空");
  101. rowserr.add(row);
  102. } else {
  103. rowssuc.add(row);
  104. }
  105. }
  106. if (!rowssuc.isEmpty()) {
  107. for (Row row : rowssuc) {
  108. long[] sat_orderclueuploadbillmxid = createTableID("sat_orderclueuploadbillmx", rowssuc.size());
  109. InsertSQL orderclueuploadbillmxInsert = SQLFactory.createInsertSQL(this, "sat_orderclueuploadbillmx");
  110. orderclueuploadbillmxInsert.setValue("sat_orderclueuploadbillmxid", sat_orderclueuploadbillmxid[i]);
  111. orderclueuploadbillmxInsert.setValue("sat_orderclueuploadbillid", sat_orderclueuploadbillid);
  112. orderclueuploadbillmxInsert.setValue("name", row.getString("name"));
  113. orderclueuploadbillmxInsert.setValue("province", row.getString("province"));
  114. orderclueuploadbillmxInsert.setValue("city", row.getString("city"));
  115. orderclueuploadbillmxInsert.setValue("county", row.getString("county"));
  116. orderclueuploadbillmxInsert.setValue("address", row.getString("address"));
  117. orderclueuploadbillmxInsert.setValue("phonenumber", row.getString("phonenumber"));
  118. orderclueuploadbillmxInsert.setValue("notes", row.getString("notes"));
  119. orderclueuploadbillmxInsert.setValue("cluesource", row.getString("cluesource"));
  120. orderclueuploadbillmxInsert.setValue("sat_orderclueid", 0);
  121. sqlDump.add(orderclueuploadbillmxInsert);
  122. i++;
  123. }
  124. }
  125. if (!sqlDump.isEmpty()) {
  126. sqlDump.commit();
  127. } else {
  128. dbConnect.runSqlUpdate("delete from sat_orderclueuploadbill where sat_orderclueuploadbillid=" + sat_orderclueuploadbillid);
  129. }
  130. if (iserr) {
  131. ExcelFactory excelFactory = new ExcelFactory("sat_orderclueuploadbillerr");
  132. HashMap<String, String> map = new HashMap<String, String>();
  133. map.put("name", "客户姓名");
  134. map.put("phonenumber", "手机号");
  135. map.put("province", "省");
  136. map.put("city", "市");
  137. map.put("county", "县");
  138. map.put("address", "地址");
  139. map.put("cluesource", "来源");
  140. map.put("notes", "备注");
  141. map.put("msg", "错误信息");
  142. ArrayList<String> colNameList = new ArrayList<String>();
  143. HashMap<String, Class> keytypemap = new HashMap<>();
  144. colNameList.add("name");
  145. colNameList.add("phonenumber");
  146. colNameList.add("province");
  147. colNameList.add("city");
  148. colNameList.add("county");
  149. colNameList.add("address");
  150. colNameList.add("cluesource");
  151. colNameList.add("notes");
  152. colNameList.add("msg");
  153. rowserr.setFieldList(colNameList);
  154. keytypemap.put("name", String.class);
  155. keytypemap.put("phonenumber", String.class);
  156. keytypemap.put("province", String.class);
  157. keytypemap.put("city", String.class);
  158. keytypemap.put("county", String.class);
  159. keytypemap.put("address", String.class);
  160. keytypemap.put("cluesource", String.class);
  161. keytypemap.put("notes", String.class);
  162. keytypemap.put("msg", String.class);
  163. rowserr.setFieldTypeMap(keytypemap);
  164. addSheet(excelFactory, "Sheet1", rowserr, map);
  165. Rows aa = saveToExcelAttachment(excelFactory);
  166. String url = "";
  167. if (!aa.isEmpty()) {
  168. url = aa.get(0).getString("url");
  169. }
  170. return getSucReturnObject().setData(url).toString();
  171. }
  172. } catch (Exception e1) {
  173. // TODO Auto-generated catch block
  174. dbConnect.runSqlUpdate("delete from sat_orderclueuploadbill where sat_orderclueuploadbillid=" + sat_orderclueuploadbillid);
  175. e1.printStackTrace();
  176. return getErrReturnObject().setErrMsg(e1.getMessage()).toString();
  177. }
  178. return getSucReturnObject().toString();
  179. }
  180. /**
  181. * 更新线索导入单
  182. *
  183. * @return
  184. */
  185. @API(title = "销售线索-通过平台(抖音,快手)导入线索导入单", apiversion = R.ID2026020914511101.v1.class)
  186. public String uploadOrderclueuploadbillByExcelAndPlatform() throws YosException {
  187. long sat_orderclueuploadbillid = createTableID("sat_orderclueuploadbill");
  188. String billcode = createBillCode("default");
  189. InsertSQL insertorderclueuploadbill = SQLFactory.createInsertSQL(this, "sat_orderclueuploadbill");
  190. insertorderclueuploadbill.setValue("status", "待审核");
  191. insertorderclueuploadbill.setValue("uploadbillnum", billcode);
  192. insertorderclueuploadbill.setValue("cluetype", content.getString("cluetype"));
  193. insertorderclueuploadbill.setUniqueid(sat_orderclueuploadbillid);
  194. insertorderclueuploadbill.insert();
  195. this.createFileLink("sat_orderclueuploadbill", sat_orderclueuploadbillid, "default", content.getLong("attachmentid"));
  196. ExcelFactory e;
  197. try {
  198. // 华为云
  199. e = getPostExcel();
  200. ArrayList<String> keys = new ArrayList<>();
  201. SQLDump sqlDump = new SQLDump();
  202. keys.add("name");
  203. keys.add("phonenumber");
  204. keys.add("addressinfo");
  205. keys.add("address");
  206. keys.add("cluesource");
  207. keys.add("notes");
  208. Rows rows = e.getSheetRows(0, keys, 2);
  209. int i = 0;
  210. boolean iserr = false;
  211. Rows rowserr = new Rows();
  212. Rows rowssuc = new Rows();
  213. String regex = "1[3-9][0-9]\\d{8}"; // 手机号码的格式:第一位只能为1,第二位可以是3,4,5,7,8,第三位到第十一位可以为0-9中任意一个数字
  214. for (Row row : rows) {
  215. JSONArray addressinfos = new JSONArray();
  216. String[] addressarray = {};
  217. if (!StringUtils.isBlank(row.getString("addressinfo"))) {
  218. if (row.getString("addressinfo").startsWith("[")) {
  219. addressinfos = JSONArray.parseArray(row.getString("addressinfo"));
  220. } else if (row.getString("addressinfo").contains("-")) {
  221. addressarray = row.getString("addressinfo").split("-");
  222. }
  223. }
  224. if (StringUtils.isBlank(row.getString("phonenumber")) || StringUtils.isBlank(row.getString("addressinfo")) || StringUtils.isBlank(row.getString("cluesource"))) {
  225. iserr = true;
  226. row.put("msg", "错误信息:手机号,省市县信息及来源不能为空");
  227. rowserr.add(row);
  228. } else {
  229. if (!row.getString("phonenumber").matches(regex)) {
  230. iserr = true;
  231. row.put("msg", "错误信息:手机号格式不正确");
  232. rowserr.add(row);
  233. } else if (addressinfos.size() < 2 && addressarray.length < 2) {
  234. iserr = true;
  235. row.put("msg", "错误信息:省市县信息中缺少省市");
  236. rowserr.add(row);
  237. } else {
  238. rowssuc.add(row);
  239. }
  240. }
  241. }
  242. if (!rowssuc.isEmpty()) {
  243. for (Row row : rowssuc) {
  244. long[] sat_orderclueuploadbillmxid = createTableID("sat_orderclueuploadbillmx", rowssuc.size());
  245. InsertSQL orderclueuploadbillmxInsert = SQLFactory.createInsertSQL(this, "sat_orderclueuploadbillmx");
  246. orderclueuploadbillmxInsert.setValue("sat_orderclueuploadbillmxid", sat_orderclueuploadbillmxid[i]);
  247. orderclueuploadbillmxInsert.setValue("sat_orderclueuploadbillid", sat_orderclueuploadbillid);
  248. orderclueuploadbillmxInsert.setValue("name", row.getString("name"));
  249. orderclueuploadbillmxInsert.setValue("province", row.getString("province"));
  250. orderclueuploadbillmxInsert.setValue("city", row.getString("city"));
  251. orderclueuploadbillmxInsert.setValue("county", row.getString("county"));
  252. orderclueuploadbillmxInsert.setValue("address", row.getString("address"));
  253. orderclueuploadbillmxInsert.setValue("phonenumber", row.getString("phonenumber"));
  254. orderclueuploadbillmxInsert.setValue("notes", row.getString("notes"));
  255. orderclueuploadbillmxInsert.setValue("cluesource", row.getString("cluesource"));
  256. orderclueuploadbillmxInsert.setValue("sat_orderclueid", 0);
  257. if (row.getString("addressinfo").startsWith("[")) {
  258. JSONArray addressinfos = JSONArray.parseArray(row.getString("addressinfo"));
  259. if (addressinfos.size() == 3) {
  260. orderclueuploadbillmxInsert.setValue("province", addressinfos.get(0));
  261. orderclueuploadbillmxInsert.setValue("city", addressinfos.get(1));
  262. orderclueuploadbillmxInsert.setValue("county", addressinfos.get(2));
  263. } else if (addressinfos.size() == 2) {
  264. orderclueuploadbillmxInsert.setValue("province", addressinfos.get(0));
  265. orderclueuploadbillmxInsert.setValue("city", addressinfos.get(1));
  266. orderclueuploadbillmxInsert.setValue("county", "");
  267. } else {
  268. orderclueuploadbillmxInsert.setValue("province", "");
  269. orderclueuploadbillmxInsert.setValue("city", "");
  270. orderclueuploadbillmxInsert.setValue("county", "");
  271. }
  272. } else if (row.getString("addressinfo").contains("-")) {
  273. String[] addressarray = row.getString("addressinfo").split("-");
  274. if (addressarray.length == 3) {
  275. orderclueuploadbillmxInsert.setValue("province", addressarray[0]);
  276. orderclueuploadbillmxInsert.setValue("city", addressarray[1]);
  277. orderclueuploadbillmxInsert.setValue("county", addressarray[2]);
  278. } else if (addressarray.length == 2) {
  279. orderclueuploadbillmxInsert.setValue("province", addressarray[0]);
  280. orderclueuploadbillmxInsert.setValue("city", addressarray[1]);
  281. orderclueuploadbillmxInsert.setValue("county", "");
  282. } else {
  283. orderclueuploadbillmxInsert.setValue("province", "");
  284. orderclueuploadbillmxInsert.setValue("city", "");
  285. orderclueuploadbillmxInsert.setValue("county", "");
  286. }
  287. }
  288. sqlDump.add(orderclueuploadbillmxInsert);
  289. i++;
  290. }
  291. }
  292. if (!sqlDump.isEmpty()) {
  293. sqlDump.commit();
  294. } else {
  295. dbConnect.runSqlUpdate("delete from sat_orderclueuploadbill where sat_orderclueuploadbillid=" + sat_orderclueuploadbillid);
  296. }
  297. if (iserr) {
  298. ExcelFactory excelFactory = new ExcelFactory("sat_orderclueuploadbillerr");
  299. HashMap<String, String> map = new HashMap<String, String>();
  300. map.put("name", "客户姓名");
  301. map.put("phonenumber", "手机号");
  302. map.put("province", "省市县信息");
  303. map.put("address", "地址");
  304. map.put("cluesource", "来源");
  305. map.put("notes", "备注");
  306. map.put("msg", "错误信息");
  307. ArrayList<String> colNameList = new ArrayList<String>();
  308. HashMap<String, Class> keytypemap = new HashMap<String, Class>();
  309. colNameList.add("name");
  310. colNameList.add("phonenumber");
  311. colNameList.add("addressinfo");
  312. colNameList.add("address");
  313. colNameList.add("cluesource");
  314. colNameList.add("notes");
  315. colNameList.add("msg");
  316. keytypemap.put("name", String.class);
  317. keytypemap.put("phonenumber", String.class);
  318. keytypemap.put("addressinfo", String.class);
  319. keytypemap.put("address", String.class);
  320. keytypemap.put("cluesource", String.class);
  321. keytypemap.put("notes", String.class);
  322. keytypemap.put("msg", String.class);
  323. rowserr.setFieldList(colNameList);
  324. rowserr.setFieldTypeMap(keytypemap);
  325. addSheet1(excelFactory, "Sheet1", rowserr, map);
  326. Rows aa = saveToExcelAttachment(excelFactory);
  327. String url = "";
  328. if (!aa.isEmpty()) {
  329. url = aa.get(0).getString("url");
  330. }
  331. return getSucReturnObject().setData(url).toString();
  332. }
  333. } catch (Exception e1) {
  334. dbConnect.runSqlUpdate("delete from sat_orderclueuploadbill where sat_orderclueuploadbillid=" + sat_orderclueuploadbillid);
  335. e1.printStackTrace();
  336. return getErrReturnObject().setErrMsg(e1.getMessage()).toString();
  337. }
  338. return getSucReturnObject().toString();
  339. }
  340. /**
  341. * 更新线索导入单
  342. *
  343. * @return
  344. */
  345. @API(title = "销售线索-更新线索-导入单", apiversion = R.ID2026020914513301.v1.class)
  346. public String updateOrderclueuploadbill() throws YosException {
  347. Long sat_orderclueuploadbillid = content.getLong("sat_orderclueuploadbillid");
  348. String notes = content.getString("notes");
  349. Rows rows = dbConnect.runSqlQuery("select sat_orderclueuploadbillid FROM sat_orderclueuploadbill WHERE siteid = '" + siteid + "' AND sat_orderclueuploadbillid = '" + sat_orderclueuploadbillid + "'");
  350. if (rows.isEmpty()) {
  351. return getErrReturnObject().setErrMsg("线索导入单不存在,无法更新").toString();
  352. }
  353. SQLFactory.createUpdateSQL(this, "sat_orderclueuploadbill").setValue("notes", notes).setUniqueid(sat_orderclueuploadbillid).update();
  354. return queryOrderclueuploadbillMain();
  355. }
  356. @API(title = "销售线索-导入列表查询", apiversion = R.ID20221101094702.v1.class)
  357. public String queryOrderclueuploadbillList() throws YosException {
  358. QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sat_orderclueuploadbill", getTableColumnNames("sat_orderclueuploadbill").toArray(new String[0])).setTableAlias("t1");
  359. querySQL.addJoinTable(JOINTYPE.left, "sat_orderclueuploadbillmx", "t2", "t1.sat_orderclueuploadbillid=t2.sat_orderclueuploadbillid");
  360. querySQL.addQueryFields("orderclueuploadcount", "count(t2.sat_orderclueuploadbillid)");
  361. querySQL.addGroupBy();
  362. querySQL.setWhere("siteid", siteid);
  363. Rows rows;
  364. if (rowindex > 0) {
  365. rows = querySQL.query(rowindex);
  366. long sat_orderclueuploadbillid = rows.get(0).getLong("sat_orderclueuploadbillid");
  367. content.put("sat_orderclueuploadbillid", sat_orderclueuploadbillid);
  368. return queryOrderclueuploadbillMain();
  369. } else {
  370. querySQL.setPage(pageSize, pageNumber);
  371. rows = querySQL.query();
  372. return getSucReturnObject().setData(rows).toString();
  373. }
  374. }
  375. @API(title = "销售线索-导入详情", apiversion = R.ID2026020914515801.v1.class)
  376. public String queryOrderclueuploadbillMain() throws YosException {
  377. Long sat_orderclueuploadbillid = content.getLong("sat_orderclueuploadbillid");
  378. QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sat_orderclueuploadbill");
  379. querySQL.setUniqueid(sat_orderclueuploadbillid);
  380. Rows rows = querySQL.query();
  381. for (Row row : rows) {
  382. Rows orderclueuploadbillmxRows = dbConnect.runSqlQuery("select sat_orderclueid from sat_orderclueuploadbillmx where sat_orderclueuploadbillid=" + sat_orderclueuploadbillid);
  383. row.put("xiansuocount", orderclueuploadbillmxRows.size());
  384. row.put("isdistribution", orderclueuploadbillmxRows.toArrayList("sat_orderclueid", new ArrayList<Long>()).stream().filter(num -> num > 0).toList().isEmpty() ? "否" : "是");
  385. }
  386. return getSucReturnObject().setData(!rows.isEmpty() ? rows.get(0) : new Row()).toString();
  387. }
  388. @API(title = "销售线索-导入详情明细", apiversion = R.ID20221102100102.v1.class)
  389. public String queryOrderclueuploadbillMxMain() throws YosException {
  390. Long sat_orderclueuploadbillid = content.getLong("sat_orderclueuploadbillid");
  391. QuerySQL orderclueuploadbillmxQuery = SQLFactory.createQuerySQL(this, "sat_orderclueuploadbillmx", "*").setTableAlias("t1");
  392. orderclueuploadbillmxQuery.addJoinTable(JOINTYPE.inner, "sat_orderclueuploadbill", "t2", "t1.sat_orderclueuploadbillid=t2.sat_orderclueuploadbillid", "cluetype");
  393. orderclueuploadbillmxQuery.setWhere("t1.sat_orderclueuploadbillid", sat_orderclueuploadbillid);
  394. orderclueuploadbillmxQuery.setPage(pageSize, pageNumber);
  395. Rows rowsdetaill = orderclueuploadbillmxQuery.query();
  396. return getSucReturnObject().setData(rowsdetaill).toString();
  397. }
  398. @API(title = "销售线索-导入删除", apiversion = R.ID20221101100702.v1.class)
  399. public String delete() throws YosException {
  400. Long sat_orderclueuploadbillid = content.getLong("sat_orderclueuploadbillid");
  401. Rows rowscount = dbConnect.runSqlQuery("select status from sat_orderclueuploadbill where sat_orderclueuploadbillid=" + sat_orderclueuploadbillid);
  402. if (rowscount.isEmpty()) {
  403. return getErrReturnObject().setErrMsg("此销售线索导入单不存在,无法删除销售线索导入单").toString();
  404. }
  405. if (!rowscount.get(0).getString("status").equals("待审核")) {
  406. return getErrReturnObject().setErrMsg("已审核状态的销售线索导入单无法删除销售线索导入单").toString();
  407. }
  408. SQLDump sqlDump = new SQLDump();
  409. sqlDump.add(SQLFactory.createDeleteSQL(this, "sat_orderclueuploadbill").setUniqueid(sat_orderclueuploadbillid));
  410. sqlDump.add(SQLFactory.createDeleteSQL(this, "sat_orderclueuploadbillmx").setWhere("sat_orderclueuploadbillid", sat_orderclueuploadbillid));
  411. sqlDump.commit(this);
  412. return getSucReturnObject().toString();
  413. }
  414. /**
  415. * 线索导入单审核
  416. *
  417. * @return
  418. */
  419. @API(title = "销售线索-审核反审核", apiversion = R.ID2026020914522001.v1.class)
  420. public String check() throws YosException {
  421. Long sat_orderclueuploadbillid = content.getLong("sat_orderclueuploadbillid");
  422. SQLDump sqlDump = new SQLDump();
  423. boolean ischeck = content.getBoolean("ischeck");
  424. Rows rowsstatus = dbConnect.runSqlQuery("select status from sat_orderclueuploadbill where sat_orderclueuploadbillid=" + sat_orderclueuploadbillid);
  425. if (rowsstatus.isEmpty()) {
  426. return getErrReturnObject().setErrMsg("此销售线索导入单不存在,无法审核").toString();
  427. }
  428. if (ischeck && !rowsstatus.get(0).getString("status").equals("待审核")) {
  429. return getErrReturnObject().setErrMsg("已审核的销售线索导入单无法再次审核").toString();
  430. }
  431. if (!ischeck && !rowsstatus.get(0).getString("status").equals("已审核")) {
  432. return getErrReturnObject().setErrMsg("待审核的销售线索导入单无法反审核").toString();
  433. }
  434. if (!ischeck) {
  435. Rows rowscount = dbConnect.runSqlQuery("select count(1) statuscount from sat_orderclueuploadbillmx t1 inner join sat_orderclue t2 on t1.sat_orderclueid=t2.sat_orderclueid and t1.siteid=t2.siteid where t1.sat_orderclueuploadbillid=" + sat_orderclueuploadbillid + " and t2.status <>'待分配'");
  436. if (rowscount.get(0).getLong("statuscount") > 0) {
  437. return getErrReturnObject().setErrMsg("关联的销售线索池中存在非待分配的线索,无法反审核").toString();
  438. }
  439. }
  440. UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sat_orderclueuploadbill");
  441. updateSQL.setValue("status", ischeck ? "已审核" : "待审核");
  442. updateSQL.setValue("checkby", ischeck ? username : null);
  443. updateSQL.setValue("checkdate", ischeck ? getDateTime_Str() : null);
  444. updateSQL.setUniqueid(sat_orderclueuploadbillid);
  445. sqlDump.add(updateSQL);
  446. sqlDump.add(geSqlStatement(ischeck, sat_orderclueuploadbillid));
  447. sqlDump.commit(this);
  448. return getSucReturnObject().toString();
  449. }
  450. @API(title = "销售线索-导入明细新增修改", apiversion = R.ID20230221092603.v1.class)
  451. public String insertormodify_Orderclueuploadbillmx() throws YosException {
  452. long sat_orderclueuploadbillid = content.getLong("sat_orderclueuploadbillid");
  453. long sat_orderclueuploadbillmxid = content.getLong("sat_orderclueuploadbillmxid");
  454. String name = content.getString("name");
  455. String province = content.getString("province");
  456. String city = content.getString("city");
  457. String county = content.getString("county");
  458. String address = content.getString("address");
  459. String phonenumber = content.getString("phonenumber");
  460. String notes = content.getString("notes");
  461. String cluesource = content.getString("cluesource");
  462. Rows rowscount = dbConnect.runSqlQuery("select status from sat_orderclueuploadbill where sat_orderclueuploadbillid=" + sat_orderclueuploadbillid);
  463. if (rowscount.isEmpty()) {
  464. return getErrReturnObject().setErrMsg("此销售线索导入单不存在").toString();
  465. }
  466. if (!rowscount.get(0).getString("status").equals("待审核")) {
  467. return getErrReturnObject().setErrMsg("已审核状态的销售线索导入单无法新增或更新明细内容").toString();
  468. }
  469. if (sat_orderclueuploadbillmxid <= 0 || dbConnect.runSqlQuery("select sat_orderclueuploadbillmxid from sat_orderclueuploadbillmx where sat_orderclueuploadbillmxid=" + sat_orderclueuploadbillmxid).isEmpty()) {
  470. sat_orderclueuploadbillmxid = createTableID("sat_orderclueuploadbillmx");
  471. InsertSQL orderclueuploadbillmxInsert = SQLFactory.createInsertSQL(this, "sat_orderclueuploadbillmx");
  472. orderclueuploadbillmxInsert.setValue("sat_orderclueuploadbillmxid", sat_orderclueuploadbillmxid);
  473. orderclueuploadbillmxInsert.setValue("sat_orderclueuploadbillid", sat_orderclueuploadbillid);
  474. orderclueuploadbillmxInsert.setValue("name", name);
  475. orderclueuploadbillmxInsert.setValue("province", province);
  476. orderclueuploadbillmxInsert.setValue("city", city);
  477. orderclueuploadbillmxInsert.setValue("county", county);
  478. orderclueuploadbillmxInsert.setValue("address", address);
  479. orderclueuploadbillmxInsert.setValue("phonenumber", phonenumber);
  480. orderclueuploadbillmxInsert.setValue("notes", notes);
  481. orderclueuploadbillmxInsert.setValue("cluesource", cluesource);
  482. orderclueuploadbillmxInsert.setValue("sat_orderclueid", 0);
  483. orderclueuploadbillmxInsert.insert();
  484. } else {
  485. UpdateSQL orderclueuploadbillmxUpdate = SQLFactory.createUpdateSQL(this, "sat_orderclueuploadbillmx");
  486. orderclueuploadbillmxUpdate.setValue("name", name);
  487. orderclueuploadbillmxUpdate.setValue("province", province);
  488. orderclueuploadbillmxUpdate.setValue("city", city);
  489. orderclueuploadbillmxUpdate.setValue("county", county);
  490. orderclueuploadbillmxUpdate.setValue("address", address);
  491. orderclueuploadbillmxUpdate.setValue("phonenumber", phonenumber);
  492. orderclueuploadbillmxUpdate.setValue("notes", notes);
  493. orderclueuploadbillmxUpdate.setValue("cluesource", cluesource);
  494. orderclueuploadbillmxUpdate.setUniqueid(sat_orderclueuploadbillmxid);
  495. orderclueuploadbillmxUpdate.update();
  496. }
  497. return queryOrderclueuploadbillMxMain();
  498. }
  499. @API(title = "销售线索-导入明细删除", apiversion = R.ID20221101100802.v1.class)
  500. public String deletemx() throws YosException {
  501. Long sat_orderclueuploadbillmxid = content.getLong("sat_orderclueuploadbillmxid");
  502. Long sat_orderclueuploadbillid = content.getLong("sat_orderclueuploadbillid");
  503. Rows rowscount = dbConnect.runSqlQuery("select status from sat_orderclueuploadbill where sat_orderclueuploadbillid=" + sat_orderclueuploadbillid);
  504. if (rowscount.isEmpty()) {
  505. return getErrReturnObject().setErrMsg("此销售线索导入单不存在,无法删除导入明细").toString();
  506. }
  507. if (!rowscount.get(0).getString("status").equals("待审核")) {
  508. return getErrReturnObject().setErrMsg("已审核状态的销售线索导入单无法删除明细内容").toString();
  509. }
  510. SQLFactory.createDeleteSQL(this, "sat_orderclueuploadbillmx").setUniqueid(sat_orderclueuploadbillmxid).delete();
  511. return getSucReturnObject().toString();
  512. }
  513. // 审核反审核时新增或删除线索池的sql语句汇总
  514. public SQLDump geSqlStatement(boolean ischeck, Long sat_orderclueuploadbillid) throws YosException {
  515. SQLDump sqlDump = new SQLDump();
  516. QuerySQL orderclueuploadbillmxQuery = SQLFactory.createQuerySQL(this, "sat_orderclueuploadbillmx", "name", "province", "city", "county", "address", "notes", "sat_orderclueid", "sat_orderclueuploadbillmxid", "sat_orderclueuploadbillid", "phonenumber", "cluesource").setTableAlias("t1");
  517. orderclueuploadbillmxQuery.addJoinTable(JOINTYPE.inner, "sat_orderclueuploadbill", "t2", "t1.sat_orderclueuploadbillid=t2.sat_orderclueuploadbillid", "cluetype");
  518. orderclueuploadbillmxQuery.setWhere("t1.sat_orderclueuploadbillid", sat_orderclueuploadbillid);
  519. Rows rowsdetaill = orderclueuploadbillmxQuery.query();
  520. if (ischeck) {
  521. for (Row row : rowsdetaill) {
  522. Long sat_orderclueid = createTableID("sat_orderclue");
  523. InsertSQL orderclueInsert = SQLFactory.createInsertSQL(this, "sat_orderclue");
  524. orderclueInsert.setValue("sat_orderclueid", sat_orderclueid);
  525. orderclueInsert.setValue("name", row.getString("name"));
  526. orderclueInsert.setValue("province", row.getString("province"));
  527. orderclueInsert.setValue("city", row.getString("city"));
  528. orderclueInsert.setValue("county", row.getString("county"));
  529. orderclueInsert.setValue("address", row.getString("address"));
  530. orderclueInsert.setValue("phonenumber", row.getString("phonenumber"));
  531. orderclueInsert.setValue("notes", row.getString("notes"));
  532. orderclueInsert.setValue("cluesource", row.getString("cluesource"));
  533. orderclueInsert.setValue("cluetype", row.getString("cluetype"));
  534. orderclueInsert.setValue("isprivate", false);
  535. orderclueInsert.setValue("status", "待分配");
  536. sqlDump.add(orderclueInsert);
  537. sqlDump.add(SQLFactory.createUpdateSQL(this, "sat_orderclueuploadbillmx").setValue("sat_orderclueid", sat_orderclueid).setUniqueid(row.getLong("sat_orderclueuploadbillmxid")));
  538. }
  539. } else {
  540. sqlDump.add(SQLFactory.createDeleteSQL(this, "sat_orderclue").setWhere("sat_orderclueid", rowsdetaill.toArrayList("sat_orderclueid")));
  541. sqlDump.add(SQLFactory.createUpdateSQL(this, "sat_orderclueuploadbillmx").setValue("sat_orderclueid", 0).setWhere("sat_orderclueuploadbillmxid", rowsdetaill.toArrayList("sat_orderclueuploadbillmxid")));
  542. }
  543. return sqlDump;
  544. }
  545. public XSSFSheet addSheet(ExcelFactory excelFactory, String sheetname, Rows datarows, HashMap<String, String> titlemap) {
  546. ArrayList<String> keylist = datarows.getFieldList();
  547. XSSFSheet sheet = excelFactory.getXssfWorkbook().createSheet(sheetname);
  548. XSSFWorkbook xssfFWorkbook = excelFactory.getXssfWorkbook();
  549. XSSFCellStyle xssfCellStyle1 = xssfFWorkbook.createCellStyle();
  550. XSSFFont font = xssfFWorkbook.createFont();
  551. font.setColor((short) 0xa);
  552. font.setFontHeightInPoints((short) 12);
  553. font.setBold(true);
  554. xssfCellStyle1.setFont(font);
  555. ExportExcel.setBatchDetailSheetColumn2(sheet);// 设置工作薄列宽
  556. XSSFCellStyle titleCellStyle1 = ExportExcel.createTitleCellStyle1(xssfFWorkbook);
  557. XSSFCellStyle titleCellStyle2 = ExportExcel.createTitleCellStyle2(xssfFWorkbook);
  558. ExportExcel.batchDetailErr(sheet, titleCellStyle1, titleCellStyle2, xssfFWorkbook);// 写入标题
  559. for (int n = 0; n < datarows.size(); n++) {
  560. Row row = datarows.get(n);
  561. XSSFRow datarow = sheet.createRow(n + 2);
  562. for (int i1 = 0; i1 < keylist.size(); i1++) {
  563. Class fieldclazztype = datarows.getFieldMeta(keylist.get(i1)).getFieldtype();
  564. if (fieldclazztype == Integer.class) {
  565. datarow.createCell(i1).setCellValue(row.getInteger(keylist.get(i1)));
  566. } else if (fieldclazztype == Long.class) {
  567. datarow.createCell(i1).setCellValue(row.getLong(keylist.get(i1)));
  568. } else if (fieldclazztype == Float.class) {
  569. datarow.createCell(i1).setCellValue(row.getFloat(keylist.get(i1)));
  570. } else if (fieldclazztype == Double.class) {
  571. datarow.createCell(i1).setCellValue(row.getDouble(keylist.get(i1)));
  572. } else {
  573. datarow.createCell(i1).setCellValue(row.getString(keylist.get(i1)));
  574. }
  575. if (i1 == 8) {
  576. datarow.getCell(i1).setCellStyle(xssfCellStyle1);
  577. }
  578. }
  579. }
  580. return sheet;
  581. }
  582. public XSSFSheet addSheet1(ExcelFactory excelFactory, String sheetname, Rows datarows, HashMap<String, String> titlemap) {
  583. ArrayList<String> keylist = datarows.getFieldList();
  584. XSSFSheet sheet = excelFactory.getXssfWorkbook().createSheet(sheetname);
  585. XSSFWorkbook xssfFWorkbook = excelFactory.getXssfWorkbook();
  586. XSSFCellStyle xssfCellStyle1 = xssfFWorkbook.createCellStyle();
  587. XSSFFont font = xssfFWorkbook.createFont();
  588. font.setColor((short) 0xa);
  589. font.setFontHeightInPoints((short) 12);
  590. font.setBold(true);
  591. xssfCellStyle1.setFont(font);
  592. ExportExcel.setBatchDetailSheetColumn2(sheet);// 设置工作薄列宽
  593. XSSFCellStyle titleCellStyle1 = ExportExcel.createTitleCellStyle1(xssfFWorkbook);
  594. XSSFCellStyle titleCellStyle2 = ExportExcel.createTitleCellStyle2(xssfFWorkbook);
  595. ExportExcel.batchDetailErr1(sheet, titleCellStyle1, titleCellStyle2, xssfFWorkbook);// 写入标题
  596. for (int n = 0; n < datarows.size(); n++) {
  597. Row row = datarows.get(n);
  598. XSSFRow datarow = sheet.createRow(n + 2);
  599. for (int i1 = 0; i1 < keylist.size(); i1++) {
  600. Class fieldclazztype = datarows.getFieldMeta(keylist.get(i1)).getFieldtype();
  601. if (fieldclazztype == Integer.class) {
  602. datarow.createCell(i1).setCellValue(row.getInteger(keylist.get(i1)));
  603. } else if (fieldclazztype == Long.class) {
  604. datarow.createCell(i1).setCellValue(row.getLong(keylist.get(i1)));
  605. } else if (fieldclazztype == Float.class) {
  606. datarow.createCell(i1).setCellValue(row.getFloat(keylist.get(i1)));
  607. } else if (fieldclazztype == Double.class) {
  608. datarow.createCell(i1).setCellValue(row.getDouble(keylist.get(i1)));
  609. } else {
  610. datarow.createCell(i1).setCellValue(row.getString(keylist.get(i1)));
  611. }
  612. if (i1 == 6) {
  613. datarow.getCell(i1).setCellStyle(xssfCellStyle1);
  614. }
  615. }
  616. }
  617. return sheet;
  618. }
  619. }