mybatis-plus
parent
e9855f0968
commit
a7b31a3667
|
@ -31,6 +31,7 @@ public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<SysConfig> pageQuery (SysConfig config) {
|
public List<SysConfig> pageQuery (SysConfig config) {
|
||||||
|
|
||||||
LambdaQueryWrapper<SysConfig> queryWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<SysConfig> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
if (StringUtils.isNotEmpty(config.getConfigName())){
|
if (StringUtils.isNotEmpty(config.getConfigName())){
|
||||||
queryWrapper.like(SysConfig::getConfigName, config.getConfigName());
|
queryWrapper.like(SysConfig::getConfigName, config.getConfigName());
|
||||||
|
@ -41,6 +42,8 @@ public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig
|
||||||
if (StringUtils.isNotEmpty(config.getConfigKey())){
|
if (StringUtils.isNotEmpty(config.getConfigKey())){
|
||||||
queryWrapper.like(SysConfig::getConfigKey, config.getConfigKey());
|
queryWrapper.like(SysConfig::getConfigKey, config.getConfigKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Object beginTime = config.getParams().get("beginTime");
|
Object beginTime = config.getParams().get("beginTime");
|
||||||
if (Objects.nonNull(beginTime) && beginTime instanceof Date beginDate){
|
if (Objects.nonNull(beginTime) && beginTime instanceof Date beginDate){
|
||||||
queryWrapper.gt(SysConfig::getCreateTime, beginDate);
|
queryWrapper.gt(SysConfig::getCreateTime, beginDate);
|
||||||
|
@ -49,6 +52,8 @@ public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig
|
||||||
if (Objects.nonNull(endTime) && endTime instanceof Date endDate){
|
if (Objects.nonNull(endTime) && endTime instanceof Date endDate){
|
||||||
queryWrapper.lt(SysConfig::getCreateTime, endDate);
|
queryWrapper.lt(SysConfig::getCreateTime, endDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return this.list(queryWrapper);
|
return this.list(queryWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
package com.muyu.test.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@TableName("t_employee")//映射数据库员工表
|
||||||
|
public class Employee extends Section{
|
||||||
|
//识别为
|
||||||
|
@TableId(type = IdType.AUTO)
|
||||||
|
private Integer empId;//id
|
||||||
|
|
||||||
|
private String empName;//姓名
|
||||||
|
private Integer empAge;//年龄
|
||||||
|
private Integer empSex;//性别
|
||||||
|
private String empImage;//图片
|
||||||
|
private String dictLabel;//性别
|
||||||
|
private String empRich;//富文本
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
private Date empDate;//入职日期
|
||||||
|
private Integer empSectionId;//部门id
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.muyu.test.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@TableName("t_section")
|
||||||
|
public class Section{
|
||||||
|
private Integer sectionId;
|
||||||
|
private String sectionName;
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
package com.muyu.test.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import javax.validation.constraints.Size;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ReqConditions {
|
||||||
|
private Integer pageNum=1;
|
||||||
|
private Integer pageSize=3;
|
||||||
|
private String empName;//员工名称查询
|
||||||
|
|
||||||
|
private Integer empSectionId;//部门id查询
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
package com.muyu.test.vo;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class VoEmployee {
|
||||||
|
private String empName;//姓名
|
||||||
|
private Integer empAge;//年龄
|
||||||
|
private String empImage;//图片
|
||||||
|
private String empRich;//富文本
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
private Date empDate;//入职日期
|
||||||
|
private Integer empSectionId;//部门id
|
||||||
|
}
|
|
@ -3,6 +3,7 @@ package com.muyu;
|
||||||
import com.muyu.common.security.annotation.EnableCustomConfig;
|
import com.muyu.common.security.annotation.EnableCustomConfig;
|
||||||
import com.muyu.common.security.annotation.EnableMyFeignClients;
|
import com.muyu.common.security.annotation.EnableMyFeignClients;
|
||||||
import com.muyu.common.swagger.annotation.EnableCustomSwagger2;
|
import com.muyu.common.swagger.annotation.EnableCustomSwagger2;
|
||||||
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
|
@ -10,6 +11,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
@EnableCustomSwagger2
|
@EnableCustomSwagger2
|
||||||
@EnableMyFeignClients
|
@EnableMyFeignClients
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
|
@MapperScan("com.muyu.test.mapper")
|
||||||
public class MuYuTestApplication {
|
public class MuYuTestApplication {
|
||||||
public static void main (String[] args) {
|
public static void main (String[] args) {
|
||||||
SpringApplication.run(MuYuTestApplication.class, args);
|
SpringApplication.run(MuYuTestApplication.class, args);
|
||||||
|
|
|
@ -0,0 +1,66 @@
|
||||||
|
package com.muyu.test.controller;
|
||||||
|
|
||||||
|
import com.muyu.common.core.domain.Result;
|
||||||
|
import com.muyu.common.core.web.controller.BaseController;
|
||||||
|
import com.muyu.common.security.annotation.RequiresPermissions;
|
||||||
|
import com.muyu.test.domain.Employee;
|
||||||
|
import com.muyu.test.service.EmployeeService;
|
||||||
|
import com.muyu.test.vo.ReqConditions;
|
||||||
|
import com.muyu.test.vo.VoEmployee;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/employee")
|
||||||
|
|
||||||
|
public class EmployeeController extends BaseController {
|
||||||
|
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private EmployeeService employeeMapper;
|
||||||
|
|
||||||
|
@PostMapping("/selectEmployeeConditions")
|
||||||
|
public Result selectEmployeeConditions(@RequestBody ReqConditions reqConditions) {//多条件查询
|
||||||
|
startPage();
|
||||||
|
List<Employee> list=employeeMapper.selectEmployeeConditions(reqConditions);
|
||||||
|
return Result.success(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
//查所有员工双表联查
|
||||||
|
@PostMapping("/selectAllEmployee")
|
||||||
|
public Result selectAllEmployee() {
|
||||||
|
List<Employee> list=employeeMapper.selectAllEmployee();
|
||||||
|
return Result.success(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping("/insertEmployee")
|
||||||
|
public Result insertEmployee(@RequestBody Employee employee) {
|
||||||
|
Integer i=employeeMapper.insertEmployee(employee);
|
||||||
|
return Result.success(i,i>0?"添加成功":"添加失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping("/updateEmployee")
|
||||||
|
|
||||||
|
public Result updateEmployee(@RequestBody Employee employee) {
|
||||||
|
Integer i=employeeMapper.updateEmployee(employee);
|
||||||
|
return Result.success(i,i>0?"修改成功":"修改失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping("/deleteEmployee/{empId}")
|
||||||
|
public Result deleteEmployee(@PathVariable Integer empId) {
|
||||||
|
Integer i=employeeMapper.deleteEmployee(empId);
|
||||||
|
return Result.success(i,i>0?"删除成功":"删除失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
package com.muyu.test.mapper;
|
||||||
|
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.muyu.test.domain.Employee;
|
||||||
|
import com.muyu.test.vo.ReqConditions;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface EmployeeMapper extends BaseMapper<Employee> {
|
||||||
|
@Select("select * from t_employee left join t_section on t_employee.emp_section_id=t_section.section_id")
|
||||||
|
List<Employee> selectAllEmployee();
|
||||||
|
|
||||||
|
|
||||||
|
List<Employee> selectEmployeeConditions(ReqConditions reqConditions);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
package com.muyu.test.service;
|
||||||
|
|
||||||
|
import com.muyu.test.domain.Employee;
|
||||||
|
import com.muyu.test.domain.Section;
|
||||||
|
import com.muyu.test.vo.ReqConditions;
|
||||||
|
import com.muyu.test.vo.VoEmployee;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface EmployeeService {
|
||||||
|
|
||||||
|
|
||||||
|
List<Employee> selectAllEmployee();
|
||||||
|
|
||||||
|
|
||||||
|
Integer insertEmployee(Employee employee);
|
||||||
|
|
||||||
|
|
||||||
|
Integer updateEmployee(Employee employee);
|
||||||
|
|
||||||
|
|
||||||
|
Integer deleteEmployee(Integer empId);
|
||||||
|
|
||||||
|
|
||||||
|
List<Employee> selectEmployeeConditions(ReqConditions reqConditions);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,52 @@
|
||||||
|
package com.muyu.test.service.impl;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.muyu.common.core.utils.StringUtils;
|
||||||
|
import com.muyu.test.domain.Employee;
|
||||||
|
import com.muyu.test.mapper.EmployeeMapper;
|
||||||
|
import com.muyu.test.service.EmployeeService;
|
||||||
|
import com.muyu.test.vo.ReqConditions;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class EmployeeServiceImpl extends ServiceImpl<EmployeeMapper, Employee> implements EmployeeService
|
||||||
|
{
|
||||||
|
@Autowired
|
||||||
|
private EmployeeMapper employeeMapper;
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Employee> selectAllEmployee() {
|
||||||
|
List<Employee> list=employeeMapper.selectAllEmployee();
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer insertEmployee(Employee employee) {
|
||||||
|
return employeeMapper.insert(employee);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer updateEmployee(Employee employee) {
|
||||||
|
return employeeMapper.updateById(employee);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer deleteEmployee(Integer empId) {
|
||||||
|
return employeeMapper.deleteById(empId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Employee> selectEmployeeConditions(ReqConditions reqConditions) {
|
||||||
|
return employeeMapper.selectEmployeeConditions(reqConditions);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -25,4 +25,4 @@ spring:
|
||||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||||
logging:
|
logging:
|
||||||
level:
|
level:
|
||||||
com.muyu.system.mapper: DEBUG
|
com.muyu.test.mapper: DEBUG
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
<?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.muyu.test.mapper.EmployeeMapper">
|
||||||
|
|
||||||
|
|
||||||
|
<resultMap type="com.muyu.test.domain.Employee" id="EmployeeResult">
|
||||||
|
<id property="empId" column="emp_id"/>
|
||||||
|
<result property="empName" column="emp_name"/>
|
||||||
|
<result property="empAge" column="emp_age"/>
|
||||||
|
<result property="empImage" column="emp_image"/>
|
||||||
|
<result property="empRich" column="emp_rich"/>
|
||||||
|
<result property="empDate" column="emp_date"/>
|
||||||
|
<result property="empSex" column="emp_sex"/>
|
||||||
|
<result property="empSectionId" column="emp_section_id"/>
|
||||||
|
<result property="sectionId" column="section_id"/>
|
||||||
|
<result property="sectionName" column="section_name"/>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<sql id="selectEmployeeVo">
|
||||||
|
SELECT DISTINCT emp_id, emp_name, emp_age, emp_image, emp_rich, emp_date, emp_section_id, section_name, sdd.dict_label
|
||||||
|
FROM t_employee
|
||||||
|
INNER JOIN t_section ON t_employee.emp_section_id = t_section.section_id
|
||||||
|
INNER JOIN sys_dict_data sdd ON sdd.dict_type = 'sys_user_sex'
|
||||||
|
AND sdd.dict_value = t_employee.emp_sex
|
||||||
|
</sql>
|
||||||
|
|
||||||
|
<select id="selectEmployeeConditions" resultType="com.muyu.test.domain.Employee" resultMap="EmployeeResult">
|
||||||
|
<include refid="selectEmployeeVo"/>
|
||||||
|
|
||||||
|
<where>
|
||||||
|
<if test="empName != null and empName != ''">
|
||||||
|
AND emp_name like concat('%', #{empName,jdbcType=VARCHAR}, '%')
|
||||||
|
</if>
|
||||||
|
<if test="empSectionId != null and empSectionId != 0">
|
||||||
|
AND emp_section_id = #{empSectionId,jdbcType=INTEGER}
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
|
||||||
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</mapper>
|
Loading…
Reference in New Issue