AdminJtBusinessController.java 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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 com.goafanti.common.model.JtBusinessProject;
  15. import okhttp3.Request;
  16. @RestController
  17. @RequestMapping(value = "/api/admin/jtBusiness")
  18. public class AdminJtBusinessController extends CertifyApiController{
  19. @Resource
  20. private JtBusinessService jtBusinessService;
  21. @Resource JtBusinessServiceWithCategoryMapper JtBusinessServiceWithCategoryMapper;
  22. /*
  23. * 删除品类
  24. *
  25. * */
  26. @RequestMapping(value="/category/delete",method=RequestMethod.POST)
  27. private Result deleteCetegoryById(String id) {
  28. Result result=new Result();
  29. if(id==null) {result.getError().add(buildError(ErrorConstants.STATUS_ERROR,"","id"));
  30. return result;}
  31. int rc=jtBusinessService.deleteCategoryById(id);
  32. result.setData(rc);
  33. if(rc==-1) {
  34. result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"","请先删除子项目及子分类,"));
  35. }
  36. return result;
  37. }
  38. /*
  39. *
  40. * 品类详情
  41. * */
  42. @RequestMapping(value="/category/detail",method=RequestMethod.GET)
  43. private Result getCategoryDetailById(String id)
  44. {
  45. Result result=new Result();
  46. if(id==null) {result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"","id"));
  47. return result;}
  48. result.setData(jtBusinessService.getCategoryById(id));
  49. return result;
  50. }
  51. /*
  52. *
  53. * 新增品類
  54. *
  55. * */
  56. @RequestMapping(value="/category/apply",method=RequestMethod.POST)
  57. private Result insertCategory(JtBusinessCategory jtBusinessCategory) {
  58. Result result=new Result();
  59. disposeCateParam(result, jtBusinessCategory);
  60. if(result.getError().size()>0)return result;
  61. int rc=jtBusinessService.insertCategory(jtBusinessCategory);
  62. if(rc==-1)result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"","每层品类不可超过99个,"));
  63. if(rc==-2)result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"","父类Id与层数需要对应,"));
  64. return result;
  65. }
  66. /*
  67. * 修改
  68. * */
  69. @RequestMapping(value="/category/update",method=RequestMethod.POST)
  70. private Result updateCategory(JtBusinessCategory jtBusinessCategory) {
  71. Result result=new Result();
  72. //只允许修改3种字段
  73. JtBusinessCategory jtBusinessCategory2=new JtBusinessCategory();
  74. jtBusinessCategory2.setImgUrl(jtBusinessCategory.getImgUrl());
  75. jtBusinessCategory2.setName(jtBusinessCategory.getName());
  76. jtBusinessCategory2.setSummary(jtBusinessCategory.getSummary());
  77. result.setData(jtBusinessService.updateCategory(jtBusinessCategory2));
  78. return result;
  79. }
  80. /*
  81. * 查询品类
  82. *
  83. * */
  84. @RequestMapping(value="/category/list",method=RequestMethod.GET)
  85. private Result getCategoryList(JtBusinessCategory jtBusinessCategory,Integer pageNo,Integer pageSize) {
  86. Result result=new Result();
  87. result.setData(JtBusinessServiceWithCategoryMapper.getCategoryListByCondition(jtBusinessCategory,pageNo,pageSize));
  88. return result;
  89. }
  90. private void disposeCateParam(Result result,JtBusinessCategory jtBusinessCategory ) {
  91. if(jtBusinessCategory.getName() == null) {
  92. result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "名称不可为空", "名称"));
  93. return ;
  94. }
  95. if(jtBusinessCategory.getLayer() == null) {
  96. result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "层级不可为空", "层级"));
  97. return ;
  98. }
  99. if(jtBusinessCategory.getLayer()>1 && jtBusinessCategory.getSuperId()==null)
  100. {
  101. result.getError().add(buildError(ErrorConstants.PARAM_ERROR, "父级品类不可为空", "父级品类"));
  102. return ;
  103. }
  104. return ;
  105. }
  106. /*
  107. *
  108. * 新增项目
  109. *
  110. * */
  111. @RequestMapping(value="/project/apply",method=RequestMethod.POST)
  112. private Result insertJtBusinessProject(JtBusinessProject jtBusinessProject) {
  113. Result result=new Result();
  114. disposeProjectParam(result, jtBusinessProject);
  115. if(result.getError().size()<=0) {
  116. result.setData(jtBusinessService.insertProject(jtBusinessProject));
  117. }
  118. return result;
  119. }
  120. private void disposeProjectParam(Result result,JtBusinessProject jtBusinessProject ) {
  121. if(jtBusinessProject.getName() == null) {
  122. result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "名称不可为空", "名称"));
  123. return ;
  124. }
  125. if(jtBusinessProject.getCategoryId() == null) {
  126. result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "品类"));
  127. return ;
  128. }
  129. //todo 判断品类是否存在
  130. JtBusinessCategory jtBusinessCategory=jtBusinessService.getCategoryById(jtBusinessProject.getCategoryId());
  131. if(jtBusinessCategory==null ||jtBusinessCategory.getLayer()!=2) {
  132. result.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "二级品类找到"));
  133. return ;
  134. }
  135. if(jtBusinessProject.getProvince()==null)
  136. {
  137. result.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "省份"));
  138. return ;
  139. }
  140. if(jtBusinessProject.getCity()==null)
  141. {
  142. result.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "城市"));
  143. return ;
  144. }
  145. if(jtBusinessProject.getPrice()==null)
  146. {
  147. result.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "价格"));
  148. return ;
  149. }
  150. return ;
  151. }
  152. /*
  153. * 项目详情
  154. *
  155. * */
  156. @RequestMapping(value="/project/detail",method=RequestMethod.GET)
  157. private Result getProjectDetail(String id) {
  158. Result result=new Result();
  159. if(id == null) {
  160. result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"","id不能为空,"));
  161. return result;
  162. }
  163. result.setData(jtBusinessService.getBusinessProjectDetail(id));
  164. return result;
  165. }
  166. /*
  167. * 删除项目
  168. * */
  169. @RequestMapping(value="/project/delete",method=RequestMethod.GET)
  170. private Result deleteProjecById(String id) {
  171. Result result=new Result();
  172. if(id == null) {
  173. result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"","id不能为空,"));
  174. return result;
  175. }
  176. result.setData(jtBusinessService.deleteProjectById(id));
  177. return result;
  178. }
  179. }