TCm0310Controller.java 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. package com.steerinfo.ems.tcm0310.controller;
  2. import com.steerinfo.auth.utils.JwtUtil;
  3. import com.steerinfo.ems.tcm0310.mapper.TCm0310Mapper;
  4. import com.steerinfo.ems.tcm0310.model.TCm0310;
  5. import com.steerinfo.ems.tcm0310.service.ITCm0310Service;
  6. import com.steerinfo.ems.tcm0312.service.ITCm0312Service;
  7. import com.steerinfo.framework.controller.BaseRESTfulController;
  8. import com.steerinfo.framework.controller.RESTfulResult;
  9. import com.steerinfo.framework.service.pagehelper.PageList;
  10. import io.swagger.annotations.ApiImplicitParam;
  11. import io.swagger.annotations.ApiImplicitParams;
  12. import io.swagger.annotations.ApiOperation;
  13. import org.slf4j.Logger;
  14. import org.slf4j.LoggerFactory;
  15. import org.springframework.beans.factory.annotation.Autowired;
  16. import org.springframework.web.bind.annotation.*;
  17. import java.util.ArrayList;
  18. import java.util.HashMap;
  19. import java.util.List;
  20. import java.util.Map;
  21. /**
  22. * TCm0310 RESTful接口:
  23. * @author 王金涛
  24. * @version 1.0-SNAPSHORT 2019-10-15
  25. * 类描述
  26. * 修订历史:
  27. * 日期:2019-10-15
  28. * 作者:王金涛
  29. * 参考:
  30. * 描述:TCm0310 RESTful接口
  31. * @see null
  32. * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved.
  33. */
  34. @RestController
  35. @RequestMapping("/${api.version}/tcm0310s")
  36. public class TCm0310Controller extends BaseRESTfulController {
  37. private static final Logger LOGGER = LoggerFactory.getLogger(TCm0310Controller.class);
  38. @Autowired
  39. ITCm0310Service tCm0310Service;
  40. @Autowired
  41. ITCm0312Service tCm0312Service;
  42. @Autowired
  43. TCm0310Mapper tCm0310Mapper;
  44. @ApiOperation(value="获取列表", notes="分页查询")
  45. @ApiImplicitParams({
  46. @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
  47. @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer")
  48. })
  49. //@RequiresPermissions("tcm0310:view")
  50. @GetMapping(value = "/")
  51. public RESTfulResult list(@RequestParam HashMap parmas,Integer pageNum, Integer pageSize){
  52. PageList<TCm0310> list = tCm0310Service.queryForPage(parmas, pageNum, pageSize);
  53. return success(list);
  54. }
  55. @ApiOperation(value="创建", notes="根据TCm0310对象创建")
  56. @ApiImplicitParam(name = "tCm0310", value = "详细实体tCm0310", required = true, dataType = "TCm0310")
  57. //@RequiresPermissions("tcm0310:create")
  58. @PostMapping(value = "/")
  59. public RESTfulResult add(@ModelAttribute TCm0310 model){
  60. model.setSort(tCm0310Service.getmaxsort() + 1);
  61. if (model.getWatercode() == null || "".equals(model.getWatercode())) {
  62. Long maxid = tCm0310Service.getMaxId() == null ? 1 : Long.parseLong(tCm0310Service.getMaxId()) + 1;
  63. model.setWatercode("Q" + String.format("%05d", maxid));
  64. }
  65. model.setCreateman(JwtUtil.getUseridByToken());
  66. TCm0310 tCm0310 = tCm0310Service.add(model);
  67. return success(tCm0310);
  68. }
  69. // @ApiOperation(value="更新详细信息", notes="根据主键watercode来指定更新对象,并根据传过来的tCm0310信息来更新详细信息")
  70. // @ApiImplicitParam(name = "tCm0310", value = "详细实体tCm0310", required = true, dataType = "TCm0310")
  71. // @PutMapping(value = "/")
  72. // public RESTfulResult update(@RequestBody TCm0310 model){
  73. // if(model.getWatercode() == null || model.getWatercode().isEmpty()){
  74. // return failed(null, "请传入主键参数:watercode");
  75. // }
  76. // else {
  77. // LOGGER.info("水质系统维护修改前的数据是" + tCm0310Service.getById(model.getWatercode()).toString());
  78. // model.setUpdateman(JwtUtil.getUseridByToken());
  79. // TCm0310 tCm0310 = tCm0310Service.modify(model);
  80. // LOGGER.info("水质系统维护修改后的数据是" + tCm0310.toString());
  81. // return success(tCm0310);
  82. // }
  83. // }
  84. @ApiOperation(value="删除", notes="根据主键watercode来指定删除对象")
  85. @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "String")
  86. @DeleteMapping( produces = "application/json;charset=UTF-8")
  87. //@RequiresPermissions("tcm0310:delete")
  88. public RESTfulResult delete(@RequestBody TCm0310[] models) {
  89. for (TCm0310 model : models) {
  90. tCm0310Mapper.deleteByPrimaryKey(model.getWatercode());
  91. }
  92. return success();
  93. }
  94. @ApiOperation(value="系统名称下拉框", notes="查询id和name")
  95. @GetMapping(value = "/getidandname/")
  96. public RESTfulResult getNameAndId(){
  97. List<TCm0310> tCm0310 = tCm0310Service.getNameAndId();
  98. return success(tCm0310);
  99. }
  100. @ApiOperation(value="批量更新详细信息", notes="根据传过来的tCm0310数组信息来更新详细信息")
  101. @ApiImplicitParam(name = "tCm0310", value = "tCm0310", required = true, dataType = "TCm0310")
  102. //@RequiresPermissions("tcm0310:update")
  103. @PutMapping(value = "/", produces = "application/json;charset=UTF-8")
  104. public RESTfulResult batchupdate(@RequestBody TCm0310[] model){
  105. int failnum = 0;
  106. String failmsg = "";
  107. List<String> errorid = new ArrayList<>();
  108. for(int i = 0;i < model.length;i++){
  109. try {
  110. LOGGER.info("水质系统维护修改的第" + (i + 1) + "条数据:");
  111. LOGGER.info("水质系统维护修改前数据是" + tCm0310Service.getById(model[i].getId()).toString());
  112. model[i].setUpdateman(JwtUtil.getUseridByToken());
  113. TCm0310 tCm0310 = tCm0310Service.modify(model[i]);
  114. LOGGER.info("水质系统维护修改后数据是" + tCm0310.toString());
  115. }
  116. catch(Exception e){
  117. failnum++;
  118. errorid.add(model[i].getId());
  119. failmsg += "水质系统维护修改在第" + (i + 1) + "条数据出现错误,错误原因是" + e + ",id是" + model[i].getId();
  120. }
  121. }
  122. if(failnum > 0){
  123. LOGGER.info("本次共修改" + model.length + "条数据,其中成功" + (model.length - failnum) + "条,失败" + failnum + "条,失败原因:" + failmsg);
  124. return success(errorid,"51","本次共修改" + model.length + "条数据,其中成功" + (model.length - failnum) + "条,失败" + failnum + "条");
  125. }
  126. return success();
  127. }
  128. /**
  129. @ApiOperation(value="获取列表", notes="分页模糊查询")
  130. @ApiImplicitParams({
  131. @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
  132. @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer")
  133. })
  134. //@RequiresPermissions("tcm0310:view")
  135. @GetMapping(value = "/like/")
  136. public RESTfulResult listLike(@RequestParam HashMap parmas,Integer pageNum, Integer pageSize){
  137. PageList<TCm0310> list = tCm0310Service.queryLikeForPage(parmas, pageNum, pageSize);
  138. return success(list);
  139. }
  140. @ApiOperation(value="获取详细信息", notes="根据url的id来获取详细信息")
  141. @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "String")
  142. //@RequiresPermissions("tcm0310:view")
  143. @GetMapping(value = "/{id}")
  144. public RESTfulResult get(@PathVariable String id){
  145. TCm0310 tCm0310 = tCm0310Service.getById(id);
  146. return success(tCm0310);
  147. }
  148. */
  149. }