liujie
1 天以前 f41b11c958ef7d0416d194278d1fe7cd1a1e8219
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TErpGoodsController.java
@@ -9,32 +9,27 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.basic.PageInfo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.BaseModel;
import com.ruoyi.common.core.domain.BasePage;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.utils.WebUtils;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.dto.TErpGoodsAddDto;
import com.ruoyi.system.dto.TErpGoodsInfoSaveDto;
import com.ruoyi.system.dto.TErpGoodsUpdateStatusDto;
import com.ruoyi.system.dto.*;
import com.ruoyi.system.importExcel.TErpGoodsExcel;
import com.ruoyi.system.model.TErpGoods;
import com.ruoyi.system.model.TErpGoodsType;
import com.ruoyi.system.model.TErpGoodsUnit;
import com.ruoyi.system.model.*;
import com.ruoyi.system.query.TErpGoodsQuery;
import com.ruoyi.system.service.TErpGoodsService;
import com.ruoyi.system.service.TErpGoodsTypeService;
import com.ruoyi.system.service.TErpGoodsUnitService;
import com.ruoyi.system.service.*;
import com.ruoyi.system.vo.TErpGoodsVO;
import com.ruoyi.web.controller.tool.ImportExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@@ -47,9 +42,10 @@
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.*;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
/**
@@ -70,13 +66,27 @@
    private final TokenService tokenService;
    private final TErpGoodsTypeService erpGoodsTypeService;
    private final TErpGoodsUnitService erpGoodsUnitService;
    private final TErpSupplierWarehousingBatchService erpSupplierWarehousingBatchService;
    private final TErpSupplierWarehousingService erpSupplierWarehousingService;
    private final TErpSupplierOutboundGoodsService erpSupplierOutboundGoodsService;
    private final TErpMaintenanceReminderService erpMaintenanceReminderService;
    private final TCrmClinicService crmClinicService;
    private final TCrmSupplierService crmSupplierService;
    @Autowired
    public TErpGoodsController(TErpGoodsService erpGoodsService, TokenService tokenService, TErpGoodsTypeService erpGoodsTypeService, TErpGoodsUnitService erpGoodsUnitService) {
    public TErpGoodsController(TErpGoodsService erpGoodsService, TokenService tokenService, TErpGoodsTypeService erpGoodsTypeService, TErpGoodsUnitService erpGoodsUnitService,
                               TErpSupplierWarehousingBatchService erpSupplierWarehousingBatchService, TErpSupplierWarehousingService erpSupplierWarehousingService,
                               TErpSupplierOutboundGoodsService erpSupplierOutboundGoodsService, TErpMaintenanceReminderService erpMaintenanceReminderService, TCrmClinicService crmClinicService, TCrmSupplierService crmSupplierService) {
        this.erpGoodsService = erpGoodsService;
        this.tokenService = tokenService;
        this.erpGoodsTypeService = erpGoodsTypeService;
        this.erpGoodsUnitService = erpGoodsUnitService;
        this.erpSupplierWarehousingBatchService = erpSupplierWarehousingBatchService;
        this.erpSupplierWarehousingService = erpSupplierWarehousingService;
        this.erpSupplierOutboundGoodsService = erpSupplierOutboundGoodsService;
        this.erpMaintenanceReminderService = erpMaintenanceReminderService;
        this.crmClinicService = crmClinicService;
        this.crmSupplierService = crmSupplierService;
    }
@@ -84,11 +94,56 @@
    /**
     * 获取erp问题上报管理列表
     */
    @ApiOperation(value = "供应商获取商品分页列表")
    @ApiOperation(value = "供应商 诊所 获取商品分页列表")
    @PostMapping(value = "/pageList")
    public R<PageInfo<TErpGoodsVO>> pageList(@RequestBody TErpGoodsQuery query) {
        SysUser user = tokenService.getLoginUser().getUser();
        Integer roleType = user.getRoleType();
        if(roleType == 4){
            // 供应商
            TCrmSupplier crmSupplier = crmSupplierService.getOne(Wrappers.lambdaQuery(TCrmSupplier.class)
                    .eq(TCrmSupplier::getUserId, user.getUserId())
                    .last("LIMIT 1"));
            query.setSupplierClinicId(crmSupplier.getId());
        }
        if(roleType == 5){
            // 诊所
            TCrmClinic crmClinic = crmClinicService.getOne(Wrappers.lambdaQuery(TCrmClinic.class)
                    .eq(TCrmClinic::getUserId, user.getUserId())
                    .last("LIMIT 1"));
            query.setSupplierClinicId(crmClinic.getId());
        }
        return R.ok(erpGoodsService.pageList(query,user));
    }
    /**
     * 获取erp问题上报管理列表
     */
    @ApiOperation(value = "诊所 一键获取商品分页列表")
    @PostMapping(value = "/pageAddList")
    public R<Page<TErpGoods>> pageAddList(BasePage query) {
        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();
        }
        Page<TErpGoods> tErpGoodsPage = new Page<>(query.getPageNum(), query.getPageSize());
        Page<TErpGoods> page = erpGoodsService.page(tErpGoodsPage, new LambdaQueryWrapper<TErpGoods>().eq(TErpGoods::getGoodsSource, 1).eq(BaseModel::getDisabled, 0).isNotNull(TErpGoods::getPlatformCommissionPrice).last(" NOT FIND_IN_SET(" + clinicSupplierId + ",clinic_ids)"));
        for (TErpGoods record : page.getRecords()) {
            TCrmSupplier byId = crmSupplierService.getById(record.getSupplierClinicId());
            record.setSupplierName(byId.getSupplierName());
            TErpGoodsType byId1 = erpGoodsTypeService.getById(record.getTypeId());
            record.setTypeName(byId1.getTypeName());
        }
        return R.ok(page);
    }
