7 changed files with 59 additions and 48 deletions
@ -0,0 +1,23 @@ |
|||||||
|
package com.biutag.supervision.pojo.param; |
||||||
|
|
||||||
|
import lombok.Getter; |
||||||
|
import lombok.Setter; |
||||||
|
import org.springframework.format.annotation.DateTimeFormat; |
||||||
|
|
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.Date; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author wxc |
||||||
|
* @date 2024/10/16 |
||||||
|
*/ |
||||||
|
@Setter |
||||||
|
@Getter |
||||||
|
public class ModelClueTaskQueryParam extends BasePage { |
||||||
|
private List<Integer> modelIds; |
||||||
|
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
||||||
|
private List<Date> distributionTime = new ArrayList<>(); |
||||||
|
private String taskName; |
||||||
|
} |
||||||
@ -1,48 +1,35 @@ |
|||||||
package com.biutag.supervision.service; |
package com.biutag.supervision.service; |
||||||
|
|
||||||
import cn.hutool.core.bean.BeanUtil; |
import cn.hutool.core.util.StrUtil; |
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||||
import com.biutag.supervision.mapper.ModelClueTaskMapper; |
import com.biutag.supervision.mapper.ModelClueTaskMapper; |
||||||
import com.biutag.supervision.mapper.ModelMapper; |
|
||||||
import com.biutag.supervision.pojo.entity.Model; |
|
||||||
import com.biutag.supervision.pojo.entity.ModelClueTask; |
import com.biutag.supervision.pojo.entity.ModelClueTask; |
||||||
import com.biutag.supervision.pojo.model.ModelClueTaskModel; |
import com.biutag.supervision.pojo.model.ModelClueTaskModel; |
||||||
import com.biutag.supervision.pojo.param.ModelClueQueryParam; |
import com.biutag.supervision.pojo.param.ModelClueTaskQueryParam; |
||||||
import lombok.RequiredArgsConstructor; |
import lombok.RequiredArgsConstructor; |
||||||
import org.springframework.stereotype.Service; |
import org.springframework.stereotype.Service; |
||||||
|
|
||||||
import java.util.ArrayList; |
import java.util.ArrayList; |
||||||
import java.util.List; |
|
||||||
import java.util.Objects; |
import java.util.Objects; |
||||||
import java.util.Set; |
|
||||||
import java.util.stream.Collectors; |
|
||||||
|
|
||||||
@RequiredArgsConstructor |
@RequiredArgsConstructor |
||||||
@Service |
@Service |
||||||
public class ModelClueTaskService extends ServiceImpl<ModelClueTaskMapper, ModelClueTask> { |
public class ModelClueTaskService extends ServiceImpl<ModelClueTaskMapper, ModelClueTask> { |
||||||
|
|
||||||
private final ModelMapper modelMapper; |
public Page<ModelClueTaskModel> page(ModelClueTaskQueryParam param) { |
||||||
|
if (Objects.nonNull(param.getModelIds()) && param.getModelIds().isEmpty()) { |
||||||
public Page<ModelClueTaskModel> page(ModelClueQueryParam param) { |
return new Page<ModelClueTaskModel>().setTotal(0).setRecords(new ArrayList<>()); |
||||||
LambdaQueryWrapper<ModelClueTask> queryWrapper = new LambdaQueryWrapper<ModelClueTask>() |
} |
||||||
.orderByDesc(ModelClueTask::getDistributionTime); |
QueryWrapper<ModelClueTask> queryWrapper = new QueryWrapper<>(); |
||||||
|
queryWrapper.in(Objects.nonNull(param.getModelIds()), "mt.model_id", param.getModelIds()); |
||||||
Page<ModelClueTask> page = page(Page.of(param.getCurrent(), param.getSize()), queryWrapper); |
queryWrapper.like(StrUtil.isNotBlank(param.getTaskName()), "mt.task_name", param.getTaskName()); |
||||||
if (page.getRecords().isEmpty()) { |
if (Objects.nonNull(param.getDistributionTime()) && !param.getDistributionTime().isEmpty()) { |
||||||
return new Page<ModelClueTaskModel>().setRecords(new ArrayList<>()).setTotal(0); |
queryWrapper.between("mt.distribution_time", param.getDistributionTime().get(0), param.getDistributionTime().get(1)); |
||||||
} |
} |
||||||
Set<Integer> modelIds = page.getRecords().stream().map(ModelClueTask::getModelId).collect(Collectors.toSet()); |
Page<ModelClueTaskModel> page = baseMapper.queryPage(Page.of(param.getCurrent(), param.getSize()), queryWrapper); |
||||||
List<Model> models = modelMapper.selectBatchIds(modelIds); |
return page; |
||||||
List<ModelClueTaskModel> list = page.getRecords().stream().map(item -> { |
|
||||||
ModelClueTaskModel taskModel = new ModelClueTaskModel(); |
|
||||||
BeanUtil.copyProperties(item, taskModel); |
|
||||||
String modelName = models.stream().filter(model -> model.getId().equals(item.getModelId())).findFirst().map(Model::getModelName).orElse(""); |
|
||||||
taskModel.setModelName(modelName); |
|
||||||
return taskModel; |
|
||||||
}).toList(); |
|
||||||
return new Page<ModelClueTaskModel>().setRecords(list).setTotal(page.getTotal()); |
|
||||||
} |
} |
||||||
|
|
||||||
} |
} |
||||||
|
|||||||
Loading…
Reference in new issue