| | |
| | | package com.ruoyi.web.controller.api; |
| | | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.lkl.laop.sdk.request.V3LabsTransPreorderRequest; |
| | | import com.ruoyi.common.basic.PageInfo; |
| | | import com.ruoyi.common.core.domain.BaseModel; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.framework.web.service.TokenService; |
| | | import com.ruoyi.system.dto.AddProcurementDto; |
| | | import com.ruoyi.system.model.TCrmClinic; |
| | | import com.ruoyi.system.model.TCrmSupplier; |
| | | import com.ruoyi.system.model.TErpGoods; |
| | | import com.ruoyi.system.dto.UpdateStatusProcurementDto; |
| | | import com.ruoyi.system.dto.UpdateStatusProcurementLastDto; |
| | | import com.ruoyi.system.model.*; |
| | | import com.ruoyi.system.query.TErpGoodsQuery; |
| | | import com.ruoyi.system.query.TErpProcurementQuery; |
| | | import com.ruoyi.system.service.TCrmClinicService; |
| | | import com.ruoyi.system.service.TErpProcurementService; |
| | | import com.ruoyi.system.service.TErpSupplierWarehousingService; |
| | | import com.ruoyi.system.vo.TErpGoodsVO; |
| | | import com.ruoyi.system.vo.TErpProcurementDetailVo; |
| | | import com.ruoyi.system.vo.TErpProcurementVo; |
| | | import com.ruoyi.system.service.*; |
| | | import com.ruoyi.system.vo.*; |
| | | import com.ruoyi.web.core.config.LakalaConfig; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.apache.poi.ss.formula.functions.T; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.validation.Valid; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.time.LocalDateTime; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | private final TErpProcurementService erpProcurementService; |
| | | private final TokenService tokenService; |
| | | private final TCrmClinicService crmClinicService; |
| | | private final TErpProcurementGoodsService erpProcurementGoodsService; |
| | | private final TErpGoodsService erpGoodsService; |
| | | private final TErpClinicWarehousingService erpClinicWarehousingService; |
| | | private final TErpClinicWarehousingBatchService erpClinicWarehousingBatchService; |
| | | private final TCrmSupplierService crmSupplierService; |
| | | private final TErpMaintenanceReminderService erpMaintenanceReminderService; |
| | | private final TSysOtherConfigService sysOtherConfigService; |
| | | private final TCrmClinicPointsService crmClinicPointsService; |
| | | private final TCrmChangePointsService crmChangePointsService; |
| | | private final TCrmBranchService crmBranchService; |
| | | private final TCrmSalespersonService crmSalespersonService; |
| | | private final TErpProcurementCommissionService erpProcurementCommissionService; |
| | | |
| | | |
| | | |
| | | @Autowired |
| | | public TErpProcurementController(TErpProcurementService erpProcurementService, TokenService tokenService,TCrmClinicService crmClinicService) { |
| | | 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) { |
| | | this.erpProcurementService = erpProcurementService; |
| | | this.tokenService = tokenService; |
| | | this.crmClinicService = crmClinicService; |
| | | this.erpProcurementGoodsService = erpProcurementGoodsService; |
| | | this.erpGoodsService = erpGoodsService; |
| | | this.erpClinicWarehousingService = erpClinicWarehousingService; |
| | | this.erpClinicWarehousingBatchService = erpClinicWarehousingBatchService; |
| | | this.crmSupplierService = crmSupplierService; |
| | | this.erpMaintenanceReminderService = erpMaintenanceReminderService; |
| | | this.sysOtherConfigService = sysOtherConfigService; |
| | | this.crmClinicPointsService = crmClinicPointsService; |
| | | this.crmChangePointsService = crmChangePointsService; |
| | | this.crmBranchService = crmBranchService; |
| | | this.crmSalespersonService = crmSalespersonService; |
| | | this.erpProcurementCommissionService = erpProcurementCommissionService; |
| | | |
| | | } |
| | | |
| | | |
| | |
| | | .last("LIMIT 1")); |
| | | clinicSupplierId = crmClinic.getId(); |
| | | } |
| | | return R.ok(erpProcurementService.addProcurement(clinicSupplierId,user,dtos)); |
| | | erpProcurementService.addProcurement(clinicSupplierId, user, dtos); |
| | | return R.ok(); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | @ApiOperation(value = "采购详情") |
| | | @GetMapping(value = "/detailProcurement/{id}") |
| | | public R<DetailProcurementVO> detailProcurement(@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.detailProcurement(clinicSupplierId, user, id)); |
| | | } |
| | | @ApiOperation(value = "采购草稿") |
| | | @GetMapping(value = "/getProcurementDraft") |
| | | public R<ArrayList<DetailProcurementNextVO>> getProcurementDraft() { |
| | | 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(); |
| | | } |
| | | ArrayList<DetailProcurementNextVO> detailProcurementNextVOS = new ArrayList<>(); |
| | | List<TErpProcurement> list1 = erpProcurementService.list(new LambdaQueryWrapper<TErpProcurement>().eq(TErpProcurement::getStatus, 1).orderByDesc(TErpProcurement::getCreateTime)); |
| | | if(list1.isEmpty()){ |
| | | return R.ok(detailProcurementNextVOS); |
| | | } |
| | | String id = list1.get(0).getId(); |
| | | List<TErpProcurementGoods> list = erpProcurementGoodsService.list(new LambdaQueryWrapper<TErpProcurementGoods>().eq(TErpProcurementGoods::getProcurementId, id)); |
| | | |
| | | for (TErpProcurementGoods tErpProcurementGoods : list) { |
| | | DetailProcurementNextVO detailProcurementNextVO = new DetailProcurementNextVO(); |
| | | detailProcurementNextVO.setId(tErpProcurementGoods.getId()); |
| | | detailProcurementNextVO.setGoodsName(tErpProcurementGoods.getGoodsName()); |
| | | detailProcurementNextVO.setQuasiNumber(tErpProcurementGoods.getQuasiNumber()); |
| | | detailProcurementNextVO.setPackingUnitName(tErpProcurementGoods.getUnitName()); |
| | | detailProcurementNextVO.setSalesAmount(tErpProcurementGoods.getSalesAmount()); |
| | | detailProcurementNextVO.setNum(tErpProcurementGoods.getPurchaseCount()); |
| | | detailProcurementNextVO.setTotalPrice(tErpProcurementGoods.getTotalPrice()); |
| | | detailProcurementNextVO.setSupplierName(tErpProcurementGoods.getSupplierName()); |
| | | detailProcurementNextVO.setUnitName(tErpProcurementGoods.getUnitName()); |
| | | detailProcurementNextVO.setPurchasePrice(tErpProcurementGoods.getPurchasePrice()); |
| | | detailProcurementNextVOS.add(detailProcurementNextVO); |
| | | } |
| | | return R.ok(detailProcurementNextVOS); |
| | | } |
| | | |
| | | @ApiOperation(value = "采购详情入库") |
| | | @PostMapping(value = "/updateStatusProcurement") |
| | | public R<DetailProcurementVO> updateStatusProcurement(@RequestParam @Valid UpdateStatusProcurementLastDto dto) { |
| | | SysUser user = tokenService.getLoginUser().getUser(); |
| | | Integer roleType = user.getRoleType(); |
| | | String clinicSupplierId=null; |
| | | TCrmClinic crmClinic = null; |
| | | if(roleType == 5){ |
| | | // 诊所 |
| | | crmClinic = crmClinicService.getOne(Wrappers.lambdaQuery(TCrmClinic.class) |
| | | .eq(TCrmClinic::getUserId, user.getUserId()) |
| | | .last("LIMIT 1")); |
| | | clinicSupplierId = crmClinic.getId(); |
| | | } |
| | | TErpProcurement erpProcurement = erpProcurementService.getById(dto.getId()); |
| | | if(!erpProcurement.getClinicId().equals(clinicSupplierId)){ |
| | | return R.fail("无权限操作"); |
| | | } |
| | | if(erpProcurement.getStatus()!=4){ |
| | | return R.fail("目前状态无法入库"); |
| | | } |
| | | erpProcurement.setStatus(5); |
| | | erpProcurementService.updateById(erpProcurement); |
| | | |
| | | List<String> collect = dto.getList().stream().map(UpdateStatusProcurementDto::getId).collect(Collectors.toList()); |
| | | |
| | | List<TErpProcurementGoods> list = erpProcurementGoodsService.list(new LambdaQueryWrapper<TErpProcurementGoods>().in(TErpProcurementGoods::getId, collect)); |
| | | TErpClinicWarehousing tErpClinicWarehousing = new TErpClinicWarehousing(); |
| | | tErpClinicWarehousing.setClinicId(erpProcurement.getClinicId()); |
| | | tErpClinicWarehousing.setProcurementId(erpProcurement.getId()); |
| | | // tErpClinicWarehousing.setGoodsId(erpGoods.getId()); |
| | | // tErpClinicWarehousing.setGoodsName(erpGoods.getGoodsName()); |
| | | TCrmSupplier byId = crmSupplierService.getById(erpProcurement.getSupplierId()); |
| | | tErpClinicWarehousing.setSupplierName(byId.getSupplierName()); |
| | | // tErpClinicWarehousing.setQuasiNumber(erpGoods.getQuasiNumber()); |
| | | // tErpClinicWarehousing.setSalesAmount(tErpProcurementGoods.getSalesAmount()); |
| | | // tErpClinicWarehousing.setPurchaseCount(updateStatusProcurementDto.getPurchaseCount()); |
| | | tErpClinicWarehousing.setTotalPrice(erpProcurement.getPayMoney()); |
| | | // tErpClinicWarehousing.setUnitAmount(tErpProcurementGoods.getSalesAmount()); |
| | | tErpClinicWarehousing.setWarehousingType(1); |
| | | tErpClinicWarehousing.setType(1); |
| | | tErpClinicWarehousing.setWarehouseNo("G"+ DateUtils.dateTimeNow()); |
| | | erpClinicWarehousingService.save(tErpClinicWarehousing); |
| | | // goodsId分组 |
| | | for (UpdateStatusProcurementDto updateStatusProcurementDto : dto.getList()) { |
| | | TErpProcurementGoods tErpProcurementGoods = list.stream().filter(t -> t.getId().equals(updateStatusProcurementDto.getId())).findFirst().get(); |
| | | |
| | | TErpGoods erpGoods = erpGoodsService.getById(tErpProcurementGoods.getGoodsId()); |
| | | TErpClinicWarehousingBatch tErpClinicWarehousingGoods = new TErpClinicWarehousingBatch(); |
| | | tErpClinicWarehousingGoods.setWarehousingId(tErpClinicWarehousing.getId()); |
| | | tErpClinicWarehousingGoods.setWarehousingNumber(updateStatusProcurementDto.getPurchaseCount()); |
| | | tErpClinicWarehousingGoods.setBatchNumber(updateStatusProcurementDto.getBatchNumber()); |
| | | tErpClinicWarehousingGoods.setProductionDate(updateStatusProcurementDto.getProductionDate()); |
| | | tErpClinicWarehousingGoods.setExpiryDate(updateStatusProcurementDto.getExpiryDate()); |
| | | tErpClinicWarehousingGoods.setGoodsId(erpGoods.getId()); |
| | | tErpClinicWarehousingGoods.setGoodsName(erpGoods.getGoodsName()); |
| | | tErpClinicWarehousingGoods.setQuasiNumber(erpGoods.getQuasiNumber()); |
| | | tErpClinicWarehousingGoods.setSalesAmount(tErpProcurementGoods.getSalesAmount()); |
| | | erpClinicWarehousingBatchService.save(tErpClinicWarehousingGoods); |
| | | |
| | | |
| | | if(erpGoods.getMaintenanceInterval()!=null){ |
| | | TErpMaintenanceReminder tErpMaintenanceReminder = new TErpMaintenanceReminder(); |
| | | tErpMaintenanceReminder.setClinicSupplierId(clinicSupplierId); |
| | | tErpMaintenanceReminder.setMaintenanceType(2); |
| | | tErpMaintenanceReminder.setWarehousingBatchId(tErpClinicWarehousingGoods.getId()); |
| | | Integer day = Integer.valueOf(erpGoods.getMaintenanceInterval()); |
| | | // 当前时间+day天 |
| | | LocalDateTime time1 = LocalDateTime.now().plusDays(day); |
| | | tErpMaintenanceReminder.setMaintenanceTime(time1); |
| | | erpMaintenanceReminderService.save(tErpMaintenanceReminder); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | BigDecimal payMoney = erpProcurement.getPayMoney(); |
| | | // 诊所添加积分 分公司添加积分 业务员添加积分 分公司添加分佣记录 业务员添加分佣记录 |
| | | TSysOtherConfig sysOtherConfig= sysOtherConfigService.getById(1); |
| | | if(sysOtherConfig!=null && sysOtherConfig.getPointsExpiration()!=null){ |
| | | Integer pointsExpiration = sysOtherConfig.getPointsExpiration(); |
| | | if(sysOtherConfig.getExpireUnit().equals(2)){ |
| | | pointsExpiration = pointsExpiration * 31; |
| | | } |
| | | if(sysOtherConfig.getExpireUnit().equals(3)){ |
| | | pointsExpiration = pointsExpiration * 365; |
| | | } |
| | | Double procurementConditions = sysOtherConfig.getProcurementConditions(); |
| | | |
| | | // 积分数 |
| | | int points = payMoney.divide(BigDecimal.valueOf(procurementConditions), 2, RoundingMode.HALF_DOWN).intValue(); |
| | | TCrmClinicPoints tCrmClinicPoints = new TCrmClinicPoints(); |
| | | tCrmClinicPoints.setClinicId(erpProcurement.getClinicId()); |
| | | tCrmClinicPoints.setPoints(points); |
| | | tCrmClinicPoints.setExpireTime(LocalDateTime.now().plusDays(pointsExpiration)); |
| | | crmClinicPointsService.save(tCrmClinicPoints); |
| | | |
| | | TCrmChangePoints tCrmChangePoints = new TCrmChangePoints(); |
| | | tCrmChangePoints.setProcurementId(erpProcurement.getId()); |
| | | tCrmChangePoints.setBranchSalespersonId(erpProcurement.getClinicId()); |
| | | tCrmChangePoints.setUserType(3); |
| | | tCrmChangePoints.setChangeType(1); |
| | | tCrmChangePoints.setChangeReason(1); |
| | | tCrmChangePoints.setChangeValue(points); |
| | | crmChangePointsService.save(tCrmChangePoints); |
| | | |
| | | } |
| | | |
| | | String branchId = crmClinic.getBranchId(); |
| | | TCrmBranch branch = crmBranchService.getById(branchId); |
| | | if(branch!=null){ |
| | | |
| | | // 积分数 |
| | | int points = payMoney.divide(branch.getPointsCommission(), 2, RoundingMode.HALF_DOWN).intValue(); |
| | | |
| | | TCrmChangePoints tCrmChangePoints = new TCrmChangePoints(); |
| | | tCrmChangePoints.setProcurementId(erpProcurement.getId()); |
| | | tCrmChangePoints.setBranchSalespersonId(branchId); |
| | | tCrmChangePoints.setUserType(1); |
| | | tCrmChangePoints.setChangeType(1); |
| | | tCrmChangePoints.setChangeReason(1); |
| | | tCrmChangePoints.setChangeValue(points); |
| | | crmChangePointsService.save(tCrmChangePoints); |
| | | |
| | | |
| | | // 分佣 |
| | | BigDecimal commission = branch.getMoneyCommission().divide(BigDecimal.valueOf(100), 4, RoundingMode.HALF_DOWN).multiply(payMoney).setScale(2, RoundingMode.HALF_UP); |
| | | TErpProcurementCommission tErpProcurementCommission = new TErpProcurementCommission(); |
| | | tErpProcurementCommission.setProcurementId(erpProcurement.getId()); |
| | | tErpProcurementCommission.setCommissionType(1); |
| | | tErpProcurementCommission.setBranchSalespersonId(branchId); |
| | | tErpProcurementCommission.setMoney(commission.doubleValue()); |
| | | erpProcurementCommissionService.save(tErpProcurementCommission); |
| | | |
| | | } |
| | | |
| | | String salespersonId = crmClinic.getSalespersonId(); |
| | | TCrmSalesperson salesperson = crmSalespersonService.getById(salespersonId); |
| | | if(salesperson!=null){ |
| | | // 积分数 |
| | | int points = payMoney.divide(salesperson.getPointsCommission(), 2, RoundingMode.HALF_DOWN).intValue(); |
| | | TCrmChangePoints tCrmChangePoints = new TCrmChangePoints(); |
| | | tCrmChangePoints.setProcurementId(erpProcurement.getId()); |
| | | tCrmChangePoints.setBranchSalespersonId(salespersonId); |
| | | tCrmChangePoints.setUserType(2); |
| | | tCrmChangePoints.setChangeType(1); |
| | | tCrmChangePoints.setChangeReason(1); |
| | | tCrmChangePoints.setChangeValue(points); |
| | | crmChangePointsService.save(tCrmChangePoints); |
| | | |
| | | |
| | | |
| | | // 分佣 |
| | | BigDecimal commission = salesperson.getMoneyCommission().divide(BigDecimal.valueOf(100), 4, RoundingMode.HALF_DOWN).multiply(payMoney).setScale(2, RoundingMode.HALF_UP); |
| | | TErpProcurementCommission tErpProcurementCommission = new TErpProcurementCommission(); |
| | | tErpProcurementCommission.setProcurementId(erpProcurement.getId()); |
| | | tErpProcurementCommission.setCommissionType(2); |
| | | tErpProcurementCommission.setBranchSalespersonId(salespersonId); |
| | | tErpProcurementCommission.setMoney(commission.doubleValue()); |
| | | erpProcurementCommissionService.save(tErpProcurementCommission); |
| | | } |
| | | |
| | | |
| | | return R.ok(); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | |