AdminJtBusinessController.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  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.business.service.JtTagService;
  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.enums.AttachmentType;
  14. import com.goafanti.common.enums.ProjectAuditStatus;
  15. import com.goafanti.common.model.JtBusinessCategory;
  16. import com.goafanti.common.model.JtBusinessProject;
  17. import com.goafanti.common.model.JtTag;
  18. import com.goafanti.common.utils.StringUtils;
  19. @RestController
  20. @RequestMapping(value = "/api/admin/jtBusiness")
  21. public class AdminJtBusinessController extends CertifyApiController{
  22. @Resource
  23. private JtBusinessService jtBusinessService;
  24. @Resource
  25. private JtTagService jtTagService;
  26. @Resource JtBusinessServiceWithCategoryMapper JtBusinessServiceWithCategoryMapper;
  27. /*
  28. * 删除品类
  29. * */
  30. @RequestMapping(value="/category/delete",method=RequestMethod.POST)
  31. private Result deleteCetegoryById(String id) {
  32. Result result=new Result();
  33. if(id==null) {result.getError().add(buildError(ErrorConstants.STATUS_ERROR,"","id"));
  34. return result;}
  35. int rc=jtBusinessService.deleteCategoryById(id);
  36. result.setData(rc);
  37. if(rc==-1) {
  38. result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"","请先删除子项目及子分类,"));
  39. }
  40. return result;
  41. }
  42. /*
  43. * 品类详情
  44. * */
  45. @RequestMapping(value="/category/detail",method=RequestMethod.GET)
  46. private Result getCategoryDetailById(String id)
  47. {
  48. Result result=new Result();
  49. if(id==null) {result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"","id"));
  50. return result;}
  51. result.setData(jtBusinessService.getCategoryById(id));
  52. return result;
  53. }
  54. /*
  55. * 新增品類
  56. * */
  57. @RequestMapping(value="/category/apply",method=RequestMethod.POST)
  58. private Result insertCategory(JtBusinessCategory jtBusinessCategory) {
  59. Result result=new Result();
  60. disposeCateParam(result, jtBusinessCategory);
  61. if(result.getError().size()>0)return result;
  62. int rc=jtBusinessService.insertCategory(jtBusinessCategory);
  63. if(rc==-1)result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"","每层品类不可超过99个,"));
  64. if(rc==-2)result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"","父类Id与层数需要对应,"));
  65. return result;
  66. }
  67. /*
  68. * 修改
  69. * */
  70. @RequestMapping(value="/category/update",method=RequestMethod.POST)
  71. private Result updateCategory(JtBusinessCategory jtBusinessCategory, Integer nextModule) {
  72. Result result=new Result();
  73. int re = jtBusinessService.updateCategory(jtBusinessCategory);
  74. result.setData(re);
  75. return result;
  76. }
  77. /*
  78. * 查询品类
  79. * */
  80. @RequestMapping(value="/category/list",method=RequestMethod.GET)
  81. private Result getCategoryList(JtBusinessCategory jtBusinessCategory,Integer pageNo,Integer pageSize) {
  82. Result result=new Result();
  83. result.setData(JtBusinessServiceWithCategoryMapper.getCategoryListByCondition(jtBusinessCategory,pageNo,pageSize));
  84. return result;
  85. }
  86. private void disposeCateParam(Result result,JtBusinessCategory jtBusinessCategory ) {
  87. if(jtBusinessCategory.getName() == null) {
  88. result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "名称不可为空", "名称"));
  89. return ;
  90. }
  91. if(jtBusinessCategory.getLayer() == null) {
  92. result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "层级不可为空", "层级"));
  93. return ;
  94. }
  95. if(jtBusinessCategory.getLayer()==2 && jtBusinessCategory.getSuperId()==null)
  96. {
  97. result.getError().add(buildError(ErrorConstants.PARAM_ERROR, "父级品类不可为空", "父级品类"));
  98. return ;
  99. }
  100. if(jtBusinessCategory.getLayer()>3 || jtBusinessCategory.getLayer()<1)
  101. {
  102. result.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "层级只能为一级或二级"));
  103. return ;
  104. }
  105. return ;
  106. }
  107. /*
  108. * 新增项目
  109. * */
  110. @RequestMapping(value="/project/apply",method=RequestMethod.POST)
  111. private Result insertJtBusinessProject(JtBusinessProject jtBusinessProject) {
  112. Result result=new Result();
  113. disposeProjectParam(result, jtBusinessProject);
  114. if(result.getError().size()<=0) {
  115. result.setData(jtBusinessService.insertProject(jtBusinessProject));
  116. }
  117. return result;
  118. }
  119. private void disposeProjectParam(Result result,JtBusinessProject jtBusinessProject ) {
  120. if(jtBusinessProject.getName() == null) {
  121. result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "名称不可为空", "名称"));
  122. return ;
  123. }
  124. if(jtBusinessProject.getCategoryId() == null) {
  125. result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "品类"));
  126. return ;
  127. }
  128. //todo 判断品类是否存在
  129. JtBusinessCategory jtBusinessCategory=jtBusinessService.getCategoryById(jtBusinessProject.getCategoryId());
  130. if(jtBusinessCategory==null ||jtBusinessCategory.getLayer()!=2) {
  131. result.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "二级品类未找到"));
  132. return ;
  133. }
  134. if(jtBusinessProject.getProvince()==null)
  135. {
  136. result.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "省份"));
  137. return ;
  138. }
  139. // if(jtBusinessProject.getCity()==null)
  140. // {
  141. // result.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "城市"));
  142. // return ;
  143. // }
  144. // if(jtBusinessProject.getPrice()==null)
  145. // {
  146. // result.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "价格"));
  147. // return ;
  148. // }
  149. return ;
  150. }
  151. /*
  152. * 项目详情
  153. * */
  154. @RequestMapping(value="/project/detail",method=RequestMethod.GET)
  155. private Result getProjectDetail(String id) {
  156. Result result=new Result();
  157. if(id == null) {
  158. result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"","id不能为空,"));
  159. return result;
  160. }
  161. result.setData(jtBusinessService.getBusinessProjectDetail(id));
  162. return result;
  163. }
  164. /*
  165. * 删除项目
  166. * */
  167. @RequestMapping(value="/project/delete",method=RequestMethod.GET)
  168. private Result deleteProjecById(String id) {
  169. Result result=new Result();
  170. if(id == null) {
  171. result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"","id不能为空,"));
  172. return result;
  173. }
  174. result.setData(jtBusinessService.deleteProjectById(id));
  175. return result;
  176. }
  177. @RequestMapping(value="/project/update",method=RequestMethod.POST)
  178. private Result updateProject(JtBusinessProject jtBusinessProject) {
  179. Result result=new Result();
  180. jtBusinessProject.setCreateTime(null);
  181. // jtBusinessProject.setId(null);
  182. jtBusinessProject.setNumber(null);
  183. disposeProjectParam(result, jtBusinessProject);
  184. if(result.getError().size()>0) {
  185. return result;
  186. }
  187. if(jtBusinessProject.getPrice()==null) {
  188. result.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "价格不可为空,"));
  189. }
  190. jtBusinessService.updateProject(jtBusinessProject);
  191. return result;
  192. }
  193. @RequestMapping(value = "/uploadPicture", method = RequestMethod.POST)
  194. public Result uploadPicture(HttpServletRequest req, String sign) {
  195. Result res = new Result();
  196. AttachmentType attachmentType = AttachmentType.getField(sign);
  197. if (attachmentType == AttachmentType.JT_BUSINESS_PICTURE
  198. ) {
  199. res.setData(handleFiles(res, "/jtVarieties/", false, req, sign, ""));
  200. } else {
  201. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "图片"));
  202. }
  203. return res;
  204. }
  205. @RequestMapping(value = "/project/uploadPicture", method = RequestMethod.POST)
  206. public Result uploadProjectPicture(HttpServletRequest req, String sign) {
  207. Result res = new Result();
  208. AttachmentType attachmentType = AttachmentType.getField(sign);
  209. if (attachmentType == AttachmentType.JT_PROJECT_PICTURE
  210. ) {
  211. res.setData(handleFiles(res, "/jtProjects/", false, req, sign, ""));
  212. } else {
  213. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "图片"));
  214. }
  215. return res;
  216. }
  217. @RequestMapping(value="/project/audit" ,method=RequestMethod.POST)
  218. private Result auditAchievemnt(String id,Integer auditResult,String auditInfo) {
  219. Result result=new Result();
  220. if(id == null || auditResult == null || auditResult.intValue()!=0 && auditResult.intValue()!=1)
  221. {
  222. result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"",""));return result;
  223. }
  224. JtBusinessProject jtBusinessProject = jtBusinessService.getBusinessProjectDetail(id);
  225. if(jtBusinessProject==null) {
  226. result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"未找到服务","服务Id"));return result;
  227. }
  228. if(jtBusinessProject.getAuditStatus()!= ProjectAuditStatus.SUBMIT.getCode()) {
  229. result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"未找到服务","当前状态不可审核"));return result;
  230. }
  231. if(auditResult.intValue() == 0) jtBusinessProject.setAuditStatus(ProjectAuditStatus.AUDITED.getCode());
  232. if(auditResult.intValue() == 1) jtBusinessProject.setAuditStatus(ProjectAuditStatus.UNAUDITED.getCode());
  233. jtBusinessProject.setAuditInfo(auditInfo);
  234. jtBusinessService.updateProject(jtBusinessProject);
  235. return result;
  236. }
  237. /*
  238. * 新增标签
  239. * */
  240. @RequestMapping(value="/tag/apply",method=RequestMethod.POST)
  241. private Result insertJtTag(JtTag a) {
  242. Result result=new Result();
  243. if(StringUtils.isBlank(a.getName())) {
  244. result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"标签名称","标签名称"));return result;
  245. }
  246. result.data(jtTagService.addTag(a));
  247. return result;
  248. }
  249. /*
  250. * 删除标签
  251. * */
  252. @RequestMapping(value="/tag/delete",method=RequestMethod.POST)
  253. private Result deleteJtTag(JtTag a) {
  254. Result result=new Result();
  255. if(StringUtils.isBlank(a.getId())) {
  256. result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"标签ID","标签ID"));return result;
  257. }
  258. result.data(jtTagService.deleteJtTag(a.getId()));
  259. return result;
  260. }
  261. /*
  262. * 修改标签
  263. * */
  264. @RequestMapping(value="/tag/update",method=RequestMethod.POST)
  265. private Result updateJtTag(JtTag a) {
  266. Result result=new Result();
  267. if(StringUtils.isBlank(a.getId())) {
  268. result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"标签ID","标签ID"));return result;
  269. }
  270. if(StringUtils.isBlank(a.getName())) {
  271. result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"标签名称","标签名称"));return result;
  272. }
  273. result.data(jtTagService.updateJtTag(a));
  274. return result;
  275. }
  276. /*
  277. * 标签内容
  278. * */
  279. @RequestMapping(value="/tag/detail",method=RequestMethod.GET)
  280. private Result detailJtTag(JtTag a) {
  281. Result result=new Result();
  282. if(StringUtils.isBlank(a.getId())) {
  283. result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"标签ID","标签ID"));return result;
  284. }
  285. result.data(jtTagService.detailJtTag(a));
  286. return result;
  287. }
  288. /*
  289. * 标签列表
  290. * */
  291. @RequestMapping(value="/tag/list",method=RequestMethod.GET)
  292. private Result detailJtTag(JtTag a,Integer pageNo,Integer pageSize) {
  293. Result result=new Result();
  294. result.data(jtTagService.selectListJtTag(a,pageNo,pageSize));
  295. return result;
  296. }
  297. }