ConstantController.java 3.5 KB

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