|  |  |  | 
|---|
|  |  |  | 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.core.exception.ServiceException; | 
|---|
|  |  |  | import com.ruoyi.common.utils.DateUtils; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.ruoyi.system.vo.*; | 
|---|
|  |  |  | import org.apache.poi.ss.formula.functions.T; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Propagation; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.annotation.Resource; | 
|---|
|  |  |  | import java.math.BigDecimal; | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | public void warehousingGoods(List<WarehousingGoodsDto> dtos, SysUser user) { | 
|---|
|  |  |  | Integer roleType = user.getRoleType(); | 
|---|
|  |  |  | String supplierClinicId = null; | 
|---|
|  |  |  | 
|---|
|  |  |  | for (WarehousingGoodsDto dto : dtos) { | 
|---|
|  |  |  | TErpSupplierWarehousing tErpSupplierWarehousing = new TErpSupplierWarehousing(); | 
|---|
|  |  |  | // 当前年月日时分秒 | 
|---|
|  |  |  | String time = DateUtils.dateTimeNow(); | 
|---|
|  |  |  | tErpSupplierWarehousing.setWarehouseNo("G"+time); | 
|---|
|  |  |  | // 查询上一个入库单 | 
|---|
|  |  |  | TErpSupplierWarehousing last = erpSupplierWarehousingMapper.selectOne(new LambdaQueryWrapper<TErpSupplierWarehousing>().orderByDesc(TErpSupplierWarehousing::getCreateTime).last("LIMIT 1")); | 
|---|
|  |  |  | if(last==null){ | 
|---|
|  |  |  | tErpSupplierWarehousing.setWarehouseNo("G"+DateUtils.dateTimeNow()+"00001"); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | String lastProcurementCode = last.getWarehouseNo(); | 
|---|
|  |  |  | String datePart = "G" + DateUtils.dateTimeNow(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 直接获取后五位数字并+1,不考虑是否同一天 | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | String numberPart = lastProcurementCode.substring(Math.max(0, lastProcurementCode.length() - 5)); | 
|---|
|  |  |  | int number = Integer.parseInt(numberPart); | 
|---|
|  |  |  | if (number < 99999) { | 
|---|
|  |  |  | number++; | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | number = 2; // 达到99999后重置为00002 | 
|---|
|  |  |  | } | 
|---|
|  |  |  | tErpSupplierWarehousing.setWarehouseNo(datePart + String.format("%05d", number)); | 
|---|
|  |  |  | } catch (NumberFormatException e) { | 
|---|
|  |  |  | // 如果解析失败,默认从00001开始 | 
|---|
|  |  |  | tErpSupplierWarehousing.setWarehouseNo(datePart + "00001"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | tErpSupplierWarehousing.setSupplierId(supplierClinicId); | 
|---|
|  |  |  | tErpSupplierWarehousing.setWarehouseId(dto.getWarehouseId()); | 
|---|
|  |  |  | tErpSupplierWarehousing.setGoodsId(dto.getGoodsId()); | 
|---|
|  |  |  | 
|---|
|  |  |  | tErpSupplierWarehousing.setTotalPrice(dto.getTotalPrice()); | 
|---|
|  |  |  | List<WarehousingGoodsNextDto> warehousingGoodsNextDtos = dto.getWarehousingGoodsNextDtos(); | 
|---|
|  |  |  | int sum = warehousingGoodsNextDtos.stream().mapToInt(WarehousingGoodsNextDto::getWarehousingNum).sum(); | 
|---|
|  |  |  | tErpSupplierWarehousing.setGoodsCount( sum); | 
|---|
|  |  |  | erpSupplierWarehousingMapper.insert(tErpSupplierWarehousing); | 
|---|
|  |  |  | tErpSupplierWarehousing.setGoodsCount(sum); | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | erpSupplierWarehousingMapper.insert(tErpSupplierWarehousing); | 
|---|
|  |  |  | }catch (Exception e){ | 
|---|
|  |  |  | throw new RuntimeException("网络繁忙,请重试"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (WarehousingGoodsNextDto warehousingGoodsNextDto : warehousingGoodsNextDtos) { | 
|---|
|  |  |  | TErpSupplierWarehousingBatch tErpSupplierWarehousingBatch = new TErpSupplierWarehousingBatch(); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED) | 
|---|
|  |  |  | public void outbountGoods(OutboundGoodsDto dto, SysUser user) { | 
|---|
|  |  |  | Integer roleType = user.getRoleType(); | 
|---|
|  |  |  | String supplierClinicId = null; | 
|---|
|  |  |  | 
|---|
|  |  |  | tErpSupplierOutbound.setWarehouseId(dto.getWarehouseId()); | 
|---|
|  |  |  | tErpSupplierOutbound.setSupplierId(supplierClinicId); | 
|---|
|  |  |  | tErpSupplierOutbound.setTotalMoney(add); | 
|---|
|  |  |  | String s = DateUtils.dateTimeNow(); | 
|---|
|  |  |  | tErpSupplierOutbound.setOutboundNumber("G" + s); | 
|---|
|  |  |  | TErpSupplierOutbound last = erpSupplierOutboundMapper.selectOne(new LambdaQueryWrapper<TErpSupplierOutbound>().orderByDesc(BaseModel::getCreateTime).last("LIMIT 1")); | 
|---|
|  |  |  | if(last==null){ | 
|---|
|  |  |  | tErpSupplierOutbound.setOutboundNumber("G" +  DateUtils.dateTimeNow()+ "00001"); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | String lastProcurementCode = last.getOutboundNumber(); | 
|---|
|  |  |  | String datePart = "G" + DateUtils.dateTimeNow(); | 
|---|
|  |  |  | // 直接获取后五位数字并+1,不考虑是否同一天 | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | String numberPart = lastProcurementCode.substring(Math.max(0, lastProcurementCode.length() - 5)); | 
|---|
|  |  |  | int number = Integer.parseInt(numberPart); | 
|---|
|  |  |  | if (number < 99999) { | 
|---|
|  |  |  | number++; | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | number = 2; // 达到99999后重置为00002 | 
|---|
|  |  |  | } | 
|---|
|  |  |  | tErpSupplierOutbound.setOutboundNumber(datePart + String.format("%05d", number)); | 
|---|
|  |  |  | } catch (NumberFormatException e) { | 
|---|
|  |  |  | // 如果解析失败,默认从00001开始 | 
|---|
|  |  |  | tErpSupplierOutbound.setOutboundNumber(datePart + "00001"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | tErpSupplierOutbound.setGoodsId(tErpSupplierWarehousing.getGoodsId()); | 
|---|
|  |  |  | erpSupplierOutboundMapper.insert(tErpSupplierOutbound); | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | erpSupplierOutboundMapper.insert(tErpSupplierOutbound); | 
|---|
|  |  |  | }catch (Exception e){ | 
|---|
|  |  |  | throw new RuntimeException("网络繁忙,请重试"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (TErpSupplierOutboundGoods tErpSupplierOutboundGoods2 : arrayList) { | 
|---|
|  |  |  | tErpSupplierOutboundGoods2.setOutboundId(tErpSupplierOutbound.getId()); | 
|---|