更新检测员工相关功能
This commit is contained in:
parent
756ce20950
commit
7b206d8f7c
@ -0,0 +1,15 @@
|
||||
package cn.iocoder.yudao.module.constant;
|
||||
|
||||
/**
|
||||
* @Description: 检测常量信息
|
||||
* @Author: 86187
|
||||
* @Date: 2025/01/23 13:55
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public class InspectionConstants {
|
||||
|
||||
/**
|
||||
* 检测基础员工角色 Code
|
||||
*/
|
||||
public static final String INSPECTION_BASE_STAFF_ROLE = "jcworker";
|
||||
}
|
@ -3,34 +3,41 @@ package cn.iocoder.yudao.module.inspection.controller;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.lang.Validator;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.IdcardUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.PhoneUtil;
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||
import cn.iocoder.yudao.module.core.controller.BaseController;
|
||||
import cn.iocoder.yudao.module.inspection.entity.InspectionPickCar;
|
||||
import cn.iocoder.yudao.module.inspection.entity.InspectionStaff;
|
||||
import cn.iocoder.yudao.module.inspection.enums.DriverLicenseType;
|
||||
import cn.iocoder.yudao.module.inspection.query.InspectionStaffQuery;
|
||||
import cn.iocoder.yudao.module.inspection.service.InspectionStaffService;
|
||||
import cn.iocoder.yudao.module.inspection.vo.InspectionStaffSaveVo;
|
||||
import cn.iocoder.yudao.module.inspection.vo.StaffImportExcelVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserImportExcelVO;
|
||||
import cn.iocoder.yudao.module.system.enums.common.SexEnum;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserPageReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserRespVO;
|
||||
import cn.iocoder.yudao.module.system.convert.user.UserConvert;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static io.micrometer.core.instrument.config.validate.Validated.valid;
|
||||
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
|
||||
import static cn.iocoder.yudao.framework.excel.core.util.ExcelUtils.exportBlankTemplate;
|
||||
|
||||
/**
|
||||
* inspectionFileController
|
||||
@ -52,7 +59,7 @@ public class InspectionStaffController extends BaseController {
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
public CommonResult list(InspectionStaffQuery query,
|
||||
@RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
|
||||
@RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNum,
|
||||
@RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) {
|
||||
Page<InspectionStaffSaveVo> page = new Page<>(pageNum, pageSize);
|
||||
IPage<InspectionStaffSaveVo> list = inspectionStaffService.getList(page, query);
|
||||
@ -70,6 +77,19 @@ public class InspectionStaffController extends BaseController {
|
||||
return success(inspectionStaffService.get(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增检测员工
|
||||
*
|
||||
* @param inspectionStaff
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/save")
|
||||
public CommonResult save(@RequestBody InspectionStaffSaveVo inspectionStaff) {
|
||||
//校验
|
||||
verify(inspectionStaff);
|
||||
return success(inspectionStaffService.saveInspectionStaff(inspectionStaff));
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑检测员工
|
||||
*
|
||||
@ -84,11 +104,55 @@ public class InspectionStaffController extends BaseController {
|
||||
return success(inspectionStaffService.edit(inspectionStaff));
|
||||
}
|
||||
|
||||
/**
|
||||
* 模板
|
||||
*
|
||||
* @param response
|
||||
* @throws IOException
|
||||
*/
|
||||
@GetMapping("/get-import-template")
|
||||
public void importTemplate(HttpServletResponse response) throws IOException {
|
||||
// 手动创建导出 demo
|
||||
// 输出
|
||||
ExcelUtils.write(response, "用户导入模板.xls", "用户列表", StaffImportExcelVO.class, null);
|
||||
// ExcelUtils.write(response, "用户导入模板.xls", "用户列表", StaffImportExcelVO.class, null);
|
||||
|
||||
// 使用 HashMap 来替代 Map.of,兼容 JDK 1.8
|
||||
Map<Integer, String> headerMap = new HashMap<>();
|
||||
headerMap.put(0, "部门名称");
|
||||
headerMap.put(1, "员工姓名");
|
||||
headerMap.put(2, "身份证号码");
|
||||
headerMap.put(3, "居住地址");
|
||||
headerMap.put(4, "学历");
|
||||
headerMap.put(5, "毕业院校");
|
||||
headerMap.put(6, "电话号码");
|
||||
headerMap.put(7, "短号");
|
||||
headerMap.put(8, "入职时间");
|
||||
headerMap.put(9, "试用期");
|
||||
headerMap.put(10, "社保购买日期");
|
||||
headerMap.put(11, "紧急联系人");
|
||||
headerMap.put(12, "紧急联系人电话");
|
||||
headerMap.put(13, "驾驶证类型");
|
||||
headerMap.put(14, "备注");
|
||||
|
||||
// 下拉框列及选项:列索引 -> 下拉框选项
|
||||
Map<Integer, String[]> dropdownColumns = new HashMap<>();
|
||||
List<String> allId = DriverLicenseType.getAllId();
|
||||
String[] array = ArrayUtil.toArray(allId, String.class);
|
||||
dropdownColumns.put(13, array); // 驾照类型
|
||||
|
||||
// 导出空白模板到Excel
|
||||
exportBlankTemplate(response, "staff_template.xlsx", "员工信息", headerMap, dropdownColumns, true);
|
||||
|
||||
}
|
||||
|
||||
@GetMapping("/export")
|
||||
@ApiAccessLog(operateType = EXPORT)
|
||||
public void exportUserList(InspectionStaffQuery query,
|
||||
HttpServletResponse response) throws IOException {
|
||||
List<InspectionStaffSaveVo> list = inspectionStaffService.getAll(query);
|
||||
// 输出 Excel
|
||||
ExcelUtils.write(response, "用户数据.xls", "数据", InspectionStaffSaveVo.class,
|
||||
list);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,9 +1,13 @@
|
||||
package cn.iocoder.yudao.module.inspection.entity;
|
||||
|
||||
import cn.iocoder.yudao.annotation.Excel;
|
||||
import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO;
|
||||
import com.alibaba.excel.annotation.ExcelIgnore;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
@ -20,77 +24,92 @@ public class InspectionStaff extends TenantBaseDO {
|
||||
* 员工id
|
||||
*/
|
||||
@TableId(type = IdType.NONE)
|
||||
@ExcelIgnore
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 身份证号
|
||||
*/
|
||||
@TableField("id_card")
|
||||
@ExcelProperty("身份证号")
|
||||
private String idCard;
|
||||
|
||||
/**
|
||||
* 居住地址
|
||||
*/
|
||||
@TableField("address")
|
||||
@ExcelProperty("居住地址")
|
||||
private String address;
|
||||
|
||||
/**
|
||||
* 学历
|
||||
*/
|
||||
@TableField("educational")
|
||||
@ExcelProperty("学历")
|
||||
private String educational;
|
||||
|
||||
/**
|
||||
* 毕业院校
|
||||
*/
|
||||
@TableField("school")
|
||||
@ExcelProperty("毕业院校")
|
||||
private String school;
|
||||
|
||||
/**
|
||||
* 短号
|
||||
*/
|
||||
@TableField("short_number")
|
||||
@ExcelProperty("短号")
|
||||
private String shortNumber;
|
||||
|
||||
/**
|
||||
* 入职日期
|
||||
*/
|
||||
@TableField("join_date")
|
||||
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
|
||||
@ExcelProperty("入职日期")
|
||||
private Date joinDate;
|
||||
|
||||
/**
|
||||
* 试用期
|
||||
*/
|
||||
@TableField("probation_period")
|
||||
@ExcelProperty("试用期")
|
||||
private String probationPeriod;
|
||||
|
||||
/**
|
||||
* 社保购买日期
|
||||
*/
|
||||
@TableField("social_security_buy_date")
|
||||
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
|
||||
@ExcelProperty("社保购买日期")
|
||||
private Date socialSecurityBuyDate;
|
||||
|
||||
/**
|
||||
* 紧急联系人
|
||||
*/
|
||||
@TableField("emergency_contact_name")
|
||||
@ExcelProperty("紧急联系人")
|
||||
private String emergencyContactName;
|
||||
|
||||
/**
|
||||
* 紧急联系人电话
|
||||
*/
|
||||
@TableField("emergency_contact_phone")
|
||||
@ExcelProperty("联系人电话")
|
||||
private String emergencyContactPhone;
|
||||
|
||||
/**
|
||||
* 驾驶证类型
|
||||
*/
|
||||
@TableField("driver_license_type")
|
||||
@ExcelProperty("驾驶证类型")
|
||||
private String driverLicenseType;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@TableField("remark")
|
||||
@ExcelIgnore
|
||||
private String remark;
|
||||
}
|
||||
|
@ -44,4 +44,11 @@ public enum DriverLicenseType {
|
||||
return commonDownRespVo;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static List<String> getAllId() {
|
||||
DriverLicenseType[] values = DriverLicenseType.values();
|
||||
return Arrays.stream(values).map(item -> {
|
||||
return item.getId();
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
}
|
@ -31,7 +31,7 @@ public interface InspectionStaffMapper extends BaseMapper<InspectionStaff> {
|
||||
* @param query
|
||||
* @return
|
||||
*/
|
||||
IPage<InspectionStaffSaveVo> getList(Page<InspectionStaffSaveVo> page, InspectionStaffQuery query);
|
||||
IPage<InspectionStaffSaveVo> getList(@Param("page") Page<InspectionStaffSaveVo> page, @Param("query") InspectionStaffQuery query);
|
||||
|
||||
/**
|
||||
* 根据条件查询检测员工子表
|
||||
@ -40,5 +40,13 @@ public interface InspectionStaffMapper extends BaseMapper<InspectionStaff> {
|
||||
* @return
|
||||
*/
|
||||
InspectionStaffSaveVo get(Long id);
|
||||
|
||||
/**
|
||||
* 根据条件查询检测员工子表
|
||||
*
|
||||
* @param query
|
||||
* @return
|
||||
*/
|
||||
List<InspectionStaffSaveVo> getAll(InspectionStaffQuery query);
|
||||
}
|
||||
|
||||
|
@ -49,4 +49,9 @@ public class InspectionStaffQuery extends InspectionStaff {
|
||||
* 用户性别
|
||||
**/
|
||||
private String sex;
|
||||
|
||||
/**
|
||||
* 用户状态
|
||||
*/
|
||||
private Integer status;
|
||||
}
|
||||
|
@ -26,6 +26,13 @@ public interface InspectionStaffService extends IService<InspectionStaff> {
|
||||
* @return
|
||||
*/
|
||||
IPage<InspectionStaffSaveVo> getList(Page<InspectionStaffSaveVo> page, InspectionStaffQuery query);
|
||||
/**
|
||||
* 获取所有检测员工
|
||||
*
|
||||
* @param query
|
||||
* @return
|
||||
*/
|
||||
List<InspectionStaffSaveVo> getAll(InspectionStaffQuery query);
|
||||
|
||||
/**
|
||||
* 编辑检测员工
|
||||
@ -42,5 +49,13 @@ public interface InspectionStaffService extends IService<InspectionStaff> {
|
||||
* @return
|
||||
*/
|
||||
InspectionStaffSaveVo get(Long id);
|
||||
|
||||
/**
|
||||
* 保存检测员工
|
||||
*
|
||||
* @param inspectionStaffVo
|
||||
* @return
|
||||
*/
|
||||
boolean saveInspectionStaff(InspectionStaffSaveVo inspectionStaffVo);
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.inspection.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.iocoder.yudao.module.constant.InspectionConstants;
|
||||
import cn.iocoder.yudao.module.inspection.entity.InspectionPickCar;
|
||||
import cn.iocoder.yudao.module.inspection.entity.InspectionStaff;
|
||||
import cn.iocoder.yudao.module.inspection.mapper.InspectionStaffMapper;
|
||||
@ -11,15 +12,24 @@ import cn.iocoder.yudao.module.inspection.vo.InspectionStaffSaveVo;
|
||||
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
||||
import cn.iocoder.yudao.module.system.api.user.dto.UserDTO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserSaveReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO;
|
||||
import cn.iocoder.yudao.module.system.service.permission.PermissionService;
|
||||
import cn.iocoder.yudao.module.system.service.permission.RoleService;
|
||||
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
/**
|
||||
@ -34,6 +44,12 @@ public class InspectionStaffServiceImpl extends ServiceImpl<InspectionStaffMappe
|
||||
@Autowired
|
||||
private AdminUserService userService;
|
||||
|
||||
@Autowired
|
||||
private RoleService roleService;
|
||||
|
||||
@Autowired
|
||||
private PermissionService permissionService;
|
||||
|
||||
/**
|
||||
* 获取检测员工分页
|
||||
*
|
||||
@ -46,6 +62,17 @@ public class InspectionStaffServiceImpl extends ServiceImpl<InspectionStaffMappe
|
||||
return baseMapper.getList(page, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有检测员工
|
||||
*
|
||||
* @param query
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<InspectionStaffSaveVo> getAll(InspectionStaffQuery query) {
|
||||
return baseMapper.getAll(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑检测员工
|
||||
*
|
||||
@ -87,5 +114,36 @@ public class InspectionStaffServiceImpl extends ServiceImpl<InspectionStaffMappe
|
||||
}
|
||||
return inspectionStaffSaveVo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存检测员工
|
||||
*
|
||||
* @param inspectionStaffVo
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean saveInspectionStaff(InspectionStaffSaveVo inspectionStaffVo) {
|
||||
//新增system_users主表
|
||||
UserSaveReqVO userDTO = BeanUtil.copyProperties(inspectionStaffVo, UserSaveReqVO.class);
|
||||
userDTO.setId(inspectionStaffVo.getUserId());
|
||||
Long userId = userService.createUser(userDTO);
|
||||
|
||||
//查询检测基础员工角色
|
||||
List<RoleDO> role = roleService.getRoleListByCodesTenant(Collections.singletonList(InspectionConstants.INSPECTION_BASE_STAFF_ROLE));
|
||||
|
||||
if (ObjectUtil.isNull(role)) {
|
||||
throw new RuntimeException("检测基础员工角色不存在");
|
||||
}
|
||||
|
||||
Set<Long> roleIds = role.stream().map(RoleDO::getId).collect(Collectors.toSet());
|
||||
//设置角色为检测基础员工
|
||||
permissionService.assignUserRole(userId, roleIds);
|
||||
|
||||
InspectionStaff inspectionStaff = BeanUtil.copyProperties(inspectionStaffVo, InspectionStaff.class);
|
||||
inspectionStaff.setUserId(userId);
|
||||
//新增检测员工子表
|
||||
return this.save(inspectionStaff);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,9 @@
|
||||
package cn.iocoder.yudao.module.inspection.vo;
|
||||
|
||||
import cn.iocoder.yudao.annotation.Excel;
|
||||
import cn.iocoder.yudao.module.inspection.entity.InspectionStaff;
|
||||
import com.alibaba.excel.annotation.ExcelIgnore;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
@ -16,54 +19,78 @@ public class InspectionStaffSaveVo extends InspectionStaff {
|
||||
/**
|
||||
* 员工编号
|
||||
*/
|
||||
@ExcelIgnore
|
||||
private Long id;
|
||||
/**
|
||||
* 用户账号
|
||||
*/
|
||||
@ExcelProperty("员工账号")
|
||||
private String username;
|
||||
/**
|
||||
* 用户昵称
|
||||
*/
|
||||
@ExcelProperty("员工名称")
|
||||
private String nickname;
|
||||
/**
|
||||
* 用户类型
|
||||
*/
|
||||
@ExcelIgnore
|
||||
private String userType;
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@ExcelIgnore
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 部门编号
|
||||
*/
|
||||
@ExcelIgnore
|
||||
private Long deptId;
|
||||
/**
|
||||
* 用户手机号码
|
||||
*/
|
||||
@ExcelProperty("手机号")
|
||||
private String mobile;
|
||||
/**
|
||||
* 用户密码
|
||||
*/
|
||||
@ExcelIgnore
|
||||
private String password;
|
||||
/**
|
||||
* 用户头像
|
||||
*/
|
||||
@ExcelIgnore
|
||||
private String avatar;
|
||||
|
||||
/**
|
||||
* 用户性别
|
||||
**/
|
||||
@ExcelIgnore
|
||||
private String sex;
|
||||
|
||||
/**
|
||||
* 用户性别
|
||||
*/
|
||||
@ExcelProperty(value = "用户性别")
|
||||
private String sexStr;
|
||||
|
||||
/**
|
||||
* 用户状态
|
||||
*/
|
||||
@ExcelIgnore
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 用户状态
|
||||
*/
|
||||
@ExcelProperty("状态")
|
||||
private String statusStr;
|
||||
|
||||
/**
|
||||
* 用户邮箱
|
||||
*/
|
||||
@ExcelProperty("邮箱")
|
||||
private String email;
|
||||
|
||||
/**
|
||||
|
@ -1,6 +1,7 @@
|
||||
package cn.iocoder.yudao.module.inspection.vo;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import com.alibaba.excel.converters.localdate.LocalDateStringConverter;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
@ -36,13 +37,13 @@ public class StaffImportExcelVO {
|
||||
@ExcelProperty("短号")
|
||||
private String shortNumber;
|
||||
|
||||
@ExcelProperty("入职时间")
|
||||
@ExcelProperty(value = "入职时间")
|
||||
private String joinDate;
|
||||
|
||||
@ExcelProperty("试用期")
|
||||
private String probationPeriod;
|
||||
|
||||
@ExcelProperty("社保购买日期")
|
||||
@ExcelProperty(value = "社保购买日期")
|
||||
private String socialSecurityBuyDate;
|
||||
|
||||
@ExcelProperty("紧急联系人")
|
||||
|
@ -5,34 +5,43 @@
|
||||
<mapper namespace="cn.iocoder.yudao.module.inspection.mapper.InspectionStaffMapper">
|
||||
<select id="getList" resultType="cn.iocoder.yudao.module.inspection.vo.InspectionStaffSaveVo">
|
||||
SELECT distinct
|
||||
su.id,
|
||||
su.nickname,
|
||||
su.username,
|
||||
su.user_type,
|
||||
su.remark,
|
||||
su.dept_id,
|
||||
su.mobile,
|
||||
su.password,
|
||||
su.avatar,
|
||||
su.sex,
|
||||
su.status,
|
||||
iss.id_card,
|
||||
iss.address,
|
||||
iss.educational,
|
||||
iss.school,
|
||||
iss.short_number,
|
||||
iss.join_date,
|
||||
iss.probation_period,
|
||||
iss.social_security_buy_date,
|
||||
iss.emergency_contact_name,
|
||||
iss.emergency_contact_phone,
|
||||
iss.driver_license_type
|
||||
su.id,
|
||||
su.nickname,
|
||||
su.username,
|
||||
su.user_type,
|
||||
su.remark,
|
||||
su.dept_id,
|
||||
su.mobile,
|
||||
su.password,
|
||||
su.avatar,
|
||||
su.sex,
|
||||
su.status,
|
||||
iss.id_card,
|
||||
iss.address,
|
||||
iss.educational,
|
||||
iss.school,
|
||||
iss.short_number,
|
||||
iss.join_date,
|
||||
iss.probation_period,
|
||||
iss.social_security_buy_date,
|
||||
iss.emergency_contact_name,
|
||||
iss.emergency_contact_phone,
|
||||
iss.driver_license_type
|
||||
FROM system_users su
|
||||
left join system_user_role sur on su.id = sur.user_id
|
||||
left join system_role sr on sur.role_id = sr.id
|
||||
left join inspection_staff iss on iss.user_id = su.id
|
||||
<where>
|
||||
sr.service_package_id = 'jiance' and sr.code != 'jcyh'
|
||||
<if test="query.nickname != null and query.nickname != ''">
|
||||
and su.nickname like concat('%', #{query.nickname}, '%')
|
||||
</if>
|
||||
<if test="query.mobile != null and query.mobile != ''">
|
||||
and su.mobile like concat('%', #{query.mobile}, '%')
|
||||
</if>
|
||||
<if test="query.status != null and query.status != ''">
|
||||
and su.status = #{query.status}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
<select id="get" resultType="cn.iocoder.yudao.module.inspection.vo.InspectionStaffSaveVo">
|
||||
@ -68,4 +77,44 @@
|
||||
and su.id = #{id}
|
||||
</where>
|
||||
</select>
|
||||
<select id="getAll" resultType="cn.iocoder.yudao.module.inspection.vo.InspectionStaffSaveVo"
|
||||
parameterType="cn.iocoder.yudao.module.inspection.query.InspectionStaffQuery">
|
||||
SELECT distinct
|
||||
su.id,
|
||||
su.nickname,
|
||||
su.username,
|
||||
su.mobile,
|
||||
su.avatar,
|
||||
su.sex,
|
||||
case sex when 0 then '男' when 1 then '女' end as sexStr,
|
||||
su.status,
|
||||
case su.status when 0 then '正常' when 1 then '停用' end as statusStr,
|
||||
iss.id_card,
|
||||
iss.address,
|
||||
iss.educational,
|
||||
iss.school,
|
||||
iss.short_number,
|
||||
iss.join_date,
|
||||
iss.probation_period,
|
||||
iss.social_security_buy_date,
|
||||
iss.emergency_contact_name,
|
||||
iss.emergency_contact_phone,
|
||||
iss.driver_license_type
|
||||
FROM system_users su
|
||||
left join system_user_role sur on su.id = sur.user_id
|
||||
left join system_role sr on sur.role_id = sr.id
|
||||
left join inspection_staff iss on iss.user_id = su.id
|
||||
<where>
|
||||
sr.service_package_id = 'jiance' and sr.code != 'jcyh'
|
||||
<if test="nickname != null and nickname != ''">
|
||||
and su.nickname like concat('%', #{nickname}, '%')
|
||||
</if>
|
||||
<if test="mobile != null and mobile != ''">
|
||||
and su.mobile like concat('%', #{mobile}, '%')
|
||||
</if>
|
||||
<if test="status != null and status != ''">
|
||||
and su.status = #{status}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
</mapper>
|
||||
|
@ -6,9 +6,16 @@ import cn.iocoder.yudao.framework.excel.core.handler.SetColumnWidthHandler;
|
||||
import com.alibaba.excel.EasyExcel;
|
||||
import com.alibaba.excel.converters.longconverter.LongStringConverter;
|
||||
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
|
||||
import org.apache.poi.hssf.usermodel.DVConstraint;
|
||||
import org.apache.poi.hssf.usermodel.HSSFDataValidation;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.ss.util.CellRangeAddressList;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@ -80,4 +87,68 @@ public class ExcelUtils {
|
||||
.doReadAllSync();
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出空白模板Excel,并为指定列添加下拉框
|
||||
*
|
||||
* @param fileName 文件名
|
||||
* @param sheetName 工作表名称
|
||||
* @param headerMap 表头字段映射(列索引 -> 列名称)
|
||||
* @param dropdownColumns 带下拉框的列及选项(列索引 -> 下拉框选项数组)
|
||||
* @throws IOException
|
||||
*/
|
||||
public static void exportBlankTemplate(HttpServletResponse response, String fileName, String sheetName,
|
||||
Map<Integer, String> headerMap,
|
||||
Map<Integer, String[]> dropdownColumns,
|
||||
boolean isMultiSelect) throws IOException {
|
||||
Workbook workbook = new XSSFWorkbook();
|
||||
Sheet sheet = workbook.createSheet(sheetName);
|
||||
|
||||
// 创建表头
|
||||
Row headerRow = sheet.createRow(0);
|
||||
for (Map.Entry<Integer, String> entry : headerMap.entrySet()) {
|
||||
headerRow.createCell(entry.getKey()).setCellValue(entry.getValue());
|
||||
}
|
||||
|
||||
// 添加下拉框到指定列
|
||||
if (dropdownColumns != null) {
|
||||
for (Map.Entry<Integer, String[]> entry : dropdownColumns.entrySet()) {
|
||||
addDropdownValidation(sheet, entry.getKey(), entry.getValue(), isMultiSelect);
|
||||
}
|
||||
}
|
||||
|
||||
// 设置响应头,指示浏览器下载文件
|
||||
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||
response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(fileName, StandardCharsets.UTF_8.name()) + ".xlsx");
|
||||
|
||||
// 将 Excel 文件写入输出流
|
||||
try (ServletOutputStream out = response.getOutputStream()) {
|
||||
workbook.write(out);
|
||||
out.flush();
|
||||
} finally {
|
||||
workbook.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 修改下拉框验证方法,支持多选功能
|
||||
private static void addDropdownValidation(Sheet sheet, int column, String[] options, boolean isMultiSelect) {
|
||||
DataValidationHelper validationHelper = sheet.getDataValidationHelper();
|
||||
DataValidationConstraint constraint;
|
||||
|
||||
// 判断是否启用多选下拉框
|
||||
if (isMultiSelect) {
|
||||
// 如果是多选,则使用逗号分隔的方式,构建一个包含所有选项的下拉框
|
||||
String combinedOptions = String.join(",", options);
|
||||
constraint = validationHelper.createExplicitListConstraint(new String[]{combinedOptions});
|
||||
} else {
|
||||
// 否则使用单选下拉框
|
||||
constraint = validationHelper.createExplicitListConstraint(options);
|
||||
}
|
||||
|
||||
// 设置下拉框范围(从第2行开始到第65535行,第column列)
|
||||
CellRangeAddressList addressList = new CellRangeAddressList(1, 65535, column, column);
|
||||
DataValidation validation = validationHelper.createValidation(constraint, addressList);
|
||||
sheet.addValidationData(validation);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user