|
@ -1,16 +1,50 @@ |
|
|
package com.iflytop.handacid.common.service; |
|
|
package com.iflytop.handacid.common.service; |
|
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
|
|
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.iflytop.handacid.common.base.BasePageQuery; |
|
|
import com.iflytop.handacid.common.mapper.FormulationMapper; |
|
|
import com.iflytop.handacid.common.mapper.FormulationMapper; |
|
|
import com.iflytop.handacid.common.model.entity.Formulation; |
|
|
import com.iflytop.handacid.common.model.entity.Formulation; |
|
|
|
|
|
import com.iflytop.handacid.common.model.entity.Solution; |
|
|
|
|
|
import com.iflytop.handacid.common.model.vo.FormulationVO; |
|
|
import lombok.RequiredArgsConstructor; |
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
import java.util.Objects; |
|
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 配方接口服务 |
|
|
* 配方接口服务 |
|
|
*/ |
|
|
*/ |
|
|
@Service |
|
|
@Service |
|
|
@RequiredArgsConstructor |
|
|
@RequiredArgsConstructor |
|
|
public class FormulationService extends ServiceImpl<FormulationMapper, Formulation> { |
|
|
public class FormulationService extends ServiceImpl<FormulationMapper, Formulation> { |
|
|
|
|
|
private final SolutionService solutionService; |
|
|
|
|
|
|
|
|
|
|
|
public IPage<FormulationVO> getPage(BasePageQuery query) { |
|
|
|
|
|
Page<Formulation> page = this.page(new Page<>(query.getPageNum(), query.getPageSize())); |
|
|
|
|
|
List<Formulation> records = page.getRecords(); |
|
|
|
|
|
if (records.isEmpty()) { |
|
|
|
|
|
return new Page<>(page.getCurrent(), page.getSize(), page.getTotal()); |
|
|
|
|
|
} |
|
|
|
|
|
List<Long> solutionIds = records.stream() |
|
|
|
|
|
.map(Formulation::getSolutionId) |
|
|
|
|
|
.filter(Objects::nonNull) |
|
|
|
|
|
.distinct() |
|
|
|
|
|
.toList(); |
|
|
|
|
|
Map<Long, String> nameMap = solutionService.listByIds(solutionIds) |
|
|
|
|
|
.stream() |
|
|
|
|
|
.collect(Collectors.toMap(Solution::getId, Solution::getName)); |
|
|
|
|
|
return page.convert(entity -> { |
|
|
|
|
|
FormulationVO vo = new FormulationVO(); |
|
|
|
|
|
BeanUtils.copyProperties(entity, vo); |
|
|
|
|
|
vo.setSolutionName(nameMap.get(entity.getSolutionId())); |
|
|
|
|
|
return vo; |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |