AppUserController.java 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. package com.goafanti.app.controller;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import javax.annotation.Resource;
  5. import javax.servlet.http.HttpServletRequest;
  6. import javax.validation.Valid;
  7. import org.apache.commons.lang3.StringUtils;
  8. import org.springframework.beans.BeanUtils;
  9. import org.springframework.validation.BindingResult;
  10. import org.springframework.web.bind.annotation.RequestMapping;
  11. import org.springframework.web.bind.annotation.RequestMethod;
  12. import org.springframework.web.bind.annotation.RestController;
  13. import com.alibaba.fastjson.JSONObject;
  14. import com.goafanti.achievement.bo.InputAchievement;
  15. import com.goafanti.achievement.service.AchievementInterestService;
  16. import com.goafanti.achievement.service.AchievementService;
  17. import com.goafanti.activity.service.ActivityService;
  18. import com.goafanti.banners.service.BannersService;
  19. import com.goafanti.common.bo.Result;
  20. import com.goafanti.common.constant.AFTConstants;
  21. import com.goafanti.common.constant.ErrorConstants;
  22. import com.goafanti.common.controller.BaseApiController;
  23. import com.goafanti.common.enums.AchievementFields;
  24. import com.goafanti.common.enums.AttachmentType;
  25. import com.goafanti.common.enums.DemandFields;
  26. import com.goafanti.common.model.Achievement;
  27. import com.goafanti.common.model.Demand;
  28. import com.goafanti.common.model.User;
  29. import com.goafanti.common.service.FieldGlossoryService;
  30. import com.goafanti.core.shiro.token.TokenManager;
  31. import com.goafanti.demand.bo.InputDemand;
  32. import com.goafanti.demand.service.DemandService;
  33. import com.goafanti.news.service.NewsService;
  34. import com.goafanti.user.service.UserCareerService;
  35. import com.goafanti.user.service.UserIdentityService;
  36. import com.goafanti.user.service.UserInterestService;
  37. import com.goafanti.user.service.UserService;
  38. @RestController
  39. @RequestMapping(path = "/app/user", method = RequestMethod.GET)
  40. public class AppUserController extends BaseApiController {
  41. @Resource
  42. private UserService userServiceImpl;
  43. @Resource
  44. private BannersService bannersService;
  45. @Resource
  46. private ActivityService activityService;
  47. @Resource
  48. private NewsService newsService;
  49. @Resource
  50. private AchievementService achievementService;
  51. @Resource
  52. private DemandService demandService;
  53. @Resource
  54. private UserCareerService userCareerService;
  55. @Resource
  56. private UserInterestService userInterestService;
  57. @Resource
  58. private UserIdentityService userIdentityService;
  59. @Resource
  60. AchievementInterestService achievementInterestService;
  61. @Resource
  62. private FieldGlossoryService fieldGlossoryService;
  63. @RequestMapping(value = "/uploadImg",method = RequestMethod.POST)
  64. public Result uploadAvatar(HttpServletRequest req){
  65. Result res = new Result();
  66. String headPortraitUrl = handleFile(res, "/avatar/", false, req, "");
  67. if(TokenManager.getToken() instanceof User){
  68. User u = new User();
  69. u.setId(TokenManager.getUserId());
  70. u.setHeadPortraitUrl(headPortraitUrl);
  71. userServiceImpl.updateByPrimaryKeySelective(u);
  72. }
  73. res.setData(headPortraitUrl);
  74. return res;
  75. }
  76. @RequestMapping(value = "/updateUser",method = RequestMethod.POST)
  77. public Result updateUser(User u){
  78. Result res = new Result();
  79. if(StringUtils.isBlank(u.getNickname())){
  80. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"用户昵称不能为空"));
  81. return res;
  82. }
  83. u.setId(TokenManager.getUserId());
  84. userServiceImpl.updateByPrimaryKeySelective(u);
  85. return res;
  86. }
  87. @RequestMapping(value = "/logout",method = RequestMethod.GET)
  88. public Result logout(HttpServletRequest request){
  89. Result res = new Result();
  90. TokenManager.logout();
  91. return res;
  92. }
  93. @RequestMapping(value = "/userInfo",method = RequestMethod.GET)
  94. public Result userInfo(HttpServletRequest request){
  95. Result res = new Result();
  96. res.setData(userServiceImpl.selectBaseInfo());
  97. return res;
  98. }
  99. @RequestMapping(value = "/index", method = RequestMethod.GET)
  100. public Result index(){
  101. Result res = new Result();
  102. return res;
  103. }
  104. /**
  105. * 查询环信昵称和头像
  106. * @param easemobName
  107. * @return
  108. */
  109. @RequestMapping(value = "/getNicknameAndHeadPortrait",method = RequestMethod.GET)
  110. public Result getNicknameAndHeadPortrait(String easemobName){
  111. Result res = new Result();
  112. User user = userServiceImpl.selectByNumber(easemobName);
  113. JSONObject jsonObject = new JSONObject();
  114. jsonObject.put("nickName", user.getNickname());
  115. jsonObject.put("headPortraitUrl", null == user.getHeadPortraitUrl()?"":user.getHeadPortraitUrl());
  116. res.setData(jsonObject);
  117. return res;
  118. }
  119. /**
  120. * 关注功能
  121. */
  122. @RequestMapping(value = "/interestAdd", method = RequestMethod.GET)
  123. public Result Addinterest( Integer type,String objectId,String interest) {
  124. Result res = new Result();
  125. if (null==type) {
  126. res.getError().add(buildError( "分类错误!", "分类错误"));
  127. return res;
  128. }
  129. String uid=null;
  130. if (StringUtils.isNotBlank(TokenManager.getUserId())) {
  131. uid=TokenManager.getUserId();
  132. }
  133. if (Integer.valueOf(interest)==0) {
  134. res.setData(achievementInterestService.saveInterest( uid, type, objectId,interest));
  135. }else {
  136. res.setData(achievementInterestService.deleteInterest( uid, type, objectId,interest));
  137. }
  138. return res;
  139. }
  140. /**
  141. * 我的成果
  142. */
  143. @RequestMapping(value = "/achievementList", method = RequestMethod.GET)
  144. private Result achievementList(String pageNo, String pageSize) {
  145. Result res = new Result();
  146. Integer pNo = 1;
  147. Integer pSize = 10;
  148. if (StringUtils.isNumeric(pageSize)) {
  149. pSize = Integer.parseInt(pageSize);
  150. }
  151. if (StringUtils.isNumeric(pageNo)) {
  152. pNo = Integer.parseInt(pageNo);
  153. }
  154. res.setData(achievementService.listAppMyAchievement(pNo, pSize));
  155. return res;
  156. }
  157. /**
  158. * 我的需求
  159. */
  160. @RequestMapping(value = "/demandList", method = RequestMethod.GET)
  161. public Result demandList(String pageNo, String pageSize) {
  162. Result res = new Result();
  163. Integer pNo = 1;
  164. Integer pSize = 10;
  165. if (StringUtils.isNumeric(pageSize)) {
  166. pSize = Integer.parseInt(pageSize);
  167. }
  168. if (StringUtils.isNumeric(pageNo)) {
  169. pNo = Integer.parseInt(pageNo);
  170. }
  171. res.setData(demandService.listMyDemand( pNo, pSize));
  172. return res;
  173. }
  174. /**
  175. * 关注列表
  176. */
  177. @RequestMapping(value = "/interestList", method = RequestMethod.GET)
  178. public Result interestList(Integer type,String pageNo, String pageSize) {
  179. Result res = new Result();
  180. Integer pNo = 1;
  181. Integer pSize = 10;
  182. if (null==type||type<0||type>8) {
  183. res.getError().add(buildError( "类型选择错误", "类型选择错误"));
  184. }
  185. if (StringUtils.isNumeric(pageSize)) {
  186. pSize = Integer.parseInt(pageSize);
  187. }
  188. if (StringUtils.isNumeric(pageNo)) {
  189. pNo = Integer.parseInt(pageNo);
  190. }
  191. res.setData(demandService.selectinterest(type, pNo, pSize));
  192. return res;
  193. }
  194. /**
  195. * 专家详情
  196. */
  197. @RequestMapping(value = "/expertsDetail", method = RequestMethod.GET)
  198. public Result expertsDetail(String uid) {
  199. Result res = new Result();
  200. if (StringUtils.isBlank(uid)) {
  201. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"专家必须指定","专家"));
  202. return res;
  203. }
  204. res.setData(userIdentityService.expertsDetail( uid));
  205. return res;
  206. }
  207. /**
  208. * 成果详情
  209. * @param id
  210. * @return
  211. */
  212. @RequestMapping(value = "/achievementDetail", method = RequestMethod.GET)
  213. private Result userDetail(String id ) {
  214. Result res = new Result();
  215. if (StringUtils.isBlank(id)) {
  216. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"成果必须指定","成果"));
  217. return res;
  218. }
  219. res.setData(achievementService.selectAppUserOwnerDetail(id));
  220. return res;
  221. }
  222. /**
  223. * 需求详情
  224. */
  225. @RequestMapping(value = "/demandDetail", method = RequestMethod.GET)
  226. public Result DemandDetail(String id ) {
  227. Result res = new Result();
  228. if (StringUtils.isBlank(id)) {
  229. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"需求必须指定","需求"));
  230. return res;
  231. }
  232. res.setData(demandService.selectDemandDetail( id));
  233. return res;
  234. }
  235. /**
  236. * 新增成果
  237. */
  238. @RequestMapping(value = "/appAddAchievement", method = RequestMethod.POST)
  239. private Result appAddAchievement(@Valid InputAchievement ia, BindingResult bindingResult,
  240. String keyword1,String keyword2,String keyword3) {
  241. Result res = new Result();
  242. List<String> keyword=new ArrayList<>();
  243. if (!StringUtils.isBlank(keyword1)) {
  244. keyword.add(keyword1);
  245. }
  246. if (!StringUtils.isBlank(keyword2)) {
  247. keyword.add(keyword2);
  248. }
  249. if (!StringUtils.isBlank(keyword3)) {
  250. keyword.add(keyword3);
  251. }
  252. String[] keywords=(String[])keyword.toArray(new String[keyword.size()]);
  253. ia.setKeyword(StringUtils.join(keywords,","));
  254. if (bindingResult.hasErrors()) {
  255. res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
  256. AchievementFields.getFieldDesc(bindingResult.getFieldError().getField())));
  257. return res;
  258. }
  259. res = disposeInputAchievement(res, ia, keywords);
  260. if (!res.getError().isEmpty()) {
  261. return res;
  262. }
  263. Achievement a = new Achievement();
  264. BeanUtils.copyProperties(ia, a);
  265. res.setData(achievementService.saveAppAchievement(a, keywords));
  266. return res;
  267. }
  268. private Result disposeInputAchievement(Result res, InputAchievement ia, String[] keywords) {
  269. if (StringUtils.isBlank(ia.getName())) {
  270. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到成果名称", "成果名称"));
  271. return res;
  272. }
  273. if (null == ia.getCategory()) {
  274. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到数据类别", "数据类别"));
  275. return res;
  276. }
  277. if (StringUtils.isBlank(ia.getKeyword())) {
  278. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到关键词", "关键词"));
  279. return res;
  280. }
  281. if (null == keywords || keywords.length < 1) {
  282. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到关键词", "关键词"));
  283. return res;
  284. }
  285. if (null == ia.getCooperationMode()) {
  286. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到合作方式", "合作方式"));
  287. return res;
  288. }
  289. for (int i = 0; i < keywords.length; i++) {
  290. if (AFTConstants.KEYWORDLENTH < keywords[i].length()) {
  291. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "关键词长度"));
  292. return res;
  293. }
  294. }
  295. return res;
  296. }
  297. /**
  298. * 新增需求
  299. */
  300. @RequestMapping(value = "/appAddDemand", method = RequestMethod.POST)
  301. public Result appAddDemand(@Valid InputDemand demand, BindingResult bindingResult,
  302. String keyword1,String keyword2,String keyword3,
  303. String validityPeriodFormattedDate) {
  304. Result res = new Result();
  305. /*String[] keywords ;
  306. if (StringUtils.isNotEmpty(keyword3)) {
  307. keywords=new String[]{keyword1,keyword2};
  308. }else if (StringUtils.isNotEmpty(keyword2)) {
  309. keywords=new String[]{keyword1};
  310. }else {
  311. keywords=new String[]{keyword1,keyword2,keyword3};
  312. }
  313. if (null!=keywords) {
  314. demand.setKeyword(StringUtils.join(keywords,","));
  315. }*/
  316. if (bindingResult.hasErrors()) {
  317. res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
  318. DemandFields.getFieldDesc(bindingResult.getFieldError().getField())));
  319. return res;
  320. }
  321. res = disposeDemand(res, demand, null);
  322. if (!res.getError().isEmpty()) {
  323. return res;
  324. }
  325. Demand d = new Demand();
  326. BeanUtils.copyProperties(demand, d);
  327. if (StringUtils.isNotBlank(demand.getUrgentDays())) {
  328. d.setUrgentDays(demand.getUrgentDays());
  329. }
  330. if (null==demand.getUrgentMoney()) {
  331. d.setUrgentMoney(demand.getUrgentMoney());
  332. }
  333. res.setData(demandService.saveAppUserDemand(d, validityPeriodFormattedDate, null));
  334. return res;
  335. }
  336. private Result disposeDemand(Result res, InputDemand demand, String[] keywords) {
  337. if (StringUtils.isBlank(demand.getName())) {
  338. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到需求名称", "需求名称"));
  339. return res;
  340. }
  341. /*if (StringUtils.isBlank(demand.getKeyword())) {
  342. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到关键词", "关键词"));
  343. return res;
  344. }
  345. if (null == keywords || keywords.length < 1) {
  346. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到关键词", "关键词"));
  347. return res;
  348. }*/
  349. if (null == demand.getIndustryCategoryA()) {
  350. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到行业类别", "行业类别"));
  351. return res;
  352. }
  353. if (null == demand.getDemandType()) {
  354. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到需求类型", "需求类型"));
  355. return res;
  356. }
  357. if (StringUtils.isBlank(demand.getProblemDes())) {
  358. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到问题说明", "问题说明"));
  359. return res;
  360. }
  361. /*for (int i = 0; i < keywords.length; i++) {
  362. if (AFTConstants.KEYWORDLENTH < keywords[i].length()) {
  363. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "关键词长度"));
  364. return res;
  365. }
  366. }*/
  367. return res;
  368. }
  369. /**
  370. * 成果、需求图片上传
  371. */
  372. @RequestMapping(value = "/uploadPicture", method = RequestMethod.POST)
  373. public Result uploadPicture(HttpServletRequest req, String sign) {
  374. Result res = new Result();
  375. AttachmentType attachmentType = AttachmentType.getField(sign);
  376. if (attachmentType == AttachmentType.ACHIEVEMENT_TECHNICAL_PICTURE) {
  377. res.setData(handleFiles(res, "/achievement/", false, req, sign, "achievement"));
  378. } else if (attachmentType==AttachmentType.DEMAND_PICTURE){
  379. res.setData(handleFiles(res, "/demand/", false, req, sign, "demand"));
  380. }else {
  381. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "附件标示"));
  382. }
  383. return res;
  384. }
  385. /**
  386. * 获取领域
  387. * @param pid
  388. * @param level
  389. * @return
  390. */
  391. @RequestMapping(value = "/getField", method = RequestMethod.POST)
  392. public Result getField(Integer pid, Integer level) {
  393. Result res = new Result();
  394. res.setData(fieldGlossoryService.getField(pid, level));
  395. return res;
  396. }
  397. }