代码补正
This commit is contained in:
parent
18b08959a9
commit
e18cf3aea2
@ -9,7 +9,10 @@ import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
|
||||
import cn.iocoder.yudao.module.rescue.core.redis.RedisCache;
|
||||
import cn.iocoder.yudao.module.rescue.domain.DriverInfo;
|
||||
import cn.iocoder.yudao.module.rescue.domain.LoginBody;
|
||||
import cn.iocoder.yudao.module.rescue.domain.WxLoginBody;
|
||||
import cn.iocoder.yudao.module.rescue.service.IDriverInfoService;
|
||||
import cn.iocoder.yudao.module.rescue.utils.RescueSysLoginService;
|
||||
import cn.iocoder.yudao.module.rescue.utils.pay.WechatPayConfig;
|
||||
import cn.iocoder.yudao.module.system.api.dict.DictDataApi;
|
||||
import cn.iocoder.yudao.module.system.api.permission.PermissionApi;
|
||||
import cn.iocoder.yudao.module.system.api.permission.RoleApi;
|
||||
@ -21,16 +24,24 @@ import cn.iocoder.yudao.module.system.controller.admin.auth.vo.AuthLoginRespVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO;
|
||||
import cn.iocoder.yudao.module.system.service.auth.AdminAuthService;
|
||||
import cn.iocoder.yudao.module.system.service.permission.MenuService;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.security.spec.AlgorithmParameterSpec;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -70,12 +81,15 @@ public class SysLoginController {
|
||||
|
||||
@Resource
|
||||
private RedisCache redisCache2;
|
||||
//
|
||||
// @Autowired
|
||||
// private RestTemplate restTemplate;
|
||||
//
|
||||
// @Resource
|
||||
// private WechatPayConfig wxConfig;
|
||||
|
||||
@Resource
|
||||
private RescueSysLoginService rescueSysLoginService;
|
||||
|
||||
@Resource
|
||||
private WechatPayConfig wxConfig;
|
||||
|
||||
@Resource
|
||||
private RestTemplate restTemplate;
|
||||
// @Autowired
|
||||
// private IUserBalanceService balanceService;
|
||||
// @Autowired
|
||||
@ -98,13 +112,11 @@ public class SysLoginController {
|
||||
*/
|
||||
@PostMapping("/login")
|
||||
public CommonResult login(@RequestBody LoginBody loginBody) {
|
||||
return null;
|
||||
// ajax = success();
|
||||
// // 生成令牌
|
||||
// String token = loginService.login(loginBody.getUsername(), loginBody.getPassword(), loginBody.getCode(),
|
||||
// loginBody.getUuid());
|
||||
// ajax.put(Constants.TOKEN, token);
|
||||
// return ajax;
|
||||
// 生成令牌
|
||||
AuthLoginReqVO authLoginReqVO = new AuthLoginReqVO();
|
||||
authLoginReqVO.setUsername(loginBody.getUsername());
|
||||
authLoginReqVO.setPassword(loginBody.getPassword());
|
||||
return success(loginService.login(authLoginReqVO));
|
||||
}
|
||||
|
||||
@GetMapping("/dict/data/type/{type}")
|
||||
@ -157,15 +169,15 @@ public class SysLoginController {
|
||||
AuthLoginRespVO login = loginService.login(authLoginReqVO);
|
||||
return success(login);
|
||||
}
|
||||
// /**
|
||||
// * 登录获取验证码
|
||||
// *
|
||||
// * @return 结果
|
||||
// */
|
||||
// @PostMapping("/loginSmsCode")
|
||||
// public CommonResult loginSmsCode(String phone) {
|
||||
// return loginService.loginSmsCode(phone);
|
||||
// }
|
||||
/**
|
||||
* 登录获取验证码
|
||||
*
|
||||
* @return 结果
|
||||
*/
|
||||
@PostMapping("/loginSmsCode")
|
||||
public CommonResult loginSmsCode(String phone) {
|
||||
return rescueSysLoginService.loginSmsCode(phone);
|
||||
}
|
||||
/**
|
||||
* 登录方法
|
||||
*
|
||||
@ -185,15 +197,15 @@ public class SysLoginController {
|
||||
// public AjaxResult loginSmsCodeJx(String phone) {
|
||||
// return loginService.loginSmsCodeJx(phone);
|
||||
// }
|
||||
// /**
|
||||
// * 忘记密码获取验证码
|
||||
// *
|
||||
// * @return 结果
|
||||
// */
|
||||
// @PostMapping("/pwdSmsCode")
|
||||
// public CommonResult pwdSmsCode(String phone) {
|
||||
// return loginService.pwdSmsCode(phone);
|
||||
// }
|
||||
/**
|
||||
* 忘记密码获取验证码
|
||||
*
|
||||
* @return 结果
|
||||
*/
|
||||
@PostMapping("/pwdSmsCode")
|
||||
public CommonResult pwdSmsCode(String phone) {
|
||||
return rescueSysLoginService.pwdSmsCode(phone);
|
||||
}
|
||||
// /**
|
||||
// * 更新密码
|
||||
// *
|
||||
@ -204,7 +216,7 @@ public class SysLoginController {
|
||||
// if (!redisCache2.hasKey(phone+"-pwdCode")||!redisCache2.getCacheObject(phone+"-pwdCode").equals(msgCode)){
|
||||
// return error(500, "验证码错误");
|
||||
// }
|
||||
// AdminUserRespDTO sysUser = userService.getUserByUsername(phone);
|
||||
// AdminUserRespDTO sysUser = userService.getUserByMobile(phone);
|
||||
// if (userService.resetPassword(sysUser.getId(), SecurityFrameworkUtils.encryptPassword(password)); > 0)
|
||||
// {
|
||||
// // 更新缓存用户密码
|
||||
@ -232,8 +244,8 @@ public class SysLoginController {
|
||||
// 角色集合
|
||||
List<Long> roleIdsByUserId = permissionApi.getRoleIdsByUserId(loginUser.getId());
|
||||
List<RoleReqDTO> roleList = roleApi.getRoleList();
|
||||
List<String> roleNames = roleList.stream().filter(item -> roleIdsByUserId.contains(item.getId())).map(item -> item.getName()).collect(Collectors.toList());
|
||||
map.put("roles", roleNames);
|
||||
List<RoleReqDTO> role = roleList.stream().filter(item -> roleIdsByUserId.contains(item.getId())).collect(Collectors.toList());
|
||||
map.put("role", role);
|
||||
// 权限集合
|
||||
List<MenuDO> menuList = menuService.getMenuList();
|
||||
// Set<String> permissions = permissionService.getMenuPermission(user);
|
||||
@ -283,19 +295,19 @@ public class SysLoginController {
|
||||
// * @return 用户信息
|
||||
// */
|
||||
// @GetMapping("/getAppInfo")
|
||||
// public AjaxResult getAppInfo()
|
||||
// public CommonResult getAppInfo()
|
||||
// {
|
||||
// SysUser user = SecurityUtils.getLoginUser().getUser();
|
||||
// SysUser sysUser = userService.selectUserById(user.getUserId());
|
||||
// LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
|
||||
// AdminUserRespDTO user = userService.getUser(loginUser.getId());
|
||||
// // 角色集合
|
||||
// Set<String> roles = permissionService.getRolePermission(user);
|
||||
// UserBalance userBalance = balanceService.selectShopUserBalanceByUserId(user.getUserId());
|
||||
// Set<String> roles = permissionService.getRolePermission(NamedObject.user);
|
||||
// UserBalance userBalance = balanceService.selectShopUserBalanceByUserId(NamedObject.user.getUserId());
|
||||
// if (ObjectUtil.isNotEmpty(userBalance)) {
|
||||
// sysUser.setBalance(userBalance.getBalance());
|
||||
// } else {
|
||||
// //新增用户积分表信息
|
||||
// userBalance=new UserBalance();
|
||||
// userBalance.setUserId(user.getUserId());
|
||||
// userBalance.setUserId(NamedObject.user.getUserId());
|
||||
// userBalance.setAllBalance(0L);
|
||||
// userBalance.setBalance(0L);
|
||||
// userBalance.setFrozenBalance(0L);
|
||||
@ -313,7 +325,7 @@ public class SysLoginController {
|
||||
// }
|
||||
// return ajax;
|
||||
// }
|
||||
//
|
||||
|
||||
/**
|
||||
* 获取App用户信息
|
||||
*
|
||||
@ -327,12 +339,12 @@ public class SysLoginController {
|
||||
// 角色集合
|
||||
List<RoleReqDTO> roleList = roleApi.getRoleList();
|
||||
List<Long> roleIdsByUserId = permissionApi.getRoleIdsByUserId(user.getId());
|
||||
List<RoleReqDTO> roles = roleList.stream().filter(item -> roleIdsByUserId.contains(item.getId())).collect(Collectors.toList());
|
||||
List<RoleReqDTO> role = roleList.stream().filter(item -> roleIdsByUserId.contains(item.getId())).collect(Collectors.toList());
|
||||
map.put("user", user);
|
||||
map.put("role", roles);
|
||||
if (CollectionUtil.isNotEmpty(roles)){
|
||||
map.put("role", role);
|
||||
if (CollectionUtil.isNotEmpty(role)){
|
||||
AtomicBoolean flag = new AtomicBoolean(false);
|
||||
roles.forEach(it->{
|
||||
role.forEach(it->{
|
||||
if (it.getCode().equals("jcgf")){
|
||||
flag.set(true);
|
||||
}
|
||||
@ -355,12 +367,12 @@ public class SysLoginController {
|
||||
// 角色集合
|
||||
List<RoleReqDTO> roleList = roleApi.getRoleList();
|
||||
List<Long> roleIdsByUserId = permissionApi.getRoleIdsByUserId(user.getId());
|
||||
List<RoleReqDTO> roles = roleList.stream().filter(item -> roleIdsByUserId.contains(item.getId())).collect(Collectors.toList());
|
||||
List<RoleReqDTO> role = roleList.stream().filter(item -> roleIdsByUserId.contains(item.getId())).collect(Collectors.toList());
|
||||
map.put("user", user);
|
||||
map.put("role", roles);
|
||||
if (CollectionUtil.isNotEmpty(roles)){
|
||||
map.put("role", role);
|
||||
if (CollectionUtil.isNotEmpty(role)){
|
||||
AtomicBoolean flag = new AtomicBoolean(false);
|
||||
roles.forEach(it->{
|
||||
role.forEach(it->{
|
||||
if (it.getCode().equals("jjdd")){
|
||||
flag.set(true);
|
||||
}
|
||||
@ -454,14 +466,14 @@ public class SysLoginController {
|
||||
// * @return 路由信息
|
||||
// */
|
||||
// @GetMapping("getRouters")
|
||||
// public AjaxResult getRouters()
|
||||
// public CommonResult getRouters()
|
||||
// {
|
||||
// Long userId = SecurityUtils.getUserId();
|
||||
// Long userId = SecurityFrameworkUtils.getLoginUserId();
|
||||
// List<SysMenu> menus = menuService.selectMenuTreeByUserId(userId);
|
||||
// return AjaxResult.success(menuService.buildMenus(menus));
|
||||
// }
|
||||
|
||||
// @ApiOperation("微信登录")
|
||||
//
|
||||
// @ApiImplicitParams({
|
||||
// @ApiImplicitParam(name = "WxLoginBody",dataType = "WxLoginBody", value = "jscode", required = true, paramType = "body")
|
||||
// })
|
||||
@ -548,90 +560,91 @@ public class SysLoginController {
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @PostMapping("/wxLoginRescue")
|
||||
// public AjaxResult wxLoginRescue(@RequestBody WxLoginBody wxLoginBody) {
|
||||
// String code = wxLoginBody.getCode();
|
||||
// //秘钥
|
||||
// String encryptedIv = wxLoginBody.getEncryptedIv();
|
||||
// //加密数据
|
||||
// String encryptedData = wxLoginBody.getEncryptedData();
|
||||
//
|
||||
//
|
||||
// //想微信服务器发送请求获取用户信息
|
||||
// String url = "https://api.weixin.qq.com/sns/jscode2session?appid=" + wxConfig.getAppId() + "&secret=" + wxConfig.getAppSecret() + "&js_code=" + code + "&grant_type=authorization_code";
|
||||
// System.out.println(url);
|
||||
// String res = restTemplate.getForObject(url, String.class);
|
||||
// JSONObject jsonObject = JSONObject.parseObject(res);
|
||||
//
|
||||
// //获取session_key和openid
|
||||
// String sessionKey = jsonObject.getString("session_key");
|
||||
// String openId = jsonObject.getString("openid");
|
||||
//
|
||||
// System.out.println(sessionKey);
|
||||
// System.out.println(openId);
|
||||
// //解密
|
||||
// String decryptResult = "";
|
||||
// try {
|
||||
// //如果没有绑定微信开放平台,解析结果是没有unionid的。
|
||||
// decryptResult = decrypt(sessionKey, encryptedIv, encryptedData);
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// return AjaxResult.error("微信登录失败!");
|
||||
// }
|
||||
//
|
||||
// if (StringUtils.hasText(decryptResult)) {
|
||||
@PostMapping("/wxLoginRescue")
|
||||
public CommonResult wxLoginRescue(@RequestBody WxLoginBody wxLoginBody) {
|
||||
String code = wxLoginBody.getCode();
|
||||
//秘钥
|
||||
String encryptedIv = wxLoginBody.getEncryptedIv();
|
||||
//加密数据
|
||||
String encryptedData = wxLoginBody.getEncryptedData();
|
||||
|
||||
|
||||
//想微信服务器发送请求获取用户信息
|
||||
String url = "https://api.weixin.qq.com/sns/jscode2session?appid=" + wxConfig.getAppId() + "&secret=" + wxConfig.getAppSecret() + "&js_code=" + code + "&grant_type=authorization_code";
|
||||
System.out.println(url);
|
||||
String res = restTemplate.getForObject(url, String.class);
|
||||
JSONObject jsonObject = JSONObject.parseObject(res);
|
||||
|
||||
//获取session_key和openid
|
||||
String sessionKey = jsonObject.getString("session_key");
|
||||
String openId = jsonObject.getString("openid");
|
||||
|
||||
System.out.println(sessionKey);
|
||||
System.out.println(openId);
|
||||
//解密
|
||||
String decryptResult = "";
|
||||
try {
|
||||
//如果没有绑定微信开放平台,解析结果是没有unionid的。
|
||||
decryptResult = decrypt(sessionKey, encryptedIv, encryptedData);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return error(500, "微信登录失败!");
|
||||
}
|
||||
|
||||
if (StringUtils.hasText(decryptResult)) {
|
||||
// TODO 待完成
|
||||
// //如果解析成功,获取token
|
||||
// String token = loginService.wxLoginRescue(decryptResult,openId,wxLoginBody.getInviteId());
|
||||
// AjaxResult ajax = AjaxResult.success();
|
||||
// ajax.put(Constants.TOKEN, token);
|
||||
// return ajax;
|
||||
// } else {
|
||||
// return AjaxResult.error("微信登录失败!");
|
||||
// }
|
||||
// }
|
||||
return error(500, "待完成");
|
||||
} else {
|
||||
return error(500, "微信登录失败!");
|
||||
}
|
||||
}
|
||||
//
|
||||
// /**
|
||||
// * AES解密
|
||||
// */
|
||||
// private String decrypt(String sessionKey,String encryptedIv,String encryptedData) throws Exception{
|
||||
// // 转化为字节数组
|
||||
// byte[] key = Base64.decode(sessionKey);
|
||||
// byte[] iv = Base64.decode(encryptedIv);
|
||||
// byte[] encData = Base64.decode(encryptedData);
|
||||
// // 如果密钥不足16位,那么就补足
|
||||
// int base =16;
|
||||
// if (key.length % base !=0) {
|
||||
// int groups = key.length / base +(key.length % base != 0 ? 1 : 0);
|
||||
// byte[] temp = new byte[groups * base];
|
||||
// Arrays.fill(temp,(byte) 0);
|
||||
// System.arraycopy(key,0,temp,0,key.length);
|
||||
// key = temp;
|
||||
// }
|
||||
// // 如果初始向量不足16位,也补足
|
||||
// if (iv.length % base !=0) {
|
||||
// int groups = iv.length / base +(iv.length % base != 0 ? 1 : 0);
|
||||
// byte[] temp = new byte[groups * base];
|
||||
// Arrays.fill(temp,(byte) 0);
|
||||
// System.arraycopy(iv,0,temp,0,iv.length);
|
||||
// iv = temp;
|
||||
// }
|
||||
//
|
||||
// AlgorithmParameterSpec ivSpec = new IvParameterSpec(iv);
|
||||
// String resultStr = null;
|
||||
//
|
||||
// try {
|
||||
// Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
|
||||
// SecretKeySpec keySpec = new SecretKeySpec(key,"AES");
|
||||
// cipher.init(Cipher.DECRYPT_MODE,keySpec,ivSpec);
|
||||
// resultStr = new String(cipher.doFinal(encData),"UTF-8");
|
||||
// } catch (Exception e){
|
||||
//// logger.info("解析错误");
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
//
|
||||
// // 解析加密后的字符串
|
||||
// return resultStr;
|
||||
// }
|
||||
/**
|
||||
* AES解密
|
||||
*/
|
||||
private String decrypt(String sessionKey,String encryptedIv,String encryptedData) throws Exception{
|
||||
// 转化为字节数组
|
||||
byte[] key = Base64.decode(sessionKey);
|
||||
byte[] iv = Base64.decode(encryptedIv);
|
||||
byte[] encData = Base64.decode(encryptedData);
|
||||
// 如果密钥不足16位,那么就补足
|
||||
int base =16;
|
||||
if (key.length % base !=0) {
|
||||
int groups = key.length / base +(key.length % base != 0 ? 1 : 0);
|
||||
byte[] temp = new byte[groups * base];
|
||||
Arrays.fill(temp,(byte) 0);
|
||||
System.arraycopy(key,0,temp,0,key.length);
|
||||
key = temp;
|
||||
}
|
||||
// 如果初始向量不足16位,也补足
|
||||
if (iv.length % base !=0) {
|
||||
int groups = iv.length / base +(iv.length % base != 0 ? 1 : 0);
|
||||
byte[] temp = new byte[groups * base];
|
||||
Arrays.fill(temp,(byte) 0);
|
||||
System.arraycopy(iv,0,temp,0,iv.length);
|
||||
iv = temp;
|
||||
}
|
||||
|
||||
AlgorithmParameterSpec ivSpec = new IvParameterSpec(iv);
|
||||
String resultStr = null;
|
||||
|
||||
try {
|
||||
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
|
||||
SecretKeySpec keySpec = new SecretKeySpec(key,"AES");
|
||||
cipher.init(Cipher.DECRYPT_MODE,keySpec,ivSpec);
|
||||
resultStr = new String(cipher.doFinal(encData),"UTF-8");
|
||||
} catch (Exception e){
|
||||
// logger.info("解析错误");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// 解析加密后的字符串
|
||||
return resultStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步数据
|
||||
|
@ -10,6 +10,7 @@ import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 【请填写功能名称】对象 rescue_info
|
||||
@ -185,6 +186,6 @@ public class RescueInfo extends TenantBaseDO
|
||||
private String rescueStartMonth;
|
||||
|
||||
@TableField(exist = false)
|
||||
private Long[] roadIds;
|
||||
private List<String> roadIds;
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,24 @@
|
||||
package cn.iocoder.yudao.module.rescue.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class WxLoginBody {
|
||||
/**
|
||||
* 临时登陆凭证 code 只能使用一次
|
||||
*/
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 偏移量
|
||||
*/
|
||||
private String encryptedIv;
|
||||
|
||||
/**
|
||||
* 加密数据
|
||||
*/
|
||||
private String encryptedData;
|
||||
|
||||
// //邀请码
|
||||
// private Long inviteId;
|
||||
}
|
@ -47,6 +47,8 @@ import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception0;
|
||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUser;
|
||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserDeptId;
|
||||
import static cn.iocoder.yudao.module.rescue.service.impl.RescueDriverInfoServiceImpl.Redis_Driver_Key;
|
||||
@ -394,21 +396,22 @@ public class RescueInfoServiceImpl extends ServiceImpl<RescueInfoMapper, RescueI
|
||||
|
||||
// 自动通知对应路段司机
|
||||
List<RescueDictStaff> list = rescueDictStaffService.list(new LambdaQueryWrapper<RescueDictStaff>().in(RescueDictStaff::getDictId, rescueInfo.getRoadIds()));
|
||||
if (CollectionUtil.isNotEmpty(list)){
|
||||
Set<Long> driverIds = list.stream()
|
||||
.map(RescueDictStaff::getDriverIds)
|
||||
.flatMap(item -> Arrays.stream(item.split(",")))
|
||||
.map(Long::parseLong)
|
||||
.collect(Collectors.toSet());
|
||||
driverIds.forEach(item -> {
|
||||
SysAnnouncement sysAnnouncement = new SysAnnouncement();
|
||||
sysAnnouncement.setType("救援信息");
|
||||
sysAnnouncement.setToUserIds(Collections.singletonList(item));
|
||||
sysAnnouncement.setTitle("有新的救援订单请立即处理");
|
||||
sysAnnouncement.setContent("有新的救援订单请立即处理");
|
||||
announcementService.insertSysAnnouncements(sysAnnouncement);
|
||||
});
|
||||
if (CollectionUtil.isEmpty(list)) {
|
||||
throw exception0(500, "该路段没有司机,请先配置");
|
||||
}
|
||||
Set<Long> driverIds = list.stream()
|
||||
.map(RescueDictStaff::getDriverIds)
|
||||
.flatMap(item -> Arrays.stream(item.split(",")))
|
||||
.map(Long::parseLong)
|
||||
.collect(Collectors.toSet());
|
||||
driverIds.forEach(item -> {
|
||||
SysAnnouncement sysAnnouncement = new SysAnnouncement();
|
||||
sysAnnouncement.setType("救援信息");
|
||||
sysAnnouncement.setToUserIds(Collections.singletonList(item));
|
||||
sysAnnouncement.setTitle("有新的救援订单请立即处理");
|
||||
sysAnnouncement.setContent("有新的救援订单请立即处理");
|
||||
announcementService.insertSysAnnouncements(sysAnnouncement);
|
||||
});
|
||||
// 新增延迟消息,用于三分钟后没人接单通知
|
||||
TaskDto taskDto = new TaskDto();
|
||||
taskDto.setManageId(loginUser.getId());
|
||||
@ -430,7 +433,7 @@ public class RescueInfoServiceImpl extends ServiceImpl<RescueInfoMapper, RescueI
|
||||
rescueInfo.setRescueStatus(null);
|
||||
}
|
||||
// 取消订单时删除定时任务
|
||||
if (rescueInfo.getRescueStatus().equals("0")){
|
||||
if (rescueInfo.getRescueStatus().equals("0")) {
|
||||
redissonDelayQueue.removeAllTasks(rescueInfo.getId());
|
||||
}
|
||||
return baseMapper.updateById(rescueInfo);
|
||||
|
@ -83,6 +83,9 @@ public class RedissonDelayQueue {
|
||||
|
||||
// TODO 还要通知总调度
|
||||
|
||||
/** 两个值虽然一样,但避免无法删除一直存在问题,干脆重新来过 */
|
||||
// 移除原来的
|
||||
removeAllTasks(taskDto.getRescueInfoId());
|
||||
// 在新创建定时任务
|
||||
offerTask(task, UserConstants.RESCUE_TIME);
|
||||
} catch (Exception e) {
|
||||
|
@ -0,0 +1,146 @@
|
||||
package cn.iocoder.yudao.module.rescue.utils;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.module.rescue.core.redis.RedisCache;
|
||||
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
||||
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
|
||||
import cn.iocoder.yudao.module.system.api.user.dto.UserDTO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.thoughtworks.xstream.core.SecurityUtils;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.error;
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
|
||||
@Component
|
||||
public class RescueSysLoginService {
|
||||
|
||||
@Resource
|
||||
private AdminUserApi adminUserApi;
|
||||
|
||||
@Resource
|
||||
@Lazy
|
||||
private RedisCache redisCache2;
|
||||
|
||||
public CommonResult loginSmsCode(String phone){
|
||||
String msg;
|
||||
AdminUserDO userDO = new AdminUserDO();
|
||||
userDO.setMobile(phone);
|
||||
if (ObjectUtil.isEmpty(adminUserApi.getUserByMobile(phone))){
|
||||
msg = "手机号'" + phone + "不存在请先注册";
|
||||
return error(500, msg);
|
||||
}
|
||||
String msgCode = generateVerificationCode();
|
||||
redisCache2.setCacheObject(phone+"-loginCode",msgCode,300, TimeUnit.SECONDS);
|
||||
SendSmsUtil.sendMsg(msgCode,phone,"1400852709","机动车管家小程序","1917285");
|
||||
return success("验证码成功生成");
|
||||
|
||||
}
|
||||
|
||||
public static String generateVerificationCode() {
|
||||
// 设置验证码长度
|
||||
int codeLength = 6;
|
||||
// 设置验证码字符源
|
||||
String codeSource = "0123456789";
|
||||
// 生成随机数对象
|
||||
Random random = new Random();
|
||||
StringBuilder verificationCode = new StringBuilder();
|
||||
|
||||
// 随机生成验证码
|
||||
for (int i = 0; i < codeLength; i++) {
|
||||
int index = random.nextInt(codeSource.length());
|
||||
char codeChar = codeSource.charAt(index);
|
||||
verificationCode.append(codeChar);
|
||||
}
|
||||
|
||||
return verificationCode.toString();
|
||||
}
|
||||
|
||||
public CommonResult pwdSmsCode(String phone) {
|
||||
String msg;
|
||||
AdminUserDO userDO = new AdminUserDO();
|
||||
userDO.setMobile(phone);
|
||||
if (ObjectUtil.isNotEmpty(adminUserApi.getUserByMobile(phone))){
|
||||
msg = "手机号" + phone + "不存在";
|
||||
return error(500, msg);
|
||||
}
|
||||
String msgCode = generateVerificationCode();
|
||||
redisCache2.setCacheObject(phone+"-pwdCode",msgCode,300, TimeUnit.SECONDS);
|
||||
SendSmsUtil.sendMsg(msgCode,phone,"1400852709","机动车管家小程序","1917285");
|
||||
return success("验证码成功生成");
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 检测模块微信登录
|
||||
// *
|
||||
// * @param decryptResult 登录凭证 只能用一次
|
||||
// * @return
|
||||
// */
|
||||
// public String wxLoginRescue(String decryptResult,String openId,Long inviteId){
|
||||
// //字符串转json
|
||||
// JSONObject jsonObject = JSONObject.parseObject(decryptResult);
|
||||
// System.out.println(jsonObject);
|
||||
// System.out.println("openId"+openId);
|
||||
// String phoneNumber = jsonObject.getString("phoneNumber");
|
||||
// //还可以获取其他信息
|
||||
// //根据openid判断数据库中是否有该用户
|
||||
// //根据openid查询用户信息
|
||||
// AdminUserRespDTO wxUser = adminUserApi.getUserByMobile(phoneNumber);
|
||||
// //如果查不到,则新增,查到了,则更新
|
||||
// UserDTO user = new UserDTO();
|
||||
// if (wxUser == null) {
|
||||
// // 新增
|
||||
// user.setUsername(phoneNumber);
|
||||
// user.setNickname(phoneNumber);
|
||||
// user.setMobile(phoneNumber);
|
||||
// user.setPassword(SecurityUtils.encryptPassword("654321"));
|
||||
// user.setRescueOpenId(openId);
|
||||
// user.setCreateTime(DateUtils.getNowDate());
|
||||
// if (null!=inviteId){
|
||||
//
|
||||
// //绑定上级
|
||||
// user.setInviteId(inviteId);
|
||||
// //给上级进行积分奖励
|
||||
// userBalanceService.inviteRewards(inviteId);
|
||||
// }
|
||||
// //新增 用户
|
||||
// SysRole role = roleService.selectRoleByCode("jcyh");
|
||||
// user.setRoleIds(new Long[]{role.getRoleId()});
|
||||
// user.setDeptId(100L);
|
||||
// userService.insertUser(user);
|
||||
// }else {
|
||||
// //更新
|
||||
// user = wxUser;
|
||||
// user.setNickName(phoneNumber);
|
||||
// user.setPhonenumber(phoneNumber);
|
||||
// user.setRescueOpenId(openId);
|
||||
// user.setUpdateTime(DateUtils.getNowDate());
|
||||
// if (ObjectUtil.isEmpty(user.getInviteId())){
|
||||
// if (null!=inviteId){
|
||||
// //绑定上级
|
||||
// user.setInviteId(inviteId);
|
||||
// //给上级进行积分奖励
|
||||
// userBalanceService.inviteRewards(inviteId);
|
||||
// }
|
||||
// }
|
||||
// userMapper.updateUser(user);
|
||||
// }
|
||||
//
|
||||
// //组装token信息
|
||||
// LoginUser loginUser = new LoginUser();
|
||||
// loginUser.setOpenId(openId);
|
||||
// //如果有的话设置
|
||||
// loginUser.setUser(user);
|
||||
// loginUser.setUserId(user.getUserId());
|
||||
//
|
||||
// // 生成token
|
||||
// return tokenService.createToken(loginUser);
|
||||
// }
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
package cn.iocoder.yudao.module.rescue.utils;
|
||||
|
||||
import com.tencentcloudapi.common.Credential;
|
||||
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
|
||||
import com.tencentcloudapi.common.profile.ClientProfile;
|
||||
import com.tencentcloudapi.common.profile.HttpProfile;
|
||||
import com.tencentcloudapi.sms.v20210111.SmsClient;
|
||||
import com.tencentcloudapi.sms.v20210111.models.SendSmsRequest;
|
||||
import com.tencentcloudapi.sms.v20210111.models.SendSmsResponse;
|
||||
|
||||
public class SendSmsUtil {
|
||||
public static void sendMsg(String code,String phoneNum,String sdkAppId,String signName,String templateId){
|
||||
|
||||
try{
|
||||
Credential cred = new Credential("AKIDQlz4xdAaypV0MYkv1AMRRKSdw350qW2x", "oRv221ymOsBMOMBwAHF4f2GJC6tX6Wnv");
|
||||
// 实例化一个http选项,可选的,没有特殊需求可以跳过
|
||||
HttpProfile httpProfile = new HttpProfile();
|
||||
httpProfile.setEndpoint("sms.tencentcloudapi.com");
|
||||
// 实例化一个client选项,可选的,没有特殊需求可以跳过
|
||||
ClientProfile clientProfile = new ClientProfile();
|
||||
clientProfile.setHttpProfile(httpProfile);
|
||||
// 实例化要请求产品的client对象,clientProfile是可选的
|
||||
SmsClient client = new SmsClient(cred, "ap-guangzhou", clientProfile);
|
||||
// 实例化一个请求对象,每个接口都会对应一个request对象
|
||||
SendSmsRequest req = new SendSmsRequest();
|
||||
String[] phoneNumberSet1 = {phoneNum};
|
||||
req.setPhoneNumberSet(phoneNumberSet1);
|
||||
|
||||
req.setSmsSdkAppId(sdkAppId);
|
||||
req.setSignName(signName);
|
||||
req.setTemplateId(templateId);
|
||||
String[] templateParamSet1 = {code};
|
||||
req.setTemplateParamSet(templateParamSet1);
|
||||
// 返回的resp是一个SendSmsResponse的实例,与请求对象对应
|
||||
SendSmsResponse resp = client.SendSms(req);
|
||||
// 输出json格式的字符串回包
|
||||
System.out.println(SendSmsResponse.toJsonString(resp));
|
||||
} catch (TencentCloudSDKException e) {
|
||||
System.out.println(e.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static void sendMsgCommon(String[] templateParamSet,String phoneNum,String sdkAppId,String signName,String templateId){
|
||||
|
||||
try{
|
||||
Credential cred = new Credential("AKIDQlz4xdAaypV0MYkv1AMRRKSdw350qW2x", "oRv221ymOsBMOMBwAHF4f2GJC6tX6Wnv");
|
||||
// 实例化一个http选项,可选的,没有特殊需求可以跳过
|
||||
HttpProfile httpProfile = new HttpProfile();
|
||||
httpProfile.setEndpoint("sms.tencentcloudapi.com");
|
||||
// 实例化一个client选项,可选的,没有特殊需求可以跳过
|
||||
ClientProfile clientProfile = new ClientProfile();
|
||||
clientProfile.setHttpProfile(httpProfile);
|
||||
// 实例化要请求产品的client对象,clientProfile是可选的
|
||||
SmsClient client = new SmsClient(cred, "ap-guangzhou", clientProfile);
|
||||
// 实例化一个请求对象,每个接口都会对应一个request对象
|
||||
SendSmsRequest req = new SendSmsRequest();
|
||||
String[] phoneNumberSet1 = {phoneNum};
|
||||
req.setPhoneNumberSet(phoneNumberSet1);
|
||||
|
||||
req.setSmsSdkAppId(sdkAppId);
|
||||
req.setSignName(signName);
|
||||
req.setTemplateId(templateId);
|
||||
req.setTemplateParamSet(templateParamSet);
|
||||
// 返回的resp是一个SendSmsResponse的实例,与请求对象对应
|
||||
SendSmsResponse resp = client.SendSms(req);
|
||||
// 输出json格式的字符串回包
|
||||
System.out.println(SendSmsResponse.toJsonString(resp));
|
||||
} catch (TencentCloudSDKException e) {
|
||||
System.out.println(e.toString());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user