31f8a9edd81ca51c7dd354adb76c74977af66035.svn-base 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. package cn.com.goldenwater.dcproj.controller.base;
  2. import cn.com.goldenwater.dcproj.model.AttInspType;
  3. import cn.com.goldenwater.dcproj.param.AttInspTypeParam;
  4. import cn.com.goldenwater.dcproj.service.AttInspTypeService;
  5. import cn.com.goldenwater.core.web.BaseController;
  6. import cn.com.goldenwater.core.web.BaseResponse;
  7. import io.swagger.annotations.Api;
  8. import io.swagger.annotations.ApiOperation;
  9. import io.swagger.annotations.ApiParam;
  10. import org.apache.commons.lang3.StringUtils;
  11. import com.github.pagehelper.PageInfo;
  12. import org.slf4j.Logger;
  13. import org.slf4j.LoggerFactory;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.web.bind.annotation.PathVariable;
  16. import org.springframework.web.bind.annotation.RequestBody;
  17. import org.springframework.web.bind.annotation.RequestMapping;
  18. import org.springframework.web.bind.annotation.RequestMethod;
  19. import org.springframework.web.bind.annotation.RestController;
  20. import java.util.Collections;
  21. import java.util.Comparator;
  22. import java.util.List;
  23. /**
  24. * @author lune
  25. * @date 2019-7-19
  26. */
  27. @Api(value = "ATT 督查对象类型管理", tags = "ATT 督查对象类型管理")
  28. @RestController
  29. @RequestMapping("/att/insp/type")
  30. public class AttInspTypeController extends BaseController {
  31. private Logger logger = LoggerFactory.getLogger(getClass());
  32. @Autowired
  33. private AttInspTypeService attInspTypeService;
  34. @ApiOperation(value = "添加/修改督查对象类型")
  35. @RequestMapping(value = "", method = RequestMethod.POST)
  36. public BaseResponse<AttInspType> insert(@ApiParam(name = "attInspType", value = "AttInspType", required = true) @RequestBody AttInspType attInspType) {
  37. if (StringUtils.isBlank(attInspType.getCode())) {
  38. int codeMax = attInspTypeService.getMaxCode();
  39. codeMax++;
  40. String code = String.valueOf(codeMax);
  41. if (String.valueOf(code).length() == 1) {
  42. code = "00" + code;
  43. }
  44. if (String.valueOf(code).length() == 2) {
  45. code = "0" + code;
  46. }
  47. attInspType.setCode(code);
  48. attInspTypeService.insert(attInspType);
  49. } else {
  50. attInspTypeService.update(attInspType);
  51. }
  52. return buildSuccessResponse(attInspType);
  53. }
  54. @ApiOperation(value = "根据ID删除督查对象类型")
  55. @RequestMapping(value = "/del/{id}", method = RequestMethod.GET)
  56. public BaseResponse delete(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) {
  57. int ret = attInspTypeService.delete(id);
  58. return buildSuccessResponse();
  59. }
  60. @ApiOperation(value = "根据ID获取督查对象类型(单表)")
  61. @RequestMapping(value = "/{id}", method = RequestMethod.GET)
  62. public BaseResponse<AttInspType> get(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) {
  63. AttInspType attInspType = attInspTypeService.get(id);
  64. return buildSuccessResponse(attInspType);
  65. }
  66. @ApiOperation(value = "获取督查对象类型(列表所有)")
  67. @RequestMapping(value = "/list", method = RequestMethod.POST)
  68. public BaseResponse<List<AttInspType>> list(@ApiParam(name = "attInspTypeParam", value = "attInspTypeParam", required = true) @RequestBody AttInspTypeParam attInspTypeParam) {
  69. List<AttInspType> attInspTypeList = attInspTypeService.findList(attInspTypeParam);
  70. Collections.sort(attInspTypeList, new Comparator<AttInspType>() {
  71. @Override
  72. public int compare(AttInspType o1, AttInspType o2) {
  73. return Integer.valueOf(o1.getCode()) - Integer.valueOf(o2.getCode());
  74. }
  75. });
  76. return buildSuccessResponse(attInspTypeList);
  77. }
  78. @ApiOperation(value = "获取督查对象类型(列表--分页)")
  79. @RequestMapping(value = "/page", method = RequestMethod.POST)
  80. public BaseResponse<PageInfo<AttInspType>> page(@ApiParam(name = "attInspTypeParam", value = "attInspTypeParam", required = true) @RequestBody AttInspTypeParam attInspTypeParam) {
  81. PageInfo<AttInspType> attInspTypeList = attInspTypeService.findPageInfo(attInspTypeParam);
  82. return buildSuccessResponse(attInspTypeList);
  83. }
  84. @ApiOperation(value = "获取督查对象类型(列表所有,code去0)")
  85. @RequestMapping(value = "/getTypes", method = RequestMethod.POST)
  86. public BaseResponse<List<AttInspType>> getTypes(@ApiParam(name = "attInspTypeParam", value = "attInspTypeParam", required = true) @RequestBody AttInspTypeParam attInspTypeParam) {
  87. List<AttInspType> attInspTypeList = attInspTypeService.findList(attInspTypeParam);
  88. attInspTypeList.forEach(attInspType -> attInspType.setCode(String.valueOf(Integer.valueOf(attInspType.getCode()))));
  89. Collections.sort(attInspTypeList, new Comparator<AttInspType>() {
  90. @Override
  91. public int compare(AttInspType o1, AttInspType o2) {
  92. return Integer.valueOf(o1.getCode()) - Integer.valueOf(o2.getCode());
  93. }
  94. });
  95. return buildSuccessResponse(attInspTypeList);
  96. }
  97. }