AdminVarietiesApiController.java 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. package com.goafanti.business.controller;
  2. import javax.annotation.Resource;
  3. import javax.servlet.http.HttpServletRequest;
  4. import org.springframework.web.bind.annotation.RequestMapping;
  5. import org.springframework.web.bind.annotation.RequestMethod;
  6. import org.springframework.web.bind.annotation.RestController;
  7. import com.goafanti.business.service.BusinessProjectService;
  8. import com.goafanti.business.service.BusinessVarietiesService;
  9. import com.goafanti.common.bo.Result;
  10. import com.goafanti.common.constant.ErrorConstants;
  11. import com.goafanti.common.controller.CertifyApiController;
  12. import com.goafanti.common.dao.BusinessCategoryMapper;
  13. import com.goafanti.common.enums.AttachmentType;
  14. import com.goafanti.common.utils.StringUtils;
  15. @RestController
  16. @RequestMapping("/api/admin/Varieties")
  17. public class AdminVarietiesApiController extends CertifyApiController{
  18. @Resource
  19. private BusinessVarietiesService businessVarietiesService;
  20. @Resource
  21. BusinessProjectService businessprojectService;
  22. @Resource
  23. BusinessCategoryMapper businessVarietiesMapper;
  24. /**
  25. * 新增品类
  26. */
  27. @RequestMapping(value = "/addVarieties" , method = RequestMethod.GET)
  28. public Result addVarieties(String cname,String superId) {
  29. Result res=new Result();
  30. if (StringUtils.isBlank(cname)) {
  31. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "品类名称为空", "品类名称"));
  32. return res;
  33. }
  34. if (StringUtils.isBlank(superId)) {
  35. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "上级品类为空", "上级品类"));
  36. return res;
  37. }
  38. if (0<(businessVarietiesService.isBeing(cname))) {
  39. res.getError().add(buildError(ErrorConstants.PARAM_BEING_ERROR, "品类名称已存在", "品类名称"));
  40. return res;
  41. }
  42. if (2<businessVarietiesService.getLayer(superId)) {
  43. res.getError().add(buildError( "品类层级不能大于3", "品类层级不能大于3"));
  44. return res;
  45. }
  46. if (businessVarietiesService.getCountSon(superId)>99) {
  47. res.getError().add(buildError( "品类下级最多存在99个", "品类下级最多存在99个"));
  48. return res;
  49. }
  50. res.setData(businessVarietiesService.insert(cname,superId));
  51. return res;
  52. }
  53. /**
  54. * 搜索品类
  55. */
  56. @RequestMapping(value="/vtList" ,method=RequestMethod.POST)
  57. public Result vtList(String cname,String superId,Integer layer,
  58. String status,Integer pageNo, Integer pageSize) {
  59. Result res = new Result();
  60. res.setData(businessVarietiesService.listVarieties(cname, superId, layer,
  61. status, pageNo, pageSize));
  62. return res;
  63. }
  64. /**
  65. * 获取父类信息
  66. *
  67. */
  68. @RequestMapping(value = "/getSuperList" , method = RequestMethod.GET)
  69. public Result getSuperList() {
  70. Result res=new Result();
  71. res.setData(businessVarietiesService.getSuperList());
  72. return res;
  73. }
  74. /**
  75. * 获取品类详情
  76. */
  77. @RequestMapping(value="/detailVarieties" ,method=RequestMethod.GET)
  78. public Result detailVarieties(String id) {
  79. Result res = new Result();
  80. res.setData(businessVarietiesService.editVarieties(id));
  81. return res;
  82. }
  83. /**
  84. * 保存编辑信息
  85. */
  86. @RequestMapping(value = "/editVarieties", method = RequestMethod.POST)
  87. public Result editVarieties (String id,String cname,String superId,String status,String varietiesLogo,Integer sort) {
  88. Result res = new Result();
  89. if (StringUtils.isBlank(cname)) {
  90. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "品类名称为空", "品类名称"));
  91. return res;
  92. }
  93. if (StringUtils.isBlank(superId)) {
  94. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "上级用户为空", "上级用户"));
  95. return res;
  96. }
  97. if (1<(businessVarietiesService.isBeing(cname))) {
  98. res.getError().add(buildError(ErrorConstants.PARAM_BEING_ERROR, "品类名称已存在", "品类名称"));
  99. return res;
  100. }
  101. if (businessVarietiesService.ifLayer(superId,id)) {
  102. res.getError().add(buildError( "品类层级不能超过三级", "品类层级不能超过三级"));
  103. return res;
  104. }
  105. if (businessVarietiesService.getCountSon(superId)>99) {
  106. res.getError().add(buildError( "品类下级最多存在99个", "品类下级最多存在99个"));
  107. return res;
  108. }
  109. if (businessVarietiesService.getCountSon(superId)>99) {
  110. res.getError().add(buildError( "品类下级最多存在99个", "品类下级最多存在99个"));
  111. return res;
  112. }
  113. res.setData(businessVarietiesService.updateVarietoes(id, cname, superId, status, varietiesLogo,sort));
  114. return res;
  115. }
  116. /**
  117. * 品类删除
  118. */
  119. @RequestMapping(value = "/deleteState", method = RequestMethod.GET)
  120. public Result deleteState(String id){
  121. Result res=new Result();
  122. if (businessVarietiesService.getCountSon(id)>0) {
  123. res.getError().add(buildError("品类下存在子品类", "品类存在子品类不允许删除"));
  124. return res;
  125. }
  126. if (businessprojectService.checkProject(id)) {
  127. res.getError().add(buildError("品类下存在项目", "品类存在项目不允许删除"));
  128. return res;
  129. }
  130. res.setData(businessVarietiesService.deleteState(id));
  131. return res;
  132. }
  133. /**
  134. * 品类停用
  135. */
  136. @RequestMapping(value = "/updateStatus", method = RequestMethod.GET)
  137. public Result updateStatus(String id){
  138. Result res=new Result();
  139. res.setData(businessVarietiesService.updateStatus(id));
  140. return res;
  141. }
  142. /**
  143. * 图片上传
  144. */
  145. @RequestMapping(value = "/uploadPicture", method = RequestMethod.POST)
  146. public Result uploadPicture(HttpServletRequest req, String sign) {
  147. Result res = new Result();
  148. AttachmentType attachmentType = AttachmentType.getField(sign);
  149. if (attachmentType == AttachmentType.VARIETIES_PICTURE
  150. ) {
  151. res.setData(handleFiles(res, "/varieties/", false, req, sign, ""));
  152. } else {
  153. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "图片"));
  154. }
  155. return res;
  156. }
  157. /**
  158. * 品类显示位置更换
  159. */
  160. @RequestMapping(value = "/locationChange", method = RequestMethod.GET)
  161. public Result locationChange(String id,Integer sort,Integer flag){
  162. Result res=new Result();
  163. if (1==sort&&flag==1) {
  164. res.getError().add(buildError("上移失败", "上移失败"));
  165. return res;
  166. }
  167. if (sort>=Integer.valueOf(businessVarietiesMapper.getSortMax())&&flag==0) {
  168. res.getError().add(buildError("下移失败", "下移失败"));
  169. return res;
  170. }
  171. res.setData(businessVarietiesService.updateLocation(id,sort,flag));
  172. return res;
  173. }
  174. }