enterprise.java 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. package restcontroller.sale.salestarget;
  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.annotation.CACHEING;
  8. import common.data.*;
  9. import org.apache.commons.lang.StringUtils;
  10. import restcontroller.R;
  11. import java.math.BigDecimal;
  12. import java.util.ArrayList;
  13. /**
  14. * 企业目标(经销商目标)
  15. */
  16. public class enterprise extends Controller {
  17. /**
  18. * 构造函数
  19. *
  20. * @param content
  21. */
  22. public enterprise(JSONObject content) throws YosException {
  23. super(content);
  24. }
  25. @API(title = "经销商列表查询", apiversion = R.ID20231018162103.v1.class)
  26. @CACHEING
  27. public String query_agentList() throws YosException {
  28. /*
  29. 过滤条件设置
  30. */
  31. StringBuffer where = new StringBuffer(" 1=1 ");
  32. if (content.containsKey("where")) {
  33. JSONObject whereObject = content.getJSONObject("where");
  34. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  35. where.append(" and(");
  36. where.append(" t1.enterprisename like'%").append(whereObject.getString("condition")).append("%' ");
  37. where.append("or t2.agentnum like'%").append(whereObject.getString("condition")).append("%' ");
  38. where.append(")");
  39. }
  40. }
  41. // SQLFactory sqlFactory = new SQLFactory(this, "查询经销商", pageSize, pageNumber, pageSorting);
  42. // sqlFactory.addParameter_SQL("where", where);
  43. // sqlFactory.addParameter("siteid", siteid);
  44. // sqlFactory.addParameter("year", content.getLong("year"));
  45. // Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
  46. QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sys_enterprise", "sys_enterpriseid", "enterprisename",
  47. "province", "city", "county", "address", "contact", "phonenumber", "taxno");
  48. querySQL.setTableAlias("t1");
  49. querySQL.addJoinTable(JOINTYPE.inner, "sa_agents", "t2", "t1.sys_enterpriseid=t2.sys_enterpriseid and t1.siteid=t2.siteid", "agentnum");
  50. querySQL.setSiteid(siteid);
  51. querySQL.setWhere("t2.status='启用'");
  52. querySQL.setWhere("t1.sys_enterpriseid not in (select t2.sys_enterpriseid from sa_salestargetbill t1 inner join sa_salestargethr t2 on t1.sa_salestargetbillid=t2.sa_salestargetbillid and t1.siteid=t2.siteid where t1.year='" + content.getLong("year") + "' and t1.targettype='企业目标' )");
  53. querySQL.setWhere(where.toString());
  54. querySQL.setPage(pageSize, pageNumber);
  55. Rows rows = querySQL.query();
  56. return getSucReturnObject().setData(rows).toString();
  57. }
  58. @API(title = "企业业绩目标(经销商)", apiversion = R.ID20230110151902.v1.class)
  59. public String selectList() throws YosException {
  60. ArrayList<Long> sys_enterpriseids = new ArrayList<>();
  61. /*
  62. 过滤条件设置
  63. */
  64. StringBuffer where = new StringBuffer(" 1=1 ");
  65. long curryear = 0;
  66. if (!content_where.getStringValue("year").isEmpty()) {
  67. where.append(" and(");
  68. where.append("year ='").append(content_where.getString("year")).append("' ");
  69. where.append(")");
  70. curryear = content_where.getLong("year");
  71. }
  72. if (sys_enterpriseid != 0) {
  73. sys_enterpriseids.add(sys_enterpriseid);
  74. } else if (!content_where.getStringValue("sys_enterpriseid").isEmpty()) {
  75. sys_enterpriseids.add(content_where.getLong("sys_enterpriseid"));
  76. }
  77. //考核指标类型
  78. String assessmentindicators = "";
  79. //统计维度
  80. String statisticaldimension = "";
  81. //统计维度
  82. String sa_accountclassids = "";
  83. long sa_salestargetbillid = 0;
  84. if (curryear != 0) {
  85. Rows rows = dbConnect.runSqlQuery("SELECT assessmentindicators,statisticaldimension,sa_accountclassids,sa_salestargetbillid FROM sa_salestargetbill WHERE `year` = " + curryear + " AND targettype ='企业目标' AND siteid = '" + siteid + "'");
  86. if (rows.isNotEmpty()) {
  87. assessmentindicators = rows.get(0).getString("assessmentindicators");
  88. statisticaldimension = rows.get(0).getString("statisticaldimension");
  89. sa_accountclassids = rows.get(0).getString("sa_accountclassids");
  90. sa_salestargetbillid = rows.get(0).getLong("sa_salestargetbillid");
  91. }
  92. }
  93. long totalPage = 0;
  94. long totalRows = 0;
  95. if (sys_enterpriseids.isEmpty()) {
  96. QuerySQL enterpriseQuery = SQLFactory.createQuerySQL(this, "sys_enterprise", "sys_enterpriseid");
  97. enterpriseQuery.setWhere("exists (select * from sa_salestarget where sa_salestarget.sa_salestargetbillid=" + sa_salestargetbillid + " and sa_salestarget.sys_enterpriseid=sys_enterprise.sys_enterpriseid) ");
  98. enterpriseQuery.setPage(pageSize, pageNumber);
  99. enterpriseQuery.setOrderBy("sys_enterpriseid");
  100. Rows enterpriseRows = enterpriseQuery.query();
  101. sys_enterpriseids = enterpriseRows.toArrayList("sys_enterpriseid", new ArrayList<>());
  102. totalPage = enterpriseRows.getTotalPage();
  103. totalRows = enterpriseRows.getTotalRows();
  104. }
  105. SQLFactory sqlFactory = new SQLFactory(this, "企业-业绩目标完成列表");
  106. sqlFactory.addParameter_SQL("where", where);
  107. sqlFactory.addParameter_in("sys_enterpriseids", sys_enterpriseids);
  108. sqlFactory.addParameter("siteid", siteid);
  109. String sql = sqlFactory.getSQL();
  110. Rows rows = dbConnect.runSqlQuery(sql);
  111. if (totalRows > 0) {
  112. rows.totalRows = totalRows;
  113. rows.totalPage = totalPage;
  114. rows.pageSize = pageSize;
  115. rows.pageNumber = pageNumber;
  116. }
  117. Rows actualRows = new Rows();
  118. //开票
  119. if (assessmentindicators.equals("开票")) {
  120. String where1 = " 1=1 ";
  121. sqlFactory = new SQLFactory(this, "企业-开票");
  122. if (content.getLongValue("num") == 0) {
  123. sqlFactory.addParameter("num", 2);
  124. } else {
  125. sqlFactory.addParameter("num", content.getLongValue("num"));
  126. }
  127. if (statisticaldimension.equals("订单审核")) {
  128. where1 = where1 + " and t2.status='审核' ";
  129. } else {
  130. where1 = where1 + " and t2.status='提交' ";
  131. }
  132. if (StringUtils.isNotBlank(sa_accountclassids)) {
  133. if (isJSONArray(sa_accountclassids)) {
  134. JSONArray jsonArrayResult = JSONArray.parseArray(sa_accountclassids);
  135. if (!jsonArrayResult.isEmpty()) {
  136. where1 = where1 + " and t2.sa_accountclassid in" + jsonArrayResult;
  137. where1 = where1.replace("[", "(").replace("]", ")");
  138. }
  139. }
  140. }
  141. sqlFactory.addParameter_SQL("where1", where1);
  142. }
  143. //订单
  144. if (assessmentindicators.equals("订单")) {
  145. String where1 = " 1=1 ";
  146. sqlFactory = new SQLFactory(this, "企业-订单");
  147. if (content.getLongValue("num") == 0) {
  148. sqlFactory.addParameter("num", 2);
  149. } else {
  150. sqlFactory.addParameter("num", content.getLongValue("num"));
  151. }
  152. if (statisticaldimension.equals("订单审核")) {
  153. where1 = where1 + " and t2.status='审核' ";
  154. } else {
  155. where1 = where1 + " and t2.status='提交' ";
  156. }
  157. if (StringUtils.isNotBlank(sa_accountclassids)) {
  158. if (isJSONArray(sa_accountclassids)) {
  159. JSONArray jsonArrayResult = JSONArray.parseArray(sa_accountclassids);
  160. if (!jsonArrayResult.isEmpty()) {
  161. where1 = where1 + " and t2.sa_accountclassid in" + jsonArrayResult;
  162. where1 = where1.replace("[", "(").replace("]", ")");
  163. }
  164. }
  165. }
  166. sqlFactory.addParameter_SQL("where1", where1);
  167. }
  168. //出货
  169. if (assessmentindicators.equals("出货")) {
  170. String where1 = " 1=1 ";
  171. sqlFactory = new SQLFactory(this, "企业-出货");
  172. if (content.getLongValue("num") == 0) {
  173. sqlFactory.addParameter("num", 2);
  174. } else {
  175. sqlFactory.addParameter("num", content.getLongValue("num"));
  176. }
  177. if (StringUtils.isNotBlank(sa_accountclassids)) {
  178. if (isJSONArray(sa_accountclassids)) {
  179. JSONArray jsonArrayResult = JSONArray.parseArray(sa_accountclassids);
  180. if (!jsonArrayResult.isEmpty()) {
  181. where1 = where1 + " and t2.sa_accountclassid in" + jsonArrayResult;
  182. where1 = where1.replace("[", "(").replace("]", ")");
  183. }
  184. }
  185. }
  186. sqlFactory.addParameter_SQL("where1", where1);
  187. }
  188. //收款
  189. if (assessmentindicators.equals("收款")) {
  190. String where1 = " 1=1 ";
  191. sqlFactory = new SQLFactory(this, "企业-收款");
  192. if (content.getLongValue("num") == 0) {
  193. sqlFactory.addParameter("num", 2);
  194. } else {
  195. sqlFactory.addParameter("num", content.getLongValue("num"));
  196. }
  197. if (StringUtils.isNotBlank(statisticaldimension)) {
  198. if (isJSONObject(statisticaldimension)) {
  199. JSONObject jsonObjectResult = JSONObject.parseObject(statisticaldimension);
  200. if (!jsonObjectResult.isEmpty()) {
  201. StringBuffer stringBuffer = new StringBuffer();
  202. if (!((JSONArray) jsonObjectResult.get("type")).isEmpty()) {
  203. stringBuffer.append(" or class in" + jsonObjectResult.get("type"));
  204. }
  205. if (!((JSONArray) jsonObjectResult.get("mx")).isEmpty()) {
  206. stringBuffer.append(" or subclass in" + jsonObjectResult.get("mx"));
  207. }
  208. if (((JSONArray) jsonObjectResult.get("mx")).isEmpty() && ((JSONArray) jsonObjectResult.get("type")).isEmpty()) {
  209. stringBuffer.append(" 1=1 ");
  210. }
  211. where1 = where1 + " and (" + (stringBuffer.toString()).replaceFirst("or", "") + ")";
  212. where1 = where1.replace("[", "(").replace("]", ")");
  213. }
  214. }
  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 sa_accountclassid in" + jsonArrayResult;
  221. where1 = where1.replace("[", "(").replace("]", ")");
  222. }
  223. }
  224. }
  225. sqlFactory.addParameter_SQL("where1", where1);
  226. }
  227. sqlFactory.addParameter_in("sys_enterpriseid", rows.toArrayList("sys_enterpriseid", new ArrayList<Long>()));
  228. sqlFactory.addParameter("siteid", siteid);
  229. sqlFactory.addParameter("year", curryear);
  230. actualRows = dbConnect.runSqlQuery(sqlFactory);
  231. for (Row row : rows) {
  232. //初始化
  233. row = addActualRow(row);
  234. Long year = row.getLong("year");
  235. Long sys_enterpriseid = row.getLong("sys_enterpriseid");
  236. Row actualRow = new Row();
  237. for (Row tempActualRow : actualRows) {
  238. if (tempActualRow.getLong("year") == year && tempActualRow.getLong("sys_enterpriseid") == sys_enterpriseid) {
  239. actualRow.putAll(tempActualRow);
  240. }
  241. }
  242. row.putAll(actualRow);
  243. row.putAll(calculate(row, actualRow));
  244. // Rows monthRows = new Rows();
  245. // for (int i = 1; i < 13; i++) {
  246. // Row monthRow = new Row();
  247. // monthRow.put("l", row.getString("m" + i + "l"));
  248. // monthRow.put("h", row.getString("m" + i + "h"));
  249. // monthRow.put("a", row.getString("m" + i + "a"));
  250. // monthRow.put("pl", row.getString("m" + i + "pl"));
  251. // monthRow.put("ph", row.getString("m" + i + "ph"));
  252. // monthRow.put("month", i);
  253. // monthRows.add(monthRow);
  254. // }
  255. // row.put("month", monthRows);
  256. }
  257. return getSucReturnObject().setData(rows).toString();
  258. }
  259. @API(title = "企业业绩目标(指定经销商)", apiversion = R.ID2025101413174203.v1.class)
  260. public String selectAgentList() throws YosException {
  261. ArrayList<Long> sys_enterpriseids = new ArrayList<>();
  262. /*
  263. 过滤条件设置
  264. */
  265. StringBuffer where = new StringBuffer(" 1=1 ");
  266. if (sys_enterpriseid != 0) {
  267. sys_enterpriseids.add(sys_enterpriseid);
  268. } else if (!content_where.getStringValue("sys_enterpriseid").isEmpty()) {
  269. sys_enterpriseids.add(content_where.getLong("sys_enterpriseid"));
  270. }
  271. SQLFactory sqlFactory = new SQLFactory(this, "企业-业绩目标完成列表-指定经销商");
  272. sqlFactory.addParameter_SQL("where", where);
  273. sqlFactory.addParameter_in("sys_enterpriseids", sys_enterpriseids);
  274. sqlFactory.addParameter("siteid", siteid);
  275. String sql = sqlFactory.getSQL();
  276. Rows rows = dbConnect.runSqlQuery(sql);
  277. sqlFactory = new SQLFactory(this, "企业-出货-经销商");
  278. if (content.getLongValue("num") == 0) {
  279. sqlFactory.addParameter("num", 2);
  280. } else {
  281. sqlFactory.addParameter("num", content.getLongValue("num"));
  282. }
  283. sqlFactory.addParameter_SQL("where1", " 1=1 ");
  284. sqlFactory.addParameter_in("sys_enterpriseid", rows.toArrayList("sys_enterpriseid", new ArrayList<Long>()));
  285. sqlFactory.addParameter("siteid", siteid);
  286. Rows chuhuoRows = dbConnect.runSqlQuery(sqlFactory);
  287. for(Row row :rows){
  288. Rows actualRows = new Rows();
  289. row = addActualRow(row);
  290. String assessmentindicators = row.getString("assessmentindicators");
  291. //统计维度
  292. String statisticaldimension = row.getString("statisticaldimension");
  293. //统计维度
  294. String sa_accountclassids = row.getString("sa_accountclassids");
  295. //开票
  296. if (assessmentindicators.equals("开票")) {
  297. String where1 = " 1=1 ";
  298. sqlFactory = new SQLFactory(this, "企业-开票-经销商");
  299. if (content.getLongValue("num") == 0) {
  300. sqlFactory.addParameter("num", 2);
  301. } else {
  302. sqlFactory.addParameter("num", content.getLongValue("num"));
  303. }
  304. if (statisticaldimension.equals("订单审核")) {
  305. where1 = where1 + " and t2.status='审核' ";
  306. } else {
  307. where1 = where1 + " and t2.status='提交' ";
  308. }
  309. if (StringUtils.isNotBlank(sa_accountclassids)) {
  310. if (isJSONArray(sa_accountclassids)) {
  311. JSONArray jsonArrayResult = JSONArray.parseArray(sa_accountclassids);
  312. if (!jsonArrayResult.isEmpty()) {
  313. where1 = where1 + " and t2.sa_accountclassid in" + jsonArrayResult;
  314. where1 = where1.replace("[", "(").replace("]", ")");
  315. }
  316. }
  317. }
  318. sqlFactory.addParameter_SQL("where1", where1);
  319. }
  320. //订单
  321. if (assessmentindicators.equals("订单")) {
  322. String where1 = " 1=1 ";
  323. sqlFactory = new SQLFactory(this, "企业-订单-经销商");
  324. if (content.getLongValue("num") == 0) {
  325. sqlFactory.addParameter("num", 2);
  326. } else {
  327. sqlFactory.addParameter("num", content.getLongValue("num"));
  328. }
  329. if (statisticaldimension.equals("订单审核")) {
  330. where1 = where1 + " and t2.status='审核' ";
  331. } else {
  332. where1 = where1 + " and t2.status='提交' ";
  333. }
  334. sqlFactory.addParameter_SQL("where1", where1);
  335. }
  336. //出货
  337. // if (assessmentindicators.equals("出货")) {
  338. // String where1 = " 1=1 ";
  339. // sqlFactory = new SQLFactory(this, "企业-出货-经销商");
  340. // if (content.getLongValue("num") == 0) {
  341. // sqlFactory.addParameter("num", 2);
  342. // } else {
  343. // sqlFactory.addParameter("num", content.getLongValue("num"));
  344. // }
  345. // sqlFactory.addParameter_SQL("where1", where1);
  346. // }
  347. //收款
  348. if (assessmentindicators.equals("收款")) {
  349. String where1 = " 1=1 ";
  350. sqlFactory = new SQLFactory(this, "企业-收款-经销商");
  351. if (content.getLongValue("num") == 0) {
  352. sqlFactory.addParameter("num", 2);
  353. } else {
  354. sqlFactory.addParameter("num", content.getLongValue("num"));
  355. }
  356. if (StringUtils.isNotBlank(statisticaldimension)) {
  357. if (isJSONObject(statisticaldimension)) {
  358. JSONObject jsonObjectResult = JSONObject.parseObject(statisticaldimension);
  359. if (!jsonObjectResult.isEmpty()) {
  360. StringBuffer stringBuffer = new StringBuffer();
  361. if (!((JSONArray) jsonObjectResult.get("type")).isEmpty()) {
  362. stringBuffer.append(" or class in" + jsonObjectResult.get("type"));
  363. }
  364. if (!((JSONArray) jsonObjectResult.get("mx")).isEmpty()) {
  365. stringBuffer.append(" or subclass in" + jsonObjectResult.get("mx"));
  366. }
  367. if (((JSONArray) jsonObjectResult.get("mx")).isEmpty() && ((JSONArray) jsonObjectResult.get("type")).isEmpty()) {
  368. stringBuffer.append(" 1=1 ");
  369. }
  370. where1 = where1 + " and (" + (stringBuffer.toString()).replaceFirst("or", "") + ")";
  371. where1 = where1.replace("[", "(").replace("]", ")");
  372. }
  373. }
  374. }
  375. if (StringUtils.isNotBlank(sa_accountclassids)) {
  376. if (isJSONArray(sa_accountclassids)) {
  377. JSONArray jsonArrayResult = JSONArray.parseArray(sa_accountclassids);
  378. if (!jsonArrayResult.isEmpty()) {
  379. where1 = where1 + " and sa_accountclassid in" + jsonArrayResult;
  380. where1 = where1.replace("[", "(").replace("]", ")");
  381. }
  382. }
  383. }
  384. sqlFactory.addParameter_SQL("where1", where1);
  385. }
  386. sqlFactory.addParameter_in("sys_enterpriseid", rows.toArrayList("sys_enterpriseid", new ArrayList<Long>()));
  387. sqlFactory.addParameter("siteid", siteid);
  388. if(assessmentindicators.equals("出货")){
  389. actualRows=chuhuoRows;
  390. }else{
  391. actualRows = dbConnect.runSqlQuery(sqlFactory);
  392. }
  393. for (Row tempActualRow : actualRows) {
  394. Row actualRow = new Row();
  395. if (tempActualRow.getLong("year")==row.getLong("year")) {
  396. actualRow.putAll(tempActualRow);
  397. }
  398. row.putAll(actualRow);
  399. row.putAll(calculate(row, actualRow));
  400. }
  401. }
  402. return getSucReturnObject().setData(rows).toString();
  403. }
  404. // @API(title = "企业业绩目标(业务员)", apiversion = R.ID20230111163102.v1.class)
  405. // public String selectSellerList() throws YosException {
  406. // /*
  407. // 过滤条件设置
  408. // */
  409. // StringBuffer where = new StringBuffer(" 1=1 ");
  410. // StringBuffer where2 = new StringBuffer(" 1=1 ");
  411. // if (content.containsKey("where")) {
  412. // JSONObject whereObject = content.getJSONObject("where");
  413. // if (whereObject.containsKey("year") && !"".equals(whereObject.getString("year"))) {
  414. // where.append(" and(");
  415. // where.append("year like'%").append(whereObject.getString("year")).append("%' ");
  416. // where.append(")");
  417. //
  418. // where2.append(" and(");
  419. // where2.append("YEAR(t2.billdate) like'%").append(whereObject.getString("year")).append("%' ");
  420. // where2.append(")");
  421. // }
  422. // if (whereObject.containsKey("tradefield") && !"".equals(whereObject.getString("tradefield"))) {
  423. // where.append(" and(");
  424. // where.append("tradefield like'%").append(whereObject.getString("tradefield")).append("%' ");
  425. // where.append(")");
  426. //
  427. // where2.append(" and(");
  428. // where2.append("tradefield like'%").append(whereObject.getString("tradefield")).append("%' ");
  429. // where2.append(")");
  430. // }
  431. //
  432. // }
  433. //
  434. // //考核指标类型
  435. // Long type = content.getLongValue("type");
  436. //
  437. // if (content.containsKey("sys_enterpriseid")) {
  438. // sys_enterpriseid = content.getLongValue("sys_enterpriseid");
  439. // }
  440. //
  441. //
  442. // SQLFactory sqlFactory = new SQLFactory(this, "企业-业绩目标完成列表-业务员");
  443. // sqlFactory.addParameter_SQL("where", where);
  444. // sqlFactory.addParameter_in("hrid", hrid);
  445. // sqlFactory.addParameter_SQL("where", where);
  446. // sqlFactory.addParameter("siteid", siteid);
  447. // String sql = sqlFactory.getSQL();
  448. // Rows rows = dbConnect.runSqlQuery(sql);
  449. //
  450. // Rows actualRows = new Rows();
  451. // //开票
  452. // if (type == 0 || type == 1) {
  453. // sqlFactory = new SQLFactory(this, "企业-开票-业务员");
  454. // }
  455. // //订单
  456. // if (type == 2) {
  457. // sqlFactory = new SQLFactory(this, "企业-订单-业务员");
  458. // }
  459. // //出货
  460. // if (type == 3) {
  461. // sqlFactory = new SQLFactory(this, "企业-出货-业务员");
  462. // }
  463. // sqlFactory.addParameter_in("hrid", hrid);
  464. // sqlFactory.addParameter_SQL("where", where2);
  465. // sqlFactory.addParameter("siteid", siteid);
  466. // actualRows = dbConnect.runSqlQuery(sqlFactory);
  467. //
  468. // for (Row row : rows) {
  469. // //初始化
  470. // row = addActualRow(row);
  471. // Long year = row.getLong("year");
  472. // String tradefield = row.getString("tradefield");
  473. // Row actualRow = new Row();
  474. // for (Row tempActualRow : actualRows) {
  475. // if (tempActualRow.getLong("year") == year && tempActualRow.getString("tradefield").equals(tradefield)) {
  476. // actualRow.putAll(tempActualRow);
  477. // }
  478. // }
  479. // row.putAll(actualRow);
  480. // row.putAll(calculate(row, actualRow));
  481. // Rows monthRows = new Rows();
  482. // for (int i = 1; i < 13; i++) {
  483. // Row monthRow = new Row();
  484. // monthRow.put("l", row.getString("m" + i + "l"));
  485. // monthRow.put("h", row.getString("m" + i + "h"));
  486. // monthRow.put("a", row.getString("m" + i + "a"));
  487. // monthRow.put("pl", row.getString("m" + i + "pl"));
  488. // monthRow.put("ph", row.getString("m" + i + "ph"));
  489. // monthRow.put("month", i);
  490. // monthRows.add(monthRow);
  491. // }
  492. // row.put("month", monthRows);
  493. // }
  494. // return getSucReturnObject().setData(rows).toString();
  495. // }
  496. //添加实际数据
  497. public Row addActualRow(Row targetRow) {
  498. String key = "y1a";
  499. targetRow.put(key, 0);
  500. for (int i = 1; i < 5; i++) {
  501. key = "s" + i + "a";
  502. targetRow.put(key, 0);
  503. }
  504. for (int i = 1; i < 13; i++) {
  505. key = "m" + i + "a";
  506. targetRow.put(key, 0);
  507. }
  508. return targetRow;
  509. }
  510. public Row calculate(Row targetRow, Row actualRow) {
  511. Row row = new Row();
  512. String key_l = "y1l";
  513. String key_h = "y1h";
  514. String key_a = "y1a";
  515. String key_p_l = "y1pl";
  516. String key_p_h = "y1ph";
  517. if (targetRow.getDouble(key_l) == 0) {
  518. row.put(key_p_l, 0);
  519. } else {
  520. row.put(key_p_l, getPercent(actualRow.getDouble(key_a), targetRow.getDouble(key_l)));
  521. }
  522. if (targetRow.getDouble(key_h) == 0) {
  523. row.put(key_p_h, 0);
  524. } else {
  525. row.put(key_p_h, getPercent(actualRow.getDouble(key_a), targetRow.getDouble(key_h)));
  526. }
  527. for (int i = 1; i < 5; i++) {
  528. key_l = "s" + i + "l";
  529. key_h = "s" + i + "h";
  530. key_a = "s" + i + "a";
  531. key_p_l = "s" + i + "pl";
  532. key_p_h = "s" + i + "ph";
  533. if (targetRow.getDouble(key_l) == 0) {
  534. row.put(key_p_l, 0);
  535. } else {
  536. row.put(key_p_l, getPercent(actualRow.getDouble(key_a), targetRow.getDouble(key_l)));
  537. }
  538. if (targetRow.getDouble(key_h) == 0) {
  539. row.put(key_p_h, 0);
  540. } else {
  541. row.put(key_p_h, getPercent(actualRow.getDouble(key_a), targetRow.getDouble(key_h)));
  542. }
  543. }
  544. // for (int i = 1; i < 13; i++) {
  545. // key_l = "m" + i + "l";
  546. // key_h = "m" + i + "h";
  547. // key_a = "m" + i + "a";
  548. // key_p_l = "m" + i + "pl";
  549. // key_p_h = "m" + i + "ph";
  550. // if (targetRow.getDouble(key_l) == 0) {
  551. // row.put(key_p_l, 0);
  552. // } else {
  553. // row.put(key_p_l, getPercent(actualRow.getDouble(key_a), targetRow.getDouble(key_l)));
  554. // }
  555. // if (targetRow.getDouble(key_h) == 0) {
  556. // row.put(key_p_h, 0);
  557. // } else {
  558. // row.put(key_p_h, getPercent(actualRow.getDouble(key_a), targetRow.getDouble(key_h)));
  559. // }
  560. // }
  561. return row;
  562. }
  563. //(实际-目标)/目标
  564. public double getPercent(Double a, Double b) {
  565. double c = a * 100 / b;
  566. BigDecimal bigDecimal = new BigDecimal(c);
  567. return bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
  568. }
  569. }