Merge remote-tracking branch 'origin/master'

This commit is contained in:
赵旭 2024-08-28 00:55:10 +08:00
commit c4ea699ae3
10 changed files with 549 additions and 240 deletions

View File

@ -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;
}
/**
* 同步数据

View File

@ -43,9 +43,9 @@ public class RescueCarSpendController extends BaseController {
/**
* 导出车辆消费管理列表
*/
@PreAuthorize("@ss.hasPermission('rescue:rescueCarSpend:export')")
// @PreAuthorize("@ss.hasPermission('rescue:rescueCarSpend:export')")
// @Log(title = "车辆消费管理", businessType = BusinessType.EXPORT)
@PostMapping("/export")
@GetMapping("/export")
public void export(HttpServletResponse response, RescueCarSpend rescueCarSpend) {
List<RescueCarSpend> list = rescueCarSpendService.list();
ExcelUtil<RescueCarSpend> util = new ExcelUtil<RescueCarSpend>(RescueCarSpend.class);

View File

@ -178,12 +178,8 @@ public class RescueInfoSystem extends BaseController {
break;
}
}
// 导出 Excel
Map<Integer, Integer> columnWidthMap = new HashMap<>();
// 第一列的索引是0宽度设置为20个字符宽
columnWidthMap.put(9, 20);
columnWidthMap.put(10, 20);
ExcelUtils.write(response, "救援订单.xls", "数据", RescueInfo.class, list, columnWidthMap);
ExcelUtil<RescueInfo> util = new ExcelUtil<RescueInfo>(RescueInfo.class);
util.exportExcel(response, list, "救援订单数据");
}
//指派司机
@ -365,13 +361,26 @@ public class RescueInfoSystem extends BaseController {
return CommonResult.success(res);
}
/** TODO 有问题,处理时间太长,还会报错 */
@GetMapping("/exportManagement")
public void exportManagement(HttpServletResponse response, RescueInfo rescueInfo) {
List<MoneyManagement> list = rescueInfoService.moneyManagement(rescueInfo);
public void exportManagement(HttpServletResponse response, RescueInfo rescueInfo,
@RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
List<MoneyManagement> result = new ArrayList<>();
while (true){
Page<RescueInfo> page = new Page<>(pageNo, pageSize);
IPage<RescueInfo> rescueInfos = rescueInfoService.getRescueInfoByDriver(rescueInfo, page);
if (ObjectUtil.isEmpty(rescueInfos) || rescueInfos.getRecords().isEmpty()){
break;
}
List<MoneyManagement> list = rescueInfoService.moneyManagement2(rescueInfos.getRecords(), rescueInfo.getRescueStart());
result.addAll(list);
pageNo ++;
}
JSONObject jsonObject = rescueInfoService.listData(rescueInfo);
ExcelUtil<MoneyManagement> util = new ExcelUtil<MoneyManagement>(MoneyManagement.class);
String title = "施救总金额:" + jsonObject.getString("allMoney") + "元 出车次数:" + jsonObject.getString("allNum") + "次 提成总金额:" + jsonObject.getString("tcAll") + " 元 燃油费小计:" + jsonObject.getString("refuelMoney") + "";
util.exportExcel(response, list, "救援财务报表", title);
util.exportExcel(response, result, "救援财务报表", title);
}
/**

View File

@ -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;
}

View File

@ -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;
}

View File

@ -32,6 +32,7 @@ import cn.iocoder.yudao.module.system.api.user.dto.UserDTO;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
@ -47,6 +48,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;
@ -374,6 +377,7 @@ public class RescueInfoServiceImpl extends ServiceImpl<RescueInfoMapper, RescueI
* @return 结果
*/
@Override
@DSTransactional
public void insertRescueInfo(RescueInfo rescueInfo) {
// 获取当前的用户
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
@ -394,21 +398,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 +435,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);
@ -941,81 +946,89 @@ public class RescueInfoServiceImpl extends ServiceImpl<RescueInfoMapper, RescueI
return resList;
}
/** 有问题 */
@Deprecated
public List<MoneyManagement> moneyManagement(RescueInfo rescueInfo) {
// List<RescueInfo> rescueInfos = baseMapper.getRescueInfoByDriver(rescueInfo);
// List<MoneyManagement> resList = new ArrayList<>();
// Double rescueTcBig = 0d;
// Double rescueTcMid = 0d;
// Double rescueTcSmall = 0d;
// RescueConfig rescueConfig = rescueConfigService.selectRescueConfigByDeptId();
// if (ObjectUtils.isNotEmpty(rescueConfig)) {
// rescueTcBig = Optional.ofNullable(rescueConfig.getRescueTcBig()).orElse(0d);
// rescueTcMid = Optional.ofNullable(rescueConfig.getRescueTcMid()).orElse(0d);
// rescueTcSmall = Optional.ofNullable(rescueConfig.getRescueTcSmall()).orElse(0d);
// }
// for (RescueInfo info : rescueInfos) {
// MoneyManagement moneyManagement = new MoneyManagement();
// moneyManagement.setDriverName(info.getDriverName());
// Double grossWages = 0d;
// Double tempSetMoney = ObjectUtils.isNotEmpty(info.getSetMoney()) ? Double.valueOf(info.getSetMoney()) / 100d : 0d;
// Double tempCheckpointMoney = ObjectUtils.isNotEmpty(info.getCheckpointMoney()) ? info.getCheckpointMoney() : 0d;
// JSONObject monthRescueRefuelRecord = new JSONObject();
// monthRescueRefuelRecord.put("refuelMoney", 0);
// monthRescueRefuelRecord.put("refuelNum", 0);
// monthRescueRefuelRecord.put("refuelDistance", 0);
// try {
// LambdaQueryWrapper<RescueCarInfo> queryWrapper = new LambdaQueryWrapper<>();
// queryWrapper.eq(RescueCarInfo::getRescueCarNum, info.getDriverCarNum()).last("limit 1");
// RescueCarInfo carInfo = carInfoService.getOne(queryWrapper);
// monthRescueRefuelRecord = refuelRecordService.getMonthRescueRefuelRecord(info.getDriverId(), DateUtil.format(info.getRescueTime(), "yyyy-MM"), carInfo.getId());
// } catch (Exception ignored) {
// }
// moneyManagement.setLicenseNum(info.getLicenseNum());
// moneyManagement.setFeeType(info.getFeeType());
// moneyManagement.setRescueTime(info.getRescueTime());
// moneyManagement.setDiverCarNum(info.getDriverCarNum());
// moneyManagement.setSetMoney(tempSetMoney);
// moneyManagement.setCheckpointMoney(info.getCheckpointMoney());
// moneyManagement.setUpMoney(tempSetMoney - tempCheckpointMoney);
// moneyManagement.setEmptyingDistance(info.getEmptyNum());
// String carType = "3";
// if (StringUtils.isNotEmpty(info.getDriverCarNum())) {
// RescueCarInfo carInfo = carInfoService.selectRescueCarInfoByNum(info.getDriverCarNum());
// carType = carInfo.getRescueCarType();
// }
// if (carType.equals("1")) {
// //大车
// moneyManagement.setRoyaltyRatio(rescueTcBig);
// moneyManagement.setRoyaltyMoney(tempSetMoney * rescueTcBig);
// } else if (carType.equals("2")) {
// //中车
// moneyManagement.setRoyaltyRatio(rescueTcMid);
// moneyManagement.setRoyaltyMoney(tempSetMoney * rescueTcMid);
// } else {
// //小车
// moneyManagement.setRoyaltyRatio(rescueTcSmall);
// moneyManagement.setRoyaltyMoney(tempSetMoney * rescueTcSmall);
// }
// //获取当前车 当前驾驶员 这个月跑了几次
// JSONObject driverInfoObj = baseMapper.getDriverCarNum(info.getDriverId(), info.getDriverCarNum(), rescueInfo.getRescueStart());
// //计算平均燃油费和平均油耗
// Double avgFuelConsumption = 0d;
// Double mglYh = 0d;
// if (driverInfoObj.getInteger("allNum") != 0) {
// avgFuelConsumption = monthRescueRefuelRecord.getDouble("refuelMoney") / driverInfoObj.getInteger("allNum");
// mglYh = monthRescueRefuelRecord.getDouble("refuelNum") / driverInfoObj.getDouble("allDistance");
// }
// moneyManagement.setFuelCost(avgFuelConsumption);
// moneyManagement.setOilConsumption(mglYh);
// Double oilSubsidy = Optional.ofNullable(info.getEmptyNum()).orElse(0d) * mglYh;
// moneyManagement.setOilSubsidy(oilSubsidy);
// grossWages = grossWages + moneyManagement.getRoyaltyMoney() + oilSubsidy - avgFuelConsumption;
// moneyManagement.setGrossWages(grossWages);
// resList.add(moneyManagement);
// }
//
// return resList;
return null;
List<MoneyManagement> resList = new ArrayList<>();
Double rescueTcBig = 0d;
Double rescueTcMid = 0d;
Double rescueTcSmall = 0d;
RescueConfig rescueConfig = rescueConfigService.selectRescueConfigByDeptId();
if (ObjectUtils.isNotEmpty(rescueConfig)) {
rescueTcBig = Optional.ofNullable(rescueConfig.getRescueTcBig()).orElse(0d);
rescueTcMid = Optional.ofNullable(rescueConfig.getRescueTcMid()).orElse(0d);
rescueTcSmall = Optional.ofNullable(rescueConfig.getRescueTcSmall()).orElse(0d);
}
Integer pageNo = 1;
while (true){
Page<RescueInfo> page = new Page<>(pageNo, 500);
IPage<RescueInfo> rescueInfos = baseMapper.getRescueInfoByDriver(rescueInfo, page);
if (ObjectUtil.isEmpty(rescueInfos) && rescueInfos.getRecords().isEmpty()){
break;
}
for (RescueInfo info : rescueInfos.getRecords()) {
MoneyManagement moneyManagement = new MoneyManagement();
moneyManagement.setDriverName(info.getDriverName());
Double grossWages = 0d;
Double tempSetMoney = ObjectUtils.isNotEmpty(info.getSetMoney()) ? Double.valueOf(info.getSetMoney()) / 100d : 0d;
Double tempCheckpointMoney = ObjectUtils.isNotEmpty(info.getCheckpointMoney()) ? info.getCheckpointMoney() : 0d;
JSONObject monthRescueRefuelRecord = new JSONObject();
monthRescueRefuelRecord.put("refuelMoney", 0);
monthRescueRefuelRecord.put("refuelNum", 0);
monthRescueRefuelRecord.put("refuelDistance", 0);
try {
LambdaQueryWrapper<RescueCarInfo> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(RescueCarInfo::getRescueCarNum, info.getDriverCarNum()).last("limit 1");
RescueCarInfo carInfo = carInfoService.getOne(queryWrapper);
monthRescueRefuelRecord = refuelRecordService.getMonthRescueRefuelRecord(info.getDriverId(), DateUtil.format(info.getRescueTime(), "yyyy-MM"), carInfo.getId());
} catch (Exception ignored) {
}
moneyManagement.setLicenseNum(info.getLicenseNum());
moneyManagement.setFeeType(info.getFeeType());
moneyManagement.setRescueTime(info.getRescueTime());
moneyManagement.setDiverCarNum(info.getDriverCarNum());
moneyManagement.setSetMoney(tempSetMoney);
moneyManagement.setCheckpointMoney(info.getCheckpointMoney());
moneyManagement.setUpMoney(tempSetMoney - tempCheckpointMoney);
moneyManagement.setEmptyingDistance(info.getEmptyNum());
String carType = "3";
if (StringUtils.isNotEmpty(info.getDriverCarNum())) {
RescueCarInfo carInfo = carInfoService.selectRescueCarInfoByNum(info.getDriverCarNum());
carType = carInfo.getRescueCarType();
}
if (carType.equals("1")) {
//大车
moneyManagement.setRoyaltyRatio(rescueTcBig);
moneyManagement.setRoyaltyMoney(tempSetMoney * rescueTcBig);
} else if (carType.equals("2")) {
//中车
moneyManagement.setRoyaltyRatio(rescueTcMid);
moneyManagement.setRoyaltyMoney(tempSetMoney * rescueTcMid);
} else {
//小车
moneyManagement.setRoyaltyRatio(rescueTcSmall);
moneyManagement.setRoyaltyMoney(tempSetMoney * rescueTcSmall);
}
//获取当前车 当前驾驶员 这个月跑了几次
JSONObject driverInfoObj = baseMapper.getDriverCarNum(info.getDriverId(), info.getDriverCarNum(), rescueInfo.getRescueStart());
//计算平均燃油费和平均油耗
Double avgFuelConsumption = 0d;
Double mglYh = 0d;
if (driverInfoObj.getInteger("allNum") != 0) {
avgFuelConsumption = monthRescueRefuelRecord.getDouble("refuelMoney") / driverInfoObj.getInteger("allNum");
mglYh = monthRescueRefuelRecord.getDouble("refuelNum") / driverInfoObj.getDouble("allDistance");
}
moneyManagement.setFuelCost(avgFuelConsumption);
moneyManagement.setOilConsumption(mglYh);
Double oilSubsidy = Optional.ofNullable(info.getEmptyNum()).orElse(0d) * mglYh;
moneyManagement.setOilSubsidy(oilSubsidy);
grossWages = grossWages + moneyManagement.getRoyaltyMoney() + oilSubsidy - avgFuelConsumption;
moneyManagement.setGrossWages(grossWages);
resList.add(moneyManagement);
}
pageNo ++;
}
return resList;
}
@Override

