| | |
| | | package com.ruoyi.system.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | 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.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.stereotype.Service; |
| | | |
| | | 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.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 TSysCommissionMapper sysCommissionMapper; |
| | | |
| | | @Resource |
| | | private TCrmClinicMapper crmClinicMapper; |
| | | private TCrmClinicMapper crmClinicMapper; |
| | | |
| | | @Resource |
| | | private TCrmSupplierMapper crmSupplierMapper; |
| | | |
| | | @Resource |
| | | private SysUserMapper sysUserMapper; |
| | | |
| | | @Resource |
| | | private TErpGoodsMapper erpGoodsMapper; |
| | | |
| | | @Resource |
| | | private TErpGoodsTypeMapper erpGoodsTypeMapper; |
| | | |
| | | @Resource |
| | | private TErpGoodsUnitMapper erpGoodsUnitMapper; |
| | | |
| | | |
| | | |
| | | @Override |
| | | public PageInfo<TErpProcurementVo> pageList(TErpProcurementQuery query, SysUser user) { |
| | | |
| | | |
| | | 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()){ |
| | |
| | | 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); |
| | | 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<TErpProcurementGoods> tErpProcurementGoods = erpProcurementGoodsMapper.selectList |
| | | (new LambdaQueryWrapper<TErpProcurementGoods>().in(TErpProcurementGoods::getProcurementId, ids).eq(TErpProcurementGoods::getSupplierId, supplierClinicId)); |
| | | List<TSysCommission> tSysCommissions =new ArrayList<>(); |
| | | if(!tErpProcurementGoods.isEmpty()){ |
| | | List<String> collect = tErpProcurementGoods.stream().map(TErpProcurementGoods::getId).collect(Collectors.toList()); |
| | |
| | | |
| | | @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.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())); |
| | | 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; |
| | | } |
| | |
| | | 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()); |
| | | } |
| | | } |
| | | pageInfo.setRecords( list); |
| | | return pageInfo; |
| | | } |
| | | |
| | | @Override |
| | | public List<TErpGoodsVO> inventoryNotEnoughList(SysUser user) { |
| | | List<TErpGoodsVO> list = this.baseMapper.inventoryNotEnoughList(user); |
| | | |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | public String 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.setSupplierId(tErpGoodsVO.getSupplierClinicId()); |
| | | dto.setGoodsSalesAmount(tErpGoodsVO.getSalesAmount()); |
| | | } |
| | | // 供应商分组 |
| | | 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.setPayMoney(value.stream().map(AddProcurementDto::getSalesAmount).reduce(BigDecimal.ZERO, BigDecimal::add)); |
| | | AddProcurementDto addProcurementDto = value.get(0); |
| | | if(addProcurementDto.getState()!=null && addProcurementDto.getState()==1){ |
| | | tErpProcurement.setStatus(1); |
| | | }else { |
| | | tErpProcurement.setStatus(2); |
| | | } |
| | | this.save(tErpProcurement); |
| | | 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.setPurchaseCount(dto.getPurchaseCount()); |
| | | tErpProcurementGoods.setSupplierId(supplierClinicId); |
| | | tErpProcurementGoods.setRecvMerchantNo(supplier.getRecvMerchantNo()); |
| | | } |
| | | |
| | | } |
| | | |
| | | return ""; |
| | | } |
| | | |
| | | } |