package com.wechat.controller;

import com.wechat.common.CommonHelper;
import com.wechat.common.Constants;
import com.wechat.common.utils.StringsUtils;
import com.wechat.global.CustomException;
import com.wechat.global.base.dao.PagingResult;
import com.wechat.global.message.InfoMsg;
import com.wechat.model.dbEntity.MdeEducationExperience;
import com.wechat.model.dbEntity.MdeUser;
import com.wechat.model.dbEntity.MdeUserCv;
import com.wechat.model.dbEntity.MdeWorkExperience;
import com.wechat.model.dto.OrderListDto;
import com.wechat.model.dto.PositionCvHisDto;
import com.wechat.model.dto.SubscribedPositionsDto;
import com.wechat.model.dto.TrendsDto;
import com.wechat.model.requestDto.*;
import com.wechat.model.responseDto.*;
import com.wechat.service.CommonService;
import com.wechat.service.MdeUserService;
import com.wechat.service.PersonCeneterService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * 个人中心
 *
 * @author tangwc
 */
@Controller
@RequestMapping(value = "person")
public class PersonCeneterController {
    @Autowired
    private PersonCeneterService personCenterService;
    @Autowired
    private CommonService commonService;
    @Resource
    private CommonHelper commonHelper;

    @Autowired
    private MdeUserService userService;

    @Value("#{configProperties['upload.base.path']}")
    private String basePackagePath;
    @Value("#{configProperties['upload.path.image']}")
    private String baseImagePackagePath;
    @Value("#{configProperties['upload.path.image.album']}")
    private String photoAlbumPath;
    @Value("#{configProperties['url.base']}")
    private String urlBase;


