AdminJtBusinessController.java 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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. if(rc==-3)result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"","该品类已经存在,"));
  66. return result;
  67. }
  68. /*
  69. * 修改
  70. * */
  71. @RequestMapping(value="/category/update",method=RequestMethod.POST)
  72. private Result updateCategory(JtBusinessCategory jtBusinessCategory, Integer nextModule) {
  73. Result result=new Result();
  74. int re = jtBusinessService.updateCategory(jtBusinessCategory);
  75. result.setData(re);
  76. return result;
  77. }
  78. /*
  79. * 查询品类
  80. * */
  81. @RequestMapping(value="/category/list",method=RequestMethod.GET)
  82. private Result getCategoryList(JtBusinessCategory jtBusinessCategory,Integer pageNo,Integer pageSize) {
  83. Result result=new Result();
  84. result.setData(JtBusinessServiceWithCategoryMapper.getCategoryListByCondition(jtBusinessCategory,pageNo,pageSize));
  85. return result;
  86. }
  87. private void disposeCateParam(Result result,JtBusinessCategory jtBusinessCategory ) {
  88. if(jtBusinessCategory.getName() == null) {
  89. result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "名称不可为空", "名称"));
  90. return ;
  91. }else if(jtBusinessCategory.getName().length()>16){
  92. result.getError().add(buildError("品类名称长度不能超过16位", "品类名称长度不能超过16位"));
  93. return ;
  94. }
  95. if(jtBusinessCategory.getLayer() == null) {
  96. result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "层级不可为空", "层级"));
  97. return ;
  98. }
  99. if(jtBusinessCategory.getLayer()==2 && jtBusinessCategory.getSuperId()==null)
  100. {
  101. result.getError().add(buildError(ErrorConstants.PARAM_ERROR, "父级品类不可为空", "父级品类"));
  102. return ;
  103. }
  104. if(jtBusinessCategory.getLayer()>3 || jtBusinessCategory.getLayer()<1)
  105. {
  106. result.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "层级只能为一级或二级"));
  107. return ;
  108. }
  109. return ;
  110. }
  111. /*
  112. * 新增项目
  113. * */
  114. @RequestMapping(value="/project/apply",method=RequestMethod.POST)
  115. private Result insertJtBusinessProject(JtBusinessProject jtBusinessProject) {
  116. Result result=new Result();
  117. disposeProjectParam(result, jtBusinessProject);
  118. if(result.getError().size()<=0) {
  119. result.setData(jtBusinessService.insertProject(jtBusinessProject));
  120. }
  121. return result;
  122. }
  123. private void disposeProjectParam(Result result,JtBusinessProject jtBusinessProject ) {
  124. if(jtBusinessProject.getName() == null) {
  125. result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "名称不可为空", "名称"));
  126. return ;
  127. }
  128. if(jtBusinessProject.getCategoryId() == null) {
  129. result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "品类"));
  130. return ;
  131. }
  132. //todo 判断品类是否存在
  133. JtBusinessCategory jtBusinessCategory=jtBusinessService.getCategoryById(jtBusinessProject.getCategoryId());
  134. if(jtBusinessCategory==null ||jtBusinessCategory.getLayer()!=2) {
  135. result.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "二级品类未找到"));
  136. return ;
  137. }
  138. if(jtBusinessProject.getProvince()==null)
  139. {
  140. result.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "省份"));
  141. return ;
  142. }
  143. // if(jtBusinessProject.getCity()==null)
  144. // {
  145. // result.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "城市"));
  146. // return ;
  147. // }
  148. // if(jtBusinessProject.getPrice()==null)
  149. // {
  150. // result.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "价格"));
  151. // return ;
  152. // }
  153. return ;
  154. }
  155. /*
  156. * 项目详情
  157. * */
  158. @RequestMapping(value="/project/detail",method=RequestMethod.GET)
  159. private Result getProjectDetail(String id) {
  160. Result result=new Result();
  161. if(id == null) {
  162. result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"","id不能为空,"));
  163. return result;
  164. }
  165. result.setData(jtBusinessService.getBusinessProjectDetail(id));
  166. return result;
  167. }
  168. /*
  169. * 删除项目
  170. * */
  171. @RequestMapping(value="/project/delete",method=RequestMethod.GET)
  172. private Result deleteProjecById(String id) {
  173. Result result=new Result();
  174. if(id == null) {
  175. result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"","id不能为空,"));
  176. return result;
  177. }
  178. result.setData(jtBusinessService.deleteProjectById(id));
  179. return result;
  180. }
  181. @RequestMapping(value="/project/update",method=RequestMethod.POST)
  182. private Result updateProject(JtBusinessProject jtBusinessProject) {
  183. Result result=new Result();
  184. jtBusinessProject.setCreateTime(null);
  185. // jtBusinessProject.setId(null);
  186. jtBusinessProject.setNumber(null);
  187. disposeProjectParam(result, jtBusinessProject);
  188. if(result.getError().size()>0) {
  189. return result;
  190. }
  191. if(jtBusinessProject.getPrice()==null) {
  192. result.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "价格不可为空,"));
  193. }
  194. jtBusinessService.updateProject(jtBusinessProject);
  195. return result;
  196. }
  197. @RequestMapping(value = "/uploadPicture", method = RequestMethod.POST)
  198. public Result uploadPicture(HttpServletRequest req, String sign) {
  199. Result res = new Result();
  200. AttachmentType attachmentType = AttachmentType.getField(sign);
  201. if (attachmentType == AttachmentType.JT_BUSINESS_PICTURE
  202. ) {
  203. res.setData(handleFiles(res, "/jtVarieties/", false, req, sign, ""));
  204. } else {
  205. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "图片"));
  206. }
  207. return res;
  208. }
  209. @RequestMapping(value = "/project/uploadPicture", method = RequestMethod.POST)
  210. public Result uploadProjectPicture(HttpServletRequest req, String sign) {
  211. Result res = new Result();
  212. AttachmentType attachmentType = AttachmentType.getField(sign);
  213. if (attachmentType == AttachmentType.JT_PROJECT_PICTURE
  214. ) {
  215. res.setData(handleFiles(res, "/jtProjects/", false, req, sign, ""));
  216. } else {
  217. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "图片"));
  218. }
  219. return res;
  220. }
  221. @RequestMapping(value="/project/audit" ,method=RequestMethod.POST)
  222. private Result auditAchievemnt(String id,Integer auditResult,String auditInfo) {
  223. Result result=new Result();
  224. if(id == null || auditResult == null || auditResult.intValue()!=0 && auditResult.intValue()!=1)
  225. {
  226. result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"",""));return result;
  227. }
  228. JtBusinessProject jtBusinessProject = jtBusinessService.getBusinessProjectDetail(id);
  229. if(jtBusinessProject==null) {
  230. result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"未找到服务","服务Id"));return result;
  231. }
  232. /*if(jtBusinessProject.getAuditStatus()!= ProjectAuditStatus.SUBMIT.getCode()) {
  233. result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"未找到服务","当前状态不可审核"));return result;
  234. }*/
  235. if(auditResult.intValue() == 0){
  236. jtBusinessProject.setAuditStatus(ProjectAuditStatus.AUDITED.getCode());
  237. jtBusinessService.addJtCollectSearch(jtBusinessProject);
  238. }
  239. if(auditResult.intValue() == 1) jtBusinessProject.setAuditStatus(ProjectAuditStatus.UNAUDITED.getCode());
  240. jtBusinessProject.setAuditInfo(auditInfo);
  241. jtBusinessService.updateProject(jtBusinessProject);
  242. return result;
  243. }
  244. /**
  245. * 撤销项目
  246. * @param jtBusinessProject
  247. * @return
  248. */
  249. @RequestMapping(value="/project/annul" ,method=RequestMethod.POST)
  250. private Result projectAnnul(JtBusinessProject jtBusinessProject) {
  251. Result result=new Result();
  252. if (StringUtils.isBlank(jtBusinessProject.getId())) {
  253. result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"","撤销"));
  254. return result;
  255. }
  256. jtBusinessProject.setAuditStatus(3);
  257. jtBusinessService.updateJtCollectSearch(jtBusinessProject.getId());
  258. result.setData(jtBusinessService.updateProject(jtBusinessProject));
  259. return result;
  260. }
  261. /**
  262. * 项目是否热门
  263. * @param jtBusinessProject
  264. * @return
  265. */
  266. @RequestMapping(value="/project/ifHot" ,method=RequestMethod.POST)
  267. private Result projectIfHot(JtBusinessProject jtBusinessProject) {
  268. Result result=new Result();
  269. if (StringUtils.isBlank(jtBusinessProject.getId())) {
  270. result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"","撤销"));
  271. return result;
  272. }
  273. if (null==jtBusinessProject.getIsHot()) {
  274. result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"","撤销"));
  275. return result;
  276. }
  277. if (jtBusinessProject.getIsHot()==0) {
  278. jtBusinessProject.setIsHot(1);
  279. }else {
  280. jtBusinessProject.setIsHot(0);
  281. }
  282. result.setData(jtBusinessService.updateProject(jtBusinessProject));
  283. return result;
  284. }
  285. /*
  286. * 新增标签
  287. * */
  288. @RequestMapping(value="/tag/apply",method=RequestMethod.POST)
  289. private Result insertJtTag(JtTag a) {
  290. Result result=new Result();
  291. if(StringUtils.isBlank(a.getName())) {
  292. result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"标签名称","标签名称"));return result;
  293. }
  294. result.data(jtTagService.addTag(a));
  295. return result;
  296. }
  297. /*
  298. * 删除标签
  299. * */
  300. @RequestMapping(value="/tag/delete",method=RequestMethod.POST)
  301. private Result deleteJtTag(JtTag a) {
  302. Result result=new Result();
  303. if(StringUtils.isBlank(a.getId())) {
  304. result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"标签ID","标签ID"));return result;
  305. }
  306. result.data(jtTagService.deleteJtTag(a.getId()));
  307. return result;
  308. }
  309. /*
  310. * 修改标签
  311. * */
  312. @RequestMapping(value="/tag/update",method=RequestMethod.POST)
  313. private Result updateJtTag(JtTag a) {
  314. Result result=new Result();
  315. if(StringUtils.isBlank(a.getId())) {
  316. result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"标签ID","标签ID"));return result;
  317. }
  318. if(StringUtils.isBlank(a.getName())) {
  319. result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"标签名称","标签名称"));return result;
  320. }
  321. result.data(jtTagService.updateJtTag(a));
  322. return result;
  323. }
  324. /*
  325. * 标签内容
  326. * */
  327. @RequestMapping(value="/tag/detail",method=RequestMethod.GET)
  328. private Result detailJtTag(JtTag a) {
  329. Result result=new Result();
  330. if(StringUtils.isBlank(a.getId())) {
  331. result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"标签ID","标签ID"));return result;
  332. }
  333. result.data(jtTagService.detailJtTag(a));
  334. return result;
  335. }
  336. /*
  337. * 标签列表
  338. * */
  339. @RequestMapping(value="/tag/list",method=RequestMethod.GET)
  340. private Result detailJtTag(JtTag a,Integer pageNo,Integer pageSize) {
  341. Result result=new Result();
  342. result.data(jtTagService.selectListJtTag(a,pageNo,pageSize));
  343. return result;
  344. }
  345. /*
  346. * 上移品类
  347. * */
  348. @RequestMapping(value="/project/moveUp",method=RequestMethod.POST)
  349. private Result updateProjectMoveUp(String id) {
  350. Result result=new Result();
  351. if(StringUtils.isBlank(id)) {
  352. result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"品类ID","品类ID"));return result;
  353. }
  354. int x=jtBusinessService.updateProjectMoveUp(id);
  355. if(x==-1) {
  356. result.getError().add(buildError("已到顶部无法上移","已到顶部无法上移"));return result;
  357. }
  358. result.data(x);
  359. return result;
  360. }
  361. /*
  362. * 品类置顶
  363. * */
  364. @RequestMapping(value="/project/setTop",method=RequestMethod.POST)
  365. private Result updateProjectSetTop(String id) {
  366. Result result=new Result();
  367. if(StringUtils.isBlank(id)) {
  368. result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"品类ID","品类ID"));return result;
  369. }
  370. int x=jtBusinessService.updateProjectSetTop(id);
  371. if(x==-1) {
  372. result.getError().add(buildError("已到顶部无法上移","已到顶部无法上移"));return result;
  373. }
  374. result.data(x);
  375. return result;
  376. }
  377. }