AppUserController.java 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853
  1. package com.goafanti.app.controller;
  2. import java.lang.reflect.InvocationTargetException;
  3. import java.util.ArrayList;
  4. import java.util.Date;
  5. import java.util.List;
  6. import java.util.UUID;
  7. import javax.annotation.Resource;
  8. import javax.servlet.http.HttpServletRequest;
  9. import javax.validation.Valid;
  10. import org.apache.commons.lang3.StringUtils;
  11. import org.apache.shiro.crypto.hash.SimpleHash;
  12. import org.springframework.beans.BeanUtils;
  13. import org.springframework.http.HttpMethod;
  14. import org.springframework.validation.BindingResult;
  15. import org.springframework.web.bind.annotation.RequestMapping;
  16. import org.springframework.web.bind.annotation.RequestMethod;
  17. import org.springframework.web.bind.annotation.RequestParam;
  18. import org.springframework.web.bind.annotation.ResponseBody;
  19. import org.springframework.web.bind.annotation.RestController;
  20. import com.alibaba.fastjson.JSONObject;
  21. import com.goafanti.achievement.bo.InputAchievement;
  22. import com.goafanti.achievement.service.AchievementInterestService;
  23. import com.goafanti.achievement.service.AchievementService;
  24. import com.goafanti.banners.service.BannersService;
  25. import com.goafanti.business.service.JtBusinessService;
  26. import com.goafanti.common.bo.Result;
  27. import com.goafanti.common.constant.AFTConstants;
  28. import com.goafanti.common.constant.ErrorConstants;
  29. import com.goafanti.common.constant.PageConstants;
  30. import com.goafanti.common.controller.CertifyApiController;
  31. import com.goafanti.common.enums.AchievementFields;
  32. import com.goafanti.common.enums.AttachmentType;
  33. import com.goafanti.common.enums.DemandFields;
  34. import com.goafanti.common.model.Achievement;
  35. import com.goafanti.common.model.Demand;
  36. import com.goafanti.common.model.JpushEasemobAccount;
  37. import com.goafanti.common.model.MessageConsumer;
  38. import com.goafanti.common.model.MessageFromSystem;
  39. import com.goafanti.common.model.MessageProducer;
  40. import com.goafanti.common.model.User;
  41. import com.goafanti.common.service.FieldGlossoryService;
  42. import com.goafanti.common.utils.DateUtils;
  43. import com.goafanti.common.utils.PasswordUtil;
  44. import com.goafanti.common.utils.VerifyCodeUtils;
  45. import com.goafanti.core.mybatis.page.Pagination;
  46. import com.goafanti.core.shiro.token.TokenManager;
  47. import com.goafanti.demand.bo.InputDemand;
  48. import com.goafanti.demand.service.DemandService;
  49. import com.goafanti.easemob.EasemobUtils;
  50. import com.goafanti.easemob.bo.EasemobInfo;
  51. import com.goafanti.message.bo.MessageBo;
  52. import com.goafanti.message.bo.MessageListBo;
  53. import com.goafanti.message.service.MessageService;
  54. import com.goafanti.news.service.NewsService;
  55. import com.goafanti.order.service.JtOrderService;
  56. import com.goafanti.portal.bo.AchievementObject;
  57. import com.goafanti.user.service.UserCareerService;
  58. import com.goafanti.user.service.UserIdentityService;
  59. import com.goafanti.user.service.UserInterestService;
  60. import com.goafanti.user.service.UserService;
  61. @RestController
  62. @RequestMapping(value = "/app/user")
  63. public class AppUserController extends CertifyApiController {
  64. @Resource
  65. private UserService userServiceImpl;
  66. @Resource
  67. private MessageService messageService;
  68. @Resource
  69. private EasemobUtils easemobUtils;
  70. @Resource
  71. private BannersService bannersService;
  72. @Resource
  73. private NewsService newsService;
  74. @Resource
  75. private AchievementService achievementService;
  76. @Resource
  77. private DemandService demandService;
  78. @Resource
  79. private UserCareerService userCareerService;
  80. @Resource
  81. private UserInterestService userInterestService;
  82. @Resource
  83. private UserIdentityService userIdentityService;
  84. @Resource
  85. private JtBusinessService jtBusinessService;
  86. @Resource
  87. AchievementInterestService achievementInterestService;
  88. @Resource
  89. JtOrderService jtOrderService;
  90. @Resource
  91. private FieldGlossoryService fieldGlossoryService;
  92. @Resource
  93. private UserService userService;
  94. @Resource(name = "passwordUtil")
  95. private PasswordUtil passwordUtil;
  96. @RequestMapping(value = "/uploadImg",method = RequestMethod.POST)
  97. public Result uploadAvatar(HttpServletRequest req){
  98. Result res = new Result();
  99. String headPortraitUrl = handleFile(res, "/avatar/", false, req, "");
  100. if(TokenManager.getToken() instanceof User){
  101. User u = new User();
  102. u.setId(TokenManager.getUserId());
  103. u.setHeadPortraitUrl(headPortraitUrl);
  104. userServiceImpl.updateByPrimaryKeySelective(u);
  105. }
  106. res.setData(headPortraitUrl);
  107. return res;
  108. }
  109. @RequestMapping(value = "/updateUser",method = RequestMethod.POST)
  110. public Result updateUser(User u){
  111. Result res = new Result();
  112. if(StringUtils.isBlank(u.getNickname())){
  113. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"用户昵称不能为空"));
  114. return res;
  115. }
  116. u.setId(TokenManager.getUserId());
  117. userServiceImpl.updateByPrimaryKeySelective(u);
  118. return res;
  119. }
  120. @RequestMapping(value = "/logout",method = RequestMethod.GET)
  121. public Result logout(HttpServletRequest request){
  122. Result res = new Result();
  123. TokenManager.logout();
  124. return res;
  125. }
  126. @RequestMapping(value = "/userInfo",method = RequestMethod.GET)
  127. public Result userInfo(HttpServletRequest request){
  128. Result res = new Result();
  129. res.setData(userServiceImpl.selectBaseInfo());
  130. return res;
  131. }
  132. @RequestMapping(value = "/index", method = RequestMethod.GET)
  133. public Result index(){
  134. Result res = new Result();
  135. res.setData(messageService.selectMessageWithGroup());
  136. return res;
  137. }
  138. @RequestMapping(value = "/listMessage", method = RequestMethod.POST)
  139. public Result listMessage(Integer subject,Integer sourceType,Integer pageNo,Integer pageSize){
  140. Result res = new Result();
  141. /*if(null == subject){
  142. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "必须指定消息类型"));
  143. return res;
  144. }*/
  145. User u = TokenManager.getUserToken();
  146. if(u != null){
  147. List<MessageBo> boList = messageService.selectSyncMessage(u.getId());
  148. if(boList != null && boList.size()>0){
  149. List<MessageProducer> producers = new ArrayList<MessageProducer>();
  150. List<MessageConsumer> consumers = new ArrayList<MessageConsumer>();
  151. MessageProducer mp = null;
  152. MessageConsumer mc = null;
  153. Date date = new Date();
  154. for(MessageBo bo : boList){
  155. mp = new MessageProducer();
  156. mp.setId(bo.getId());
  157. mp.setSendTime(date);
  158. producers.add(mp);
  159. mc = new MessageConsumer();
  160. mc.setId(UUID.randomUUID().toString());
  161. mc.setConsumerId(TokenManager.getUserId());
  162. mc.setMessageId(bo.getMessageId());
  163. consumers.add(mc);
  164. }
  165. if(producers.size()>0)messageService.updateMessageProducer(producers);
  166. //新增 message_consumer
  167. if(consumers.size()>0)messageService.insertBatchConsumer(consumers);
  168. }
  169. }
  170. res.setData(messageService.listPersonalMessage(subject,sourceType,pageNo,pageSize));
  171. return res;
  172. }
  173. /**
  174. * 同步绑定账号
  175. * @param uuid
  176. * @param registrationId
  177. * @param userName
  178. */
  179. @RequestMapping(value = "/synBindingAccount",method = RequestMethod.POST)
  180. private Result synBindingAccount(String uuid,String registrationId,String easemobName,String easemobPass){
  181. Result res = new Result();
  182. //更新 jpush_easemob_account
  183. messageService.updateJpushEasemobAccount(uuid, registrationId, easemobName,easemobPass);
  184. return res;
  185. }
  186. /*
  187. * 更新极光推送
  188. *
  189. * */
  190. @RequestMapping(value = "/updateJpushAccount",method = RequestMethod.POST)
  191. private Result updateJpush(String uuid,String registrationId,String easemobName,String easemobPass,String uid){
  192. Result res = new Result();
  193. //更新 jpush_easemob_account
  194. JpushEasemobAccount jpushEasemobAccount=messageService.selectSynAccByUid(uid);
  195. if(jpushEasemobAccount==null) {
  196. messageService.addJpushEasemobAccount(uuid, uid, easemobName, easemobPass);
  197. }
  198. messageService.updateJpushEasemobAccount(uuid, registrationId, easemobName,easemobPass);
  199. return res;
  200. }
  201. /**
  202. * 读取消息
  203. * @param messageId
  204. * @throws IllegalAccessException
  205. * @throws InvocationTargetException
  206. */
  207. @RequestMapping(value = "/readMessage",method = RequestMethod.GET)
  208. private Result readMessage(String messageId){
  209. Result res = new Result();
  210. if(StringUtils.isBlank(messageId)){
  211. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"", "消息编号为空"));
  212. return res;
  213. }
  214. //读取消息详情
  215. MessageFromSystem mfs = messageService.selectSystemMessageDetail(messageId);
  216. MessageListBo bo = new MessageListBo();
  217. bo.setCreateTime(mfs.getCreateTime()==null?"":DateUtils.formatDate(mfs.getCreateTime(), AFTConstants.YYYYMMDDHHMMSS));
  218. bo.setResourceType(String.valueOf(mfs.getResourceType()));
  219. bo.setSubject(String.valueOf(mfs.getSubject()));
  220. bo.setMessageId(mfs.getId());
  221. bo.setTitle(mfs.getTitle());
  222. bo.setBody(mfs.getBody());
  223. bo.setIsRead("1");//app操作已读
  224. res.setData(bo);
  225. //更新 message_consumer
  226. messageService.updateMessageConsumer(messageId);
  227. return res;
  228. }
  229. /**
  230. * 查询环信昵称和头像
  231. * @param easemobName
  232. * @return
  233. */
  234. @RequestMapping(value = "/getNicknameAndHeadPortrait",method = RequestMethod.GET)
  235. public Result getNicknameAndHeadPortrait(String easemobName){
  236. Result res = new Result();
  237. User user = userServiceImpl.selectByNumber(easemobName);
  238. JSONObject jsonObject = new JSONObject();
  239. jsonObject.put("nickName", user.getNickname());
  240. jsonObject.put("headPortraitUrl", null == user.getHeadPortraitUrl()?"":user.getHeadPortraitUrl());
  241. res.setData(jsonObject);
  242. return res;
  243. }
  244. /**
  245. * 关注功能
  246. */
  247. @RequestMapping(value = "/interestAdd", method = RequestMethod.POST)
  248. public Result Addinterest( Integer type,String objectId,String interest) {
  249. Result res = new Result();
  250. if (null==type) {
  251. res.getError().add(buildError( "分类错误!", "分类错误"));
  252. return res;
  253. }
  254. String uid=null;
  255. if (StringUtils.isNotBlank(TokenManager.getUserId())) {
  256. uid=TokenManager.getUserId();
  257. }
  258. if (Integer.valueOf(interest)==0) {
  259. res.setData(achievementInterestService.saveInterest( uid, type, objectId,interest));
  260. }else {
  261. res.setData(achievementInterestService.deleteInterest( uid, type, objectId,interest));
  262. }
  263. return res;
  264. }
  265. /**
  266. * 我的需求
  267. */
  268. @RequestMapping(value = "/demandList", method = RequestMethod.GET)
  269. public Result demandList(String pageNo, String pageSize) {
  270. Result res = new Result();
  271. Integer pNo = 1;
  272. Integer pSize = 10;
  273. if (StringUtils.isNumeric(pageSize)) {
  274. pSize = Integer.parseInt(pageSize);
  275. }
  276. if (StringUtils.isNumeric(pageNo)) {
  277. pNo = Integer.parseInt(pageNo);
  278. }
  279. if(TokenManager.getUserId() ==null) {
  280. res.getError().add(buildError(ErrorConstants.NON_LOGIN, "", ""));return res;
  281. }
  282. res.setData(demandService.listMyDemand( pNo, pSize));
  283. return res;
  284. }
  285. /**
  286. * 关注列表
  287. */
  288. @RequestMapping(value = "/interestList", method = RequestMethod.GET)
  289. public Result interestList(Integer type,String pageNo, String pageSize) {
  290. Result res = new Result();
  291. Integer pNo = 1;
  292. Integer pSize = 10;
  293. if (null==type||type<0||type>8) {
  294. res.getError().add(buildError( "类型选择错误", "类型选择错误"));
  295. }
  296. if (StringUtils.isNumeric(pageSize)) {
  297. pSize = Integer.parseInt(pageSize);
  298. }
  299. if (StringUtils.isNumeric(pageNo)) {
  300. pNo = Integer.parseInt(pageNo);
  301. }
  302. res.setData(demandService.selectinterest(type, pNo, pSize));
  303. return res;
  304. }
  305. /**
  306. * 成果详情
  307. * @param id
  308. * @return
  309. */
  310. @RequestMapping(value = "/achievementDetail", method = RequestMethod.GET)
  311. private Result userDetail(String id ) {
  312. Result res = new Result();
  313. if (StringUtils.isBlank(id)) {
  314. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"成果必须指定","成果"));
  315. return res;
  316. }
  317. res.setData(achievementService.selectAppUserOwnerDetail(id));
  318. return res;
  319. }
  320. /**
  321. * 需求详情
  322. */
  323. @RequestMapping(value = "/demandDetail", method = RequestMethod.GET)
  324. public Result DemandDetail(String id ) {
  325. Result res = new Result();
  326. if (StringUtils.isBlank(id)) {
  327. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"需求必须指定","需求"));
  328. return res;
  329. }
  330. res.setData(demandService.selectAppDemandDetail( id));
  331. return res;
  332. }
  333. /**
  334. * 新增成果
  335. */
  336. @RequestMapping(value = "/appAddAchievement", method = RequestMethod.POST)
  337. private Result appAddAchievement(@Valid InputAchievement ia, BindingResult bindingResult,
  338. String keyword1,String keyword2,String keyword3) {
  339. Result res = new Result();
  340. List<String> keyword=new ArrayList<>();
  341. if (!StringUtils.isBlank(keyword1)) {
  342. keyword.add(keyword1);
  343. }
  344. if (!StringUtils.isBlank(keyword2)) {
  345. keyword.add(keyword2);
  346. }
  347. if (!StringUtils.isBlank(keyword3)) {
  348. keyword.add(keyword3);
  349. }
  350. String[] keywords = keyword.toArray(new String[keyword.size()]);
  351. ia.setKeyword(StringUtils.join(keywords,","));
  352. if (bindingResult.hasErrors()) {
  353. res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
  354. AchievementFields.getFieldDesc(bindingResult.getFieldError().getField())));
  355. return res;
  356. }
  357. res = disposeInputAchievement(res, ia, keywords);
  358. if (!res.getError().isEmpty()) {
  359. return res;
  360. }
  361. Achievement a = new Achievement();
  362. BeanUtils.copyProperties(ia, a);
  363. res.setData(achievementService.saveAppAchievement(a, keywords));
  364. return res;
  365. }
  366. private Result disposeInputAchievement(Result res, InputAchievement ia, String[] keywords) {
  367. if (StringUtils.isBlank(ia.getName())) {
  368. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到成果名称", "成果名称"));
  369. return res;
  370. }
  371. if (null == ia.getCategory()) {
  372. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到数据类别", "数据类别"));
  373. return res;
  374. }
  375. if (StringUtils.isBlank(ia.getKeyword())) {
  376. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到关键词", "关键词"));
  377. return res;
  378. }
  379. if (null == keywords || keywords.length < 1) {
  380. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到关键词", "关键词"));
  381. return res;
  382. }
  383. for (int i = 0; i < keywords.length; i++) {
  384. if (AFTConstants.KEYWORDLENTH < keywords[i].length()) {
  385. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "关键词长度"));
  386. return res;
  387. }
  388. }
  389. return res;
  390. }
  391. /**
  392. * 新增需求
  393. */
  394. @RequestMapping(value = "/appAddDemand", method = RequestMethod.POST)
  395. public Result appAddDemand(@Valid InputDemand demand, BindingResult bindingResult,
  396. String keyword1,String keyword2,String keyword3,
  397. String validityPeriodFormattedDate) {
  398. Result res = new Result();
  399. List<String> keyword=new ArrayList<>();
  400. if (!StringUtils.isBlank(keyword1)) {
  401. keyword.add(keyword1);
  402. }
  403. if (!StringUtils.isBlank(keyword2)) {
  404. keyword.add(keyword2);
  405. }
  406. if (!StringUtils.isBlank(keyword3)) {
  407. keyword.add(keyword3);
  408. }
  409. String[] keywords = keyword.toArray(new String[keyword.size()]);
  410. demand.setKeyword(StringUtils.join(keywords,","));
  411. if (bindingResult.hasErrors()) {
  412. res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
  413. DemandFields.getFieldDesc(bindingResult.getFieldError().getField())));
  414. return res;
  415. }
  416. res = disposeDemand(res, demand, keywords);
  417. if (!res.getError().isEmpty()) {
  418. return res;
  419. }
  420. Demand d = new Demand();
  421. BeanUtils.copyProperties(demand, d);
  422. if (null == demand.getUrgentMoney()) {
  423. d.setUrgentMoney(demand.getUrgentMoney());
  424. }
  425. res.setData(demandService.saveAppUserDemand(d, validityPeriodFormattedDate, keywords));
  426. return res;
  427. }
  428. private Result disposeDemand(Result res, InputDemand demand, String[] keywords) {
  429. if (StringUtils.isBlank(demand.getName())) {
  430. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到需求名称", "需求名称"));
  431. return res;
  432. }
  433. if (StringUtils.isBlank(demand.getKeyword())) {
  434. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到关键词", "关键词"));
  435. return res;
  436. }
  437. if (null == keywords || keywords.length < 1) {
  438. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到关键词", "关键词"));
  439. return res;
  440. }
  441. if (null == demand.getIndustryCategoryA()) {
  442. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到行业类别", "行业类别"));
  443. return res;
  444. }
  445. if (null == demand.getDemandType()) {
  446. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到需求类型", "需求类型"));
  447. return res;
  448. }
  449. if (StringUtils.isBlank(demand.getProblemDes())) {
  450. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到问题说明", "问题说明"));
  451. return res;
  452. }
  453. /*for (int i = 0; i < keywords.length; i++) {
  454. if (AFTConstants.KEYWORDLENTH < keywords[i].length()) {
  455. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "关键词长度"));
  456. return res;
  457. }
  458. }*/
  459. return res;
  460. }
  461. /**
  462. * 成果、需求图片上传
  463. */
  464. @RequestMapping(value = "/uploadPicture", method = RequestMethod.POST)
  465. public Result uploadPicture(HttpServletRequest req, String sign) {
  466. Result res = new Result();
  467. AttachmentType attachmentType = AttachmentType.getField(sign);
  468. if (attachmentType == AttachmentType.ACHIEVEMENT_PICTURE) {
  469. res.setData(handleFiles(res, "/achievement/", false, req, sign, "achievement"));
  470. } else if (attachmentType==AttachmentType.DEMAND_PICTURE){
  471. res.setData(handleFiles(res, "/demand/", false, req, sign, "demand"));
  472. }else {
  473. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "附件标示"));
  474. }
  475. return res;
  476. }
  477. /**
  478. * 获取领域
  479. * @param pid
  480. * @param level
  481. * @return
  482. */
  483. @RequestMapping(value = "/getField", method = RequestMethod.POST)
  484. public Result getField(Integer pid, Integer level) {
  485. Result res = new Result();
  486. res.setData(fieldGlossoryService.getField(pid, level));
  487. return res;
  488. }
  489. /**
  490. * 获取环信登录账号,如果未注册则先注册
  491. */
  492. @RequestMapping(value = "/easemob", method = RequestMethod.GET)
  493. public Result getEasemob() {
  494. User u = TokenManager.getUserToken();
  495. if (u != null) {
  496. JSONObject res = easemobUtils.send(new EasemobInfo().uri("/users/" + u.getNumber()).method(HttpMethod.GET));
  497. JSONObject resultObj = new JSONObject();
  498. resultObj.put("easemobPass", new SimpleHash("md5", u.getId(), null, 1).toHex());
  499. resultObj.put("easemobName", String.valueOf(u.getNumber()));
  500. resultObj.put("nickname", StringUtils.isBlank(u.getNickname()) ? "技淘用户" + u.getNumber() : u.getNickname());
  501. if (res == null || StringUtils.equals("service_resource_not_found", (CharSequence) res.get("error"))) {
  502. easemobUtils.sendLater(
  503. new EasemobInfo().uri("/users/").data(resultObj.toJSONString()).method(HttpMethod.POST));
  504. }
  505. return res().data(resultObj);
  506. } else {
  507. return res().error(buildError("user only", "必须是登录会员才能访问。"));
  508. }
  509. }
  510. /**
  511. * 修改密码
  512. * @param newPwd
  513. * @param pwd
  514. * @return
  515. */
  516. @RequestMapping(value = "/updatePassword", method = RequestMethod.POST)
  517. @ResponseBody
  518. public Result resetPassword(String newPwd,String pwd) {
  519. Result res=new Result();
  520. if (StringUtils.isBlank(newPwd)) {
  521. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "新密码"));
  522. return res;
  523. }
  524. if (res.getError().isEmpty() && TokenManager.isLogin()) {
  525. User u = new User();
  526. User user = userService.selectByPrimaryKey(TokenManager.getUserId());
  527. u.setId(user.getId());
  528. u.setCreateTime(user.getCreateTime());
  529. u.setPassword(newPwd);
  530. u.setPassword(passwordUtil.getEncryptPwd(u));
  531. if (!user.getPassword().equals(passwordUtil.getEncryptPwd(pwd, user.getCreateTime()))) {
  532. res.getError().add(buildError(ErrorConstants.PWD_NOT_MATCH_ERROR));
  533. } else {
  534. res.setData(userService.updateByPrimaryKeySelective(u));
  535. }
  536. }
  537. return res;
  538. }
  539. private void cleanCodeSession() {
  540. VerifyCodeUtils.clearResetCode();
  541. VerifyCodeUtils.clearResetCodeTime();
  542. VerifyCodeUtils.clearMobileCode();
  543. VerifyCodeUtils.clearMobileCodeTime();
  544. }
  545. /*APP我的订单列表
  546. * userType-----0-购买者 1-出售者 2-管理员
  547. *
  548. * */
  549. @RequestMapping(value="/orderList",method = RequestMethod.GET)
  550. public Result getMyJtOrderList(Integer orderType,Integer userType,Integer pageNo,Integer pageSize) {
  551. Result result=new Result();
  552. if(userType==null || userType>1 || userType<0) {
  553. result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"","用户类型错误"));
  554. return result;
  555. }
  556. result.setData(jtOrderService.appSearchOrderList(orderType, userType, pageNo, pageSize));
  557. return result;
  558. }
  559. /*
  560. * APP我的成果列表
  561. **/
  562. @RequestMapping(value="/appAchievementList",method = RequestMethod.GET)
  563. public Result msyJtAchievementList(Integer auditStatus, String name,Integer dataCategory, String startDate,
  564. String endDate, Integer pageNo, Integer pageSize) {
  565. Result result=new Result();
  566. if(null==pageNo||pageNo<0)pageNo=1;
  567. if(null==pageSize||pageSize<0)pageSize=10;
  568. if(TokenManager.getUserId() ==null) {
  569. result.getError().add(buildError(ErrorConstants.NON_LOGIN, "", ""));return result;
  570. }
  571. Pagination<AchievementObject> p=achievementService.listMyAchievement(auditStatus, name, dataCategory,
  572. startDate, endDate, pageNo, pageSize);
  573. result.data(p);
  574. return result;
  575. }
  576. /**
  577. * 修改成果
  578. */
  579. @RequestMapping(value = "/updateAchievement", method = RequestMethod.POST)
  580. public Result updateAchievement(@Valid InputAchievement ia, BindingResult bindingResult,
  581. @RequestParam(name = "keywords[]", required = false) String[] keywords,
  582. @RequestParam(name = "publishPages[]", required = false) String[] publishPages) {
  583. Result res = new Result();
  584. if (bindingResult.hasErrors()) {
  585. res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
  586. AchievementFields.getFieldDesc(bindingResult.getFieldError().getField())));
  587. return res;
  588. }
  589. if (StringUtils.isBlank(ia.getId())) {
  590. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到成果ID", "成果ID"));
  591. return res;
  592. }
  593. /*if (!AchievementAuditStatus.CREATE.getCode().equals(ia.getAuditStatus())
  594. && !AchievementAuditStatus.SUBMIT.getCode().equals(ia.getAuditStatus())
  595. && !AchievementAuditStatus.UNAUDITED.getCode().equals(ia.getAuditStatus())) {
  596. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "当前状态无法提交审核!"));
  597. return res;
  598. }*/
  599. List<String> webPages = new ArrayList<String>();
  600. List<String> appPages = new ArrayList<String>();
  601. PageConstants.putAchievement(publishPages, webPages, appPages);
  602. res = disposeInputAchievement(res, ia, keywords,publishPages);
  603. if (!res.getError().isEmpty()) {
  604. return res;
  605. }
  606. /*if(webPages.size()==0 && appPages.size() == 0){
  607. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "页面参数错误","页面参数"));
  608. return res;
  609. }*/
  610. /*if(TokenManager.getUserId() ==null) {
  611. res.getError().add(buildError(ErrorConstants.NON_LOGIN, "", ""));return res;
  612. }*/
  613. Achievement a = new Achievement();
  614. BeanUtils.copyProperties(ia, a);
  615. a.setOwnerId(TokenManager.getUserId());
  616. res.setData(achievementService.updateAchievement(a, keywords, null,webPages,appPages));
  617. return res;
  618. }
  619. private Result disposeInputAchievement(Result res, InputAchievement ia, String[] keywords,String[] publishPages) {
  620. if (StringUtils.isBlank(ia.getName())) {
  621. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到成果名称", "成果名称"));
  622. return res;
  623. }
  624. if (null == ia.getCategory()) {
  625. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到数据类别", "数据类别"));
  626. return res;
  627. }
  628. if (null == ia.getFieldA()) {
  629. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到行业", "行业"));
  630. return res;
  631. }
  632. if (StringUtils.isBlank(ia.getKeyword())) {
  633. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到关键词", "关键词"));
  634. return res;
  635. }
  636. if (null == keywords || keywords.length < 1) {
  637. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到关键词", "关键词"));
  638. return res;
  639. }
  640. for (int i = 0; i < keywords.length; i++) {
  641. if (AFTConstants.KEYWORDLENTH < keywords[i].length()) {
  642. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "关键词长度"));
  643. return res;
  644. }
  645. }
  646. return res;
  647. }
  648. /**
  649. * 修改需求
  650. */
  651. @RequestMapping(value = "/updateDemand", method = RequestMethod.POST)
  652. public Result updateDemand(@Valid InputDemand demand, BindingResult bindingResult,
  653. @RequestParam(name = "keywords[]", required = false) String[] keywords,
  654. @RequestParam(name = "publishPages[]", required = false) String[] publishPages,
  655. String validityPeriodFormattedDate) {
  656. Result res = new Result();
  657. if (bindingResult.hasErrors()) {
  658. res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
  659. DemandFields.getFieldDesc(bindingResult.getFieldError().getField())));
  660. return res;
  661. }
  662. if (StringUtils.isBlank(demand.getId())) {
  663. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到需求ID", "需求ID"));
  664. return res;
  665. }
  666. /*if (!DemandAuditStatus.CREATE.getCode().equals(demand.getAuditStatus())
  667. && !DemandAuditStatus.UNAUDITED.getCode().equals(demand.getAuditStatus())
  668. && !DemandAuditStatus.REVOKE.getCode().equals(demand.getAuditStatus())) {
  669. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "当前状态无法提交审核!"));
  670. return res;
  671. }*/
  672. //demand.setAuditStatus(DemandAuditStatus.INAUDIT.getCode()); 两步操作,先保存后提交
  673. res = disposeDemand(res, demand, keywords, publishPages);
  674. if (!res.getError().isEmpty()) {
  675. return res;
  676. }
  677. List<String> webPages = new ArrayList<String>();
  678. List<String> appPages = new ArrayList<String>();
  679. // PageConstants.putDemand(publishPages, webPages, appPages);
  680. // if(webPages.size()==0 && appPages.size() == 0){
  681. // res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "页面参数错误"));
  682. // return res;
  683. // }
  684. Demand d = new Demand();
  685. BeanUtils.copyProperties(demand, d);
  686. d.setEmployerId(TokenManager.getUserId());
  687. res.setData(demandService.updateUserDemand(d, validityPeriodFormattedDate, keywords, webPages,appPages));
  688. return res;
  689. }
  690. private Result disposeDemand(Result res, InputDemand demand, String[] keywords,String[] publishPages) {
  691. if (StringUtils.isBlank(demand.getName())) {
  692. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到需求名称", "需求名称"));
  693. return res;
  694. }
  695. // if (!DemandDataCategory.USERDEMAND.getCode().equals(demand.getDataCategory())
  696. // && !DemandDataCategory.ORGDEMAND.getCode().equals(demand.getDataCategory())) {
  697. // res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "数据类型"));
  698. // return res;
  699. // }
  700. if (StringUtils.isBlank(demand.getKeyword())) {
  701. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到关键词", "关键词"));
  702. return res;
  703. }
  704. if (null == keywords || keywords.length < 1) {
  705. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到关键词", "关键词"));
  706. return res;
  707. }
  708. if (null == demand.getIndustryCategoryA()) {
  709. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到行业类别", "行业类别"));
  710. return res;
  711. }
  712. if (null == demand.getDemandType()) {
  713. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到需求类型", "需求类型"));
  714. return res;
  715. }
  716. if (StringUtils.isBlank(demand.getProblemDes())) {
  717. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到问题说明", "问题说明"));
  718. return res;
  719. }
  720. for (int i = 0; i < keywords.length; i++) {
  721. if (AFTConstants.KEYWORDLENTH < keywords[i].length()) {
  722. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "关键词长度"));
  723. return res;
  724. }
  725. }
  726. return res;
  727. }
  728. /*
  729. * 收藏列表 0 成果 1需求 2项目
  730. * */
  731. @RequestMapping(value="/appMyCollection",method=RequestMethod.GET)
  732. public Result listProjectIInterestedIn(Integer type,Integer pageNo,Integer pageSize) {
  733. Result res=new Result();
  734. if(StringUtils.isBlank(TokenManager.getUserId())) {
  735. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "当前用户未登陆"));
  736. return res;
  737. }
  738. if(null==type||type>3||type<0) {
  739. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "列表类型", "列表类型请指定"));
  740. return res;
  741. }
  742. if (type==0) {
  743. res.setData(achievementService.myCollectionAchievement(pageNo, pageSize));
  744. } else if(type==1){
  745. res.setData(demandService.myCollectionDemand(pageNo, pageSize));
  746. } else if(type==2){
  747. res.setData(jtBusinessService.myCollectionProject(pageNo,pageSize));
  748. }
  749. return res;
  750. }
  751. /*
  752. * 关注列表 -专家 顾问
  753. * */
  754. @RequestMapping(value="/appMyInterested",method=RequestMethod.GET)
  755. public Result appMyInterested(Integer type,Integer pageNo,Integer pageSize) {
  756. Result result=new Result();
  757. if(StringUtils.isBlank(TokenManager.getUserId())) {
  758. result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "当前用户未登陆"));
  759. return result;
  760. }
  761. result.setData(userIdentityService.appMyInterestedExpert(type,pageNo,pageSize));
  762. return result;
  763. }
  764. /**
  765. * 消息列表
  766. */
  767. @RequestMapping(value="/applistMessage",method=RequestMethod.GET)
  768. public Result applistMessage(Integer pageNo,Integer pageSize){
  769. Result result=new Result();
  770. if(StringUtils.isBlank(TokenManager.getUserId())) {
  771. result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "当前用户未登陆"));
  772. return result;
  773. }
  774. result.setData(messageService.applistMessage(pageNo,pageSize));
  775. return result;
  776. }
  777. /**
  778. * 读取消息
  779. */
  780. @RequestMapping(value="/appReadMessage",method=RequestMethod.GET)
  781. public Result updateAppReadMessage(String id){
  782. Result result=new Result();
  783. if(StringUtils.isBlank(id)) {
  784. result.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "消息ID错误"));
  785. return result;
  786. }
  787. result.setData(messageService.updateAppReadMessage(id));
  788. return result;
  789. }
  790. }