ConstantController.java 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. package com.xintong.visualinspection.controller;
  2. import java.util.List;
  3. import javax.validation.Valid;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.web.bind.annotation.PathVariable;
  6. import org.springframework.web.bind.annotation.RequestBody;
  7. import org.springframework.web.bind.annotation.RequestMapping;
  8. import org.springframework.web.bind.annotation.RestController;
  9. import com.github.pagehelper.PageHelper;
  10. import com.github.pagehelper.PageInfo;
  11. import com.mysql.jdbc.StringUtils;
  12. import com.xintong.system.err.BusinessException;
  13. import com.xintong.visualinspection.bean.Constant;
  14. import com.xintong.visualinspection.bean.User;
  15. import com.xintong.visualinspection.service.ConstantService;
  16. /**
  17. * 文件名:TestController
  18. * 版本信息:日期:2017/3/30 Copyright 江苏省交通规划设计院 Corporation 2017 版权所有.
  19. */
  20. @RestController
  21. @RequestMapping("/constant")
  22. public class ConstantController extends BaseController {
  23. @Autowired
  24. private ConstantService constantService;
  25. /**
  26. * 添加常量
  27. * @return
  28. * String
  29. * @exception
  30. * @since 1.0.0
  31. */
  32. @RequestMapping(value = "/add")
  33. public String add(@Valid @RequestBody Constant constant){
  34. if(constant.getValid()==1) constant.setValid(1);
  35. constantService.insert(constant);
  36. return super.returnSuccessResult("添加成功");
  37. }
  38. /**
  39. * 修改常量
  40. * @return
  41. * String
  42. * @exception
  43. * @since 1.0.0
  44. */
  45. @RequestMapping(value = "/update")
  46. public String update(@RequestBody Constant constant){
  47. if(constant.getId()==null){
  48. throw new BusinessException(20002);
  49. }
  50. constantService.update(constant);
  51. return super.returnSuccessResult("修改成功");
  52. }
  53. /**
  54. * 删除常量
  55. * @return
  56. * String
  57. * @exception
  58. * @since 1.0.0
  59. */
  60. @RequestMapping(value = "/delete")
  61. public String delete(@RequestBody Constant constant){
  62. if(constant.getId()==null){
  63. throw new BusinessException(20002);
  64. }
  65. constantService.delete(constant.getId());
  66. return super.returnSuccessResult("删除成功");
  67. }
  68. /**
  69. * 通过常量标识获取某一类型常量
  70. * @return
  71. * String
  72. * @exception
  73. * @since 1.0.0
  74. */
  75. @RequestMapping(value = "/getConstantByFlag")
  76. public String getConstantByFlag(@RequestBody Constant constant){
  77. if(StringUtils.isNullOrEmpty(constant.getCode_flag())){
  78. throw new BusinessException(20101);
  79. }
  80. List<Constant> constantList = constantService.getByFlag(constant.getCode_flag());
  81. return super.returnSuccessResult(constantList);
  82. }
  83. /**
  84. * 通过常量标识和字典值获取常量
  85. * @return
  86. * String
  87. * @exception
  88. * @since 1.0.0
  89. */
  90. @RequestMapping(value = "/getConstantByFlagAndValue")
  91. public String getConstantByFlagAndValue(@RequestBody Constant constant){
  92. if(StringUtils.isNullOrEmpty(constant.getCode_flag())){
  93. throw new BusinessException(20101);
  94. }
  95. if(StringUtils.isNullOrEmpty(constant.getCode_flag())){
  96. throw new BusinessException(20102);
  97. }
  98. Constant con = constantService.getByFlagAndValue(constant);
  99. return super.returnSuccessResult(con);
  100. }
  101. /**
  102. * 通过名称模糊查询
  103. * @return
  104. * String
  105. * @exception
  106. * @since 1.0.0
  107. */
  108. @RequestMapping(value = "/getConstantByName/{page}/{size}")
  109. public String getConstantByName(@PathVariable Integer page,@PathVariable Integer size, @RequestBody Constant constant){
  110. PageHelper.startPage(page, size);
  111. List<Constant> constantList;
  112. if(StringUtils.isNullOrEmpty(constant.getFlag_name())){
  113. // throw new BusinessException(20103);
  114. constantList = constantService.getAll();
  115. }else{
  116. constantList = constantService.getByName(constant.getFlag_name());
  117. }
  118. return super.returnSuccessResult(new PageInfo(constantList));
  119. }
  120. }