InspectServiceImpl.java 1.68 KB
package vion.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.base.MPJBaseServiceImpl;
import io.github.linpeilie.Converter;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import vion.dto.InspectDTO;
import vion.mapper.InspectMapper;
import vion.model.Account;
import vion.model.Inspect;
import vion.model.Store;
import vion.service.IAccountService;
import vion.service.IInspectService;
import vion.service.IStoreService;

import java.util.List;

@Service
@RequiredArgsConstructor
public class InspectServiceImpl extends MPJBaseServiceImpl<InspectMapper, Inspect> implements IInspectService {

    private final IStoreService storeService;
    private final IAccountService accountService;
    private final Converter converter;

    @Override
    public Page<Inspect> getInspectList(InspectDTO data) {
        Page<Inspect> inspectList = this.lambdaQuery(converter.convert(data, new Inspect()))
                .between(data.getStartdate() != null && data.getEnddate() != null, Inspect::getInspectTime, data.getStartdate(), data.getEnddate())
                .page(Page.of(data.getPageNum(), data.getPageSize()));

        List<Store> storeList = storeService.list();
        List<Account> accountList = accountService.list();
        inspectList.getRecords().forEach(item -> {
            item.setAccountName(accountList.stream().filter(v -> v.getId().equals(item.getAccountId())).map(Account::getName).findFirst().orElse("--"));
            item.setStoreName(storeList.stream().filter(v -> v.getId().equals(item.getStoreId())).map(Store::getName).findFirst().orElse("--"));
        });
        return inspectList;
    }
}