import com.baomidou.mybatisplus.exension.plugins.pagination.Page;
@Data
public class TrainEntityDto {
@Schema(description = "id")
private Long id;
@Schema(description = "客户(租户)id")
private Long customerId;
@Schema(description = "客户(租户)名称")
private String customerName;
@Schema(description = "培训方式(线下0,线上1)")
private Boolean trainMode;
@Schema(description = "培训时间")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date trainTime;
@Schema(description = "培训地址")
private String trainAddress;
@Schema(description = "培训目的")
private String trainPurpose;
@Schema(description = "开始培训时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date startTrainTime;
@Schema(description = "结束培训时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date endTrainTime;
@Schema(description = "培训结果")
private String trainResult;
@Schema(description = "状态(待审核0,待培训1,培训中2,完成3,取消4)")
private Integer state;
@Schema(description = "取消原因")
private String cancelReason;
@Schema(description = "备注")
private String remark;
@Schema(description = "参与培训的人员")
private List<Trainer> trainers;
}
@Data
public class Trainer {
@Schema(description = "培训人id")
private Long trainerId;
@Schema(description = "培训人名称")
private String trainerName;
}
@Tag(name = "客户培训相关")
@RestController
@RequestMapping("/train")
@Slf4j
public class TrainController {
@Autowired
private TrainService trainService;
@GetMapping("/getTrainList")
@Operation(summary = "获取培训列表")
@Parameters({
@Parameter(name = "current", description = "当前页"),
@Parameter(name = "size", description = "页面大小"),
@Parameter(name = "customerName", description = "培训客户名称"),
@Parameter(name = "start", description = "查询开始时间"),
@Parameter(name = "end", description = "查询结束时间"),
@Parameter(name = "state", description = "状态")})
public R<Page<TrainEntityDto>> getTrainList(@RequestParam Integer current,
@RequestParam Integer size,
@RequestParam(required = false) String customerName,
@RequestParam(required = false) @JsonFormat(pattern = "yyyy-MM-dd") LocalDate start,
@RequestParam(required = false) @JsonFormat(pattern = "yyyy-MM-dd") LocalDate end,
@RequestParam Integer state) {
return R.ok(trainService.getTrainList(current, size, customerName, start, end, state));
}
}
public interface TrainService extends IService<TrainEntity> {
Page<TrainEntityDto> getTrainList(Integer current, Integer size, String customerName, LocalDate start, LocalDate end, Integer state);
}
@Slf4j
@Service
public class TrainServiceImpl extends ServiceImpl<TrainMapper, TrainEntity> implements TrainService {
@Autowired
private TrainMapper trainMapper;
@Override
public Page<TrainEntityDto> getTrainList(Integer current, Integer size, String customerName, LocalDate start, LocalDate end , Integer state) {
Page<TrainEntityDto> page = new Page<>(current,size);
Integer currentSize = (current - 1)*size;
List<TrainEntityDto> trainEntities = trainMapper.selectTrains(currentSize,size,customerName,start,end,state);
Integer total = trainMapper.getTotal(currentSize,size,customerName, start, end, state);
page.setRecords(trainEntities);
page.setTotal(total);
return page;
}
}
@Mapper
public interface TrainMapper extends BaseMapper<TrainEntity> {
List<TrainEntityDto> selectTrains(@Param("currentSize") Integer currentSize, @Param("size") Integer size, @Param("customerName") String customerName, @Param("start") LocalDate start, @Param("end") LocalDate end, @Param("state") Integer state);
Integer getTotal(@Param("currentSize") Integer currentSize, @Param("size") Integer size, @Param("customerName") String customerName, @Param("start") LocalDate start, @Param("end") LocalDate end, @Param("state") Integer state);
}
<?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.perfectlinks.applink.operation.mapper.TrainMapper">
<resultMap id="map" type="com.perfectlinks.applink.operation.train.TrainEntityDto">
<id property="id" column="id"/>
<result property="customerId" column="customer_id"/>
<result property="customerName" column="customer_name"/>
<result property="trainMode" column="train_mode"/>
<result property="trainTime" column="train_time"/>
<result property="trainAddress" column="train_address"/>
<result property="trainPurpose" column="train_purpose"/>
<result property="startTrainTime" column="start_train_time"/>
<result property="endTrainTime" column="end_train_time"/>
<result property="trainResult" column="train_result"/>
<result property="state" column="state"/>
<result property="cancelReason" column="cancel_reason"/>
<result property="remark" column="remark"/>
<collection property="trainers" ofType="com.perfectlinks.applink.operation.train.Trainer">
<result property="trainerId" column="trainer_id"/>
<result property="trainerName" column="trainer_name"/>
</collection>
</resultMap>
<select id="selectTrains" resultMap="map">
SELECT
ct.id,
ct.customer_id,
ct.customer_name,
ct.train_mode,
ct.train_time,
ct.train_address,
ct.train_purpose,
ct.start_train_time,
ct.end_train_time,
ct.train_result,
ct.state,
ct.cancel_reason,
ct.remark,
ctr.trainer_id,
ctr.trainer_name
FROM
(SELECT
id,
customer_id,
customer_name,
train_mode,
train_time,
train_address,
train_purpose,
start_train_time,
end_train_time,
train_result,
state,
cancel_reason,
remark
FROM
customer_train
where state = #{state}
<if test="customerName != null and customerName != ''">
and customer_name like CONCAT('%', #{customerName},'%')
</if>
<if test="start != null">
AND train_time >= date_format(#{start},'%Y-%c-%d 00:00:00')
</if>
<if test="end != null">
AND train_time <= date_format(#{end},'%Y-%c-%d 23:59:59')
</if>
ORDER BY train_time ASC
LIMIT #{currentSize},#{size}
) ct
LEFT JOIN customer_train_relation ctr
ON ct.id = ctr.train_id
</select>
<select id="getTotal" resultType="java.lang.Integer">
SELECT
count(0)
FROM
customer_train
where state = #{state}
<if test="customerName != null and customerName != ''">
and customer_name like CONCAT('%', #{customerName},'%')
</if>
<if test="start != null">
AND train_time >= date_format(#{start},'%Y-%c-%d 00:00:00')
</if>
<if test="end != null">
AND train_time <= date_format(#{end},'%Y-%c-%d 23:59:59')
</if>
ORDER BY train_time ASC
</select>
</mapper>