| | |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDateTime; |
| | | import java.util.Collections; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | |
| | | @Resource |
| | | private TErpSupplierInventoryMapper erpSupplierInventoryMapper; |
| | | @Resource |
| | | private TErpClinicInventoryMapper erpClinicInventoryMapper; |
| | | |
| | | @Resource |
| | | private TErpSupplierInventoryGoodsMapper erpSupplierInventoryGoodsMapper; |
| | | @Resource |
| | | private TErpClinicInventoryGoodsMapper erpClinicInventoryGoodsMapper; |
| | | |
| | | @Resource |
| | | private TErpSupplierWarehousingMapper erpSupplierWarehousingMapper; |
| | | @Resource |
| | | private TErpClinicWarehousingMapper erpClinicWarehousingMapper; |
| | | |
| | | @Resource |
| | | private TErpSupplierWarehousingBatchMapper erpSupplierWarehousingBatchMapper; |
| | | @Resource |
| | | private TErpClinicWarehousingBatchMapper erpClinicWarehousingBatchMapper; |
| | | |
| | | @Resource |
| | | private TErpSupplierOutboundMapper erpSupplierOutboundMapper; |
| | | @Resource |
| | | private TErpClinicOutboundMapper erpClinicOutboundMapper; |
| | | |
| | | @Resource |
| | | private TErpSupplierOutboundGoodsMapper erpSupplierOutboundGoodsMapper; |
| | | @Resource |
| | | private TErpClinicOutboundGoodsMapper erpClinicOutboundGoodsMapper; |
| | | |
| | | @Resource |
| | | private TCrmClinicMapper crmClinicMapper; |
| | |
| | | .last("LIMIT 1")); |
| | | supplierClinicId =crmClinic.getId(); |
| | | } |
| | | |
| | | // 当前时间一个月后 |
| | | Date endDate = DateUtils.addMonths(DateUtils.getNowDate(), 1); |
| | | |
| | | PageInfo<TErpGoodsInventoryVO> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize()); |
| | | List<TErpGoodsInventoryVO> list = this.baseMapper.pageInventoryGoodsPageList(query, pageInfo, user,supplierClinicId); |
| | | List<TErpGoodsInventoryVO> list = this.baseMapper.pageInventoryGoodsPageList(query, pageInfo, user,supplierClinicId,endDate); |
| | | if (list.isEmpty()) { |
| | | return pageInfo; |
| | | } |
| | |
| | | } |
| | | pageInfo.setRecords(list); |
| | | return pageInfo; |
| | | } |
| | | @Override |
| | | public PageInfo<TErpGoodsInventoryVO> pageInventoryGoodsPageList1(TErpGoodsInventoryQuery 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(); |
| | | } |
| | | |
| | | // 当前时间一个月后 |
| | | Date endDate = DateUtils.addMonths(DateUtils.getNowDate(), 1); |
| | | |
| | | PageInfo<TErpGoodsInventoryVO> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize()); |
| | | List<TErpGoodsInventoryVO> list = this.baseMapper.pageInventoryGoodsPageList1(query, pageInfo, user,supplierClinicId,endDate); |
| | | if (list.isEmpty()) { |
| | | return pageInfo; |
| | | } |
| | | List<String> typeIds = list.stream().map(TErpGoodsInventoryVO::getTypeId).collect(Collectors.toList()); |
| | | if (!typeIds.isEmpty()) { |
| | | List<TErpGoodsType> typeList = erpGoodsTypeMapper.selectBatchIds(typeIds); |
| | | for (TErpGoodsInventoryVO tErpGoodsVO : list) { |
| | | typeList.stream().filter(t -> t.getId().equals(tErpGoodsVO.getTypeId())).findFirst().ifPresent(t -> tErpGoodsVO.setTypeName(t.getTypeName())); |
| | | tErpGoodsVO.setTypeName(tErpGoodsVO.getTypeName()); |
| | | } |
| | | } |
| | | List<String> packingUnitId = list.stream().map(TErpGoodsInventoryVO::getPackingUnitId).collect(Collectors.toList()); |
| | | if (!packingUnitId.isEmpty()) { |
| | | List<TErpGoodsUnit> tErpGoodsUnits = erpGoodsUnitMapper.selectBatchIds(packingUnitId); |
| | | for (TErpGoodsInventoryVO tErpGoodsVO : list) { |
| | | tErpGoodsUnits.stream().filter(t -> t.getId().equals(tErpGoodsVO.getPackingUnitId())).findFirst().ifPresent(t -> tErpGoodsVO.setPackingUnitName(t.getUnitName())); |
| | | } |
| | | } |
| | | pageInfo.setRecords(list); |
| | | return pageInfo; |
| | | } |
| | | @Override |
| | | public List<TErpGoodsInventoryVO> pageInventoryGoodsList(String warehouseId, 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(); |
| | | } |
| | | |
| | | // 当前时间一个月后 |
| | | Date endDate = DateUtils.addMonths(DateUtils.getNowDate(), 1); |
| | | |
| | | List<TErpGoodsInventoryVO> list = this.baseMapper.pageInventoryGoodsList(warehouseId, user,supplierClinicId,endDate); |
| | | if (list.isEmpty()) { |
| | | return list; |
| | | } |
| | | List<String> typeIds = list.stream().map(TErpGoodsInventoryVO::getTypeId).collect(Collectors.toList()); |
| | | if (!typeIds.isEmpty()) { |
| | | List<TErpGoodsType> typeList = erpGoodsTypeMapper.selectBatchIds(typeIds); |
| | | for (TErpGoodsInventoryVO tErpGoodsVO : list) { |
| | | typeList.stream().filter(t -> t.getId().equals(tErpGoodsVO.getTypeId())).findFirst().ifPresent(t -> tErpGoodsVO.setTypeName(t.getTypeName())); |
| | | tErpGoodsVO.setTypeName(tErpGoodsVO.getTypeName()); |
| | | } |
| | | } |
| | | List<String> packingUnitId = list.stream().map(TErpGoodsInventoryVO::getPackingUnitId).collect(Collectors.toList()); |
| | | if (!packingUnitId.isEmpty()) { |
| | | List<TErpGoodsUnit> tErpGoodsUnits = erpGoodsUnitMapper.selectBatchIds(packingUnitId); |
| | | for (TErpGoodsInventoryVO tErpGoodsVO : list) { |
| | | tErpGoodsUnits.stream().filter(t -> t.getId().equals(tErpGoodsVO.getPackingUnitId())).findFirst().ifPresent(t -> tErpGoodsVO.setPackingUnitName(t.getUnitName())); |
| | | } |
| | | } |
| | | return list; |
| | | } |
| | | @Override |
| | | public List<TErpGoodsInventoryVO> pageInventoryGoodsList1(String warehouseId, 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(); |
| | | } |
| | | |
| | | // 当前时间一个月后 |
| | | Date endDate = DateUtils.addMonths(DateUtils.getNowDate(), 1); |
| | | |
| | | List<TErpGoodsInventoryVO> list = this.baseMapper.pageInventoryGoodsList1(warehouseId, user,supplierClinicId,endDate); |
| | | if (list.isEmpty()) { |
| | | return list; |
| | | } |
| | | List<String> typeIds = list.stream().map(TErpGoodsInventoryVO::getTypeId).collect(Collectors.toList()); |
| | | if (!typeIds.isEmpty()) { |
| | | List<TErpGoodsType> typeList = erpGoodsTypeMapper.selectBatchIds(typeIds); |
| | | for (TErpGoodsInventoryVO tErpGoodsVO : list) { |
| | | typeList.stream().filter(t -> t.getId().equals(tErpGoodsVO.getTypeId())).findFirst().ifPresent(t -> tErpGoodsVO.setTypeName(t.getTypeName())); |
| | | tErpGoodsVO.setTypeName(tErpGoodsVO.getTypeName()); |
| | | } |
| | | } |
| | | List<String> packingUnitId = list.stream().map(TErpGoodsInventoryVO::getPackingUnitId).collect(Collectors.toList()); |
| | | if (!packingUnitId.isEmpty()) { |
| | | List<TErpGoodsUnit> tErpGoodsUnits = erpGoodsUnitMapper.selectBatchIds(packingUnitId); |
| | | for (TErpGoodsInventoryVO tErpGoodsVO : list) { |
| | | tErpGoodsUnits.stream().filter(t -> t.getId().equals(tErpGoodsVO.getPackingUnitId())).findFirst().ifPresent(t -> tErpGoodsVO.setPackingUnitName(t.getUnitName())); |
| | | } |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | @Override |
| | |
| | | TErpSupplierOutbound tErpSupplierOutbound = new TErpSupplierOutbound(); |
| | | tErpSupplierOutbound.setWarehouseId(dto.getWarehouseId()); |
| | | tErpSupplierOutbound.setSupplierId(supplierClinicId); |
| | | tErpSupplierOutbound.setGoodsId(tErpSupplierWarehousing1.getGoodsId()); |
| | | tErpSupplierOutbound.setOutboundType(6); |
| | | tErpSupplierOutbound.setOutboundNumber("G" + s); |
| | | int count = inventoryGoodsDto.getNum() - inventoryGoodsDto.getInventoryCount(); |
| | | tErpSupplierOutbound.setTotalMoney(erpGoods.getSalesAmount().multiply(new BigDecimal(count))); |
| | | tErpSupplierOutbound.setGoodsId(erpGoods.getId()); |
| | | erpSupplierOutboundMapper.insert(tErpSupplierOutbound); |
| | | |
| | | |
| | | TErpSupplierOutboundGoods tErpSupplierOutboundGoods = new TErpSupplierOutboundGoods(); |
| | | tErpSupplierOutboundGoods.setOutboundId(tErpSupplierOutbound.getId()); |
| | | tErpSupplierOutboundGoods.setWarehousingId(tErpSupplierWarehousing.getId()); |
| | | tErpSupplierOutboundGoods.setWarehousingId(tErpSupplierWarehousing1.getId()); |
| | | tErpSupplierOutboundGoods.setWarehousingBatchId(tErpSupplierWarehousingBatch.getId()); |
| | | tErpSupplierOutboundGoods.setOutboundCount(count); |
| | | tErpSupplierOutboundGoods.setTotalPrice(erpGoods.getSalesAmount().multiply(new BigDecimal(count))); |
| | | erpSupplierOutboundGoodsMapper.insert(tErpSupplierOutboundGoods); |
| | | |
| | | |
| | | // 添加盘点信息 |
| | | TErpSupplierInventoryGoods tErpSupplierInventoryGoods = new TErpSupplierInventoryGoods(); |
| | | tErpSupplierInventoryGoods.setInventoryId(tErpSupplierInventory.getId()); |
| | | tErpSupplierInventoryGoods.setWarehousingId(tErpSupplierOutbound.getId()); |
| | | tErpSupplierInventoryGoods.setWarehousingBatchId(tErpSupplierOutboundGoods.getId()); |
| | | tErpSupplierInventoryGoods.setInventoryCount(inventoryGoodsDto.getInventoryCount()); |
| | | tErpSupplierInventoryGoods.setDamagedCount(inventoryGoodsDto.getDamagedCount()); |
| | | tErpSupplierInventoryGoods.setInventoryType(2); |
| | | tErpSupplierInventoryGoods.setGoodsId(tErpSupplierWarehousing1.getGoodsId()); |
| | | erpSupplierInventoryGoodsMapper.insert(tErpSupplierInventoryGoods); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| | | @Override |
| | | public void inventoryGoods1(InventoryDto dto, 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(); |
| | | } |
| | | TErpClinicInventory tErpSupplierInventory = new TErpClinicInventory(); |
| | | String s = DateUtils.dateTimeNow(); |
| | | tErpSupplierInventory.setInventoryNumber("P" + s); |
| | | tErpSupplierInventory.setClinicId(supplierClinicId); |
| | | erpClinicInventoryMapper.insert(tErpSupplierInventory); |
| | | |
| | | List<InventoryGoodsDto> dtos = dto.getDtos(); |
| | | for (InventoryGoodsDto inventoryGoodsDto : dtos) { |
| | | // 根据入库批次id查询入库信息 |
| | | TErpClinicWarehousing tErpSupplierWarehousing = new TErpClinicWarehousing(); |
| | | TErpClinicWarehousingBatch tErpSupplierWarehousingBatch = erpClinicWarehousingBatchMapper.selectById(inventoryGoodsDto.getId()); |
| | | String warehousingId = tErpSupplierWarehousingBatch.getWarehousingId(); |
| | | TErpClinicWarehousing tErpSupplierWarehousing1 = erpClinicWarehousingMapper.selectById(warehousingId); |
| | | TErpGoods erpGoods = this.getById(tErpSupplierWarehousing1.getGoodsId()); |
| | | |
| | | // 盘点是盘亏盘盈 赢 |
| | | if (inventoryGoodsDto.getNum() < inventoryGoodsDto.getInventoryCount()) { |
| | | // 添加入库信息 |
| | | tErpSupplierWarehousing.setClinicId(supplierClinicId); |
| | | tErpSupplierWarehousing.setGoodsId(tErpSupplierWarehousing1.getGoodsId()); |
| | | tErpSupplierWarehousing.setGoodsName(erpGoods.getGoodsName()); |
| | | tErpSupplierWarehousing.setPurchaseCount(inventoryGoodsDto.getInventoryCount() - inventoryGoodsDto.getNum()); |
| | | tErpSupplierWarehousing.setUnitAmount(erpGoods.getSalesAmount()); |
| | | tErpSupplierWarehousing.setTotalPrice(erpGoods.getSalesAmount().multiply(new BigDecimal(tErpSupplierWarehousing.getPurchaseCount()))); |
| | | // 当前年月日时分秒 |
| | | String time = DateUtils.dateTimeNow(); |
| | | tErpSupplierWarehousing.setWarehouseNo("G" + time); |
| | | tErpSupplierWarehousing.setType(2); |
| | | erpClinicWarehousingMapper.insert(tErpSupplierWarehousing); |
| | | |
| | | // 添加批次信息 |
| | | TErpSupplierWarehousingBatch tErpSupplierWarehousingBatch1 = new TErpSupplierWarehousingBatch(); |
| | | tErpSupplierWarehousingBatch1.setWarehousingId(tErpSupplierWarehousing.getId()); |
| | | tErpSupplierWarehousingBatch1.setWarehousingNumber(tErpSupplierWarehousing.getPurchaseCount()); |
| | | tErpSupplierWarehousingBatch1.setBatchNumber(tErpSupplierWarehousingBatch.getBatchNumber()); |
| | | tErpSupplierWarehousingBatch1.setProductionDate(tErpSupplierWarehousingBatch.getProductionDate()); |
| | | tErpSupplierWarehousingBatch1.setExpiryDate(tErpSupplierWarehousingBatch.getExpiryDate()); |
| | | erpSupplierWarehousingBatchMapper.insert(tErpSupplierWarehousingBatch1); |
| | | |
| | | |
| | | // 添加盘点信息 |
| | | TErpSupplierInventoryGoods tErpSupplierInventoryGoods = new TErpSupplierInventoryGoods(); |
| | | tErpSupplierInventoryGoods.setInventoryId(tErpSupplierInventory.getId()); |
| | | tErpSupplierInventoryGoods.setWarehousingId(tErpSupplierWarehousing.getId()); |
| | | tErpSupplierInventoryGoods.setWarehousingBatchId(tErpSupplierWarehousingBatch1.getId()); |
| | | tErpSupplierInventoryGoods.setInventoryCount(inventoryGoodsDto.getInventoryCount()); |
| | | tErpSupplierInventoryGoods.setDamagedCount(inventoryGoodsDto.getDamagedCount()); |
| | | tErpSupplierInventoryGoods.setInventoryType(1); |
| | | tErpSupplierInventoryGoods.setGoodsId(tErpSupplierWarehousing1.getGoodsId()); |
| | | erpSupplierInventoryGoodsMapper.insert(tErpSupplierInventoryGoods); |
| | | |
| | | } else { |
| | | |
| | | |
| | | TErpSupplierOutbound tErpSupplierOutbound = new TErpSupplierOutbound(); |
| | | tErpSupplierOutbound.setWarehouseId(dto.getWarehouseId()); |
| | | tErpSupplierOutbound.setSupplierId(supplierClinicId); |
| | | tErpSupplierOutbound.setOutboundType(6); |
| | | tErpSupplierOutbound.setOutboundNumber("G" + s); |
| | | int count = inventoryGoodsDto.getNum() - inventoryGoodsDto.getInventoryCount(); |
| | | tErpSupplierOutbound.setTotalMoney(erpGoods.getSalesAmount().multiply(new BigDecimal(count))); |
| | | erpSupplierOutboundMapper.insert(tErpSupplierOutbound); |
| | | |
| | | |
| | | TErpSupplierOutboundGoods tErpSupplierOutboundGoods = new TErpSupplierOutboundGoods(); |
| | | tErpSupplierOutboundGoods.setOutboundId(tErpSupplierOutbound.getId()); |
| | | tErpSupplierOutboundGoods.setWarehousingId(tErpSupplierWarehousing1.getId()); |
| | | tErpSupplierOutboundGoods.setWarehousingBatchId(tErpSupplierWarehousingBatch.getId()); |
| | | tErpSupplierOutboundGoods.setOutboundCount(count); |
| | | tErpSupplierOutboundGoods.setTotalPrice(erpGoods.getSalesAmount().multiply(new BigDecimal(count))); |