AdminJtBusinessController.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. package com.goafanti.business.controller;
  2. import java.util.HashMap;
  3. import java.util.Map;
  4. import javax.annotation.Resource;
  5. import org.springframework.web.bind.annotation.RequestMapping;
  6. import org.springframework.web.bind.annotation.RequestMethod;
  7. import org.springframework.web.bind.annotation.RestController;
  8. import com.goafanti.business.service.JtBusinessService;
  9. import com.goafanti.business.service.JtBusinessServiceWithCategoryMapper;
  10. import com.goafanti.common.bo.Result;
  11. import com.goafanti.common.constant.ErrorConstants;
  12. import com.goafanti.common.controller.CertifyApiController;
  13. import com.goafanti.common.model.JtBusinessCategory;
  14. import okhttp3.Request;
  15. @RestController
  16. @RequestMapping(value = "/api/admin/jtBusiness")
  17. public class AdminJtBusinessController extends CertifyApiController{
  18. @Resource
  19. private JtBusinessService jtBusinessService;
  20. @Resource JtBusinessServiceWithCategoryMapper JtBusinessServiceWithCategoryMapper;
  21. /*
  22. * 删除品类
  23. *
  24. * */
  25. @RequestMapping(value="/category/delete",method=RequestMethod.POST)
  26. private Result deleteCetegoryById(String id) {
  27. Result result=new Result();
  28. if(id==null) {result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"","id"));
  29. return result;}
  30. result.setData(jtBusinessService.deleteCategoryById(id));
  31. return result;
  32. }
  33. /*
  34. *
  35. * 品类详情
  36. * */
  37. @RequestMapping(value="/category/detail",method=RequestMethod.GET)
  38. private Result getCategoryDetailById(String id)
  39. {
  40. Result result=new Result();
  41. if(id==null) {result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"","id"));
  42. return result;}
  43. result.setData(jtBusinessService.getCategoryById(id));
  44. return result;
  45. }
  46. /*
  47. *
  48. * 新增品類
  49. *
  50. * */
  51. @RequestMapping(value="/category/apply",method=RequestMethod.POST)
  52. private Result insertCategory(JtBusinessCategory jtBusinessCategory) {
  53. Result result=new Result();
  54. disposeCateParam(result, jtBusinessCategory);
  55. if(result.getError().size()>0)return result;
  56. int rc=jtBusinessService.insertCategory(jtBusinessCategory);
  57. if(rc==-1)result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"","每层品类不可超过99个,"));
  58. if(rc==-2)result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"","父类Id与层数需要对应,"));
  59. return result;
  60. }
  61. /*
  62. * 修改
  63. * */
  64. @RequestMapping(value="/category/update",method=RequestMethod.POST)
  65. private Result updateCategory(JtBusinessCategory jtBusinessCategory) {
  66. Result result=new Result();
  67. //只允许修改3种字段
  68. JtBusinessCategory jtBusinessCategory2=new JtBusinessCategory();
  69. jtBusinessCategory2.setImgUrl(jtBusinessCategory.getImgUrl());
  70. jtBusinessCategory2.setName(jtBusinessCategory.getName());
  71. jtBusinessCategory2.setSummary(jtBusinessCategory.getSummary());
  72. result.setData(jtBusinessService.updateCategory(jtBusinessCategory2));
  73. return result;
  74. }
  75. /*
  76. * 查询品类
  77. *
  78. * */
  79. @RequestMapping(value="/category/list",method=RequestMethod.GET)
  80. private Result getCategoryList(JtBusinessCategory jtBusinessCategory,Integer pageNo,Integer pageSize) {
  81. Result result=new Result();
  82. result.setData(JtBusinessServiceWithCategoryMapper.getCategoryListByCondition(jtBusinessCategory,pageNo,pageSize));
  83. return result;
  84. }
  85. private void disposeCateParam(Result result,JtBusinessCategory jtBusinessCategory ) {
  86. if(jtBusinessCategory.getName() == null) {
  87. result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "名称不可为空", "名称"));
  88. return ;
  89. }
  90. if(jtBusinessCategory.getLayer() == null) {
  91. result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "层级不可为空", "层级"));
  92. return ;
  93. }
  94. if(jtBusinessCategory.getLayer()>1 && jtBusinessCategory.getSuperId()==null)
  95. {
  96. result.getError().add(buildError(ErrorConstants.PARAM_ERROR, "父级品类不可为空", "父级品类"));
  97. return ;
  98. }
  99. return ;
  100. }
  101. }