    /**
     * 个人中心 初始化
     *
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping(method = RequestMethod.GET)
    @ResponseBody
    public ResultEntity<Map<String, Object>> init(HttpServletRequest request) throws Exception {
        String userCode = commonService.getUserCode(request);
        Map<String, Object> map = personCenterService.init(userCode);
        return new ResultEntity<Map<String, Object>>(InfoMsg.SUCCESS_REQUEST, map);
    }


    /**
     * 获取用户信息
     *
     * @param userCode
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "getPersonInformation", method = RequestMethod.GET)
    @ResponseBody
    public ResultEntity<PersonInformationReq> getPersonInformation(HttpServletRequest request) throws Exception {
        String userCode = commonService.getUserCode(request);
        String lang = commonService.getLanguage(request);
        MdeUser user = personCenterService.getPersonInformation(userCode, lang);

        //结果集封装
        PersonInformationReq req = new PersonInformationReq();
        //将user和返回类中相同属性复制至返回集中
        BeanUtils.copyProperties(user, req);
        req.setShortInviter(commonService.getShortInviter(userCode));
        req.setShareCode(commonHelper.getShareCodeAes(userCode, user.getCreateDate()));
        //获取PC底部广告图并赋值
        req.setAdListPc(commonService.getAdImages(Constants.PC_PERSON_DETAIL_BOTTOM));
        //获取手机中部广告图并赋值
        req.setAdListPhone(commonService.getAdImages(Constants.SJ_PERSONCENTER_MIDDLE));

        return new ResultEntity<PersonInformationReq>(InfoMsg.SUCCESS_REQUEST, req);
    }

    /**
     * 修改用户基本信息
     *
     * @param info
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "modifyBaseInfo", method = RequestMethod.POST)
    @ResponseBody
    public ResultEntity<String> modifyBaseInfo(HttpServletRequest req) throws Exception {

        return personCenterService.modifyBaseInfo(req);
    }

    /**
     * 修改企业联系人信息
     *
     * @param info
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "modifyEntContacts", method = RequestMethod.POST)
    @ResponseBody
    public ResultEntity<String> modifyEntContacts(HttpServletRequest req) throws Exception {

        return personCenterService.modifyEntContacts(req);
    }

    /**
     * 修改用户简介信息
     *
     * @param info
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "modifyIntroduction", method = RequestMethod.POST)
    @ResponseBody
    public ResultEntity<String> modifyIntroduction(HttpServletRequest req) throws Exception {

        return personCenterService.modifyIntroduction(req);
    }

    /**
     * 投递简历情况详情
     *
     * @param info
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "postPositionDetailInfo", method = RequestMethod.GET)
    @ResponseBody
    public ResultEntity<List<PositionCvHisDto>> postPositionDetailInfo(HttpServletRequest request, @RequestParam String status) throws Exception {
        String userCode = commonService.getUserCode(request);
        List<PositionCvHisDto> list = personCenterService.postPositionDetailInfo(userCode, status);

        return new ResultEntity<List<PositionCvHisDto>>(InfoMsg.SUCCESS_REQUEST, list);
    }

    /**
     * 酒店(职位)邀请信息获取
     *
     * @param userCode
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "getRecievedHotelInvationInfo", method = RequestMethod.POST)
    @ResponseBody
    public ResultEntity<PagingResult<HotelInvitationInfoResp>> getRecievedHotelInvationInfo(@RequestBody Map<String, String> param, HttpServletRequest request) throws Exception {
        param.put("userCode", commonService.getUserCode(request));
        PagingResult<HotelInvitationInfoResp> pageResult = personCenterService.getRecievedHotelInvationInfo(param, request);
        return new ResultEntity<PagingResult<HotelInvitationInfoResp>>(InfoMsg.SUCCESS_REQUEST, pageResult);
    }

    /**
     * 我的互动 - 收到的评论列表
     *
     * @param userCode
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "myInteractionOfTrends", method = RequestMethod.GET)
    @ResponseBody
    public ResultEntity<List<TrendCommentInfo>> myInteractionOfTrends(HttpServletRequest request) throws Exception {
        String userCode = commonService.getUserCode(request);
        List<TrendCommentInfo> list = personCenterService.myInteractionOfTrends(userCode);

        return new ResultEntity<List<TrendCommentInfo>>(InfoMsg.SUCCESS_REQUEST, list);
    }

    /**
     * 我的互动 - 点赞列表
     *
     * @param userCode
     * @return
     * @throws Exception
     */
//	@RequestMapping(value = "myThumbUp", method = RequestMethod.GET)
//	@ResponseBody
//	public ResultEntity<List<MdeTrends>> myThumbUp(HttpServletRequest request) throws Exception {
//		String userCode = commonService.getUserCode(request);
//		String lang = commonService.getLanguage(request);
//		List<MdeTrends> list = personCenterService.myThumbUp(userCode,lang);
//
//		return new ResultEntity<List<MdeTrends>>(InfoMsg.SUCCESS_REQUEST, list);
//	}

