ConstructionTeamServiceImpl.java 3.84 KB
package vion.service.impl;

import org.dromara.hutool.core.text.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.base.MPJBaseServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import io.github.linpeilie.Converter;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import vion.dto.ConstructionTeamDTO;
import vion.dto.RContractTeamDTO;
import vion.mapper.ConstructionTeamMapper;
import vion.model.ConstructionTeam;
import vion.model.Contract;
import vion.model.RContractTeam;
import vion.service.IConstructionTeamService;
import vion.service.IRContractTeamService;
import vion.vo.ConstructionTeamVO;
import vion.vo.RContractTeamVO;

import java.util.List;

/**
 * @author HlQ
 * @date 2023/12/26
 */
@Service
@RequiredArgsConstructor
public class ConstructionTeamServiceImpl extends MPJBaseServiceImpl<ConstructionTeamMapper, ConstructionTeam> implements IConstructionTeamService {

    private final IRContractTeamService contractTeamService;
    private final Converter converter;

    @Override
    public Page<ConstructionTeamVO> list(ConstructionTeamDTO dto) {
        Page<ConstructionTeam> constructionTeamList = this.lambdaQuery(converter.convert(dto, ConstructionTeam.class))
                .page(Page.of(dto.getPageNum(), dto.getPageSize()));
        List<ConstructionTeamVO> voList = converter.convert(constructionTeamList.getRecords(), ConstructionTeamVO.class);
        return Page.<ConstructionTeamVO>of(constructionTeamList.getCurrent(), constructionTeamList.getSize(), constructionTeamList.getTotal()).setRecords(voList);
    }

    @Override
    public ConstructionTeamVO getVOById(Long id) {
        return converter.convert(this.getById(id), ConstructionTeamVO.class);
    }

    @Override
    public Object save(ConstructionTeamDTO dto) {
        ConstructionTeam constructionTeam = converter.convert(dto, ConstructionTeam.class);
        return this.save(constructionTeam) ? constructionTeam.getId() : "新增失败";
    }

    @Override
    public String updateById(ConstructionTeamDTO dto) {
        ConstructionTeam constructionTeam = converter.convert(dto, ConstructionTeam.class);
        return this.updateById(constructionTeam) ? "更新成功" : "更新失败";
    }

    @Override
    public Page<RContractTeamVO> list(RContractTeamDTO dto) {
        var wrapper = new MPJLambdaWrapper<>(converter.convert(dto, RContractTeam.class))
                .selectAll(RContractTeam.class)
                .selectAs(Contract::getContractNo, RContractTeamVO::getContractNo)
                .selectAs(Contract::getName, RContractTeamVO::getContractName)
                .selectAs(Contract::getStatus, RContractTeamVO::getContractStatus)
                .selectAs(ConstructionTeam::getName, RContractTeamVO::getTeamName)
                .leftJoin(Contract.class, Contract::getId, RContractTeam::getContractId)
                .leftJoin(ConstructionTeam.class, ConstructionTeam::getId, RContractTeam::getCtId)
                .like(StrUtil.isNotBlank(dto.getContractNo()), Contract::getContractNo, dto.getContractNo())
                .like(StrUtil.isNotBlank(dto.getContractName()), Contract::getName, dto.getContractName())
                .orderByAsc(RContractTeam::getStatus)
                .orderByDesc(RContractTeam::getCreateTime);
        return contractTeamService.selectJoinListPage(Page.of(dto.getPageNum(), dto.getPageSize()), RContractTeamVO.class, wrapper);
    }

    @Override
    public String assignTeam(RContractTeamDTO dto) {
        RContractTeam rContractTeam = converter.convert(dto, RContractTeam.class);
        return contractTeamService.updateById(rContractTeam) ? "分配施工队成功。" : "分配施工队失败";
    }

    @Override
    public String delContractTeamById(Long id) {
        return contractTeamService.removeById(id) ? "删除成功" : "删除失败";
    }
}