xuhy
2026-02-04 07a08efc3bd17142a81c2128be99abb34c498577
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpProcurementServiceImpl.java
@@ -11,6 +11,7 @@
import com.ruoyi.system.dto.AddProcurementDto;
import com.ruoyi.system.export.PlatformLedgerReportExport;
import com.ruoyi.system.export.ProcurementReportClinicExport;
import com.ruoyi.system.export.ProcurementReportDetailExport;
import com.ruoyi.system.export.ProcurementReportPlatformExport;
import com.ruoyi.system.export.ProcurementReportSupplierExport;
import com.ruoyi.system.mapper.*;
@@ -19,22 +20,12 @@
import com.ruoyi.system.query.PerformanceReportQuery;
import com.ruoyi.system.query.TErpGoodsQuery;
import com.ruoyi.system.query.TErpProcurementQuery;
import com.ruoyi.system.service.TErpGoodsService;
import com.ruoyi.system.service.ISysUserService;
import com.ruoyi.system.service.TErpProcurementGoodsService;
import com.ruoyi.system.service.TErpProcurementService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.system.vo.*;
import lombok.SneakyThrows;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
@@ -42,20 +33,11 @@
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.security.PrivateKey;
import java.security.cert.X509Certificate;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -122,6 +104,11 @@
    @Resource
    private TErpProcurementCommissionMapper erpProcurementCommissionMapper;
    @Autowired
    private ISysUserService sysUserService;
    @Autowired
    private TCrmBranchAreaMapper crmBranchAreaMapper;
    @Override
    public PageInfo<TErpProcurementVo> pageList(TErpProcurementQuery query, SysUser user) {
@@ -134,6 +121,11 @@
            TCrmSupplier crmSupplier = crmSupplierMapper.selectOne(Wrappers.lambdaQuery(TCrmSupplier.class)
                    .eq(TCrmSupplier::getUserId, user.getUserId())
                    .last("LIMIT 1"));
            // ***
            if(Objects.isNull(crmSupplier)){
                SysUser sysUser = sysUserService.selectUserById(user.getUserId());
                crmSupplier = crmSupplierMapper.selectById(sysUser.getObjectId());
            }
            supplierClinicId = crmSupplier.getId();
        }
        if (roleType == 5) {
@@ -141,6 +133,11 @@
            TCrmClinic crmClinic = crmClinicMapper.selectOne(Wrappers.lambdaQuery(TCrmClinic.class)
                    .eq(TCrmClinic::getUserId, user.getUserId())
                    .last("LIMIT 1"));
            // ***
            if(Objects.isNull(crmClinic)){
                SysUser sysUser = sysUserService.selectUserById(user.getUserId());
                crmClinic = crmClinicMapper.selectById(sysUser.getObjectId());
            }
            supplierClinicId = crmClinic.getId();
        }
@@ -258,6 +255,11 @@
            TCrmSupplier crmSupplier = crmSupplierMapper.selectOne(Wrappers.lambdaQuery(TCrmSupplier.class)
                    .eq(TCrmSupplier::getUserId, user.getUserId())
                    .last("LIMIT 1"));
            // ***
            if(Objects.isNull(crmSupplier)){
                SysUser sysUser = sysUserService.selectUserById(user.getUserId());
                crmSupplier = crmSupplierMapper.selectById(sysUser.getObjectId());
            }
            supplierClinicId = crmSupplier.getId();
        }
        if (roleType == 5) {
@@ -265,6 +267,11 @@
            TCrmClinic crmClinic = crmClinicMapper.selectOne(Wrappers.lambdaQuery(TCrmClinic.class)
                    .eq(TCrmClinic::getUserId, user.getUserId())
                    .last("LIMIT 1"));
            // ***
            if(Objects.isNull(crmClinic)){
                SysUser sysUser = sysUserService.selectUserById(user.getUserId());
                crmClinic = crmClinicMapper.selectById(sysUser.getObjectId());
            }
            supplierClinicId = crmClinic.getId();
        }