    /**
     * 获取 工作经历、教育经历、简历列表
     *
     * @param userCode
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "getMyCVInfos", method = RequestMethod.GET)
    @ResponseBody
    public ResultEntity<Map<String, Object>> getMyCVInfos(HttpServletRequest request) throws Exception {
        String userCode = commonService.getUserCode(request);
        String lang = commonService.getLanguage(request);
        Map<String, Object> map = personCenterService.getMyCVInfos(userCode, lang);

        return new ResultEntity<Map<String, Object>>(InfoMsg.SUCCESS_REQUEST, map);
    }

    /**
     * 新增(修改)工作履历
     *
     * @param workExperience
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "modefyWorkExperience", method = RequestMethod.POST)
    @ResponseBody
    public ResultEntity<String> modefyWorkExperience(@Validated @RequestBody MdeWorkExperience workExperience, HttpServletRequest request)
            throws Exception {
        String userCode = commonService.getUserCode(request);
        workExperience.setUserCode(userCode + "");
        return personCenterService.modefyWorkExperience(workExperience, request);
    }

    /**
     * 删除工作履历
     *
     * @param request
     * @param workExperience -> workId
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "deleteWorkExperience", method = RequestMethod.POST)
    @ResponseBody
    public ResultEntity<Integer> deleteWorkExperience(HttpServletRequest request,
                                                      @RequestBody Map<String, Integer> workExperience) throws Exception {
        Integer workId = workExperience.get("workId");
        personCenterService.deleteAndUpdatePositionTitle(workId, request);
        return new ResultEntity<Integer>(InfoMsg.SUCCESS_REQUEST);
    }

    /**
     * 修改职位头衔
     *
     * @param workExperience workId
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "modefyPositionTitle", method = RequestMethod.POST)
    @ResponseBody
    public ResultEntity<Integer> modefyPositionTitle(HttpServletRequest request,
                                                     @RequestBody Map<String, Integer> workExperience) throws Exception {
        String userCode = commonService.getUserCode(request);
        Integer workId = workExperience.get("workId");
        if (workId == null)
            throw new CustomException(InfoMsg.ERROR_EMPTY_REQUEST);
        int i = personCenterService.modefyPositionTitle(workId, userCode);

        return new ResultEntity<Integer>(InfoMsg.SUCCESS_REQUEST, i);
    }

    /**
     * 新增(修改)教育经历
     *
     * @param educationExperience
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "modefyEducationExperience", method = RequestMethod.POST)
    @ResponseBody
    public ResultEntity<Integer> modefyEducationExperience(
            @Validated(value = MdeEducationExperience.SaveGroup.class) @RequestBody MdeEducationExperience educationExperience,
            HttpServletRequest req)
            throws Exception {
        String lang = commonService.getLanguage(req);
        int i = personCenterService.modefyEducationExperience(educationExperience, lang);

        return new ResultEntity<Integer>(InfoMsg.SUCCESS_REQUEST, i);
    }

    /**
     * 删除教育履历
     *
     * @param request
     * @param workExperience
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "deleteEducationExperience", method = RequestMethod.POST)
    @ResponseBody
    public ResultEntity<Integer> deleteEducationExperience(HttpServletRequest request,
                                                           @RequestBody Map<String, Integer> educationExperience) throws Exception {
        String userCode = commonService.getUserCode(request);
        Integer eduId = educationExperience.get("eduId");
        if (eduId == null)
            throw new CustomException(InfoMsg.ERROR_EMPTY_REQUEST);
        int i = personCenterService.deleteEducationExperience(educationExperience.get("eduId"), userCode);

        return new ResultEntity<Integer>(InfoMsg.SUCCESS_REQUEST, i);
    }

    /**
     * 删除简历附件
     *
     * @param userCv
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "deleteUserCv", method = RequestMethod.POST)
    @ResponseBody
    public ResultEntity<Integer> deleteUserCv(HttpServletRequest request, @RequestBody Map<String, Long> map) throws Exception {
        String userCode = commonService.getUserCode(request);

        Long cvId = map.get("cvId");
        if (cvId == null)
            throw new CustomException(InfoMsg.ERROR_EMPTY_REQUEST);
        int i = personCenterService.deleteUserCv(cvId, userCode);
        return new ResultEntity<Integer>(InfoMsg.SUCCESS_REQUEST, i);
    }

    /**
     * 上传简历附件
     *
     * @param userCv
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "uploadUserCv", method = RequestMethod.POST)
    @ResponseBody
    public ResultEntity<Integer> uploadUserCv(HttpServletRequest request) throws Exception {
        ResultEntity<Integer> rest = new ResultEntity<Integer>();
        String userCode = commonService.getUserCode(request);
        String system = commonHelper.getDeviceType(request).getSystem();
        List<MultipartFile> file = ((MultipartHttpServletRequest) request).getFiles("file");
        if (file.size() != 1) {
            rest.setMsg(InfoMsg.ERROR_EMPTY_REQUEST);
        } else {
            try {
                int i = personCenterService.uploadUserCv(file.get(0), userCode + "", system);
                rest.setResult(i);
            } catch (CustomException e) {
                rest.setMsg(e.getMessage());
                rest.setCode(e.getCode());
            }
        }

        return rest;
    }

    /**
     * 获取简历
     *
     * @param userCv
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "getUserCv", method = RequestMethod.GET)
    @ResponseBody
    public ResultEntity<List<MdeUserCv>> getUserCv(HttpServletRequest request) throws Exception {
        String userCode = commonService.getUserCode(request);
        List<MdeUserCv> list = personCenterService.getUserCv(userCode);
        return new ResultEntity<List<MdeUserCv>>(InfoMsg.SUCCESS_REQUEST, list);
    }

    /**
     * 获取收藏的职位列表
     *
     * @param userCode
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "getCollectionJobList", method = RequestMethod.GET)
    @ResponseBody
    public ResultEntity<List<JobAdvertisedRes>> getCollectionJobList(HttpServletRequest request) throws Exception {
        String userCode = commonService.getUserCode(request);
        String lang = commonService.getLanguage(request);
        List<JobAdvertisedRes> list = personCenterService.getCollectionJobList(userCode, lang);
        return new ResultEntity<List<JobAdvertisedRes>>(InfoMsg.SUCCESS_REQUEST, list);
    }

    /**
     * 修改用户头像
     *
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "changeUserHeadPortrait", method = RequestMethod.POST)
    @ResponseBody
    public ResultEntity<String> changeUserHeadPortrait(HttpServletRequest request) throws Exception {
        List<MultipartFile> file = ((MultipartHttpServletRequest) request).getFiles("headPortrait");
        String userCode = commonService.getUserCode(request);
        if (file.size() != 1) {
            return new ResultEntity<String>(InfoMsg.ERROR_EMPTY_REQUEST);
        }
        String path = personCenterService.changeUserHeadPortrait(file.get(0), userCode);
        return new ResultEntity<String>(InfoMsg.SUCCESS_REQUEST, path);
    }

    /**
     * 获取我的动态
     *
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "getMyTrends", method = RequestMethod.POST)
    @ResponseBody
    public ResultEntity<PagingResult<TrendsDto>> getMyTrends(HttpServletRequest request, @RequestBody PageReq page)
            throws Exception {
        String userCode = commonService.getUserCode(request);
        String lang = commonService.getLanguage(request);
        PagingResult<TrendsDto> trends = personCenterService.getMyTrends(userCode, userCode, page, lang);
        return new ResultEntity<PagingResult<TrendsDto>>(InfoMsg.SUCCESS_REQUEST, trends);
    }

    /**
     * 删除好友
     *
     * @param request
     * @param map     -> userCode(需要删除的好友信息)
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "delFriends", method = RequestMethod.POST)
    @ResponseBody
    public ResultEntity<Integer> delFriends(HttpServletRequest request, @RequestBody Map<String, String> map)
            throws Exception {
        String userCode = commonService.getUserCode(request);
        String userCode1 = map.get("userCode");
        if (userCode1 == null)
            throw new CustomException(InfoMsg.ERROR_EMPTY_REQUEST);
        int i = personCenterService.delFriends(userCode, userCode1);
        return new ResultEntity<Integer>(InfoMsg.SUCCESS_REQUEST, i);
    }

    /**
     * 删除动态
     *
     * @param request
     * @param map     -> trendId
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "delTrends", method = RequestMethod.POST)
    @ResponseBody
    public ResultEntity<Integer> delTrends(HttpServletRequest request, @RequestBody Map<String, Long> map)
            throws Exception {
        String userCode = commonService.getUserCode(request);
        Long trendId = map.get("trendId");
        if (trendId == null)
            throw new CustomException(InfoMsg.ERROR_EMPTY_REQUEST);
        int i = personCenterService.delTrends(userCode, trendId);
        return new ResultEntity<Integer>(InfoMsg.SUCCESS_REQUEST, i);
    }

    /**
     * 修改密码
     *
     * @param request
     * @param req
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "changePassword", method = RequestMethod.POST)
    @ResponseBody
    public ResultEntity<Integer> changePassword(HttpServletRequest request, @Validated @RequestBody ChangPReq req)
            throws Exception {
        String userCode = commonService.getUserCode(request);
        req.setUserCode(userCode);
        int i = personCenterService.changePassword(req);
        return new ResultEntity<Integer>(InfoMsg.SUCCESS_REQUEST, i);
    }

    /**
     * 购买记录
     *
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "buyRecord", method = RequestMethod.POST)
    @ResponseBody
    public ResultEntity<PagingResult<OrderListDto>> buyRecord(
            @RequestBody BuyRecordReq record, HttpServletRequest request) throws Exception {
        String lang = commonService.getLanguage(request);
        PagingResult<OrderListDto> i = personCenterService.buyRecord(record, lang);
        return new ResultEntity<PagingResult<OrderListDto>>(InfoMsg.SUCCESS_REQUEST, i);
    }

    /**
     * 查看企业详情并更新职位状态 (不知道哪边会用到)
     *
     * @param req
     * @param jobId
     * @return
     */
    @RequestMapping(value = "lookEnterPriseDetailAndUpdateStatus", method = RequestMethod.GET)
    @ResponseBody
    public ResultEntity<Map<String, Object>> lookEnterPriseDetailAndUpdateStatus(
            HttpServletRequest req,
            @RequestParam(value = "jobId") Integer jobId) {
        String userCode = commonService.getUserCode(req);
        String lang = commonService.getLanguage(req);
        Map<String, Object> maps = personCenterService.lookEnterPriseDetailAndUpdateStatus(userCode, jobId, lang);
        return new ResultEntity<>(InfoMsg.SUCCESS_REQUEST, maps);
    }

