feat(smartfactory): 增加员工导入功能并优化员工相关接口
- 新增员工导入模板下载和导入功能 - 添加获取指定厂区员工列表的接口 - 优化员工信息相关接口,移除不必要的字段 - 重构员工信息的数据库表结构
This commit is contained in:
parent
ca586f4173
commit
58d31795ac
@ -6,36 +6,47 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|||||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||||
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
|
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
|
||||||
import cn.iocoder.yudao.module.smartfactory.controller.admin.staff.vo.StaffPageReqVO;
|
import cn.iocoder.yudao.module.smartfactory.controller.admin.staff.vo.*;
|
||||||
import cn.iocoder.yudao.module.smartfactory.controller.admin.staff.vo.StaffRespVO;
|
import cn.iocoder.yudao.module.smartfactory.dal.dataobject.factoryinfo.FactoryInfoDO;
|
||||||
import cn.iocoder.yudao.module.smartfactory.controller.admin.staff.vo.StaffSaveReqVO;
|
|
||||||
import cn.iocoder.yudao.module.smartfactory.dal.dataobject.staff.StaffDO;
|
import cn.iocoder.yudao.module.smartfactory.dal.dataobject.staff.StaffDO;
|
||||||
|
import cn.iocoder.yudao.module.smartfactory.service.factoryinfo.FactoryInfoService;
|
||||||
import cn.iocoder.yudao.module.smartfactory.service.staff.StaffService;
|
import cn.iocoder.yudao.module.smartfactory.service.staff.StaffService;
|
||||||
|
import cn.iocoder.yudao.module.system.api.dict.DictDataApi;
|
||||||
|
import cn.iocoder.yudao.module.system.api.dict.dto.DictDataRespDTO;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
|
import io.swagger.v3.oas.annotations.Parameters;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||||
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
|
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
|
||||||
|
|
||||||
@Tag(name = "管理后台 - 员工")
|
@Tag(name = "管理后台 - 员工")
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/factory/staff")
|
@RequestMapping("/smartfactory/staff")
|
||||||
@Validated
|
@Validated
|
||||||
public class StaffController {
|
public class StaffController {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private StaffService staffService;
|
private StaffService staffService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private FactoryInfoService factoryInfoService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private DictDataApi dictDataApi;
|
||||||
|
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
@Operation(summary = "创建员工")
|
@Operation(summary = "创建员工")
|
||||||
@PreAuthorize("@ss.hasPermission('factory:staff:create')")
|
@PreAuthorize("@ss.hasPermission('factory:staff:create')")
|
||||||
@ -69,6 +80,17 @@ public class StaffController {
|
|||||||
return success(BeanUtils.toBean(staff, StaffRespVO.class));
|
return success(BeanUtils.toBean(staff, StaffRespVO.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/getListByFactory")
|
||||||
|
@Operation(summary = "获得指定厂区得员工")
|
||||||
|
@Parameter(name = "factoryId", description = "厂区编号", required = true, example = "1024")
|
||||||
|
@Parameter(name = "isIn", description = "是否获取该厂区得员工", required = true, example = "1024")
|
||||||
|
@PreAuthorize("@ss.hasPermission('factory:staff:query')")
|
||||||
|
public CommonResult<List<StaffRespVO>> getListByFactory(@RequestParam("factoryId") Long factoryId,
|
||||||
|
@RequestParam("isIn") Boolean isIn) {
|
||||||
|
List<StaffDO> staffs = staffService.getListByFactory(factoryId, isIn);
|
||||||
|
return success(BeanUtils.toBean(staffs, StaffRespVO.class));
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("/page")
|
@GetMapping("/page")
|
||||||
@Operation(summary = "获得员工分页")
|
@Operation(summary = "获得员工分页")
|
||||||
@PreAuthorize("@ss.hasPermission('factory:staff:query')")
|
@PreAuthorize("@ss.hasPermission('factory:staff:query')")
|
||||||
@ -90,4 +112,39 @@ public class StaffController {
|
|||||||
BeanUtils.toBean(list, StaffRespVO.class));
|
BeanUtils.toBean(list, StaffRespVO.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/get-import-template")
|
||||||
|
@Operation(summary = "获得导入用户模板")
|
||||||
|
public void importTemplate(HttpServletResponse response) throws IOException {
|
||||||
|
|
||||||
|
//获取部门名称
|
||||||
|
List<FactoryInfoDO> factoryInfoDOS = factoryInfoService.getFactoryListByType();
|
||||||
|
List<String> factoryName = factoryInfoDOS.stream()
|
||||||
|
.map(item -> item.getId() + ":" + item.getName())
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
//获取工种名称
|
||||||
|
List<DictDataRespDTO> workTypeVOs = dictDataApi.getDictDataList("user_work_type").getCheckedData();
|
||||||
|
List<String> workTypeName = workTypeVOs.stream()
|
||||||
|
.map(item -> item.getValue() + ":" + item.getLabel())
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
// 输出
|
||||||
|
ExcelUtils.write(response, "工人导入模板.xlsx", "工人列表",
|
||||||
|
StaffImportExcelVO.class, null,
|
||||||
|
1, factoryName,
|
||||||
|
2, workTypeName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/import")
|
||||||
|
@Operation(summary = "导入用户")
|
||||||
|
@Parameters({
|
||||||
|
@Parameter(name = "file", description = "Excel 文件", required = true),
|
||||||
|
@Parameter(name = "updateSupport", description = "是否支持更新,默认为 false", example = "true")
|
||||||
|
})
|
||||||
|
@PreAuthorize("@ss.hasPermission('factory:staff:import')")
|
||||||
|
public CommonResult<StaffImportRespVO> importExcel(@RequestParam("file") MultipartFile file,
|
||||||
|
@RequestParam(value = "updateSupport", required = false, defaultValue = "false") Boolean updateSupport) throws Exception {
|
||||||
|
List<StaffImportExcelVO> list = ExcelUtils.read(file, StaffImportExcelVO.class);
|
||||||
|
return success(staffService.importUserList(list, updateSupport));
|
||||||
|
}
|
||||||
}
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
package cn.iocoder.yudao.module.smartfactory.controller.admin.staff.vo;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.common.validation.IdCard;
|
||||||
|
import cn.iocoder.yudao.framework.common.validation.Mobile;
|
||||||
|
import com.alibaba.excel.annotation.ExcelProperty;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户 Excel 导入 VO
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Accessors(chain = false) // 设置 chain = false,避免用户导入有问题
|
||||||
|
public class StaffImportExcelVO {
|
||||||
|
|
||||||
|
@ExcelProperty("用户名称")
|
||||||
|
private String nickName;
|
||||||
|
|
||||||
|
@ExcelProperty("厂区名称")
|
||||||
|
private String factoryName;
|
||||||
|
|
||||||
|
@ExcelProperty("工种名称")
|
||||||
|
private String workTypeName;
|
||||||
|
|
||||||
|
@ExcelProperty("手机号码")
|
||||||
|
@Mobile
|
||||||
|
private String mobile;
|
||||||
|
|
||||||
|
@ExcelProperty("身份证号码")
|
||||||
|
@IdCard
|
||||||
|
private String idCard;
|
||||||
|
|
||||||
|
@ExcelProperty("薪资")
|
||||||
|
private BigDecimal salary;
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package cn.iocoder.yudao.module.smartfactory.controller.admin.staff.vo;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Schema(description = "管理后台 - 用户导入 Response VO")
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
public class StaffImportRespVO {
|
||||||
|
|
||||||
|
@Schema(description = "创建成功的用户名数组", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
private List<String> createUsernames;
|
||||||
|
|
||||||
|
@Schema(description = "更新成功的用户名数组", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
private List<String> updateUsernames;
|
||||||
|
|
||||||
|
@Schema(description = "导入失败的用户集合,key 为用户名,value 为失败原因", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
private Map<String, String> failureUsernames;
|
||||||
|
|
||||||
|
}
|
@ -1,13 +1,10 @@
|
|||||||
package cn.iocoder.yudao.module.smartfactory.controller.admin.staff.vo;
|
package cn.iocoder.yudao.module.smartfactory.controller.admin.staff.vo;
|
||||||
|
|
||||||
import lombok.*;
|
|
||||||
import java.util.*;
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||||
import org.springframework.format.annotation.DateTimeFormat;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import java.time.LocalDateTime;
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
import lombok.ToString;
|
||||||
|
|
||||||
@Schema(description = "管理后台 - 员工分页 Request VO")
|
@Schema(description = "管理后台 - 员工分页 Request VO")
|
||||||
@Data
|
@Data
|
||||||
@ -15,9 +12,6 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
|
|||||||
@ToString(callSuper = true)
|
@ToString(callSuper = true)
|
||||||
public class StaffPageReqVO extends PageParam {
|
public class StaffPageReqVO extends PageParam {
|
||||||
|
|
||||||
@Schema(description = "员工编号")
|
|
||||||
private String staffNo;
|
|
||||||
|
|
||||||
@Schema(description = "员工昵称")
|
@Schema(description = "员工昵称")
|
||||||
private String nickName;
|
private String nickName;
|
||||||
|
|
||||||
@ -27,23 +21,13 @@ public class StaffPageReqVO extends PageParam {
|
|||||||
@Schema(description = "用户性别(0男 1女 2未知)")
|
@Schema(description = "用户性别(0男 1女 2未知)")
|
||||||
private Integer sex;
|
private Integer sex;
|
||||||
|
|
||||||
@Schema(description = "岗位id", example = "28091")
|
|
||||||
private Long postId;
|
|
||||||
|
|
||||||
@Schema(description = "工种id", example = "6971")
|
@Schema(description = "工种id", example = "6971")
|
||||||
private Long workTypeId;
|
private Integer workTypeId;
|
||||||
|
|
||||||
@Schema(description = "工厂id", example = "6971")
|
@Schema(description = "工厂id", example = "6971")
|
||||||
private Long factoryId;
|
private Long factoryId;
|
||||||
|
|
||||||
@Schema(description = "身份证号")
|
|
||||||
private String idCard;
|
|
||||||
|
|
||||||
@Schema(description = "0离职 1在职", example = "1")
|
@Schema(description = "0离职 1在职", example = "1")
|
||||||
private Integer status;
|
private Integer status;
|
||||||
|
|
||||||
@Schema(description = "创建时间")
|
|
||||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
|
||||||
private LocalDateTime[] createTime;
|
|
||||||
|
|
||||||
}
|
}
|
@ -1,27 +1,23 @@
|
|||||||
package cn.iocoder.yudao.module.smartfactory.controller.admin.staff.vo;
|
package cn.iocoder.yudao.module.smartfactory.controller.admin.staff.vo;
|
||||||
|
|
||||||
|
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||||
|
import com.alibaba.excel.annotation.ExcelProperty;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.*;
|
import lombok.Data;
|
||||||
import java.util.*;
|
|
||||||
import java.util.*;
|
|
||||||
import org.springframework.format.annotation.DateTimeFormat;
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import com.alibaba.excel.annotation.*;
|
|
||||||
|
|
||||||
@Schema(description = "管理后台 - 员工 Response VO")
|
@Schema(description = "管理后台 - 员工 Response VO")
|
||||||
@Data
|
@Data
|
||||||
@ExcelIgnoreUnannotated
|
@ExcelIgnoreUnannotated
|
||||||
public class StaffRespVO {
|
public class StaffRespVO {
|
||||||
|
|
||||||
@Schema(description = "主键id", requiredMode = Schema.RequiredMode.REQUIRED, example = "8717")
|
@Schema(description = "主键id")
|
||||||
@ExcelProperty("主键id")
|
@ExcelProperty("序号")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@Schema(description = "员工编号")
|
|
||||||
@ExcelProperty("员工编号")
|
|
||||||
private String staffNo;
|
|
||||||
|
|
||||||
@Schema(description = "员工昵称")
|
@Schema(description = "员工昵称")
|
||||||
|
@ExcelProperty("姓名")
|
||||||
private String nickName;
|
private String nickName;
|
||||||
|
|
||||||
@Schema(description = "年龄")
|
@Schema(description = "年龄")
|
||||||
@ -29,29 +25,31 @@ public class StaffRespVO {
|
|||||||
private Integer age;
|
private Integer age;
|
||||||
|
|
||||||
@Schema(description = "用户性别(0男 1女 2未知)")
|
@Schema(description = "用户性别(0男 1女 2未知)")
|
||||||
|
@ExcelProperty("性别")
|
||||||
private Integer sex;
|
private Integer sex;
|
||||||
|
|
||||||
@Schema(description = "岗位id", example = "28091")
|
|
||||||
@ExcelProperty("岗位id")
|
|
||||||
private Long postId;
|
|
||||||
|
|
||||||
@Schema(description = "工种id", example = "6971")
|
@Schema(description = "工种id", example = "6971")
|
||||||
@ExcelProperty("工种id")
|
private Integer workTypeId;
|
||||||
private Long workTypeId;
|
|
||||||
|
|
||||||
@Schema(description = "工厂id", example = "6971")
|
@Schema(description = "工厂id", example = "6971")
|
||||||
private Long factoryId;
|
private Long factoryId;
|
||||||
|
|
||||||
|
@Schema(description = "工厂名称", example = "6971")
|
||||||
|
@ExcelProperty("工厂名称")
|
||||||
|
private String factoryName;
|
||||||
|
|
||||||
|
@Schema(description = "手机号")
|
||||||
|
@ExcelProperty("手机号")
|
||||||
|
private String mobile;
|
||||||
|
|
||||||
@Schema(description = "身份证号")
|
@Schema(description = "身份证号")
|
||||||
@ExcelProperty("身份证号")
|
@ExcelProperty("身份证号")
|
||||||
private String idCard;
|
private String idCard;
|
||||||
|
|
||||||
@Schema(description = "0离职 1在职", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
@Schema(description = "0离职 1在职 2工伤")
|
||||||
@ExcelProperty("0离职 1在职")
|
|
||||||
private Integer status;
|
private Integer status;
|
||||||
|
|
||||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
@ExcelProperty("创建时间")
|
|
||||||
private LocalDateTime createTime;
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
}
|
}
|
@ -1,10 +1,12 @@
|
|||||||
package cn.iocoder.yudao.module.smartfactory.controller.admin.staff.vo;
|
package cn.iocoder.yudao.module.smartfactory.controller.admin.staff.vo;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.common.validation.IdCard;
|
||||||
|
import cn.iocoder.yudao.framework.common.validation.Mobile;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.*;
|
import lombok.Data;
|
||||||
import java.util.*;
|
|
||||||
import javax.validation.constraints.*;
|
import javax.validation.constraints.NotNull;
|
||||||
import java.util.*;
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
@Schema(description = "管理后台 - 员工新增/修改 Request VO")
|
@Schema(description = "管理后台 - 员工新增/修改 Request VO")
|
||||||
@Data
|
@Data
|
||||||
@ -13,9 +15,6 @@ public class StaffSaveReqVO {
|
|||||||
@Schema(description = "主键id", requiredMode = Schema.RequiredMode.REQUIRED, example = "8717")
|
@Schema(description = "主键id", requiredMode = Schema.RequiredMode.REQUIRED, example = "8717")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@Schema(description = "员工编号")
|
|
||||||
private String staffNo;
|
|
||||||
|
|
||||||
@Schema(description = "员工昵称")
|
@Schema(description = "员工昵称")
|
||||||
private String nickName;
|
private String nickName;
|
||||||
|
|
||||||
@ -25,20 +24,26 @@ public class StaffSaveReqVO {
|
|||||||
@Schema(description = "用户性别(0男 1女 2未知)")
|
@Schema(description = "用户性别(0男 1女 2未知)")
|
||||||
private Integer sex;
|
private Integer sex;
|
||||||
|
|
||||||
@Schema(description = "岗位id", example = "28091")
|
|
||||||
private Long postId;
|
|
||||||
|
|
||||||
@Schema(description = "工种id", example = "6971")
|
@Schema(description = "工种id", example = "6971")
|
||||||
private Long workTypeId;
|
private Integer workTypeId;
|
||||||
|
|
||||||
@Schema(description = "工厂id", example = "6971")
|
@Schema(description = "工厂id", example = "6971")
|
||||||
private Long factoryId;
|
private Long factoryId;
|
||||||
|
|
||||||
@Schema(description = "身份证号")
|
@Schema(description = "手机号", requiredMode = Schema.RequiredMode.REQUIRED, example = "15601691300")
|
||||||
|
@NotNull(message = "手机号不能为空")
|
||||||
|
@Mobile
|
||||||
|
private String mobile;
|
||||||
|
|
||||||
|
@Schema(description = "身份证号", requiredMode = Schema.RequiredMode.REQUIRED, example = "15601691300")
|
||||||
|
@NotNull(message = "身份证号不能为空")
|
||||||
|
@IdCard
|
||||||
private String idCard;
|
private String idCard;
|
||||||
|
|
||||||
@Schema(description = "0离职 1在职", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
@Schema(description = "薪资")
|
||||||
@NotNull(message = "0离职 1在职不能为空")
|
private BigDecimal salary;
|
||||||
|
|
||||||
|
@Schema(description = "0离职 1在职 2工伤")
|
||||||
private Integer status;
|
private Integer status;
|
||||||
|
|
||||||
}
|
}
|
@ -1,11 +1,12 @@
|
|||||||
package cn.iocoder.yudao.module.smartfactory.dal.dataobject.staff;
|
package cn.iocoder.yudao.module.smartfactory.dal.dataobject.staff;
|
||||||
|
|
||||||
import lombok.*;
|
|
||||||
import java.util.*;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import com.baomidou.mybatisplus.annotation.*;
|
|
||||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 员工 DO
|
* 员工 DO
|
||||||
@ -13,7 +14,6 @@ import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
|||||||
* @author 艾楷
|
* @author 艾楷
|
||||||
*/
|
*/
|
||||||
@TableName("sf_staff")
|
@TableName("sf_staff")
|
||||||
@KeySequence("sf_staff_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@ToString(callSuper = true)
|
@ToString(callSuper = true)
|
||||||
@ -27,47 +27,52 @@ public class StaffDO extends BaseDO {
|
|||||||
*/
|
*/
|
||||||
@TableId
|
@TableId
|
||||||
private Long id;
|
private Long id;
|
||||||
/**
|
|
||||||
* 员工编号
|
|
||||||
*/
|
|
||||||
private String staffNo;
|
|
||||||
/**
|
/**
|
||||||
* 员工昵称
|
* 员工昵称
|
||||||
*/
|
*/
|
||||||
private String nickName;
|
private String nickName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 年龄
|
* 年龄
|
||||||
*/
|
*/
|
||||||
private Integer age;
|
private Integer age;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户性别(0男 1女 2未知)
|
* 用户性别(0男 1女 2未知)
|
||||||
*/
|
*/
|
||||||
private Integer sex;
|
private Integer sex;
|
||||||
/**
|
|
||||||
* 岗位id
|
|
||||||
*/
|
|
||||||
private Long postId;
|
|
||||||
/**
|
/**
|
||||||
* 工种id
|
* 工种id
|
||||||
*/
|
*/
|
||||||
private Long workTypeId;
|
private Integer workTypeId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 工厂id
|
* 工厂id
|
||||||
*/
|
*/
|
||||||
private Long factoryId;
|
private Long factoryId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 手机号
|
||||||
|
*/
|
||||||
|
private String mobile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 身份证号
|
* 身份证号
|
||||||
*/
|
*/
|
||||||
private String idCard;
|
private String idCard;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 0离职 1在职
|
* 工资
|
||||||
|
*/
|
||||||
|
private BigDecimal salary;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 0离职 1在职 2工伤
|
||||||
*/
|
*/
|
||||||
private Integer status;
|
private Integer status;
|
||||||
|
|
||||||
/**
|
|
||||||
* 岗位名称
|
|
||||||
*/
|
|
||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
private String postName;
|
private String postName;
|
||||||
|
|
||||||
}
|
}
|
@ -20,28 +20,24 @@ public interface StaffMapper extends BaseMapperX<StaffDO> {
|
|||||||
|
|
||||||
default PageResult<StaffDO> selectPage(StaffPageReqVO reqVO) {
|
default PageResult<StaffDO> selectPage(StaffPageReqVO reqVO) {
|
||||||
return selectPage(reqVO, new LambdaQueryWrapperX<StaffDO>()
|
return selectPage(reqVO, new LambdaQueryWrapperX<StaffDO>()
|
||||||
.eqIfPresent(StaffDO::getStaffNo, reqVO.getStaffNo())
|
|
||||||
.eqIfPresent(StaffDO::getAge, reqVO.getAge())
|
.eqIfPresent(StaffDO::getAge, reqVO.getAge())
|
||||||
.eqIfPresent(StaffDO::getPostId, reqVO.getPostId())
|
|
||||||
.eqIfPresent(StaffDO::getWorkTypeId, reqVO.getWorkTypeId())
|
.eqIfPresent(StaffDO::getWorkTypeId, reqVO.getWorkTypeId())
|
||||||
.eqIfPresent(StaffDO::getIdCard, reqVO.getIdCard())
|
|
||||||
.eqIfPresent(StaffDO::getStatus, reqVO.getStatus())
|
.eqIfPresent(StaffDO::getStatus, reqVO.getStatus())
|
||||||
.betweenIfPresent(StaffDO::getCreateTime, reqVO.getCreateTime())
|
|
||||||
.orderByDesc(StaffDO::getId));
|
.orderByDesc(StaffDO::getId));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过工厂id获取员工信息
|
* 通过工厂id获取员工信息
|
||||||
*
|
*
|
||||||
* @param factoryId
|
* @param factoryId 工厂编号
|
||||||
* @return
|
* @return 员工信息列表
|
||||||
*/
|
*/
|
||||||
List<StaffDO> getStaffData(@Param("factoryId") Long factoryId);
|
List<StaffDO> getStaffData(@Param("factoryId") Long factoryId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取员工信息
|
* 获取员工信息
|
||||||
* @param factoryId
|
* @param factoryId 工厂编号
|
||||||
* @return
|
* @return 员工信息列表
|
||||||
*/
|
*/
|
||||||
List<StaffDO> getStaffDataV2(@Param("factoryId") Long factoryId);
|
List<StaffDO> getStaffDataV2(@Param("factoryId") Long factoryId);
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
package cn.iocoder.yudao.module.smartfactory.service.staff;
|
package cn.iocoder.yudao.module.smartfactory.service.staff;
|
||||||
|
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.module.smartfactory.controller.admin.staff.vo.StaffPageReqVO;
|
import cn.iocoder.yudao.module.smartfactory.controller.admin.staff.vo.*;
|
||||||
import cn.iocoder.yudao.module.smartfactory.controller.admin.staff.vo.StaffSaveReqVO;
|
|
||||||
import cn.iocoder.yudao.module.smartfactory.controller.admin.screendata.factory.vo.StaffDataRespVO;
|
import cn.iocoder.yudao.module.smartfactory.controller.admin.screendata.factory.vo.StaffDataRespVO;
|
||||||
import cn.iocoder.yudao.module.smartfactory.dal.dataobject.staff.StaffDO;
|
import cn.iocoder.yudao.module.smartfactory.dal.dataobject.staff.StaffDO;
|
||||||
|
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 员工 Service 接口
|
* 员工 Service 接口
|
||||||
@ -69,8 +70,40 @@ public interface StaffService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询工厂员工信息
|
* 查询工厂员工信息
|
||||||
* @param factoryId
|
* @param factoryId 工厂编号
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
StaffDataRespVO getStaffDataV2(Long factoryId);
|
StaffDataRespVO getStaffDataV2(Long factoryId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导入员工
|
||||||
|
* @param list 导入数据集合
|
||||||
|
* @param updateSupport 是否可更新
|
||||||
|
* @return 导入结果
|
||||||
|
*/
|
||||||
|
StaffImportRespVO importUserList(List<StaffImportExcelVO> list, Boolean updateSupport);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取指定厂区得员工列表
|
||||||
|
*
|
||||||
|
* @param factoryId 工厂编号
|
||||||
|
* @param isIn 是否获取该厂区员工
|
||||||
|
* @return 员工列表
|
||||||
|
*/
|
||||||
|
List<StaffDO> getListByFactory(Long factoryId, Boolean isIn);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取指定厂区得员工列表
|
||||||
|
*
|
||||||
|
* @param factoryIds 工厂编号集合
|
||||||
|
* @return 员工列表
|
||||||
|
*/
|
||||||
|
List<StaffDO> getListByFactoryIds(Collection<Long> factoryIds);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取员工信息列表
|
||||||
|
* @param staffIds 员工编号集合
|
||||||
|
* @return 员工信息列表
|
||||||
|
*/
|
||||||
|
List<StaffDO> getList(Collection<Long> staffIds);
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,35 @@
|
|||||||
package cn.iocoder.yudao.module.smartfactory.service.staff;
|
package cn.iocoder.yudao.module.smartfactory.service.staff;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.iocoder.yudao.framework.common.exception.ServiceException;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||||
|
import cn.iocoder.yudao.framework.common.util.string.DTO.IdCardDO;
|
||||||
|
import cn.iocoder.yudao.framework.common.util.string.StrUtils;
|
||||||
|
import cn.iocoder.yudao.framework.datapermission.core.util.DataPermissionUtils;
|
||||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||||
import cn.iocoder.yudao.module.smartfactory.controller.admin.screendata.factory.vo.StaffDataRespVO;
|
import cn.iocoder.yudao.module.smartfactory.controller.admin.screendata.factory.vo.StaffDataRespVO;
|
||||||
|
import cn.iocoder.yudao.module.smartfactory.controller.admin.staff.vo.StaffImportExcelVO;
|
||||||
|
import cn.iocoder.yudao.module.smartfactory.controller.admin.staff.vo.StaffImportRespVO;
|
||||||
import cn.iocoder.yudao.module.smartfactory.controller.admin.staff.vo.StaffPageReqVO;
|
import cn.iocoder.yudao.module.smartfactory.controller.admin.staff.vo.StaffPageReqVO;
|
||||||
import cn.iocoder.yudao.module.smartfactory.controller.admin.staff.vo.StaffSaveReqVO;
|
import cn.iocoder.yudao.module.smartfactory.controller.admin.staff.vo.StaffSaveReqVO;
|
||||||
import cn.iocoder.yudao.module.smartfactory.dal.dataobject.staff.StaffDO;
|
import cn.iocoder.yudao.module.smartfactory.dal.dataobject.staff.StaffDO;
|
||||||
import cn.iocoder.yudao.module.smartfactory.dal.mysql.staff.StaffMapper;
|
import cn.iocoder.yudao.module.smartfactory.dal.mysql.staff.StaffMapper;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
|
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.USER_IMPORT_LIST_IS_EMPTY;
|
||||||
|
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.USER_USERNAME_EXISTS;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 员工 Service 实现类
|
* 员工 Service 实现类
|
||||||
@ -38,6 +54,7 @@ public class StaffServiceImpl implements StaffService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateStaff(StaffSaveReqVO updateReqVO) {
|
public void updateStaff(StaffSaveReqVO updateReqVO) {
|
||||||
|
validateUserForCreateOrUpdate(updateReqVO.getId(), null, null, null);
|
||||||
// 更新
|
// 更新
|
||||||
StaffDO updateObj = BeanUtils.toBean(updateReqVO, StaffDO.class);
|
StaffDO updateObj = BeanUtils.toBean(updateReqVO, StaffDO.class);
|
||||||
staffMapper.updateById(updateObj);
|
staffMapper.updateById(updateObj);
|
||||||
@ -49,6 +66,22 @@ public class StaffServiceImpl implements StaffService {
|
|||||||
staffMapper.deleteById(id);
|
staffMapper.deleteById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void validateUserForCreateOrUpdate(Long id, String username, String mobile, String idCard) {
|
||||||
|
// 关闭数据权限,避免因为没有数据权限,查询不到数据,进而导致唯一校验不正确
|
||||||
|
DataPermissionUtils.executeIgnore(() -> {
|
||||||
|
|
||||||
|
// 校验用户名、身份证号是否已经存在
|
||||||
|
Long cunt = staffMapper.selectCount(new LambdaQueryWrapperX<StaffDO>()
|
||||||
|
.eqIfPresent(StaffDO::getId, id)
|
||||||
|
.eqIfPresent(StaffDO::getNickName, username)
|
||||||
|
.eqIfPresent(StaffDO::getIdCard, idCard)
|
||||||
|
.eqIfPresent(StaffDO::getMobile, mobile));
|
||||||
|
if (cunt > 0) {
|
||||||
|
throw exception(USER_USERNAME_EXISTS);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StaffDO getStaff(Long id) {
|
public StaffDO getStaff(Long id) {
|
||||||
return staffMapper.selectById(id);
|
return staffMapper.selectById(id);
|
||||||
@ -86,4 +119,90 @@ public class StaffServiceImpl implements StaffService {
|
|||||||
return vo;
|
return vo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class) // 添加事务,异常则回滚所有导入
|
||||||
|
public StaffImportRespVO importUserList(List<StaffImportExcelVO> importUsers, Boolean updateSupport) {
|
||||||
|
if (CollUtil.isEmpty(importUsers)) {
|
||||||
|
throw exception(USER_IMPORT_LIST_IS_EMPTY);
|
||||||
|
}
|
||||||
|
StaffImportRespVO respVO = StaffImportRespVO.builder()
|
||||||
|
.createUsernames(new ArrayList<>())
|
||||||
|
.updateUsernames(new ArrayList<>())
|
||||||
|
.failureUsernames(new HashMap<>()).build();
|
||||||
|
|
||||||
|
importUsers.forEach(importUser -> {
|
||||||
|
if (importUser.getNickName() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//校验,判断是否有不符合的原因
|
||||||
|
try {
|
||||||
|
if (!updateSupport) {
|
||||||
|
validateUserForCreateOrUpdate(null, importUser.getNickName(), null, importUser.getIdCard());
|
||||||
|
}
|
||||||
|
} catch (ServiceException ex) {
|
||||||
|
respVO.getFailureUsernames().put(importUser.getNickName(), ex.getMessage());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
StaffDO updateUser = BeanUtils.toBean(importUser, StaffDO.class);
|
||||||
|
|
||||||
|
//解析身份证号码
|
||||||
|
IdCardDO idCardDO = StrUtils.IdCardAnalysis(updateUser.getIdCard());
|
||||||
|
|
||||||
|
//设置 性别、年龄
|
||||||
|
updateUser.setSex(idCardDO.getSex());
|
||||||
|
updateUser.setAge(idCardDO.getAge());
|
||||||
|
|
||||||
|
//设置部门ID
|
||||||
|
if (StrUtil.isNotEmpty(importUser.getFactoryName())) {
|
||||||
|
|
||||||
|
//excel接受到工厂名称格式为 id:name
|
||||||
|
updateUser.setFactoryId(Long.valueOf(importUser.getFactoryName().split(":")[0]));
|
||||||
|
}
|
||||||
|
|
||||||
|
//设置岗位ID
|
||||||
|
if (StrUtil.isNotEmpty(importUser.getWorkTypeName())) {
|
||||||
|
|
||||||
|
//excel接受到工种名称格式为 id:name
|
||||||
|
updateUser.setWorkTypeId(Integer.valueOf(importUser.getWorkTypeName().split(":")[0]));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 判断如果不存在,在进行插入
|
||||||
|
if (updateSupport) {
|
||||||
|
StaffDO staffDO = staffMapper.selectOne(new LambdaQueryWrapperX<StaffDO>()
|
||||||
|
.eq(StaffDO::getIdCard, importUser.getIdCard())
|
||||||
|
.eq(StaffDO::getNickName, importUser.getNickName()));
|
||||||
|
|
||||||
|
updateUser.setId(staffDO.getId());
|
||||||
|
staffMapper.updateById(updateUser);
|
||||||
|
respVO.getUpdateUsernames().add(importUser.getNickName());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 插入用户
|
||||||
|
staffMapper.insert(updateUser);
|
||||||
|
respVO.getCreateUsernames().add(importUser.getNickName());
|
||||||
|
});
|
||||||
|
|
||||||
|
return respVO;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<StaffDO> getListByFactory(Long factoryId, Boolean isIn) {
|
||||||
|
return staffMapper.selectList(new LambdaQueryWrapperX<StaffDO>()
|
||||||
|
.eq(isIn, StaffDO::getFactoryId, factoryId)
|
||||||
|
.ne(!isIn, StaffDO::getFactoryId, factoryId)
|
||||||
|
.ne(StaffDO::getStatus, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<StaffDO> getListByFactoryIds(Collection<Long> factoryIds) {
|
||||||
|
|
||||||
|
return staffMapper.selectList(StaffDO::getFactoryId, factoryIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<StaffDO> getList(Collection<Long> staffIds) {
|
||||||
|
return staffMapper.selectList(StaffDO::getId, staffIds);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,10 +12,12 @@
|
|||||||
<select id="getStaffData" resultType="cn.iocoder.yudao.module.smartfactory.dal.dataobject.staff.StaffDO">
|
<select id="getStaffData" resultType="cn.iocoder.yudao.module.smartfactory.dal.dataobject.staff.StaffDO">
|
||||||
select
|
select
|
||||||
a.*,
|
a.*,
|
||||||
ifnull( t3.NAME, t2.post_name ) AS postName
|
t3.label AS postName
|
||||||
from sf_staff as a
|
from sf_staff as a
|
||||||
LEFT JOIN sf_post t2 ON a.post_id = t2.id
|
LEFT JOIN system_dict_data t3 ON
|
||||||
LEFT JOIN sf_work_type t3 ON a.work_type_id = t3.id
|
t3.dict_type = 'user_work_type'
|
||||||
|
AND a.work_type_id = t3.value
|
||||||
|
AND t3.deleted = 0
|
||||||
<where>
|
<where>
|
||||||
a.status = 1
|
a.status = 1
|
||||||
and a.deleted = 0
|
and a.deleted = 0
|
||||||
|
Loading…
Reference in New Issue
Block a user