优化sql

This commit is contained in:
think 2025-01-24 12:14:37 +08:00
parent 26f379916e
commit 806ae14a9a

View File

@ -42,13 +42,17 @@ public interface TaskDispatchDetailMapper extends BaseMapperX<TaskDispatchDetail
query.select( "DATE_FORMAT(t.create_time, '%Y-%m') as yearMonth,\n" +
" t.owner," +
" t.device_model," +
" max(c.name) as manufacturingEquipment," +
" CASE " +
" WHEN t.device_model IS NULL THEN '' " +
" ELSE (select c.name from base_equip_manufacture c where c.id = t.device_model) " +
" END AS manufacturingEquipment," +
" sum(t.work_time) as totalPlannedHours," +
" sum(b.work_time) as totalReportedHours," +
" sum(t.amount) as totalDispatchedQuantity," +
" sum(b.amount) as totalReportedQuantity,max(u2.username) as workerId ,max(u2.nickname) as workerName ")
.leftJoin(TaskReportDO.class,"b",TaskReportDO::getDispatchDetailId,TaskDispatchDetailDO::getId)
.leftJoin(EquipManufactureDO.class,"c",EquipManufactureDO::getId,TaskDispatchDetailDO::getDeviceModel)
//.leftJoin("base_equip_manufacture c on c.id = t.device_model or t.device_model is null ")
//.leftJoin(EquipManufactureDO.class,"c",EquipManufactureDO::getId,TaskDispatchDetailDO::getDeviceModel)
.leftJoin("system_users u2 on u2.id = t.owner");
if (pageReqVO.getWorkerIdOrName()!= null &&!pageReqVO.getWorkerIdOrName().isEmpty()) {
query.and(i -> i.like("u2.username", pageReqVO.getWorkerIdOrName()).or().like("u2.nickname", pageReqVO.getWorkerIdOrName()));