    /**
     * 个人主页单独使用
     * 获取用的详细信息
     *
     * @param req
     * @param jobId
     * @return
     */
    @RequestMapping(value = "getUserFullInfo", method = RequestMethod.GET)
    @ResponseBody
    public ResultEntity<UserHomePageResp<JobAdvertisedResp>> getUserFullInfo(HttpServletRequest request, @RequestParam String userCode, @RequestParam(required = false) String shareCode) {
        ResultEntity<UserHomePageResp<JobAdvertisedResp>> rest = new ResultEntity<UserHomePageResp<JobAdvertisedResp>>();
        String theSearch = commonService.getUserCode(request);
        String currentUserIdentityFlag = commonService.getIdentityFlag(request);
        String lang = commonService.getLanguage(request);

        //当通过外部链接进入时，没有userCode 只有shareCode
        if (StringsUtils.isEmpty(userCode) && !StringsUtils.isEmpty(shareCode)) {
            //获取解密后数据
            String[] codeAndTime = commonHelper.getUserCodeAes(shareCode);
            if (codeAndTime.length > 1) {
                userCode = codeAndTime[0];
            } else {
                rest.setMsg(InfoMsg.ERROR_USER_MISS);
                return rest;
            }
        }
        rest.setResult(personCenterService.getHomePageInfo(userCode, lang, theSearch, currentUserIdentityFlag));
        return rest;
    }

