package com.ruoyi.web.controller.api;
|
|
|
import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
import cn.afterturn.easypoi.excel.ExcelImportUtil;
|
import cn.afterturn.easypoi.excel.entity.ExportParams;
|
import cn.afterturn.easypoi.excel.entity.ImportParams;
|
import cn.hutool.crypto.SecureUtil;
|
import com.alibaba.fastjson2.JSONObject;
|
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.annotation.Log;
|
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.enums.BusinessType;
|
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.common.utils.WebUtils;
|
import com.ruoyi.framework.web.service.TokenService;
|
import com.ruoyi.system.constant.GoodsTypeConstants;
|
import com.ruoyi.system.dto.*;
|
import com.ruoyi.system.export.TErpGoodsDetailExport;
|
import com.ruoyi.system.importExcel.TErpCloudGoodsExcel;
|
import com.ruoyi.system.importExcel.TErpFixedGoodsExcel;
|
import com.ruoyi.system.importExcel.TErpGoodsExcel;
|
import com.ruoyi.system.model.*;
|
import com.ruoyi.system.query.PageAddListQuery;
|
import com.ruoyi.system.query.TErpGoodsAdminQuery;
|
import com.ruoyi.system.query.TErpGoodsQuery;
|
import com.ruoyi.system.service.*;
|
import com.ruoyi.system.vo.TErpGoodsVO;
|
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.validation.annotation.Validated;
|
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.multipart.MultipartFile;
|
|
import javax.servlet.ServletOutputStream;
|
import javax.servlet.http.HttpServletResponse;
|
import javax.validation.Valid;
|
import java.io.IOException;
|
import java.io.InputStream;
|
import java.math.BigDecimal;
|
import java.math.RoundingMode;
|
import java.net.URLEncoder;
|
import java.time.LocalDateTime;
|
import java.util.*;
|
import java.util.stream.Collectors;
|
import java.util.stream.Stream;
|
|
/**
|
* <p>
|
* erp商品 前端控制器
|
* </p>
|
*
|
* @author xiaochen
|
* @since 2025-08-20
|
*/
|
@RestController
|
@RequestMapping("/t-erp-goods")
|
@Api(tags = "供应商商品管理")
|
public class TErpGoodsController {
|
|
|
private final TErpGoodsService erpGoodsService;
|
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;
|
private final ISysUserService sysUserService;
|
|
@Autowired
|
public TErpGoodsController(TErpGoodsService erpGoodsService, TokenService tokenService, TErpGoodsTypeService erpGoodsTypeService, TErpGoodsUnitService erpGoodsUnitService,
|
TErpSupplierWarehousingBatchService erpSupplierWarehousingBatchService, TErpSupplierWarehousingService erpSupplierWarehousingService,
|
TErpSupplierOutboundGoodsService erpSupplierOutboundGoodsService, TErpMaintenanceReminderService erpMaintenanceReminderService, TCrmClinicService crmClinicService, TCrmSupplierService crmSupplierService, ISysUserService sysUserService) {
|
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;
|
this.sysUserService = sysUserService;
|
}
|
|
|
/**
|
* 获取erp问题上报管理列表
|
*/
|
@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"));
|
// ***
|
if (Objects.isNull(crmSupplier)) {
|
SysUser sysUser = sysUserService.selectUserById(user.getUserId());
|
crmSupplier = crmSupplierService.getById(sysUser.getObjectId());
|
}
|
|
query.setSupplierClinicId(crmSupplier.getId());
|
}
|
if (roleType == 5) {
|
// 诊所
|
TCrmClinic crmClinic = crmClinicService.getOne(Wrappers.lambdaQuery(TCrmClinic.class)
|
.eq(TCrmClinic::getUserId, user.getUserId())
|
.last("LIMIT 1"));
|
// ---
|
if (Objects.isNull(crmClinic)) {
|
SysUser sysUser = sysUserService.selectUserById(user.getUserId());
|
crmClinic = crmClinicService.getById(sysUser.getObjectId());
|
}
|
query.setSupplierClinicId(crmClinic.getId());
|
}
|
|
return R.ok(erpGoodsService.pageList(query, user));
|
}
|
|
/**
|
* 获取erp问题上报管理列表
|
*/
|
@ApiOperation(value = "平台获取商品分页列表")
|
@PostMapping(value = "/pageAdminList")
|
public R<PageInfo<TErpGoodsVO>> pageAdminList(@RequestBody TErpGoodsAdminQuery query) {
|
SysUser user = tokenService.getLoginUser().getUser();
|
Integer roleType = user.getRoleType();
|
if (roleType == 1) {
|
// 平台
|
return R.ok(erpGoodsService.pageAdminList(query));
|
}
|
return R.ok();
|
}
|
|
@ApiOperation(value = "平台设置商品排序")
|
@PostMapping(value = "/setGoodsSort")
|
public R<?> setGoodsSort(@RequestBody GoodsSortUpdateDto dto) {
|
SysUser user = tokenService.getLoginUser().getUser();
|
Integer roleType = user.getRoleType();
|
if (roleType == 1) {
|
// 平台
|
TErpGoods goods = erpGoodsService.getById(dto.getId());
|
if(goods!=null){
|
goods.setSort(dto.getSort());
|
erpGoodsService.updateById(goods);
|
}
|
}
|
return R.ok();
|
}
|
|
|
|
@ApiOperation(value = "平台审核商品内容")
|
@PostMapping(value = "/adminAudit")
|
@Log(title = "商品管理-平台审核商品内容", businessType = BusinessType.UPDATE)
|
public R<?> adminAudit(@RequestBody AdminAuditDto dto) {
|
SysUser user = tokenService.getLoginUser().getUser();
|
Integer roleType = user.getRoleType();
|
List<TErpGoods> tErpGoods = erpGoodsService.listByIds(dto.getIds());
|
if (roleType == 1) {
|
tErpGoods.stream().forEach(e -> {
|
e.setContentState(dto.getContentState());
|
e.setContentRemark(dto.getContentRemark());
|
}
|
);
|
erpGoodsService.updateBatchById(tErpGoods);
|
// 平台
|
return R.ok();
|
}
|
return R.ok();
|
}
|
|
|
@ApiOperation(value = "供应商提交商品内容")
|
@PostMapping(value = "/supplierSubmitContent")
|
@Log(title = "商品管理-供应商提交商品内容", businessType = BusinessType.UPDATE)
|
public R<?> adminAudit(@RequestBody SupplierSubmitContentDto dto) {
|
SysUser user = tokenService.getLoginUser().getUser();
|
Integer roleType = user.getRoleType();
|
TErpGoods erpGoods = erpGoodsService.getById(dto.getId());
|
if (roleType == 4) {
|
erpGoods.setContent(dto.getContent());
|
erpGoods.setContentState(0);
|
erpGoodsService.updateById(erpGoods);
|
return R.ok();
|
}
|
return R.ok();
|
}
|
|
|
/**
|
* 获取erp问题上报管理列表
|
*/
|
@ApiOperation(value = "诊所 一键获取商品分页列表")
|
@PostMapping(value = "/pageAddList")
|
public R<Page<TErpGoods>> pageAddList(@RequestBody PageAddListQuery 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"));
|
// ---
|
if (Objects.isNull(crmClinic)) {
|
SysUser sysUser = sysUserService.selectUserById(user.getUserId());
|
crmClinic = crmClinicService.getById(sysUser.getObjectId());
|
}
|
clinicSupplierId = crmClinic.getId();
|
}
|
Page<TErpGoods> tErpGoodsPage = new Page<>(query.getPageNum(), query.getPageSize());
|
|
List<TErpGoods> page = erpGoodsService.pageAddList(tErpGoodsPage, clinicSupplierId, query);
|
tErpGoodsPage.setRecords(page);
|
return R.ok(tErpGoodsPage);
|
}
|
|
/**
|
* 获取erp问题上报管理列表
|
*/
|
@ApiOperation(value = "诊所 一键获取商品 获取全部")
|
@PostMapping(value = "/getAllGoodsList")
|
@Log(title = "商品管理-诊所 一键获取商品", businessType = BusinessType.INSERT)
|
public R<?> getAllGoodsList() {
|
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"));
|
// ---
|
if (Objects.isNull(crmClinic)) {
|
SysUser sysUser = sysUserService.selectUserById(user.getUserId());
|
crmClinic = crmClinicService.getById(sysUser.getObjectId());
|
}
|
clinicSupplierId = crmClinic.getId();
|
}
|
|
List<TErpGoods> list = erpGoodsService.list(new LambdaQueryWrapper<TErpGoods>().eq(TErpGoods::getGoodsSource, 1).eq(TErpGoods::getState, 1).eq(BaseModel::getDisabled, 0).isNotNull(TErpGoods::getPlatformCommissionPrice).last("and (NOT FIND_IN_SET(" + clinicSupplierId + ",clinic_ids) or clinic_ids is null)"));
|
for (TErpGoods goods : list) {
|
String clinicIds = goods.getClinicIds();
|
if (clinicIds == null || clinicIds.isEmpty()) {
|
goods.setClinicIds(clinicSupplierId);
|
} else {
|
String[] split = clinicIds.split(",");
|
ArrayList<String> split1 = new ArrayList<>();
|
for (String s : split) {
|
split1.add(s);
|
}
|
if (!split1.contains(clinicSupplierId)) {
|
split1.add(clinicSupplierId);
|
goods.setClinicIds(String.join(",", split1));
|
}
|
}
|
|
}
|
erpGoodsService.updateBatchById(list);
|
return R.ok();
|
}
|
|
|
@ApiOperation(value = "供应商添加商品")
|
@PostMapping(value = "/add")
|
@Log(title = "商品管理-供应商添加", businessType = BusinessType.INSERT)
|
public R<Boolean> add(@Validated @RequestBody TErpGoodsAddDto dto) {
|
SysUser user = tokenService.getLoginUser().getUser();
|
if (erpGoodsService.isExit(dto.getGoodsIdCode(), dto.getQuasiNumber(), null)) {
|
return R.fail("erp商品已存在");
|
}
|
Integer roleType = user.getRoleType();
|
TErpGoods goods = new TErpGoods();
|
BeanUtils.copyProperties(dto, goods);
|
if (roleType == 4) {
|
// 供应商
|
TCrmSupplier crmSupplier = crmSupplierService.getOne(Wrappers.lambdaQuery(TCrmSupplier.class)
|
.eq(TCrmSupplier::getUserId, user.getUserId())
|
.last("LIMIT 1"));
|
// ***
|
if (Objects.isNull(crmSupplier)) {
|
SysUser sysUser = sysUserService.selectUserById(user.getUserId());
|
crmSupplier = crmSupplierService.getById(sysUser.getObjectId());
|
}
|
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"));
|
// ---
|
if (Objects.isNull(crmClinic)) {
|
SysUser sysUser = sysUserService.selectUserById(user.getUserId());
|
crmClinic = crmClinicService.getById(sysUser.getObjectId());
|
}
|
goods.setSupplierClinicId(crmClinic.getId());
|
goods.setGoodsSource(2);
|
}
|
goods.setCreateId(user.getUserId().toString());
|
goods.setGoodsIdCode(dto.getGoodsIdCode());
|
goods.setQuasiNumber(dto.getQuasiNumber());
|
goods.setManufacturer(dto.getManufacturer());
|
goods.setFormulationSpec(dto.getFormulationSpec());
|
goods.setPackingSpec(dto.getPackingSpec());
|
goods.setGoodsName(dto.getGoodsName());
|
goods.setIsPrescriptionDrug(dto.getIsPrescriptionDrug());
|
goods.setTypeId(dto.getTypeId());
|
goods.setGoodsSpec(buildGoodsSpec(dto.getFormulationSpec(), dto.getPackingSpec()));
|
return R.ok(erpGoodsService.save(goods));
|
}
|
|
@ApiOperation(value = "诊所添加商品")
|
@PostMapping(value = "/clinicAdd")
|
@Log(title = "商品管理-诊所添加", businessType = BusinessType.INSERT)
|
public R<Boolean> clinicAdd(@Validated @RequestBody TErpClinicGoodsAddDto dto) {
|
SysUser user = tokenService.getLoginUser().getUser();
|
if (erpGoodsService.isExit(dto.getGoodsIdCode(), dto.getQuasiNumber(), null)) {
|
return R.fail("erp商品已存在,商品条码重复");
|
}
|
if (StringUtils.isNotBlank(dto.getQuasiNumber())
|
&& erpGoodsService.isExitOne(dto.getGoodsIdCode(), dto.getQuasiNumber(), null)) {
|
return R.fail("erp商品已存在,国药准字号重复");
|
}
|
Integer roleType = user.getRoleType();
|
TErpGoods goods = new TErpGoods();
|
BeanUtils.copyProperties(dto, goods);
|
goods.setGoodsSpec(buildGoodsSpec(dto.getFormulationSpec(), dto.getPackingSpec()));
|
if (roleType == 5) {
|
// 诊所
|
TCrmClinic crmClinic = crmClinicService.getOne(Wrappers.lambdaQuery(TCrmClinic.class)
|
.eq(TCrmClinic::getUserId, user.getUserId())
|
.last("LIMIT 1"));
|
// ---
|
if (Objects.isNull(crmClinic)) {
|
SysUser sysUser = sysUserService.selectUserById(user.getUserId());
|
crmClinic = crmClinicService.getById(sysUser.getObjectId());
|
}
|
goods.setSupplierClinicId(crmClinic.getId());
|
goods.setGoodsSource(2);
|
}
|
goods.setCreateId(user.getUserId().toString());
|
goods.setGoodsIdCode(dto.getGoodsIdCode());
|
goods.setGoodsSpec(buildGoodsSpec(dto.getFormulationSpec(), dto.getPackingSpec()));
|
// goods.setClinicPurchasePrice(dto.getSalesAmount());
|
if (goods.getIsPrescriptionDrug() != null && goods.getIsPrescriptionDrug() == 3) {
|
goods.setIsPrescriptionDrug(null);
|
}
|
return R.ok(erpGoodsService.save(goods));
|
}
|
|
@ApiOperation(value = "诊所编辑商品")
|
@PostMapping(value = "/clinicUpdate")
|
@Log(title = "商品管理-诊所编辑", businessType = BusinessType.UPDATE)
|
public R<Boolean> clinicUpdate(@Validated @RequestBody TErpClinicGoodsUpdateDto dto) {
|
SysUser user = tokenService.getLoginUser().getUser();
|
if (erpGoodsService.isExit(dto.getGoodsIdCode(), dto.getQuasiNumber(), dto.getId())) {
|
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"));
|
// ---
|
if (Objects.isNull(crmClinic)) {
|
SysUser sysUser = sysUserService.selectUserById(user.getUserId());
|
crmClinic = crmClinicService.getById(sysUser.getObjectId());
|
}
|
goods.setSupplierClinicId(crmClinic.getId());
|
goods.setGoodsSource(2);
|
}
|
goods.setCreateId(user.getUserId().toString());
|
goods.setGoodsIdCode(dto.getGoodsIdCode());
|
goods.setId(dto.getId());
|
goods.setGoodsSpec(buildGoodsSpec(dto.getFormulationSpec(), dto.getPackingSpec()));
|
if (goods.getIsPrescriptionDrug() != null && goods.getIsPrescriptionDrug() == 3) {
|
goods.setIsPrescriptionDrug(null);
|
}
|
return R.ok(erpGoodsService.updateById(goods));
|
}
|
|
@ApiOperation(value = "供应商/诊所 删除商品")
|
@DeleteMapping(value = "/delete/{id}")
|
@Log(title = "商品管理-删除", businessType = BusinessType.DELETE)
|
public R<Boolean> delete(@PathVariable String id) {
|
TErpGoods goods = erpGoodsService.getById(id);
|
SysUser user = tokenService.getLoginUser().getUser();
|
String cid = null;
|
|
if (user.getRoleType() == 5) {
|
// 诊所
|
TCrmClinic crmClinic = crmClinicService.getOne(Wrappers.lambdaQuery(TCrmClinic.class)
|
.eq(TCrmClinic::getUserId, user.getUserId())
|
.last("LIMIT 1"));
|
// ---
|
if (Objects.isNull(crmClinic)) {
|
SysUser sysUser = sysUserService.selectUserById(user.getUserId());
|
crmClinic = crmClinicService.getById(sysUser.getObjectId());
|
}
|
cid = crmClinic.getId();
|
if (goods.getGoodsSource() == 1) {
|
String clinicIds = goods.getClinicIds();
|
String[] split = clinicIds.split(",");
|
// clinicIds 移除cid
|
ArrayList<String> strings = new ArrayList<>();
|
for (String s : split) {
|
if (!s.equals(cid)) {
|
strings.add(s);
|
}
|
}
|
goods.setClinicIds(String.join(",", strings));
|
erpGoodsService.updateById(goods);
|
} else {
|
erpGoodsService.removeById(id);
|
}
|
return R.ok();
|
}
|
erpGoodsService.removeById(id);
|
return R.ok();
|
}
|
|
@ApiOperation(value = "诊所 一键添加商品")
|
@PostMapping(value = "/addSupplierGoods")
|
@Log(title = "商品管理-诊所一键添加商品", businessType = BusinessType.INSERT)
|
public R<Boolean> addSupplierGoods(@RequestBody AddSupplierGoodsDto dto) {
|
// List<String> split = Arrays.asList(goodsIds.split(","));
|
List<TErpGoods> list = erpGoodsService.list(new LambdaQueryWrapper<TErpGoods>().in(TErpGoods::getId, dto.getGoodsIds()));
|
SysUser user = tokenService.getLoginUser().getUser();
|
String cid = null;
|
|
if (user.getRoleType() == 5) {
|
TCrmClinic crmClinic = crmClinicService.getOne(Wrappers.lambdaQuery(TCrmClinic.class)
|
.eq(TCrmClinic::getUserId, user.getUserId())
|
.last("LIMIT 1"));
|
// ---
|
if (Objects.isNull(crmClinic)) {
|
SysUser sysUser = sysUserService.selectUserById(user.getUserId());
|
crmClinic = crmClinicService.getById(sysUser.getObjectId());
|
}
|
cid = crmClinic.getId();
|
for (TErpGoods goods : list) {
|
String clinicIds = goods.getClinicIds();
|
if (clinicIds == null || clinicIds.isEmpty()) {
|
goods.setClinicIds(cid);
|
} else {
|
String[] split = clinicIds.split(",");
|
List<String> split1 = new ArrayList<>();
|
for (String s : split) {
|
split1.add(s);
|
}
|
if (!split1.contains(cid)) {
|
split1.add(cid);
|
goods.setClinicIds(String.join(",", split1));
|
}
|
}
|
|
}
|
erpGoodsService.updateBatchById(list);
|
}
|
return R.ok();
|
}
|
|
|
/**
|
* 启用 停用
|
*/
|
@ApiOperation(value = "供应商启用 停用商品")
|
@PostMapping(value = "/updateStatus")
|
@Log(title = "商品管理-启用/停用商品", businessType = BusinessType.UPDATE)
|
public R<Boolean> updateStatus(@RequestBody TErpGoodsUpdateStatusDto dto) {
|
|
SysUser user = tokenService.getLoginUser().getUser();
|
TErpGoods goods = erpGoodsService.getById(dto.getId());
|
if (goods.getState() == 2 && dto.getState() == 2) {
|
return R.fail("操作失败,该商品已是禁用状态");
|
}
|
if (dto.getState() == 1 && goods.getTypeId() == null) {
|
return R.fail("操作失败,请先完善商品信息");
|
}
|
if (dto.getState() == 1 && goods.getClinicPurchasePrice() == null) {
|
return R.fail("操作失败,请设置供应商分佣比例后再启用");
|
}
|
if (dto.getState() == 1 && Objects.nonNull(goods.getStateUser()) && goods.getStateUser() == 1 && user.getRoleType() == 4) {
|
return R.fail("操作失败,平台禁用商品不可启用");
|
}
|
if (user.getRoleType() == 1) {
|
goods.setStateUser(1);
|
} else if (user.getRoleType() == 5) {
|
goods.setStateUser(2);
|
}
|
goods.setStateRemark(dto.getStateRemark());
|
goods.setState(dto.getState());
|
boolean b = erpGoodsService.updateById(goods);
|
return R.ok(b);
|
}
|
|
|
public static void main(String[] args) {
|
String s = SecureUtil.md5("cca19Broker@.!142536cca");
|
System.out.println(s);
|
}
|
|
@ApiOperation(value = "供应商完善商品")
|
@PostMapping(value = "/saveDataInfo")
|
@Log(title = "商品管理-供应商完善商品", businessType = BusinessType.UPDATE)
|
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"));
|
// ***
|
if (Objects.isNull(crmSupplier)) {
|
SysUser sysUser = sysUserService.selectUserById(user.getUserId());
|
crmSupplier = crmSupplierService.getById(sysUser.getObjectId());
|
}
|
clinicSupplierId = crmSupplier.getId();
|
}
|
if (roleType == 5) {
|
// 诊所
|
TCrmClinic crmClinic = crmClinicService.getOne(Wrappers.lambdaQuery(TCrmClinic.class)
|
.eq(TCrmClinic::getUserId, user.getUserId())
|
.last("LIMIT 1"));
|
// ---
|
if (Objects.isNull(crmClinic)) {
|
SysUser sysUser = sysUserService.selectUserById(user.getUserId());
|
crmClinic = crmClinicService.getById(sysUser.getObjectId());
|
}
|
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);
|
}
|
}
|
|
}
|
|
}
|
|
}
|
if (goods.getIsPrescriptionDrug() != null && goods.getIsPrescriptionDrug() == 3) {
|
goods.setIsPrescriptionDrug(null);
|
}
|
|
return R.ok(erpGoodsService.updateById(goods));
|
}
|
|
@ApiOperation(value = "商品详情")
|
@GetMapping(value = "/detail/{id}")
|
public R<TErpGoods> detail(@PathVariable String id) {
|
TErpGoods goods = erpGoodsService.getById(id);
|
return R.ok(goods);
|
}
|
|
private String buildGoodsSpec(String formulationSpec, String packingSpec) {
|
if (StringUtils.isNotBlank(formulationSpec) && StringUtils.isNotBlank(packingSpec)) {
|
return formulationSpec + "*" + packingSpec;
|
}
|
return StringUtils.isNotBlank(packingSpec) ? packingSpec : formulationSpec;
|
}
|
|
@ApiOperation(value = "商品管理信息导出--导出")
|
@PostMapping("/export")
|
@Log(title = "商品管理-导出", businessType = BusinessType.EXPORT)
|
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"));
|
// ***
|
if (Objects.isNull(crmSupplier)) {
|
SysUser sysUser = sysUserService.selectUserById(user.getUserId());
|
crmSupplier = crmSupplierService.getById(sysUser.getObjectId());
|
}
|
query.setSupplierClinicId(crmSupplier.getId());
|
}
|
if (roleType == 5) {
|
// 诊所
|
TCrmClinic crmClinic = crmClinicService.getOne(Wrappers.lambdaQuery(TCrmClinic.class)
|
.eq(TCrmClinic::getUserId, user.getUserId())
|
.last("LIMIT 1"));
|
// ---
|
if (Objects.isNull(crmClinic)) {
|
SysUser sysUser = sysUserService.selectUserById(user.getUserId());
|
crmClinic = crmClinicService.getById(sysUser.getObjectId());
|
}
|
query.setSupplierClinicId(crmClinic.getId());
|
}
|
|
List<TErpGoodsVO> pageList = erpGoodsService.listExport(query, user);
|
List<TErpGoodsDetailExport> exportList = pageList.stream().map(goods -> {
|
TErpGoodsDetailExport exportItem = new TErpGoodsDetailExport();
|
BeanUtils.copyProperties(goods, exportItem);
|
return exportItem;
|
}).collect(Collectors.toList());
|
Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), TErpGoodsDetailExport.class, exportList);
|
HttpServletResponse response = WebUtils.response();
|
assert response != null;
|
response.setContentType("application/vnd.ms-excel");
|
response.setCharacterEncoding("utf-8");
|
ServletOutputStream outputStream = null;
|
try {
|
String fileName = URLEncoder.encode("商品管理信息导出.xls", "utf-8");
|
response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
|
response.setContentType("application/vnd.ms-excel;charset=UTF-8");
|
response.setHeader("Pragma", "no-cache");
|
response.setHeader("Cache-Control", "no-cache");
|
outputStream = response.getOutputStream();
|
workbook.write(outputStream);
|
} catch (IOException e) {
|
e.printStackTrace();
|
} finally {
|
try {
|
outputStream.close();
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
}
|
}
|
|
|
@ApiOperation(value = "商品管理信息导入")
|
@PostMapping("/importFile")
|
@Log(title = "商品管理-导入", businessType = BusinessType.IMPORT)
|
public AjaxResult importFile(@RequestParam(value = "file") MultipartFile file) {
|
|
SysUser user = tokenService.getLoginUser().getUser();
|
JSONObject jsonObject = new JSONObject();
|
ImportParams params = new ImportParams();
|
params.setHeadRows(1); //表头行数
|
InputStream inputStream = null;
|
ArrayList<String> names = new ArrayList<>();
|
ArrayList<TErpGoods> tErpGoods = new ArrayList<>();
|
|
try {
|
inputStream = file.getInputStream();
|
List<TErpGoodsExcel> carAnnuallyImportExcels = ExcelImportUtil.importExcel(inputStream, TErpGoodsExcel.class, params);
|
Set<String> collect = carAnnuallyImportExcels.stream().map(TErpGoodsExcel::getGoodsIdCode).collect(Collectors.toSet());
|
if (collect.size() != carAnnuallyImportExcels.size()) {
|
return AjaxResult.error("导入数据中商品条码重复");
|
}
|
Integer roleType = user.getRoleType();
|
for (TErpGoodsExcel erpGoodsExcel : carAnnuallyImportExcels) {
|
TErpGoods goods = new TErpGoods();
|
|
if (roleType == 4) {
|
// 供应商
|
TCrmSupplier crmSupplier = crmSupplierService.getOne(Wrappers.lambdaQuery(TCrmSupplier.class)
|
.eq(TCrmSupplier::getUserId, user.getUserId())
|
.last("LIMIT 1"));
|
// ***
|
if (Objects.isNull(crmSupplier)) {
|
SysUser sysUser = sysUserService.selectUserById(user.getUserId());
|
crmSupplier = crmSupplierService.getById(sysUser.getObjectId());
|
}
|
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"));
|
// ---
|
if (Objects.isNull(crmClinic)) {
|
SysUser sysUser = sysUserService.selectUserById(user.getUserId());
|
crmClinic = crmClinicService.getById(sysUser.getObjectId());
|
}
|
goods.setSupplierClinicId(crmClinic.getId());
|
goods.setGoodsSource(2);
|
}
|
|
// 判空
|
if (erpGoodsExcel.getGoodsName() == null || erpGoodsExcel.getGoodsName().isEmpty()) {
|
names.add("商品名称不能为空");
|
continue;
|
}
|
if (erpGoodsExcel.getGoodsIdCode() == null || erpGoodsExcel.getGoodsIdCode().isEmpty()
|
|| erpGoodsExcel.getQuasiNumber() == null || erpGoodsExcel.getQuasiNumber().isEmpty()
|
|| erpGoodsExcel.getManufacturer() == null || erpGoodsExcel.getManufacturer().isEmpty()
|
|| erpGoodsExcel.getFormulationSpec() == null || erpGoodsExcel.getFormulationSpec().isEmpty()
|
|| erpGoodsExcel.getPackingSpec() == null || erpGoodsExcel.getPackingSpec().isEmpty()
|
|| erpGoodsExcel.getClinicPurchasePrice() == null || erpGoodsExcel.getClinicPurchasePrice().isEmpty()
|
|| erpGoodsExcel.getWarningInventory() == null || erpGoodsExcel.getWarningInventory().isEmpty()
|
|| erpGoodsExcel.getTypeName() == null || erpGoodsExcel.getTypeName().isEmpty()) {
|
names.add(erpGoodsExcel.getGoodsName() + " :信息有误,请检查后重新提交。");
|
continue;
|
}
|
goods.setGoodsName(erpGoodsExcel.getGoodsName());
|
// 判断数据是否正确
|
// 判断条码是否重复
|
long count = erpGoodsService.count(new QueryWrapper<TErpGoods>().eq("goods_id_code", erpGoodsExcel.getGoodsIdCode()));
|
if (count > 0) {
|
names.add(erpGoodsExcel.getGoodsName() + " :条码重复");
|
continue;
|
}
|
goods.setGoodsIdCode(erpGoodsExcel.getGoodsIdCode());
|
goods.setQuasiNumber(erpGoodsExcel.getQuasiNumber());
|
goods.setManufacturer(erpGoodsExcel.getManufacturer());
|
goods.setFormulationSpec(erpGoodsExcel.getFormulationSpec());
|
goods.setPackingSpec(erpGoodsExcel.getPackingSpec());
|
|
// 商品类型
|
TErpGoodsType one = erpGoodsTypeService.getOne(new LambdaQueryWrapper<TErpGoodsType>().eq(TErpGoodsType::getTypeName, erpGoodsExcel.getTypeName()));
|
if (one == null) {
|
names.add(erpGoodsExcel.getGoodsName() + " :商品类型不存在");
|
continue;
|
}
|
goods.setTypeId(one.getId());
|
|
// 采购价
|
try {
|
goods.setClinicPurchasePrice(new BigDecimal(erpGoodsExcel.getClinicPurchasePrice()).setScale(2, RoundingMode.HALF_UP));
|
} catch (Exception e) {
|
names.add(erpGoodsExcel.getGoodsName() + " :采购价有误");
|
continue;
|
}
|
// 预警库存
|
try {
|
goods.setWarningInventory(Integer.valueOf(erpGoodsExcel.getWarningInventory()));
|
} catch (Exception e) {
|
names.add(erpGoodsExcel.getGoodsName() + " :预警库存有误");
|
continue;
|
}
|
goods.setGoodsYards(erpGoodsExcel.getGoodsYards());
|
try {
|
if (erpGoodsExcel.getMaintenanceInterval() != null && !erpGoodsExcel.getMaintenanceInterval().isEmpty()) {
|
Integer i = Integer.valueOf(erpGoodsExcel.getMaintenanceInterval());
|
}
|
} catch (Exception e) {
|
names.add(erpGoodsExcel.getGoodsName() + " :保养周期有误");
|
continue;
|
}
|
goods.setMaintenanceInterval(erpGoodsExcel.getMaintenanceInterval());
|
|
try {
|
if (erpGoodsExcel.getLowPurchaseQuantity() != null && !erpGoodsExcel.getLowPurchaseQuantity().isEmpty()) {
|
goods.setLowPurchaseQuantity(Integer.valueOf(erpGoodsExcel.getLowPurchaseQuantity()));
|
}
|
} catch (Exception e) {
|
names.add(erpGoodsExcel.getGoodsName() + " :最低采购数量有误");
|
continue;
|
}
|
|
if (erpGoodsExcel.getLowUnitName() != null && !erpGoodsExcel.getLowUnitName().isEmpty()) {
|
TErpGoodsUnit one1 = erpGoodsUnitService.getOne(new LambdaQueryWrapper<TErpGoodsUnit>().eq(TErpGoodsUnit::getUnitName, erpGoodsExcel.getLowUnitName()));
|
if (one1 == null) {
|
names.add(erpGoodsExcel.getGoodsName() + " :最低采购单位有误");
|
continue;
|
}
|
goods.setLowUnitId(one1.getId());
|
}
|
|
|
if (erpGoodsExcel.getIsPrescriptionDrug() != null && !erpGoodsExcel.getIsPrescriptionDrug().isEmpty()) {
|
if (erpGoodsExcel.getIsPrescriptionDrug().equals("是")) {
|
goods.setIsPrescriptionDrug(1);
|
} else if (erpGoodsExcel.getIsPrescriptionDrug().equals("否")) {
|
goods.setIsPrescriptionDrug(2);
|
} else {
|
names.add(erpGoodsExcel.getGoodsName() + " :是否为处方药有误");
|
continue;
|
}
|
}
|
|
if (erpGoodsExcel.getPackingUnitName() != null && !erpGoodsExcel.getPackingUnitName().isEmpty()) {
|
TErpGoodsUnit unit = erpGoodsUnitService.getOne(new LambdaQueryWrapper<TErpGoodsUnit>().eq(TErpGoodsUnit::getUnitName, erpGoodsExcel.getPackingUnitName()));
|
if (unit != null) {
|
goods.setPackingUnitId(unit.getId());
|
} else {
|
names.add(erpGoodsExcel.getGoodsName() + " :包装单位有误");
|
continue;
|
}
|
}
|
|
goods.setInstructionsUse(erpGoodsExcel.getInstructionsUse());
|
goods.setSideEffect(erpGoodsExcel.getSideEffect());
|
goods.setSimplifiedCode(erpGoodsExcel.getSimplifiedCode());
|
goods.setDosageForm(erpGoodsExcel.getDosageForm());
|
goods.setUsageClassification(erpGoodsExcel.getUsageClassification());
|
goods.setProductBrand(erpGoodsExcel.getProductBrand());
|
goods.setPlaceOfOrigin(erpGoodsExcel.getPlaceOfOrigin());
|
goods.setIngredient(erpGoodsExcel.getIngredient());
|
goods.setTrait(erpGoodsExcel.getTrait());
|
goods.setIndication(erpGoodsExcel.getIndication());
|
goods.setTaboo(erpGoodsExcel.getTaboo());
|
goods.setPrecautions(erpGoodsExcel.getPrecautions());
|
goods.setInteraction(erpGoodsExcel.getInteraction());
|
goods.setStorage(erpGoodsExcel.getStorage());
|
tErpGoods.add(goods);
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
return AjaxResult.error("记录导入失败!");
|
} finally {
|
try {
|
inputStream.close();
|
} catch (IOException e) {
|
throw new ServiceException(e.getMessage());
|
}
|
}
|
if (names.size() > 0) {
|
return AjaxResult.error("导入失败记录如下:", names);
|
}
|
erpGoodsService.saveBatch(tErpGoods);
|
return AjaxResult.success();
|
|
}
|
|
/**
|
* 供应商固定商品类型导入。旧商品导入接口保留给非固定类型模板使用。
|
*/
|
@ApiOperation(value = "供应商固定商品类型导入")
|
@PostMapping("/importFixedGoodsFile")
|
@Log(title = "商品管理-固定类型导入", businessType = BusinessType.IMPORT)
|
public AjaxResult importFixedGoodsFile(
|
@RequestParam(value = "file") MultipartFile file,
|
@RequestParam(value = "typeId") String typeId) {
|
SysUser user = tokenService.getLoginUser().getUser();
|
if (user == null || user.getRoleType() == null || user.getRoleType() != 4) {
|
return AjaxResult.error("仅供应商可以导入固定商品类型");
|
}
|
int sheetIndex = getFixedGoodsSheetIndex(typeId);
|
if (sheetIndex < 0) {
|
return AjaxResult.error("商品类型不支持固定模板导入");
|
}
|
if (file == null || file.isEmpty()) {
|
return AjaxResult.error("请选择要导入的文件");
|
}
|
|
TCrmSupplier supplier = getCurrentSupplier(user);
|
if (supplier == null) {
|
return AjaxResult.error("未找到当前供应商信息");
|
}
|
|
List<String> errors = new ArrayList<>();
|
List<TErpGoods> goodsList = new ArrayList<>();
|
Set<String> barcodeSet = new HashSet<>();
|
ImportParams params = new ImportParams();
|
params.setHeadRows(1);
|
params.setStartSheetIndex(sheetIndex);
|
params.setSheetNum(1);
|
|
try (InputStream inputStream = file.getInputStream()) {
|
List<TErpFixedGoodsExcel> rows = ExcelImportUtil.importExcel(
|
inputStream, TErpFixedGoodsExcel.class, params);
|
if (rows == null || rows.isEmpty()) {
|
return AjaxResult.error("所选商品类型工作表没有可导入的数据");
|
}
|
|
for (int index = 0; index < rows.size(); index++) {
|
TErpFixedGoodsExcel row = rows.get(index);
|
if (isBlankFixedGoodsRow(row)) {
|
continue;
|
}
|
String rowName = StringUtils.isBlank(row.getGoodsName())
|
? "第" + (index + 2) + "行"
|
: row.getGoodsName().trim();
|
String validationError = validateFixedGoodsRow(row, typeId);
|
if (validationError != null) {
|
errors.add(rowName + ":" + validationError);
|
continue;
|
}
|
|
String goodsIdCode = row.getGoodsIdCode().trim();
|
if (!barcodeSet.add(goodsIdCode)) {
|
errors.add(rowName + ":商品条码在导入文件中重复");
|
continue;
|
}
|
if (erpGoodsService.count(new QueryWrapper<TErpGoods>()
|
.eq("goods_id_code", goodsIdCode)) > 0) {
|
errors.add(rowName + ":商品条码已存在");
|
continue;
|
}
|
|
try {
|
TErpGoods goods = buildFixedGoods(row, typeId, supplier, user);
|
goodsList.add(goods);
|
} catch (IllegalArgumentException e) {
|
errors.add(rowName + ":" + e.getMessage());
|
}
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
return AjaxResult.error("导入文件解析失败,请确认使用固定商品类型模板");
|
}
|
|
if (goodsList.isEmpty() && errors.isEmpty()) {
|
return AjaxResult.error("所选商品类型工作表没有可导入的数据");
|
}
|
if (!errors.isEmpty()) {
|
return AjaxResult.error("导入失败记录如下:", errors);
|
}
|
erpGoodsService.saveBatch(goodsList);
|
return AjaxResult.success();
|
}
|
|
private int getFixedGoodsSheetIndex(String typeId) {
|
if (GoodsTypeConstants.DRUG_ID.equals(typeId)) {
|
return 0;
|
}
|
if (GoodsTypeConstants.MEDICAL_DEVICE_ID.equals(typeId)) {
|
return 1;
|
}
|
if (GoodsTypeConstants.FOOD_ID.equals(typeId)) {
|
return 2;
|
}
|
return -1;
|
}
|
|
private TCrmSupplier getCurrentSupplier(SysUser user) {
|
TCrmSupplier supplier = crmSupplierService.getOne(
|
Wrappers.lambdaQuery(TCrmSupplier.class)
|
.eq(TCrmSupplier::getUserId, user.getUserId())
|
.last("LIMIT 1"));
|
if (supplier == null) {
|
SysUser sysUser = sysUserService.selectUserById(user.getUserId());
|
if (sysUser != null && sysUser.getObjectId() != null) {
|
supplier = crmSupplierService.getById(sysUser.getObjectId());
|
}
|
}
|
return supplier;
|
}
|
|
private String validateFixedGoodsRow(TErpFixedGoodsExcel row, String typeId) {
|
if (StringUtils.isBlank(row.getGoodsName())) {
|
return "商品名称不能为空";
|
}
|
if (StringUtils.isBlank(row.getGoodsIdCode())) {
|
return "商品条形码不能为空";
|
}
|
if (StringUtils.isBlank(row.getManufacturer())) {
|
return "生产厂家不能为空";
|
}
|
if (StringUtils.isBlank(row.getWarningInventory())) {
|
return "预警库存不能为空";
|
}
|
if (StringUtils.isBlank(row.getPackingUnitName())) {
|
return "包装单位不能为空";
|
}
|
if (GoodsTypeConstants.DRUG_ID.equals(typeId)) {
|
if (StringUtils.isBlank(row.getQuasiNumber())) {
|
return "批准文号或国药准字号不能为空";
|
}
|
if (StringUtils.isBlank(row.getProductType())) {
|
return "商品类型不能为空";
|
}
|
if (StringUtils.isBlank(row.getFormulationSpec())) {
|
return "剂型规格不能为空";
|
}
|
if (StringUtils.isBlank(row.getPackingSpec())) {
|
return "包装规格不能为空";
|
}
|
if (StringUtils.isBlank(row.getEffectivePeriod())) {
|
return "有效时间不能为空";
|
}
|
} else if (GoodsTypeConstants.MEDICAL_DEVICE_ID.equals(typeId)) {
|
if (StringUtils.isBlank(row.getDeviceCategory())) {
|
return "器械类别不能为空";
|
}
|
if (StringUtils.isBlank(row.getProductType())) {
|
return "商品类型不能为空";
|
}
|
if (StringUtils.isBlank(row.getProductTechnicalRequirementNumber())) {
|
return "产品技术要求编号不能为空";
|
}
|
if (StringUtils.isBlank(row.getProductionLicenseOrFilingNumber())) {
|
return "生产许可证或备案凭证编号不能为空";
|
}
|
if (StringUtils.isBlank(row.getRegistrantOrFiler())) {
|
return "注册人或备案人不能为空";
|
}
|
if (StringUtils.isBlank(row.getEffectivePeriod())) {
|
return "有效时间不能为空";
|
}
|
} else if (GoodsTypeConstants.FOOD_ID.equals(typeId)) {
|
if (StringUtils.isBlank(row.getProductionLicenseNumber())) {
|
return "生产许可证号不能为空";
|
}
|
if (StringUtils.isBlank(row.getProductType())) {
|
return "商品类型不能为空";
|
}
|
if (StringUtils.isBlank(row.getPackingSpec())) {
|
return "包装规格不能为空";
|
}
|
if (StringUtils.isBlank(row.getProductCategory())) {
|
return "产品类别不能为空";
|
}
|
}
|
return null;
|
}
|
|
private boolean isBlankFixedGoodsRow(TErpFixedGoodsExcel row) {
|
return Stream.of(
|
row.getGoodsName(), row.getCommonName(), row.getGoodsIdCode(), row.getQuasiNumber(),
|
row.getProductType(), row.getManufacturer(), row.getFormulationSpec(), row.getPackingSpec(),
|
row.getDeviceCategory(), row.getProductTechnicalRequirementNumber(),
|
row.getProductionLicenseOrFilingNumber(), row.getRegistrantOrFiler(), row.getStructureComposition(),
|
row.getApplicableScope(), row.getOriginType(), row.getProductionLicenseNumber(),
|
row.getProductCategory(), row.getProductExecutionStandard(), row.getSpecialFoodFlag(),
|
row.getSpecialFood(), row.getGoodsYards(), row.getMaintenanceInterval(), row.getLowPurchaseQuantity(),
|
row.getLowUnitName(), row.getIsPrescriptionDrug(), row.getGoodsSpec(), row.getWarningInventory(),
|
row.getPackingUnitName(), row.getInstructionsUse(), row.getSideEffect(), row.getSimplifiedCode(),
|
row.getDosageForm(), row.getUsageClassification(), row.getProductBrand(),
|
row.getProductBrandAndPrecautions(), row.getPlaceOfOrigin(), row.getIngredient(), row.getTrait(),
|
row.getIndication(), row.getTaboo(), row.getPrecautions(), row.getInteraction(),
|
row.getAdverseReaction(), row.getStorage(), row.getEffectivePeriod(), row.getOtherDescription())
|
.allMatch(StringUtils::isBlank);
|
}
|
|
private TErpGoods buildFixedGoods(
|
TErpFixedGoodsExcel row,
|
String typeId,
|
TCrmSupplier supplier,
|
SysUser user) {
|
TErpGoods goods = new TErpGoods();
|
goods.setSupplierClinicId(supplier.getId());
|
goods.setGoodsSource(1);
|
goods.setCreateId(user.getUserId().toString());
|
goods.setTypeId(typeId);
|
goods.setGoodsName(row.getGoodsName().trim());
|
goods.setGoodsIdCode(row.getGoodsIdCode().trim());
|
goods.setManufacturer(row.getManufacturer().trim());
|
goods.setQuasiNumber(trim(row.getQuasiNumber()));
|
goods.setFormulationSpec(trim(row.getFormulationSpec()));
|
goods.setPackingSpec(trim(row.getPackingSpec()));
|
goods.setCommonName(trim(row.getCommonName()));
|
goods.setProductType(trim(row.getProductType()));
|
goods.setDeviceCategory(trim(row.getDeviceCategory()));
|
goods.setProductTechnicalRequirementNumber(trim(row.getProductTechnicalRequirementNumber()));
|
goods.setProductionLicenseOrFilingNumber(trim(row.getProductionLicenseOrFilingNumber()));
|
goods.setRegistrantOrFiler(trim(row.getRegistrantOrFiler()));
|
goods.setStructureComposition(trim(row.getStructureComposition()));
|
goods.setApplicableScope(trim(row.getApplicableScope()));
|
goods.setOriginType(trim(row.getOriginType()));
|
goods.setProductionLicenseNumber(trim(row.getProductionLicenseNumber()));
|
goods.setProductCategory(trim(row.getProductCategory()));
|
goods.setProductExecutionStandard(trim(row.getProductExecutionStandard()));
|
goods.setSpecialFoodFlag(parseFlag(row.getSpecialFoodFlag(), "是否特殊食品"));
|
goods.setSpecialFood(trim(row.getSpecialFood()));
|
goods.setGoodsYards(trim(row.getGoodsYards()));
|
parseInteger(row.getMaintenanceInterval(), "保养周期");
|
goods.setMaintenanceInterval(trim(row.getMaintenanceInterval()));
|
goods.setLowPurchaseQuantity(parseInteger(row.getLowPurchaseQuantity(), "最低采购数量"));
|
goods.setIsPrescriptionDrug(parseFlag(row.getIsPrescriptionDrug(), "是否为处方药"));
|
goods.setGoodsSpec(StringUtils.isBlank(row.getGoodsSpec())
|
? buildGoodsSpec(row.getFormulationSpec(), row.getPackingSpec())
|
: row.getGoodsSpec().trim());
|
goods.setWarningInventory(parseInteger(row.getWarningInventory(), "预警库存"));
|
goods.setLowUnitId(findUnitId(row.getLowUnitName(), "最低采购单位"));
|
goods.setPackingUnitId(findUnitId(row.getPackingUnitName(), "包装单位"));
|
goods.setInstructionsUse(trim(row.getInstructionsUse()));
|
goods.setSideEffect(StringUtils.isBlank(row.getSideEffect())
|
? trim(row.getAdverseReaction()) : row.getSideEffect().trim());
|
goods.setSimplifiedCode(trim(row.getSimplifiedCode()));
|
goods.setDosageForm(trim(row.getDosageForm()));
|
goods.setUsageClassification(trim(row.getUsageClassification()));
|
goods.setProductBrand(StringUtils.isBlank(row.getProductBrand())
|
? trim(row.getProductBrandAndPrecautions())
|
: row.getProductBrand().trim());
|
goods.setPlaceOfOrigin(trim(row.getPlaceOfOrigin()));
|
goods.setIngredient(trim(row.getIngredient()));
|
goods.setTrait(trim(row.getTrait()));
|
goods.setIndication(trim(row.getIndication()));
|
goods.setTaboo(trim(row.getTaboo()));
|
goods.setPrecautions(trim(row.getPrecautions()));
|
goods.setInteraction(trim(row.getInteraction()));
|
goods.setStorage(trim(row.getStorage()));
|
goods.setEffectivePeriod(trim(row.getEffectivePeriod()));
|
goods.setOtherDescription(trim(row.getOtherDescription()));
|
return goods;
|
}
|
|
private String findUnitId(String unitName, String fieldName) {
|
if (StringUtils.isBlank(unitName)) {
|
return null;
|
}
|
TErpGoodsUnit unit = erpGoodsUnitService.getOne(
|
new LambdaQueryWrapper<TErpGoodsUnit>().eq(TErpGoodsUnit::getUnitName, unitName.trim()));
|
if (unit == null) {
|
throw new IllegalArgumentException(fieldName + "有误");
|
}
|
return unit.getId();
|
}
|
|
private Integer parseInteger(String value, String fieldName) {
|
if (StringUtils.isBlank(value)) {
|
return null;
|
}
|
try {
|
return new BigDecimal(value.trim()).intValueExact();
|
} catch (Exception e) {
|
throw new IllegalArgumentException(fieldName + "有误");
|
}
|
}
|
|
private Integer parseFlag(String value, String fieldName) {
|
if (StringUtils.isBlank(value)) {
|
return null;
|
}
|
String normalized = value.trim();
|
if ("是".equals(normalized) || "1".equals(normalized)) {
|
return 1;
|
}
|
if ("否".equals(normalized) || "2".equals(normalized)) {
|
return 2;
|
}
|
throw new IllegalArgumentException(fieldName + "有误");
|
}
|
|
private String trim(String value) {
|
return StringUtils.isBlank(value) ? null : value.trim();
|
}
|
|
|
@ApiOperation(value = "平台设置分佣")
|
@PostMapping(value = "/setCommission")
|
@Log(title = "商品管理-平台设置分佣", businessType = BusinessType.UPDATE)
|
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));
|
goods.setRetailPrice(dto.getRetailPrice());
|
goods.setSalesAmount(dto.getRetailPrice());
|
erpGoodsService.updateById(goods);
|
}
|
return R.ok();
|
}
|
|
@Log(title = "云仓商品关联导入模板-导出", businessType = BusinessType.EXPORT)
|
@ApiOperation(value = "云仓商品关联导入模板")
|
@PostMapping("/cloudGoodsImportTemplate")
|
public void cloudGoodsImportTemplate() {
|
List<TErpCloudGoodsExcel> pageList = new ArrayList<>();
|
Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), TErpCloudGoodsExcel.class, pageList);
|
HttpServletResponse response = WebUtils.response();
|
assert response != null;
|
response.setContentType("application/vnd.ms-excel");
|
response.setCharacterEncoding("utf-8");
|
ServletOutputStream outputStream = null;
|
try {
|
String fileName = URLEncoder.encode("云仓商品关联导入模板.xls", "utf-8");
|
response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
|
response.setContentType("application/vnd.ms-excel;charset=UTF-8");
|
response.setHeader("Pragma", "no-cache");
|
response.setHeader("Cache-Control", "no-cache");
|
outputStream = response.getOutputStream();
|
workbook.write(outputStream);
|
} catch (IOException e) {
|
e.printStackTrace();
|
} finally {
|
try {
|
outputStream.close();
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
}
|
}
|
|
@Log(title = "云仓商品导入-导入", businessType = BusinessType.IMPORT)
|
@ApiOperation(value = "云仓商品信息导入",notes = "cloudWarehouse:云仓类型 1=旺店通")
|
@PostMapping("/importCloudGoodsFile")
|
public AjaxResult importCloudGoodsFile(@RequestParam(value = "file") MultipartFile file,
|
@RequestParam(value = "cloudWarehouse") Integer cloudWarehouse) {
|
ImportParams params = new ImportParams();
|
params.setHeadRows(1); //表头行数
|
InputStream inputStream = null;
|
ArrayList<String> names = new ArrayList<>();
|
ArrayList<TErpGoods> tErpGoods = new ArrayList<>();
|
|
try {
|
inputStream = file.getInputStream();
|
List<TErpCloudGoodsExcel> erpCloudGoodsExcels = ExcelImportUtil.importExcel(inputStream, TErpCloudGoodsExcel.class, params);
|
Set<String> collect = erpCloudGoodsExcels.stream().map(TErpCloudGoodsExcel::getCloudSpecCode).collect(Collectors.toSet());
|
if (collect.size() != erpCloudGoodsExcels.size()) {
|
return AjaxResult.error("导入数据中商品规格编码重复");
|
}
|
for (TErpCloudGoodsExcel erpCloudGoodsExcel : erpCloudGoodsExcels) {
|
// 判空
|
if (StringUtils.isBlank(erpCloudGoodsExcel.getGoodsName())) {
|
names.add("云仓商品名称不能为空");
|
continue;
|
}
|
if (StringUtils.isBlank(erpCloudGoodsExcel.getCloudGoodsCode())) {
|
names.add("云仓商品编码不能为空");
|
continue;
|
}
|
if (StringUtils.isBlank(erpCloudGoodsExcel.getCloudSpecCode())) {
|
names.add("云仓商品规格编码不能为空");
|
continue;
|
}
|
if (StringUtils.isBlank(erpCloudGoodsExcel.getCloudGoodsId())) {
|
names.add("云仓商品ID不能为空");
|
continue;
|
}
|
if (StringUtils.isBlank(erpCloudGoodsExcel.getCloudSpecId())) {
|
names.add("云仓商品规格ID不能为空");
|
continue;
|
}
|
TErpGoods erpGoods = erpGoodsService.getOne(Wrappers.lambdaQuery(TErpGoods.class)
|
.eq(TErpGoods::getGoodsName, erpCloudGoodsExcel.getGoodsName())
|
.last("LIMIT 1"));
|
if (Objects.isNull(erpGoods)) {
|
names.add(erpCloudGoodsExcel.getGoodsName() + " :信息有误,未查询到匹配得商品。");
|
continue;
|
}
|
erpGoods.setCloudWarehouse(cloudWarehouse);
|
erpGoods.setCloudGoodsCode(erpCloudGoodsExcel.getCloudGoodsCode());
|
erpGoods.setCloudSpecCode(erpCloudGoodsExcel.getCloudSpecCode());
|
erpGoods.setCloudGoodsId(erpCloudGoodsExcel.getCloudGoodsId());
|
erpGoods.setCloudSpecId(erpCloudGoodsExcel.getCloudSpecId());
|
tErpGoods.add(erpGoods);
|
}
|
erpGoodsService.updateBatchById(tErpGoods);
|
} catch (Exception e) {
|
e.printStackTrace();
|
return AjaxResult.error("记录导入失败!");
|
} finally {
|
try {
|
inputStream.close();
|
} catch (IOException e) {
|
throw new ServiceException(e.getMessage());
|
}
|
}
|
if (!names.isEmpty()) {
|
return AjaxResult.error("导入失败记录如下:", names);
|
}
|
return AjaxResult.success();
|
|
}
|
|
}
|