AppUserController.java 32 KB

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