1、员工管理准备工作
分页插件配置类
@Configuration
public class MybatisPlusConfig {
@Bean
public PaginationInterceptor paginationInterceptor(){
return new PaginationInterceptor();
}
}
分页公共响应类
@Data
@NoArgsConstructor
@AllArgsConstructor
public class RespPageBean {
private Long total;
private List<?> data;
}
全局日期转换类
@Component
public class DateConverter implements Converter<String, LocalDate> {
@Override
public LocalDate convert(String s) {
try {
return LocalDate.parse(s, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
员工类
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("t_employee")
@ApiModel(value = "Employee对象", description = "")
public class Employee implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "员工编号")
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
@ApiModelProperty(value = "员工姓名")
private String name;
@ApiModelProperty(value = "性别")
private String gender;
@ApiModelProperty(value = "出生日期")
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "Asia/shanghai")
private LocalDate birthday;
@ApiModelProperty(value = "身份证号")
private String idCard;
@ApiModelProperty(value = "婚姻状况")
private String wedlock;
@ApiModelProperty(value = "民族")
private Integer nationId;
@ApiModelProperty(value = "籍贯")
private String nativePlace;
@ApiModelProperty(value = "政治面貌")
private Integer politicId;
@ApiModelProperty(value = "邮箱")
private String email;
@ApiModelProperty(value = "电话号码")
private String phone;
@ApiModelProperty(value = "联系地址")
private String address;
@ApiModelProperty(value = "所属部门")
private Integer departmentId;
@ApiModelProperty(value = "职称ID")
private Integer jobLevelId;
@ApiModelProperty(value = "职位ID")
private Integer posId;
@ApiModelProperty(value = "聘用形式")
private String engageForm;
@ApiModelProperty(value = "最高学历")
private String tiptopDegree;
@ApiModelProperty(value = "所属专业")
private String specialty;
@ApiModelProperty(value = "毕业院校")
private String school;
@ApiModelProperty(value = "入职日期")
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "Asia/shanghai")
private LocalDate beginDate;
@ApiModelProperty(value = "在职状态")
private String workState;
@ApiModelProperty(value = "工号")
private String workID;
@ApiModelProperty(value = "合同期限")
private Double contractTerm;
@ApiModelProperty(value = "转正日期")
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "Asia/shanghai")
private LocalDate conversionTime;
@ApiModelProperty(value = "离职日期")
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "Asia/shanghai")
private LocalDate notWorkDate;
@ApiModelProperty(value = "合同起始日期")
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "Asia/shanghai")
private LocalDate beginContract;
@ApiModelProperty(value = "合同终止日期")
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "Asia/shanghai")
private LocalDate endContract;
@ApiModelProperty(value = "工龄")
private Integer workAge;
@ApiModelProperty(value = "工资账套ID")
private Integer salaryId;
@ApiModelProperty(value = "民族")
@TableField(exist = false)
private Nation nation;
@ApiModelProperty(value = "政治面貌")
@TableField(exist = false)
private PoliticsStatus politicsStatus;
@ApiModelProperty(value = "部门")
@TableField(exist = false)
private Department department;
@ApiModelProperty(value = "职称")
@TableField(exist = false)
private Joblevel joblevel;
@ApiModelProperty(value = "职位")
@TableField(exist = false)
private Position position;
}
2、获取所有员工分页查询
EmployeeController
@RestController
@RequestMapping("/employee/basic")
public class EmployeeController {
@Resource
private IEmployeeEcService employeeEcService;
@ApiOperation(value = "获取所有员工(分页)")
@GetMapping("/")
public RespPageBean getEmployeePage(@RequestParam(defaultValue = "1") Integer currentPage,
@RequestParam(defaultValue = "10") Integer size,
Employee employee,
LocalDate[] beginDateScope) {
return employeeEcService.getEmployeePage(currentPage, size, employee, beginDateScope);
}
}
IEmployeeEcService
public interface IEmployeeEcService extends IService<EmployeeEc> {
RespPageBean getEmployeePage(Integer currentPage, Integer size, Employee employee, LocalDate[] beginDateScope);
}
EmployeeEcServiceImpl
@Service
public class EmployeeEcServiceImpl extends ServiceImpl<EmployeeEcMapper, EmployeeEc> implements IEmployeeEcService {
@Resource
private EmployeeMapper employeeMapper;
@Override
public RespPageBean getEmployeePage(Integer currentPage, Integer size, Employee employee, LocalDate[] beginDateScope) {
Page<Employee> page = new Page<>(currentPage, size);
IPage<Employee> employeeIPage = employeeMapper.getEmployeePage(page, employee, beginDateScope);
RespPageBean respPageBean = new RespPageBean(employeeIPage.getTotal(), employeeIPage.getRecords());
return respPageBean;
}
}
EmployeeMapper
public interface EmployeeMapper extends BaseMapper<Employee> {
IPage<Employee> getEmployeePage(Page<Employee> employeePage,
@Param("employee") Employee employee,
@Param("beginDateScope") LocalDate[] beginDateScope);
}
EmployeeMapper.xml
<?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="com.xxxx.server.mapper.EmployeeMapper">
<resultMap id="BaseResultMap" type="com.xxxx.server.pojo.Employee">
<id column="id" property="id"/>
<result column="name" property="name"/>
<result column="gender" property="gender"/>
<result column="birthday" property="birthday"/>
<result column="idCard" property="idCard"/>
<result column="wedlock" property="wedlock"/>
<result column="nationId" property="nationId"/>
<result column="nativePlace" property="nativePlace"/>
<result column="politicId" property="politicId"/>
<result column="email" property="email"/>
<result column="phone" property="phone"/>
<result column="address" property="address"/>
<result column="departmentId" property="departmentId"/>
<result column="jobLevelId" property="jobLevelId"/>
<result column="posId" property="posId"/>
<result column="engageForm" property="engageForm"/>
<result column="tiptopDegree" property="tiptopDegree"/>
<result column="specialty" property="specialty"/>
<result column="school" property="school"/>
<result column="beginDate" property="beginDate"/>
<result column="workState" property="workState"/>
<result column="workID" property="workID"/>
<result column="contractTerm" property="contractTerm"/>
<result column="conversionTime" property="conversionTime"/>
<result column="notWorkDate" property="notWorkDate"/>
<result column="beginContract" property="beginContract"/>
<result column="endContract" property="endContract"/>
<result column="workAge" property="workAge"/>
<result column="salaryId" property="salaryId"/>
</resultMap>
<resultMap id="EmployeeInfo" type="com.xxxx.server.pojo.Employee" extends="BaseResultMap">
<association property="nation" javaType="com.xxxx.server.pojo.Nation">
<id column="nid" property="id"/>
<result column="nname" property="name"/>
</association>
<association property="politicsStatus" javaType="com.xxxx.server.pojo.PoliticsStatus">
<id column="pid" property="id"/>
<result column="pname" property="name"/>
</association>
<association property="departmentId" javaType="com.xxxx.server.pojo.Department">
<id column="did" property="id"/>
<result column="dname" property="name"/>
</association>
<association property="joblevel" javaType="com.xxxx.server.pojo.Joblevel">
<id column="jid" property="id"/>
<result column="jname" property="name"/>
</association>
<association property="position" javaType="com.xxxx.server.pojo.Position">
<id column="poid" property="id"/>
<result column="poname" property="name"/>
</association>
</resultMap>
<sql id="Base_Column_List">
id, name, gender, birthday, idCard, wedlock, nationId, nativePlace, politicId, email, phone, address, departmentId, jobLevelId, posId, engageForm, tiptopDegree, specialty, school, beginDate, workState, workID, contractTerm, conversionTime, notWorkDate, beginContract, endContract, workAge, salaryId
</sql>
<select id="getEmployeePage" resultMap="EmployeeInfo">
SELECT
e.*,
n.id AS nid,
n.`name` AS nname,
p.id AS pid,
p.`name` AS pname,
d.id AS did,
d.`name` AS dname,
j.id AS jid,
j.`name` AS jname,
po.id AS posid,
po.`name` AS posname
FROM
t_employee e,
t_nation n,
t_politics_status p,
t_department d,
t_joblevel j,
t_position po
WHERE
e.nationId = n.id
AND e.politicId = p.id
AND e.departmentId = d.id
AND e.jobLevelId = j.id
AND e.posId = po.id
<if test="null!=employee.name and ''!=employee.name">
AND e.`name` LIKE CONCAT( '%', #{employee.name}, '%' )
</if>
<if test="null!=employee.politicId">
AND e.politicId =#{employee.politicId}
</if>
<if test="null!=employee.nationId">
AND e.nationId =#{employee.nationId}
</if>
<if test="null!=employee.jobLevelId">
AND e.jobLevelId =#{employee.jobLevelId}
</if>
<if test="null!=employee.posId">
AND e.posId =#{employee.posId}
</if>
<if test="null!=employee.engageForm and ''!=employee.engageForm">
AND e.engageForm =#{employee.engageForm}
</if>
<if test="null!=employee.departmentId">
AND e.departmentId =#{employee.departmentId}
</if>
<if test="null!=beginDateScope and 2==beginDateScope.length">
AND e.beginDate BETWEEN beginDateScope[0] AND beginDateScope[1]
</if>
ORDER BY
e.id
</select>
</mapper>
|