    /**
     * 获取指定用户动态
     *
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "getTrendsOfSomeone", method = RequestMethod.POST)
    @ResponseBody
    public ResultEntity<PagingResult<TrendsDto>> getTrendsOfSomeone(HttpServletRequest request, @RequestBody UserCodeWithPage param)
            throws Exception {
        String theSearch = commonService.getUserCode(request);
        String lang = commonService.getLanguage(request);
        PagingResult<TrendsDto> trends = personCenterService.getMyTrends(param.getUserCode(), theSearch, param, lang);
        return new ResultEntity<PagingResult<TrendsDto>>(InfoMsg.SUCCESS_REQUEST, trends);
    }


    /**
     * 上传企业相册
     *
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "uploadPhotoAlbum", method = RequestMethod.POST)
    @ResponseBody
    public ResultEntity<String> uploadPhotoAlbum(HttpServletRequest request, @RequestParam List<MultipartFile> pictureList) throws Exception {
        int size = pictureList.size();
        if (size > 8) {
            throw new CustomException(InfoMsg.ERROR_IMG_BEYOUND_LIMIT);
        }

        String userCode = commonService.getUserCode(request);

        int i = personCenterService.uploadPhotoAlbum(userCode, pictureList);
        if (i == size) {
            return new ResultEntity<String>(InfoMsg.SUCCESS_REQUEST);
        } else {
            return new ResultEntity<String>(InfoMsg.ERROR_UPLOAD_FIELD);
        }
    }

    /**
     * 删除照片
     *
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "delPhotoAlbum", method = RequestMethod.POST)
    @ResponseBody
    public ResultEntity<String> delPhotoAlbum(HttpServletRequest request, @RequestParam int pictureId) throws Exception {
        String userCode = commonService.getUserCode(request);

        int i = personCenterService.delPhotoAlbum(userCode, pictureId);
        if (i == 1) {
            return new ResultEntity<String>(InfoMsg.SUCCESS_REQUEST);
        } else {
            return new ResultEntity<String>(InfoMsg.ERROR_DATA_UPDATE);
        }
    }

    /**
     * 修改排序和描述
     *
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "updatePhotoSort", method = RequestMethod.POST)
    @ResponseBody
    public ResultEntity<String> updatePhotoSort(HttpServletRequest request, @RequestBody List<PhotoAlbumReq> photoAlbumReqList) throws Exception {
        String userCode = commonService.getUserCode(request);

        int count = personCenterService.updatePhotoSort(userCode, photoAlbumReqList);
        if (count == photoAlbumReqList.size()) {
            return new ResultEntity<String>(InfoMsg.SUCCESS_REQUEST);
        } else {
            return new ResultEntity<String>(InfoMsg.ERROR_DATA_UPDATE);
        }
    }


    /**
     * 获取企业相册
     *
     * @param userCode
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "getPhotoAlbum", method = RequestMethod.GET)
    @ResponseBody
    public ResultEntity<List<PhotoAlbumResp>> getPhotoAlbum(@RequestParam String userCode) throws Exception {
        List<PhotoAlbumResp> req = personCenterService.getPhotoAlbum(userCode);

        return new ResultEntity<List<PhotoAlbumResp>>(InfoMsg.SUCCESS_REQUEST, req);
    }


    /**
     * 上传企业相册-手机
     *
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "uploadPhotoAlbumMobile", method = RequestMethod.POST)
    @ResponseBody
    public ResultEntity<String> uploadPhotoAlbumMobile(HttpServletRequest request, @RequestBody List<String> pictureIds) throws Exception {
        ResultEntity<String> resq = new ResultEntity<String>();
        String userCode = commonService.getUserCode(request);
        int count = 0;
        int size = pictureIds.size();
        if (size > 8) {
            resq.setMsg(InfoMsg.ERROR_IMG_BEYOUND_LIMIT);
        } else if (size < 1) {
            resq.setMsg(InfoMsg.ERROR_NULL_PARAM);
        } else {
            //上传并保存
            count = personCenterService.uploadPhotoAlbumMobile(userCode, pictureIds);
        }

        if (count != size) {
            resq.setMsg(InfoMsg.ERROR_UPLOAD_FIELD);
        }
        return resq;
    }

    /**
     * 用户信息完整度验证
     *
     * @return
     */
    @RequestMapping(value = "checkUserInfo", method = RequestMethod.GET)
    @ResponseBody
    public ResultEntity<Boolean> checkUserInfo(HttpServletRequest request) {
        ResultEntity<Boolean> checkEnt = new ResultEntity<Boolean>();

        //暂时去除 20200612
	/*	String userCode = commonService.getUserCode(request);
		checkEnt = userService.checkUserInfo(userCode);*/

        checkEnt.setResult(true);
        return checkEnt;
    }


