From 7da22f97db382c98efd03f1bc63071f78467ddad Mon Sep 17 00:00:00 2001 From: wangpengfei <1928057482@qq.com> Date: Fri, 5 Jul 2024 18:01:44 +0800 Subject: [PATCH] 7/5 --- .../yxt/portal/apiadmin/SysStaffinfoRest.java | 80 ++- .../com/yxt/portal/apiwx/AppSysUserRest.java | 486 +++++++++++++++ .../com/yxt/portal/apiwx/WxSysUserRest.java | 578 ++++++++++++++++++ .../com/yxt/portal/biz/sysrole/SysRole.java | 1 + .../com/yxt/portal/biz/sysrole/SysRoleVo.java | 2 + .../sysstaffinfo/SysStaffinfoDetailsVo.java | 117 +--- .../biz/sysstaffinfo/SysStaffinfoDto.java | 10 +- .../biz/sysstaffinfo/SysStaffinfoMapper.xml | 94 +-- .../biz/sysstaffinfo/SysStaffinfoService.java | 178 +++++- .../biz/sysstafforg/SysStaffOrgDetailsVo.java | 4 +- .../biz/sysstafforg/SysStaffOrgMapper.xml | 2 +- .../com/yxt/portal/biz/sysuser/SysUser.java | 1 + .../portal/biz/sysuser/SysUserService.java | 64 +- .../com/yxt/portal/biz/sysuser/SysUserVo.java | 8 + .../biz/sysuserrole/SysUserRoleMapper.java | 2 + .../biz/sysuserrole/SysUserRoleMapper.xml | 9 +- .../biz/sysuserrole/SysUserRoleService.java | 3 + .../portal/biz/sysuserrole/SysUserRoleVo.java | 1 + 18 files changed, 1384 insertions(+), 256 deletions(-) create mode 100644 src/main/java/com/yxt/portal/apiwx/AppSysUserRest.java create mode 100644 src/main/java/com/yxt/portal/apiwx/WxSysUserRest.java diff --git a/src/main/java/com/yxt/portal/apiadmin/SysStaffinfoRest.java b/src/main/java/com/yxt/portal/apiadmin/SysStaffinfoRest.java index 6feea80..aa1adff 100644 --- a/src/main/java/com/yxt/portal/apiadmin/SysStaffinfoRest.java +++ b/src/main/java/com/yxt/portal/apiadmin/SysStaffinfoRest.java @@ -12,11 +12,10 @@ import com.yxt.common.core.result.ResultBean; import com.yxt.common.core.vo.PagerVo; import com.yxt.portal.biz.sysstaffinfo.SysStaffinfoService; import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import java.text.SimpleDateFormat; import java.util.Collections; @@ -59,7 +58,8 @@ public class SysStaffinfoRest{ * @param pq 查询条件 * @return */ - + @ApiOperation("员工管理分页列表") + @PostMapping("/listPage") public ResultBean> listPage(@RequestBody PagerQuery pq) { ResultBean> rb = ResultBean.fireFail(); IPage page = sysStaffinfoService.pagerList(pq); @@ -74,7 +74,8 @@ public class SysStaffinfoRest{ * @param dto 数据传输对象 * @return */ - + @ApiOperation("新增保存") + @PostMapping("/save") public ResultBean save(SysStaffinfoDto dto) { ResultBean rb = ResultBean.fireFail(); ResultBean resultBean = sysStaffinfoService.saveStaffInfo(dto); @@ -91,7 +92,8 @@ public class SysStaffinfoRest{ * @param sid 员工信息sid * @return */ - + @ApiOperation("修改保存") + @PostMapping("/update/{sid}") public ResultBean update(SysStaffinfoDto dto, String sid) { ResultBean rb = ResultBean.fireFail(); ResultBean resultBean = sysStaffinfoService.updateStaffInfo(dto, sid); @@ -107,7 +109,8 @@ public class SysStaffinfoRest{ * @param sysStaffQuery 数据传输对象 * @return */ - + @ApiOperation("设置离职") + @PostMapping("/del") public ResultBean del(SysStaffQuery sysStaffQuery) { ResultBean rb = ResultBean.fireFail(); //查询员工是否是离职 @@ -126,8 +129,9 @@ public class SysStaffinfoRest{ return rb.success().setMsg("成功"); } - - public ResultBean fetchBySid(String sid) { + @ApiOperation("员工信息编辑初始化及详情") + @GetMapping("/fetchBySid/{sid}") + public ResultBean fetchBySid(@PathVariable("sid") String sid) { ResultBean rb = ResultBean.fireFail(); SysStaffinfoDetailsVo sysStaffinfo = sysStaffinfoService.selectDetailsBySid(sid); if (sysStaffinfo == null) { @@ -135,14 +139,28 @@ public class SysStaffinfoRest{ } return rb.success().setData(sysStaffinfo); } - + /** + * 获取集团内全部员工姓名 + * + * @param staffName 员工姓名 + * @return + */ + @ApiOperation("获取集团内全部员工姓名") + @GetMapping("/getStaffName") public ResultBean>> getStaffName(String staffName, String deptSid) { ResultBean rb = ResultBean.fireFail(); List> staffNameList = sysStaffinfoService.getStaffName(staffName, deptSid); return rb.success().setData(staffNameList); } - + /** + * 获取部门内全部员工姓名 + * + * @param staffName 员工姓名 + * @return + */ + @ApiOperation("获取部门内全部员工姓名") + @GetMapping("/getStaffNameByDeptSid") public ResultBean>> getStaffNameByDeptSid(String staffName, String deptSid) { ResultBean rb = ResultBean.fireFail(); @@ -151,12 +169,16 @@ public class SysStaffinfoRest{ } - + @ApiOperation("获取App通讯录") + @ResponseBody + @GetMapping("/selectAppContactsList") public ResultBean> selectAppContactsList(String names) { return new ResultBean>().success().setData(sysStaffinfoService.selectAppContactsList()); } - + @ApiOperation("app查看通讯录详情") + @ResponseBody + @GetMapping("/selectAppContactsVO/{staffSid}") public ResultBean selectAppContactsVO(String staffSid) { if (StringUtils.isBlank(staffSid)) { return new ResultBean().fail().setMsg("staffSid不能为空"); @@ -176,7 +198,9 @@ public class SysStaffinfoRest{ return new ResultBean().success().setData(appContactsDetailsVo); } - + @ApiOperation("App通讯录搜索") + @ResponseBody + @PostMapping("/searchAppContactsList") public ResultBean> searchAppContactsList(PagerQuery pq) { String names = pq.getParams().getName(); if (StringUtils.isBlank(names)) @@ -189,7 +213,9 @@ public class SysStaffinfoRest{ return new ResultBean>().success().setData(pv_result); } - + @ApiOperation("App通讯录搜索2") + @ResponseBody + @PostMapping("/searchAppContactsList2") public ResultBean> searchAppContactsList2(PagerQuery pq) { PagerVo page1 = new PagerVo<>(); IPage iPage = sysStaffinfoService.searchAppContactsList2(pq); @@ -199,34 +225,46 @@ public class SysStaffinfoRest{ return new ResultBean>().success().setData(pv_result); } - + @ApiOperation("销售订单-内部推荐人下拉框") + @ResponseBody + @GetMapping("/selectStaffList") public ResultBean> selectStaffList(PcSysStaffQuery pcSysStaffQuery) { return sysStaffinfoService.selectStaffList(pcSysStaffQuery); } - + @ApiOperation("移动端-销售订单-内部推荐人下拉框") + @ResponseBody + @PostMapping("/getUserList") public ResultBean> getUserList(PagerQuery pagerQuery) { ResultBean rb = ResultBean.fireFail(); PagerVo pv = sysStaffinfoService.getUserList(pagerQuery); return rb.success().setData(pv); } - + @ApiOperation("存放地点变更-获取人员列表") + @ResponseBody + @GetMapping("/getGressionUserList/{userSid}") public ResultBean> getGressionUserList(String userSid) { return sysStaffinfoService.getGressionUserList(userSid, ""); } - + @ApiOperation("切换机构:存放地点变更-获取人员列表") + @ResponseBody + @GetMapping("/getGressionUserList") public ResultBean> getGressionUserList(String userSid, String orgPath) { return sysStaffinfoService.getGressionUserList(userSid, orgPath); } - + @ApiOperation("获取集团所有人员") + @ResponseBody + @GetMapping("/selectStaffLists") public ResultBean> selectStaffLists() { return sysStaffinfoService.selectStaffLists(); } - + @ApiOperation("获取集团所有在职人员") + @ResponseBody + @GetMapping("/selectStaffListss") public ResultBean> selectStaffListss() { return sysStaffinfoService.selectStaffListss(); } diff --git a/src/main/java/com/yxt/portal/apiwx/AppSysUserRest.java b/src/main/java/com/yxt/portal/apiwx/AppSysUserRest.java new file mode 100644 index 0000000..d86db4f --- /dev/null +++ b/src/main/java/com/yxt/portal/apiwx/AppSysUserRest.java @@ -0,0 +1,486 @@ +package com.yxt.portal.apiwx; + +import com.alibaba.fastjson.JSON; +import com.auth0.jwt.JWT; +import com.auth0.jwt.interfaces.DecodedJWT; +import com.yxt.common.base.config.RedisUtil; +import com.yxt.common.base.config.component.FileUploadComponent; +import com.yxt.common.base.utils.*; +import com.yxt.common.core.result.ResultBean; +import com.yxt.portal.biz.sysorganization.SysOrganization; +import com.yxt.portal.biz.sysorganization.SysOrganizationService; +import com.yxt.portal.biz.sysrole.SysRoleService; +import com.yxt.portal.biz.sysstafforg.SysStaffOrg; +import com.yxt.portal.biz.sysuser.SysUser; +import com.yxt.portal.biz.sysuser.SysUserQuery; +import com.yxt.portal.biz.sysuser.SysUserService; +import com.yxt.portal.biz.sysuser.SysUserVo; +import com.yxt.portal.biz.sysuser.app.AppMySysUserInfo; +import com.yxt.portal.biz.sysuser.app.MyInfoQuery; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.http.HttpServletRequest; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * @Description + * @Author liuguohui + * @Date 2021/9/4 + */ +@Api(tags = "用户表-移动端") +@Controller +@RequestMapping("apiwx/appuser") +public class AppSysUserRest{ + + @Autowired + private SysUserService sysUserService; + + @Autowired + private RedisUtil redisUtil; + @Autowired(required = false) + private HttpServletRequest httpServletRequest; + @Autowired + private FileUploadComponent fileUploadComponent; + @Autowired + private SysRoleService sysRoleService; + @Autowired + private SysOrganizationService sysOrganizationService; + + @PostMapping("/login") + @ResponseBody + @ApiOperation(value = "1、app用户登录") + public ResultBean login(SysUserQuery userQuery) { + /* + 1、根据传参设备appId查询绑定账号 + 1、1未查询到绑定的账号: + 1、1、1、查询用户登录账号(不存在-->返回“账号不存在”); + 1、1、2、账号存在,获取当前账号绑定的设备值: + 1)设备值为空,验证登录成功后即绑定设备,返回用户信息,验证不成功返回错误信息(验证码、密码错误) + 2)设备值存在,向表sys_exception_log插入数据,返回:当前账号已被其它设备绑定(错误码101(说明:错误码为sys_exception_log的id)) + 1、2查询到绑定的账号 + 1、2、1、根据传参设备appId查询到绑定的账号与用户传递的账号不一致 + 1)向表sys_exception_log插入数据,返回:当前设备已绑定其它账号(错误码102) + 1、2、2、根据传参设备appId查询到绑定的账号与用户传递的账号一致,验证登录信息 + 1)验证登录信息,成功后返回用户信息,验证不成功返回错误信息(验证码、密码错误) + */ + ResultBean rb = ResultBean.fireFail(); + String userName = userQuery.getUserName(); + String password = userQuery.getPassword(); + String appId = userQuery.getAppId(); + String verifyCode = userQuery.getVerifyCode(); + String type = userQuery.getType(); // type:1、密码登录2、验证码登录 + + if (StringUtils.isBlank(userName)) return new ResultBean().fail().setMsg("用户名不能为空"); +// if (StringUtils.isBlank(appId)) return new ResultBean().fail().setMsg("appId不能为空"); + if (type.equals("1")) { + if (StringUtils.isBlank(password)) return new ResultBean().fail().setMsg("密码不能为空"); + } else { + if (StringUtils.isBlank(verifyCode)) return new ResultBean().fail().setMsg("验证码不能为空"); + // 访问后清理key + } + boolean isTest = false; + if(userQuery.getIsTest() != null){ + isTest = userQuery.getIsTest(); + } + isTest = true; + if (isTest) {//添加测试版 + //将该appId的所有账号的appId都置为空 + if(StringUtils.isNotBlank(appId)){ + sysUserService.updateAppIdNull(appId); + } + SysUser sysUser = sysUserService.selectByUserNameApp(userName); + if (sysUser == null) { + sysUser = sysUserService.selectByMobile(userName); + if (sysUser == null) { + return rb.setMsg("用户名或密码错误"); + } + } + if (type.equals("1")) { + String md5 = Encodes.md5(password); + if (md5.equals(sysUser.getPassword())) { + if(StringUtils.isNotBlank(appId)){ + sysUserService.updateAppId(sysUser.getSid(), appId); + } + SysUserVo sysUserVo = sysUserService.selectUser(sysUser); + if (sysUserVo == null) { + return rb.setMsg("用户名或密码错误"); + } + insertLoginLog(sysUser); + return new ResultBean().success().setData(sysUserVo); + } else { + return new ResultBean().fail().setMsg("用户名或密码错误"); + } + } else { + String codeFromRedis = redisUtil.get("loginCode" + userName); + if (StringUtils.isBlank(codeFromRedis)) + return new ResultBean().fail().setMsg("短信验证码已失效,请重新发送"); + if (verifyCode.equals(codeFromRedis.substring(0, 4))) { + if(StringUtils.isNotBlank(appId)){ + sysUserService.updateAppId(sysUser.getSid(), appId); + } + SysUserVo sysUserVo = sysUserService.selectUser(sysUser); + if (sysUserVo == null) { + return rb.setMsg("用户名或密码错误"); + } + redisUtil.remove("loginCode" + userName); + insertLoginLog(sysUser); + return new ResultBean().success().setData(sysUserVo); + } else { + return new ResultBean().fail().setMsg("短信验证码错误或已失效,请重新获取"); + } + } + } else { + SysUser sysUser = sysUserService.selectByAppId(appId); + if (null == sysUser) { // 未查询到绑定的账号 + sysUser = sysUserService.selectByUserNameApp(userName); + if (sysUser == null) { + sysUser = sysUserService.selectByMobile(userName); + if (sysUser == null) { + return rb.setMsg("用户名或密码错误"); + } + } + String appIdVal = sysUser.getAppId(); + if (StringUtils.isBlank(appIdVal)) { // 设备值为空 + if (type.equals("1")) { + String md5 = Encodes.md5(password); + if (md5.equals(sysUser.getPassword())) { + sysUserService.updateAppId(sysUser.getSid(), appId); + SysUserVo sysUserVo = sysUserService.selectUser(sysUser); + if (sysUserVo == null) { + return rb.setMsg("用户名或密码错误"); + } + insertLoginLog(sysUser); + return new ResultBean().success().setData(sysUserVo); + } else { + return new ResultBean().fail().setMsg("用户名或密码错误"); + } + } else { + String codeFromRedis = redisUtil.get("loginCode" + userName); + if (StringUtils.isBlank(codeFromRedis)) + return new ResultBean().fail().setMsg("短信验证码已失效,请重新发送"); + if (verifyCode.equals(codeFromRedis.substring(0, 4))) { + sysUserService.updateAppId(sysUser.getSid(), appId); + SysUserVo sysUserVo = sysUserService.selectUser(sysUser); + if (sysUserVo == null) { + return rb.setMsg("用户名或密码错误"); + } + redisUtil.remove("loginCode" + userName); + insertLoginLog(sysUser); + return new ResultBean().success().setData(sysUserVo); + } else { + return new ResultBean().fail().setMsg("短信验证码错误或已失效,请重新获取"); + } + } + } else { // 设备值存在 + int res = insertSysExceptionLog("b", JSON.toJSON(userQuery).toString(), "当前账号已被其它设备绑定"); + return new ResultBean().fail().setMsg("当前账号已被其它设备绑定(错误码:" + res + ")"); + } + } else { // 查询到绑定的账号 + if (userName.equals(sysUser.getUserName()) || userName.equals(sysUser.getMobile())) { // 设备appId一致,验证用户名 + if (type.equals("1")) { + String md5 = Encodes.md5(password); + if (md5.equals(sysUser.getPassword())) { + SysUserVo sysUserVo = sysUserService.selectUser(sysUser); + if (sysUserVo == null) { + return rb.setMsg("用户名或密码错误"); + } + insertLoginLog(sysUser); + return new ResultBean().success().setData(sysUserVo); + } else { + return new ResultBean().fail().setMsg("用户名或密码错误"); + } + } else { + String codeFromRedis = redisUtil.get("loginCode" + userName); + if (StringUtils.isBlank(codeFromRedis)) + return new ResultBean().fail().setMsg("短信验证码已失效,请重新发送"); + if (verifyCode.equals(codeFromRedis.substring(0, 4))) { + SysUserVo sysUserVo = sysUserService.selectUser(sysUser); + if (sysUserVo == null) { + return rb.setMsg("该用户不是公司员工"); + } + redisUtil.remove("loginCode" + userName); + insertLoginLog(sysUser); + return new ResultBean().success().setData(sysUserVo); + } else { + return new ResultBean().fail().setMsg("短信验证码错误或已失效,请重新获取"); + } + } + } else { // 用户名不一致 + int res = insertSysExceptionLog("a", JSON.toJSON(userQuery).toString(), "当前设备已绑定其它账号"); + return new ResultBean().fail().setMsg("当前设备已绑定其它账号(错误码:" + res + ")"); + } + } + } + } + + /** + * 插入登录日志 + * + * @param user + */ + private void insertLoginLog(SysUser user) { +// SystemLog systemLog = new SystemLog(); +// systemLog.setUserName(user.getUserName()); +// String ip = WebUtil.getIpAddr(httpServletRequest); +// systemLog.setUserIp(ip); +// systemLog.setEventUrl("portal/v1/appuser/login"); +// systemLog.setEventContent("用户登录"); +// systemLog.setEventName("用户登录"); +// systemLogService.save(systemLog); + } + + /** + * 手机发送短信验证码 + * + * @param mobile + * @param type 1、登录2、修改密码3、找回密码 + * @param appId 绑定手机的appid + * @return + */ + @ApiOperation(value = "手机发送验证码(登录、修改密码、找回密码)") + @ResponseBody + @PostMapping("/sendVerificationCodeForApp") + public ResultBean sendVerificationCodeForApp(String mobile, String type, String appId) { + if (StringUtils.isBlank(mobile) || !RegexUtil.isMobile(mobile)) { + return new ResultBean().fail().setMsg("请输入正确的手机号"); + } + if (type.equals("1") && StringUtils.isBlank(appId)) { + return new ResultBean().fail().setMsg("appId不能为空"); + } + // 登录、修改密码、重置密码先验证mobile与appId是否一致 +// if(type.equals("1") && !appId.equals(sysUser.getAppId())){ +// return new ResultBean().fail().setMsg("当前设备与账号不匹配,请解绑后再试"); +// } + if (type.equals("2") || type.equals("3")) { + SysUser sysUser = sysUserService.selectByUserNameApp(mobile); + if (null == sysUser) { + sysUser = sysUserService.selectByMobile(mobile); + if (sysUser == null) { + return new ResultBean().fail().setMsg("该手机号暂时还未注册,请先注册"); + } + + } + } else { // 登录 + SysUser sysUser = sysUserService.selectByAppId(appId); + if (sysUser == null) { // 设备未绑定账号 + sysUser = sysUserService.selectByUserNameApp(mobile); + if (sysUser == null) { + sysUser = sysUserService.selectByMobile(mobile); + if (sysUser == null) { + return new ResultBean().fail().setMsg("该手机号暂时还未注册,请先注册"); + } + } + /*if (StringUtils.isNotBlank(sysUser.getAppId())) { + Map map = new HashMap<>(); + map.put("mobile", mobile); + map.put("appId", appId); + int res = insertSysExceptionLog("b", JSON.toJSON(map).toString(), "当前账号已被其它设备绑定"); + return new ResultBean().fail().setMsg("当前账号已被其它设备绑定(错误码:" + res + ")"); + }*/ + } else { // 设备已绑定账号 + /* if (!mobile.equals(sysUser.getMobile())) { + Map map = new HashMap<>(); + map.put("mobile", mobile); + map.put("appId", appId); + int res = insertSysExceptionLog("a", JSON.toJSON(map).toString(), "当前设备已绑定其它账号"); + return new ResultBean().fail().setMsg("当前设备已绑定其它账号(错误码:" + res + ")"); + }*/ + } + } + return sysUserService.sendVerificationCodeForApp(mobile, type); + } + + /** + * 插入错误的信息 + * + * @param operChar + * @param operArg + * @param remark + */ + private int insertSysExceptionLog(String operChar, String operArg, String remark) { +// SysExceptionLog sysExceptionLog = new SysExceptionLog(); +// sysExceptionLog.setExceptionCode("M00001"); // 当前设备已绑定其它账号 +// sysExceptionLog.setExceptionType("移动端登陆"); +// sysExceptionLog.setOperChar(operChar); +// sysExceptionLog.setOperArg(operArg); +// sysExceptionLog.setRemark(remark); +// sysExceptionLogService.insert(sysExceptionLog); + return 1; + } + + @ApiOperation(value = "我的信息") + @ResponseBody + @GetMapping("/getMyInfo/{userSid}") + public ResultBean getMyInfo(String userSid) { + if (StringUtils.isBlank(userSid)) return new ResultBean().fail().setMsg("userSid不能为空"); + SysUserVo sysUserVo = sysUserService.fetchBySidVo(userSid); + if (null == sysUserVo) new ResultBean().fail().setMsg("信息错误"); + AppMySysUserInfo userInfo = new AppMySysUserInfo(); + String headImage = ""; + if (StringUtils.isNotBlank(sysUserVo.getHeadImage())) { + headImage = fileUploadComponent.getUrlPrefix() + sysUserVo.getHeadImage(); + } + userInfo.setHeadImage(headImage); + userInfo.setName(StringUtils.isBlank(sysUserVo.getName()) ? "" : sysUserVo.getName()); + userInfo.setId("ID:" + sysUserVo.getId()); +// Map map = new HashMap<>(); +// map.put("headImage", StringUtils.isBlank(sysUserVo.getHeadImage())?"":sysUserVo.getHeadImage()); +// map.put("name", StringUtils.isBlank(sysUserVo.getName())?"":sysUserVo.getName()); +// map.put("ID", "ID:"+sysUserVo.getId()); // 是否为jobNumber,暂时为空 + return new ResultBean().success().setData(userInfo); + } + + @ApiOperation(value = "我的信息:切换机构") + @ResponseBody + @GetMapping("/getMyInfo") + public ResultBean getMyInfo(MyInfoQuery myInfoQuery) { + ResultBean rb = ResultBean.fireFail(); + String userSid = myInfoQuery.getUserSid(); + String orgPath = myInfoQuery.getOrgPath(); + SysUserVo sysUserVo = sysUserService.fetchBySidVo(userSid); + if (null == sysUserVo) rb.setMsg("信息错误"); + AppMySysUserInfo userInfo = new AppMySysUserInfo(); + String headImage = ""; + if (StringUtils.isNotBlank(sysUserVo.getHeadImage())) { + headImage = fileUploadComponent.getUrlPrefix() + sysUserVo.getHeadImage(); + } + userInfo.setHeadImage(headImage); + userInfo.setName(StringUtils.isBlank(sysUserVo.getName()) ? "" : sysUserVo.getName()); + userInfo.setId("ID:" + sysUserVo.getJobNumber()); + //根据组织机构sid查询该用户的职位以及分公司的部门 + List strings = new ArrayList<>(); + List list = sysUserService.selectOrgBySid(orgPath, sysUserVo.getStaffSid()); + for (SysStaffOrg s : list) { + String orgSid = s.getOrgSid(); + SysOrganization sysOrganization = sysOrganizationService.fetchBySid(orgSid); +// String orgName = s.getOrgName(); + strings.add(sysOrganization.getName()); + } + strings.removeAll(Collections.singleton(null)); + if (!strings.isEmpty()) { + userInfo.setDepartment(String.join("|", strings)); + } + String isAdmin = ""; + SysUser sysUser = sysUserService.fetchBySid(userSid); + if(sysUser != null){ + isAdmin = sysUser.getIsAdmin(); + } + if("1".equals(isAdmin)){ + String roleName = sysRoleService.selectByUserSid(userSid); + userInfo.setPosition(roleName); + + }else{ + //根据用户sid查询岗位 + List stringList = sysUserService.getPost(sysUserVo.getStaffSid()); + stringList.removeAll(Collections.singleton(null)); + if (!stringList.isEmpty()) { + userInfo.setPosition(String.join("|", stringList)); + } + } + + return new ResultBean().success().setData(userInfo); + } + + @ApiOperation(value = "手机更改密码") + @ResponseBody + @PostMapping("/updatePassword") + public ResultBean updatePassword(String userSid, String appId, String oldPassword, String newPassword, HttpServletRequest httpServletRequest) { + ResultBean rb = ResultBean.fireFail(); + String token = httpServletRequest.getHeader("token"); + SysUser user = sysUserService.fetchBySid(userSid); + if (user == null) { + return rb.setMsg("抱歉,用户不存在"); + } + if (!appId.equals(user.getAppId())) { + return rb.setMsg("当前设备与账号不匹配,请解绑后再试"); + } + return sysUserService.updatePasswordApp(user, oldPassword, newPassword, token); + } + + @ApiOperation(value = "手机找回密码验证验证码") + @ResponseBody + @PostMapping("/checkResetPwdCode") + public ResultBean checkResetPwdCode(String resetPwdCode, String mobile) { + if (StringUtils.isBlank(resetPwdCode)) return new ResultBean().fail().setMsg("验证码不能为空"); + String codeFromRedis = redisUtil.get("resetPwdCode" + mobile); + if (StringUtils.isBlank(codeFromRedis)) return new ResultBean().fail().setMsg("短信验证码已失效,请重新发送"); + if (resetPwdCode.equals(codeFromRedis.substring(0, 4))) { + redisUtil.remove("resetPwdCode" + mobile); + return new ResultBean().success(); + } else { + return new ResultBean().fail().setMsg("短信验证码错误或已失效,请重新获取"); + } + } + + + @ApiOperation(value = "手机端找回密码") + @ResponseBody + @PostMapping("/resetPwd") + public ResultBean resetPwdApp(String mobile, String newPwd, HttpServletRequest httpServletRequest) { + String token = httpServletRequest.getHeader("token"); + if (StringUtils.isBlank(mobile) || !RegexUtil.isMobile(mobile)) + return new ResultBean().fail().setMsg("请输入正确的手机号"); + if (StringUtils.isBlank(newPwd)) return new ResultBean().fail().setMsg("请输入密码"); + return sysUserService.resetPwdApp(mobile, newPwd, token); + } + + @ApiOperation(value = "手机修改用户头像") + @ResponseBody + @PostMapping("/updateHeadImage") + public ResultBean updateHeadImage(MultipartFile multipartFile, String userSid) { + SysUser user = sysUserService.fetchBySid(userSid); + if (user == null) return new ResultBean().fail().setMsg("抱歉,用户不存在"); + if (multipartFile.isEmpty()) { + return new ResultBean().fail().setMsg("上传图片不能为空"); + } + String filename = multipartFile.getOriginalFilename(); + String suffix = filename.substring(filename.lastIndexOf(".")); + if (!suffix.equals(".jpg") && !suffix.equals(".jpeg") && !suffix.equals(".png") && !suffix.equals(".bmp") && !suffix.equals(".tif") && !suffix.equals(".gif")) { + return new ResultBean().fail().setMsg("图片格式不正确"); + } + return sysUserService.updateHeadImage(multipartFile, user); + + } + + /** + * 手机端根据token获取userSid + * + * @return + */ + @ApiOperation(value = "手机端根据token获取userSid") + @ResponseBody + @PostMapping("/getUserSidByToken") + public ResultBean getUserSidByToken(String token) { + DecodedJWT decode = JWT.decode(token.substring(3)); + String userSid = JWTUtil.getUserSid(decode); + if (StringUtils.isBlank(userSid)) { + return new ResultBean().fail().setMsg("用户sid不能为空"); + } else { + return new ResultBean().success().setData(userSid); + } + } + + @ApiOperation(value = "解绑某个用户或解绑所有的用户") + @ResponseBody + @PutMapping("/updateAppId") + public ResultBean updateAppId(String mobile) { + return sysUserService.updateAppIdByMobile(mobile); + } + +// @ApiOperation(value = "移动端:查询该菜单是否允许创建,是否有提醒消息") +// @GetMapping(value = "/selectAppHaveMessage") +// public ResultBean selectAppHaveMessage(String menuSid, String orgPath) { +// return sysUserService.selectAppHaveMessage(menuSid,orgPath); +// } + + + // 解绑设备关联的账号 + // 解绑账号绑定的设备 +} diff --git a/src/main/java/com/yxt/portal/apiwx/WxSysUserRest.java b/src/main/java/com/yxt/portal/apiwx/WxSysUserRest.java new file mode 100644 index 0000000..0ded873 --- /dev/null +++ b/src/main/java/com/yxt/portal/apiwx/WxSysUserRest.java @@ -0,0 +1,578 @@ +package com.yxt.portal.apiwx; + +import cn.hutool.core.codec.Base64; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.TypeReference; +import com.auth0.jwt.JWT; +import com.auth0.jwt.interfaces.DecodedJWT; +import com.yxt.common.base.config.RedisUtil; +import com.yxt.common.base.config.component.FileUploadComponent; +import com.yxt.common.base.utils.*; +import com.yxt.common.core.result.ResultBean; +import com.yxt.portal.biz.sysorganization.SysOrganization; +import com.yxt.portal.biz.sysorganization.SysOrganizationService; +import com.yxt.portal.biz.sysstaffinfo.SysStaffinfoService; +import com.yxt.portal.biz.sysuser.SysUser; +import com.yxt.portal.biz.sysuser.SysUserService; +import com.yxt.portal.biz.sysuser.wx.*; +import com.yxt.portal.config.DictCommonType; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +import javax.crypto.Mac; +import javax.crypto.spec.SecretKeySpec; +import javax.servlet.http.HttpServletRequest; +import java.io.BufferedReader; +import java.io.DataOutputStream; +import java.io.InputStreamReader; +import java.io.UnsupportedEncodingException; +import java.net.HttpURLConnection; +import java.net.URL; +import java.net.URLEncoder; +import java.security.InvalidKeyException; +import java.security.Key; +import java.security.NoSuchAlgorithmException; +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.*; + +/** + * @author dimengzhe + * @date 2021/10/5 13:09 + * @description 客户端用户接口 + */ +@Controller +@RequestMapping("apiwx/wxuser") +@Api(tags = "用户表-小程序端") +public class WxSysUserRest{ + + @Autowired + private SysUserService sysUserService; + @Autowired + private SysStaffinfoService sysStaffinfoService; + + @Autowired + private RedisUtil redisUtil; + + @Autowired + private SysOrganizationService sysOrganizationService; + @Autowired + private HttpServletRequest request; + @Autowired + private FileUploadComponent fileUploadComponent; + @Autowired + private HttpServletRequest httpServletRequest; + + /** + * 调用发送短信接口返回值 + */ + static final String RESULT_CODE = "1"; + + /** + * @param mobile 手机号 + * @param type 类型:1、注册,2、登录 3、忘记密码,4旧手机号获取验证码、5新手机号 + * @description: 获取验证码(按类型区分是哪块验证码) + * @return: + * @Author: dimengzhe + * @Date: 2021/10/9 9:12 + */ + @ApiImplicitParams({ + @ApiImplicitParam(name = "mobile", value = "手机号", required = true), + @ApiImplicitParam(name = "type", value = "类型:1、注册,2、登录 3、忘记密码 4、旧手机号获取验证码、5新手机号", required = true), + }) + @ApiOperation(value = "获取验证码(1、注册,2、登录 3、忘记密码)") + @GetMapping("/sendMessageCode") + @ResponseBody + public ResultBean sendMessageCode(String mobile, String type) { + //1、注册,2、登录 3、忘记密码 + ResultBean rb = ResultBean.fireFail(); + //验证手机号是否正确 + if (StringUtils.isBlank(mobile) || !RegexUtil.isMobile(mobile)) { + return rb.setMsg("请输入正确的手机号"); + } + if ("2".equals(type) || "3".equals(type)) { + //查询该手机号是否已注册 + SysUser sysUser = sysUserService.selectByMobileAndType(mobile, 2); + if (null == sysUser) { + return rb.setMsg("该手机号还未注册或已被停用"); + } + } + if ("4".equals(type)) { + //将token解密userSid + String token = request.getHeader("token"); + DecodedJWT decodedJWT = JWT.decode(token.substring(2, token.length())); + String userSid = JWTUtil.getUserSid(decodedJWT); + SysUser sysUser = sysUserService.fetchBySid(userSid); + if (sysUser == null) { + return rb.setMsg("请登录"); + } + if (!sysUser.getUserName().equals(mobile)) { + return rb.setMsg("手机号错误"); + } + } + //验证是否已注册 + if ("5".equals(type)) { + SysUser sysUser = sysUserService.selectByMobileAndType(mobile, 2); + if (sysUser != null) { + return rb.setMsg("该手机号已注册"); + } + } + String verificationCode = ""; + return sysUserService.getWxVerificationCode(mobile, verificationCode, type); + } + + /** + * @param wxSysUserLoginQuery 数据传输对象 + * @description: 免密码登录、账号密码登录 + * @return: + * @Author: dimengzhe + * @Date: 2021/10/9 9:15 + */ + @ApiOperation(value = "登录") + @ResponseBody + @PostMapping("/login") + public ResultBean login(WxSysUserLoginQuery wxSysUserLoginQuery) { + WxSysUserVo wxSysUserVo = new WxSysUserVo(); + ResultBean rb = ResultBean.fireFail(); + String type = wxSysUserLoginQuery.getType();//手机登录类型:1、密码登录,2、验证码登录 + String verifyCode = wxSysUserLoginQuery.getVerifyCode();//验证码 + String password = wxSysUserLoginQuery.getPassword();//密码 + String userName = wxSysUserLoginQuery.getUserName(); + if ("1".equals(type)) {//密码登录 + if (StringUtils.isBlank(password)) { + return rb.setMsg("密码不能为空"); + } + } else if ("2".equals(type)) {//验证码登录 + if (StringUtils.isBlank(verifyCode)) { + return rb.setMsg("验证码不能为空"); + } + } + SysUser sysUser = sysUserService.selectByMobileAndType(userName, 2); + if (null == sysUser) { + return rb.setMsg("账号不存在或已被停用"); + } + if ("1".equals(type)) {//密码登录 + String md5 = Encodes.md5(password); + if (md5.equals(sysUser.getPassword())) {//匹配 + wxSysUserVo = sysUserService.selectByWxUserName(userName, 2); + } else { + return rb.setMsg("用户名或密码错误"); + } + } else if ("2".equals(type)) {//验证码登录 + String redisCode = redisUtil.get(DictCommonType.WX_LOGIN + userName); + if (StringUtils.isBlank(redisCode)) { + return rb.setMsg("短信验证码错误或已失效,请重新获取"); + } + if (verifyCode.equals(redisCode.substring(0, 4))) { + wxSysUserVo = sysUserService.selectByWxUserName(userName, 2); + redisUtil.remove(DictCommonType.WX_LOGIN + userName); + + } else { + return rb.setMsg("短信验证码错误或已失效,请重新获取"); + } + } + return new ResultBean().success().setData(wxSysUserVo); + } + + /** + * @param wxSysUserDto 数据传输对象 + * @description: 客户端注册 + * @return: + * @Author: dimengzhe + * @Date: 2021/10/9 9:21 + */ + @ApiOperation(value = "注册") + @ResponseBody + @PostMapping("/registsUser") + public ResultBean registsUser(WxSysUserDto wxSysUserDto) { + ResultBean rb = ResultBean.fireFail(); + String mobile = wxSysUserDto.getMobile();//手机号 + String idNo = wxSysUserDto.getIdNo();//身份证号 + String verificationCode = wxSysUserDto.getVerificationCode();//验证码 + String name = wxSysUserDto.getName();//姓名 + String result = ""; + //判断身份证号是否正确 + try { + if (StringUtils.isNotBlank(RegexUtil.IDCardValidate(idNo))) { + return rb.setMsg(RegexUtil.IDCardValidate(idNo)); + } + } catch (ParseException e) { + e.printStackTrace(); + } + //判断是否已注册 + int userType = 2;//用户类型 + SysUser sysUser = sysUserService.selectByMobileAndType(mobile, userType); + if (sysUser != null) { + return rb.setMsg("该手机号已注册"); + } + //验证码是否正确 + Map map = sysUserService.mobileValidateWxRegister(mobile, verificationCode); + String code = map.get("code").toString(); + boolean isSave = false; + if (Tools.CODE_SUCCESS.equals(code)) { + //需验证手机号+姓名+身份证号是否匹配 + WxSysUserRegistQuery wxSysUserRegistQuery = new WxSysUserRegistQuery(); + wxSysUserRegistQuery.setMobile(mobile); + wxSysUserRegistQuery.setName(name); + wxSysUserRegistQuery.setIdcard(idNo); + try { + ResultBean resultBean = isTr2(wxSysUserRegistQuery); + if (!resultBean.getSuccess()) { + return ResultBean.fireFail().setMsg(resultBean.getMsg()); + } + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + } catch (InvalidKeyException e) { + e.printStackTrace(); + } + SysUser sysUser1 = new SysUser(); + sysUser1.setUserName(mobile); + sysUser1.setMobile(mobile); + sysUser1.setUserType(userType); + String password = mobile.substring(5, 11); + String md5 = Encodes.md5(password); + sysUser1.setPassword(md5); + //查询客户表中身份证号是否存在,若存在直接更新客户信息。若不存在,则根据姓名和手机号查询, + // 若存在,则更新身份证号,若不存在,则直接创建客户信息 +// WxCrmCustomerQuery wxCrmCustomerQuery = new WxCrmCustomerQuery(); +// wxCrmCustomerQuery.setMobile(mobile); +// wxCrmCustomerQuery.setName(name); +// wxCrmCustomerQuery.setIdNo(idNo); +// //查询最大一级的组织机构 +// SysOrganization sysOrganization = sysOrganizationService.selectOrgCode(); +// if (StringUtils.isBlank(sysOrganization.getOrgCode())) { +// wxCrmCustomerQuery.setOrgCode("" + 1); +// wxCrmCustomerQuery.setOrgSid(sysOrganization.getSid()); +// } else { +// wxCrmCustomerQuery.setOrgSid(sysOrganization.getSid()); +// wxCrmCustomerQuery.setOrgCode(sysOrganization.getOrgCode() + 1); +// } +// +// ResultBean resultBean = crmCustomerFeign.wxSaveCustomer(wxCrmCustomerQuery); +// sysUser1.setStaffSid(resultBean.getData().toString()); + sysUser1.setHeadImage("http://120.46.131.15:8111/upload/appImage/headImage.jpg"); + isSave = sysUserService.save(sysUser1); + String regiMsg = "客户端账号为:" + mobile + "的账号,已注册成功,登录密码为" + password; + result = MsgWs.SendWaitWorkMsg(mobile, regiMsg); + } else { + return ResultBean.fireFail().setMsg(map.get("details").toString()); + } + if (!isSave) { + return ResultBean.fireSuccess().setMsg("注册失败"); + } + if (!RESULT_CODE.equals(result)) { + return ResultBean.fireFail().setMsg("注册成功,未发送密码"); + } + return ResultBean.fireSuccess().setMsg("注册成功"); + } + + /** + * @param userSid 用户sid + * @description: 客户端获取我的信息 + * @return: 头像+保密后的姓名 + * @Author: dimengzhe + * @Date: 2021/10/6 12:19 + */ + @ApiOperation(value = "我的信息") + @ResponseBody + @GetMapping("/myInfo/{userSid}") + public ResultBean selectMyInfo(String userSid) { + ResultBean rb = ResultBean.fireFail(); + SysUser sysUser = sysUserService.fetchBySid(userSid); + if (null == sysUser) { + return rb.setMsg("该用户不存在"); + } + WxMySysUserInfoVo infoVo = sysUserService.selectMyInfo(userSid); +// ResultBean resultBean = crmCustomerFeign.selectBySid(sysUser.getStaffSid()); +// if (resultBean.getSuccess()) { +// infoVo.setName(resultBean.getData().getName()); +// } + if (StringUtils.isBlank(infoVo.getHeadImage())) { + //默认头像 + infoVo.setHeadImage("http://120.46.131.15:8111/upload/appImage/headImage.jpg"); + } else { + infoVo.setHeadImage(fileUploadComponent.getUrlPrefix() + infoVo.getHeadImage()); + } + return rb.success().setData(infoVo); + } + + @ApiOperation(value = "首页") + @ResponseBody + @GetMapping("/selectHomePage/{userSid}") + public ResultBean selectHomePage(String userSid) { + ResultBean rb = ResultBean.fireFail(); + SysUser sysUser = sysUserService.fetchBySid(userSid); + if (null == sysUser) { + return rb.setMsg("该用户不存在"); + } + boolean isHave = false; + WxHomePageVo wxHomePageVo = sysUserService.selectHomePage(userSid); +// ResultBean resultBean = crmCustomerFeign.selectBySid(wxHomePageVo.getStaffSid()); +// if (resultBean.getSuccess()) { +// wxHomePageVo.setIdTerm(resultBean.getData().getEndDate()); +// } + if (StringUtils.isBlank(wxHomePageVo.getHeadImage())) { + //默认头像 + wxHomePageVo.setHeadImage("http://120.46.131.15:8111/upload/appImage/headImage.jpg"); + } else { + wxHomePageVo.setHeadImage(fileUploadComponent.getUrlPrefix() + wxHomePageVo.getHeadImage()); + } + //2018.08.24-2038.08.24 + /*String idTerm = wxHomePageVo.getIdTerm(); + List split = Arrays.asList(idTerm.split("-")); + if (split.size() == 2) { + String idTermEnd = split.get(1); + String date = idTermEnd.replace('.', '-'); + int days = days(date); + if (days == 30 || days == 60) { + isHave = true; + wxHomePageVo.setMessage("您的身份证将在" + days + "天后到期,请及时更新信息"); + } + }*/ + wxHomePageVo.setIsHave(isHave); + return new ResultBean().success().setData(wxHomePageVo); + } + + @ApiOperation(value = "客户端验证验证码是否正确") + @ResponseBody + @PostMapping("/checkResetPwdCode") + @ApiImplicitParams({ + @ApiImplicitParam(name = "code", value = "验证码", required = true), + @ApiImplicitParam(name = "mobile", value = "手机号", required = true), + @ApiImplicitParam(name = "type", value = "类型:1、找回密码 2、验证旧手机号的验证码、3、验证新手机好的验证码", required = true) + }) + public ResultBean checkResetPwdCode(String code, String mobile, String type) { + ResultBean rb = ResultBean.fireFail(); + String key = ""; + if (!"1".equals(type) && !"2".equals(type) && !"3".equals(type)) { + return rb.setMsg("类型错误"); + } + if ("1".equals(type)) { + key = DictCommonType.WX_FORGET + mobile; + } else if ("2".equals(type)) { + key = DictCommonType.WX_UPDATE + mobile; + } else if ("3".equals(type)) { + key = DictCommonType.WX_NEW + mobile; + } + String keyOne = redisUtil.get(key); + String redisCode = redisUtil.get(key).substring(0, 4); + // 判断验证码是否失效 + if (StringUtils.isEmpty(redisCode)) { + return rb.setMsg("验证码失效"); + } else if (!"".equals(redisCode) && !code.equals(redisCode)) { + return rb.setMsg("验证码错误"); + } + return rb.success(); + } + + /** + * @param mobile 手机号 + * @param newPwd 新密码 + * @description: 客户端找回密码 + * @return: + * @Author: dimengzhe + * @Date: 2021/10/9 9:21 + */ + @ApiOperation(value = "客户端找回密码") + @ResponseBody + @PostMapping("/resetPwd") + public ResultBean resetPwdWx(String mobile, String newPwd) { + if (StringUtils.isBlank(mobile) || !RegexUtil.isMobile(mobile)) { + return new ResultBean().fail().setMsg("请输入正确的手机号"); + } + if (StringUtils.isBlank(newPwd)) { + return new ResultBean().fail().setMsg("请输入密码"); + } + return sysUserService.resetPwdWx(mobile, newPwd); + } + + @ApiOperation(value = "根据用户sid查询用户信息") + @ResponseBody + @PostMapping("/selectBySid") + public ResultBean selectBySid(String sid) { + SysUser sysUser = sysUserService.fetchBySid(sid); + if (sysUser == null) { + sysUser = new SysUser(); + return new ResultBean().fail().setData(sysUser).setMsg("用户不存在"); + } + return new ResultBean().success().setData(sysUser); + } + + /** + * @param end 结束日期 + * @description: 计算两个日期相差多少天 + * @return: + * @Author: dimengzhe + * @Date: 2021/10/12 14:36 + */ + private int days(String end) { + int i = 0; + DateFormat dft = new SimpleDateFormat("yyyy-MM-dd"); + try { + Date star = new Date();//开始时间 + Date endDay = dft.parse(end);//结束时间 + Date nextDay = star; + while (nextDay.before(endDay)) {//当明天不在结束时间之前是终止循环 + Calendar cld = Calendar.getInstance(); + cld.setTime(star); + cld.add(Calendar.DATE, 1); + star = cld.getTime(); + //获得下一天日期字符串 + nextDay = star; + i++; + } + System.out.println("相差天数为:" + i); + } catch (ParseException e) { + e.printStackTrace(); + } + return i; + } + + public ResultBean isTr2(WxSysUserRegistQuery wxSysUserRegistQuery) throws UnsupportedEncodingException, NoSuchAlgorithmException, InvalidKeyException { + String result = ""; + String msg = ""; + //云市场分配的密钥Id + String secretId = "AKID7rl35uAlxzadzo1I299iEiYnMH111I0beWu"; + //云市场分配的密钥Key + String secretKey = "atdsoC8Q2fjuhf31agmub4g8fzh93n8V9yoXQJtk"; + String source = "market"; + + Calendar cd = Calendar.getInstance(); + SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss 'GMT'", Locale.US); + sdf.setTimeZone(TimeZone.getTimeZone("GMT")); + String datetime = sdf.format(cd.getTime()); + // 签名 + String auth = calcAuthorization(source, secretId, secretKey, datetime); + // 请求方法 + String method = "GET"; + // 请求头 + Map headers = new HashMap(); + headers.put("X-Source", source); + headers.put("X-Date", datetime); + headers.put("Authorization", auth); + + // 查询参数 + Map queryParams = new HashMap(); + queryParams.put("idCard", wxSysUserRegistQuery.getIdcard()); + queryParams.put("mobile", wxSysUserRegistQuery.getMobile()); + queryParams.put("realName", wxSysUserRegistQuery.getName()); + // body参数 + Map bodyParams = new HashMap(); + + // url参数拼接 + String url = "https://service-08ijl3bf-1301232119.bj.apigw.tencentcs.com/release/phonecheck"; + if (!queryParams.isEmpty()) { + url += "?" + urlencode(queryParams); + } + + BufferedReader in = null; + try { + URL realUrl = new URL(url); + HttpURLConnection conn = (HttpURLConnection) realUrl.openConnection(); + conn.setConnectTimeout(5000); + conn.setReadTimeout(5000); + conn.setRequestMethod(method); + + // request headers + for (Map.Entry entry : headers.entrySet()) { + conn.setRequestProperty(entry.getKey(), entry.getValue()); + } + + // request body + Map methods = new HashMap<>(); + methods.put("POST", true); + methods.put("PUT", true); + methods.put("PATCH", true); + Boolean hasBody = methods.get(method); + if (hasBody != null) { + conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); + + conn.setDoOutput(true); + DataOutputStream out = new DataOutputStream(conn.getOutputStream()); + out.writeBytes(urlencode(bodyParams)); + out.flush(); + out.close(); + } + + // 定义 BufferedReader输入流来读取URL的响应 + in = new BufferedReader(new InputStreamReader(conn.getInputStream())); + String line; + while ((line = in.readLine()) != null) { + result += line; + } + + System.out.println(result); + } catch (Exception e) { + System.out.println(e); + e.printStackTrace(); + } finally { + try { + if (in != null) { + in.close(); + } + } catch (Exception e2) { + e2.printStackTrace(); + } + } + //判断result + JSONObject object = JSONObject.parseObject(result); + Map map = JSONObject.parseObject(object.toJSONString(), new TypeReference>() { + }); + int code = ConstantUtils.getInteger(map, "error_code"); + if (code == 0) { + Map mapo = ConstantUtils.getMap(map, "result"); + String VerificationResult = mapo.get("VerificationResult").toString(); + if ("1".equals(VerificationResult)) { + msg = "信息匹配"; + } else if ("-1".equals(VerificationResult)) { + return ResultBean.fireFail().setMsg("信息不匹配"); + } else if ("0".equals(VerificationResult)) { + return ResultBean.fireFail().setMsg("运营商系统中无记录"); + } + } else { + return ResultBean.fireFail().setMsg(ConstantUtils.getString(map, "reason", "错误")); + } + return ResultBean.fireSuccess().setMsg(msg); + + } + + public static String calcAuthorization(String source, String secretId, String secretKey, String datetime) + throws NoSuchAlgorithmException, UnsupportedEncodingException, InvalidKeyException { + String signStr = "x-date: " + datetime + "\n" + "x-source: " + source; + Mac mac = Mac.getInstance("HmacSHA1"); + Key sKey = new SecretKeySpec(secretKey.getBytes("UTF-8"), mac.getAlgorithm()); + mac.init(sKey); + byte[] hash = mac.doFinal(signStr.getBytes("UTF-8")); + String sig = Base64.encode(hash); + + String auth = "hmac id=\"" + secretId + "\", algorithm=\"hmac-sha1\", headers=\"x-date x-source\", signature=\"" + sig + "\""; + return auth; + } + + public static String urlencode(Map map) throws UnsupportedEncodingException { + StringBuilder sb = new StringBuilder(); + for (Map.Entry entry : map.entrySet()) { + if (sb.length() > 0) { + sb.append("&"); + } + sb.append(String.format("%s=%s", + URLEncoder.encode(entry.getKey().toString(), "UTF-8"), + URLEncoder.encode(entry.getValue().toString(), "UTF-8") + )); + } + return sb.toString(); + } + +} diff --git a/src/main/java/com/yxt/portal/biz/sysrole/SysRole.java b/src/main/java/com/yxt/portal/biz/sysrole/SysRole.java index fa4b152..fa08956 100644 --- a/src/main/java/com/yxt/portal/biz/sysrole/SysRole.java +++ b/src/main/java/com/yxt/portal/biz/sysrole/SysRole.java @@ -46,4 +46,5 @@ public class SysRole extends BaseEntity { @ApiModelProperty(value = "角色组织层级value") private String roleTypeValue; private String orgSid; + private String dataRuleId; } diff --git a/src/main/java/com/yxt/portal/biz/sysrole/SysRoleVo.java b/src/main/java/com/yxt/portal/biz/sysrole/SysRoleVo.java index ebe0635..ae76109 100644 --- a/src/main/java/com/yxt/portal/biz/sysrole/SysRoleVo.java +++ b/src/main/java/com/yxt/portal/biz/sysrole/SysRoleVo.java @@ -44,4 +44,6 @@ public class SysRoleVo implements Vo { private String postName; @ApiModelProperty(value = "组织层级") private String roleTypeValue; + private String dataRuleId; + private String dataRuleValue; } diff --git a/src/main/java/com/yxt/portal/biz/sysstaffinfo/SysStaffinfoDetailsVo.java b/src/main/java/com/yxt/portal/biz/sysstaffinfo/SysStaffinfoDetailsVo.java index e32576f..610441b 100644 --- a/src/main/java/com/yxt/portal/biz/sysstaffinfo/SysStaffinfoDetailsVo.java +++ b/src/main/java/com/yxt/portal/biz/sysstaffinfo/SysStaffinfoDetailsVo.java @@ -1,11 +1,18 @@ package com.yxt.portal.biz.sysstaffinfo; +import com.yxt.portal.biz.sysrole.SysRole; +import com.yxt.portal.biz.sysrole.SysRoleVo; import com.yxt.portal.biz.sysstafforg.SysStaffOrgDetailsVo; import com.yxt.portal.biz.sysstaffpost.SysStaffPostDetailsVo; import com.yxt.common.core.vo.Vo; +import com.yxt.portal.biz.sysuserrole.SysUserRole; +import com.yxt.portal.biz.sysuserrole.SysUserRoleVo; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import java.util.Date; +import java.util.List; + /** * @Author dimengzhe * @Date 2022/2/11 16:12 @@ -14,72 +21,41 @@ import lombok.Data; @Data public class SysStaffinfoDetailsVo implements Vo { private static final long serialVersionUID = 1232171677690215067L; - - @ApiModelProperty(value = "工号") + private String sid; + @ApiModelProperty("工号") private String jobNumber; - - @ApiModelProperty(value = "姓名") + @ApiModelProperty("姓名") private String name; - @ApiModelProperty(value = "性别key") - private Integer genderKey; @ApiModelProperty(value = "性别") private String gender; - @ApiModelProperty(value = "身份证号") + @ApiModelProperty("身份证号") private String idNo; - @ApiModelProperty(value = "证件有效期") + @ApiModelProperty("证件有效期") private String idTerm; @ApiModelProperty("生日") - private String birthday; - @ApiModelProperty(value = "民族") + private Date birthday; + @ApiModelProperty("民族") private String national; - @ApiModelProperty(value = "民族key") - private String nationalKey; @ApiModelProperty("籍贯") private String nativePlace; - @ApiModelProperty(value = "省") - private String province; - @ApiModelProperty(value = "市") - private String city; - @ApiModelProperty(value = "县区") - private String county; - @ApiModelProperty(value = "省code") - private String provinceCode; - @ApiModelProperty(value = "市code") - private String cityCode; - @ApiModelProperty(value = "县区code") - private String countyCode; @ApiModelProperty("住址") private String address; - @ApiModelProperty(value = "手机号") + @ApiModelProperty("手机号") private String mobile; @ApiModelProperty("邮箱") private String email; - @ApiModelProperty(value = "紧急联系人") - private String emergencyContact; - @ApiModelProperty(value = "紧急联系电话") - private String emergencyMobile; - @ApiModelProperty("政治面貌") - private String poliCode; - @ApiModelProperty(value = "政治面貌key") - private String poliCodeKey; @ApiModelProperty("婚姻状况") private String maritalStatus; - @ApiModelProperty("婚姻状况key") - private String maritalStatusKey; @ApiModelProperty("员工类型(无类型、全职、兼职、实习、劳务派遣、退休返聘、劳务外包)") private String personType; - @ApiModelProperty("员工类型key") - private String personTypeKey; @ApiModelProperty("入职时间") - private String joinCompnyDate; + private Date joinCompnyDate; @ApiModelProperty("试用期(无试用期、1个月、2个月、3个月、其他)") private String probPeriod; - @ApiModelProperty("试用期key") - private String probPeriodKey; @ApiModelProperty("计划转正日期") - private String plannedConfirmDate; + private Date plannedConfirmDate; @ApiModelProperty("实际转正日期") - private String confirmationDate; + private Date confirmationDate; @ApiModelProperty("银行卡号") private String bankCardNo; @ApiModelProperty("开户行") @@ -98,58 +74,9 @@ public class SysStaffinfoDetailsVo implements Vo { private String photo; @ApiModelProperty(value = "员工部门信息") private SysStaffOrgDetailsVo sysStaffOrg; - @ApiModelProperty(value = "员工岗位信息") - private SysStaffPostDetailsVo sysStaffPost; + private List sysUserRoles; - //===========================================// - @ApiModelProperty(value = "毕业院校") - private String graduate; - @ApiModelProperty(value = "学历/专业") - private String education; - @ApiModelProperty(value = "职称") - private String title; - @ApiModelProperty(value = "资格认证") - private String qualification; - @ApiModelProperty(value = "驾照类型") - private String licenseType; - @ApiModelProperty(value = "驾照类型key") - private String licenseTypeKey; - @ApiModelProperty(value = "意外险参保:1是,0否") - private Integer isHaveInsurance; - @ApiModelProperty(value = "意外险参保:1是,0否") - private String isHaveInsuranceValue; - @ApiModelProperty(value = "意外险参保时间") - private String insuranceStartDate; - @ApiModelProperty(value = "意外险参保终止日期") - private String insuranceEndDate; - @ApiModelProperty(value = "意外险参保地") - private String insuranceAddr; - @ApiModelProperty(value = "养老:1是,0否") - private Integer isHaveAged; - @ApiModelProperty(value = "养老:1是,0否") - private String isHaveAgedValue; - @ApiModelProperty(value = "医疗:1是,0否") - private Integer isHaveMedical; - @ApiModelProperty(value = "医疗:1是,0否") - private String isHaveMedicalValue; - @ApiModelProperty(value = "工伤:1是,0否") - private Integer isHaveInjury; - @ApiModelProperty(value = "工伤:1是,0否") - private String isHaveInjuryValue; - @ApiModelProperty(value = "失业:1是,0否") - private Integer isHaveUnemploy; - @ApiModelProperty(value = "失业:1是,0否") - private String isHaveUnemployValue; - @ApiModelProperty(value = "社保参保地") - private String insuredPlace; - @ApiModelProperty(value = "纸质档案保管地") - private String paperPlace; - @ApiModelProperty(value = "合同起止日期") - private String contractStartDate; - @ApiModelProperty(value = "合同结束日期") - private String contractEndDate; - @ApiModelProperty(value = "离职日期") - private String quitDate; - @ApiModelProperty(value = "离职原因") - private String quitReason; + private String accountType;//账号类型 1单位管理员,2操作员,0是平台管理员 3非登录账户 + private String userType;//用户类型:1员工、2客户、3供应商 + private List sysRoleVos;// } diff --git a/src/main/java/com/yxt/portal/biz/sysstaffinfo/SysStaffinfoDto.java b/src/main/java/com/yxt/portal/biz/sysstaffinfo/SysStaffinfoDto.java index 17226fa..51a2cd5 100644 --- a/src/main/java/com/yxt/portal/biz/sysstaffinfo/SysStaffinfoDto.java +++ b/src/main/java/com/yxt/portal/biz/sysstaffinfo/SysStaffinfoDto.java @@ -5,6 +5,8 @@ import com.fasterxml.jackson.annotation.JsonFormat; import com.yxt.portal.biz.sysstafforg.SysStaffOrgDto; import com.yxt.portal.biz.sysstaffpost.SysStaffPostDto; import com.yxt.common.core.dto.Dto; +import com.yxt.portal.biz.sysuserrole.SysUserRole; +import com.yxt.portal.biz.sysuserrole.SysUserRoleDto; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -12,6 +14,7 @@ import lombok.Data; import javax.validation.constraints.NotBlank; import javax.validation.constraints.Pattern; import java.util.Date; +import java.util.List; /** * Project: anrui_portal(门户建设)
@@ -133,7 +136,8 @@ public class SysStaffinfoDto implements Dto { private SysStaffOrgDto sysStaffOrg; @ApiModelProperty(value = "员工岗位信息") private SysStaffPostDto sysStaffPost; - + @ApiModelProperty(value = "员工角色信息") + private List sysUserRoles; //========================================// @ApiModelProperty(value = "毕业院校") private String graduate; @@ -182,5 +186,7 @@ public class SysStaffinfoDto implements Dto { private Date quitDate; @ApiModelProperty(value = "离职原因") private String quitReason; - + private String accountType;//账号类型 1单位管理员,2操作员,0是平台管理员 3非登录账户 + private String userType;//用户类型:1员工、2客户、3供应商 + private String orgSid; } \ No newline at end of file diff --git a/src/main/java/com/yxt/portal/biz/sysstaffinfo/SysStaffinfoMapper.xml b/src/main/java/com/yxt/portal/biz/sysstaffinfo/SysStaffinfoMapper.xml index 371772a..a8306b4 100644 --- a/src/main/java/com/yxt/portal/biz/sysstaffinfo/SysStaffinfoMapper.xml +++ b/src/main/java/com/yxt/portal/biz/sysstaffinfo/SysStaffinfoMapper.xml @@ -143,12 +143,11 @@ diff --git a/src/main/java/com/yxt/portal/biz/sysstaffinfo/SysStaffinfoService.java b/src/main/java/com/yxt/portal/biz/sysstaffinfo/SysStaffinfoService.java index 265f577..a2c27aa 100644 --- a/src/main/java/com/yxt/portal/biz/sysstaffinfo/SysStaffinfoService.java +++ b/src/main/java/com/yxt/portal/biz/sysstaffinfo/SysStaffinfoService.java @@ -23,6 +23,7 @@ import com.yxt.portal.biz.sysrole.SysRoleService; import com.yxt.portal.biz.sysstafforg.SysStaffOrgService; import com.yxt.portal.biz.sysstaffpost.SysStaffPostService; import com.yxt.portal.biz.sysuser.SysUserService; +import com.yxt.portal.biz.sysuserrole.SysUserRoleDto; import com.yxt.portal.biz.sysuserrole.SysUserRoleService; import com.yxt.common.base.config.RedisUtil; import com.yxt.common.base.config.component.FileUploadComponent; @@ -33,6 +34,7 @@ import com.yxt.common.base.utils.PinYinUtils; import com.yxt.common.core.query.PagerQuery; import com.yxt.common.core.result.ResultBean; import com.yxt.common.core.vo.PagerVo; +import com.yxt.portal.biz.sysuserrole.SysUserRoleVo; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -270,7 +272,7 @@ public class SysStaffinfoService extends MybatisBaseService sysStaffOrgVos = sysStaffOrgService.selectByStaffS(sid); @@ -628,7 +694,100 @@ public class SysStaffinfoService extends MybatisBaseService sysStaffOrgVos = sysStaffOrgService.selectByStaffS(sid); + List orgList = new ArrayList<>(); + if (sysStaffOrgVos.size() > 0) { + for (SysStaffOrgVo vv : sysStaffOrgVos) { +// String orgSid = sysStaffOrgService.getOrgByOrgSid(vv.getOrgSid()); + String orgSid = vv.getOrgSid(); + SysOrganization sysOrganization = sysOrganizationService.fetchBySid(orgSid); + if (sysOrganization != null) { + orgList.add(orgSid); + } else { + continue; + } + } + } + //根据员工sid查询员工的信息 + SysStaffinfo sysStaffinfo = fetchBySid(sid); + if (sysStaffinfo == null) { + return rb.setMsg("此员工信息不存在"); + } + //查询员工的手机号是否重复 + SysStaffinfo sysStaffinfo2 = baseMapper.selectByMobileAndSid(dto.getMobile(), sid); + if (sysStaffinfo2 != null) { + return rb.setMsg("已存在手机号为" + dto.getMobile() + "的员工"); + } + + //更新员工基础信息 + BeanUtil.copyProperties(dto, sysStaffinfo); + sysStaffinfo.setJobNumber(dto.getJobNumber()); + //更新用户信息 + sysUserService.updateByStaffSid(dto.getJobNumber(), sysStaffinfo.getMobile(), sid); + //更新员工的关联的部门信息 + SysStaffOrgDto sysStaffOrgDto = dto.getSysStaffOrg(); +// int count = sysStaffOrgService.selectByStaffAndOrg(sysStaffOrgDto.getOrgSidPath(), sid, "2"); +// if (count > 0) { +// sysStaffOrgService.deleteByStaffSidAndType(sysStaffOrgDto.getOrgSidPath(), sid, "2"); +// } +// SysStaffOrg sysStaffOrg = sysStaffOrgService.getOrgByStaffSidAndPath(sid,sysStaffOrgDto.getOrgSidPath()); +// if(sysStaffOrg == null){ +// ResultBean staffOrgResultBean = sysStaffOrgService.selectAllByStaffSid(sid); +// sysStaffOrg = staffOrgResultBean.getData(); +// if(sysStaffOrg == null){ +// sysStaffOrg = new SysStaffOrg(); +// sysStaffOrg.setStaffSid(sid); +// BeanUtil.copyProperties(sysStaffOrgDto,sysStaffOrg); +// sysStaffOrg.setManageType("3"); +// sysStaffOrgService.insert(sysStaffOrg); +// }else{ +// BeanUtil.copyProperties(sysStaffOrgDto,sysStaffOrg); +// sysStaffOrg.setManageType("3"); +// sysStaffOrgService.updateById(sysStaffOrg); +// } +// }else{ +// BeanUtil.copyProperties(sysStaffOrgDto,sysStaffOrg); +// sysStaffOrg.setManageType("3"); +// sysStaffOrgService.updateById(sysStaffOrg); +// } + boolean isUpdate = updateById(sysStaffinfo); + if (!isUpdate) { + return rb.setMsg("更新员工信息失败"); + } + List sysStaffOrgVos1 = sysStaffOrgService.selectByStaffS(sid); + List orgList1 = new ArrayList<>(); + if (sysStaffOrgVos1.size() > 0) { + for (SysStaffOrgVo vv : sysStaffOrgVos1) { +// String orgSid = sysStaffOrgService.getOrgByOrgSid(vv.getOrgSid()); + String orgSid = vv.getOrgSid(); + SysOrganization sysOrganization = sysOrganizationService.fetchBySid(orgSid); + if (sysOrganization != null) { + orgList1.add(orgSid); + } else { + continue; + } + } + } + List reduce1 = orgList.stream().filter(item -> !orgList1.contains(item)).collect(toList()); + if (reduce1.size() > 0) { + //根据staffSid查询token + String token = sysUserService.selectByStaffsid(sid).getToken(); + //清空该token + redisUtil.remove(token); + } + return rb.success().setMsg("更新员工信息成功"); + } /** * 根据员工sid查询员工信息 * @@ -656,22 +815,17 @@ public class SysStaffinfoService extends MybatisBaseService().eq("staffSid",sysStaffinfoDetailsVo.getSid())); + List list=sysUserRoleService.selByUserSid(s.getSid()); + sysStaffinfoDetailsVo.setSysUserRoles(list); +// SysStaffPostDetailsVo sysStaffPostDetailsVo = sysStaffPostService.selectByStaff(sid, staffPostDetailsVo.getPostSid()); if(sysStaffOrgDetailsVo != null){ sysStaffinfoDetailsVo.setSysStaffOrg(sysStaffOrgDetailsVo); }else{ sysStaffinfoDetailsVo.setSysStaffOrg(new SysStaffOrgDetailsVo()); } - if(sysStaffPostDetailsVo != null){ - sysStaffinfoDetailsVo.setSysStaffPost(sysStaffPostDetailsVo); - }else{ - sysStaffinfoDetailsVo.setSysStaffPost(new SysStaffPostDetailsVo()); - } - - - } return sysStaffinfoDetailsVo; } diff --git a/src/main/java/com/yxt/portal/biz/sysstafforg/SysStaffOrgDetailsVo.java b/src/main/java/com/yxt/portal/biz/sysstafforg/SysStaffOrgDetailsVo.java index 029c658..d557b03 100644 --- a/src/main/java/com/yxt/portal/biz/sysstafforg/SysStaffOrgDetailsVo.java +++ b/src/main/java/com/yxt/portal/biz/sysstafforg/SysStaffOrgDetailsVo.java @@ -19,8 +19,8 @@ public class SysStaffOrgDetailsVo implements Vo { private String orgName; @ApiModelProperty("部门路径") private String orgSidPath; - @ApiModelProperty("部门名称路径") - private String orgNamePath; +// @ApiModelProperty("部门名称路径") +// private String orgNamePath; @ApiModelProperty(value = "部门编码") private String orgCode; @ApiModelProperty("管理类型:1、主管。2、分管。3、员工") diff --git a/src/main/java/com/yxt/portal/biz/sysstafforg/SysStaffOrgMapper.xml b/src/main/java/com/yxt/portal/biz/sysstafforg/SysStaffOrgMapper.xml index 1bb3f2a..e88e80f 100644 --- a/src/main/java/com/yxt/portal/biz/sysstafforg/SysStaffOrgMapper.xml +++ b/src/main/java/com/yxt/portal/biz/sysstafforg/SysStaffOrgMapper.xml @@ -50,7 +50,7 @@ + + delete from sys_user_role where userSid=#{params} diff --git a/src/main/java/com/yxt/portal/biz/sysuserrole/SysUserRoleService.java b/src/main/java/com/yxt/portal/biz/sysuserrole/SysUserRoleService.java index 0ab9dbe..4ff7e09 100644 --- a/src/main/java/com/yxt/portal/biz/sysuserrole/SysUserRoleService.java +++ b/src/main/java/com/yxt/portal/biz/sysuserrole/SysUserRoleService.java @@ -99,6 +99,9 @@ public class SysUserRoleService extends MybatisBaseService selectByUserSid(String userSid,String orgSid,String sourceSid) { return baseMapper.selectByUserSid(userSid,orgSid,sourceSid); } + public List selByUserSid(String userSid) { + return baseMapper.selByUserSid(userSid); + } /*public void updateUserRole(SysUserRoleDto dto) { //sysUserRoleService.deleteByUserSid(dto.getUserSid()); SysUserRole entity = new SysUserRole(); diff --git a/src/main/java/com/yxt/portal/biz/sysuserrole/SysUserRoleVo.java b/src/main/java/com/yxt/portal/biz/sysuserrole/SysUserRoleVo.java index 3ee785f..970b6fd 100644 --- a/src/main/java/com/yxt/portal/biz/sysuserrole/SysUserRoleVo.java +++ b/src/main/java/com/yxt/portal/biz/sysuserrole/SysUserRoleVo.java @@ -29,4 +29,5 @@ public class SysUserRoleVo implements Vo { @ApiModelProperty("角色sid") private String roleSid; + private String roleName; }