personnelstatistics.java 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093
  1. package restcontroller.webmanage.sale.salestarget;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import common.Controller;
  5. import common.YosException;
  6. import common.annotation.API;
  7. import common.annotation.CACHEING;
  8. import common.data.*;
  9. import org.apache.commons.lang.StringUtils;
  10. import org.apache.poi.xssf.usermodel.*;
  11. import restcontroller.R;
  12. import restcontroller.webmanage.saletool.orderclue.ExportExcel;
  13. import java.math.BigDecimal;
  14. import java.util.ArrayList;
  15. import java.util.Calendar;
  16. @API(title = "管理端-销售目标-人员目标统计")
  17. public class personnelstatistics extends Controller {
  18. /**
  19. * 构造函数
  20. *
  21. * @param content
  22. */
  23. public personnelstatistics(JSONObject content) throws YosException {
  24. super(content);
  25. }
  26. @API(title = "人员目标导出", apiversion = R.ID20220916095402.v1.class)
  27. public String export() throws YosException {
  28. JSONArray array = content.getJSONArray("row");
  29. ExcelFactory excelFactory = new ExcelFactory("人员目标导出模板");
  30. XSSFSheet sheet = excelFactory.getXssfWorkbook().createSheet("Sheet1");
  31. XSSFWorkbook xssfFWorkbook = excelFactory.getXssfWorkbook();
  32. personnelexcel.setBatchDetailSheetColumn3(sheet);// 设置工作薄列宽
  33. XSSFCellStyle titleCellStyle1 = ExportExcel.createTitleCellStyle1(xssfFWorkbook);
  34. XSSFCellStyle titleCellStyle2 = ExportExcel.createTitleCellStyle2(xssfFWorkbook);
  35. XSSFCellStyle titleCellStyle3 = ExportExcel.createBodyCellStyle(xssfFWorkbook);
  36. personnelexcel.batchDetailExport(sheet, titleCellStyle1, titleCellStyle2, titleCellStyle3, xssfFWorkbook, array);// 写入标题
  37. Rows aa = uploadExcelToObs(excelFactory);
  38. String url = "";
  39. if (!aa.isEmpty()) {
  40. url = aa.get(0).getString("url");
  41. }
  42. return getSucReturnObject().setData(url).toString();
  43. }
  44. public XSSFSheet addSheet(ExcelFactory excelFactory, String sheetname, Rows datarows) {
  45. ArrayList<String> keylist = datarows.getFieldList();
  46. XSSFSheet sheet = excelFactory.getXssfWorkbook().createSheet(sheetname);
  47. XSSFWorkbook xssfFWorkbook = excelFactory.getXssfWorkbook();
  48. XSSFCellStyle xssfCellStyle1 = xssfFWorkbook.createCellStyle();
  49. XSSFFont font = xssfFWorkbook.createFont();
  50. font.setColor((short) 0xa);
  51. font.setFontHeightInPoints((short) 12);
  52. font.setBold(true);
  53. xssfCellStyle1.setFont(font);
  54. personnelexcel.setBatchDetailSheetColumn2(sheet);// 设置工作薄列宽
  55. XSSFCellStyle titleCellStyle1 = ExportExcel.createTitleCellStyle1(xssfFWorkbook);
  56. XSSFCellStyle titleCellStyle2 = ExportExcel.createTitleCellStyle2(xssfFWorkbook);
  57. personnelexcel.batchDetailErr(sheet, titleCellStyle1, titleCellStyle2, xssfFWorkbook);// 写入标题
  58. for (int n = 0; n < datarows.size(); n++) {
  59. Row row = datarows.get(n);
  60. XSSFRow datarow = sheet.createRow(n + 2);
  61. for (int i1 = 0; i1 < keylist.size(); i1++) {
  62. Class fieldclazztype = datarows.getFieldMeta( keylist.get(i1)).getFieldtype();
  63. if (fieldclazztype == Integer.class) {
  64. datarow.createCell(i1).setCellValue(row.getInteger(keylist.get(i1)));
  65. } else if (fieldclazztype == Long.class) {
  66. datarow.createCell(i1).setCellValue(row.getLong(keylist.get(i1)));
  67. } else if (fieldclazztype == Float.class) {
  68. datarow.createCell(i1).setCellValue(row.getFloat(keylist.get(i1)));
  69. } else if (fieldclazztype == Double.class) {
  70. datarow.createCell(i1).setCellValue(row.getDouble(keylist.get(i1)));
  71. } else {
  72. datarow.createCell(i1).setCellValue(row.getString(keylist.get(i1)));
  73. }
  74. if (i1 == 36) {
  75. datarow.getCell(i1).setCellStyle(xssfCellStyle1);
  76. }
  77. }
  78. }
  79. return sheet;
  80. }
  81. // @API(title = "获取区域经理的营销区域", apiversion = R.ID20231018093803.v1.class)
  82. // public String getcurrentusersalearea() throws YosException {
  83. //
  84. // SQLFactory sqlFactory = new SQLFactory(this, "业务员列表查询");
  85. // sqlFactory.addParameter("siteid", siteid);
  86. // sqlFactory.addParameter("hrid", hrid);
  87. // Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
  88. //
  89. // SQLFactory areasqlFactory = new SQLFactory(this, "下级区域获取");
  90. // areasqlFactory.addParameter("siteid", siteid);
  91. // areasqlFactory.addParameter_in("sa_saleareaid", rows.toArrayList("sa_saleareaid",new ArrayList<>()));
  92. // Rows arearows = dbConnect.runSqlQuery(areasqlFactory.getSQL());
  93. // return getSucReturnObject().setData(arearows).toString();
  94. // }
  95. @API(title = "查询当前账户负责的区域", apiversion = R.ID20231108160203.v1.class)
  96. @CACHEING
  97. public String queryList_currentArea() throws YosException {
  98. SQLFactory hrsqlFactory = new SQLFactory(this, "业务员列表查询");
  99. hrsqlFactory.addParameter("siteid", siteid);
  100. hrsqlFactory.addParameter("hrid", hrid);
  101. Rows hrrows = dbConnect.runSqlQuery(hrsqlFactory.getSQL());
  102. return getSucReturnObject().setData(hrrows).toString();
  103. }
  104. @API(title = "人员目标统计(区域经理)", apiversion = R.ID20231018103203.v1.class)
  105. @CACHEING
  106. public String queryList_areamanager() throws YosException {
  107. //年份
  108. Calendar cal = Calendar.getInstance();
  109. int year = cal.get(Calendar.YEAR);
  110. Rows billRows = dbConnect.runSqlQuery("SELECT sa_salestargetbillid,assessmentindicators,statisticaldimension,sa_accountclassids FROM sa_salestargetbill WHERE year="+year+" AND siteid ='" + siteid + "' and targettype = '人员目标'");
  111. SQLFactory hrsqlFactory = new SQLFactory(this, "业务员列表查询");
  112. hrsqlFactory.addParameter("siteid", siteid);
  113. hrsqlFactory.addParameter("hrid", hrid);
  114. Rows hrrows = dbConnect.runSqlQuery(hrsqlFactory.getSQL());
  115. RowsMap hrrowsMap = hrrows.toRowsMap("sa_saleareaid");
  116. // if(sa_saleareaid==0){
  117. // if(hrrows.isNotEmpty()){
  118. // sa_saleareaid=hrrows.get(0).getLong("sa_saleareaid");
  119. // }
  120. // }
  121. SQLFactory areasqlFactory = new SQLFactory(this, "下级区域获取");
  122. areasqlFactory.addParameter("siteid", siteid);
  123. areasqlFactory.addParameter_in("sa_saleareaid", hrrows.toArrayList("sa_saleareaid",new ArrayList<>()));
  124. Rows arearows = dbConnect.runSqlQuery(areasqlFactory.getSQL());
  125. ArrayList<Long> areaList = arearows.toArrayList("sa_saleareaid",new ArrayList<Long>());
  126. //考核指标类型
  127. long sa_salestargetbillid = 0;
  128. String assessmentindicators="";
  129. //统计维度
  130. String statisticaldimension="";
  131. //账户
  132. String sa_accountclassids="";
  133. if (billRows.isNotEmpty()) {
  134. sa_salestargetbillid=billRows.get(0).getLong("sa_salestargetbillid");
  135. assessmentindicators=billRows.get(0).getString("assessmentindicators");
  136. statisticaldimension=billRows.get(0).getString("statisticaldimension");
  137. sa_accountclassids=billRows.get(0).getString("sa_accountclassids");
  138. }
  139. /*
  140. 过滤条件设置
  141. */
  142. StringBuffer where = new StringBuffer();
  143. if(areaList.size()>0){
  144. where = where.append(" 1=1 and t.sa_saleareaid in "+areaList.toString().replace("[", "(").replace("]", ")"));
  145. }else{
  146. where = where.append(" 1=1 ");
  147. }
  148. SQLFactory sqlFactory = new SQLFactory(this, "人员-目标详情列表");
  149. sqlFactory.addParameter("sa_salestargetbillid", sa_salestargetbillid);
  150. sqlFactory.addParameter_SQL("where", where);
  151. sqlFactory.addParameter("siteid", siteid);
  152. String sql = sqlFactory.getSQL();
  153. Rows rows = dbConnect.runSqlQuery(sql);
  154. Rows saleareas = dbConnect.runSqlQuery("select * from sa_salearea where ifnull(parentid,0)=0 and siteid='"+siteid+"'");
  155. Long sa_saleareaidtop=0l;
  156. String areanametop="";
  157. if(!saleareas.isEmpty() && saleareas.size()==1){
  158. sa_saleareaidtop=saleareas.get(0).getLong("sa_saleareaid");
  159. areanametop=saleareas.get(0).getString("areaname");
  160. for (Row row :rows) {
  161. if(row.getLong("parentid")==0){
  162. row.put("y1l",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("y1l"));
  163. row.put("y1h",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("y1h"));
  164. row.put("s1l",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("s1l"));
  165. row.put("s1h",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("s1h"));
  166. row.put("s2l",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("s2l"));
  167. row.put("s2h",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("s2h"));
  168. row.put("s3l",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("s3l"));
  169. row.put("s3h",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("s3h"));
  170. row.put("s4l",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("s4l"));
  171. row.put("s4h",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("s4h"));
  172. row.put("m1l",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m1l"));
  173. row.put("m1h",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m1h"));
  174. row.put("m2l",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m2l"));
  175. row.put("m2h",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m2h"));
  176. row.put("m3l",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m3l"));
  177. row.put("m3h",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m3h"));
  178. row.put("m4l",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m4l"));
  179. row.put("m4h",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m4h"));
  180. row.put("m5l",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m5l"));
  181. row.put("m5h",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m5h"));
  182. row.put("m6l",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m6l"));
  183. row.put("m6h",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m6h"));
  184. row.put("m7l",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m7l"));
  185. row.put("m7h",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m7h"));
  186. row.put("m8l",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m8l"));
  187. row.put("m8h",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m8h"));
  188. row.put("m9l",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m9l"));
  189. row.put("m9h",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m9h"));
  190. row.put("m10l",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m10l"));
  191. row.put("m10h",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m10h"));
  192. row.put("m11l",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m11l"));
  193. row.put("m11h",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m11h"));
  194. row.put("m12l",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m12l"));
  195. row.put("m12h",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m12h"));
  196. }
  197. }
  198. }
  199. Rows actualRows = new Rows();
  200. //开票
  201. if (assessmentindicators .equals("开票")) {
  202. String where1 =" 1=1 ";
  203. sqlFactory = new SQLFactory(this, "人员目标统计-开票");
  204. if(content.getLongValue("num")==0){
  205. sqlFactory.addParameter("num",2);
  206. }else{
  207. sqlFactory.addParameter("num",content.getLongValue("num"));
  208. }
  209. sqlFactory.addParameter("sa_salestargetbillid", sa_salestargetbillid);
  210. sqlFactory.addParameter_SQL("where", where);
  211. if(statisticaldimension.equals("订单审核")){
  212. where1=where1+" and t2.status='审核'";
  213. }else{
  214. where1=where1+" and t2.status='提交'";
  215. }
  216. if(StringUtils.isNotBlank(sa_accountclassids)){
  217. if(isJSONArray(sa_accountclassids)){
  218. JSONArray jsonArrayResult = JSONArray.parseArray(sa_accountclassids);
  219. if(!jsonArrayResult.isEmpty()){
  220. where1=where1+ " and t2.sa_accountclassid in"+jsonArrayResult;
  221. where1 = where1.replace("[", "(").replace("]", ")");
  222. }
  223. }
  224. }
  225. sqlFactory.addParameter_SQL("where1",where1);
  226. sqlFactory.addParameter("siteid", siteid);
  227. sqlFactory.addParameter("year", year);
  228. actualRows = dbConnect.runSqlQuery(sqlFactory);
  229. }
  230. //订单
  231. if (assessmentindicators .equals("订单")) {
  232. String where1 =" 1=1 ";
  233. sqlFactory = new SQLFactory(this, "人员目标统计-订单");
  234. if(content.getLongValue("num")==0){
  235. sqlFactory.addParameter("num",2);
  236. }else{
  237. sqlFactory.addParameter("num",content.getLongValue("num"));
  238. }
  239. sqlFactory.addParameter("sa_salestargetbillid", sa_salestargetbillid);
  240. sqlFactory.addParameter_SQL("where", where);
  241. if(statisticaldimension.equals("订单审核")){
  242. where1=where1+" and t2.status='审核'";
  243. }else{
  244. where1=where1+" and t2.status='提交'";
  245. }
  246. if(StringUtils.isNotBlank(sa_accountclassids)){
  247. if(isJSONArray(sa_accountclassids)){
  248. JSONArray jsonArrayResult = JSONArray.parseArray(sa_accountclassids);
  249. if(!jsonArrayResult.isEmpty()){
  250. where1=where1+ " and t2.sa_accountclassid in"+jsonArrayResult;
  251. where1 = where1.replace("[", "(").replace("]", ")");
  252. }
  253. }
  254. }
  255. sqlFactory.addParameter_SQL("where1",where1);
  256. sqlFactory.addParameter("siteid", siteid);
  257. sqlFactory.addParameter("year", year);
  258. actualRows = dbConnect.runSqlQuery(sqlFactory);
  259. }
  260. //出货
  261. if (assessmentindicators .equals("出货")) {
  262. String where1 =" 1=1 ";
  263. sqlFactory = new SQLFactory(this, "人员目标统计-出货");
  264. if(content.getLongValue("num")==0){
  265. sqlFactory.addParameter("num",2);
  266. }else{
  267. sqlFactory.addParameter("num",content.getLongValue("num"));
  268. }
  269. sqlFactory.addParameter("sa_salestargetbillid", sa_salestargetbillid);
  270. sqlFactory.addParameter_SQL("where", where);
  271. if(StringUtils.isNotBlank(sa_accountclassids)){
  272. if(isJSONArray(sa_accountclassids)){
  273. JSONArray jsonArrayResult = JSONArray.parseArray(sa_accountclassids);
  274. if(!jsonArrayResult.isEmpty()){
  275. where1=where1+ " and t2.sa_accountclassid in"+jsonArrayResult;
  276. where1 = where1.replace("[", "(").replace("]", ")");
  277. }
  278. }
  279. }
  280. sqlFactory.addParameter_SQL("where1",where1);
  281. sqlFactory.addParameter("siteid", siteid);
  282. sqlFactory.addParameter("year", year);
  283. actualRows = dbConnect.runSqlQuery(sqlFactory);
  284. }
  285. //收款
  286. if (assessmentindicators .equals("收款")) {
  287. String where1 =" 1=1 ";
  288. sqlFactory = new SQLFactory(this, "人员目标统计-收款");
  289. if(content.getLongValue("num")==0){
  290. sqlFactory.addParameter("num",2);
  291. }else{
  292. sqlFactory.addParameter("num",content.getLongValue("num"));
  293. }
  294. sqlFactory.addParameter("sa_saleareaid", sa_saleareaidtop);
  295. sqlFactory.addParameter("areaname", areanametop);
  296. sqlFactory.addParameter("sa_salestargetbillid", sa_salestargetbillid);
  297. sqlFactory.addParameter_SQL("where", where);
  298. if(StringUtils.isNotBlank(statisticaldimension)){
  299. if(isJSONObject(statisticaldimension)){
  300. JSONObject jsonObjectResult = JSONObject.parseObject(statisticaldimension);
  301. if(!jsonObjectResult.isEmpty()){
  302. StringBuffer stringBuffer= new StringBuffer();
  303. if(!((JSONArray)jsonObjectResult.get("type")).isEmpty()){
  304. stringBuffer.append(" or t1.class in"+ jsonObjectResult.get("type"));
  305. }
  306. if(!((JSONArray)jsonObjectResult.get("mx")).isEmpty()){
  307. stringBuffer.append(" or t1.subclass in"+ jsonObjectResult.get("mx"));
  308. }
  309. if(((JSONArray)jsonObjectResult.get("mx")).isEmpty() && ((JSONArray)jsonObjectResult.get("type")).isEmpty()){
  310. stringBuffer.append(" 1=1 ");
  311. }
  312. where1= where1+ " and ("+(stringBuffer.toString()).replaceFirst("or", "")+")";
  313. where1 = where1.replace("[", "(").replace("]", ")");
  314. }
  315. }
  316. }
  317. if(StringUtils.isNotBlank(sa_accountclassids)){
  318. if(isJSONArray(sa_accountclassids)){
  319. JSONArray jsonArrayResult = JSONArray.parseArray(sa_accountclassids);
  320. if(!jsonArrayResult.isEmpty()){
  321. where1=where1+ " and t1.sa_accountclassid in"+jsonArrayResult;
  322. where1 = where1.replace("[", "(").replace("]", ")");
  323. }
  324. }
  325. }
  326. sqlFactory.addParameter_SQL("where1",where1);
  327. sqlFactory.addParameter("siteid", siteid);
  328. sqlFactory.addParameter("year", year);
  329. actualRows = dbConnect.runSqlQuery(sqlFactory);
  330. }
  331. if(!saleareas.isEmpty() && saleareas.size()==1){
  332. for (Row row :actualRows) {
  333. if(row.getLong("parentid")==0){
  334. row.put("y1a",actualRows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("y1a"));
  335. row.put("s1a",actualRows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("s1a"));
  336. row.put("s2a",actualRows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("s2a"));
  337. row.put("s3a",actualRows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("s3a"));
  338. row.put("s4a",actualRows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("s4a"));
  339. row.put("m1a",actualRows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m1a"));
  340. row.put("m2a",actualRows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m2a"));
  341. row.put("m3a",actualRows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m3a"));
  342. row.put("m4a",actualRows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m4a"));
  343. row.put("m5a",actualRows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m5a"));
  344. row.put("m6a",actualRows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m6a"));
  345. row.put("m7a",actualRows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m7a"));
  346. row.put("m8a",actualRows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m8a"));
  347. row.put("m9a",actualRows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m9a"));
  348. row.put("m10a",actualRows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m10a"));
  349. row.put("m11a",actualRows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m11a"));
  350. row.put("m12a",actualRows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m12a"));
  351. }
  352. }
  353. }
  354. Rows rowsResult =new Rows();
  355. for (Row row : rows) {
  356. if(hrrows.size()!=0){
  357. if(hrrowsMap.containsKey(row.getString("sa_saleareaid"))){
  358. if(row.getString("type").equals("区域")){
  359. rowsResult.add(row);
  360. }
  361. }
  362. }else{
  363. if(row.getString("type").equals("区域")){
  364. rowsResult.add(row);
  365. }
  366. }
  367. }
  368. for (Row row : rowsResult) {
  369. //初始化
  370. row = addActualRow(row);
  371. Long sa_saleareaid1 = row.getLong("sa_saleareaid");
  372. Row actualRow = new Row();
  373. for (Row tempActualRow : actualRows) {
  374. if (tempActualRow.getLong("sa_saleareaid") == sa_saleareaid1) {
  375. actualRow.putAll(tempActualRow);
  376. }
  377. }
  378. row.putAll(actualRow);
  379. row.putAll(calculate(row, actualRow));
  380. }
  381. Row rowResult = new Row();
  382. rowResult.put("y1l",sum1("y1l",rowsResult));
  383. rowResult.put("y1a",sum1("y1a",rowsResult));
  384. for (int i = 1; i < 5; i++) {
  385. rowResult.put("s" + i + "l",sum1("s" + i + "l",rowsResult));
  386. rowResult.put("s" + i + "a",sum1("s" + i + "a",rowsResult));
  387. }
  388. for (int i = 1; i < 13; i++) {
  389. rowResult.put("m" + i + "l",sum1("m" + i + "l",rowsResult));
  390. rowResult.put("m" + i + "a",sum1("m" + i + "a",rowsResult));
  391. }
  392. rowsResult = new Rows();
  393. rowsResult.add(rowResult);
  394. return getSucReturnObject().setData(rowsResult).toString();
  395. }
  396. @API(title = "人员目标统计列表(区域经理)", apiversion = R.ID20231018103303.v1.class)
  397. @CACHEING
  398. public String queryList_areamanagerList() throws YosException {
  399. //年份
  400. Calendar cal = Calendar.getInstance();
  401. int year = cal.get(Calendar.YEAR);
  402. Rows billRows = dbConnect.runSqlQuery("SELECT sa_salestargetbillid,assessmentindicators,statisticaldimension,sa_accountclassids FROM sa_salestargetbill WHERE year="+year+" AND siteid ='" + siteid + "' and targettype = '人员目标'");
  403. SQLFactory hrsqlFactory = new SQLFactory(this, "业务员列表查询");
  404. hrsqlFactory.addParameter("siteid", siteid);
  405. hrsqlFactory.addParameter("hrid", hrid);
  406. Rows hrrows = dbConnect.runSqlQuery(hrsqlFactory.getSQL());
  407. SQLFactory areasqlFactory = new SQLFactory(this, "下级区域获取");
  408. areasqlFactory.addParameter("siteid", siteid);
  409. areasqlFactory.addParameter_in("sa_saleareaid", hrrows.toArrayList("sa_saleareaid",new ArrayList<>()));
  410. Rows arearows = dbConnect.runSqlQuery(areasqlFactory.getSQL());
  411. ArrayList<Long> areaList = arearows.toArrayList("sa_saleareaid",new ArrayList<Long>());
  412. areaList.add(0l);
  413. //考核指标类型
  414. long sa_salestargetbillid = 0;
  415. String assessmentindicators="";
  416. //统计维度
  417. String statisticaldimension="";
  418. //账户
  419. String sa_accountclassids="";
  420. if (billRows.isNotEmpty()) {
  421. sa_salestargetbillid=billRows.get(0).getLong("sa_salestargetbillid");
  422. assessmentindicators=billRows.get(0).getString("assessmentindicators");
  423. statisticaldimension=billRows.get(0).getString("statisticaldimension");
  424. sa_accountclassids=billRows.get(0).getString("sa_accountclassids");
  425. }
  426. /*
  427. 过滤条件设置
  428. */
  429. StringBuffer where = new StringBuffer(" 1=1 and t.sa_saleareaid in "+areaList.toString().replace("[", "(").replace("]", ")"));
  430. SQLFactory sqlFactory = new SQLFactory(this, "人员-目标详情列表");
  431. sqlFactory.addParameter("sa_salestargetbillid", sa_salestargetbillid);
  432. sqlFactory.addParameter_SQL("where", where);
  433. sqlFactory.addParameter("siteid", siteid);
  434. String sql = sqlFactory.getSQL();
  435. Rows rows = dbConnect.runSqlQuery(sql);
  436. Rows saleareas = dbConnect.runSqlQuery("select * from sa_salearea where ifnull(parentid,0)=0 and siteid='"+siteid+"'");
  437. Long sa_saleareaidtop=0l;
  438. String areanametop="";
  439. if(!saleareas.isEmpty() && saleareas.size()==1){
  440. sa_saleareaidtop=saleareas.get(0).getLong("sa_saleareaid");
  441. areanametop=saleareas.get(0).getString("areaname");
  442. for (Row row :rows) {
  443. if(row.getLong("parentid")==0){
  444. row.put("y1l",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("y1l"));
  445. row.put("y1h",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("y1h"));
  446. row.put("s1l",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("s1l"));
  447. row.put("s1h",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("s1h"));
  448. row.put("s2l",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("s2l"));
  449. row.put("s2h",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("s2h"));
  450. row.put("s3l",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("s3l"));
  451. row.put("s3h",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("s3h"));
  452. row.put("s4l",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("s4l"));
  453. row.put("s4h",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("s4h"));
  454. row.put("m1l",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m1l"));
  455. row.put("m1h",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m1h"));
  456. row.put("m2l",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m2l"));
  457. row.put("m2h",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m2h"));
  458. row.put("m3l",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m3l"));
  459. row.put("m3h",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m3h"));
  460. row.put("m4l",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m4l"));
  461. row.put("m4h",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m4h"));
  462. row.put("m5l",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m5l"));
  463. row.put("m5h",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m5h"));
  464. row.put("m6l",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m6l"));
  465. row.put("m6h",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m6h"));
  466. row.put("m7l",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m7l"));
  467. row.put("m7h",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m7h"));
  468. row.put("m8l",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m8l"));
  469. row.put("m8h",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m8h"));
  470. row.put("m9l",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m9l"));
  471. row.put("m9h",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m9h"));
  472. row.put("m10l",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m10l"));
  473. row.put("m10h",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m10h"));
  474. row.put("m11l",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m11l"));
  475. row.put("m11h",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m11h"));
  476. row.put("m12l",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m12l"));
  477. row.put("m12h",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m12h"));
  478. }
  479. }
  480. }
  481. Rows actualRows = new Rows();
  482. //开票
  483. if (assessmentindicators .equals("开票")) {
  484. String where1 =" 1=1 ";
  485. sqlFactory = new SQLFactory(this, "人员目标统计-开票");
  486. if(content.getLongValue("num")==0){
  487. sqlFactory.addParameter("num",2);
  488. }else{
  489. sqlFactory.addParameter("num",content.getLongValue("num"));
  490. }
  491. sqlFactory.addParameter("sa_salestargetbillid", sa_salestargetbillid);
  492. sqlFactory.addParameter_SQL("where", where);
  493. if(statisticaldimension.equals("订单审核")){
  494. where1=where1+" and t2.status='审核'";
  495. }else{
  496. where1=where1+" and t2.status='提交'";
  497. }
  498. if(StringUtils.isNotBlank(sa_accountclassids)){
  499. if(isJSONArray(sa_accountclassids)){
  500. JSONArray jsonArrayResult = JSONArray.parseArray(sa_accountclassids);
  501. if(!jsonArrayResult.isEmpty()){
  502. where1=where1+ " and t2.sa_accountclassid in"+jsonArrayResult;
  503. where1 = where1.replace("[", "(").replace("]", ")");
  504. }
  505. }
  506. }
  507. sqlFactory.addParameter_SQL("where1",where1);
  508. sqlFactory.addParameter("siteid", siteid);
  509. sqlFactory.addParameter("year", year);
  510. actualRows = dbConnect.runSqlQuery(sqlFactory);
  511. }
  512. //订单
  513. if (assessmentindicators .equals("订单")) {
  514. String where1 =" 1=1 ";
  515. sqlFactory = new SQLFactory(this, "人员目标统计-订单");
  516. if(content.getLongValue("num")==0){
  517. sqlFactory.addParameter("num",2);
  518. }else{
  519. sqlFactory.addParameter("num",content.getLongValue("num"));
  520. }
  521. sqlFactory.addParameter("sa_salestargetbillid", sa_salestargetbillid);
  522. sqlFactory.addParameter_SQL("where", where);
  523. if(statisticaldimension.equals("订单审核")){
  524. where1=where1+" and t2.status='审核'";
  525. }else{
  526. where1=where1+" and t2.status='提交'";
  527. }
  528. if(StringUtils.isNotBlank(sa_accountclassids)){
  529. if(isJSONArray(sa_accountclassids)){
  530. JSONArray jsonArrayResult = JSONArray.parseArray(sa_accountclassids);
  531. if(!jsonArrayResult.isEmpty()){
  532. where1=where1+ " and t2.sa_accountclassid in"+jsonArrayResult;
  533. where1 = where1.replace("[", "(").replace("]", ")");
  534. }
  535. }
  536. }
  537. sqlFactory.addParameter_SQL("where1",where1);
  538. sqlFactory.addParameter("siteid", siteid);
  539. sqlFactory.addParameter("year", year);
  540. actualRows = dbConnect.runSqlQuery(sqlFactory);
  541. }
  542. //出货
  543. if (assessmentindicators .equals("出货")) {
  544. String where1 =" 1=1 ";
  545. sqlFactory = new SQLFactory(this, "人员目标统计-出货");
  546. if(content.getLongValue("num")==0){
  547. sqlFactory.addParameter("num",2);
  548. }else{
  549. sqlFactory.addParameter("num",content.getLongValue("num"));
  550. }
  551. sqlFactory.addParameter("sa_salestargetbillid", sa_salestargetbillid);
  552. sqlFactory.addParameter_SQL("where", where);
  553. if(StringUtils.isNotBlank(sa_accountclassids)){
  554. if(isJSONArray(sa_accountclassids)){
  555. JSONArray jsonArrayResult = JSONArray.parseArray(sa_accountclassids);
  556. if(!jsonArrayResult.isEmpty()){
  557. where1=where1+ " and t2.sa_accountclassid in"+jsonArrayResult;
  558. where1 = where1.replace("[", "(").replace("]", ")");
  559. }
  560. }
  561. }
  562. sqlFactory.addParameter_SQL("where1",where1);
  563. sqlFactory.addParameter("siteid", siteid);
  564. sqlFactory.addParameter("year", year);
  565. actualRows = dbConnect.runSqlQuery(sqlFactory);
  566. }
  567. //收款
  568. if (assessmentindicators .equals("收款")) {
  569. String where1 =" 1=1 ";
  570. sqlFactory = new SQLFactory(this, "人员目标统计-收款");
  571. if(content.getLongValue("num")==0){
  572. sqlFactory.addParameter("num",2);
  573. }else{
  574. sqlFactory.addParameter("num",content.getLongValue("num"));
  575. }
  576. sqlFactory.addParameter("sa_saleareaid", sa_saleareaidtop);
  577. sqlFactory.addParameter("areaname", areanametop);
  578. sqlFactory.addParameter("sa_salestargetbillid", sa_salestargetbillid);
  579. sqlFactory.addParameter_SQL("where", where);
  580. if(StringUtils.isNotBlank(statisticaldimension)){
  581. if(isJSONObject(statisticaldimension)){
  582. JSONObject jsonObjectResult = JSONObject.parseObject(statisticaldimension);
  583. if(!jsonObjectResult.isEmpty()){
  584. StringBuffer stringBuffer= new StringBuffer();
  585. if(!((JSONArray)jsonObjectResult.get("type")).isEmpty()){
  586. stringBuffer.append(" or t1.class in"+ jsonObjectResult.get("type"));
  587. }
  588. if(!((JSONArray)jsonObjectResult.get("mx")).isEmpty()){
  589. stringBuffer.append(" or t1.subclass in"+ jsonObjectResult.get("mx"));
  590. }
  591. if(((JSONArray)jsonObjectResult.get("mx")).isEmpty() && ((JSONArray)jsonObjectResult.get("type")).isEmpty()){
  592. stringBuffer.append(" 1=1 ");
  593. }
  594. where1= where1+ " and ("+(stringBuffer.toString()).replaceFirst("or", "")+")";
  595. where1 = where1.replace("[", "(").replace("]", ")");
  596. }
  597. }
  598. }
  599. if(StringUtils.isNotBlank(sa_accountclassids)){
  600. if(isJSONArray(sa_accountclassids)){
  601. JSONArray jsonArrayResult = JSONArray.parseArray(sa_accountclassids);
  602. if(!jsonArrayResult.isEmpty()){
  603. where1=where1+ " and t1.sa_accountclassid in"+jsonArrayResult;
  604. where1 = where1.replace("[", "(").replace("]", ")");
  605. }
  606. }
  607. }
  608. sqlFactory.addParameter_SQL("where1",where1);
  609. sqlFactory.addParameter("siteid", siteid);
  610. sqlFactory.addParameter("year", year);
  611. actualRows = dbConnect.runSqlQuery(sqlFactory);
  612. }
  613. if(!saleareas.isEmpty() && saleareas.size()==1){
  614. for (Row row :actualRows) {
  615. if(row.getLong("parentid")==0){
  616. row.put("y1a",actualRows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("y1a"));
  617. row.put("s1a",actualRows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("s1a"));
  618. row.put("s2a",actualRows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("s2a"));
  619. row.put("s3a",actualRows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("s3a"));
  620. row.put("s4a",actualRows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("s4a"));
  621. row.put("m1a",actualRows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m1a"));
  622. row.put("m2a",actualRows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m2a"));
  623. row.put("m3a",actualRows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m3a"));
  624. row.put("m4a",actualRows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m4a"));
  625. row.put("m5a",actualRows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m5a"));
  626. row.put("m6a",actualRows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m6a"));
  627. row.put("m7a",actualRows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m7a"));
  628. row.put("m8a",actualRows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m8a"));
  629. row.put("m9a",actualRows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m9a"));
  630. row.put("m10a",actualRows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m10a"));
  631. row.put("m11a",actualRows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m11a"));
  632. row.put("m12a",actualRows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m12a"));
  633. }
  634. }
  635. }
  636. for (Row row : rows) {
  637. //初始化
  638. row = addActualRow(row);
  639. Long sa_saleareaid1 = row.getLong("sa_saleareaid");
  640. Row actualRow = new Row();
  641. for (Row tempActualRow : actualRows) {
  642. if (tempActualRow.getLong("sa_saleareaid") == sa_saleareaid1) {
  643. actualRow.putAll(tempActualRow);
  644. }
  645. }
  646. row.putAll(actualRow);
  647. row.putAll(calculate(row, actualRow));
  648. }
  649. return getSucReturnObject().setData(rows).toString();
  650. }
  651. @API(title = "人员目标统计", apiversion = R.ID20220904134102.v1.class)
  652. @CACHEING
  653. public String queryList() throws YosException {
  654. //年份
  655. Long sa_salestargetbillid = content.getLong("sa_salestargetbillid");
  656. Rows billRows = dbConnect.runSqlQuery("SELECT assessmentindicators,year,statisticaldimension,sa_accountclassids FROM sa_salestargetbill WHERE sa_salestargetbillid=" + sa_salestargetbillid + " AND siteid ='" + siteid + "'");
  657. //考核指标类型
  658. String assessmentindicators = "";
  659. //统计维度
  660. String statisticaldimension="";
  661. //账户
  662. String sa_accountclassids="";
  663. long year = 2023;
  664. if (billRows.isNotEmpty()) {
  665. assessmentindicators=billRows.get(0).getString("assessmentindicators");
  666. statisticaldimension=billRows.get(0).getString("statisticaldimension");
  667. sa_accountclassids=billRows.get(0).getString("sa_accountclassids");
  668. year=billRows.get(0).getLong("year");
  669. }
  670. /*
  671. 过滤条件设置
  672. */
  673. StringBuffer where = new StringBuffer(" 1=1 ");
  674. if (content.containsKey("where")) {
  675. JSONObject whereObject = content.getJSONObject("where");
  676. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  677. where.append(" and(");
  678. where.append("t.name like'%").append(whereObject.getString("condition")).append("%' ");
  679. where.append("or t.depfullname like'%").append(whereObject.getString("condition")).append("%' ");
  680. where.append("or t.depname like'%").append(whereObject.getString("condition")).append("%' ");
  681. where.append("or t.position like'%").append(whereObject.getString("condition")).append("%' ");
  682. where.append(")");
  683. }
  684. }
  685. SQLFactory sqlFactory = new SQLFactory(this, "人员-目标详情列表");
  686. sqlFactory.addParameter("sa_salestargetbillid", sa_salestargetbillid);
  687. sqlFactory.addParameter_SQL("where", where);
  688. sqlFactory.addParameter("siteid", siteid);
  689. String sql = sqlFactory.getSQL();
  690. Rows rows = dbConnect.runSqlQuery(sql);
  691. Rows saleareas = dbConnect.runSqlQuery("select * from sa_salearea where ifnull(parentid,0)=0 and siteid='"+siteid+"'");
  692. Long sa_saleareaidtop=0l;
  693. String areanametop="";
  694. if(!saleareas.isEmpty() && saleareas.size()==1){
  695. sa_saleareaidtop=saleareas.get(0).getLong("sa_saleareaid");
  696. areanametop=saleareas.get(0).getString("areaname");
  697. for (Row row :rows) {
  698. if(row.getLong("parentid")==0){
  699. row.put("y1l",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("y1l"));
  700. row.put("y1h",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("y1h"));
  701. row.put("s1l",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("s1l"));
  702. row.put("s1h",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("s1h"));
  703. row.put("s2l",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("s2l"));
  704. row.put("s2h",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("s2h"));
  705. row.put("s3l",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("s3l"));
  706. row.put("s3h",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("s3h"));
  707. row.put("s4l",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("s4l"));
  708. row.put("s4h",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("s4h"));
  709. row.put("m1l",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m1l"));
  710. row.put("m1h",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m1h"));
  711. row.put("m2l",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m2l"));
  712. row.put("m2h",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m2h"));
  713. row.put("m3l",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m3l"));
  714. row.put("m3h",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m3h"));
  715. row.put("m4l",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m4l"));
  716. row.put("m4h",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m4h"));
  717. row.put("m5l",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m5l"));
  718. row.put("m5h",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m5h"));
  719. row.put("m6l",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m6l"));
  720. row.put("m6h",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m6h"));
  721. row.put("m7l",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m7l"));
  722. row.put("m7h",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m7h"));
  723. row.put("m8l",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m8l"));
  724. row.put("m8h",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m8h"));
  725. row.put("m9l",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m9l"));
  726. row.put("m9h",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m9h"));
  727. row.put("m10l",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m10l"));
  728. row.put("m10h",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m10h"));
  729. row.put("m11l",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m11l"));
  730. row.put("m11h",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m11h"));
  731. row.put("m12l",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m12l"));
  732. row.put("m12h",rows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m12h"));
  733. }
  734. }
  735. }
  736. Rows actualRows = new Rows();
  737. //开票
  738. if (assessmentindicators .equals("开票")) {
  739. String where1 =" 1=1 ";
  740. sqlFactory = new SQLFactory(this, "人员目标统计-开票");
  741. if(content.getLongValue("num")==0){
  742. sqlFactory.addParameter("num",2);
  743. }else{
  744. sqlFactory.addParameter("num",content.getLongValue("num"));
  745. }
  746. sqlFactory.addParameter("sa_salestargetbillid", sa_salestargetbillid);
  747. sqlFactory.addParameter_SQL("where", where);
  748. if(statisticaldimension.equals("订单审核")){
  749. where1=where1+" and t2.status='审核'";
  750. }else{
  751. where1=where1+" and t2.status='提交'";
  752. }
  753. if(StringUtils.isNotBlank(sa_accountclassids)){
  754. if(isJSONArray(sa_accountclassids)){
  755. JSONArray jsonArrayResult = JSONArray.parseArray(sa_accountclassids);
  756. if(!jsonArrayResult.isEmpty()){
  757. where1=where1+ " and t2.sa_accountclassid in"+jsonArrayResult;
  758. where1 = where1.replace("[", "(").replace("]", ")");
  759. }
  760. }
  761. }
  762. sqlFactory.addParameter_SQL("where1",where1);
  763. sqlFactory.addParameter("siteid", siteid);
  764. sqlFactory.addParameter("year", year);
  765. actualRows = dbConnect.runSqlQuery(sqlFactory);
  766. }
  767. //订单
  768. if (assessmentindicators .equals("订单")) {
  769. String where1 =" 1=1 ";
  770. sqlFactory = new SQLFactory(this, "人员目标统计-订单");
  771. if(content.getLongValue("num")==0){
  772. sqlFactory.addParameter("num",2);
  773. }else{
  774. sqlFactory.addParameter("num",content.getLongValue("num"));
  775. }
  776. sqlFactory.addParameter("sa_salestargetbillid", sa_salestargetbillid);
  777. sqlFactory.addParameter_SQL("where", where);
  778. if(statisticaldimension.equals("订单审核")){
  779. where1=where1+" and t2.status='审核'";
  780. }else{
  781. where1=where1+" and t2.status='提交'";
  782. }
  783. if(StringUtils.isNotBlank(sa_accountclassids)){
  784. if(isJSONArray(sa_accountclassids)){
  785. JSONArray jsonArrayResult = JSONArray.parseArray(sa_accountclassids);
  786. if(!jsonArrayResult.isEmpty()){
  787. where1=where1+ " and t2.sa_accountclassid in"+jsonArrayResult;
  788. where1 = where1.replace("[", "(").replace("]", ")");
  789. }
  790. }
  791. }
  792. sqlFactory.addParameter_SQL("where1",where1);
  793. sqlFactory.addParameter("siteid", siteid);
  794. sqlFactory.addParameter("year", year);
  795. actualRows = dbConnect.runSqlQuery(sqlFactory);
  796. }
  797. //出货
  798. if (assessmentindicators .equals("出货")) {
  799. String where1 =" 1=1 ";
  800. sqlFactory = new SQLFactory(this, "人员目标统计-出货");
  801. if(content.getLongValue("num")==0){
  802. sqlFactory.addParameter("num",2);
  803. }else{
  804. sqlFactory.addParameter("num",content.getLongValue("num"));
  805. }
  806. if(content.getLongValue("num")==0){
  807. sqlFactory.addParameter("num",2);
  808. }else{
  809. sqlFactory.addParameter("num",content.getLongValue("num"));
  810. }
  811. sqlFactory.addParameter("sa_salestargetbillid", sa_salestargetbillid);
  812. sqlFactory.addParameter_SQL("where", where);
  813. if(StringUtils.isNotBlank(sa_accountclassids)){
  814. if(isJSONArray(sa_accountclassids)){
  815. JSONArray jsonArrayResult = JSONArray.parseArray(sa_accountclassids);
  816. if(!jsonArrayResult.isEmpty()){
  817. where1=where1+ " and t2.sa_accountclassid in"+jsonArrayResult;
  818. where1 = where1.replace("[", "(").replace("]", ")");
  819. }
  820. }
  821. }
  822. sqlFactory.addParameter_SQL("where1",where1);
  823. sqlFactory.addParameter("siteid", siteid);
  824. sqlFactory.addParameter("year", year);
  825. actualRows = dbConnect.runSqlQuery(sqlFactory);
  826. }
  827. //收款
  828. if (assessmentindicators .equals("收款")) {
  829. String where1 =" 1=1 ";
  830. sqlFactory = new SQLFactory(this, "人员目标统计-收款");
  831. if(content.getLongValue("num")==0){
  832. sqlFactory.addParameter("num",2);
  833. }else{
  834. sqlFactory.addParameter("num",content.getLongValue("num"));
  835. }
  836. sqlFactory.addParameter("sa_saleareaid", sa_saleareaidtop);
  837. sqlFactory.addParameter("areaname", areanametop);
  838. sqlFactory.addParameter("sa_salestargetbillid", sa_salestargetbillid);
  839. sqlFactory.addParameter_SQL("where", where);
  840. if(StringUtils.isNotBlank(statisticaldimension)){
  841. if(isJSONObject(statisticaldimension)){
  842. JSONObject jsonObjectResult = JSONObject.parseObject(statisticaldimension);
  843. if(!jsonObjectResult.isEmpty()){
  844. StringBuffer stringBuffer= new StringBuffer();
  845. if(!((JSONArray)jsonObjectResult.get("type")).isEmpty()){
  846. stringBuffer.append(" or t1.class in"+ jsonObjectResult.get("type"));
  847. }
  848. if(!((JSONArray)jsonObjectResult.get("mx")).isEmpty()){
  849. stringBuffer.append(" or t1.subclass in"+ jsonObjectResult.get("mx"));
  850. }
  851. if(((JSONArray)jsonObjectResult.get("mx")).isEmpty() && ((JSONArray)jsonObjectResult.get("type")).isEmpty()){
  852. stringBuffer.append(" 1=1 ");
  853. }
  854. where1= where1+ " and ("+(stringBuffer.toString()).replaceFirst("or", "")+")";
  855. where1 = where1.replace("[", "(").replace("]", ")");
  856. }
  857. }
  858. }
  859. if(StringUtils.isNotBlank(sa_accountclassids)){
  860. if(isJSONArray(sa_accountclassids)){
  861. JSONArray jsonArrayResult = JSONArray.parseArray(sa_accountclassids);
  862. if(!jsonArrayResult.isEmpty()){
  863. where1=where1+ " and t1.sa_accountclassid in"+jsonArrayResult;
  864. where1 = where1.replace("[", "(").replace("]", ")");
  865. }
  866. }
  867. }
  868. sqlFactory.addParameter_SQL("where1",where1);
  869. sqlFactory.addParameter("siteid", siteid);
  870. sqlFactory.addParameter("year", year);
  871. actualRows = dbConnect.runSqlQuery(sqlFactory);
  872. }
  873. if(!saleareas.isEmpty() && saleareas.size()==1){
  874. for (Row row :actualRows) {
  875. if(row.getLong("parentid")==0){
  876. row.put("y1a",actualRows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("y1a"));
  877. row.put("s1a",actualRows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("s1a"));
  878. row.put("s2a",actualRows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("s2a"));
  879. row.put("s3a",actualRows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("s3a"));
  880. row.put("s4a",actualRows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("s4a"));
  881. row.put("m1a",actualRows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m1a"));
  882. row.put("m2a",actualRows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m2a"));
  883. row.put("m3a",actualRows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m3a"));
  884. row.put("m4a",actualRows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m4a"));
  885. row.put("m5a",actualRows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m5a"));
  886. row.put("m6a",actualRows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m6a"));
  887. row.put("m7a",actualRows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m7a"));
  888. row.put("m8a",actualRows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m8a"));
  889. row.put("m9a",actualRows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m9a"));
  890. row.put("m10a",actualRows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m10a"));
  891. row.put("m11a",actualRows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m11a"));
  892. row.put("m12a",actualRows.toRowsMap("parentid").get(sa_saleareaidtop.toString()).sum("m12a"));
  893. }
  894. }
  895. }
  896. for (Row row : rows) {
  897. //初始化
  898. row = addActualRow(row);
  899. Long sa_saleareaid = row.getLong("sa_saleareaid");
  900. Row actualRow = new Row();
  901. for (Row tempActualRow : actualRows) {
  902. if (tempActualRow.getLong("sa_saleareaid") == sa_saleareaid) {
  903. actualRow.putAll(tempActualRow);
  904. }
  905. }
  906. row.putAll(actualRow);
  907. row.putAll(calculate(row, actualRow));
  908. }
  909. return getSucReturnObject().setData(rows).toString();
  910. }
  911. //添加实际数据
  912. public Row addActualRow(Row targetRow) {
  913. String key = "y1a";
  914. targetRow.put(key, 0);
  915. for (int i = 1; i < 5; i++) {
  916. key = "s" + i + "a";
  917. targetRow.put(key, 0);
  918. }
  919. for (int i = 1; i < 13; i++) {
  920. key = "m" + i + "a";
  921. targetRow.put(key, 0);
  922. }
  923. return targetRow;
  924. }
  925. public Row calculate(Row targetRow, Row actualRow) {
  926. Row row = new Row();
  927. String key_l = "y1l";
  928. String key_h = "y1h";
  929. String key_a = "y1a";
  930. String key_p_l = "y1pl";
  931. String key_p_h = "y1ph";
  932. if (targetRow.getDouble(key_l) == 0) {
  933. row.put(key_p_l, 0);
  934. } else {
  935. row.put(key_p_l, getPercent(actualRow.getDouble(key_a), targetRow.getDouble(key_l)));
  936. }
  937. if (targetRow.getDouble(key_h) == 0) {
  938. row.put(key_p_h, 0);
  939. } else {
  940. row.put(key_p_h, getPercent(actualRow.getDouble(key_a), targetRow.getDouble(key_h)));
  941. }
  942. for (int i = 1; i < 5; i++) {
  943. key_l = "s" + i + "l";
  944. key_h = "s" + i + "h";
  945. key_a = "s" + i + "a";
  946. key_p_l = "s" + i + "pl";
  947. key_p_h = "s" + i + "ph";
  948. if (targetRow.getDouble(key_l) == 0) {
  949. row.put(key_p_l, 0);
  950. } else {
  951. row.put(key_p_l, getPercent(actualRow.getDouble(key_a), targetRow.getDouble(key_l)));
  952. }
  953. if (targetRow.getDouble(key_h) == 0) {
  954. row.put(key_p_h, 0);
  955. } else {
  956. row.put(key_p_h, getPercent(actualRow.getDouble(key_a), targetRow.getDouble(key_h)));
  957. }
  958. }
  959. for (int i = 1; i < 13; i++) {
  960. key_l = "m" + i + "l";
  961. key_h = "m" + i + "h";
  962. key_a = "m" + i + "a";
  963. key_p_l = "m" + i + "pl";
  964. key_p_h = "m" + i + "ph";
  965. if (targetRow.getDouble(key_l) == 0) {
  966. row.put(key_p_l, 0);
  967. } else {
  968. row.put(key_p_l, getPercent(actualRow.getDouble(key_a), targetRow.getDouble(key_l)));
  969. }
  970. if (targetRow.getDouble(key_h) == 0) {
  971. row.put(key_p_h, 0);
  972. } else {
  973. row.put(key_p_h, getPercent(actualRow.getDouble(key_a), targetRow.getDouble(key_h)));
  974. }
  975. }
  976. return row;
  977. }
  978. public double getPercent(Double a, Double b) {
  979. double c = a * 100 / b;
  980. BigDecimal bigDecimal = new BigDecimal(c);
  981. return bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
  982. }
  983. public BigDecimal sum1(String column,Rows rows) {
  984. BigDecimal value = new BigDecimal("0");
  985. for (Row row : rows) {
  986. if (row.containsKey(column)) {
  987. value = value.add(new BigDecimal(row.getString(column)));
  988. }
  989. }
  990. return value;
  991. }
  992. }