注册系统用户时为系统用户绑定所属的代理组织

This commit is contained in:
liuchengqian 2022-07-06 17:46:57 +08:00
parent 36da0dfb4b
commit d22cfcc85b
5 changed files with 90 additions and 96 deletions

View File

@ -1,10 +1,10 @@
package com.xkrs.controller;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.aliyuncs.exceptions.ClientException;
import com.xkrs.common.encapsulation.PromptMessageEnum;
import com.xkrs.common.tool.TokenUtil;
import com.xkrs.dao.AgentOrgDao;
import com.xkrs.dao.SysUserDao;
import com.xkrs.model.entity.AgentOrgEntity;
import com.xkrs.model.entity.SysUserEntity;
import com.xkrs.model.qo.SysUserQo;
import com.xkrs.model.qo.SysUserReceiveSmsQo;
@ -15,7 +15,10 @@ import com.xkrs.model.validation.SysUserQoUpdate;
import com.xkrs.model.vo.SysUserVo;
import com.xkrs.service.RedisService;
import com.xkrs.service.SysUserService;
import com.xkrs.sms.SMSHelper;
import com.xkrs.utils.FirePointCodeUtils;
import com.xkrs.utils.RandomUtil;
import org.apache.hc.core5.util.TextUtils;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.BindingResult;
@ -29,7 +32,6 @@ import java.util.concurrent.TimeUnit;
import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationErrorList;
import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject;
import static com.xkrs.utils.AliYunSmsUtils.sendSms;
import static com.xkrs.utils.EncryptDecryptUtil.encry256;
/**
@ -50,11 +52,14 @@ public class SysUserController {
@Resource
private RedisService redisService;
@Resource
private AgentOrgDao agentOrgDao;
@Resource
private SMSHelper smsHelper;
/**
* 修改vip等级
*
* @param sysUserVipLevelQo
* @return
*/
@Transactional(rollbackFor = Exception.class)
@RequestMapping(value = "/updateviplevel", method = RequestMethod.POST)
@ -81,9 +86,6 @@ public class SysUserController {
/**
* 修改是否接收短信
*
* @param sysUserReceiveSmsQo
* @return
*/
@Transactional(rollbackFor = Exception.class)
@RequestMapping(value = "/updatereceivesms", method = RequestMethod.POST)
@ -124,8 +126,6 @@ public class SysUserController {
/**
* 登录用户Token验证
*
* @return
*/
@RequestMapping(value = "/logged/check", method = RequestMethod.POST)
public String loginUserTokenCheck() {
@ -144,6 +144,9 @@ public class SysUserController {
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "OK", locale);
}
/**
* 注册系统用户
*/
@RequestMapping(value = "/add", method = RequestMethod.POST)
public String addUser(@Validated({SysUserQoInsert.class}) @RequestBody SysUserQo userQo, BindingResult bindingResult, HttpServletRequest servletRequest) {
// 获取区域信息
@ -162,9 +165,6 @@ public class SysUserController {
/**
* 删除系统用户
*
* @param userName 用户名
* @return
*/
@RequestMapping(value = "/general/deletesysuser", method = RequestMethod.DELETE)
public String deleteSysUser(@RequestParam(value = "userName") String userName) {
@ -173,9 +173,6 @@ public class SysUserController {
/**
* 软删除指定id的普通用户
*
* @param id
* @return
*/
@RequestMapping(value = "/general/delete", method = RequestMethod.DELETE)
public String deleteCustomUser(@RequestParam(value = "userId", required = false) int id) {
@ -205,9 +202,6 @@ public class SysUserController {
/**
* 判断用户名是否存在
*
* @param userName
* @return
*/
@GetMapping("/booleanUserName")
public String booleanUserName(@RequestParam("userName") String userName) {
@ -226,8 +220,6 @@ public class SysUserController {
/**
* 查看用户信息
*
* @return
*/
@GetMapping("/selectAllUser")
public String selectAllUser(@RequestHeader(value = "Authorization") String token) {
@ -248,10 +240,6 @@ public class SysUserController {
/**
* 管理员进行启用禁用的操作
*
* @param map
* @param token
* @return
*/
@PostMapping("/operateActiveFlag")
public String operateActiveFlag(@RequestBody Map map, @RequestHeader(value = "Authorization") String token) {
@ -277,10 +265,6 @@ public class SysUserController {
/**
* 用户修改密码
*
* @param map
* @param token
* @return
*/
@PostMapping("/updatePassword")
public String updatePassword(@RequestBody Map map, @RequestHeader(value = "Authorization") String token) {
@ -300,10 +284,6 @@ public class SysUserController {
/**
* 管理员修改用户的密码
*
* @param map
* @param token
* @return
*/
@PostMapping("/adminUpdatePassword")
public String adminUpdatePassword(@RequestBody Map map, @RequestHeader(value = "Authorization") String token) {
@ -324,10 +304,6 @@ public class SysUserController {
/**
* 用户忘记密码
*
* @param map
* @param
* @return
*/
@Transactional(rollbackFor = Exception.class)
@PostMapping("/userUnRememberPassword")
@ -350,49 +326,42 @@ public class SysUserController {
}
/**
* 发送手机号
*
* @param phone
* @return
* @throws ClientException
* 发送验证码
*/
@GetMapping("/verificationCode")
public String verificationCode(@RequestParam("phone") String phone) throws ClientException {
public String verificationCode(@RequestParam("phone") String phone, @RequestParam(value = "agentOrgId", required = false) String agentOrgId) throws Exception {
// 获取区域信息
Locale locale = LocaleContextHolder.getLocale();
Long finalAgentOrgId = Long.parseLong(TextUtils.isEmpty(agentOrgId) ? "1" : agentOrgId);
List<AgentOrgEntity> agentOrgList = agentOrgDao.findAll();
String targetAgentOrgName = FirePointCodeUtils.getTargetAgentOrgName(finalAgentOrgId, agentOrgList);
String optCode = String.valueOf(RandomUtil.returnCode());
redisService.set(phone, optCode, 10, TimeUnit.MINUTES);
SendSmsResponse response = sendSms(phone, optCode);
smsHelper.dispatchSMSCode(targetAgentOrgName, phone, optCode);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "", locale);
}
/**
* 填写手机号发送验证码用于用户忘记密码
*
* @param phone
* @return
* @throws ClientException
*/
@GetMapping("/verificationCodeUpdate")
public String verificationCodeUpdate(@RequestParam("phone") String phone) throws ClientException {
public String verificationCodeUpdate(@RequestParam("phone") String phone) throws Exception {
// 获取区域信息
Locale locale = LocaleContextHolder.getLocale();
SysUserVo sysUserVo = sysUserDao.selectUserByUserName(phone);
if (sysUserVo == null) {
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "手机号错误,请使用您注册的手机号", locale);
}
List<AgentOrgEntity> agentOrgList = agentOrgDao.findAll();
String targetAgentOrgName = FirePointCodeUtils.getTargetAgentOrgName(sysUserVo.getAgentOrgId(), agentOrgList);
String optCode = String.valueOf(RandomUtil.returnCode());
redisService.set(phone, optCode, 10, TimeUnit.MINUTES);
SendSmsResponse response = sendSms(phone, optCode);
smsHelper.dispatchSMSCode(targetAgentOrgName, phone, optCode);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "", locale);
}
/**
* 输入验证码进行判断
*
* @param phone
* @param verificationCode
* @return
*/
@GetMapping("/getVerificationCode")
public String getVerificationCode(@RequestParam("phone") String phone, @RequestParam("verificationCode") String verificationCode) {
@ -409,8 +378,6 @@ public class SysUserController {
/**
* 更改账号过期时间
*
* @return
*/
@PostMapping("/updateExpireDate")
public String updateExpireDate(@RequestBody Map map, @RequestHeader(value = "Authorization") String token) {
@ -430,10 +397,6 @@ public class SysUserController {
/**
* 修改账号到期时间
*
* @param map
* @param token
* @return
*/
@PostMapping("/updateOverTime")
public String updateOverTime(@RequestBody Map map, @RequestHeader(value = "Authorization") String token) {

View File

@ -159,7 +159,7 @@ public class SysUserServiceImpl implements SysUserService {
sysUserEntity.setVipLevel(0);
sysUserEntity.setReceiveSms(0);
sysUserEntity.setRemark("");//备注
sysUserEntity.setAgentOrgId(sysUserQo.getAgentOrgId());
sysUserEntity.setAgentOrgId(sysUserQo.getAgentOrgId() == null ? 1L : sysUserQo.getAgentOrgId());
sysUserDao.save(sysUserEntity);
RelUserRoleEntity relUserRoleEntity = new RelUserRoleEntity();

View File

@ -1,7 +1,9 @@
package com.xkrs.sms;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.xkrs.model.entity.SysUserEntity;
import com.xkrs.utils.AliYunSmsUtils;
import com.xkrs.utils.HttpClientUtils;
import com.xkrs.utils.SMSUtils;
import org.slf4j.Logger;
@ -31,26 +33,27 @@ public class SMSHelper {
}
if ("青岛星科瑞升信息科技有限公司".equals(targetAgentOrgName)) {
xkrsSendSmsToUser(telephoneArray, templateParamArray);
xingkeSMSMessage(telephoneArray, templateParamArray);
} else if ("青岛华正信息技术股份有限公司".equals(targetAgentOrgName)) {
try {
huaZhengXinXi(telephoneArray, templateParamArray);
huazhengSMSMessage(telephoneArray, templateParamArray);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
}
/**
* 星科瑞升向用户发送短信
*/
private void xkrsSendSmsToUser(String[] telephoneArray, String[] templateParamArray) {
SMSUtils.sendSmsToUser(telephoneArray, "1425995", templateParamArray);
private void xingkeSMSMessage(String[] telephoneArray, String[] templateParamArray) {
int resValue = SMSUtils.sendSmsToUser(telephoneArray, "1425995", templateParamArray);
String sendResult = resValue == 0 ? "短信通知发送成功!" : "短信通知发送失败!";
//记录短信通知日志
StringBuilder stringBuilder = new StringBuilder("发送人:青岛星科瑞升信息科技有限公司\n");
for (String telephone : telephoneArray) {
@ -59,13 +62,14 @@ public class SMSHelper {
for (String templateParam : templateParamArray) {
stringBuilder.append("模板参数:").append(templateParam).append("\n");
}
stringBuilder.append(sendResult);
log.info(stringBuilder.toString());
}
/**
* 华正信息向用户发送短信
*/
private void huaZhengXinXi(String[] telephoneArray, String[] templateParamArray) throws Exception {
private void huazhengSMSMessage(String[] telephoneArray, String[] templateParamArray) throws Exception {
StringBuilder telephoneBuilder = new StringBuilder();
for (int i = 0; i < telephoneArray.length; i++) {
telephoneBuilder.append(telephoneArray[i]);
@ -94,4 +98,43 @@ public class SMSHelper {
log.info(stringBuilder.toString());
}
public void dispatchSMSCode(String targetAgentOrgName, String telephone, String code) throws Exception {
if ("青岛星科瑞升信息科技有限公司".equals(targetAgentOrgName)) {
xingkeSMSCode(telephone, code);
} else if ("青岛华正信息技术股份有限公司".equals(targetAgentOrgName)) {
huazhengSMSCode(telephone, code);
}
}
/**
* 星科瑞升向用户发送验证码
*/
private void xingkeSMSCode(String telephone, String code) throws Exception {
SendSmsResponse response = AliYunSmsUtils.sendCode(telephone, code);
}
/**
* 华正信息向用户发送验证码
*/
private void huazhengSMSCode(String telephone, String code) throws Exception {
String url = "http://58.56.128.186:10144/msg/msgReceive";
Map<String, Object> map = new HashMap<>();
map.put("receiver", telephone);
map.put("msgContent", "{\"content\":\"{'code':'" + code + "'}\"}");
map.put("idType", "30");
map.put("sendChannel", "30");
map.put("sendAccount", "11");
HttpClientUtils.sendHttpPost(url, new ObjectMapper().writeValueAsString(map));
//记录短信通知日志
String stringBuilder = "发送人:青岛华正信息技术股份有限公司\n" + "接收人:" + telephone + "\n" + "验证码:" + code + "\n";
log.info(stringBuilder);
}
}

View File

@ -4,36 +4,24 @@ import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Xin
*/
public class AliYunSmsUtils {
public static Logger log = LoggerFactory.getLogger(AliYunSmsUtils.class);
/**
* 产品名称:云通信短信API产品,开发者无需替换
*/
static final String product = "Dysmsapi";
/**
* 产品域名,开发者无需替换
*/
static final String domain = "dysmsapi.aliyuncs.com";
/**
* TODO 此处需要替换成开发者自己的AK(在阿里云访问控制台寻找)
* TODO 修改成自己的
*/
static final String accessKeyId = "LTAI5tMSjLfu8Xu2w6WeguFF";
/**
* TODO 修改成自己的
*/
static final String accessKeySecret = "hvqM5zpi72hvX4VXM71wq6AE0XYtDI";
public static SendSmsResponse sendSms(String telephone, String code) throws ClientException {
public static Logger log = LoggerFactory.getLogger(AliYunSmsUtils.class);
public static SendSmsResponse sendCode(String telephone, String code) throws Exception {
//产品名称:云通信短信API产品,开发者无需替换
String product = "Dysmsapi";
//产品域名,开发者无需替换
String domain = "dysmsapi.aliyuncs.com";
//此处需要替换成开发者自己的AK(在阿里云访问控制台寻找)
String accessKeyId = "LTAI5tMSjLfu8Xu2w6WeguFF";
//修改成自己的
String accessKeySecret = "hvqM5zpi72hvX4VXM71wq6AE0XYtDI";
//可自助调整超时时间
System.setProperty("sun.net.client.defaultConnectTimeout", "10000");
System.setProperty("sun.net.client.defaultReadTimeout", "10000");

View File

@ -100,7 +100,7 @@ public class FirePointCodeUtils {
return groupMap;
}
for (SysUserEntity smsReceiver : smsReceiverList) {
String targetAgentOrgName = getTargetAgentOrgName(smsReceiver, agentOrgList);
String targetAgentOrgName = getTargetAgentOrgName(smsReceiver.getAgentOrgId(), agentOrgList);
if (groupMap.containsKey(targetAgentOrgName)) {
List<SysUserEntity> groupSmsReceiverList = groupMap.get(targetAgentOrgName);
groupSmsReceiverList.add(smsReceiver);
@ -116,10 +116,10 @@ public class FirePointCodeUtils {
/**
* 获取系统用户的代理组织名称
*/
private static String getTargetAgentOrgName(SysUserEntity smsReceiver, List<AgentOrgEntity> agentOrgList) {
public static String getTargetAgentOrgName(Long agentOrgId, List<AgentOrgEntity> agentOrgList) {
for (AgentOrgEntity agentOrg : agentOrgList) {
try {
if (smsReceiver.getAgentOrgId().longValue() == agentOrg.getId().longValue()) {
if (agentOrgId.longValue() == agentOrg.getId().longValue()) {
return agentOrg.getOrgName();
}
} catch (Exception e) {