liyong
2 天以前 510f839b2a8703fc9faa7dc987b1421ea1716bce
src/main/java/com/ruoyi/aftersalesservice/service/impl/AfterSalesServiceServiceImpl.java
@@ -1,17 +1,34 @@
package com.ruoyi.aftersalesservice.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
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.ruoyi.aftersalesservice.dto.AfterSalesServiceNewDto;
import com.ruoyi.aftersalesservice.mapper.AfterSalesServiceMapper;
import com.ruoyi.aftersalesservice.pojo.AfterSalesService;
import com.ruoyi.aftersalesservice.service.AfterSalesServiceService;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.project.system.domain.SysDept;
import com.ruoyi.project.system.domain.SysUser;
import com.ruoyi.project.system.mapper.SysDeptMapper;
import com.ruoyi.project.system.mapper.SysUserMapper;
import com.ruoyi.sales.dto.SalesLedgerDto;
import com.ruoyi.sales.pojo.SalesLedger;
import com.ruoyi.sales.pojo.SalesLedgerProduct;
import com.ruoyi.sales.service.ISalesLedgerProductService;
import com.ruoyi.sales.service.ISalesLedgerService;
import com.ruoyi.sales.service.impl.SalesLedgerProductServiceImpl;
import com.ruoyi.sales.service.impl.SalesLedgerServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/**
 * @author :yys
@@ -27,6 +44,13 @@
    @Autowired
    private SysDeptMapper sysDeptMapper;
    @Autowired
    private SysUserMapper sysUserMapper;
    @Autowired
    private ISalesLedgerProductService salesLedgerProductService;
    @Autowired
    private ISalesLedgerService salesLedgerService;
    @Override
    public IPage<AfterSalesService> listPage(Page page, AfterSalesService afterSalesService) {
        Long tenantId = SecurityUtils.getLoginUser().getTenantId();
@@ -37,4 +61,34 @@
        });
        return afterSalesServiceIPage;
    }
    @Override
    public boolean addAfterSalesServiceDto(AfterSalesServiceNewDto afterSalesServiceNewDto) {
        afterSalesServiceNewDto.setStatus(1);
        if (afterSalesServiceNewDto.getProductModelIdList() != null && afterSalesServiceNewDto.getProductModelIdList().isEmpty() ) {
            String productModelIds = afterSalesServiceNewDto.getProductModelIdList().stream()
                    .map(String::valueOf)
                    .collect(Collectors.joining(","));
            afterSalesServiceNewDto.setProductModelIds(productModelIds);
        }
        SysUser sysUser = sysUserMapper.selectUserById(afterSalesServiceNewDto.getCheckUserId());
        if(sysUser == null) throw new RuntimeException("审核人不存在");
        afterSalesServiceNewDto.setCheckNickName(sysUser.getNickName());
        return this.save(afterSalesServiceNewDto);
    }
    @Override
    public AfterSalesServiceNewDto getAfterSalesServiceNewDtoById(Long id) {
        AfterSalesService afterSalesService = afterSalesServiceMapper.selectById(id);
        SalesLedger byId = salesLedgerService.getById(afterSalesService.getSalesLedgerId());
        List<Long> collect = Arrays.stream(afterSalesService.getProductModelIds().split(",")).map(Long::valueOf).collect(Collectors.toList());
        List<SalesLedgerProduct> list = salesLedgerProductService.list(new QueryWrapper<SalesLedgerProduct>().lambda().in(SalesLedgerProduct::getProductModelId, collect));
        AfterSalesServiceNewDto afterSalesServiceNewDto = new AfterSalesServiceNewDto();
        BeanUtils.copyProperties(afterSalesService, afterSalesServiceNewDto);
        SalesLedgerDto salesLedgerDto = new SalesLedgerDto();
        BeanUtils.copyProperties(byId, salesLedgerDto);
        salesLedgerDto.setProductData( list);
        afterSalesServiceNewDto.setSalesLedgerDto(salesLedgerDto);
        return afterSalesServiceNewDto;
    }
}