| | |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.framework.web.service.TokenService; |
| | | import com.ruoyi.system.dto.AddProcurementDto; |
| | | import com.ruoyi.system.dto.DetailProcurementSendDto; |
| | | import com.ruoyi.system.dto.UpdateStatusProcurementDto; |
| | | import com.ruoyi.system.dto.UpdateStatusProcurementLastDto; |
| | | import com.ruoyi.system.model.*; |
| | |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.apache.poi.ss.formula.functions.T; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.validation.Valid; |
| | |
| | | private final TCrmBranchService crmBranchService; |
| | | private final TCrmSalespersonService crmSalespersonService; |
| | | private final TErpProcurementCommissionService erpProcurementCommissionService; |
| | | private final TCrmWarehouseService crmWarehouseService; |
| | | |
| | | |
| | | |
| | | @Autowired |
| | | public TErpProcurementController(TErpProcurementService erpProcurementService, TokenService tokenService, TCrmClinicService crmClinicService, TErpProcurementGoodsService erpProcurementGoodsService |
| | | , TErpGoodsService erpGoodsService, TErpClinicWarehousingService erpClinicWarehousingService, TErpClinicWarehousingBatchService erpClinicWarehousingBatchService, |
| | | TCrmSupplierService crmSupplierService, TErpMaintenanceReminderService erpMaintenanceReminderService, TSysOtherConfigService sysOtherConfigService, TCrmClinicPointsService crmClinicPointsService, TCrmChangePointsService crmChangePointsService, TCrmBranchService crmBranchService, TCrmSalespersonService crmSalespersonService, TErpProcurementCommissionService erpProcurementCommissionService) { |
| | | TCrmSupplierService crmSupplierService, TErpMaintenanceReminderService erpMaintenanceReminderService, TSysOtherConfigService sysOtherConfigService, TCrmClinicPointsService crmClinicPointsService, TCrmChangePointsService crmChangePointsService, TCrmBranchService crmBranchService, TCrmSalespersonService crmSalespersonService, TErpProcurementCommissionService erpProcurementCommissionService, TCrmWarehouseService crmWarehouseService) { |
| | | this.erpProcurementService = erpProcurementService; |
| | | this.tokenService = tokenService; |
| | | this.crmClinicService = crmClinicService; |
| | |
| | | this.crmSalespersonService = crmSalespersonService; |
| | | this.erpProcurementCommissionService = erpProcurementCommissionService; |
| | | |
| | | this.crmWarehouseService = crmWarehouseService; |
| | | |
| | | } |
| | | |
| | | |
| | |
| | | SysUser user = tokenService.getLoginUser().getUser(); |
| | | return R.ok(erpProcurementService.pageList(query,user)); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * erp采购管理分页列表 |
| | | */ |
| | | @ApiOperation(value = "erp采购管理分页列表--仓库专用") |
| | | @PostMapping(value = "/pageListWarehouse") |
| | | public R<PageInfo<TErpProcurementVo>> pageListWarehouse(@RequestBody TErpProcurementQuery query) { |
| | | SysUser user = tokenService.getLoginUser().getUser(); |
| | | return R.ok(erpProcurementService.pageListWarehouse(query,user)); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | |
| | | return R.ok(); |
| | | } |
| | | |
| | | @ApiOperation(value = "删除采购") |
| | | @DeleteMapping(value = "/delProcurement/{id}") |
| | | public R<String> delProcurement(@PathVariable String id) { |
| | | SysUser user = tokenService.getLoginUser().getUser(); |
| | | Integer roleType = user.getRoleType(); |
| | | String clinicSupplierId=null; |
| | | if(roleType == 5){ |
| | | // 诊所 |
| | | TCrmClinic crmClinic = crmClinicService.getOne(Wrappers.lambdaQuery(TCrmClinic.class) |
| | | .eq(TCrmClinic::getUserId, user.getUserId()) |
| | | .last("LIMIT 1")); |
| | | clinicSupplierId = crmClinic.getId(); |
| | | } |
| | | TErpProcurement tErpProcurement = erpProcurementService.getById(id); |
| | | if(tErpProcurement.getClinicId().equals(clinicSupplierId)){ |
| | | erpProcurementService.removeById( id); |
| | | return R.ok(); |
| | | }else { |
| | | return R.fail("无权限"); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | |
| | | |
| | | return R.ok( erpProcurementService.detailProcurement(clinicSupplierId, user, id)); |
| | | } |
| | | |
| | | |
| | | @ApiOperation(value = "采购详情--发货(仓库角色)") |
| | | @PostMapping(value = "/detailProcurementSend") |
| | | public R<?> detailProcurementSend(@RequestBody DetailProcurementSendDto dto) { |
| | | SysUser user = tokenService.getLoginUser().getUser(); |
| | | Integer roleType = user.getRoleType(); |
| | | List<String> clinicSupplierId=null; |
| | | if(roleType == 6){ |
| | | |
| | | TCrmWarehouse warehouse = crmWarehouseService.getOne(Wrappers.lambdaQuery(TCrmWarehouse.class) |
| | | .eq(TCrmWarehouse::getUserId, user.getUserId()) |
| | | .last("LIMIT 1")); |
| | | |
| | | // 供应商 |
| | | clinicSupplierId = crmSupplierService.list(Wrappers.lambdaQuery(TCrmSupplier.class) |
| | | .eq(TCrmSupplier::getWarehouseId, warehouse.getId())).stream().map(TCrmSupplier::getId).collect(Collectors.toList()); |
| | | } |
| | | erpProcurementService.detailProcurementSend(clinicSupplierId, user, dto.getId(),dto.getLogisticsNumber()); |
| | | return R.ok(); |
| | | } |
| | | |
| | | // @ApiOperation(value = "采购详情--仓库角色专用") |
| | | // @GetMapping(value = "/detailProcurementWarehouse/{id}") |
| | | // public R<DetailProcurementVO> detailProcurementWarehouse(@PathVariable String id) { |
| | | // SysUser user = tokenService.getLoginUser().getUser(); |
| | | // Integer roleType = user.getRoleType(); |
| | | // String clinicSupplierId=null; |
| | | // if(roleType == 5){ |
| | | // // 诊所 |
| | | // TCrmClinic crmClinic = crmClinicService.getOne(Wrappers.lambdaQuery(TCrmClinic.class) |
| | | // .eq(TCrmClinic::getUserId, user.getUserId()) |
| | | // .last("LIMIT 1")); |
| | | // clinicSupplierId = crmClinic.getId(); |
| | | // } |
| | | // |
| | | // return R.ok( erpProcurementService.detailProcurementWarehouse(clinicSupplierId, user, id)); |
| | | // } |
| | | |
| | | |
| | | |
| | | |
| | | @ApiOperation(value = "采购草稿") |
| | | @GetMapping(value = "/getProcurementDraft") |
| | | public R<ArrayList<DetailProcurementNextVO>> getProcurementDraft() { |
| | |
| | | clinicSupplierId = crmClinic.getId(); |
| | | } |
| | | ArrayList<DetailProcurementNextVO> detailProcurementNextVOS = new ArrayList<>(); |
| | | List<TErpProcurement> list1 = erpProcurementService.list(new LambdaQueryWrapper<TErpProcurement>().eq(TErpProcurement::getStatus, 1).orderByDesc(TErpProcurement::getCreateTime)); |
| | | List<TErpProcurement> list1 = erpProcurementService.list(new LambdaQueryWrapper<TErpProcurement>().eq(TErpProcurement::getClinicId, clinicSupplierId).eq(TErpProcurement::getStatus, 1).orderByDesc(TErpProcurement::getCreateTime)); |
| | | if(list1.isEmpty()){ |
| | | return R.ok(detailProcurementNextVOS); |
| | | } |
| | |
| | | |
| | | @ApiOperation(value = "采购详情入库") |
| | | @PostMapping(value = "/updateStatusProcurement") |
| | | public R<DetailProcurementVO> updateStatusProcurement(@RequestParam @Valid UpdateStatusProcurementLastDto dto) { |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R<DetailProcurementVO> updateStatusProcurement(@RequestBody @Valid UpdateStatusProcurementLastDto dto) { |
| | | SysUser user = tokenService.getLoginUser().getUser(); |
| | | Integer roleType = user.getRoleType(); |
| | | String clinicSupplierId=null; |
| | |
| | | return R.fail("目前状态无法入库"); |
| | | } |
| | | erpProcurement.setStatus(5); |
| | | erpProcurement.setWarehousingUserId(user.getUserId().toString()); |
| | | erpProcurement.setWarehousingTime(LocalDateTime.now()); |
| | | erpProcurementService.updateById(erpProcurement); |
| | | |
| | | List<String> collect = dto.getList().stream().map(UpdateStatusProcurementDto::getId).collect(Collectors.toList()); |
| | |
| | | // tErpClinicWarehousing.setUnitAmount(tErpProcurementGoods.getSalesAmount()); |
| | | tErpClinicWarehousing.setWarehousingType(1); |
| | | tErpClinicWarehousing.setType(1); |
| | | tErpClinicWarehousing.setWarehouseNo("G"+ DateUtils.dateTimeNow()); |
| | | erpClinicWarehousingService.save(tErpClinicWarehousing); |
| | | |
| | | TErpClinicWarehousing last = erpClinicWarehousingService.getOne(new LambdaQueryWrapper<TErpClinicWarehousing>().orderByDesc(BaseModel::getCreateTime).orderByDesc(TErpClinicWarehousing::getWarehouseNo).last("LIMIT 1")); |
| | | if(last==null){ |
| | | tErpClinicWarehousing.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 |
| | | } |
| | | tErpClinicWarehousing.setWarehouseNo(datePart + String.format("%05d", number)); |
| | | } catch (NumberFormatException e) { |
| | | // 如果解析失败,默认从00001开始 |
| | | tErpClinicWarehousing.setWarehouseNo(datePart + "00001"); |
| | | } |
| | | } |
| | | tErpClinicWarehousing.setProcurementId(erpProcurement.getId()); |
| | | try { |
| | | erpClinicWarehousingService.save(tErpClinicWarehousing); |
| | | }catch (Exception e){ |
| | | throw new RuntimeException("网络繁忙,请重试"); |
| | | } |
| | | // goodsId分组 |
| | | for (UpdateStatusProcurementDto updateStatusProcurementDto : dto.getList()) { |
| | | TErpProcurementGoods tErpProcurementGoods = list.stream().filter(t -> t.getId().equals(updateStatusProcurementDto.getId())).findFirst().get(); |
| | |
| | | tCrmChangePoints.setChangeValue(points); |
| | | crmChangePointsService.save(tCrmChangePoints); |
| | | |
| | | branch.setUserPoints(branch.getUserPoints()+points); |
| | | crmBranchService.updateById(branch); |
| | | |
| | | |
| | | // 分佣 |
| | | BigDecimal commission = branch.getMoneyCommission().divide(BigDecimal.valueOf(100), 4, RoundingMode.HALF_DOWN).multiply(payMoney).setScale(2, RoundingMode.HALF_UP); |
| | |
| | | tErpProcurementCommission.setProcurementId(erpProcurement.getId()); |
| | | tErpProcurementCommission.setCommissionType(1); |
| | | tErpProcurementCommission.setBranchSalespersonId(branchId); |
| | | tErpProcurementCommission.setMoney(commission.doubleValue()); |
| | | tErpProcurementCommission.setMoney(commission); |
| | | erpProcurementCommissionService.save(tErpProcurementCommission); |
| | | |
| | | } |
| | |
| | | tCrmChangePoints.setChangeReason(1); |
| | | tCrmChangePoints.setChangeValue(points); |
| | | crmChangePointsService.save(tCrmChangePoints); |
| | | salesperson.setUserPoints(salesperson.getUserPoints()+points); |
| | | crmSalespersonService.updateById(salesperson); |
| | | |
| | | |
| | | |
| | |
| | | tErpProcurementCommission.setProcurementId(erpProcurement.getId()); |
| | | tErpProcurementCommission.setCommissionType(2); |
| | | tErpProcurementCommission.setBranchSalespersonId(salespersonId); |
| | | tErpProcurementCommission.setMoney(commission.doubleValue()); |
| | | tErpProcurementCommission.setMoney(commission); |
| | | erpProcurementCommissionService.save(tErpProcurementCommission); |
| | | } |
| | | |