| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440 |
- package com.goafanti.app.controller;
- import java.util.ArrayList;
- import java.util.List;
- import javax.annotation.Resource;
- import javax.servlet.http.HttpServletRequest;
- import javax.validation.Valid;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.BeanUtils;
- import org.springframework.validation.BindingResult;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import org.springframework.web.bind.annotation.RestController;
- import com.alibaba.fastjson.JSONObject;
- import com.goafanti.achievement.bo.InputAchievement;
- import com.goafanti.achievement.service.AchievementInterestService;
- import com.goafanti.achievement.service.AchievementService;
- import com.goafanti.activity.service.ActivityService;
- import com.goafanti.banners.service.BannersService;
- import com.goafanti.common.bo.Result;
- import com.goafanti.common.constant.AFTConstants;
- import com.goafanti.common.constant.ErrorConstants;
- import com.goafanti.common.controller.BaseApiController;
- import com.goafanti.common.enums.AchievementFields;
- import com.goafanti.common.enums.AttachmentType;
- import com.goafanti.common.enums.DemandFields;
- import com.goafanti.common.model.Achievement;
- import com.goafanti.common.model.Demand;
- import com.goafanti.common.model.User;
- import com.goafanti.common.service.FieldGlossoryService;
- import com.goafanti.core.shiro.token.TokenManager;
- import com.goafanti.demand.bo.InputDemand;
- import com.goafanti.demand.service.DemandService;
- import com.goafanti.news.service.NewsService;
- import com.goafanti.user.service.UserCareerService;
- import com.goafanti.user.service.UserIdentityService;
- import com.goafanti.user.service.UserInterestService;
- import com.goafanti.user.service.UserService;
- @RestController
- @RequestMapping(path = "/app/user", method = RequestMethod.GET)
- public class AppUserController extends BaseApiController {
- @Resource
- private UserService userServiceImpl;
- @Resource
- private BannersService bannersService;
- @Resource
- private ActivityService activityService;
- @Resource
- private NewsService newsService;
- @Resource
- private AchievementService achievementService;
- @Resource
- private DemandService demandService;
- @Resource
- private UserCareerService userCareerService;
- @Resource
- private UserInterestService userInterestService;
- @Resource
- private UserIdentityService userIdentityService;
- @Resource
- AchievementInterestService achievementInterestService;
- @Resource
- private FieldGlossoryService fieldGlossoryService;
-
-
-
- @RequestMapping(value = "/uploadImg",method = RequestMethod.POST)
- public Result uploadAvatar(HttpServletRequest req){
- Result res = new Result();
- String headPortraitUrl = handleFile(res, "/avatar/", false, req, "");
- if(TokenManager.getToken() instanceof User){
- User u = new User();
- u.setId(TokenManager.getUserId());
- u.setHeadPortraitUrl(headPortraitUrl);
- userServiceImpl.updateByPrimaryKeySelective(u);
- }
- res.setData(headPortraitUrl);
- return res;
- }
- @RequestMapping(value = "/updateUser",method = RequestMethod.POST)
- public Result updateUser(User u){
- Result res = new Result();
- if(StringUtils.isBlank(u.getNickname())){
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"用户昵称不能为空"));
- return res;
- }
- u.setId(TokenManager.getUserId());
- userServiceImpl.updateByPrimaryKeySelective(u);
- return res;
- }
-
- @RequestMapping(value = "/logout",method = RequestMethod.GET)
- public Result logout(HttpServletRequest request){
- Result res = new Result();
- TokenManager.logout();
- return res;
- }
-
- @RequestMapping(value = "/userInfo",method = RequestMethod.GET)
- public Result userInfo(HttpServletRequest request){
- Result res = new Result();
- res.setData(userServiceImpl.selectBaseInfo());
- return res;
- }
-
- @RequestMapping(value = "/index", method = RequestMethod.GET)
- public Result index(){
- Result res = new Result();
- return res;
- }
-
-
-
-
- /**
- * 查询环信昵称和头像
- * @param easemobName
- * @return
- */
- @RequestMapping(value = "/getNicknameAndHeadPortrait",method = RequestMethod.GET)
- public Result getNicknameAndHeadPortrait(String easemobName){
- Result res = new Result();
- User user = userServiceImpl.selectByNumber(easemobName);
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("nickName", user.getNickname());
- jsonObject.put("headPortraitUrl", null == user.getHeadPortraitUrl()?"":user.getHeadPortraitUrl());
- res.setData(jsonObject);
- return res;
- }
-
-
- /**
- * 关注功能
- */
- @RequestMapping(value = "/interestAdd", method = RequestMethod.GET)
- public Result Addinterest( Integer type,String objectId,String interest) {
- Result res = new Result();
- if (null==type) {
- res.getError().add(buildError( "分类错误!", "分类错误"));
- return res;
- }
- String uid=null;
- if (StringUtils.isNotBlank(TokenManager.getUserId())) {
- uid=TokenManager.getUserId();
- }
- if (Integer.valueOf(interest)==0) {
- res.setData(achievementInterestService.saveInterest( uid, type, objectId,interest));
- }else {
- res.setData(achievementInterestService.deleteInterest( uid, type, objectId,interest));
- }
-
- return res;
- }
-
-
- /**
- * 我的成果
- */
- @RequestMapping(value = "/achievementList", method = RequestMethod.GET)
- private Result achievementList(String pageNo, String pageSize) {
- Result res = new Result();
- Integer pNo = 1;
- Integer pSize = 10;
- if (StringUtils.isNumeric(pageSize)) {
- pSize = Integer.parseInt(pageSize);
- }
- if (StringUtils.isNumeric(pageNo)) {
- pNo = Integer.parseInt(pageNo);
- }
- res.setData(achievementService.listAppMyAchievement(pNo, pSize));
- return res;
- }
- /**
- * 我的需求
- */
- @RequestMapping(value = "/demandList", method = RequestMethod.GET)
- public Result demandList(String pageNo, String pageSize) {
- Result res = new Result();
- Integer pNo = 1;
- Integer pSize = 10;
- if (StringUtils.isNumeric(pageSize)) {
- pSize = Integer.parseInt(pageSize);
- }
- if (StringUtils.isNumeric(pageNo)) {
- pNo = Integer.parseInt(pageNo);
- }
- res.setData(demandService.listMyDemand( pNo, pSize));
- return res;
- }
- /**
- * 关注列表
- */
- @RequestMapping(value = "/interestList", method = RequestMethod.GET)
- public Result interestList(Integer type,String pageNo, String pageSize) {
- Result res = new Result();
- Integer pNo = 1;
- Integer pSize = 10;
- if (null==type||type<0||type>8) {
- res.getError().add(buildError( "类型选择错误", "类型选择错误"));
- }
- if (StringUtils.isNumeric(pageSize)) {
- pSize = Integer.parseInt(pageSize);
- }
- if (StringUtils.isNumeric(pageNo)) {
- pNo = Integer.parseInt(pageNo);
- }
- res.setData(demandService.selectinterest(type, pNo, pSize));
- return res;
- }
- /**
- * 专家详情
- */
- @RequestMapping(value = "/expertsDetail", method = RequestMethod.GET)
- public Result expertsDetail(String uid) {
- Result res = new Result();
- if (StringUtils.isBlank(uid)) {
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"专家必须指定","专家"));
- return res;
- }
- res.setData(userIdentityService.expertsDetail( uid));
- return res;
- }
- /**
- * 成果详情
- * @param id
- * @return
- */
- @RequestMapping(value = "/achievementDetail", method = RequestMethod.GET)
- private Result userDetail(String id ) {
- Result res = new Result();
- if (StringUtils.isBlank(id)) {
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"成果必须指定","成果"));
- return res;
- }
- res.setData(achievementService.selectAppUserOwnerDetail(id));
- return res;
- }
- /**
- * 需求详情
- */
- @RequestMapping(value = "/demandDetail", method = RequestMethod.GET)
- public Result DemandDetail(String id ) {
- Result res = new Result();
- if (StringUtils.isBlank(id)) {
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"需求必须指定","需求"));
- return res;
- }
- res.setData(demandService.selectDemandDetail( id));
- return res;
- }
-
- /**
- * 新增成果
- */
-
- @RequestMapping(value = "/appAddAchievement", method = RequestMethod.POST)
- private Result appAddAchievement(@Valid InputAchievement ia, BindingResult bindingResult,
- String keyword1,String keyword2,String keyword3) {
- Result res = new Result();
- List<String> keyword=new ArrayList<>();
- if (!StringUtils.isBlank(keyword1)) {
- keyword.add(keyword1);
- }
- if (!StringUtils.isBlank(keyword2)) {
- keyword.add(keyword2);
- }
- if (!StringUtils.isBlank(keyword3)) {
- keyword.add(keyword3);
- }
- String[] keywords=(String[])keyword.toArray(new String[keyword.size()]);
- ia.setKeyword(StringUtils.join(keywords,","));
- if (bindingResult.hasErrors()) {
- res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
- AchievementFields.getFieldDesc(bindingResult.getFieldError().getField())));
- return res;
- }
-
- res = disposeInputAchievement(res, ia, keywords);
- if (!res.getError().isEmpty()) {
- return res;
- }
- Achievement a = new Achievement();
- BeanUtils.copyProperties(ia, a);
- res.setData(achievementService.saveAppAchievement(a, keywords));
- return res;
- }
-
- private Result disposeInputAchievement(Result res, InputAchievement ia, String[] keywords) {
- if (StringUtils.isBlank(ia.getName())) {
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到成果名称", "成果名称"));
- return res;
- }
- if (null == ia.getCategory()) {
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到数据类别", "数据类别"));
- return res;
- }
- if (StringUtils.isBlank(ia.getKeyword())) {
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到关键词", "关键词"));
- return res;
- }
- if (null == keywords || keywords.length < 1) {
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到关键词", "关键词"));
- return res;
- }
-
- if (null == ia.getCooperationMode()) {
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到合作方式", "合作方式"));
- return res;
- }
- for (int i = 0; i < keywords.length; i++) {
- if (AFTConstants.KEYWORDLENTH < keywords[i].length()) {
- res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "关键词长度"));
- return res;
- }
- }
- return res;
- }
-
- /**
- * 新增需求
- */
- @RequestMapping(value = "/appAddDemand", method = RequestMethod.POST)
- public Result appAddDemand(@Valid InputDemand demand, BindingResult bindingResult,
- String keyword1,String keyword2,String keyword3,
- String validityPeriodFormattedDate) {
- Result res = new Result();
- /*String[] keywords ;
- if (StringUtils.isNotEmpty(keyword3)) {
- keywords=new String[]{keyword1,keyword2};
- }else if (StringUtils.isNotEmpty(keyword2)) {
- keywords=new String[]{keyword1};
- }else {
- keywords=new String[]{keyword1,keyword2,keyword3};
- }
- if (null!=keywords) {
- demand.setKeyword(StringUtils.join(keywords,","));
- }*/
- if (bindingResult.hasErrors()) {
- res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
- DemandFields.getFieldDesc(bindingResult.getFieldError().getField())));
- return res;
- }
- res = disposeDemand(res, demand, null);
- if (!res.getError().isEmpty()) {
- return res;
- }
- Demand d = new Demand();
- BeanUtils.copyProperties(demand, d);
- if (StringUtils.isNotBlank(demand.getUrgentDays())) {
- d.setUrgentDays(demand.getUrgentDays());
- }
- if (null==demand.getUrgentMoney()) {
- d.setUrgentMoney(demand.getUrgentMoney());
- }
- res.setData(demandService.saveAppUserDemand(d, validityPeriodFormattedDate, null));
- return res;
- }
-
- private Result disposeDemand(Result res, InputDemand demand, String[] keywords) {
- if (StringUtils.isBlank(demand.getName())) {
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到需求名称", "需求名称"));
- return res;
- }
- /*if (StringUtils.isBlank(demand.getKeyword())) {
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到关键词", "关键词"));
- return res;
- }
- if (null == keywords || keywords.length < 1) {
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到关键词", "关键词"));
- return res;
- }*/
- if (null == demand.getIndustryCategoryA()) {
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到行业类别", "行业类别"));
- return res;
- }
- if (null == demand.getDemandType()) {
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到需求类型", "需求类型"));
- return res;
- }
- if (StringUtils.isBlank(demand.getProblemDes())) {
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到问题说明", "问题说明"));
- return res;
- }
-
- /*for (int i = 0; i < keywords.length; i++) {
- if (AFTConstants.KEYWORDLENTH < keywords[i].length()) {
- res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "关键词长度"));
- return res;
- }
- }*/
- return res;
- }
-
-
- /**
- * 成果、需求图片上传
- */
- @RequestMapping(value = "/uploadPicture", method = RequestMethod.POST)
- public Result uploadPicture(HttpServletRequest req, String sign) {
- Result res = new Result();
- AttachmentType attachmentType = AttachmentType.getField(sign);
- if (attachmentType == AttachmentType.ACHIEVEMENT_TECHNICAL_PICTURE) {
- res.setData(handleFiles(res, "/achievement/", false, req, sign, "achievement"));
- } else if (attachmentType==AttachmentType.DEMAND_PICTURE){
- res.setData(handleFiles(res, "/demand/", false, req, sign, "demand"));
- }else {
- res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "附件标示"));
- }
- return res;
- }
- /**
- * 获取领域
- * @param pid
- * @param level
- * @return
- */
- @RequestMapping(value = "/getField", method = RequestMethod.POST)
- public Result getField(Integer pid, Integer level) {
- Result res = new Result();
- res.setData(fieldGlossoryService.getField(pid, level));
- return res;
- }
-
- }
|