TRmCalpointController.java 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. package com.steerinfo.ems.trmcalpoint.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.trmcalpoint.model.TRmCalpoint;
  7. import com.steerinfo.ems.trmcalpoint.service.ITRmCalpointService;
  8. import com.steerinfo.ems.trmelectricitylocation.mapper.TRmElectricityLocationMapper;
  9. import com.steerinfo.ems.trmelectricitylocation.model.TRmElectricityLocation;
  10. import com.steerinfo.ems.trmenergy.model.TRmEnergy;
  11. import com.steerinfo.ems.trmenergy.service.ITRmEnergyService;
  12. import com.steerinfo.ems.trmenergyproperty.model.TRmEnergyProperty;
  13. import com.steerinfo.ems.trmenergyproperty.service.ITRmEnergyPropertyService;
  14. import com.steerinfo.ems.trmlocation.model.TRmLocation;
  15. import com.steerinfo.ems.trmlocation.service.ITRmLocationService;
  16. import com.steerinfo.ems.trmstation.model.TRmStation;
  17. import com.steerinfo.ems.trmstation.service.ITRmStationService;
  18. import com.steerinfo.framework.controller.BaseRESTfulController;
  19. import com.steerinfo.framework.controller.RESTfulResult;
  20. import com.steerinfo.framework.service.pagehelper.PageList;
  21. import io.swagger.annotations.ApiImplicitParam;
  22. import io.swagger.annotations.ApiImplicitParams;
  23. import io.swagger.annotations.ApiOperation;
  24. import org.slf4j.Logger;
  25. import org.slf4j.LoggerFactory;
  26. import org.springframework.beans.factory.annotation.Autowired;
  27. import org.springframework.web.bind.annotation.*;
  28. import java.util.Date;
  29. import java.util.HashMap;
  30. import java.util.List;
  31. import java.util.Map;
  32. /**
  33. * TRmCalpoint RESTful接口:
  34. * @author 王金涛
  35. * @version 1.0-SNAPSHORT 2019-10-11
  36. * 类描述
  37. * 修订历史:
  38. * 日期:2019-10-11
  39. * 作者:王金涛
  40. * 参考:
  41. * 描述:TRmCalpoint RESTful接口
  42. * @see null
  43. * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved.
  44. */
  45. @RestController
  46. @RequestMapping("/${api.version}/trmcalpoints")
  47. public class TRmCalpointController extends BaseRESTfulController {
  48. private static final Logger LOGGER = LoggerFactory.getLogger(TRmCalpointController.class);
  49. @Autowired
  50. ITRmCalpointService tRmCalpointService;
  51. @Autowired
  52. ITRmEnergyService tRmEnergyService;
  53. @Autowired
  54. ITRmLocationService tRmLocationService;
  55. @Autowired
  56. ITRmEnergyPropertyService tRmEnergyPropertyService;
  57. @Autowired
  58. IFormulaService formulaService;
  59. @Autowired
  60. ITRmStationService tRmStationService;
  61. @Autowired
  62. private TRmElectricityLocationMapper tRmElectricityLocationMapper;
  63. @ApiOperation(value="获取列表", notes="分页查询")
  64. @ApiImplicitParams({
  65. @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
  66. @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer")
  67. })
  68. //@RequiresPermissions("trmcalpoint:view")
  69. @GetMapping(value = "/")
  70. public RESTfulResult list(@RequestParam HashMap parmas,Integer pageNum, Integer pageSize){
  71. PageList<TRmCalpoint> list = tRmCalpointService.queryForPage(parmas, pageNum, pageSize);
  72. return success(list);
  73. }
  74. @ApiOperation(value="获取列表", notes="分页模糊查询")
  75. @ApiImplicitParams({
  76. @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
  77. @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer")
  78. })
  79. //@RequiresPermissions("trmcalpoint:view")
  80. @GetMapping(value = "/like/")
  81. public RESTfulResult listLike(@RequestParam HashMap parmas,Integer pageNum, Integer pageSize){
  82. if(parmas.get("locateid") != null && !parmas.get("locateid").toString().isEmpty()){
  83. String locateid = parmas.get("locateid").toString();
  84. if(!locateid.startsWith("'")){
  85. locateid = "'" + locateid.replaceAll(",", "','").replaceAll(",", "','") + "'";
  86. }
  87. parmas.put("locateid", locateid);
  88. }
  89. if(parmas.get("itemid") != null && !parmas.get("itemid").toString().isEmpty()){
  90. String itemid = parmas.get("itemid").toString();
  91. if(!itemid.startsWith("'")){
  92. itemid = "'" + itemid.replaceAll(",", "','").replaceAll(",", "','") + "'";
  93. }
  94. parmas.put("itemid", itemid);
  95. }
  96. if(parmas.get("networkid") != null && !parmas.get("networkid").toString().isEmpty()){
  97. String networkid = parmas.get("networkid").toString();
  98. if(!networkid.startsWith("'")){
  99. networkid = "'" + networkid.replaceAll(",", "','").replaceAll(",", "','") + "'";
  100. }
  101. parmas.put("networkid", networkid);
  102. }
  103. if(parmas.get("energytypeid") != null && !parmas.get("energytypeid").toString().isEmpty()){
  104. String energytypeid = parmas.get("energytypeid").toString();
  105. if(!energytypeid.startsWith("'")){
  106. energytypeid = "'" + energytypeid.replaceAll(",", "','").replaceAll(",", "','") + "'";
  107. }
  108. parmas.put("energytypeid", energytypeid);
  109. }
  110. if(parmas.get("energyid") != null && !parmas.get("energyid").toString().isEmpty()){
  111. String energyid = parmas.get("energyid").toString();
  112. if(!energyid.startsWith("'")){
  113. energyid = "'" + energyid.replaceAll(",", "','").replaceAll(",", "','") + "'";
  114. }
  115. parmas.put("energyid", energyid);
  116. }
  117. if(parmas.get("propertyid") != null && !parmas.get("propertyid").toString().isEmpty()){
  118. String propertyid = parmas.get("propertyid").toString();
  119. if(!propertyid.startsWith("'")){
  120. propertyid = "'" + propertyid.replaceAll(",", "','").replaceAll(",", "','") + "'";
  121. }
  122. parmas.put("propertyid", propertyid);
  123. }
  124. PageList<TRmCalpoint> list = tRmCalpointService.queryLikeForPage(parmas, pageNum, pageSize);
  125. return success(list);
  126. }
  127. @ApiOperation(value="创建", notes="根据TRmCalpoint对象创建")
  128. @ApiImplicitParam(name = "tRmCalpoint", value = "详细实体tRmCalpoint", required = true, dataType = "TRmCalpoint")
  129. //@RequiresPermissions("trmcalpoint:create")
  130. @PostMapping(value = "/")
  131. public RESTfulResult add(@ModelAttribute TRmCalpoint model){
  132. if(model.getEnergytypeid() == null || "".equals(model.getEnergytypeid())){
  133. return failed(null, "能介类型不能为空");
  134. }else if(model.getEnergyid() == null || "".equals(model.getEnergyid())){
  135. return failed(null, "能介信息不能为空");
  136. }else if(model.getPropertyid() == null || "".equals(model.getPropertyid())){
  137. return failed(null, "能介属性不能为空");
  138. }else if (model.getItemtype() == null || "".equals(model.getItemtype())) {
  139. return failed(null, "手抄或者自动不能为空");
  140. }else if (model.getLocateid() == null || "".equals(model.getLocateid())) {
  141. return failed(null, "位置不能为空");
  142. }
  143. if(model.getEnergytypeid().equalsIgnoreCase("E") && (model.getNetworkid() == null || "".equals(model.getNetworkid()))){
  144. return failed(null, "能介电的计量点站所不能为空");
  145. }
  146. TRmEnergy tRmEnergy = tRmEnergyService.getById(model.getEnergyid());
  147. TRmEnergyProperty tRmEnergyProperty = tRmEnergyPropertyService.getById(model.getPropertyid());
  148. TRmLocation tRmLocation = tRmLocationService.getById(model.getLocateid());
  149. int maxid = 0;
  150. if(model.getEnergytypeid().equalsIgnoreCase("E")){
  151. if(model.getItemname()==null || model.getItemname().isEmpty()){
  152. TRmStation tRmStation = tRmStationService.getById(model.getNetworkid());
  153. model.setItemname(tRmStation.getName() + tRmEnergy.getName() + tRmEnergyProperty.getName());
  154. }
  155. String mid = tRmCalpointService.getMaxId(model.getNetworkid() + model.getEnergyid() + model.getPropertyid());
  156. maxid = mid == null ? 0 : Integer.parseInt(mid);
  157. String ls = (maxid + 1) < 1000 ? String.format("%04d", maxid + 1) : (maxid + 1) + "";
  158. model.setItemid(model.getNetworkid() + model.getEnergyid() + model.getPropertyid() + ls);
  159. }else{
  160. if(model.getItemname()==null || model.getItemname().isEmpty()){
  161. model.setItemname(tRmLocation.getName() + tRmEnergy.getName() + tRmEnergyProperty.getName());
  162. }
  163. String mid = tRmCalpointService.getMaxId(model.getLocateid() + model.getEnergyid() + model.getPropertyid());
  164. maxid = mid == null ? 0 : Integer.parseInt(mid);
  165. String ls = (maxid + 1) < 1000 ? String.format("%04d", maxid + 1) : (maxid + 1) + "";
  166. model.setItemid(model.getLocateid() + model.getEnergyid() + model.getPropertyid() + ls);
  167. }
  168. if(model.getTagAlias() == null || "".equals(model.getTagAlias())) {
  169. model.setTagAlias(tRmLocation.getName() + tRmEnergy.getName() + tRmEnergyProperty.getName());
  170. }
  171. if(model.getRecTime() == null || "".equals(model.getRecTime())){
  172. model.setRecTime(DateUtils.getCurrentTime("yyyy-MM-dd HH:mm:ss"));
  173. }
  174. model.setRecman(JwtUtil.getUseridByToken());
  175. TRmCalpoint tRmCalpoint = tRmCalpointService.add(model);
  176. Formula formula = new Formula();
  177. formula.setCode(model.getItemid());
  178. String itemdesc = model.getItemdesc(); // 项目描述
  179. formula.setDescription(itemdesc!=null && !itemdesc.trim().isEmpty() ? itemdesc : model.getTagAlias());
  180. // formula.setClock(DateUtils.getCurrentTime("yyyyMM"));
  181. formula.setClock("202001");
  182. formula.setIsavailable("1");
  183. formula.setRevisetime(DateUtils.getCurrentTime("yyyy-MM-dd HH:mm:ss"));
  184. formula.setTablename("T_RM_CALPOINT_VALUE");
  185. formula.setSourcecode("R(T_RM_CALPOINT_VALUE," + model.getItemid() + ")");
  186. formula.setRevisor(JwtUtil.getUseridByToken());
  187. formulaService.add(formula);
  188. return success(tRmCalpoint);
  189. }
  190. @ApiOperation(value="获取详细信息", notes="根据url的id来获取详细信息")
  191. @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "String")
  192. //@RequiresPermissions("trmcalpoint:view")
  193. @GetMapping(value = "/{id}")
  194. public RESTfulResult get(@PathVariable String id){
  195. TRmCalpoint tRmCalpoint = tRmCalpointService.getById(id);
  196. return success(tRmCalpoint);
  197. }
  198. @ApiOperation(value="更新详细信息", notes="根据url的id来指定更新对象,并根据传过来的tRmCalpoint信息来更新详细信息")
  199. @ApiImplicitParams({
  200. @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "String"),
  201. @ApiImplicitParam(name = "tRmCalpoint", value = "详细实体tRmCalpoint", required = true, dataType = "TRmCalpoint")
  202. })
  203. //@RequiresPermissions("trmcalpoint:update")
  204. @PutMapping(value = "/{id}", produces = "application/json;charset=UTF-8")
  205. public RESTfulResult update(@PathVariable String id, @RequestBody TRmCalpoint model){
  206. if(model.getEnergytypeid() == null || "".equals(model.getEnergytypeid())){
  207. return failed(null, "能介类型不能为空");
  208. }
  209. if(model.getEnergyid() == null || "".equals(model.getEnergyid())){
  210. return failed(null, "能介信息不能为空");
  211. }
  212. if(model.getPropertyid() == null || "".equals(model.getPropertyid())){
  213. return failed(null, "能介属性不能为空");
  214. }
  215. if (model.getItemtype() == null || "".equals(model.getItemtype())) {
  216. return failed(null, "手抄或者自动不能为空");
  217. }
  218. if (model.getLocateid() == null || "".equals(model.getLocateid())) {
  219. return failed(null, "位置不能为空");
  220. }
  221. if (model.getMintimegranid() == null || "".equals(model.getMintimegranid())) {
  222. return failed(null, "最小时间粒度不能为空");
  223. }
  224. if(model.getEnergytypeid().equalsIgnoreCase("E") && (model.getNetworkid() == null || "".equals(model.getNetworkid()))){
  225. return failed(null, "能介电的计量点站所不能为空");
  226. }
  227. TRmElectricityLocation tl = tRmElectricityLocationMapper.getByItemid(model.getItemid());
  228. if (tl!=null) {
  229. if(!model.getEnergyid().equalsIgnoreCase("E001")){
  230. return failed(null, "转供电计量点能介为电正向有功");
  231. }
  232. if(!model.getItemtype().equalsIgnoreCase("MANUAL")){
  233. return failed(null, "转供电计量点为手动");
  234. }
  235. if(!model.getUnitid().equalsIgnoreCase("006")){
  236. return failed(null, "转供电计量点单位为千瓦时");
  237. }
  238. }
  239. model.setItemid(id);
  240. model.setUpdateman(JwtUtil.getUseridByToken());
  241. model.setUpdatetime(new Date());
  242. List<Formula> formulaList = formulaService.getAssociatedFormula(id);
  243. if("0".equals(model.getUseflag()) && formulaList != null && formulaList.size() > 0){
  244. String ids = "";
  245. for (Formula forms : formulaList){
  246. ids += forms.getCode() + ",";
  247. }
  248. return failed(null, "该计量点被" + formulaList.size() + "条公式所使用,公式名:" + ids);
  249. }
  250. Map<String, Object> formulaparam = new HashMap<>();
  251. formulaparam.put("clock", DateUtils.getCurrentTime("yyyyMM"));
  252. formulaparam.put("code", model.getItemid());
  253. formulaparam.put("tablename", "T_RM_CALPOINT_VALUE");
  254. Formula newestformula = formulaService.getByParams(formulaparam);
  255. TRmCalpoint old = tRmCalpointService.getById(model.getItemid());
  256. if("1".equals(model.getUseflag()) && formulaService.checkFormula(newestformula) !=""){
  257. return failed(null, "公式不合法,无法启用,不合法原因是" + formulaService.checkFormula(newestformula));
  258. }
  259. // 修改最小时间粒度
  260. String msg = "";
  261. if("1".equals(model.getUseflag()) && !old.getMintimegranid().equalsIgnoreCase(model.getMintimegranid())){
  262. msg = formulaService.checkFormulaMint(newestformula, model.getMintimegranid());
  263. }
  264. TRmLocation tRmLocation = tRmLocationService.getById(model.getLocateid());
  265. TRmEnergy tRmEnergy = tRmEnergyService.getById(model.getEnergyid());
  266. TRmEnergyProperty tRmEnergyProperty = tRmEnergyPropertyService.getById(model.getPropertyid());
  267. if(model.getEnergytypeid().equalsIgnoreCase("E") && (model.getItemname()==null || model.getItemname().isEmpty())){
  268. TRmStation tRmStation = tRmStationService.getById(model.getNetworkid());
  269. model.setItemname(tRmStation.getName() + tRmEnergy.getName() + tRmEnergyProperty.getName());
  270. }else if(model.getItemname() == null || model.getItemname().isEmpty()){
  271. model.setItemname(tRmLocation.getName() + tRmEnergy.getName() + tRmEnergyProperty.getName());
  272. }
  273. if(model.getTagAlias()==null || model.getTagAlias().isEmpty()){
  274. model.setTagAlias(model.getItemname());
  275. }
  276. if(tl!=null){
  277. tl.setBcode(model.getTagid()); // 电度表编号
  278. tl.setItemname(model.getItemname());
  279. tl.setLocation(model.getLocateid());
  280. tl.setWorkshop(model.getNetworkid()); // 站所
  281. tl.setMods(model.getTagModulus().intValue());
  282. tl.setWorkprocid(model.getCostid());
  283. tl.setUpdateman(JwtUtil.getUseridByToken());
  284. tl.setUpdatetime(new Date());
  285. tRmElectricityLocationMapper.updateByPrimaryKeySelective(tl);
  286. }
  287. LOGGER.info("计量点维护表修改前数据是" + old.toString());
  288. TRmCalpoint tRmCalpoint = tRmCalpointService.modify(model);
  289. LOGGER.info("计量点维护表修改后数据是" + tRmCalpoint.toString());
  290. // 修改公式描述和是否启用(计量点公式描述为计量点别名)
  291. Map<String, Object> pm = new HashMap<>();
  292. pm.put("code", model.getItemid());
  293. String itemdesc = model.getItemdesc(); // 项目描述
  294. pm.put("description", itemdesc!=null && !itemdesc.trim().isEmpty() ? itemdesc : model.getTagAlias());
  295. pm.put("isavailable", model.getUseflag());
  296. formulaService.updateDesBycode(pm);
  297. if(!msg.isEmpty()){
  298. return success(null, msg);
  299. }else{
  300. return success();
  301. }
  302. }
  303. @ApiOperation(value="删除", notes="根据url的id来指定删除对象")
  304. @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "String")
  305. //@RequiresPermissions("trmcalpoint:delete")
  306. @DeleteMapping(value = "/{id}")
  307. public RESTfulResult delete(@PathVariable String id){
  308. String[] ids = id.split(",");
  309. for (int i = 0; i < ids.length; i++) {
  310. List<Formula> list = formulaService.getFormulaByCode(ids[i]);
  311. if(list!=null && list.size()>0){
  312. String item="";
  313. for(Formula fa:list){
  314. item += "[" + fa.getClock() +"版本,项目编号"+ fa.getCode() + "],";
  315. }
  316. item = item.substring(0,item.length()-1);
  317. return failed(null, item + " 公式中包含计量点 " + ids[i] + ",请先处理");
  318. }
  319. }
  320. if(ids.length >= 1){
  321. tRmCalpointService.delCalpoint(ids);
  322. return success();
  323. }else{
  324. return failed(null, "请输入要删除的计量点编号");
  325. }
  326. }
  327. @ApiOperation(value="获得计量层级列表", notes="能源调度管理-计量点数据管理-计量点数据录入页面,计量层级下拉框数据")
  328. @GetMapping(value = "/getRmCalpoint")
  329. public RESTfulResult getTimegran(){
  330. List<Map> list = tRmCalpointService.getRmCalpoint();
  331. return success(list);
  332. }
  333. @ApiOperation(value="获得计量点数据", notes="能源调度管理-计量点数据管理-准点数据查询")
  334. @ApiImplicitParams({
  335. @ApiImplicitParam(name = "clock", value = "开始时间", required = false, dataType = "String"),
  336. @ApiImplicitParam(name = "clocke", value = "每结束时间", required = false, dataType = "String"),
  337. @ApiImplicitParam(name = "itemid", value = "计量点,多个以,隔开", required = false, dataType = "String"),
  338. @ApiImplicitParam(name = "datatype", value = "数据类型,sum:累计值,ontime:准点值", required = false, dataType = "String")
  339. })
  340. @GetMapping(value = "/getRmCalpointVal")
  341. public RESTfulResult getRmCalpointVal(String clock,String clocke,String itemid,String datatype){
  342. if(clock == null || clock.isEmpty()){
  343. return failed(null, "请传入开始时间");
  344. }
  345. if(clocke == null || clocke.isEmpty()){
  346. return failed(null, "请传入结束时间");
  347. }
  348. if(itemid == null || itemid.isEmpty()){
  349. return failed(null, "请传入计量点编号");
  350. }
  351. if(datatype == null || datatype.isEmpty()){
  352. return failed(null, "请传入数据类型");
  353. }
  354. String[] ids = itemid.split(",");
  355. String failmsg = "";
  356. String failmsg2 = "";
  357. for(int i=0; i<ids.length; i++){
  358. String id = ids[i];
  359. TRmCalpoint tRmCalpoint = tRmCalpointService.getById(id);
  360. if(tRmCalpoint == null){
  361. return failed(null, "计量点" + id + "不存在");
  362. }
  363. String itemname = tRmCalpoint.getItemname();
  364. String tagTable = tRmCalpoint.getTagTable()==null? "" :tRmCalpoint.getTagTable().trim(); // 小时表
  365. String tagCol = tRmCalpoint.getTagCol()==null? "" :tRmCalpoint.getTagCol().trim(); // 小时表字段
  366. String itemtype = tRmCalpoint.getItemtype();
  367. if (!itemtype.equalsIgnoreCase("AUTO")){
  368. failmsg += itemname + ",";
  369. } else if(tagTable.isEmpty() || tagCol.isEmpty()){
  370. failmsg2 += itemname + ",";
  371. }
  372. }
  373. if(!failmsg.isEmpty() || !failmsg2.isEmpty()){
  374. failmsg = "计量点:";
  375. if(!failmsg.isEmpty()){
  376. failmsg = "(" + failmsg.substring(0, failmsg.length()-1) + ")不是自动采集模式,没有准点值; ";
  377. }
  378. if(!failmsg2.isEmpty()){
  379. failmsg = "(" + failmsg2.substring(0, failmsg2.length()-1) + ")没有配置准点数据表或数据列;";
  380. }
  381. return failed(null, failmsg);
  382. }
  383. List<Map<String, Object>> list = tRmCalpointService.getRmCalpointVal(clock,clocke,itemid,datatype);
  384. return success(list);
  385. }
  386. //十分钟
  387. @GetMapping(value = "/getRmCalpointValTim")
  388. public RESTfulResult getRmCalpointValTim(String clock,String clocke,String itemid,String datatype){
  389. if(clock == null || clock.isEmpty()){
  390. return failed(null, "请传入开始时间");
  391. }
  392. if(clocke == null || clocke.isEmpty()){
  393. return failed(null, "请传入结束时间");
  394. }
  395. if(itemid == null || itemid.isEmpty()){
  396. return failed(null, "请传入计量点编号");
  397. }
  398. if(datatype == null || datatype.isEmpty()){
  399. return failed(null, "请传入数据类型");
  400. }
  401. String[] ids = itemid.split(",");
  402. String failmsg = "";
  403. String failmsg2 = "";
  404. for(int i=0; i<ids.length; i++){
  405. String id = ids[i];
  406. TRmCalpoint tRmCalpoint = tRmCalpointService.getById(id);
  407. if(tRmCalpoint == null){
  408. return failed(null, "计量点" + id + "不存在");
  409. }
  410. String itemname = tRmCalpoint.getItemname();
  411. String tagTable = tRmCalpoint.getBtype2()==null? "" :tRmCalpoint.getBtype2().trim(); // 备用描述2
  412. String[] tens = tagTable.split("\\.");
  413. if(tens.length!=2){
  414. return failed("十分钟表字段配置错误");
  415. }
  416. String tenTab = tens[0]; // 十分钟表
  417. String tenCol = tens[1]; // 十分钟字段
  418. String itemtype = tRmCalpoint.getItemtype();
  419. if (!itemtype.equalsIgnoreCase("AUTO")){
  420. failmsg += itemname + ",";
  421. } else if(tenTab.isEmpty() || tenCol.isEmpty()){
  422. failmsg2 += itemname + ",";
  423. }
  424. }
  425. if(!failmsg.isEmpty() || !failmsg2.isEmpty()){
  426. failmsg = "计量点:";
  427. if(!failmsg.isEmpty()){
  428. failmsg = "(" + failmsg.substring(0, failmsg.length()-1) + ")不是自动采集模式,没有准点值; ";
  429. }
  430. if(!failmsg2.isEmpty()){
  431. failmsg = "(" + failmsg2.substring(0, failmsg2.length()-1) + ")没有配置准点数据表或数据列;";
  432. }
  433. return failed(null, failmsg);
  434. }
  435. List<Map<String, Object>> list = tRmCalpointService.getRmCalpointValTim(clock,clocke,itemid,datatype);
  436. return success(list);
  437. }
  438. @ApiOperation(value="能源调度管理-计量点数据管理-计量点数据录入列表", notes="分页查询")
  439. @ApiImplicitParams({
  440. @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
  441. @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer")
  442. })
  443. @GetMapping(value = "/getDate312ForPage")
  444. public RESTfulResult getDate312ForPage(@RequestParam HashMap<String, Object> parmas,Integer pageNum, Integer pageSize){
  445. if(parmas.containsKey("locateid") && parmas.get("locateid") != null && !"".equals(parmas.get("locateid").toString())){
  446. String locateid = parmas.get("locateid").toString();
  447. if(locateid.indexOf(",") == -1){
  448. parmas.put("locateid", "and locateid = '" + locateid + "'");
  449. } else {
  450. locateid = "and locateid in ('" + locateid.replaceAll(",", "','") + "')";
  451. parmas.put("locateid", locateid);
  452. }
  453. }
  454. if(parmas.containsKey("propertyid") && parmas.get("propertyid") != null && !"".equals(parmas.get("propertyid").toString())){
  455. String propertyid = parmas.get("propertyid").toString();
  456. if(propertyid.indexOf(",") == -1){
  457. parmas.put("propertyid", "and propertyid = '" + propertyid + "'");
  458. } else {
  459. propertyid = "and propertyid in ('" + propertyid.replaceAll(",", "','") + "')";
  460. parmas.put("propertyid", propertyid);
  461. }
  462. }
  463. if(parmas.containsKey("energytypeid") && parmas.get("energytypeid") != null && !"".equals(parmas.get("energytypeid").toString())){
  464. String energytypeid = parmas.get("energytypeid").toString();
  465. if(energytypeid.indexOf(",") == -1){
  466. parmas.put("energytypeid", "and t.energytypeid = '" + energytypeid + "'");
  467. } else {
  468. energytypeid = "and t.energytypeid in ('" + energytypeid.replaceAll(",", "','") + "')";
  469. parmas.put("energytypeid", energytypeid);
  470. }
  471. }
  472. if(parmas.containsKey("energyid") && parmas.get("energyid") != null && !"".equals(parmas.get("energyid").toString())){
  473. String energyid = parmas.get("energyid").toString();
  474. if(energyid.indexOf(",") == -1){
  475. parmas.put("energyid", "and energyid = '" + energyid + "'");
  476. } else {
  477. energyid = "and energyid in ('" + energyid.replaceAll(",", "','") + "')";
  478. parmas.put("energyid", energyid);
  479. }
  480. }
  481. if(parmas.get("itemid") != null && !parmas.get("itemid").toString().isEmpty()){
  482. String itemid = parmas.get("itemid").toString();
  483. if(!itemid.startsWith("'")){
  484. itemid = "'" + itemid.replaceAll(",", "','").replaceAll(",", "','") + "'";
  485. }
  486. parmas.put("itemid", itemid);
  487. }
  488. PageList<Map<String, Object>> list = tRmCalpointService.getDate312ForPage(parmas, pageNum, pageSize);
  489. return success(list);
  490. }
  491. @ApiOperation(value="能源调度管理-计量点数据管理-计量点数据趋势图", notes="json格式")
  492. @PostMapping(value = "/getDate312ForChart")
  493. public RESTfulResult getDate312ForChart(@RequestBody HashMap<String, Object> parmas){
  494. if(parmas.get("size") == null){
  495. return failed(null, "请传入记录数");
  496. }
  497. int size = Integer.valueOf(parmas.get("size").toString());
  498. List<Map<String, Object>> lt = tRmCalpointService.getDate312ForChart((List<Map<String, Object>>)parmas.get("list"), size);
  499. return success(lt);
  500. }
  501. @ApiOperation(value="系统接口管理-能耗数据管理", notes="查询")
  502. @ApiImplicitParams({
  503. @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
  504. @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer")
  505. })
  506. @GetMapping(value = "/getInIdDate312")
  507. public RESTfulResult getInIdDate312(@RequestParam HashMap<String, Object> parmas){
  508. if(parmas.containsKey("itemid")) {
  509. String itemids = parmas.get("itemid").toString();
  510. itemids = itemids.replaceAll(",", "', '");
  511. parmas.put("itemid", itemids);
  512. }
  513. List<Map<String, Object>> list = tRmCalpointService.getInIdDate312(parmas);
  514. return success(list);
  515. }
  516. @ApiOperation(value="系统管理重新生成小时数据(动力、水)", notes="")
  517. @GetMapping(value = "/reHourData")
  518. public RESTfulResult reHourData(@RequestParam HashMap<String, Object> parmas){
  519. String itemid = "";
  520. String clock = "";
  521. String clocke = "";
  522. if(parmas.containsKey("itemid")) {
  523. itemid = parmas.get("itemid").toString();
  524. if(itemid.isEmpty()) {
  525. return failed(null, "请传入计量点ID");
  526. }
  527. }
  528. else {
  529. return failed(null, "请传入计量点ID");
  530. }
  531. if(parmas.containsKey("clock")){
  532. clock = parmas.get("clock").toString();
  533. if(clock.isEmpty()) {
  534. return failed(null, "请传入开始时间");
  535. }
  536. }else {
  537. return failed(null, "请传入开始时间");
  538. }
  539. if(parmas.containsKey("clocke")){
  540. clocke = parmas.get("clocke").toString();
  541. if(clocke.isEmpty()) {
  542. return failed(null, "请传入结束时间");
  543. }
  544. }else {
  545. return failed(null, "请传入结束时间");
  546. }
  547. String ret = tRmCalpointService.restatHourDate(itemid, clock, clocke);
  548. return success(ret);
  549. }
  550. @ApiOperation(value="系统管理重新生成小时数据(电)", notes="")
  551. @GetMapping(value = "/reHourDataE")
  552. public RESTfulResult reHourDataE(@RequestParam HashMap<String, Object> parmas){
  553. String clock = "";
  554. String clocke = "";
  555. if(parmas.containsKey("clock")){
  556. clock = parmas.get("clock").toString();
  557. if(clock.isEmpty()) {
  558. return failed(null, "请传入开始时间");
  559. }
  560. }else {
  561. return failed(null, "请传入开始时间");
  562. }
  563. if(parmas.containsKey("clocke")){
  564. clocke = parmas.get("clocke").toString();
  565. if(clocke.isEmpty()) {
  566. return failed(null, "请传入结束时间");
  567. }
  568. }else {
  569. return failed(null, "请传入结束时间");
  570. }
  571. String ret = tRmCalpointService.restatHourDateE(clock, clocke);
  572. return success(ret);
  573. }
  574. }