|
|
@@ -1,30 +1,140 @@
|
|
|
-package com.goafanti.user.controller;
|
|
|
-
|
|
|
-import java.io.IOException;
|
|
|
-import java.util.List;
|
|
|
-
|
|
|
-import javax.annotation.Resource;
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
-
|
|
|
-import org.springframework.stereotype.Controller;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
-import org.springframework.web.multipart.MultipartFile;
|
|
|
-
|
|
|
-import com.goafanti.common.bo.Result;
|
|
|
-import com.goafanti.common.controller.BaseApiController;
|
|
|
-import com.goafanti.common.utils.LoggerUtils;
|
|
|
-import com.goafanti.common.utils.PasswordUtil;
|
|
|
-import com.goafanti.user.service.UserService;
|
|
|
-
|
|
|
-@Controller
|
|
|
-@RequestMapping(value = "/api/user")
|
|
|
-public class UserApiController extends BaseApiController {
|
|
|
- @Resource
|
|
|
- private UserService userService;
|
|
|
- @Resource(name = "passwordUtil")
|
|
|
- private PasswordUtil passwordUtil;
|
|
|
-
|
|
|
+package com.goafanti.user.controller;
|
|
|
+
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.List;
|
|
|
+import java.util.UUID;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.validation.Valid;
|
|
|
+
|
|
|
+import org.springframework.stereotype.Controller;
|
|
|
+import org.springframework.validation.BindingResult;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import com.goafanti.common.bo.Result;
|
|
|
+import com.goafanti.common.constant.ErrorConstants;
|
|
|
+import com.goafanti.common.controller.BaseApiController;
|
|
|
+import com.goafanti.common.model.OrganizationIdentity;
|
|
|
+import com.goafanti.common.model.OrganizationInfo;
|
|
|
+import com.goafanti.common.model.OrganizationTech;
|
|
|
+import com.goafanti.common.model.User;
|
|
|
+import com.goafanti.common.model.UserAbility;
|
|
|
+import com.goafanti.common.model.UserCareer;
|
|
|
+import com.goafanti.common.model.UserEdu;
|
|
|
+import com.goafanti.common.model.UserIdentity;
|
|
|
+import com.goafanti.common.model.UserInfo;
|
|
|
+import com.goafanti.common.utils.LoggerUtils;
|
|
|
+import com.goafanti.common.utils.PasswordUtil;
|
|
|
+import com.goafanti.core.shiro.token.TokenManager;
|
|
|
+import com.goafanti.user.bo.OrgIdentityBo;
|
|
|
+import com.goafanti.user.bo.UidAndTypeBo;
|
|
|
+import com.goafanti.user.bo.UserIdentityBo;
|
|
|
+import com.goafanti.user.bo.UserInfoBo;
|
|
|
+import com.goafanti.user.service.OrganizationIdentityService;
|
|
|
+import com.goafanti.user.service.OrganizationInfoService;
|
|
|
+import com.goafanti.user.service.OrganizationTechService;
|
|
|
+import com.goafanti.user.service.UserAbilityService;
|
|
|
+import com.goafanti.user.service.UserCareerService;
|
|
|
+import com.goafanti.user.service.UserEduService;
|
|
|
+import com.goafanti.user.service.UserIdentityService;
|
|
|
+import com.goafanti.user.service.UserInfoService;
|
|
|
+import com.goafanti.user.service.UserService;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+@Controller
|
|
|
+@RequestMapping(value = "/api/user")
|
|
|
+public class UserApiController extends BaseApiController {
|
|
|
+ @Resource
|
|
|
+ private UserService userService;
|
|
|
+ @Resource(name = "passwordUtil")
|
|
|
+ private PasswordUtil passwordUtil;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private UserIdentityService userIdentityService;
|
|
|
+ @Resource
|
|
|
+ private UserInfoService userInfoService;
|
|
|
+ @Resource
|
|
|
+ private UserEduService userEduService;
|
|
|
+ @Resource
|
|
|
+ private UserCareerService userCareerService;
|
|
|
+ @Resource
|
|
|
+ private UserAbilityService userAbilityService;
|
|
|
+ @Resource
|
|
|
+ private OrganizationIdentityService organizationIdentityService;
|
|
|
+ @Resource
|
|
|
+ private OrganizationInfoService organizationInfoService;
|
|
|
+ @Resource
|
|
|
+ private OrganizationTechService organizationTechService;
|
|
|
+
|
|
|
+ @RequestMapping(value = "/pwd", method = RequestMethod.POST)
|
|
|
+ public Result updatePwd(String password, String newPassword) {
|
|
|
+ Result res = new Result();
|
|
|
+ if (password == null || newPassword == null) {
|
|
|
+ res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "必须指定", "密码"));
|
|
|
+ }
|
|
|
+ if (res.getError().isEmpty() && TokenManager.isLogin()) {
|
|
|
+ User u = new User();
|
|
|
+ User user = userService.selectByPrimaryKey(TokenManager.getUserId());
|
|
|
+ u.setId(user.getId());
|
|
|
+ u.setCreateTime(user.getCreateTime());
|
|
|
+ u.setPassword(newPassword);
|
|
|
+ u.setPassword(passwordUtil.getEncryptPwd(u));
|
|
|
+ if (!user.getPassword().equals(passwordUtil.getEncryptPwd(password, user.getCreateTime()))) {
|
|
|
+ res.getError().add(buildError(ErrorConstants.PWD_NOT_MATCH_ERROR));
|
|
|
+ } else {
|
|
|
+ res.setData(userService.updateByPrimaryKeySelective(u));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 个人会员基本信息
|
|
|
+ * @param userIdentityBo
|
|
|
+ * @param bindingResult
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/basicinfo", method = RequestMethod.POST)
|
|
|
+ public Result basicInfo(@Valid UserIdentityBo userIdentityBo,BindingResult bindingResult){
|
|
|
+ Result res = new Result();
|
|
|
+ if (bindingResult.hasErrors()) {
|
|
|
+ res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
|
|
|
+ bindingResult.getFieldError().getField()));
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ if(res.getError().isEmpty()){
|
|
|
+ UserIdentity userIdentity = new UserIdentity();
|
|
|
+ UserIdentity identity= userIdentityService.selectUserIdentityByUserId(TokenManager.getUserId());
|
|
|
+ userIdentity.setUsername(userIdentityBo.getUsername());
|
|
|
+ userIdentity.setIdNumber(userIdentityBo.getIdNumber());
|
|
|
+ userIdentity.setSex(userIdentityBo.getSex());
|
|
|
+ userIdentity.setDateOfBirth(userIdentityBo.getDateOfBirth());
|
|
|
+ userIdentity.setPositiveId(userIdentityBo.getPositiveId());
|
|
|
+ userIdentity.setOppositeId(userIdentityBo.getOppositeId());
|
|
|
+ if(identity == null){
|
|
|
+ userIdentity.setId(UUID.randomUUID().toString());
|
|
|
+ userIdentity.setUid(TokenManager.getUserId());
|
|
|
+ userIdentityService.insert(userIdentity);
|
|
|
+ }else{
|
|
|
+ userIdentity.setId(identity.getId());
|
|
|
+ userIdentityService.updateByPrimaryKeySelective(userIdentity);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ res.setData(userIdentityBo);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 个人资料
|
|
|
+ * @param userInfoBo
|
|
|
+ * @param bindingResult
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@RequestMapping(value = "/avatar/upload", method = RequestMethod.POST)
|
|
|
public Result avatar(HttpServletRequest req) {
|
|
|
Result res = new Result();
|
|
|
@@ -37,25 +147,277 @@ public class UserApiController extends BaseApiController {
|
|
|
Result res = new Result();
|
|
|
res.setData(handleFile(res, "/identity/", true, req));
|
|
|
return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String handleFile(Result res, String path, boolean isPrivate, HttpServletRequest req) {
|
|
|
+ List<MultipartFile> files = getFiles(req);
|
|
|
+ String fileName = path + System.nanoTime() + ".jpg";
|
|
|
+ if (!files.isEmpty()) {
|
|
|
+ try {
|
|
|
+ MultipartFile mf = files.get(0);
|
|
|
+ mf.transferTo(isPrivate ? toPrivateFile(fileName) : toFile(fileName));
|
|
|
+ LoggerUtils.debug(getClass(), fileName + " 文件上传成功");
|
|
|
+ } catch (IllegalStateException | IOException e) {
|
|
|
+ LoggerUtils.error(getClass(), "文件上传失败", e);
|
|
|
+ res.getError().add(buildError("", "文件上传失败!"));
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ res.getError().add(buildError("", "文件上传失败!"));
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ return fileName;
|
|
|
}
|
|
|
+
|
|
|
+ @RequestMapping(value = "/personaldata", method = RequestMethod.POST)
|
|
|
+ public Result personalData(@Valid UserInfoBo userInfoBo,BindingResult bindingResult){
|
|
|
+ Result res = new Result();
|
|
|
+ if (bindingResult.hasErrors()) {
|
|
|
+ res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
|
|
|
+ bindingResult.getFieldError().getField()));
|
|
|
+ return res;
|
|
|
|
|
|
- private String handleFile(Result res, String path, boolean isPrivate, HttpServletRequest req) {
|
|
|
- List<MultipartFile> files = getFiles(req);
|
|
|
- String fileName = path + System.nanoTime() + ".jpg";
|
|
|
- if (!files.isEmpty()) {
|
|
|
- try {
|
|
|
- MultipartFile mf = files.get(0);
|
|
|
- mf.transferTo(isPrivate ? toPrivateFile(fileName) : toFile(fileName));
|
|
|
- LoggerUtils.debug(getClass(), fileName + " 文件上传成功");
|
|
|
- } catch (IllegalStateException | IOException e) {
|
|
|
- LoggerUtils.error(getClass(), "文件上传失败", e);
|
|
|
- res.getError().add(buildError("", "文件上传失败!"));
|
|
|
- return "";
|
|
|
- }
|
|
|
- } else {
|
|
|
- res.getError().add(buildError("", "文件上传失败!"));
|
|
|
- return "";
|
|
|
- }
|
|
|
- return fileName;
|
|
|
- }
|
|
|
-}
|
|
|
+ }
|
|
|
+ if(res.getError().isEmpty()){
|
|
|
+ UserInfo info= userInfoService.selectUserInfoByUserId(TokenManager.getUserId());
|
|
|
+ User u =userService.selectByPrimaryKey(TokenManager.getUserId());
|
|
|
+ u.setNickname(userInfoBo.getNickname());
|
|
|
+ u.setEmail(userInfoBo.getEmail());
|
|
|
+ userService.updateByPrimaryKeySelective(u);
|
|
|
+ UserInfo userInfo = new UserInfo();
|
|
|
+ userInfo.setResidence(userInfoBo.getResidence());
|
|
|
+ userInfo.setPersonPortrait(userInfoBo.getPersonPortrait());
|
|
|
+ userInfo.setPersonalProfile(userInfoBo.getPersonalProfile());
|
|
|
+ userInfo.setLifePhoto(userInfoBo.getLifePhoto());
|
|
|
+ userInfo.setFixedTel(userInfoBo.getFixedTel());
|
|
|
+ userInfo.setQq(userInfoBo.getQq());
|
|
|
+ userInfo.setPostalAddress(userInfoBo.getPostalAddress());
|
|
|
+ userInfo.setPostcode(userInfoBo.getPostcode());
|
|
|
+ if(info == null){
|
|
|
+ userInfo.setId(UUID.randomUUID().toString());
|
|
|
+ userInfo.setUid(TokenManager.getUserId());
|
|
|
+ userInfoService.insert(userInfo);
|
|
|
+ }else{
|
|
|
+ userInfo.setId(info.getId());
|
|
|
+ userInfoService.updateByPrimaryKeySelective(userInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ res.setData(userInfoBo);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 个人会员教育信息
|
|
|
+ * @param userEdu
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/eduinfo", method = RequestMethod.POST)
|
|
|
+ public Result educationInfo(UserEdu userEdu){
|
|
|
+ Result res = new Result();
|
|
|
+ UserEdu edu = userEduService.selectUserEduByUserId(TokenManager.getUserId());
|
|
|
+
|
|
|
+ if(edu == null){
|
|
|
+ userEdu.setId(UUID.randomUUID().toString());
|
|
|
+ userEdu.setUid(TokenManager.getUserId());
|
|
|
+ userEduService.insert(userEdu);
|
|
|
+ }else{
|
|
|
+ userEduService.updateByPrimaryKeySelective(userEdu);
|
|
|
+ }
|
|
|
+ res.setData(userEdu);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 个人会员职业信息
|
|
|
+ * @param userCareer
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+
|
|
|
+ @RequestMapping(value = "/careerinfo", method = RequestMethod.POST)
|
|
|
+ public Result careerInfo(UserCareer userCareer){
|
|
|
+ Result res = new Result();
|
|
|
+ UserCareer career = userCareerService.selectUserCareerByUserId(TokenManager.getUserId());
|
|
|
+
|
|
|
+ if(career == null){
|
|
|
+ userCareer.setId(UUID.randomUUID().toString());
|
|
|
+ userCareer.setUid(TokenManager.getUserId());
|
|
|
+ userCareerService.insert(userCareer);
|
|
|
+ }else{
|
|
|
+ userCareer.setId(career.getId());
|
|
|
+ userCareerService.updateByPrimaryKeySelective(userCareer);
|
|
|
+ }
|
|
|
+ res.setData(userCareer);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 会员能力标签
|
|
|
+ * @param userAbility
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+
|
|
|
+ @RequestMapping(value = "/abilitylabel", method = RequestMethod.POST)
|
|
|
+ public Result abilityLabel(UserAbility userAbility){
|
|
|
+ Result res = new Result();
|
|
|
+ UserCareer ability = userAbilityService.selectUserAbilityByUserId(TokenManager.getUserId());
|
|
|
+ if(ability == null){
|
|
|
+ userAbility.setId(UUID.randomUUID().toString());
|
|
|
+ userAbility.setUid(TokenManager.getUserId());
|
|
|
+ userAbilityService.insert(userAbility);
|
|
|
+ }else{
|
|
|
+ userAbility.setId(ability.getId());
|
|
|
+ userAbilityService.updateByPrimaryKeySelective(userAbility);
|
|
|
+ }
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 团体会员基本信息
|
|
|
+ * @param orgIdentityBo
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequestMapping(value="/groupbasicinfo",method = RequestMethod.POST)
|
|
|
+ public Result groupBasicInfo(OrgIdentityBo orgIdentityBo){
|
|
|
+ Result res = new Result();
|
|
|
+ OrganizationIdentity organizationIdentity = new OrganizationIdentity();
|
|
|
+ OrganizationIdentity identity = organizationIdentityService.selectOrgIdentityByUserId(TokenManager.getUserId());
|
|
|
+ User u =userService.selectByPrimaryKey(TokenManager.getUserId());
|
|
|
+ u.setEmail(orgIdentityBo.getEmail());
|
|
|
+ userService.updateByPrimaryKeySelective(u);
|
|
|
+ organizationIdentity.setContacts(orgIdentityBo.getContacts());
|
|
|
+ organizationIdentity.setFixedTel(orgIdentityBo.getFixedTel());
|
|
|
+ organizationIdentity.setQq(orgIdentityBo.getQq());
|
|
|
+ organizationIdentity.setPostalAddress(orgIdentityBo.getPostalAddress());
|
|
|
+ organizationIdentity.setPostcode(orgIdentityBo.getPostcode());
|
|
|
+ if(identity==null){
|
|
|
+ organizationIdentity.setId(UUID.randomUUID().toString());
|
|
|
+ organizationIdentity.setUid(TokenManager.getUserId());
|
|
|
+ organizationIdentityService.insert(organizationIdentity);
|
|
|
+ }else{
|
|
|
+ organizationIdentity.setId(identity.getId());
|
|
|
+ organizationIdentityService.updateByPrimaryKeySelective(organizationIdentity);
|
|
|
+ }
|
|
|
+ res.setData(orgIdentityBo);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 团体会员单位资料
|
|
|
+ * @param orgInfo
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequestMapping(value="/unitdata",method = RequestMethod.POST)
|
|
|
+ public Result groupBasicInfo(OrganizationInfo orgInfo){
|
|
|
+ Result res = new Result();
|
|
|
+ OrganizationInfo info = organizationInfoService.selectOrgInfoByUserId(TokenManager.getUserId());
|
|
|
+ if(info == null){
|
|
|
+ orgInfo.setId(UUID.randomUUID().toString());
|
|
|
+ orgInfo.setUid(TokenManager.getUserId());
|
|
|
+ organizationInfoService.insert(orgInfo);
|
|
|
+ }else{
|
|
|
+ orgInfo.setId(info.getId());
|
|
|
+ organizationInfoService.updateByPrimaryKeySelective(orgInfo);
|
|
|
+ }
|
|
|
+ res.setData(orgInfo);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 团体会员技术能力
|
|
|
+ * @param orgTech
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequestMapping(value="/tech",method = RequestMethod.POST)
|
|
|
+ public Result tech(OrganizationTech orgTech){
|
|
|
+ Result res = new Result();
|
|
|
+ OrganizationTech tech = organizationTechService.selectOrgTechByUserId(TokenManager.getUserId());
|
|
|
+ if(tech == null){
|
|
|
+ orgTech.setId(UUID.randomUUID().toString());
|
|
|
+ orgTech.setUid(TokenManager.getUserId());
|
|
|
+ organizationTechService.insert(orgTech);
|
|
|
+ }else{
|
|
|
+ orgTech.setId(tech.getId());
|
|
|
+ organizationTechService.updateByPrimaryKeySelective(orgTech);
|
|
|
+ }
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @RequestMapping(value="/base",method = RequestMethod.POST)
|
|
|
+ public Result basic(){
|
|
|
+ Result res = new Result();
|
|
|
+ UidAndTypeBo ub =basicInfo(userService);
|
|
|
+ if(ub.getType()==0){
|
|
|
+ UserIdentityBo u = userIdentityService.selectUserIdentityBoByUserId(ub.getUid());
|
|
|
+ res.setData(u);
|
|
|
+ }else{
|
|
|
+ OrgIdentityBo o = organizationIdentityService.selectOrgIdentityBoByUserId(ub.getUid());
|
|
|
+ res.setData(o);
|
|
|
+ }
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(value="/member",method = RequestMethod.POST)
|
|
|
+ public Result member(){
|
|
|
+ Result res = new Result();
|
|
|
+ UidAndTypeBo ub =basicInfo(userService);
|
|
|
+ if(ub.getType()==0){
|
|
|
+ UserInfoBo u=userInfoService.selectUserInfoBoByUserId(ub.getUid());
|
|
|
+ res.setData(u);
|
|
|
+ }else{
|
|
|
+ OrganizationInfo o = organizationInfoService.selectOrgInfoByUserId(ub.getUid());
|
|
|
+ res.setData(o);
|
|
|
+ }
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(value="/educate",method = RequestMethod.POST)
|
|
|
+ public Result educate(){
|
|
|
+ Result res = new Result();
|
|
|
+ UidAndTypeBo ub =basicInfo(userService);
|
|
|
+ UserEdu u = userEduService.selectUserEduByUserId(ub.getUid());
|
|
|
+ res.setData(u);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(value="/job",method = RequestMethod.POST)
|
|
|
+ public Result job(){
|
|
|
+ Result res = new Result();
|
|
|
+ UidAndTypeBo ub =basicInfo(userService);
|
|
|
+ if(ub.getType()==0){
|
|
|
+ UserCareer u = userCareerService.selectUserCareerByUserId(ub.getUid());
|
|
|
+ res.setData(u);
|
|
|
+ }else{
|
|
|
+ OrganizationTech o = organizationTechService.selectOrgTechByUserId(ub.getUid());
|
|
|
+ res.setData(o);
|
|
|
+ }
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(value="/ability",method = RequestMethod.POST)
|
|
|
+ public Result ability(){
|
|
|
+ Result res = new Result();
|
|
|
+ UidAndTypeBo ub =basicInfo(userService);
|
|
|
+
|
|
|
+ UserCareer u = userAbilityService.selectUserAbilityByUserId(ub.getUid());
|
|
|
+ res.setData(u);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private static UidAndTypeBo basicInfo(UserService userService){
|
|
|
+ User u = userService.selectByPrimaryKey(TokenManager.getUserId());
|
|
|
+ UidAndTypeBo ub = new UidAndTypeBo();
|
|
|
+
|
|
|
+ ub.setType(u.getType());
|
|
|
+ ub.setUid(u.getId());
|
|
|
+ return ub;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|