AdminJtBusinessController.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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) {
  72. Result result=new Result();
  73. //只允许修改3种字段
  74. JtBusinessCategory jtBusinessCategory2=new JtBusinessCategory();
  75. jtBusinessCategory2.setId(jtBusinessCategory.getId());
  76. jtBusinessCategory2.setImgUrl(jtBusinessCategory.getImgUrl());
  77. jtBusinessCategory2.setName(jtBusinessCategory.getName());
  78. jtBusinessCategory2.setSummary(jtBusinessCategory.getSummary());
  79. result.setData(jtBusinessService.updateCategory(jtBusinessCategory2));
  80. return result;
  81. }
  82. /*
  83. * 查询品类
  84. * */
  85. @RequestMapping(value="/category/list",method=RequestMethod.GET)
  86. private Result getCategoryList(JtBusinessCategory jtBusinessCategory,Integer pageNo,Integer pageSize) {
  87. Result result=new Result();
  88. result.setData(JtBusinessServiceWithCategoryMapper.getCategoryListByCondition(jtBusinessCategory,pageNo,pageSize));
  89. return result;
  90. }
  91. private void disposeCateParam(Result result,JtBusinessCategory jtBusinessCategory ) {
  92. if(jtBusinessCategory.getName() == null) {
  93. result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "名称不可为空", "名称"));
  94. return ;
  95. }
  96. if(jtBusinessCategory.getLayer() == null) {
  97. result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "层级不可为空", "层级"));
  98. return ;
  99. }
  100. if(jtBusinessCategory.getLayer()==2 && jtBusinessCategory.getSuperId()==null)
  101. {
  102. result.getError().add(buildError(ErrorConstants.PARAM_ERROR, "父级品类不可为空", "父级品类"));
  103. return ;
  104. }
  105. if(jtBusinessCategory.getLayer()>3 || jtBusinessCategory.getLayer()<1)
  106. {
  107. result.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "层级只能为一级或二级"));
  108. return ;
  109. }
  110. return ;
  111. }
  112. /*
  113. * 新增项目
  114. * */
  115. @RequestMapping(value="/project/apply",method=RequestMethod.POST)
  116. private Result insertJtBusinessProject(JtBusinessProject jtBusinessProject) {
  117. Result result=new Result();
  118. disposeProjectParam(result, jtBusinessProject);
  119. if(result.getError().size()<=0) {
  120. result.setData(jtBusinessService.insertProject(jtBusinessProject));
  121. }
  122. return result;
  123. }
  124. private void disposeProjectParam(Result result,JtBusinessProject jtBusinessProject ) {
  125. if(jtBusinessProject.getName() == null) {
  126. result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "名称不可为空", "名称"));
  127. return ;
  128. }
  129. if(jtBusinessProject.getCategoryId() == null) {
  130. result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "品类"));
  131. return ;
  132. }
  133. //todo 判断品类是否存在
  134. JtBusinessCategory jtBusinessCategory=jtBusinessService.getCategoryById(jtBusinessProject.getCategoryId());
  135. if(jtBusinessCategory==null ||jtBusinessCategory.getLayer()!=2) {
  136. result.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "二级品类未找到"));
  137. return ;
  138. }
  139. if(jtBusinessProject.getProvince()==null)
  140. {
  141. result.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "省份"));
  142. return ;
  143. }
  144. // if(jtBusinessProject.getCity()==null)
  145. // {
  146. // result.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "城市"));
  147. // return ;
  148. // }
  149. // if(jtBusinessProject.getPrice()==null)
  150. // {
  151. // result.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "价格"));
  152. // return ;
  153. // }
  154. return ;
  155. }
  156. /*
  157. * 项目详情
  158. * */
  159. @RequestMapping(value="/project/detail",method=RequestMethod.GET)
  160. private Result getProjectDetail(String id) {
  161. Result result=new Result();
  162. if(id == null) {
  163. result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"","id不能为空,"));
  164. return result;
  165. }
  166. result.setData(jtBusinessService.getBusinessProjectDetail(id));
  167. return result;
  168. }
  169. /*
  170. * 删除项目
  171. * */
  172. @RequestMapping(value="/project/delete",method=RequestMethod.GET)
  173. private Result deleteProjecById(String id) {
  174. Result result=new Result();
  175. if(id == null) {
  176. result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"","id不能为空,"));
  177. return result;
  178. }
  179. result.setData(jtBusinessService.deleteProjectById(id));
  180. return result;
  181. }
  182. @RequestMapping(value="/project/update",method=RequestMethod.POST)
  183. private Result updateProject(JtBusinessProject jtBusinessProject) {
  184. Result result=new Result();
  185. jtBusinessProject.setCreateTime(null);
  186. // jtBusinessProject.setId(null);
  187. jtBusinessProject.setNumber(null);
  188. disposeProjectParam(result, jtBusinessProject);
  189. if(result.getError().size()>0) {
  190. return result;
  191. }
  192. if(jtBusinessProject.getPrice()==null) {
  193. result.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "价格不可为空,"));
  194. }
  195. jtBusinessService.updateProject(jtBusinessProject);
  196. return result;
  197. }
  198. @RequestMapping(value = "/uploadPicture", method = RequestMethod.POST)
  199. public Result uploadPicture(HttpServletRequest req, String sign) {
  200. Result res = new Result();
  201. AttachmentType attachmentType = AttachmentType.getField(sign);
  202. if (attachmentType == AttachmentType.JT_BUSINESS_PICTURE
  203. ) {
  204. res.setData(handleFiles(res, "/jtVarieties/", false, req, sign, ""));
  205. } else {
  206. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "图片"));
  207. }
  208. return res;
  209. }
  210. @RequestMapping(value = "/project/uploadPicture", method = RequestMethod.POST)
  211. public Result uploadProjectPicture(HttpServletRequest req, String sign) {
  212. Result res = new Result();
  213. AttachmentType attachmentType = AttachmentType.getField(sign);
  214. if (attachmentType == AttachmentType.JT_PROJECT_PICTURE
  215. ) {
  216. res.setData(handleFiles(res, "/jtProjects/", false, req, sign, ""));
  217. } else {
  218. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "图片"));
  219. }
  220. return res;
  221. }
  222. @RequestMapping(value="/project/audit" ,method=RequestMethod.POST)
  223. private Result auditAchievemnt(String id,Integer auditResult,String auditInfo) {
  224. Result result=new Result();
  225. if(id == null || auditResult == null || auditResult.intValue()!=0 && auditResult.intValue()!=1)
  226. {
  227. result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"",""));return result;
  228. }
  229. JtBusinessProject jtBusinessProject = jtBusinessService.getBusinessProjectDetail(id);
  230. if(jtBusinessProject==null) {
  231. result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"未找到服务","服务Id"));return result;
  232. }
  233. if(jtBusinessProject.getAuditStatus()!= ProjectAuditStatus.SUBMIT.getCode()) {
  234. result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"未找到服务","当前状态不可审核"));return result;
  235. }
  236. if(auditResult.intValue() == 0) jtBusinessProject.setAuditStatus(ProjectAuditStatus.AUDITED.getCode());
  237. if(auditResult.intValue() == 1) jtBusinessProject.setAuditStatus(ProjectAuditStatus.UNAUDITED.getCode());
  238. jtBusinessProject.setAuditInfo(auditInfo);
  239. jtBusinessService.updateProject(jtBusinessProject);
  240. return result;
  241. }
  242. /*
  243. * 新增标签
  244. * */
  245. @RequestMapping(value="/tag/apply",method=RequestMethod.POST)
  246. private Result insertJtTag(JtTag a) {
  247. Result result=new Result();
  248. if(StringUtils.isBlank(a.getName())) {
  249. result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"标签名称","标签名称"));return result;
  250. }
  251. result.data(jtTagService.addTag(a));
  252. return result;
  253. }
  254. /*
  255. * 删除标签
  256. * */
  257. @RequestMapping(value="/tag/delete",method=RequestMethod.POST)
  258. private Result deleteJtTag(JtTag a) {
  259. Result result=new Result();
  260. if(StringUtils.isBlank(a.getId())) {
  261. result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"标签ID","标签ID"));return result;
  262. }
  263. result.data(jtTagService.deleteJtTag(a.getId()));
  264. return result;
  265. }
  266. /*
  267. * 修改标签
  268. * */
  269. @RequestMapping(value="/tag/update",method=RequestMethod.POST)
  270. private Result updateJtTag(JtTag a) {
  271. Result result=new Result();
  272. if(StringUtils.isBlank(a.getId())) {
  273. result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"标签ID","标签ID"));return result;
  274. }
  275. if(StringUtils.isBlank(a.getName())) {
  276. result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"标签名称","标签名称"));return result;
  277. }
  278. result.data(jtTagService.updateJtTag(a));
  279. return result;
  280. }
  281. /*
  282. * 标签内容
  283. * */
  284. @RequestMapping(value="/tag/detail",method=RequestMethod.GET)
  285. private Result detailJtTag(JtTag a) {
  286. Result result=new Result();
  287. if(StringUtils.isBlank(a.getId())) {
  288. result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"标签ID","标签ID"));return result;
  289. }
  290. result.data(jtTagService.detailJtTag(a));
  291. return result;
  292. }
  293. /*
  294. * 标签列表
  295. * */
  296. @RequestMapping(value="/tag/list",method=RequestMethod.GET)
  297. private Result detailJtTag(JtTag a,Integer pageNo,Integer pageSize) {
  298. Result result=new Result();
  299. result.data(jtTagService.selectListJtTag(a,pageNo,pageSize));
  300. return result;
  301. }
  302. }