View File

@ -22,12 +22,12 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.nio.charset.StandardCharsets;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.locks.ReentrantLock;
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.module.rescue.service.impl.RescueDriverInfoServiceImpl.getRandomString6;
@ -158,7 +158,7 @@ public class RescueOrderInfoServiceImpl extends ServiceImpl<RescueOrderInfoMappe
// }
// }
//待支付的情况下进行主动查询
orderInfo.setOrderNo("appJy" + "-" + System.currentTimeMillis() + "-" + getRandomString6());
orderInfo.setOrderNo("appJy" + "-" + System.currentTimeMillis() + "-" + getRandomString6() + "-" + rescueInfo.getId());
this.updateById(orderInfo);
RescueOrderDetail rescueOrderDetail =new RescueOrderDetail();
rescueOrderDetail.setRecordTime(new Date());
@ -178,6 +178,30 @@ public class RescueOrderInfoServiceImpl extends ServiceImpl<RescueOrderInfoMappe
return one;
}
/**
* 通过rescue_info_id去拿订单
* @author 小李
* @date 10:56 2024/8/27
* @param rescueInfoId
**/
private RescueOrderInfo getOrderByRescueInfoId(Integer rescueInfoId){
/*
不确定是否会出现多条记录的情况所以用创建订单时的时间降序去取最新的一条
*/
List<RescueOrderInfo> list = this.list(new LambdaQueryWrapper<RescueOrderInfo>().eq(RescueOrderInfo::getRescueInfoId, rescueInfoId));
// 没查到直接抛异常理论上讲是不会抛的但以防万一抛了好过直接报错
if (ObjectUtils.isEmpty(list) || CollectionUtil.isEmpty(list)){
throw exception0(500, "系统故障");
}
// 如果只有一条就用这一条
if (list.size() == 1){
return list.get(0);
}
// 多条就创建时间降序排序取第一条
List<RescueOrderInfo> result = list.stream().sorted(Comparator.comparing(RescueOrderInfo::getCreateTime).reversed()).collect(Collectors.toList());
return result.get(0);
}
public Map<String,Object> transactions(Long orderId){
RescueOrderInfo orderInfo = this.getById(orderId);
@ -216,9 +240,10 @@ public class RescueOrderInfoServiceImpl extends ServiceImpl<RescueOrderInfoMappe
JSONObject decryptDataObj = JSONObject.parseObject(decryptData, JSONObject.class);
if(lock.tryLock()) {
try {
// 解密resource中的通知数据
// 解密resource中的通知数据 TODO
String orderNo = decryptDataObj.get("out_trade_no").toString();
RescueOrderInfo orderInfo = this.getOrderByOrderNo(orderNo);
String rescueInfoId = orderNo.split("-")[orderNo.split("-").length - 1];
RescueOrderInfo orderInfo = getOrderByRescueInfoId(Integer.parseInt(rescueInfoId));
if (orderInfo.getOrderStatus().equals("1")){
RescueInfo rescueInfo = rescueInfoService.getById(orderInfo.getRescueInfoId());
DriverInfo driverInfo = driverInfoService.getById(rescueInfo.getDriverId());

View File

@ -83,6 +83,9 @@ public class RedissonDelayQueue {
// TODO 还要通知总调度
/** 两个值虽然一样,但避免无法删除一直存在问题,干脆重新来过 */
// 移除原来的
removeAllTasks(taskDto.getRescueInfoId());
// 在新创建定时任务
offerTask(task, UserConstants.RESCUE_TIME);
} catch (Exception e) {

View File

@ -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);
// }
}

View File

@ -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());
}
}
}