diff --git a/dq-financial-api/src/main/java/com/daqing/financial/hrms/UserControllerApi.java b/dq-financial-api/src/main/java/com/daqing/financial/hrms/UserControllerApi.java index 38030d96..c8629e6c 100644 --- a/dq-financial-api/src/main/java/com/daqing/financial/hrms/UserControllerApi.java +++ b/dq-financial-api/src/main/java/com/daqing/financial/hrms/UserControllerApi.java @@ -5,6 +5,7 @@ import com.daqing.framework.model.response.ResponseResult; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.apache.http.HttpResponse; +import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; @@ -25,9 +26,14 @@ public interface UserControllerApi { ResponseResult code(String phone); @ApiOperation(value = "修改密码",notes = "修改密码") - ResponseResult updatePassword(Long id, String primaryPassword, String newPassword, String affirmNewPassword); + ResponseResult updatePassword(String primaryPassword, String newPassword, String affirmNewPassword); @ApiOperation(value = "绑定手机号",notes = "绑定手机号") - ResponseResult binding(Long id,String phone,String code); + ResponseResult binding(String phone,String code); + @ApiOperation(value = "取消微信绑定",notes = "取消微信绑定") + ResponseResult cancel(); + + @ApiOperation(value = "图像文件上传",notes = "图像文件上传") + ResponseResult uploadFile(MultipartFile file); } diff --git a/dq-financial-crms/pom.xml b/dq-financial-crms/pom.xml index f86c18b2..6f2f5867 100644 --- a/dq-financial-crms/pom.xml +++ b/dq-financial-crms/pom.xml @@ -21,13 +21,13 @@ - + + com.daqing.financial dq-financial-api 0.0.1-SNAPSHOT @@ -39,12 +39,11 @@ org.springframework.boot spring-boot-starter-web - --> - org.springframework.boot spring-boot-starter-test diff --git a/dq-financial-crms/src/main/java/com/daqing/financial/crms/config/IPageConfig.java b/dq-financial-crms/src/main/java/com/daqing/financial/crms/config/IPageConfig.java index 243e1e84..a48778d6 100644 --- a/dq-financial-crms/src/main/java/com/daqing/financial/crms/config/IPageConfig.java +++ b/dq-financial-crms/src/main/java/com/daqing/financial/crms/config/IPageConfig.java @@ -1,15 +1,13 @@ -/* -package com.daqing.financial.crms.config; - -import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -@Configuration -public class IPageConfig { - @Bean - public PaginationInterceptor paginationInterceptor() { - return new PaginationInterceptor(); - } -} -*/ +//package com.daqing.financial.crms.config; +// +//import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor; +//import org.springframework.context.annotation.Bean; +//import org.springframework.context.annotation.Configuration; +// +//@Configuration +//public class IPageConfig { +// @Bean +// public PaginationInterceptor paginationInterceptor() { +// return new PaginationInterceptor(); +// } +//} diff --git a/dq-financial-crms/src/main/java/com/daqing/financial/crms/service/impl/CustomerWorkbenchServiceImpl.java b/dq-financial-crms/src/main/java/com/daqing/financial/crms/service/impl/CustomerWorkbenchServiceImpl.java index a1db376f..2968dd5c 100644 --- a/dq-financial-crms/src/main/java/com/daqing/financial/crms/service/impl/CustomerWorkbenchServiceImpl.java +++ b/dq-financial-crms/src/main/java/com/daqing/financial/crms/service/impl/CustomerWorkbenchServiceImpl.java @@ -17,12 +17,16 @@ import com.daqing.framework.exception.ExceptionCast; import com.daqing.framework.exception.ExceptionCatch; import com.daqing.framework.model.response.CommonCode; import com.daqing.framework.model.response.ResponseResult; +import com.daqing.framework.util.RedisUtil; import com.daqing.framework.utils.PageUtils; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; +import javax.servlet.http.HttpServletRequest; import java.text.SimpleDateFormat; import java.util.*; @@ -34,12 +38,6 @@ import java.util.*; public class CustomerWorkbenchServiceImpl extends ServiceImpl implements CustomerWorkbenchService { - //TODO 从redis获取当前登录用户信息 - /*HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); - String token = request.getHeader("token"); - String userId = RedisUtil.get("dq:token:"+token);*/ - Long userId = Long.parseLong("1"); - @Autowired private HrmsFeignService hrmsFeignService; @@ -76,7 +74,7 @@ public class CustomerWorkbenchServiceImpl extends ServiceImpl !Objects.equals(customerWorkbenchListVO.getStatus(),cwr.getStatus())); } } - // 属性拷贝,将泛型为CustomerEntity类型的IPage的属性拷贝给泛型为CustomerTO类型的IPage,才能赋值给PageUtils IPage iPage = new Page<>(); BeanUtils.copyProperties(customerEntityIPage,iPage); @@ -120,6 +117,7 @@ public class CustomerWorkbenchServiceImpl extends ServiceImpl getCustomerManager() { + Long userId = Long.parseLong(this.getUserId()); ResponseResult> employees = hrmsFeignService.listEmployeeById(userId); - return employees.getData(); } @@ -263,4 +262,13 @@ public class CustomerWorkbenchServiceImpl extends ServiceImpl - UPDATE hrms_customer SET manager = #{manager} WHERE id = #{id} + UPDATE crms_customer SET manager = #{manager} WHERE id = #{id} \ No newline at end of file diff --git a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/feign/HrauthFeignService.java b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/feign/HrauthFeignService.java index 46c59db4..e1fad3cc 100644 --- a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/feign/HrauthFeignService.java +++ b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/feign/HrauthFeignService.java @@ -12,7 +12,7 @@ import java.util.List; /** * 这是一个声明式的远程调用 */ -@FeignClient("dq-financial-hrms-auth") +@FeignClient(value = "dq-financial-hrms-auth",contextId = "hrms-auth") public interface HrauthFeignService { @GetMapping("/hrms/auth/permission/getUserRoles") diff --git a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/impl/UserServiceImpl.java b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/impl/UserServiceImpl.java index 27b76050..752fa20b 100644 --- a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/impl/UserServiceImpl.java +++ b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/impl/UserServiceImpl.java @@ -12,14 +12,18 @@ import com.daqing.framework.domain.hrms.UserEntity; import com.daqing.framework.domain.hrms.request.LoginRequest; import com.daqing.framework.domain.hrms.response.LoginResponse; import com.daqing.framework.model.response.ResponseResult; +import com.daqing.framework.util.RedisUtil; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.MapUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.stereotype.Service; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.UnsupportedEncodingException; @@ -132,11 +136,9 @@ public class UserServiceImpl extends ServiceImpl imple return false; } String openId = (String) baseMap.get("openid"); - /*HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); + HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); String token = request.getHeader("token"); - String userId = RedisUtil.get("dq:token:"+token);*/ - //TODO:测试环境模拟从redis中拿取用户id - String userId = "1"; + String userId = RedisUtil.get("dq:token:"+token); Boolean result = this.getBaseMapper().updateWeChat(Long.parseLong(userId), openId); log.info("绑定成功---------------------------------------"); if (result){ diff --git a/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/config/IPageConfig.java b/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/config/IPageConfig.java index ed530d1c..f4b53595 100644 --- a/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/config/IPageConfig.java +++ b/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/config/IPageConfig.java @@ -1,15 +1,13 @@ -/* -package com.daqing.financial.hrms.config; - -import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -@Configuration -public class IPageConfig { - @Bean - public PaginationInterceptor paginationInterceptor() { - return new PaginationInterceptor(); - } -} -*/ +//package com.daqing.financial.hrms.config; +// +//import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor; +//import org.springframework.context.annotation.Bean; +//import org.springframework.context.annotation.Configuration; +// +//@Configuration +//public class IPageConfig { +// @Bean +// public PaginationInterceptor paginationInterceptor() { +// return new PaginationInterceptor(); +// } +//} diff --git a/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/controller/UserController.java b/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/controller/UserController.java index e78002a8..8f927d49 100644 --- a/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/controller/UserController.java +++ b/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/controller/UserController.java @@ -10,6 +10,7 @@ import com.daqing.framework.utils.PageUtils; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; @@ -57,12 +58,23 @@ public class UserController implements UserControllerApi { return result ? ResponseResult.SUCCESS() : new ResponseResult(CommonCode.UPDATE_FAIL); } + /** + * 图像文件上传 + */ + @PostMapping("/uploadFile") + public ResponseResult uploadFile(@RequestParam("file") MultipartFile file){ + + String result = userService.uploadFile(file); + + return ResponseResult.SUCCESS(result); + } + /** * 获取验证码 */ @GetMapping("/code") @Override - public ResponseResult code(String phone) { + public ResponseResult code(@RequestParam("phone") String phone) { Boolean result = userService.getVerificationCode(phone); @@ -74,9 +86,10 @@ public class UserController implements UserControllerApi { */ @GetMapping("/updatePassword") @Override - public ResponseResult updatePassword(@RequestParam("id") Long id, String primaryPassword, - String newPassword, String affirmNewPassword) { - Boolean result = userService.updatePassword(id, primaryPassword, newPassword, affirmNewPassword); + public ResponseResult updatePassword(@RequestParam("primaryPassword") String primaryPassword, + @RequestParam("newPassword") String newPassword, + @RequestParam("affirmNewPassword") String affirmNewPassword) { + Boolean result = userService.updatePassword(primaryPassword, newPassword, affirmNewPassword); return result ? ResponseResult.SUCCESS() : new ResponseResult(CommonCode.UPDATE_FAIL); } @@ -86,20 +99,21 @@ public class UserController implements UserControllerApi { */ @GetMapping("/binding") @Override - public ResponseResult binding(@RequestParam("id") Long id, String phone, String code) { + public ResponseResult binding(String phone, String code) { - Boolean result = userService.bindingPhoneAccount(id, phone, code); + Boolean result = userService.bindingPhoneAccount(phone, code); return result ? ResponseResult.SUCCESS() : ResponseResult.FAIL(); } /** - * 微信绑定回调 + * 取消微信绑定 */ - @GetMapping("/callbackBinding") - public ResponseResult weChatCallback(@RequestParam("code") String code, HttpServletResponse response) throws IOException { + @GetMapping("/cancel") + @Override + public ResponseResult cancel() { - Boolean result = userService.weChatCallback(code, response); + Boolean result = userService.cancel(); return result ? ResponseResult.SUCCESS() : ResponseResult.FAIL(); } diff --git a/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/dao/EmployeeDao.java b/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/dao/EmployeeDao.java index 0e6a8e99..d8ecfa27 100644 --- a/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/dao/EmployeeDao.java +++ b/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/dao/EmployeeDao.java @@ -80,4 +80,5 @@ public interface EmployeeDao extends BaseMapper { EmployeeAndUserVO getEmployeeByUserId(Long id); Boolean updateEmployeeAndUser(EmployeeEntity employeeEntity); + } diff --git a/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/dao/UserDao.java b/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/dao/UserDao.java index 3ce72337..d07a978d 100644 --- a/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/dao/UserDao.java +++ b/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/dao/UserDao.java @@ -26,4 +26,6 @@ public interface UserDao extends BaseMapper { Boolean updatePhoneAccount(@Param("id")Long id,@Param("phoneAccount") String phoneAccount); Boolean updateWeChat(@Param("id") Long id, @Param("weChatId") String weChatId); + + Long getEmployeeIdByUserId(Long userId); } diff --git a/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/service/UserService.java b/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/service/UserService.java index a9618636..99d14563 100644 --- a/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/service/UserService.java +++ b/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/service/UserService.java @@ -2,12 +2,9 @@ package com.daqing.financial.hrms.service; import com.baomidou.mybatisplus.extension.service.IService; import com.daqing.framework.domain.hrms.ext.EmployeeAndUserVO; -import com.daqing.framework.utils.PageUtils; import com.daqing.framework.domain.hrms.UserEntity; +import org.springframework.web.multipart.MultipartFile; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.util.Map; /** * 人资管理系统,员工账号信息表,用于存储员工账号密码等登录相关数据 @@ -22,12 +19,14 @@ public interface UserService extends IService { Boolean update(EmployeeAndUserVO employeeAndUserVO); - Boolean updatePassword(Long id,String primaryPassword,String newPassword,String affirmNewPassword); + String uploadFile(MultipartFile file); + + Boolean updatePassword(String primaryPassword,String newPassword,String affirmNewPassword); Boolean getVerificationCode(String phone); - Boolean bindingPhoneAccount(Long id,String phone,String code); + Boolean bindingPhoneAccount(String phone,String code); - Boolean weChatCallback(String code, HttpServletResponse response) throws IOException; + Boolean cancel(); } diff --git a/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/service/impl/UserServiceImpl.java b/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/service/impl/UserServiceImpl.java index 4ed15308..074ed761 100644 --- a/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/service/impl/UserServiceImpl.java +++ b/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/service/impl/UserServiceImpl.java @@ -11,7 +11,6 @@ import com.daqing.framework.domain.hrms.UserEntity; import com.daqing.framework.domain.hrms.ext.EmployeeAndUserVO; import com.daqing.framework.domain.hrms.response.HrmsCode; import com.daqing.framework.exception.ExceptionCast; -import com.daqing.framework.model.response.CommonCode; import com.daqing.framework.model.response.PromptSuccess; import com.daqing.framework.util.HttpUtils; import com.daqing.framework.util.Md5Util; @@ -22,13 +21,18 @@ import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; +import org.springframework.web.multipart.MultipartFile; import javax.imageio.ImageIO; +import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.awt.image.BufferedImage; import java.io.*; import java.util.Map; import java.util.Objects; +import java.util.UUID; @Slf4j @@ -41,28 +45,25 @@ public class UserServiceImpl extends ServiceImpl implements @Autowired private HrmsAuthFeignService hrmsAuthFeignService; + /** * 当前登录的用户信息 */ @Override public EmployeeAndUserVO info() { - /*HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); - String token = request.getHeader("token"); - String userId = RedisUtil.get("dq:token:"+token);*/ - //TODO:测试环境模拟从redis中拿取用户id - String userId = "1"; + String userId = this.getUserId(); EmployeeAndUserVO employeeAndUser = employeeDao.getEmployeeByUserId(Long.parseLong(userId)); if (employeeAndUser.getWechatId() == null || employeeAndUser.getWechatId().length() == 0){ JSONObject responseResult = hrmsAuthFeignService.getWeChatConfig(); JSONObject weChatConfig = responseResult.getJSONObject("data"); if (weChatConfig == null){ - employeeAndUser.setWechatId("二维码获取失败,请稍后重试"); + employeeAndUser.setWechatId(PromptSuccess.QR_CODE_FAIL); }else { - employeeAndUser.setWechatId(String.format(weChatConfig.get("OPEN_QRCODE_URL").toString(),weChatConfig.get("openAppid"), - weChatConfig.get("openRedirectUrl"),weChatConfig.get("openAppsecret"))); + employeeAndUser.setWechatId(String.format(weChatConfig.get("open_QRCODE_URL").toString(),weChatConfig.get("openAppid"), + weChatConfig.get("openRedirectUrl"),1)); // state=1作为回调时分辨绑定和登陆的标识 } }else { - employeeAndUser.setWechatId("已绑定,微信扫码即可登录"); + employeeAndUser.setWechatId(PromptSuccess.QR_CODE_BINDING_SUCCESS); } return employeeAndUser; } @@ -74,59 +75,11 @@ public class UserServiceImpl extends ServiceImpl implements @Override public Boolean update(EmployeeAndUserVO employeeAndUserVO) { EmployeeEntity employee = new EmployeeEntity(); + String userId = this.getUserId(); + Long employeeId = this.getBaseMapper().getEmployeeIdByUserId(Long.parseLong(userId)); + employeeAndUserVO.setId(employeeId); + employeeAndUserVO.setUserId(Long.parseLong(userId)); Boolean result = true; - if (employeeAndUserVO.getFile() != null && !employeeAndUserVO.getFile().isEmpty()){ - //TODO:上传图像文件到oss服务器,返回一个路径地址 - try { - // 通过获取图片文件的宽度和高度来校验是否为图片文件 - BufferedImage image = ImageIO.read(employeeAndUserVO.getFile().getInputStream()); - if (image == null || image.getHeight() <= 0 || image.getWidth() <= 0){ - ExceptionCast.cast(HrmsCode.USER_FILE_TYPE_MISTAKE); - } - }catch (IOException e){ - ExceptionCast.cast(HrmsCode.USER_FILE_UPLOAD_FAIL); - } - OutputStream os = null; - InputStream inputStream = null; - String fileName = null; - try { - inputStream = employeeAndUserVO.getFile().getInputStream(); - fileName = employeeAndUserVO.getFile().getOriginalFilename(); - log.info("fileName="+fileName); - } catch (IOException e) { - e.printStackTrace(); - } - try { - String path = "D:\\image"; - // 2、保存到临时文件 - // 1K的数据缓冲 - byte[] bs = new byte[1024]; - // 读取到的数据长度 - int len; - // 输出的文件流保存到本地文件 - File tempFile = new File(path); - if (!tempFile.exists()) { - tempFile.mkdirs(); - } - os = new FileOutputStream(tempFile.getPath() + File.separator + "MyFileName.png"); - // 开始读取 - while ((len = inputStream.read(bs)) != -1) { - os.write(bs, 0, len); - } - } catch (IOException e) { - ExceptionCast.cast(HrmsCode.USER_FILE_UPLOAD_FAIL); - } catch (Exception e) { - e.printStackTrace(); - } finally { - // 完毕,关闭所有链接 - try { - os.close(); - inputStream.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - } BeanUtils.copyProperties(employeeAndUserVO,employee); String phoneAccount = this.getBaseMapper().getPhoneAccount(employee.getUserId()); if ((phoneAccount == null || phoneAccount.length() == 0) @@ -172,15 +125,44 @@ public class UserServiceImpl extends ServiceImpl implements return result && employeeDao.updateEmployeeAndUser(employee); } + /** + * 图像文件上传 + */ + @Override + public String uploadFile(MultipartFile file) { + if (file == null || file.isEmpty()){ + ExceptionCast.cast(HrmsCode.USER_FILE_IS_NULL); + } + try { + // 通过获取图片文件的宽度和高度来校验是否为图片文件 + BufferedImage image = ImageIO.read(file.getInputStream()); + if (image == null || image.getHeight() <= 0 || image.getWidth() <= 0){ + ExceptionCast.cast(HrmsCode.USER_FILE_TYPE_MISTAKE); + } + }catch (IOException e){ + ExceptionCast.cast(HrmsCode.USER_FILE_UPLOAD_FAIL); + } + String filename = file.getOriginalFilename(); + if (filename == null){ + ExceptionCast.cast(HrmsCode.USER_FILE_TYPE_MISTAKE); + } + String substring = filename.substring(filename.lastIndexOf(".")); + String filePrefix = UUID.randomUUID().toString(); + String filePath = PromptSuccess.UPLOAD_FILE_PATH+filePrefix+substring; + try { + file.transferTo(new File(filePath)); + } catch (IOException e) { + ExceptionCast.cast(HrmsCode.USER_FILE_UPLOAD_FAIL); + } + return filePath; + } + /** * 修改密码 */ @Transactional @Override - public Boolean updatePassword(Long id, String primaryPassword, String newPassword, String affirmNewPassword) { - if (id == null){ - ExceptionCast.cast(CommonCode.INVALID_PARAM); - } + public Boolean updatePassword(String primaryPassword, String newPassword, String affirmNewPassword) { if (primaryPassword == null || primaryPassword.length() == 0 || newPassword == null || newPassword.length() == 0 || affirmNewPassword == null || affirmNewPassword.length() == 0){ @@ -190,7 +172,8 @@ public class UserServiceImpl extends ServiceImpl implements if (!Objects.equals(affirmNewPassword, newPassword)){ ExceptionCast.cast(HrmsCode.USER_PASSWORD_NO_CONSISTENT); } - if (!Objects.equals(Md5Util.md5(primaryPassword + id),this.getBaseMapper().getPasswordById(id))){ + String userId = this.getUserId(); + if (!Objects.equals(Md5Util.md5(primaryPassword + Long.parseLong(userId)),this.getBaseMapper().getPasswordById(Long.parseLong(userId)))){ ExceptionCast.cast(HrmsCode.USER_PASSWORD_MISTAKE); } // 正则校验 @@ -198,10 +181,10 @@ public class UserServiceImpl extends ServiceImpl implements ExceptionCast.cast(HrmsCode.USER_PASSWORD_MATCHES); } // 是否与账号相同 - if (Objects.equals(newPassword,this.getBaseMapper().getAccountById(id))){ + if (Objects.equals(newPassword,this.getBaseMapper().getAccountById(Long.parseLong(userId)))){ ExceptionCast.cast(HrmsCode.USER_PASSWORD_IS_NO_ACCOUNT); } - return this.getBaseMapper().updatePassword(id,Md5Util.md5(newPassword + id)); + return this.getBaseMapper().updatePassword(Long.parseLong(userId),Md5Util.md5(newPassword + Long.parseLong(userId))); } /** @@ -227,10 +210,7 @@ public class UserServiceImpl extends ServiceImpl implements */ @Transactional @Override - public Boolean bindingPhoneAccount(Long id,String phone, String code) { - if (id == null){ - ExceptionCast.cast(CommonCode.INVALID_PARAM); - } + public Boolean bindingPhoneAccount(String phone, String code) { if (phone == null || phone.length() == 0 || code == null || code.length() == 0){ ExceptionCast.cast(HrmsCode.USER_PHONE_OR_CODE_NOT_NULL); } @@ -239,43 +219,25 @@ public class UserServiceImpl extends ServiceImpl implements ExceptionCast.cast(HrmsCode.USER_BINDING_FAIL); } RedisUtil.del(phone); - return this.getBaseMapper().updatePhoneAccount(id, phone); + String userId = this.getUserId(); + return this.getBaseMapper().updatePhoneAccount(Long.parseLong(userId), phone); } /** - * 绑定微信回调接收接口 - * @param code 微信端返回的code,用于申请openid - * @return + * 取消微信绑定 */ @Override - public Boolean weChatCallback(String code, HttpServletResponse response) { - log.info("微信回调成功---------------------------------------"); - - - JSONObject responseResult = hrmsAuthFeignService.getWeChatConfig(); - JSONObject weChatConfig = responseResult.getJSONObject("data"); - String accessTokenUrl = String.format(weChatConfig.get("OPEN_ACCESS_TOKEN_URL").toString(), weChatConfig.get("openAppid"), weChatConfig.get("openAppsecret"), code); - - //获取access_token - Map baseMap = HttpUtils.doGet(accessTokenUrl); + public Boolean cancel() { + String userId = this.getUserId(); + return this.getBaseMapper().updateWeChat(Long.parseLong(userId),null); + } - if(baseMap == null || baseMap.isEmpty()){ return false; } - String openId = (String) baseMap.get("openid"); - /*HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); + /** + * 获取当前登录用户信息 + */ + private String getUserId(){ + HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); String token = request.getHeader("token"); - String userId = RedisUtil.get("dq:token:"+token);*/ - //TODO:测试环境模拟从redis中拿取用户id - String userId = "1"; - Boolean result = this.getBaseMapper().updateWeChat(Long.parseLong(userId), openId); - log.info("绑定成功---------------------------------------"); - if (result){ - try { - log.info("转发成功---------------------------------------"); - response.sendRedirect("https://www.baidu.com?openId="+openId); - }catch (IOException e){ - e.printStackTrace(); - } - } - return false; + return RedisUtil.get("dq:token:"+token); } } \ No newline at end of file diff --git a/dq-financial-hrms/src/main/resources/mapper/hrms/EmployeeDao.xml b/dq-financial-hrms/src/main/resources/mapper/hrms/EmployeeDao.xml index 326e5d3c..1950ecbf 100644 --- a/dq-financial-hrms/src/main/resources/mapper/hrms/EmployeeDao.xml +++ b/dq-financial-hrms/src/main/resources/mapper/hrms/EmployeeDao.xml @@ -459,4 +459,5 @@ company_mail = #{companyMail},spare_mail = #{spareMail},head_portarit_url = #{headPortaritUrl} WHERE id = #{id} + \ No newline at end of file diff --git a/dq-financial-hrms/src/main/resources/mapper/hrms/UserDao.xml b/dq-financial-hrms/src/main/resources/mapper/hrms/UserDao.xml index f45444af..ce325376 100644 --- a/dq-financial-hrms/src/main/resources/mapper/hrms/UserDao.xml +++ b/dq-financial-hrms/src/main/resources/mapper/hrms/UserDao.xml @@ -22,11 +22,11 @@ @@ -34,7 +34,7 @@ @@ -45,4 +45,13 @@ UPDATE hrms_user SET wechat_id = #{weChatId} WHERE id = #{id} + + \ No newline at end of file diff --git a/dq-framework-common/src/main/java/com/daqing/framework/model/response/PromptSuccess.java b/dq-framework-common/src/main/java/com/daqing/framework/model/response/PromptSuccess.java index 8cd0992f..ecce71be 100644 --- a/dq-framework-common/src/main/java/com/daqing/framework/model/response/PromptSuccess.java +++ b/dq-framework-common/src/main/java/com/daqing/framework/model/response/PromptSuccess.java @@ -25,4 +25,10 @@ public class PromptSuccess { public static final String MATCHES_STRING = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)[a-zA-Z\\d]{6,}$"; public static final Long OVERDUE_TIME = 70L; // 过期时间,单位为秒 + + public static final String QR_CODE_FAIL = "二维码获取失败,请稍后重试"; + + public static final String QR_CODE_BINDING_SUCCESS = "已绑定,扫码即可登录"; + + public static final String UPLOAD_FILE_PATH = "D://upload//"; } diff --git a/dq-framework-common/src/main/java/com/daqing/framework/util/Md5Util.java b/dq-framework-common/src/main/java/com/daqing/framework/util/Md5Util.java index 862ddc5f..f683905b 100644 --- a/dq-framework-common/src/main/java/com/daqing/framework/util/Md5Util.java +++ b/dq-framework-common/src/main/java/com/daqing/framework/util/Md5Util.java @@ -22,12 +22,13 @@ public class Md5Util { } public static void main(String[] args) throws UnsupportedEncodingException { - System.out.printf(md5("1111Aa5")); + //System.out.printf(md5("1111Aa5")); /*String s = URLEncoder.encode("www.occupationlab.com", "utf-8"); System.out.println(s);*/ //System.out.printf(md5("1234561")); - String s = URLEncoder.encode("www.occupationlab.com", "utf-8"); + //String s = URLEncoder.encode("www.occupationlab.com", "utf-8"); //System.out.println(s); //System.out.println(md5("1234564")); + System.out.println(md5("Aa12344")); } } diff --git a/dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/ext/EmployeeAndUserVO.java b/dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/ext/EmployeeAndUserVO.java index b9183615..d26e096d 100644 --- a/dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/ext/EmployeeAndUserVO.java +++ b/dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/ext/EmployeeAndUserVO.java @@ -27,7 +27,6 @@ import java.util.List; public class EmployeeAndUserVO implements Serializable { @ApiModelProperty("id") - @NotNull(message = "员工id不能为空") @TableId(value = "id", type = IdType.INPUT) private Long id; @@ -67,7 +66,6 @@ public class EmployeeAndUserVO implements Serializable { @ApiModelProperty("图像地址") private String headPortaritUrl; - @NotNull(message = "用户id不能为空") @ApiModelProperty("用户id") private Long userId; @@ -105,9 +103,6 @@ public class EmployeeAndUserVO implements Serializable { /** * 修改信息字段 */ - @ApiModelProperty("接收图像文件") - private MultipartFile file; - @ApiModelProperty("旧手机号") private String primaryPhone; diff --git a/dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/response/HrmsCode.java b/dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/response/HrmsCode.java index 9dfe9436..78212a16 100644 --- a/dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/response/HrmsCode.java +++ b/dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/response/HrmsCode.java @@ -53,6 +53,7 @@ public enum HrmsCode implements ResultCode { USER_PRIMARY_PHONE_MISTAKE(false,88010,"原手机号码错误!"), USER_PHONE_OR_CODE_NOT_NULL(false,88011,"手机号码或验证码不能为空!"), USER_BINDING_FAIL(false,88012,"绑定失败,手机验证码错误!"), + USER_FILE_IS_NULL(false,88015,"当前文件不存在,请正确选择文件!"), USER_FILE_TYPE_MISTAKE(false,88013,"文件格式不正确,请重新选择图片文件!"), USER_FILE_UPLOAD_FAIL(false,88014,"上传图像失败,请稍后刷新再试!"),