TRmActItemController.java 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772
  1. package com.steerinfo.ems.trmactitem.controller;
  2. import com.steerinfo.auth.utils.JwtUtil;
  3. import com.steerinfo.ems.Utils.DateUtils;
  4. import com.steerinfo.ems.formula.model.Formula;
  5. import com.steerinfo.ems.formula.service.IFormulaService;
  6. import com.steerinfo.ems.trmactitem.mapper.TRmActItemMapper;
  7. import com.steerinfo.ems.trmactitem.model.TRmActItem;
  8. import com.steerinfo.ems.trmactitem.service.ITRmActItemService;
  9. import com.steerinfo.ems.trmactvalue.service.ITRmActValueService;
  10. import com.steerinfo.ems.trmbalancevalue.service.ITRmBalanceValueService;
  11. import com.steerinfo.ems.trmdfvalue.service.ITRmDfValueService;
  12. import com.steerinfo.ems.trmdwvalue.service.ITRmDwValueService;
  13. import com.steerinfo.ems.trmplanvalue.service.ITRmPlanValueService;
  14. import com.steerinfo.framework.controller.BaseRESTfulController;
  15. import com.steerinfo.framework.controller.RESTfulResult;
  16. import com.steerinfo.framework.service.pagehelper.PageList;
  17. import com.steerinfo.task.SpringCronTask;
  18. import io.swagger.annotations.ApiImplicitParam;
  19. import io.swagger.annotations.ApiImplicitParams;
  20. import io.swagger.annotations.ApiModelProperty;
  21. import io.swagger.annotations.ApiOperation;
  22. import org.apache.commons.lang3.StringUtils;
  23. import org.slf4j.Logger;
  24. import org.slf4j.LoggerFactory;
  25. import org.springframework.beans.factory.annotation.Autowired;
  26. import org.springframework.web.bind.annotation.*;
  27. import javax.script.ScriptEngine;
  28. import javax.script.ScriptEngineManager;
  29. import java.math.BigDecimal;
  30. import java.util.*;
  31. /**
  32. * TRmActItem RESTful接口:
  33. * @author generator
  34. * @version 1.0-SNAPSHORT 2019-10-11 11:41
  35. * 类描述
  36. * 修订历史:
  37. * 日期:2019-10-11
  38. * 作者:generator
  39. * 参考:
  40. * 描述:TRmActItem RESTful接口
  41. * @see null
  42. * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved.
  43. */
  44. @RestController
  45. @RequestMapping("/${api.version}/trmactitems")
  46. public class TRmActItemController extends BaseRESTfulController {
  47. private static final Logger logger = LoggerFactory.getLogger(SpringCronTask.class);
  48. @Autowired
  49. TRmActItemMapper tRmActItemMapper;
  50. @Autowired
  51. ITRmActItemService tRmActItemService;
  52. @Autowired
  53. IFormulaService formulaService;
  54. @Autowired
  55. ITRmActValueService tRmActValueService;
  56. @Autowired
  57. ITRmBalanceValueService tRmBalanceValueService;
  58. @Autowired
  59. ITRmPlanValueService tRmPlanValueService;
  60. @Autowired
  61. ITRmDwValueService tRmDwValueService;
  62. @Autowired
  63. ITRmDfValueService tRmDfValueService;
  64. @ApiOperation(value="获取列表", notes="分页查询")
  65. @ApiImplicitParams({
  66. @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
  67. @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer")
  68. })
  69. //@RequiresPermissions("trmactitem:view")
  70. @GetMapping(value = "/")
  71. public RESTfulResult list(@RequestParam HashMap parmas,Integer pageNum, Integer pageSize){
  72. PageList<TRmActItem> list = tRmActItemService.queryForPage(parmas, pageNum, pageSize);
  73. return success(list);
  74. }
  75. @ApiOperation(value="获取列表", notes="分页模糊查询")
  76. @ApiImplicitParams({
  77. @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
  78. @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer")
  79. })
  80. //@RequiresPermissions("trmactitem:view")
  81. @GetMapping(value = "/like/")
  82. public RESTfulResult listLike(@RequestParam HashMap parmas,Integer pageNum, Integer pageSize){
  83. if(parmas.containsKey("energyid") && parmas.get("energyid") != null && !"".equals(parmas.get("energyid").toString())){
  84. String energyid = parmas.get("energyid").toString();
  85. if(energyid.indexOf(",") == -1){
  86. parmas.put("energyid", "and t.energyid = '" + energyid + "'");
  87. } else {
  88. energyid = "and t.energyid in ('" + energyid.replaceAll(",", "','") + "')";
  89. parmas.put("energyid", energyid);
  90. }
  91. }
  92. if(parmas.containsKey("workprocid") && parmas.get("workprocid") != null && !"".equals(parmas.get("workprocid").toString())){
  93. String workprocid = parmas.get("workprocid").toString();
  94. if(workprocid.indexOf(",") == -1){
  95. parmas.put("workprocid", "and t.workprocid = '" + workprocid + "'");
  96. } else {
  97. workprocid = "and t.workprocid in ('" + workprocid.replaceAll(",", "','") + "')";
  98. parmas.put("workprocid", workprocid);
  99. }
  100. }
  101. if(parmas.containsKey("propertyid") && parmas.get("propertyid") != null && !"".equals(parmas.get("propertyid").toString())){
  102. String propertyid = parmas.get("propertyid").toString();
  103. if(propertyid.indexOf(",") == -1){
  104. parmas.put("propertyid", "and t.propertyid = '" + propertyid + "'");
  105. } else {
  106. propertyid = "and t.propertyid in ('" + propertyid.replaceAll(",", "','") + "')";
  107. parmas.put("propertyid", propertyid);
  108. }
  109. }
  110. if(parmas.get("itemid") != null && !parmas.get("itemid").toString().isEmpty()){
  111. String itemid = parmas.get("itemid").toString();
  112. if(!itemid.startsWith("'")){
  113. itemid = "'" + itemid.replaceAll(",", "','").replaceAll(",", "','") + "'";
  114. }
  115. parmas.put("itemid", itemid);
  116. }
  117. PageList<TRmActItem> list = tRmActItemService.queryLikeForPage(parmas, pageNum, pageSize);
  118. return success(list);
  119. }
  120. @ApiOperation(value="创建", notes="根据TRmActItem对象创建")
  121. @ApiImplicitParam(name = "tRmActItem", value = "详细实体tRmActItem", required = true, dataType = "TRmActItem")
  122. //@RequiresPermissions("trmactitem:create")
  123. @PostMapping(value = "/")
  124. public RESTfulResult add(@RequestBody Map<String,Object> maps){
  125. // 能介
  126. Map trmenergy = (Map) maps.get("trmenergy");
  127. String trmenergyId = (String) trmenergy.get("id");
  128. String trmenergyName = (String) trmenergy.get("name");
  129. // 工序
  130. Map trmworkproc = (Map) maps.get("trmworkproc");
  131. String trmworkprocId = (String) trmworkproc.get("id");
  132. String trmworkprocName = (String) trmworkproc.get("name");
  133. // 能介类型
  134. Map trmenergyproperty = (Map) maps.get("trmenergyproperty");
  135. String trmenergypropertyId = (String) trmenergyproperty.get("id");
  136. String trmenergypropertyName = (String) trmenergyproperty.get("name");
  137. //单位
  138. Map trmunit = (Map) maps.get("trmunit");
  139. String trmunitId = trmunit.get("id")==null?"":trmunit.get("id").toString();
  140. Integer seqno = maps.get("seqno") == null || maps.get("seqno").toString().isEmpty() ? 10 : Integer.valueOf(maps.get("seqno").toString());
  141. String itemtype = (String) maps.get("itemtype");
  142. String itemid = trmworkprocId + trmenergyId + trmenergypropertyId + itemtype;
  143. String itemtypeName = "";
  144. if (itemtype.equalsIgnoreCase("R")) {
  145. itemtypeName = "实绩";
  146. } else if (itemtype.equalsIgnoreCase("P")) {
  147. itemtypeName = "计划";
  148. }
  149. String itemname = trmworkprocName + trmenergyName + itemtypeName + trmenergypropertyName;
  150. String itemdesc = maps.get("itemdesc")==null?"":maps.get("itemdesc").toString();
  151. if (itemdesc.isEmpty()) {
  152. itemdesc = itemname;
  153. }
  154. TRmActItem rmActItem = tRmActItemService.getById(itemid);
  155. if (rmActItem != null) {
  156. return failed(null, "已存在该项目");
  157. }
  158. // F为波动系数,其他为单位转换系数
  159. Integer defaultvalue = 1;
  160. if (itemtype.equalsIgnoreCase("F")){
  161. defaultvalue = maps.get("defaultvalue") == null ? 0 : Integer.valueOf(maps.get("defaultvalue").toString());
  162. }else{
  163. defaultvalue = maps.get("defaultvalue") == null ? 1 : Integer.valueOf(maps.get("defaultvalue").toString());
  164. }
  165. // 数值精度
  166. String digits = maps.get("digits") == null || maps.get("digits").toString().isEmpty() ? "3" :maps.get("digits").toString();
  167. TRmActItem tRmActItem = new TRmActItem();
  168. tRmActItem.setId(itemid);
  169. tRmActItem.setItemname(itemname);
  170. tRmActItem.setItemdesc(itemdesc);
  171. tRmActItem.setItemtype(itemtype);
  172. tRmActItem.setPropertyid(trmenergypropertyId);
  173. tRmActItem.setWorkprocid(trmworkprocId);
  174. tRmActItem.setEnergyid(trmenergyId);
  175. tRmActItem.setUnitid(trmunitId);
  176. tRmActItem.setUseflag("1");
  177. tRmActItem.setSeqno(seqno);
  178. tRmActItem.setDefaultvalue(defaultvalue);
  179. tRmActItem.setDigits(Short.parseShort(digits));
  180. tRmActItem.setUserid(JwtUtil.getUseridByToken());
  181. tRmActItem.setState(maps.get("state")==null?"":maps.get("state").toString());
  182. tRmActItem.setIsup(maps.get("isup")==null?"0":maps.get("isup").toString());
  183. tRmActItem.setShowno(tRmActItemService.MaxSeq(itemtype));
  184. tRmActItem.setAssociateid(maps.get("associateid")==null?"":maps.get("associateid").toString());
  185. tRmActItem.setClock(DateUtils.dateStr(new Date(), "yyyy-MM-dd HH:mm:ss"));
  186. tRmActItem.setFid(maps.get("fid")==null?"":maps.get("fid").toString());
  187. tRmActItem.setBz(maps.get("bz")==null?"":maps.get("bz").toString());
  188. tRmActItem.setMintimegranid(maps.get("mintimegranid")==null?"MONTH":maps.get("mintimegranid").toString());
  189. tRmActItemService.add(tRmActItem);
  190. //增加公式
  191. Formula formula = new Formula();
  192. formula.setClock("202001"); // DateUtils.getCurrentTime("yyyyMM")
  193. formula.setCode(itemid);
  194. formula.setDescription(itemname);
  195. formula.setSourcecode("R("+maps.get("tablename")+","+itemid+")");
  196. formula.setIsavailable("1");
  197. formula.setRevisetime(DateUtils.getCurrentTime("yyyy-MM-dd HH:mm:ss"));
  198. formula.setTablename(maps.get("tablename").toString());
  199. formulaService.add(formula);
  200. return success(tRmActItem);
  201. }
  202. @ApiOperation(value="获取详细信息", notes="根据url的id来获取详细信息")
  203. @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "String")
  204. //@RequiresPermissions("trmactitem:view")
  205. @GetMapping(value = "/{id}")
  206. public RESTfulResult get(@PathVariable String id){
  207. TRmActItem tRmActItem = tRmActItemService.getById(id);
  208. return success(tRmActItem);
  209. }
  210. @ApiOperation(value="更新详细信息", notes="根据url的id来指定更新对象,并根据传过来的tRmActItem信息来更新详细信息")
  211. @ApiImplicitParams({
  212. @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "String"),
  213. @ApiImplicitParam(name = "tRmActItem", value = "详细实体tRmActItem", required = true, dataType = "TRmActItem")
  214. })
  215. //@RequiresPermissions("trmactitem:update")
  216. @PutMapping(value = "/{id}", produces = "application/json;charset=UTF-8")
  217. public RESTfulResult update(@PathVariable String id, @RequestBody TRmActItem model){
  218. model.setId(id);
  219. model.setDefaulman(JwtUtil.getUseridByToken());
  220. model.setModificationtime(DateUtils.dateStr(new Date(), "yyyy-MM-dd HH:mm:ss"));
  221. Map<String,Object> params = new HashMap<>();
  222. params.put("clock", DateUtils.getCurrentTime("yyyyMM"));
  223. params.put("code", model.getItemid());
  224. Formula fm = formulaService.getByParams(params);
  225. List<Formula> associatedFormula = formulaService.getAssociatedFormula(model.getItemid());
  226. if(model.getUseflag().equalsIgnoreCase("0")) {
  227. if (associatedFormula.size() > 0) {
  228. String ids = "";
  229. for (Formula formula : associatedFormula) {
  230. ids += formula.getClock() + " " + formula.getCode() + ",";
  231. }
  232. return failed(500, "该项目公式已经被其他项目关联,无法进行禁用 关联的项目有:" + ids);
  233. }
  234. }
  235. if (model.getUseflag().equalsIgnoreCase("1")){
  236. String s = formulaService.checkFormula(fm);
  237. if (!s.equals("")){
  238. return failed(500,"该项目所对应的公式不合法无法启动 "+"["+s+"]");
  239. }
  240. }
  241. fm.setDescription(model.getItemname());
  242. fm.setIsavailable(model.getUseflag());
  243. formulaService.updateFormula(fm);
  244. TRmActItem tRmActItem = tRmActItemService.modify(model);
  245. logger.info("用户id为"+ JwtUtil.getUseridByToken()+"进行了修改操作"+DateUtils.dateStr(new Date(),"yyyy-MM-dd HH:mm:ss"));
  246. return success(tRmActItem);
  247. }
  248. @ApiModelProperty(value = "批量更新实体信息",notes = "根据url的id来指定更新对象,并根据传过来的tRmActItem集合来更新详细信息")
  249. @ApiImplicitParam(name = "List<TRmActItem>",value = "详细实体tRmActItem集合",required = true,dataType = "TRmActItem")
  250. @PutMapping(value = "/batchUpdate",produces ="application/json;charset=UTF-8" )
  251. public RESTfulResult batchUpdate(@RequestBody TRmActItem[] model){
  252. int failnum = 0;
  253. ArrayList<String> failmsgs = new ArrayList<String>();
  254. ArrayList<String> warnmsg = new ArrayList<String>();
  255. String userId = JwtUtil.getUseridByToken();
  256. for(int i = 0;i < model.length;i++){
  257. try {
  258. if(model[i].getIssettle() != null && !model[i].getIssettle().equals("")){
  259. tRmActItemService.modify(model[i]);
  260. } else {
  261. TRmActItem old = tRmActItemService.getById(model[i].getId());
  262. logger.info("T_RM_ACT_ITEM表的数据发生修改(操作人ID:" + userId + "):");
  263. logger.info("修改前数据是" + old.toString());
  264. String oldMintimegranid = old.getMintimegranid();
  265. // 如果修改最小时间粒度,判断公式是否合法(最小时间粒度影响公式计算)
  266. if(!oldMintimegranid.equalsIgnoreCase(model[i].getMintimegranid())){
  267. HashMap<String, Object> parmas = new HashMap<>();
  268. parmas.put("code", model[i].getItemid());
  269. parmas.put("clock", DateUtils.dateStr(new Date(), "yyyyMM"));
  270. // 获取公式
  271. Formula fm = formulaService.getFormulaCodeClock(parmas);
  272. String res = formulaService.checkFormulaMint(fm, model[i].getMintimegranid());
  273. if(!res.isEmpty()){
  274. warnmsg.add(model[i].getId() + ":" + res);
  275. }
  276. }
  277. model[i].setDefaulman(userId);
  278. model[i].setModificationtime(DateUtils.dateStr(new Date(), "yyyy-MM-dd HH:mm:ss"));
  279. TRmActItem trmData = tRmActItemService.modify(model[i]);
  280. if(model[i].getItemdesc()!=null && !model[i].getItemdesc().trim().isEmpty()) {
  281. Map<String, Object> pm = new HashMap<>();
  282. pm.put("code", model[i].getItemid());
  283. pm.put("description", model[i].getItemdesc().trim());
  284. formulaService.updateDesBycode(pm);
  285. }
  286. logger.info("修改后数据是" + trmData.toString());
  287. }
  288. }
  289. catch(Exception e){
  290. failnum++;
  291. failmsgs.add(model[i].getId());
  292. logger.error("T_RM_ACT_ITEM表的数据修改出现错误,错误原因是" + e + ",id是" + model[i].getId());
  293. }
  294. }
  295. String wmsg = "";
  296. if(warnmsg.size()>0){
  297. wmsg = "(" + warnmsg.toString() + ")";
  298. }
  299. if(failnum > 0){
  300. logger.info("本次共修改" + model.length + "条数据,其中成功" + (model.length - failnum) + "条,失败" + failnum + "条");
  301. return success(failmsgs, "51","本次共修改" + model.length + "条数据,其中成功" + (model.length - failnum) + "条"+wmsg+",失败" + failnum + "条:" + failmsgs.toString());
  302. }
  303. if(warnmsg.size()>0){
  304. return success(null, wmsg);
  305. }else{
  306. return success();
  307. }
  308. }
  309. @ApiOperation(value = "批量删除",notes = "根据url传过来的id集合删除对象")
  310. @ApiImplicitParam(paramType = "path",name = "id",value = "ID",required = true,dataType = "String")
  311. @DeleteMapping("/batchDel")
  312. public RESTfulResult dels(@RequestBody TRmActItem[] model){
  313. int failnum = 0;
  314. ArrayList<String> failmsgs = new ArrayList<String>();
  315. String userId = JwtUtil.getUseridByToken();
  316. for(int i = 0;i < model.length;i++){
  317. try {
  318. logger.info("T_RM_ACT_ITEM表的数据发生了删除(操作人ID:" + userId + "):");
  319. logger.info("删除的数据是" + tRmActItemService.getById(model[i].getId()).toString());
  320. List<Formula> list = formulaService.getFormulaByCode(model[i].getId());
  321. if(list!=null && list.size()>0){
  322. String item="";
  323. for(Formula fa:list){
  324. item += "[" + fa.getClock() +"版本,项目编号"+ fa.getCode() + "],";
  325. }
  326. item = item.substring(0,item.length()-1);
  327. return failed(null, item + " 公式中包含计量点 " + model[i].getId() + ",请先处理");
  328. }
  329. Map<String, Object> params = new HashMap<String, Object>();
  330. params.put("itemid", model[i].getId());
  331. if (model[i].getId().endsWith("R")) {
  332. if(tRmActValueService.getCount(params) > 0){
  333. return failed(null, model[i].getId() + " 已有数据,请先处理");
  334. }
  335. // tRmActValueService.deleteByParams(params);
  336. } else if (model[i].getId().endsWith("B")) {
  337. if(tRmBalanceValueService.getCount(params) > 0){
  338. return failed(null, model[i].getId() + " 已有数据,请先处理");
  339. }
  340. // tRmBalanceValueService.deleteByParams(params);
  341. } else if (model[i].getId().endsWith("P")) {
  342. if(tRmPlanValueService.getCount(params) > 0){
  343. return failed(null, model[i].getId() + " 已有数据,请先处理");
  344. }
  345. // tRmPlanValueService.deleteByParams(params);
  346. } else if (model[i].getId().endsWith("W")) {
  347. if(tRmDwValueService.getCount(params) > 0){
  348. return failed(null, model[i].getId() + " 已有数据,请先处理");
  349. }
  350. // tRmDwValueService.deleteByParams(params);
  351. } else if (model[i].getId().endsWith("F")) {
  352. if(tRmDfValueService.getCount(params) > 0){
  353. return failed(null, model[i].getId() + " 已有数据,请先处理");
  354. }
  355. }
  356. tRmActItemService.delete(model[i].getId());
  357. formulaService.deleteBycode(model[i].getId());
  358. }
  359. catch(Exception e){
  360. failnum++;
  361. failmsgs.add(model[i].getId());
  362. logger.error("T_RM_ACT_ITEM表的数据删除时出现错误,错误原因是" + e + ",数据的id是" + model[i].getId());
  363. }
  364. }
  365. if(failnum > 0){
  366. logger.info("本次共准备删除" + model.length + "条数据,其中成功" + (model.length - failnum) + "条,失败" + failnum + "条");
  367. return success(failmsgs, "51","本次共准备删除" + model.length + "条数据,其中成功" + (model.length - failnum) + "条,失败" + failnum + "条,失败的数据id:" + failmsgs.toString());
  368. }
  369. return success();
  370. }
  371. @ApiOperation(value="删除", notes="根据url的id来指定删除对象")
  372. @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "String")
  373. //@RequiresPermissions("trmactitem:delete")
  374. @DeleteMapping(value = "/{id}")
  375. public RESTfulResult delete(@PathVariable String id){
  376. if (StringUtils.indexOf(id, ",") == -1) {
  377. tRmActItemService.delete(id);
  378. } else {
  379. tRmActItemService.delete(Arrays.asList(id.split(",")));
  380. }
  381. formulaService.deleteBycode(id);
  382. return success();
  383. }
  384. @ApiOperation(value = "查询 ITEMNAME 和 ITEMID")
  385. @GetMapping("/getIdAndName")
  386. public RESTfulResult getIdAndName(){
  387. List<TRmActItem> idAndName = tRmActItemService.getIdAndName("P");
  388. return success(idAndName);
  389. }
  390. @ApiOperation(value="批量新增", notes="根据TRmActItem对象创建")
  391. @ApiImplicitParam(name = "list<tRmActItem>", value = "详细实体tRmActItem集合", required = true, dataType = "List<tRmActItem>")
  392. @PostMapping(value = "/batchAdd")
  393. public RESTfulResult batchAdd(List<TRmActItem> models){
  394. for (TRmActItem item : models) {
  395. if(item.getItemid().isEmpty()) {
  396. return failed(null, "itemid不能为空");
  397. }
  398. }
  399. int re = tRmActItemService.batchAdd(models);
  400. return success();
  401. }
  402. @ApiOperation(value = "查询")
  403. @ApiImplicitParams({
  404. @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
  405. @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer")
  406. })
  407. @GetMapping("/getActitemDetaltsForPage")
  408. public RESTfulResult getActitemDetaltsForPage(@RequestParam HashMap<String,Object> parmas,Integer pageNum,Integer pageSize){
  409. if(parmas.get("workprocid") != null && !parmas.get("workprocid").toString().isEmpty()){
  410. String workprocid = parmas.get("workprocid").toString();
  411. if(!workprocid.startsWith("'")){
  412. workprocid = "'" + workprocid.replaceAll(",", "','").replaceAll(",", "','") + "'";
  413. }
  414. parmas.put("workprocid", workprocid);
  415. }
  416. if(parmas.get("energytypeid") != null && !parmas.get("energytypeid").toString().isEmpty()){
  417. String energytypeid = parmas.get("energytypeid").toString();
  418. if(!energytypeid.startsWith("'")){
  419. energytypeid = "'" + energytypeid.replaceAll(",", "','").replaceAll(",", "','") + "'";
  420. }
  421. parmas.put("energytypeid", energytypeid);
  422. }
  423. if(parmas.get("energyid") != null && !parmas.get("energyid").toString().isEmpty()){
  424. String energyid = parmas.get("energyid").toString();
  425. if(!energyid.startsWith("'")){
  426. energyid = "'" + energyid.replaceAll(",", "','").replaceAll(",", "','") + "'";
  427. }
  428. parmas.put("energyid", energyid);
  429. }
  430. if(parmas.get("propertyid") != null && !parmas.get("propertyid").toString().isEmpty()){
  431. String propertyid = parmas.get("propertyid").toString();
  432. if(!propertyid.startsWith("'")){
  433. propertyid = "'" + propertyid.replaceAll(",", "','").replaceAll(",", "','") + "'";
  434. }
  435. parmas.put("propertyid", propertyid);
  436. }
  437. if(parmas.get("itemid")!=null && !parmas.get("itemid").toString().isEmpty()) {
  438. String itemid = parmas.get("itemid").toString();
  439. if(!itemid.startsWith("'")) {
  440. itemid="'"+itemid.replaceAll(",", "','").replaceAll(",", ",")+"'";
  441. }
  442. parmas.put("itemid", itemid);
  443. }
  444. if(parmas.containsKey("startDate") && parmas.get("startDate") != null && !"".equals(parmas.get("startDate").toString()) &&
  445. parmas.containsKey("endDate") && parmas.get("endDate") != null && !"".equals(parmas.get("endDate").toString())){
  446. String begin = parmas.get("startDate").toString();
  447. String end = parmas.get("endDate").toString();
  448. parmas.put("clock", begin);
  449. parmas.put("clocke", end);
  450. }
  451. PageList<Map<String, Object>> actitemDetaltsForPage = tRmActItemService.getActitemDetaltsForPage(parmas, pageNum, pageSize);
  452. return success(actitemDetaltsForPage);
  453. }
  454. @ApiOperation(value = "查询计划项目维护结果区",notes = "计划项目数据维护页面")
  455. @ApiImplicitParams({
  456. @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
  457. @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer")
  458. })
  459. @GetMapping("/getPlanitemDetalts")
  460. public RESTfulResult getPlanitemDetalts(@RequestParam HashMap<String,Object> parmas,Integer pageNum,Integer pageSize){
  461. if(parmas.get("workprocid") != null && !parmas.get("workprocid").toString().isEmpty()){
  462. String workprocid = parmas.get("workprocid").toString();
  463. if(!workprocid.startsWith("'")){
  464. workprocid = "'" + workprocid.replaceAll(",", "','").replaceAll(",", "','") + "'";
  465. }
  466. parmas.put("workprocid", workprocid);
  467. }
  468. if(parmas.get("energyid") != null && !parmas.get("energyid").toString().isEmpty()){
  469. String energyid = parmas.get("energyid").toString();
  470. if(!energyid.startsWith("'")){
  471. energyid = "'" + energyid.replaceAll(",", "','").replaceAll(",", "','") + "'";
  472. }
  473. parmas.put("energyid", energyid);
  474. }
  475. if(parmas.get("propertyid") != null && !parmas.get("propertyid").toString().isEmpty()){
  476. String propertyid = parmas.get("propertyid").toString();
  477. if(!propertyid.startsWith("'")){
  478. propertyid = "'" + propertyid.replaceAll(",", "','").replaceAll(",", "','") + "'";
  479. }
  480. parmas.put("propertyid", propertyid);
  481. }
  482. PageList<Map<String, Object>> planitemDetalts = tRmActItemService.getPlanitemDetalts(parmas, pageNum, pageSize);
  483. return success(planitemDetalts);
  484. }
  485. @ApiOperation(value = "查询平衡数据")
  486. @ApiImplicitParams({
  487. @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
  488. @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer")
  489. })
  490. @GetMapping("/getBalanceData")
  491. public RESTfulResult getBalanceData(@RequestParam HashMap<String,Object> parmas,Integer pageNum,Integer pageSize){
  492. if(parmas.get("workprocid") != null && !parmas.get("workprocid").toString().isEmpty()){
  493. String workprocid = parmas.get("workprocid").toString();
  494. if(!workprocid.startsWith("'")){
  495. workprocid = "'" + workprocid.replaceAll(",", "','").replaceAll(",", "','") + "'";
  496. }
  497. parmas.put("workprocid", workprocid);
  498. }
  499. if(parmas.get("energyid") != null && !parmas.get("energyid").toString().isEmpty()){
  500. String energyid = parmas.get("energyid").toString();
  501. if(!energyid.startsWith("'")){
  502. energyid = "'" + energyid.replaceAll(",", "','").replaceAll(",", "','") + "'";
  503. }
  504. parmas.put("energyid", energyid);
  505. }
  506. if(parmas.get("propertyid") != null && !parmas.get("propertyid").toString().isEmpty()){
  507. String propertyid = parmas.get("propertyid").toString();
  508. if(!propertyid.startsWith("'")){
  509. propertyid = "'" + propertyid.replaceAll(",", "','").replaceAll(",", "','") + "'";
  510. }
  511. parmas.put("propertyid", propertyid);
  512. }
  513. if(parmas.containsKey("itemid") && parmas.get("itemid") != null && !"".equals(parmas.get("itemid").toString())){
  514. String itemid = parmas.get("itemid").toString();
  515. if(!itemid.startsWith("'")){
  516. itemid = "'" + itemid.replaceAll(",", "','").replaceAll(",", "','") + "'";
  517. }
  518. parmas.put("itemid", itemid);
  519. }
  520. if(parmas.containsKey("startDate") && parmas.get("startDate") != null && !"".equals(parmas.get("startDate").toString()) &&
  521. parmas.containsKey("endDate") && parmas.get("endDate") != null && !"".equals(parmas.get("endDate").toString())){
  522. String begin = parmas.get("startDate").toString();
  523. String end = parmas.get("endDate").toString();
  524. parmas.put("clock", begin);
  525. parmas.put("clocke", end);
  526. }
  527. PageList<Map<String, Object>> blist = tRmActItemService.getBalanceDataForPage(parmas, pageNum, pageSize);
  528. return success(blist);
  529. }
  530. @ApiOperation(value="重新计算生成项目数据")
  531. @GetMapping(value = "/reData")
  532. public RESTfulResult reData(@RequestParam HashMap<String, Object> parmas, String clock, String clocke, String timegranid, String itemtype){
  533. if (clock==null || clock.isEmpty()) {
  534. return failed(null, "请传入起始时间");
  535. }
  536. if (clocke==null || clocke.isEmpty()) {
  537. return failed(null, "请传入结束时间");
  538. }
  539. if (timegranid==null || timegranid.isEmpty()) {
  540. return failed(null, "请传入时间粒度");
  541. }
  542. if (itemtype==null || itemtype.isEmpty()) {
  543. return failed(null, "请传入项目类型");
  544. }
  545. if(parmas.get("workprocid") != null && !parmas.get("workprocid").toString().isEmpty()){
  546. String workprocid = parmas.get("workprocid").toString();
  547. if(!workprocid.startsWith("'")){
  548. workprocid = "'" + workprocid.replaceAll(",", "','").replaceAll(",", "','") + "'";
  549. }
  550. parmas.put("workprocid", workprocid);
  551. }
  552. if(parmas.get("energyid") != null && !parmas.get("energyid").toString().isEmpty()){
  553. String energyid = parmas.get("energyid").toString();
  554. if(!energyid.startsWith("'")){
  555. energyid = "'" + energyid.replaceAll(",", "','").replaceAll(",", "','") + "'";
  556. }
  557. parmas.put("energyid", energyid);
  558. }
  559. if(parmas.get("propertyid") != null && !parmas.get("propertyid").toString().isEmpty()){
  560. String propertyid = parmas.get("propertyid").toString();
  561. if(!propertyid.startsWith("'")){
  562. propertyid = "'" + propertyid.replaceAll(",", "','").replaceAll(",", "','") + "'";
  563. }
  564. parmas.put("propertyid", propertyid);
  565. }
  566. if(parmas.containsKey("itemid") && parmas.get("itemid") != null && !"".equals(parmas.get("itemid").toString())){
  567. String itemid = parmas.get("itemid").toString();
  568. if(!itemid.startsWith("'")){
  569. itemid = "'" + itemid.replaceAll(",", "','").replaceAll(",", "','") + "'";
  570. }
  571. parmas.put("itemid", itemid);
  572. }
  573. String res = "";
  574. parmas.put("itemtype", itemtype);
  575. parmas.put("useflag", "1");
  576. // 查询需要统计的项目信息
  577. List<TRmActItem> l = tRmActItemMapper.selectActr(parmas);
  578. int size = l.size();
  579. for(int i = 0; i<l.size(); i++){
  580. if(res.isEmpty()){
  581. res = formulaService.reItemVal(l.get(i).getItemid(),clock,timegranid,clocke);
  582. }else{
  583. formulaService.reItemVal(l.get(i).getItemid(),clock,timegranid,clocke);
  584. }
  585. logger.info("剩下要处理的项目数:" + (size-1-i) + "(" + size + ")");
  586. }
  587. if(!res.isEmpty()){
  588. return success(null, res);
  589. }
  590. return success();
  591. }
  592. @ApiOperation(value="获取上报项目列表", notes="分页模糊查询")
  593. @ApiImplicitParams({
  594. @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
  595. @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer")
  596. })
  597. //@RequiresPermissions("trmactitem:view")
  598. @GetMapping(value = "/likew/")
  599. public RESTfulResult listLikew(@RequestParam HashMap<String, Object> parmas,Integer pageNum, Integer pageSize){
  600. if(parmas.containsKey("energyid") && parmas.get("energyid") != null && !"".equals(parmas.get("energyid").toString())){
  601. String energyid = parmas.get("energyid").toString();
  602. if(energyid.indexOf(",") == -1){
  603. parmas.put("energyid", "and t.energyid = '" + energyid + "'");
  604. } else {
  605. energyid = "and t.energyid in ('" + energyid.replaceAll(",", "','") + "')";
  606. parmas.put("energyid", energyid);
  607. }
  608. }
  609. if(parmas.containsKey("workprocid") && parmas.get("workprocid") != null && !"".equals(parmas.get("workprocid").toString())){
  610. String workprocid = parmas.get("workprocid").toString();
  611. if(workprocid.indexOf(",") == -1){
  612. parmas.put("workprocid", "and t.workprocid = '" + workprocid + "'");
  613. } else {
  614. workprocid = "and t.workprocid in ('" + workprocid.replaceAll(",", "','") + "')";
  615. parmas.put("workprocid", workprocid);
  616. }
  617. }
  618. if(parmas.containsKey("propertyid") && parmas.get("propertyid") != null && !"".equals(parmas.get("propertyid").toString())){
  619. String propertyid = parmas.get("propertyid").toString();
  620. if(propertyid.indexOf(",") == -1){
  621. parmas.put("propertyid", "and t.propertyid = '" + propertyid + "'");
  622. } else {
  623. propertyid = "and t.propertyid in ('" + propertyid.replaceAll(",", "','") + "')";
  624. parmas.put("propertyid", propertyid);
  625. }
  626. }
  627. if(parmas.get("itemid") != null && !parmas.get("itemid").toString().isEmpty()){
  628. String itemid = parmas.get("itemid").toString();
  629. if(!itemid.startsWith("'")){
  630. itemid = "'" + itemid.replaceAll(",", "','").replaceAll(",", "','") + "'";
  631. }
  632. parmas.put("itemid", itemid);
  633. }
  634. PageList<TRmActItem> list = tRmActItemService.queryLikewForPage(parmas, pageNum, pageSize);
  635. return success(list);
  636. }
  637. @ApiOperation(value="获取财务项目列表", notes="分页模糊查询")
  638. @ApiImplicitParams({
  639. @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
  640. @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer")
  641. })
  642. //@RequiresPermissions("trmactitem:view")
  643. @GetMapping(value = "/likef/")
  644. public RESTfulResult listLikef(@RequestParam HashMap<String, Object> parmas,Integer pageNum, Integer pageSize){
  645. if(parmas.containsKey("energyid") && parmas.get("energyid") != null && !"".equals(parmas.get("energyid").toString())){
  646. String energyid = parmas.get("energyid").toString();
  647. if(energyid.indexOf(",") == -1){
  648. parmas.put("energyid", "and t.energyid = '" + energyid + "'");
  649. } else {
  650. energyid = "and t.energyid in ('" + energyid.replaceAll(",", "','") + "')";
  651. parmas.put("energyid", energyid);
  652. }
  653. }
  654. if(parmas.containsKey("workprocid") && parmas.get("workprocid") != null && !"".equals(parmas.get("workprocid").toString())){
  655. String workprocid = parmas.get("workprocid").toString();
  656. if(workprocid.indexOf(",") == -1){
  657. parmas.put("workprocid", "and t.workprocid = '" + workprocid + "'");
  658. } else {
  659. workprocid = "and t.workprocid in ('" + workprocid.replaceAll(",", "','") + "')";
  660. parmas.put("workprocid", workprocid);
  661. }
  662. }
  663. if(parmas.containsKey("propertyid") && parmas.get("propertyid") != null && !"".equals(parmas.get("propertyid").toString())){
  664. String propertyid = parmas.get("propertyid").toString();
  665. if(propertyid.indexOf(",") == -1){
  666. parmas.put("propertyid", "and t.propertyid = '" + propertyid + "'");
  667. } else {
  668. propertyid = "and t.propertyid in ('" + propertyid.replaceAll(",", "','") + "')";
  669. parmas.put("propertyid", propertyid);
  670. }
  671. }
  672. if(parmas.get("itemid") != null && !parmas.get("itemid").toString().isEmpty()){
  673. String itemid = parmas.get("itemid").toString();
  674. if(!itemid.startsWith("'")){
  675. itemid = "'" + itemid.replaceAll(",", "','").replaceAll(",", "','") + "'";
  676. }
  677. parmas.put("itemid", itemid);
  678. }
  679. PageList<TRmActItem> list = tRmActItemService.queryLikefForPage(parmas, pageNum, pageSize);
  680. return success(list);
  681. }
  682. @ApiOperation(value="获取上报产量确认数据", notes="分页模糊查询")
  683. @ApiImplicitParams({
  684. @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
  685. @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer")
  686. })
  687. //@RequiresPermissions("trmactitem:view")
  688. @GetMapping(value = "/listpv/")
  689. public RESTfulResult listpv(@RequestParam HashMap<String, Object> parmas,String clock, String clocke,Integer pageNum, Integer pageSize){
  690. if(!parmas.containsKey("clock") || parmas.get("clock").toString().isEmpty()){
  691. return failed(null, "请传入起始时间");
  692. }
  693. if(!parmas.containsKey("clocke") || parmas.get("clocke").toString().isEmpty()){
  694. return failed(null, "请传入结束时间");
  695. }
  696. if(parmas.get("workprocid")!=null && !parmas.get("workprocid").toString().isEmpty()){
  697. String workprocid = parmas.get("workprocid").toString();
  698. if(!workprocid.startsWith("'")){
  699. workprocid = "'" + workprocid.replaceAll(",", "','").replaceAll(",", "','") + "'";
  700. }
  701. parmas.put("workprocid", workprocid);
  702. }
  703. List<Map<String, Object>> its = tRmActItemService.getProItems();
  704. Map<String, Object> mp = new HashMap<String, Object>();
  705. String cpid = "";
  706. for(Map<String, Object> m:its){
  707. String itemid = m.get("ITEMID").toString();
  708. mp.put(itemid, m.get("RATE")==null?"":m.get("RATE").toString());
  709. cpid += "'" + itemid + "',";
  710. }
  711. if(!cpid.isEmpty()){
  712. cpid = cpid.substring(0,cpid.length()-1);
  713. parmas.put("cpid", cpid);
  714. List<Map<String, Object>> re = tRmActItemService.listpv(parmas);
  715. for(Map<String, Object> m:re){
  716. String itemid = m.get("ITEMID").toString();
  717. String ck = m.get("CLOCK").toString();
  718. if(mp.containsKey(itemid) && !mp.get(itemid).toString().isEmpty()){
  719. String js = m.get("APPORTVALUE").toString() + mp.get(itemid).toString();
  720. ScriptEngineManager manager = new ScriptEngineManager();
  721. ScriptEngine engine = manager.getEngineByName("JavaScript");
  722. String apv = "";
  723. try {
  724. Object result = engine.eval(js);
  725. apv = new BigDecimal(result.toString()).setScale(0, BigDecimal.ROUND_HALF_UP).toPlainString();
  726. } catch (Exception e) {
  727. logger.error("计算错误:" + js + ",itemid:" + itemid + ",clock:" + ck);
  728. apv = "0";
  729. }
  730. m.put("APPORTVALUE", apv);
  731. }
  732. }
  733. return success(re);
  734. }else{
  735. return success();
  736. }
  737. }
  738. }