diff --git a/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/app/controller/admin/SysLoginController.java b/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/app/controller/admin/SysLoginController.java index f4881c58..feb4ebb7 100644 --- a/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/app/controller/admin/SysLoginController.java +++ b/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/app/controller/admin/SysLoginController.java @@ -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 roleIdsByUserId = permissionApi.getRoleIdsByUserId(loginUser.getId()); List roleList = roleApi.getRoleList(); - List roleNames = roleList.stream().filter(item -> roleIdsByUserId.contains(item.getId())).map(item -> item.getName()).collect(Collectors.toList()); - map.put("roles", roleNames); + List role = roleList.stream().filter(item -> roleIdsByUserId.contains(item.getId())).collect(Collectors.toList()); + map.put("role", role); // 权限集合 List menuList = menuService.getMenuList(); // Set 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 roles = permissionService.getRolePermission(user); -// UserBalance userBalance = balanceService.selectShopUserBalanceByUserId(user.getUserId()); +// Set 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 roleList = roleApi.getRoleList(); List roleIdsByUserId = permissionApi.getRoleIdsByUserId(user.getId()); - List roles = roleList.stream().filter(item -> roleIdsByUserId.contains(item.getId())).collect(Collectors.toList()); + List 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 roleList = roleApi.getRoleList(); List roleIdsByUserId = permissionApi.getRoleIdsByUserId(user.getId()); - List roles = roleList.stream().filter(item -> roleIdsByUserId.contains(item.getId())).collect(Collectors.toList()); + List 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 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; + } /** * 同步数据 diff --git a/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/controller/admin/RescueCarSpendController.java b/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/controller/admin/RescueCarSpendController.java index a07122a6..49db4f28 100644 --- a/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/controller/admin/RescueCarSpendController.java +++ b/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/controller/admin/RescueCarSpendController.java @@ -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 list = rescueCarSpendService.list(); ExcelUtil util = new ExcelUtil(RescueCarSpend.class); diff --git a/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/controller/admin/RescueInfoSystem.java b/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/controller/admin/RescueInfoSystem.java index f93d7240..0c9490c6 100644 --- a/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/controller/admin/RescueInfoSystem.java +++ b/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/controller/admin/RescueInfoSystem.java @@ -178,12 +178,8 @@ public class RescueInfoSystem extends BaseController { break; } } - // 导出 Excel - Map columnWidthMap = new HashMap<>(); - // 第一列的索引是0,宽度设置为20个字符宽 - columnWidthMap.put(9, 20); - columnWidthMap.put(10, 20); - ExcelUtils.write(response, "救援订单.xls", "数据", RescueInfo.class, list, columnWidthMap); + ExcelUtil util = new ExcelUtil(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 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 result = new ArrayList<>(); + while (true){ + Page page = new Page<>(pageNo, pageSize); + IPage rescueInfos = rescueInfoService.getRescueInfoByDriver(rescueInfo, page); + if (ObjectUtil.isEmpty(rescueInfos) || rescueInfos.getRecords().isEmpty()){ + break; + } + List list = rescueInfoService.moneyManagement2(rescueInfos.getRecords(), rescueInfo.getRescueStart()); + result.addAll(list); + pageNo ++; + } JSONObject jsonObject = rescueInfoService.listData(rescueInfo); ExcelUtil util = new ExcelUtil(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); } /** diff --git a/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/domain/RescueInfo.java b/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/domain/RescueInfo.java index be24eb45..e6723f26 100644 --- a/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/domain/RescueInfo.java +++ b/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/domain/RescueInfo.java @@ -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 roadIds; } diff --git a/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/domain/WxLoginBody.java b/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/domain/WxLoginBody.java new file mode 100644 index 00000000..63bffa92 --- /dev/null +++ b/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/domain/WxLoginBody.java @@ -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; +} diff --git a/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/service/impl/RescueInfoServiceImpl.java b/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/service/impl/RescueInfoServiceImpl.java index 2c3cabff..dd4b2d03 100644 --- a/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/service/impl/RescueInfoServiceImpl.java +++ b/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/service/impl/RescueInfoServiceImpl.java @@ -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 list = rescueDictStaffService.list(new LambdaQueryWrapper().in(RescueDictStaff::getDictId, rescueInfo.getRoadIds())); - if (CollectionUtil.isNotEmpty(list)){ - Set 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 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 moneyManagement(RescueInfo rescueInfo) { -// List rescueInfos = baseMapper.getRescueInfoByDriver(rescueInfo); -// List 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 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 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 page = new Page<>(pageNo, 500); + IPage 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 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 diff --git a/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/service/impl/RescueOrderInfoServiceImpl.java b/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/service/impl/RescueOrderInfoServiceImpl.java index 25107ef4..3e668959 100644 --- a/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/service/impl/RescueOrderInfoServiceImpl.java +++ b/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/service/impl/RescueOrderInfoServiceImpl.java @@ -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 list = this.list(new LambdaQueryWrapper().eq(RescueOrderInfo::getRescueInfoId, rescueInfoId)); + // 没查到直接抛异常,理论上讲是不会抛的,但以防万一,抛了好过直接报错 + if (ObjectUtils.isEmpty(list) || CollectionUtil.isEmpty(list)){ + throw exception0(500, "系统故障"); + } + // 如果只有一条,就用这一条 + if (list.size() == 1){ + return list.get(0); + } + // 多条就创建时间降序排序取第一条 + List result = list.stream().sorted(Comparator.comparing(RescueOrderInfo::getCreateTime).reversed()).collect(Collectors.toList()); + return result.get(0); + } + public Map transactions(Long orderId){ RescueOrderInfo orderInfo = this.getById(orderId); @@ -216,9 +240,10 @@ public class RescueOrderInfoServiceImpl extends ServiceImpl