救援新功能1/2

This commit is contained in:
xiao-fajia 2024-08-26 16:08:24 +08:00
parent fa0deb4ff3
commit 889b9b6b2c
11 changed files with 227 additions and 12 deletions

View File

@ -75,4 +75,9 @@ public class UserConstants
*/
public static final int PASSWORD_MIN_LENGTH = 5;
public static final int PASSWORD_MAX_LENGTH = 20;
/** 救援业务管理员 */
public static final String RESCUE_MANAGE = "jiuyuan";
/** 救援司机 */
public static final String RESCUE_DRIVER = "jysj";
}

View File

@ -1,34 +1,38 @@
package cn.iocoder.yudao.module.rescue.controller.admin;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.security.core.LoginUser;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.module.constant.UserConstants;
import cn.iocoder.yudao.module.rescue.core.controller.BaseController;
import cn.iocoder.yudao.module.rescue.core.page.TableDataInfo;
import cn.iocoder.yudao.module.rescue.domain.DriverInfo;
import cn.iocoder.yudao.module.rescue.domain.RescueInfo;
import cn.iocoder.yudao.module.rescue.domain.RescueInfoDetail;
import cn.iocoder.yudao.module.rescue.domain.RescueOrderInfo;
import cn.iocoder.yudao.module.rescue.domain.*;
import cn.iocoder.yudao.module.rescue.dto.DriverInfoDto;
import cn.iocoder.yudao.module.rescue.dto.SysDictData;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.security.core.LoginUser;
import cn.iocoder.yudao.module.staff.entity.CompanyStaff;
import cn.iocoder.yudao.module.system.api.dict.DictDataApi;
import cn.iocoder.yudao.module.system.api.dict.dto.DictDataRespDTO;
import cn.iocoder.yudao.module.rescue.service.IRescueDictStaffService;
import cn.iocoder.yudao.module.rescue.service.IRescueInfoDetailService;
import cn.iocoder.yudao.module.rescue.service.IRescueInfoService;
import cn.iocoder.yudao.module.rescue.service.IRescueOrderInfoService;
import cn.iocoder.yudao.module.rescue.utils.ExcelUtil;
import cn.iocoder.yudao.module.rescue.utils.StringUtils;
import cn.iocoder.yudao.module.rescue.vo.MoneyManagement;
import cn.iocoder.yudao.module.staff.entity.CompanyStaff;
import cn.iocoder.yudao.module.staff.service.CompanyStaffService;
import cn.iocoder.yudao.module.system.api.dict.DictDataApi;
import cn.iocoder.yudao.module.system.api.dict.dto.DictDataRespDTO;
import cn.iocoder.yudao.module.system.api.permission.PermissionApi;
import cn.iocoder.yudao.module.system.api.permission.RoleApi;
import cn.iocoder.yudao.module.system.api.permission.dto.RoleReqDTO;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
@ -53,6 +57,22 @@ public class RescueInfoSystem extends BaseController {
@Resource
private IRescueInfoDetailService rescueInfoDetailService;
@Resource
private IRescueDictStaffService rescueDictStaffService;
@Resource
@Lazy
private AdminUserApi adminUserApi;
@Resource
private CompanyStaffService staffService;
@Resource
private RoleApi roleApi;
@Resource
private PermissionApi permissionApi;
/**
* 新增道路救援发起
*/
@ -310,6 +330,10 @@ public class RescueInfoSystem extends BaseController {
@PostMapping("/delRescueRoad")
public CommonResult delRescueRoad(Long dictId) {
dictDataApi.deleteDictDataByIds(new Long[]{dictId});
RescueDictStaff flag = rescueDictStaffService.getOne(new LambdaQueryWrapper<RescueDictStaff>().eq(RescueDictStaff::getDictId, dictId));
if (ObjectUtil.isNotEmpty(flag)){
rescueDictStaffService.remove(new LambdaQueryWrapper<RescueDictStaff>().eq(RescueDictStaff::getDictId, dictId));
}
return CommonResult.ok();
}
@ -349,4 +373,65 @@ public class RescueInfoSystem extends BaseController {
String title = "施救总金额:" + jsonObject.getString("allMoney") + "元 出车次数:" + jsonObject.getString("allNum") + "次 提成总金额:" + jsonObject.getString("tcAll") + " 元 燃油费小计:" + jsonObject.getString("refuelMoney") + "";
util.exportExcel(response, list, "救援财务报表", title);
}
/**
* 查询救援路段的司机和管理人员信息
* @author 小李
* @date 9:17 2024/8/26
* @param ids 路段IDs 一个或多个
**/
@GetMapping("/getDictStaff/{ids}")
public CommonResult getDictStaff(@PathVariable("ids") Long[] ids){
List<Long> dictIds = Arrays.asList(ids);
List<RescueDictStaff> rescueDictStaffs = dictIds.stream().map(item -> {
RescueDictStaff rescueDictStaff = rescueDictStaffService.getOne(new LambdaQueryWrapper<RescueDictStaff>().eq(RescueDictStaff::getDictId, item));
if (ObjectUtil.isNotEmpty(rescueDictStaff)) {
// 拿路段管理员的名字
AdminUserRespDTO user = adminUserApi.getUser(rescueDictStaff.getManageId());
rescueDictStaff.setManageName(user.getNickname());
// 拿路段司机的名字
List<Long> driverIds = Arrays.asList(rescueDictStaff.getDriverIds().split(",")).stream().map(Long::parseLong).collect(Collectors.toList());
List<AdminUserRespDTO> drivers = adminUserApi.getUserList(driverIds);
StringJoiner tempStr = new StringJoiner("|");
for (AdminUserRespDTO driver : drivers) {
tempStr.add(driver.getNickname());
}
rescueDictStaff.setDriverNames(tempStr.toString());
}
return rescueDictStaff;
}).collect(Collectors.toList());
return success(rescueDictStaffs);
}
/**
* 获得所有救援业务管理员
* @author 小李
* @date 10:10 2024/8/26
**/
@GetMapping("/getManages")
public CommonResult getManages(){
RoleReqDTO roleInfo = roleApi.getRoleInfo(UserConstants.RESCUE_MANAGE);
List<Long> userIds = permissionApi.getUserIdByRoleId(roleInfo.getId());
List<CompanyStaff> staffs = staffService.list(new LambdaQueryWrapper<CompanyStaff>().in(CompanyStaff::getUserId, userIds));
return success(staffs);
}
/**
* 获得所有司机
* @author 小李
* @date 10:10 2024/8/26
**/
@GetMapping("/getDrivers")
public CommonResult getDrivers(){
RoleReqDTO roleInfo = roleApi.getRoleInfo(UserConstants.RESCUE_DRIVER);
List<Long> userIds = permissionApi.getUserIdByRoleId(roleInfo.getId());
List<CompanyStaff> staffs = staffService.list(new LambdaQueryWrapper<CompanyStaff>().in(CompanyStaff::getUserId, userIds));
return success(staffs);
}
@PostMapping("/bindDictStaff")
public CommonResult bindDictStaff(@RequestBody RescueDictStaff rescueDictStaff){
rescueDictStaffService.saveOrUpdate(rescueDictStaff);
return CommonResult.ok();
}
}

View File

@ -0,0 +1,41 @@
package cn.iocoder.yudao.module.rescue.domain;
import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* 路段和人员绑定表
* @author 小李
* @date 9:12 2024/8/26
**/
@Data
@TableName("rescue_dict_staff")
@EqualsAndHashCode(callSuper = true)
public class RescueDictStaff extends TenantBaseDO {
/** 主键标识 */
@TableId(type = IdType.ASSIGN_ID)
private String id;
/** 字典数据ID */
private Long dictId;
/** 管理人员ID */
private Long manageId;
/** 管理人员名字 */
@TableField(exist = false)
private String manageName;
/** 司机们的ID 逗号分隔 */
private String driverIds;
/** 司机们的名字 */
@TableField(exist = false)
private String driverNames;
}

View File

@ -0,0 +1,9 @@
package cn.iocoder.yudao.module.rescue.mapper;
import cn.iocoder.yudao.module.rescue.domain.RescueDictStaff;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface RescueDictStaffMapper extends BaseMapper<RescueDictStaff> {
}

View File

@ -0,0 +1,12 @@
package cn.iocoder.yudao.module.rescue.service;
import cn.iocoder.yudao.module.rescue.domain.RescueDictStaff;
import com.baomidou.mybatisplus.extension.service.IService;
/**
* 路段和人员绑定表 接口
* @author 小李
* @date 9:13 2024/8/26
**/
public interface IRescueDictStaffService extends IService<RescueDictStaff> {
}

View File

@ -0,0 +1,16 @@
package cn.iocoder.yudao.module.rescue.service.impl;
import cn.iocoder.yudao.module.rescue.domain.RescueDictStaff;
import cn.iocoder.yudao.module.rescue.mapper.RescueDictStaffMapper;
import cn.iocoder.yudao.module.rescue.service.IRescueDictStaffService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
/**
* 路段和人员绑定表 接口实现类
* @author 小李
* @date 9:13 2024/8/26
**/
@Service
public class RescueDictStaffServiceImpl extends ServiceImpl<RescueDictStaffMapper, RescueDictStaff> implements IRescueDictStaffService {
}

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.iocoder.yudao.module.rescue.mapper.RescueDictStaffMapper">
</mapper>

View File

@ -72,4 +72,12 @@ public interface PermissionApi {
* @param userId 用户ID
**/
List<Long> getRoleIdsByUserId(Long userId);
/**
* 根据权限ID拿拥有该权限的所有人
* @author 小李
* @date 10:25 2024/8/26
* @param roleId 权限ID
**/
List<Long> getUserIdByRoleId(Long roleId);
}

View File

@ -77,4 +77,15 @@ public class PermissionApiImpl implements PermissionApi {
return roleIds.stream().collect(Collectors.toList());
}
/**
* 根据权限ID拿拥有该权限的所有人
* @author 小李
* @date 10:25 2024/8/26
* @param roleId 权限ID
**/
@Override
public List<Long> getUserIdByRoleId(Long roleId){
return permissionService.getUserIdByRoleId(roleId);
}
}

