TCm0325Controller.java 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. package com.steerinfo.ems.tcm0325.controller;
  2. import com.steerinfo.auth.utils.JwtUtil;
  3. import com.steerinfo.ems.tcm0310.model.TCm0310;
  4. import com.steerinfo.ems.tcm0325.mapper.TCm0325Mapper;
  5. import com.steerinfo.ems.tcm0325.model.TCm0325;
  6. import com.steerinfo.ems.tcm0325.service.ITCm0325Service;
  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.apache.commons.lang3.StringUtils;
  14. import org.slf4j.Logger;
  15. import org.slf4j.LoggerFactory;
  16. import org.springframework.beans.factory.annotation.Autowired;
  17. import org.springframework.web.bind.annotation.*;
  18. import java.util.Arrays;
  19. import java.util.HashMap;
  20. import java.util.Set;
  21. @RestController
  22. @RequestMapping("/${api.version}/tcm0325s")
  23. public class TCm0325Controller extends BaseRESTfulController {
  24. private static final Logger LOGGER = LoggerFactory.getLogger(TCm0325Controller.class);
  25. @Autowired
  26. ITCm0325Service tCm0325Service;
  27. @Autowired
  28. TCm0325Mapper tCm0325Mapper;
  29. @ApiOperation(value="获取列表", notes="分页查询")
  30. @ApiImplicitParams({
  31. @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
  32. @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer")
  33. })
  34. //@RequiresPermissions("trmunit:view")
  35. @GetMapping(value = "/")
  36. public RESTfulResult list(@RequestParam HashMap parmas,Integer pageNum, Integer pageSize){
  37. PageList<TCm0325> list = tCm0325Service.queryForPage(parmas, pageNum, pageSize);
  38. return success(list);
  39. }
  40. @ApiOperation(value="获取列表", notes="分页模糊查询")
  41. @ApiImplicitParams({
  42. @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
  43. @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer")
  44. })
  45. //@RequiresPermissions("tpmcaseact:view")
  46. @GetMapping(value = "/like/")
  47. public RESTfulResult listLike(@RequestParam HashMap parmas,Integer pageNum, Integer pageSize){
  48. PageList<TCm0325> list = tCm0325Service.queryLikeForPage(parmas, pageNum, pageSize);
  49. return success(list);
  50. }
  51. @ApiOperation(value="创建", notes="根据tCm0325对象创建")
  52. @ApiImplicitParam(name = "tCm0325", value = "详细实体tCm0325", required = true, dataType = "TCm0325")
  53. //@RequiresPermissions("trmunit:create")
  54. @PostMapping(value = "/")
  55. public RESTfulResult add(@ModelAttribute TCm0325 model){
  56. if (null == model.getPowercode() || "".equals(model.getPowercode())) {
  57. Long maxid = tCm0325Service.getMaxId() == null ? 1 : Long.parseLong(tCm0325Service.getMaxId()) + 1;
  58. model.setPowercode("P" + String.format("%05d", maxid));
  59. }
  60. model.setSort(tCm0325Service.getMaxSort()==null? 1 : tCm0325Service.getMaxSort() + 1);
  61. model.setPowername(model.getPowername());
  62. TCm0325 tCm0325 = tCm0325Service.add(model);
  63. return success(tCm0325);
  64. }
  65. @ApiOperation(value="获取详细信息", notes="根据url的id来获取详细信息")
  66. @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "String")
  67. //@RequiresPermissions("trmunit:view")
  68. @GetMapping(value = "/{id}")
  69. public RESTfulResult get(@PathVariable String id){
  70. TCm0325 tCm0325 = tCm0325Service.getById(id);
  71. return success(tCm0325);
  72. }
  73. @ApiOperation(value="更新详细信息", notes="根据url的id来指定更新对象,并根据传过来的tCm0325信息来更新详细信息")
  74. @ApiImplicitParams({
  75. @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "String"),
  76. @ApiImplicitParam(name = "tCm0325", value = "详细实体tCm0325", required = true, dataType = "TCm0325")
  77. })
  78. //@RequiresPermissions("trmunit:update")
  79. @PutMapping(produces = "application/json;charset=UTF-8")
  80. public RESTfulResult update(@RequestBody TCm0325[] models){
  81. for (TCm0325 model : models) {
  82. tCm0325Mapper.updateByPrimaryKeySelective(model);
  83. }
  84. return success(null,"修改成功");
  85. }
  86. @ApiOperation(value="删除", notes="根据url的id来指定删除对象")
  87. @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "String")
  88. //@RequiresPermissions("trmunit:delete")
  89. @DeleteMapping( produces = "application/json;charset=UTF-8")//String
  90. public RESTfulResult delete(@RequestBody TCm0325[] models){
  91. for (TCm0325 model : models) {
  92. tCm0325Mapper.deleteByPrimaryKey(model.getPowercode());
  93. }
  94. return success();
  95. }
  96. @ApiOperation(value = "获取 code 和 Name",notes = "获取下拉框得值")
  97. @GetMapping(value = "/getCodeAndName")
  98. public RESTfulResult getCodeAndName(){
  99. Set<TCm0325> codeAndName = tCm0325Service.getCodeAndName();
  100. return success(codeAndName);
  101. }
  102. }