@@ -100,8 +155,24 @@
        if (erpGoodsService.isExit(dto.getGoodsIdCode(), dto.getQuasiNumber())) {
            return R.fail("erp商品已存在");
        }
        Integer roleType = user.getRoleType();
        TErpGoods goods = new TErpGoods();
        goods.setSupplierClinicId(user.getUserId().toString());
        if(roleType == 4){
            // 供应商
            TCrmSupplier crmSupplier = crmSupplierService.getOne(Wrappers.lambdaQuery(TCrmSupplier.class)
                    .eq(TCrmSupplier::getUserId, user.getUserId())
                    .last("LIMIT 1"));
            goods.setSupplierClinicId(crmSupplier.getId());
            goods.setGoodsSource(1);
        }
        if(roleType == 5){
            // 诊所
            TCrmClinic crmClinic = crmClinicService.getOne(Wrappers.lambdaQuery(TCrmClinic.class)
                    .eq(TCrmClinic::getUserId, user.getUserId())
                    .last("LIMIT 1"));
            goods.setSupplierClinicId(crmClinic.getId());
            goods.setGoodsSource(2);
        }
        goods.setCreateId(user.getUserId().toString());
        goods.setGoodsIdCode(dto.getGoodsIdCode());
        goods.setQuasiNumber(dto.getQuasiNumber());
@@ -109,6 +180,28 @@
        goods.setFormulationSpec(dto.getFormulationSpec());
        goods.setPackingSpec(dto.getPackingSpec());
        goods.setGoodsName(dto.getGoodsName());
        return R.ok(erpGoodsService.save(goods));
    }
    @ApiOperation(value = "诊所添加商品")
    @PostMapping(value = "/clinicAdd")
    public R<Boolean> clinicAdd(@Validated @RequestBody TErpClinicGoodsAddDto dto) {
        SysUser user = tokenService.getLoginUser().getUser();
        if (erpGoodsService.isExit(dto.getGoodsIdCode(), dto.getQuasiNumber())) {
            return R.fail("erp商品已存在");
        }
        Integer roleType = user.getRoleType();
        TErpGoods goods = new TErpGoods();
        BeanUtils.copyProperties(dto,goods);
        if(roleType == 5){
            // 诊所
            TCrmClinic crmClinic = crmClinicService.getOne(Wrappers.lambdaQuery(TCrmClinic.class)
                    .eq(TCrmClinic::getUserId, user.getUserId())
                    .last("LIMIT 1"));
            goods.setSupplierClinicId(crmClinic.getId());
            goods.setGoodsSource(2);
        }
        goods.setCreateId(user.getUserId().toString());
        goods.setGoodsIdCode(dto.getGoodsIdCode());
        return R.ok(erpGoodsService.save(goods));
    }