    /**
     * 修改个人隐私标识
     *
     * @param userCode
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "updatePrivateFlag", method = RequestMethod.POST)
    @ResponseBody
    public ResultEntity<Integer> updatePrivateFlag(@RequestParam String privateFlag, HttpServletRequest request) {
        ResultEntity<Integer> rest = new ResultEntity<Integer>();
        Integer count = userService.updatePrivateFlag(commonService.getUserCode(request), privateFlag);
        rest.setResult(count);
        return rest;
    }


    /**
     * 修改意向工作地信息
     *
     * @param info
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "modifyInterestedAdds", method = RequestMethod.POST)
    @ResponseBody
    public ResultEntity<Integer> modifyInterestedAdds(@RequestBody @Valid List<InterestedAddsReq> addsList, HttpServletRequest req) {
        ResultEntity<Integer> rest = new ResultEntity<Integer>();
        String userCode = commonService.getUserCode(req);
        Integer num = personCenterService.modifyInterestedAdds(addsList, userCode);
        rest.setResult(num);
        return rest;
    }

    /**
     * 修改职位订阅信息
     *
     * @param info
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "modifySubscribedPositions", method = RequestMethod.POST)
    @ResponseBody
    public ResultEntity<Integer> modifySubscribedPositions(@RequestBody @Valid SubscribePositionReq subPositionReq, HttpServletRequest req) {
        ResultEntity<Integer> rest = new ResultEntity<Integer>();
        String userCode = commonService.getUserCode(req);
        Integer num = new Integer(0);
        //订阅时验证用户是否关注公众号
        InfoMsg msg = commonService.checkBindingAndSubscribe(userCode);

        if (InfoMsg.SUCCESS_REQUEST.getCode().equals(msg.getCode())) {
            //验证通过的情况下 修改职位订阅信息
            num = personCenterService.modifySubscribedPositions(subPositionReq, userCode);
        }
        rest.setMsg(msg);
        rest.setResult(num);
        return rest;
    }


    /**
     * 获取用户订阅信息
     *
     * @param userCode
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "getSubscribedInfo", method = RequestMethod.GET)
    @ResponseBody
    public ResultEntity<SubscribedInfoResp> getSubscribedInfo(HttpServletRequest request) throws Exception {
        ResultEntity<SubscribedInfoResp> resp = new ResultEntity<SubscribedInfoResp>();
        String userCode = commonService.getUserCode(request);
        String lang = commonService.getLanguage(request);
        //获取意向工作地信息
        List<InterestedAddsReq> interestedAdds = personCenterService.getInterestedAdds(userCode, lang);
        //获取意向职位信息
        List<SubscribedPositionsDto> subdPositions = personCenterService.getSubscribedPositions(userCode, lang);
        //获取意向筹开类型信息
        List<String> prepareFlags = personCenterService.getSubscribedPrepareType(userCode);
        //获取用户信息
        MdeUser user = commonService.getUserInfo(userCode);

        //结果集封装
        SubscribedInfoResp req = new SubscribedInfoResp();
        req.setInterestedAdds(interestedAdds);
        req.setPositions(subdPositions);
        req.setPrepareFlags(prepareFlags);
        req.setSubscribedFlag(user.getSubscribedFlag());
        resp.setResult(req);

        return resp;
    }

    /**
     * 修改职位订阅标识
     *
     * @param info
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "modifySubscribedFlag", method = RequestMethod.POST)
    @ResponseBody
    public ResultEntity<Integer> modifySubscribedFlag(@RequestParam String subdFlag, HttpServletRequest request) {
        ResultEntity<Integer> rest = new ResultEntity<Integer>();
        String userCode = commonService.getUserCode(request);
        InfoMsg msg = userService.modifySubscribedFlag(userCode, subdFlag);
        rest.setMsg(msg);
        return rest;
    }

    /**
     * 修改企业主页背景
     *
     * @param request
     * @return
     * @throws Exception
     */
//	@RequestMapping(value = "changeCenterBgImages", method = RequestMethod.POST)
//	@ResponseBody
//	public ResultEntity<EnterpriseBgImgsResp> changePortraitBackgroundPc(
//			@RequestParam(required = false) MultipartFile portraitBackgroundPc,
//			@RequestParam(required = false) MultipartFile portraitBackgroundMob,
//			@RequestParam(required = false) MultipartFile topBackgroundPc,
//			@RequestParam(required = false) MultipartFile topBackgroundMob, HttpServletRequest request)
//			throws Exception {
//		String userCode = commonService.getUserCode(request);
//		ResultEntity<EnterpriseBgImgsResp> rest = new ResultEntity<EnterpriseBgImgsResp>();
//		// 上传后的完整的背景图地址
//		EnterpriseBgImgsResp bgImgsResp = new EnterpriseBgImgsResp(urlBase);
//		// 上传图片并返回地址和更新的db数据条数
//		int count = personCenterService.changeCenterBgImages(userCode, portraitBackgroundPc,portraitBackgroundMob,topBackgroundPc,topBackgroundMob, bgImgsResp);
//
//		if (count < 1) {
//			rest.setMsg(InfoMsg.ERROR_UPLOAD_FIELD);
//		} else {
//			rest.setResult(bgImgsResp);
//		}
//		return rest;
//	}

}