@@ -304,6 +311,7 @@
        ArrayList<TErpProcurementDetailNextVo> tErpProcurementDetailNextVos = new ArrayList<>();
        for (TErpProcurementGoods tErpProcurementGood : tErpProcurementGoods) {
            TErpProcurementDetailNextVo tErpProcurementDetailNextVo = new TErpProcurementDetailNextVo();
            BeanUtils.copyProperties(tErpProcurementGood, tErpProcurementDetailNextVo);
            tErpProcurementDetailNextVo.setGoodsName(tErpProcurementGood.getGoodsName());
            tErpProcurementDetailNextVo.setUnitName(tErpProcurementGood.getUnitName());
            tErpProcurementDetailNextVo.setNum(tErpProcurementGood.getPurchaseCount());
@@ -329,7 +337,22 @@
    @Override
    public PageInfo<TErpGoods> pageGoodsPageList(TErpGoodsQuery query, SysUser user) {
        PageInfo<TErpGoods> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize());
        PageInfo<TErpGoods> p = erpGoodsMapper.selectPage(pageInfo, new LambdaQueryWrapper<TErpGoods>().eq(TErpGoods::getState,1).eq(TErpGoods::getGoodsSource, 1).isNotNull(TErpGoods::getClinicPurchasePrice).orderByDesc(BaseModel::getCreateTime));
        // 获取未禁用的供应商
        List<TCrmSupplier> suppliers = crmSupplierMapper.selectList(new LambdaQueryWrapper<TCrmSupplier>().eq(TCrmSupplier::getStatus, 1));
        if(suppliers.isEmpty()){
            return pageInfo;
        }
        PageInfo<TErpGoods> p = erpGoodsMapper.selectPage(pageInfo, new LambdaQueryWrapper<TErpGoods>()
                .like(StringUtils.isNotBlank(query.getGoodsName()), TErpGoods::getGoodsName, query.getGoodsName())
                .like(StringUtils.isNotBlank(query.getGoodsIdCode()), TErpGoods::getGoodsIdCode, query.getGoodsIdCode())
                .like(StringUtils.isNotBlank(query.getQuasiNumber()), TErpGoods::getQuasiNumber, query.getQuasiNumber())
                .eq(StringUtils.isNotBlank(query.getTypeId()),TErpGoods::getTypeId, query.getTypeId())
                .eq(TErpGoods::getState,1)
                .eq(TErpGoods::getGoodsSource, 1)
                .in(TErpGoods::getSupplierClinicId, suppliers.stream().map(TCrmSupplier::getId).collect(Collectors.toList()))
                .isNotNull(TErpGoods::getClinicPurchasePrice)
                .orderByDesc(BaseModel::getCreateTime));
        List<TErpGoods> list = p.getRecords();
        List<String> typeIds = list.stream().map(TErpGoods::getTypeId).collect(Collectors.toList());
@@ -353,7 +376,14 @@
    @Override
    public List<TErpGoodsVO> inventoryNotEnoughList(SysUser user) {
        List<TErpGoodsVO> list = this.baseMapper.inventoryNotEnoughList(user);
        // 查询诊所
        TCrmClinic crmClinic = crmClinicMapper.selectOne(new LambdaQueryWrapper<TCrmClinic>().eq(TCrmClinic::getUserId, user.getUserId())
                .last("limit 1"));
        if (Objects.isNull(crmClinic)) {
            SysUser sysUser = sysUserService.selectUserById(user.getUserId());
            crmClinic = crmClinicMapper.selectById(sysUser.getObjectId());
        }
        List<TErpGoodsVO> list = this.baseMapper.inventoryNotEnoughList(user,crmClinic.getId());
        List<String> typeIds = list.stream().map(TErpGoodsVO::getTypeId).collect(Collectors.toList());
        if (!typeIds.isEmpty()) {
            List<TErpGoodsType> typeList = erpGoodsTypeMapper.selectBatchIds(typeIds);
@@ -428,6 +458,13 @@
                TErpProcurementGoods tErpProcurementGoods = new TErpProcurementGoods();
                tErpProcurementGoods.setProcurementId(tErpProcurement.getId());
                TErpGoods goods = tErpGoods.stream().filter(e -> e.getId().equals(dto.getGoodsId())).findFirst().get();
                BeanUtils.copyProperties(goods, tErpProcurementGoods);
                if (goods.getContentState()==null || goods.getContentState()!=1) {
                    tErpProcurementGoods.setContent(null);
                }
                tErpProcurementGoods.setGoodsId(dto.getGoodsId());
                tErpProcurementGoods.setGoodsName(goods.getGoodsName());
                tErpProcurementGoods.setSupplierName(supplier.getSupplierName());
@@ -499,7 +536,10 @@
                e.printStackTrace();
                throw new RuntimeException("网络繁忙,请重试");
            }
            tErpProcurementGoods1.forEach(e -> e.setProcurementId(tErpProcurement.getId()));
            for (TErpProcurementGoods tErpProcurementGoods : tErpProcurementGoods1) {
                tErpProcurementGoods.setId(null);
                tErpProcurementGoods.setProcurementId(tErpProcurement.getId());
            }
            erpProcurementGoodsService.saveBatch(tErpProcurementGoods1);
        }
@@ -530,6 +570,7 @@
        ArrayList<DetailProcurementNextVO> detailProcurementNextVOS = new ArrayList<>();
        for (TErpProcurementGoods tErpProcurementGoods : list) {
            DetailProcurementNextVO detailProcurementNextVO = new DetailProcurementNextVO();
            BeanUtils.copyProperties(tErpProcurementGoods, detailProcurementNextVO);
            detailProcurementNextVO.setGoodsName(tErpProcurementGoods.getGoodsName());
            detailProcurementNextVO.setQuasiNumber(tErpProcurementGoods.getQuasiNumber());
            detailProcurementNextVO.setPackingUnitName(tErpProcurementGoods.getUnitName());
@@ -870,6 +911,34 @@
    public PageInfo<BranchPerformanceReportVO> branchPerformanceReport(PerformanceReportQuery query) {
        List<String> clinicIds = new ArrayList<>();
        List<TCrmBranchArea> crmBranchAreas = new ArrayList<>();
        if(StringUtils.isNotEmpty(query.getCityCode())){
            crmBranchAreas = crmBranchAreaMapper.selectList(Wrappers.lambdaQuery(TCrmBranchArea.class)
                    .eq(TCrmBranchArea::getCityCode, query.getCityCode())
                    .eq(TCrmBranchArea::getAreaType, 2));
            if(CollectionUtils.isEmpty(crmBranchAreas)){
                return new PageInfo<>();
            }
        }
        if(StringUtils.isNotEmpty(query.getProvinceCode())){
            crmBranchAreas = crmBranchAreaMapper.selectList(Wrappers.lambdaQuery(TCrmBranchArea.class)
                    .eq(TCrmBranchArea::getProvinceCode, query.getProvinceCode())
                    .eq(TCrmBranchArea::getAreaType, 2));
            if(CollectionUtils.isEmpty(crmBranchAreas)){
                return new PageInfo<>();
            }
        }
        if(!CollectionUtils.isEmpty(crmBranchAreas)){
            List<String> branchIds = crmBranchAreas.stream().map(TCrmBranchArea::getBranchId).collect(Collectors.toList());
            List<TCrmClinic> crmClinics = crmClinicMapper.selectList(Wrappers.lambdaQuery(TCrmClinic.class)
                    .in(TCrmClinic::getBranchId, branchIds));
            if(CollectionUtils.isEmpty(crmClinics)){
                return new PageInfo<>();
            }
            List<String> ids = crmClinics.stream().map(TCrmClinic::getId).collect(Collectors.toList());
            clinicIds.addAll(ids);
        }
        if(StringUtils.isNotBlank(query.getBranchName())){
            // 查询分公司名称
@@ -887,6 +956,7 @@
            List<String> ids = crmClinics.stream().map(TCrmClinic::getId).collect(Collectors.toList());
            clinicIds.addAll(ids);
        }
        clinicIds = clinicIds.stream().distinct().collect(Collectors.toList());
        query.setClinicIds(clinicIds);
        PageInfo<BranchPerformanceReportVO> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize());
@@ -996,7 +1066,28 @@
    @Override
    public List<BranchPerformanceReportVO> exportBranchPerformanceReport(PerformanceReportQuery query) {
        List<String> clinicIds = new ArrayList<>();
        List<TCrmBranchArea> crmBranchAreas = new ArrayList<>();
        if(StringUtils.isNotEmpty(query.getCityCode())){
            crmBranchAreas = crmBranchAreaMapper.selectList(Wrappers.lambdaQuery(TCrmBranchArea.class)
                    .eq(TCrmBranchArea::getCityCode, query.getCityCode())
                    .eq(TCrmBranchArea::getAreaType, 2));
        }
        if(StringUtils.isNotEmpty(query.getProvinceCode())){
            crmBranchAreas = crmBranchAreaMapper.selectList(Wrappers.lambdaQuery(TCrmBranchArea.class)
                    .eq(TCrmBranchArea::getProvinceCode, query.getProvinceCode())
                    .eq(TCrmBranchArea::getAreaType, 2));
        }
        if(!CollectionUtils.isEmpty(crmBranchAreas)){
            List<String> branchIds = crmBranchAreas.stream().map(TCrmBranchArea::getBranchId).collect(Collectors.toList());
            List<TCrmClinic> crmClinics = crmClinicMapper.selectList(Wrappers.lambdaQuery(TCrmClinic.class)
                    .in(TCrmClinic::getBranchId, branchIds));
            if(CollectionUtils.isEmpty(crmClinics)){
                return new ArrayList<>();
            }
            List<String> ids = crmClinics.stream().map(TCrmClinic::getId).collect(Collectors.toList());
            clinicIds.addAll(ids);
        }
        if(StringUtils.isNotBlank(query.getBranchName())){
            // 查询分公司名称
            List<TCrmBranch> crmBranches = crmBranchMapper.selectList(Wrappers.lambdaQuery(TCrmBranch.class)
@@ -1122,4 +1213,14 @@
        return list;
    }
    @Override
    public List<ClinicProcurementReportDetailVO> clinicProcurementReportDetail(String id) {
        return this.baseMapper.clinicProcurementReportDetail(id);
    }
    @Override
    public List<ProcurementReportDetailExport> exportProcurementReportDetail(List<String> procurementIds) {
        return this.baseMapper.exportProcurementReportDetail(procurementIds);
    }
}