@@ -140,8 +233,56 @@
    @ApiOperation(value = "供应商完善商品")
    @PostMapping(value = "/saveDataInfo")
    public R<Boolean> saveDataInfo(@RequestBody @Valid TErpGoodsInfoSaveDto dto) {
        SysUser user = tokenService.getLoginUser().getUser();
        Integer roleType = user.getRoleType();
        String clinicSupplierId=null;
        if(roleType == 4){
            // 供应商
            TCrmSupplier crmSupplier = crmSupplierService.getOne(Wrappers.lambdaQuery(TCrmSupplier.class)
                    .eq(TCrmSupplier::getUserId, user.getUserId())
                    .last("LIMIT 1"));
            clinicSupplierId = crmSupplier.getId();
        }
        if(roleType == 5){
            // 诊所
            TCrmClinic crmClinic = crmClinicService.getOne(Wrappers.lambdaQuery(TCrmClinic.class)
                    .eq(TCrmClinic::getUserId, user.getUserId())
                    .last("LIMIT 1"));
            clinicSupplierId =crmClinic.getId();
        }
        TErpGoods goods = erpGoodsService.getById(dto.getId());
        BeanUtils.copyProperties(dto,goods);
        if(goods.getMaintenanceInterval()!=null){
            List<TErpSupplierWarehousing> list = erpSupplierWarehousingService.list(new LambdaQueryWrapper<TErpSupplierWarehousing>().eq(TErpSupplierWarehousing::getGoodsId, dto.getId()));
            if(!list.isEmpty()){
                List<TErpSupplierWarehousingBatch> tErpSupplierWarehousingBatches = erpSupplierWarehousingBatchService.list(new LambdaQueryWrapper<TErpSupplierWarehousingBatch>().in(TErpSupplierWarehousingBatch::getWarehousingId, list.stream().map(TErpSupplierWarehousing::getId).collect(Collectors.toList())));
                for (TErpSupplierWarehousingBatch tErpSupplierWarehousingBatch : tErpSupplierWarehousingBatches) {
                    List<TErpSupplierOutboundGoods> list1 = erpSupplierOutboundGoodsService.list(new LambdaQueryWrapper<TErpSupplierOutboundGoods>().eq(TErpSupplierOutboundGoods::getWarehousingBatchId, tErpSupplierWarehousingBatch.getId()));
                    if(!list1.isEmpty()){
                        int sum = list1.stream().mapToInt(TErpSupplierOutboundGoods::getOutboundCount).sum();
                        if (tErpSupplierWarehousingBatch.getWarehousingNumber()-sum>0) {
                            // 生成保养单
                            TErpMaintenanceReminder tErpMaintenanceReminder = new TErpMaintenanceReminder();
                            tErpMaintenanceReminder.setClinicSupplierId(clinicSupplierId);
                            tErpMaintenanceReminder.setMaintenanceType(1);
                            tErpMaintenanceReminder.setWarehousingBatchId(tErpSupplierWarehousingBatch.getId());
                            Integer day = Integer.valueOf(goods.getMaintenanceInterval());
                            // 当前时间+day天
                            LocalDateTime time1 = LocalDateTime.now().plusDays(day);
                            tErpMaintenanceReminder.setMaintenanceTime(time1);
                            erpMaintenanceReminderService.save(tErpMaintenanceReminder);
                        }
                    }
                }
            }
        }
        return R.ok(erpGoodsService.updateById(goods));
    }
@@ -157,6 +298,23 @@
    public void listExport(@RequestBody TErpGoodsQuery query)
    {
        SysUser user = tokenService.getLoginUser().getUser();
        Integer roleType = user.getRoleType();
        if(roleType == 4){
            // 供应商
            TCrmSupplier crmSupplier = crmSupplierService.getOne(Wrappers.lambdaQuery(TCrmSupplier.class)
                    .eq(TCrmSupplier::getUserId, user.getUserId())
                    .last("LIMIT 1"));
            query.setSupplierClinicId(crmSupplier.getId());
        }
        if(roleType == 5){
            // 诊所
            TCrmClinic crmClinic = crmClinicService.getOne(Wrappers.lambdaQuery(TCrmClinic.class)
                    .eq(TCrmClinic::getUserId, user.getUserId())
                    .last("LIMIT 1"));
            query.setSupplierClinicId(crmClinic.getId());
        }
        List<TErpGoodsVO> pageList = erpGoodsService.listExport(query,user);
        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), TErpGoodsVO.class, pageList);
        HttpServletResponse response = WebUtils.response();
@@ -203,10 +361,26 @@
            if (collect.size() != carAnnuallyImportExcels.size()) {
                return AjaxResult.error("导入数据中商品标识码重复");
            }
            Integer roleType = user.getRoleType();
            for (TErpGoodsExcel erpGoodsExcel : carAnnuallyImportExcels) {
                TErpGoods goods = new TErpGoods();
                goods.setSupplierClinicId(user.getUserId().toString());
                goods.setGoodsSource(1);
                if(roleType == 4){
                    // 供应商
                    TCrmSupplier crmSupplier = crmSupplierService.getOne(Wrappers.lambdaQuery(TCrmSupplier.class)
                            .eq(TCrmSupplier::getUserId, user.getUserId())
                            .last("LIMIT 1"));
                    goods.setSupplierClinicId(crmSupplier.getId());
                    goods.setGoodsSource(1);
                }
                if(roleType == 5){
                    // 诊所
                    TCrmClinic crmClinic = crmClinicService.getOne(Wrappers.lambdaQuery(TCrmClinic.class)
                            .eq(TCrmClinic::getUserId, user.getUserId())
                            .last("LIMIT 1"));
                    goods.setSupplierClinicId(crmClinic.getId());
                    goods.setGoodsSource(2);
                }
                // 判空
                if(erpGoodsExcel.getGoodsName()==null || erpGoodsExcel.getGoodsName().isEmpty()){
@@ -346,5 +520,20 @@
    }
    @ApiOperation(value = "平台设置分佣")
    @PostMapping(value = "/setCommission")
    public R<Boolean> setCommission(@RequestBody @Valid TErpGoodsSetCommissionDto dto) {
        SysUser user = tokenService.getLoginUser().getUser();
        if(user.getRoleType()==1){
            TErpGoods goods = erpGoodsService.getById(dto.getId());
            goods.setClinicPurchasePrice(BigDecimal.valueOf(dto.getClinicPurchasePrice()).setScale(2,RoundingMode.HALF_UP));
            goods.setPlatformCommissionPrice(BigDecimal.valueOf(dto.getPlatformCommissionPrice()).setScale(2,RoundingMode.HALF_UP));
            erpGoodsService.updateById( goods);
        }
        return R.ok();
    }
}