UserJtBusinessController.java 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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.JtBusinessService;
  8. import com.goafanti.business.service.JtBusinessServiceWithCategoryMapper;
  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.enums.AttachmentType;
  13. import com.goafanti.common.model.JtBusinessCategory;
  14. import com.goafanti.common.model.JtBusinessProject;
  15. @RestController
  16. @RequestMapping(value = "/api/user/jtBusiness")
  17. public class UserJtBusinessController extends CertifyApiController{
  18. @Resource
  19. private JtBusinessService jtBusinessService;
  20. @Resource JtBusinessServiceWithCategoryMapper JtBusinessServiceWithCategoryMapper;
  21. /*
  22. *
  23. * 新增项目
  24. *
  25. * */
  26. @RequestMapping(value="/project/apply",method=RequestMethod.POST)
  27. private Result insertJtBusinessProject(JtBusinessProject jtBusinessProject) {
  28. Result result=new Result();
  29. disposeProjectParam(result, jtBusinessProject);
  30. if(result.getError().size()<=0) {
  31. result.setData(jtBusinessService.insertProject(jtBusinessProject));
  32. }
  33. return result;
  34. }
  35. private void disposeProjectParam(Result result,JtBusinessProject jtBusinessProject ) {
  36. if(jtBusinessProject.getName() == null) {
  37. result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "名称不可为空", "名称"));
  38. return ;
  39. }
  40. if(jtBusinessProject.getCategoryId() == null) {
  41. result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "品类"));
  42. return ;
  43. }
  44. //todo 判断品类是否存在
  45. JtBusinessCategory jtBusinessCategory=jtBusinessService.getCategoryById(jtBusinessProject.getCategoryId());
  46. if(jtBusinessCategory==null ||jtBusinessCategory.getLayer()!=2) {
  47. result.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "二级品类未找到"));
  48. return ;
  49. }
  50. if(jtBusinessProject.getProvince()==null)
  51. {
  52. result.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "省份"));
  53. return ;
  54. }
  55. // if(jtBusinessProject.getCity()==null)
  56. // {
  57. // result.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "城市"));
  58. // return ;
  59. // }
  60. // if(jtBusinessProject.getPrice()==null)
  61. // {
  62. // result.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "价格"));
  63. // return ;
  64. // }
  65. return ;
  66. }
  67. /*
  68. * 项目详情
  69. *
  70. * */
  71. @RequestMapping(value="/project/detail",method=RequestMethod.GET)
  72. private Result getProjectDetail(String id) {
  73. Result result=new Result();
  74. if(id == null) {
  75. result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"","id不能为空,"));
  76. return result;
  77. }
  78. result.setData(jtBusinessService.getBusinessProjectDetail(id));
  79. return result;
  80. }
  81. /*
  82. * 删除项目
  83. * */
  84. @RequestMapping(value="/project/delete",method=RequestMethod.GET)
  85. private Result deleteProjecById(String id) {
  86. Result result=new Result();
  87. if(id == null) {
  88. result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"","id不能为空,"));
  89. return result;
  90. }
  91. result.setData(jtBusinessService.deleteProjectById(id));
  92. return result;
  93. }
  94. @RequestMapping(value="/project/update",method=RequestMethod.POST)
  95. private Result updateProject(JtBusinessProject jtBusinessProject) {
  96. Result result=new Result();
  97. jtBusinessProject.setCreateTime(null);
  98. // jtBusinessProject.setId(null);
  99. jtBusinessProject.setNumber(null);
  100. disposeProjectParam(result, jtBusinessProject);
  101. if(result.getError().size()>0) {
  102. return result;
  103. }
  104. if(jtBusinessProject.getPrice()==null) {
  105. result.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "价格不可为空,"));
  106. }
  107. jtBusinessService.updateProject(jtBusinessProject);
  108. return result;
  109. }
  110. @RequestMapping(value = "/project/uploadPicture", method = RequestMethod.POST)
  111. public Result uploadProjectPicture(HttpServletRequest req, String sign) {
  112. Result res = new Result();
  113. AttachmentType attachmentType = AttachmentType.getField(sign);
  114. if (attachmentType == AttachmentType.JT_PROJECT_PICTURE
  115. ) {
  116. res.setData(handleFiles(res, "/jtProjects/", false, req, sign, ""));
  117. } else {
  118. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "图片"));
  119. }
  120. return res;
  121. }
  122. /*
  123. * 查询品类
  124. *
  125. * */
  126. @RequestMapping(value="/category/list",method=RequestMethod.GET)
  127. private Result getCategoryList(JtBusinessCategory jtBusinessCategory,Integer pageNo,Integer pageSize) {
  128. Result result=new Result();
  129. result.setData(JtBusinessServiceWithCategoryMapper.getCategoryListByCondition(jtBusinessCategory,pageNo,pageSize));
  130. return result;
  131. }
  132. }