View File

@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.system.service.permission;
import cn.iocoder.yudao.module.system.api.permission.dto.DeptDataPermissionRespDTO;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import static java.util.Collections.singleton;
@ -161,4 +162,12 @@ public interface PermissionService {
*/
DeptDataPermissionRespDTO getDeptDataPermission(Long userId);
/**
* 根据权限ID拿拥有该权限的所有人
* @author 小李
* @date 10:25 2024/8/26
* @param roleId 权限ID
**/
List<Long> getUserIdByRoleId(Long roleId);
}

View File

@ -7,6 +7,7 @@ import cn.hutool.extra.spring.SpringUtil;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.framework.datapermission.core.annotation.DataPermission;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.module.system.api.permission.dto.DeptDataPermissionRespDTO;
import cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO;
@ -33,6 +34,7 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.*;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
import static cn.iocoder.yudao.framework.common.util.json.JsonUtils.toJsonString;
@ -359,4 +361,15 @@ public class PermissionServiceImpl implements PermissionService {
return SpringUtil.getBean(getClass());
}
/**
* 根据权限ID拿拥有该权限的所有人
* @author 小李
* @date 10:25 2024/8/26
* @param roleId 权限ID
**/
public List<Long> getUserIdByRoleId(Long roleId){
List<UserRoleDO> userRoleDOS = userRoleMapper.selectList(new LambdaQueryWrapperX<UserRoleDO>().eq(UserRoleDO::getRoleId, roleId));
List<Long> userIds = userRoleDOS.stream().map(item -> item.getUserId()).collect(Collectors.toList());
return userIds;
}
}