时隔多年又用到这样的查询方式了,提前声明一下分页最后返回的数据会小于每页条数,废话不多说直接上代码!
@Data
public class PbcUserTargetTaskPageVO {
@ApiModelProperty("个人绩效指标id")
private Long id;
@ApiModelProperty("月份")
private String month;
@ApiModelProperty("工号")
private String employeeNo;
@ApiModelProperty("姓名")
private String employeeName;
@ApiModelProperty("月份")
private String oraName;
@ApiModelProperty(value = "目标")
private BigDecimal goal;
@ApiModelProperty(value = "绩效指标")
private String targetName;
@ApiModelProperty(value = "个人绩效指标关键任务")
private List<PbcKeyTaskVO> taskList;
}
@Data
public class PbcKeyTaskVO {
@ApiModelProperty(value = "主键id")
private Long id;
@ApiModelProperty(value = "任务编码")
private String code;
@ApiModelProperty(value = "任务名称")
private String name;
@ApiModelProperty(value = "任务类型")
private String type;
@ApiModelProperty(value = "任务描述")
private String detail;
@ApiModelProperty(value = "创建人工号")
private String createBy;
@ApiModelProperty(value = "创建人名字")
private String createName;
@ApiModelProperty(value = "创建时间")
private String createTime;
@ApiModelProperty(value = "是否关联绩效指标任务 Y=已关联,N=未关联")
private String isRelated;
}
public interface PbcUserTargetTaskMapper extends BaseMapper<PbcUserTargetTask> {
Page<PbcUserTargetTaskPageVO> pageList(Page page, PbcUserTargetTaskPageRequest dto);
}
<!-- 通用查询映射结果 -->
<resultMap id="PageResultMap" type="com.shinho.plrs.manager.pojo.vo.PbcUserTargetTaskPageVO">
<id column="user_target_id" property="id" />
<result column="month" property="month" />
<result column="employee_no" property="employeeNo" />
<result column="employee_name" property="employeeName" />
<result column="oraName" property="oraName" />
<result column="goal" property="goal" />
<result column="targetName" property="targetName" />
<!-- 配置一对多关联 -->
<collection property="taskList" ofType="com.shinho.plrs.manager.pojo.vo.PbcKeyTaskVO">
<id property="id" column="task_id"/>
<result property="code" column="task_code"/>
<result property="name" column="task_name"/>
<result property="type" column="task_type"/>
<result property="detail" column="task_detail"/>
<result property="createTime" column="task_create_time"/>
</collection>
</resultMap>
<select id="pageList" resultMap="PageResultMap">
SELECT
a.id AS user_target_id,
a.`user_number` AS employee_no,
a.`name` AS employee_name,
a.`position` AS position,
d.ora_name AS oraName,
a.`target_code`,
e.`name` AS targetName,
a.`goal`,
a.`version_date` AS `month`,
b.task_id,
c.`code` AS task_code,
c.`name` AS task_name,
c.type AS task_type,
c.detail AS task_detail,
c.create_time AS task_create_time
FROM
user_target_result a
LEFT JOIN pbc_user_target_task b ON a.version_date=b.`month` AND a.user_number=b.employee_no AND a.target_code=b.target_code
LEFT JOIN pbc_key_task c ON b.task_id=c.id
LEFT JOIN assess_base_snapshot d ON a.version_date=d.`month` AND a.user_number=d.employee_no AND a.position=d.assess_position_name
LEFT JOIN plrs_target e ON a.target_code=e.`code`
WHERE
a.version_date = '2024-07'
AND a.user_number = '21120060'
AND ( d.ora_id = '01003403' OR locate('01003403',d.ora_parent_group ) > 0)
ORDER BY a.user_number DESC
</select>
这里就知道了,一页10条,但是返回后有一条数据1v2,所以变成了9,前端页面会看起来很怪就会有问题,这是只有一个,如果一对10那一页就只返回了一条数据。这种查询不适合用于分页查询!