| | |
| | | package com.ruoyi.system.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.ruoyi.common.basic.PageInfo; |
| | | import com.ruoyi.common.core.domain.BaseModel; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.system.dto.AddProcurementDto; |
| | | import com.ruoyi.system.mapper.*; |
| | | import com.ruoyi.system.model.*; |
| | | import com.ruoyi.system.query.TErpGoodsQuery; |
| | | import com.ruoyi.system.query.TErpProcurementQuery; |
| | | import com.ruoyi.system.service.TErpGoodsService; |
| | | 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.TErpProcurementDetailNextVo; |
| | | import com.ruoyi.system.vo.TErpProcurementDetailVo; |
| | | import com.ruoyi.system.vo.TErpProcurementVo; |
| | | import com.ruoyi.system.vo.ValidityPeriodWarningVo; |
| | | 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.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Propagation; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | 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.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | private TCrmClinicMapper crmClinicMapper; |
| | | |
| | | @Resource |
| | | private TCrmSupplierMapper crmSupplierMapper; |
| | | |
| | | @Resource |
| | | private SysUserMapper sysUserMapper; |
| | | |
| | | @Resource |
| | | private TErpGoodsMapper erpGoodsMapper; |
| | | |
| | | @Resource |
| | | private TErpGoodsTypeMapper erpGoodsTypeMapper; |
| | | |
| | | @Resource |
| | | private TErpGoodsUnitMapper erpGoodsUnitMapper; |
| | | |
| | | @Autowired |
| | | private TErpProcurementGoodsService erpProcurementGoodsService; |
| | | |
| | | |
| | | @Override |
| | | public PageInfo<TErpProcurementVo> pageList(TErpProcurementQuery query, SysUser user) { |
| | | String sTime=null; |
| | | String eTime =null; |
| | | if(query.getTime()!=null && !query.getTime().isEmpty()){ |
| | | |
| | | |
| | | Integer roleType = user.getRoleType(); |
| | | String supplierClinicId = null; |
| | | if (roleType == 4) { |
| | | // 供应商 |
| | | TCrmSupplier crmSupplier = crmSupplierMapper.selectOne(Wrappers.lambdaQuery(TCrmSupplier.class) |
| | | .eq(TCrmSupplier::getUserId, user.getUserId()) |
| | | .last("LIMIT 1")); |
| | | supplierClinicId = crmSupplier.getId(); |
| | | } |
| | | if (roleType == 5) { |
| | | // 诊所 |
| | | TCrmClinic crmClinic = crmClinicMapper.selectOne(Wrappers.lambdaQuery(TCrmClinic.class) |
| | | .eq(TCrmClinic::getUserId, user.getUserId()) |
| | | .last("LIMIT 1")); |
| | | supplierClinicId = crmClinic.getId(); |
| | | } |
| | | |
| | | String sTime = null; |
| | | String eTime = null; |
| | | if (query.getTime() != null && !query.getTime().isEmpty()) { |
| | | String[] split = query.getTime().split(" - "); |
| | | sTime = split[0] + " 00:00:00"; |
| | | eTime = split[1] + " 23:59:59"; |
| | | } |
| | | PageInfo<TErpProcurementVo> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize()); |
| | | List<TErpProcurementVo> list = this.baseMapper.pageList(query,pageInfo,user,sTime,eTime); |
| | | if(list.isEmpty()){ |
| | | List<TErpProcurementVo> list = this.baseMapper.pageList(query, pageInfo, user, sTime, eTime, supplierClinicId); |
| | | if (list.isEmpty()) { |
| | | return pageInfo; |
| | | } |
| | | List<String> ids = list.stream().map(TErpProcurementVo::getId).collect(Collectors.toList()); |
| | | List<TErpProcurementGoods> tErpProcurementGoods = erpProcurementGoodsMapper.selectList(new LambdaQueryWrapper<TErpProcurementGoods>().in(TErpProcurementGoods::getProcurementId, ids).eq(TErpProcurementGoods::getSupplierId, user.getUserId())); |
| | | List<TSysCommission> tSysCommissions =new ArrayList<>(); |
| | | if(!tErpProcurementGoods.isEmpty()){ |
| | | List<TErpProcurementGoods> tErpProcurementGoods = erpProcurementGoodsMapper.selectList |
| | | (new LambdaQueryWrapper<TErpProcurementGoods>().in(TErpProcurementGoods::getProcurementId, ids)); |
| | | List<TSysCommission> tSysCommissions = new ArrayList<>(); |
| | | if (!tErpProcurementGoods.isEmpty()) { |
| | | List<String> collect = tErpProcurementGoods.stream().map(TErpProcurementGoods::getId).collect(Collectors.toList()); |
| | | tSysCommissions = sysCommissionMapper.selectList(new LambdaQueryWrapper<TSysCommission>().in(TSysCommission::getTErpProcurementGoodsId, collect)); |
| | | } |
| | |
| | | tErpProcurementVo.setTypeNum(size); |
| | | BigDecimal reduce = collect.stream().map(TErpProcurementGoods::getTotalPrice).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | tErpProcurementVo.setTotalPrice(reduce); |
| | | if(!collect.isEmpty()){ |
| | | if (!collect.isEmpty()) { |
| | | List<String> collect1 = collect.stream().map(TErpProcurementGoods::getId).collect(Collectors.toList()); |
| | | List<TSysCommission> collect2 = tSysCommissions.stream().filter(e -> collect1.contains(e.getTErpProcurementGoodsId())).collect(Collectors.toList()); |
| | | BigDecimal reduce1 = collect2.stream().filter(e->e.getType()==1).map(TSysCommission::getMoney).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | BigDecimal reduce2 = collect2.stream().filter(e->e.getType()==2).map(TSysCommission::getMoney).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | BigDecimal reduce1 = collect2.stream().filter(e -> e.getType() == 1).map(TSysCommission::getMoney).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | BigDecimal reduce2 = collect2.stream().filter(e -> e.getType() == 2).map(TSysCommission::getMoney).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | tErpProcurementVo.setPlatformMoney(reduce1); |
| | | tErpProcurementVo.setSupplierMoney(reduce2); |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public PageInfo<TErpProcurementVo> pageListWarehouse(TErpProcurementQuery query, SysUser user) { |
| | | |
| | | |
| | | Integer roleType = user.getRoleType(); |
| | | String supplierClinicId = null; |
| | | if (roleType == 6) { |
| | | // 供应商 |
| | | TCrmSupplier crmSupplier = crmSupplierMapper.selectOne(Wrappers.lambdaQuery(TCrmSupplier.class) |
| | | .eq(TCrmSupplier::getUserId, user.getUserId()) |
| | | .last("LIMIT 1")); |
| | | supplierClinicId = crmSupplier.getId(); |
| | | |
| | | |
| | | String sTime = null; |
| | | String eTime = null; |
| | | if (query.getTime() != null && !query.getTime().isEmpty()) { |
| | | String[] split = query.getTime().split(" - "); |
| | | sTime = split[0] + " 00:00:00"; |
| | | eTime = split[1] + " 23:59:59"; |
| | | } |
| | | PageInfo<TErpProcurementVo> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize()); |
| | | List<TErpProcurementVo> list = this.baseMapper.pageListWarehouse(query, pageInfo, user, sTime, eTime, supplierClinicId); |
| | | // if (list.isEmpty()) { |
| | | // return pageInfo; |
| | | // } |
| | | // List<String> ids = list.stream().map(TErpProcurementVo::getId).collect(Collectors.toList()); |
| | | // List<TErpProcurementGoods> tErpProcurementGoods = erpProcurementGoodsMapper.selectList |
| | | // (new LambdaQueryWrapper<TErpProcurementGoods>().in(TErpProcurementGoods::getProcurementId, ids)); |
| | | // List<TSysCommission> tSysCommissions = new ArrayList<>(); |
| | | // if (!tErpProcurementGoods.isEmpty()) { |
| | | // List<String> collect = tErpProcurementGoods.stream().map(TErpProcurementGoods::getId).collect(Collectors.toList()); |
| | | // tSysCommissions = sysCommissionMapper.selectList(new LambdaQueryWrapper<TSysCommission>().in(TSysCommission::getTErpProcurementGoodsId, collect)); |
| | | // } |
| | | // for (TErpProcurementVo tErpProcurementVo : list) { |
| | | // List<TErpProcurementGoods> collect = tErpProcurementGoods.stream().filter(e -> e.getProcurementId().equals(tErpProcurementVo.getId())).collect(Collectors.toList()); |
| | | // int size = collect.stream().map(TErpProcurementGoods::getGoodsId).collect(Collectors.toSet()).size(); |
| | | // tErpProcurementVo.setTypeNum(size); |
| | | // BigDecimal reduce = collect.stream().map(TErpProcurementGoods::getTotalPrice).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | // tErpProcurementVo.setTotalPrice(reduce); |
| | | // if (!collect.isEmpty()) { |
| | | // List<String> collect1 = collect.stream().map(TErpProcurementGoods::getId).collect(Collectors.toList()); |
| | | // List<TSysCommission> collect2 = tSysCommissions.stream().filter(e -> collect1.contains(e.getTErpProcurementGoodsId())).collect(Collectors.toList()); |
| | | // BigDecimal reduce1 = collect2.stream().filter(e -> e.getType() == 1).map(TSysCommission::getMoney).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | // BigDecimal reduce2 = collect2.stream().filter(e -> e.getType() == 2).map(TSysCommission::getMoney).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | // tErpProcurementVo.setPlatformMoney(reduce1); |
| | | // tErpProcurementVo.setSupplierMoney(reduce2); |
| | | // } |
| | | // |
| | | // } |
| | | |
| | | |
| | | pageInfo.setRecords(list); |
| | | return pageInfo; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | public TErpProcurementDetailVo detail(String id, SysUser user, String goodsName) { |
| | | |
| | | Integer roleType = user.getRoleType(); |
| | | String supplierClinicId = null; |
| | | if (roleType == 4) { |
| | | // 供应商 |
| | | TCrmSupplier crmSupplier = crmSupplierMapper.selectOne(Wrappers.lambdaQuery(TCrmSupplier.class) |
| | | .eq(TCrmSupplier::getUserId, user.getUserId()) |
| | | .last("LIMIT 1")); |
| | | supplierClinicId = crmSupplier.getId(); |
| | | } |
| | | if (roleType == 5) { |
| | | // 诊所 |
| | | TCrmClinic crmClinic = crmClinicMapper.selectOne(Wrappers.lambdaQuery(TCrmClinic.class) |
| | | .eq(TCrmClinic::getUserId, user.getUserId()) |
| | | .last("LIMIT 1")); |
| | | supplierClinicId = crmClinic.getId(); |
| | | } |
| | | |
| | | TErpProcurementDetailVo tErpProcurementVo = new TErpProcurementDetailVo(); |
| | | |
| | | TErpProcurement tErpProcurement = this.getById(id); |
| | |
| | | tErpProcurementVo.setUserName(sysUser.getNickName()); |
| | | tErpProcurementVo.setCreateTime(tErpProcurement.getCreateTime()); |
| | | tErpProcurementVo.setUpdateTime(tErpProcurement.getUpdateTime()); |
| | | if(tErpProcurement.getWarehousingUserId()!=null){ |
| | | if (tErpProcurement.getWarehousingUserId() != null) { |
| | | SysUser sysUser1 = sysUserMapper.selectUserById(Long.valueOf(tErpProcurement.getWarehousingUserId())); |
| | | tErpProcurementVo.setOperName(sysUser1.getNickName()); |
| | | } |
| | | tErpProcurementVo.setStatus(tErpProcurement.getStatus()); |
| | | tErpProcurementVo.setSendTime(tErpProcurement.getSendTime()); |
| | | |
| | | List<TErpProcurementGoods> tErpProcurementGoods = erpProcurementGoodsMapper.selectList(new LambdaQueryWrapper<TErpProcurementGoods>().eq(TErpProcurementGoods::getProcurementId, id).like(goodsName != null && !goodsName.isEmpty(), TErpProcurementGoods::getGoodsName, goodsName).eq(TErpProcurementGoods::getSupplierId, user.getUserId())); |
| | | if(tErpProcurementGoods.isEmpty()){ |
| | | tErpProcurementVo.setMoney(tErpProcurement.getMoney()); |
| | | tErpProcurementVo.setTotalPrice(tErpProcurement.getPayMoney()); |
| | | |
| | | List<TErpProcurementGoods> tErpProcurementGoods = erpProcurementGoodsMapper.selectList |
| | | (new LambdaQueryWrapper<TErpProcurementGoods>().eq(TErpProcurementGoods::getProcurementId, id) |
| | | .like(goodsName != null && !goodsName.isEmpty(), TErpProcurementGoods::getGoodsName, goodsName) |
| | | .eq(TErpProcurementGoods::getSupplierId, supplierClinicId)); |
| | | if (tErpProcurementGoods.isEmpty()) { |
| | | return tErpProcurementVo; |
| | | } |
| | | |
| | |
| | | tErpProcurementDetailNextVo.setNum(tErpProcurementGood.getPurchaseCount()); |
| | | tErpProcurementDetailNextVo.setTotalPrice(tErpProcurementGood.getTotalPrice()); |
| | | tErpProcurementDetailNextVo.setQuasiNumber(tErpProcurementGood.getQuasiNumber()); |
| | | tErpProcurementDetailNextVo.setPurchasePrice(tErpProcurementGood.getSalesAmount()); |
| | | |
| | | |
| | | List<TSysCommission> tSysCommissions = sysCommissionMapper.selectList(new LambdaQueryWrapper<TSysCommission>().eq(TSysCommission::getTErpProcurementGoodsId, tErpProcurementGood.getId())); |
| | | if(!tSysCommissions.isEmpty()){ |
| | | if (!tSysCommissions.isEmpty()) { |
| | | BigDecimal reduce = tSysCommissions.stream().filter(e -> e.getType() == 1).map(TSysCommission::getMoney).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | tErpProcurementDetailNextVo.setPlatformMoney(reduce); |
| | | BigDecimal reduce1 = tSysCommissions.stream().filter(e -> e.getType() == 2).map(TSysCommission::getMoney).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | |
| | | tErpProcurementVo.setList(tErpProcurementDetailNextVos); |
| | | return tErpProcurementVo; |
| | | } |
| | | |
| | | @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::getGoodsSource, 1).isNotNull(TErpGoods::getClinicPurchasePrice).orderByDesc(BaseModel::getCreateTime)); |
| | | List<TErpGoods> list = p.getRecords(); |
| | | |
| | | List<String> typeIds = list.stream().map(TErpGoods::getTypeId).collect(Collectors.toList()); |
| | | if (!typeIds.isEmpty()) { |
| | | List<TErpGoodsType> typeList = erpGoodsTypeMapper.selectBatchIds(typeIds); |
| | | for (TErpGoods tErpGoodsVO : list) { |
| | | typeList.stream().filter(t -> t.getId().equals(tErpGoodsVO.getTypeId())).findFirst().ifPresent(t -> tErpGoodsVO.setTypeName(t.getTypeName())); |
| | | tErpGoodsVO.setTypeName(tErpGoodsVO.getTypeName()); |
| | | } |
| | | } |
| | | List<String> supplierClinicId = list.stream().filter(e -> e.getGoodsSource() == 1).map(TErpGoods::getSupplierClinicId).collect(Collectors.toList()); |
| | | if (!supplierClinicId.isEmpty()) { |
| | | List<TCrmSupplier> crmClinics = crmSupplierMapper.selectBatchIds(supplierClinicId); |
| | | for (TErpGoods tErpGoodsVO : list) { |
| | | crmClinics.stream().filter(t -> t.getId().equals(tErpGoodsVO.getSupplierClinicId())).findFirst().ifPresent(t -> tErpGoodsVO.setSupplierName(t.getSupplierName())); |
| | | } |
| | | } |
| | | pageInfo.setRecords(list); |
| | | return pageInfo; |
| | | } |
| | | |
| | | @Override |
| | | public List<TErpGoodsVO> inventoryNotEnoughList(SysUser user) { |
| | | List<TErpGoodsVO> list = this.baseMapper.inventoryNotEnoughList(user); |
| | | List<String> typeIds = list.stream().map(TErpGoodsVO::getTypeId).collect(Collectors.toList()); |
| | | if (!typeIds.isEmpty()) { |
| | | List<TErpGoodsType> typeList = erpGoodsTypeMapper.selectBatchIds(typeIds); |
| | | for (TErpGoodsVO tErpGoodsVO : list) { |
| | | typeList.stream().filter(t -> t.getId().equals(tErpGoodsVO.getTypeId())).findFirst().ifPresent(t -> tErpGoodsVO.setTypeName(t.getTypeName())); |
| | | } |
| | | } |
| | | List<String> supplierClinicId = list.stream().filter(e -> e.getGoodsSource() == 1).map(TErpGoodsVO::getSupplierClinicId).collect(Collectors.toList()); |
| | | if (!supplierClinicId.isEmpty()) { |
| | | List<TCrmSupplier> crmSuppliers = crmSupplierMapper.selectBatchIds(supplierClinicId); |
| | | for (TErpGoodsVO tErpGoodsVO : list) { |
| | | crmSuppliers.stream().filter(t -> t.getId().equals(tErpGoodsVO.getSupplierClinicId())).findFirst().ifPresent(t -> tErpGoodsVO.setSupplierName(t.getSupplierName())); |
| | | } |
| | | } |
| | | |
| | | return list; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED) |
| | | public void addProcurement(String clinicSupplierId, SysUser user, List<AddProcurementDto> dtos) { |
| | | List<String> goodsIds = dtos.stream().map(AddProcurementDto::getGoodsId).collect(Collectors.toList()); |
| | | List<TErpGoods> tErpGoods = erpGoodsMapper.selectBatchIds(goodsIds); |
| | | for (AddProcurementDto dto : dtos) { |
| | | TErpGoods tErpGoodsVO = tErpGoods.stream().filter(t -> t.getId().equals(dto.getGoodsId())).findFirst().get(); |
| | | dto.setPlatformCommissionPrice(tErpGoodsVO.getPlatformCommissionPrice()); |
| | | dto.setSupplierId(tErpGoodsVO.getSupplierClinicId()); |
| | | dto.setGoodsSalesAmount(tErpGoodsVO.getClinicPurchasePrice()); |
| | | if (dto.getSalesAmount() == null) { |
| | | dto.setSalesAmount(tErpGoodsVO.getClinicPurchasePrice()); |
| | | } |
| | | } |
| | | // 供应商分组 |
| | | Map<String, List<AddProcurementDto>> supplierClinicIdListMap = dtos.stream().collect(Collectors.groupingBy(AddProcurementDto::getSupplierId)); |
| | | for (Map.Entry<String, List<AddProcurementDto>> entry : supplierClinicIdListMap.entrySet()) { |
| | | String supplierClinicId = entry.getKey(); |
| | | TCrmSupplier supplier = crmSupplierMapper.selectById(supplierClinicId); |
| | | List<AddProcurementDto> value = entry.getValue(); |
| | | TErpProcurement tErpProcurement = new TErpProcurement(); |
| | | tErpProcurement.setClinicId(clinicSupplierId); |
| | | tErpProcurement.setProcurementCode("C" + DateUtils.dateTimeNow()); |
| | | tErpProcurement.setSupplierId(supplierClinicId); |
| | | |
| | | tErpProcurement.setTermNo(supplier.getTermNo()); |
| | | tErpProcurement.setMerchantNo(supplier.getRecvMerchantNo()); |
| | | tErpProcurement.setCreateId(user.getUserId().toString()); |
| | | |
| | | BigDecimal all = BigDecimal.ZERO; |
| | | |
| | | for (AddProcurementDto addProcurementDto : value) { |
| | | BigDecimal multiply = addProcurementDto.getSalesAmount().multiply(BigDecimal.valueOf(addProcurementDto.getPurchaseCount())); |
| | | all = all.add(multiply); |
| | | } |
| | | tErpProcurement.setPayMoney(all); |
| | | AddProcurementDto addProcurementDto = value.get(0); |
| | | if (addProcurementDto.getState() != null && addProcurementDto.getState() == 1) { |
| | | tErpProcurement.setStatus(1); |
| | | } else { |
| | | tErpProcurement.setStatus(2); |
| | | } |
| | | ArrayList<TErpProcurementGoods> tErpProcurementGoods1 = new ArrayList<>(); |
| | | |
| | | BigDecimal add = BigDecimal.ZERO; |
| | | |
| | | for (AddProcurementDto dto : value) { |
| | | TErpProcurementGoods tErpProcurementGoods = new TErpProcurementGoods(); |
| | | tErpProcurementGoods.setProcurementId(tErpProcurement.getId()); |
| | | TErpGoods goods = tErpGoods.stream().filter(e -> e.getId().equals(dto.getGoodsId())).findFirst().get(); |
| | | tErpProcurementGoods.setGoodsId(dto.getGoodsId()); |
| | | tErpProcurementGoods.setGoodsName(goods.getGoodsName()); |
| | | tErpProcurementGoods.setSupplierName(supplier.getSupplierName()); |
| | | tErpProcurementGoods.setQuasiNumber(goods.getQuasiNumber()); |
| | | |
| | | TErpGoodsUnit tErpGoodsUnit = erpGoodsUnitMapper.selectById(goods.getPackingUnitId()); |
| | | tErpProcurementGoods.setUnitName(tErpGoodsUnit.getUnitName()); |
| | | tErpProcurementGoods.setPurchasePrice(dto.getGoodsSalesAmount()); |
| | | tErpProcurementGoods.setSalesAmount(dto.getSalesAmount()); |
| | | tErpProcurementGoods.setTotalPrice(dto.getGoodsSalesAmount().multiply(new BigDecimal(dto.getPurchaseCount()))); |
| | | |
| | | tErpProcurementGoods.setPurchaseCount(dto.getPurchaseCount()); |
| | | tErpProcurementGoods.setSupplierId(supplierClinicId); |
| | | tErpProcurementGoods.setRecvMerchantNo(supplier.getRecvMerchantNo()); |
| | | tErpProcurementGoods.setSupplierMoney(dto.getSalesAmount().subtract(dto.getPlatformCommissionPrice())); |
| | | if (tErpProcurementGoods.getSupplierMoney().doubleValue() < 0) { |
| | | throw new RuntimeException("平台抽成不能大于售卖价格"); |
| | | } |
| | | add = add.add(dto.getPlatformCommissionPrice().multiply(BigDecimal.valueOf(dto.getPurchaseCount()))); |
| | | tErpProcurementGoods1.add(tErpProcurementGoods); |
| | | } |
| | | BigDecimal bigDecimal = tErpProcurement.getPayMoney().multiply(BigDecimal.valueOf(0.0038)).setScale(2, RoundingMode.HALF_UP); |
| | | |
| | | tErpProcurement.setMoney(add.subtract(bigDecimal)); |
| | | if (tErpProcurement.getMoney().doubleValue() < 0) { |
| | | throw new RuntimeException("金额设置错误,请联系平台管理员"); |
| | | } |
| | | this.save(tErpProcurement); |
| | | tErpProcurementGoods1.forEach(e -> e.setProcurementId(tErpProcurement.getId())); |
| | | erpProcurementGoodsService.saveBatch(tErpProcurementGoods1); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public DetailProcurementVO detailProcurement(String clinicSupplierId, SysUser user, String id) { |
| | | DetailProcurementVO detailProcurementVO = new DetailProcurementVO(); |
| | | TErpProcurement tErpProcurement = this.getById(id); |
| | | detailProcurementVO.setStatus(tErpProcurement.getStatus()); |
| | | detailProcurementVO.setCreateTime(tErpProcurement.getCreateTime()); |
| | | detailProcurementVO.setSendTime(tErpProcurement.getSendTime()); |
| | | TCrmSupplier supplier = crmSupplierMapper.selectById(tErpProcurement.getSupplierId()); |
| | | detailProcurementVO.setSupplierName(supplier.getSupplierName()); |
| | | detailProcurementVO.setUserName(sysUserMapper.selectUserById(Long.valueOf(tErpProcurement.getCreateId())).getUserName()); |
| | | TCrmClinic tCrmClinic = crmClinicMapper.selectById(tErpProcurement.getClinicId()); |
| | | detailProcurementVO.setClinicName(tCrmClinic.getClinicName()); |
| | | detailProcurementVO.setClinicAddress(tCrmClinic.getClinicAddress()); |
| | | detailProcurementVO.setLogisticsNumber(tErpProcurement.getLogisticsNumber()); |
| | | List<TErpProcurementGoods> list = erpProcurementGoodsService.list(new QueryWrapper<TErpProcurementGoods>().eq("procurement_id", id)); |
| | | ArrayList<DetailProcurementNextVO> detailProcurementNextVOS = new ArrayList<>(); |
| | | for (TErpProcurementGoods tErpProcurementGoods : list) { |
| | | DetailProcurementNextVO detailProcurementNextVO = new DetailProcurementNextVO(); |
| | | detailProcurementNextVO.setGoodsName(tErpProcurementGoods.getGoodsName()); |
| | | detailProcurementNextVO.setQuasiNumber(tErpProcurementGoods.getQuasiNumber()); |
| | | detailProcurementNextVO.setPackingUnitName(tErpProcurementGoods.getUnitName()); |
| | | detailProcurementNextVO.setSalesAmount(tErpProcurementGoods.getSalesAmount()); |
| | | detailProcurementNextVO.setNum(tErpProcurementGoods.getPurchaseCount()); |
| | | detailProcurementNextVO.setTotalPrice(tErpProcurement.getPayMoney()); |
| | | detailProcurementNextVO.setId(tErpProcurementGoods.getId()); |
| | | detailProcurementNextVO.setPurchasePrice(tErpProcurementGoods.getPurchasePrice()); |
| | | detailProcurementNextVOS.add(detailProcurementNextVO); |
| | | } |
| | | detailProcurementVO.setList(detailProcurementNextVOS); |
| | | return detailProcurementVO; |
| | | } |
| | | |
| | | } |