ERP:增加供应商的实现

This commit is contained in:
YunaiV 2024-02-06 17:59:44 +08:00
parent 46d26659bf
commit bfe3dc95fe
17 changed files with 650 additions and 11 deletions

View File

@ -9,12 +9,16 @@ import cn.iocoder.yudao.framework.common.exception.ErrorCode;
*/ */
public interface ErrorCodeConstants { public interface ErrorCodeConstants {
// ========== 销售订单1-020-000-000 ========== // ========== ERP 供应商1-030-100-000 ==========
ErrorCode SALE_ORDER_NOT_EXISTS = new ErrorCode(1_020_000_000, "销售订单不存在"); ErrorCode SUPPLIER_NOT_EXISTS = new ErrorCode(1_030_100_000, "供应商不存在");
ErrorCode SUPPLIER_NOT_ENABLE = new ErrorCode(1_030_100_000, "供应商({})未启用");
// ========== 销售订单1-030-200-000 ==========
ErrorCode SALE_ORDER_NOT_EXISTS = new ErrorCode(1_020_200_000, "销售订单不存在");
// ========== ERP 仓库 1-030-400-000 ========== // ========== ERP 仓库 1-030-400-000 ==========
ErrorCode WAREHOUSE_NOT_EXISTS = new ErrorCode(1_030_400_000, "仓库不存在"); ErrorCode WAREHOUSE_NOT_EXISTS = new ErrorCode(1_030_400_000, "仓库不存在");
ErrorCode WAREHOUSE_NOT_ENABLE = new ErrorCode(1_030_500_001, "仓库({})未启用"); ErrorCode WAREHOUSE_NOT_ENABLE = new ErrorCode(1_030_400_001, "仓库({})未启用");
// ========== ERP 其它入库单 1-030-401-000 ========== // ========== ERP 其它入库单 1-030-401-000 ==========
ErrorCode STOCK_IN_NOT_EXISTS = new ErrorCode(1_030_401_000, "其它入库单不存在"); ErrorCode STOCK_IN_NOT_EXISTS = new ErrorCode(1_030_401_000, "其它入库单不存在");

View File

@ -0,0 +1,102 @@
package cn.iocoder.yudao.module.erp.controller.admin.purchase;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.supplier.ErpSupplierPageReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.supplier.ErpSupplierRespVO;
import cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.supplier.ErpSupplierSaveReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.supplier.ErpSupplierDO;
import cn.iocoder.yudao.module.erp.service.purchase.ErpSupplierService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
@Tag(name = "管理后台 - ERP 供应商")
@RestController
@RequestMapping("/erp/supplier")
@Validated
public class ErpSupplierController {
@Resource
private ErpSupplierService supplierService;
@PostMapping("/create")
@Operation(summary = "创建供应商")
@PreAuthorize("@ss.hasPermission('erp:supplier:create')")
public CommonResult<Long> createSupplier(@Valid @RequestBody ErpSupplierSaveReqVO createReqVO) {
return success(supplierService.createSupplier(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新供应商")
@PreAuthorize("@ss.hasPermission('erp:supplier:update')")
public CommonResult<Boolean> updateSupplier(@Valid @RequestBody ErpSupplierSaveReqVO updateReqVO) {
supplierService.updateSupplier(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除供应商")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('erp:supplier:delete')")
public CommonResult<Boolean> deleteSupplier(@RequestParam("id") Long id) {
supplierService.deleteSupplier(id);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得供应商")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('erp:supplier:query')")
public CommonResult<ErpSupplierRespVO> getSupplier(@RequestParam("id") Long id) {
ErpSupplierDO supplier = supplierService.getSupplier(id);
return success(BeanUtils.toBean(supplier, ErpSupplierRespVO.class));
}
@GetMapping("/page")
@Operation(summary = "获得供应商分页")
@PreAuthorize("@ss.hasPermission('erp:supplier:query')")
public CommonResult<PageResult<ErpSupplierRespVO>> getSupplierPage(@Valid ErpSupplierPageReqVO pageReqVO) {
PageResult<ErpSupplierDO> pageResult = supplierService.getSupplierPage(pageReqVO);
return success(BeanUtils.toBean(pageResult, ErpSupplierRespVO.class));
}
@GetMapping("/simple-list")
@Operation(summary = "获得供应商精简列表", description = "只包含被开启的供应商,主要用于前端的下拉选项")
public CommonResult<List<ErpSupplierRespVO>> getSupplierSimpleList() {
List<ErpSupplierDO> list = supplierService.getSupplierListByStatus(CommonStatusEnum.ENABLE.getStatus());
return success(convertList(list, supplier -> new ErpSupplierRespVO().setId(supplier.getId()).setName(supplier.getName())));
}
@GetMapping("/export-excel")
@Operation(summary = "导出供应商 Excel")
@PreAuthorize("@ss.hasPermission('erp:supplier:export')")
@OperateLog(type = EXPORT)
public void exportSupplierExcel(@Valid ErpSupplierPageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<ErpSupplierDO> list = supplierService.getSupplierPage(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "供应商.xls", "数据", ErpSupplierRespVO.class,
BeanUtils.toBean(list, ErpSupplierRespVO.class));
}
}

View File

@ -0,0 +1,24 @@
package cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.supplier;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@Schema(description = "管理后台 - ERP 供应商分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ErpSupplierPageReqVO extends PageParam {
@Schema(description = "供应商名称", example = "芋道源码")
private String name;
@Schema(description = "手机号码", example = "15601691300")
private String mobile;
@Schema(description = "联系电话", example = "18818288888")
private String telephone;
}

View File

@ -0,0 +1,84 @@
package cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.supplier;
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
import cn.iocoder.yudao.module.system.enums.DictTypeConstants;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDateTime;
@Schema(description = "管理后台 - ERP 供应商 Response VO")
@Data
@ExcelIgnoreUnannotated
public class ErpSupplierRespVO {
@Schema(description = "供应商编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "17791")
@ExcelProperty("供应商编号")
private Long id;
@Schema(description = "供应商名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道源码")
@ExcelProperty("供应商名称")
private String name;
@Schema(description = "联系人", example = "芋艿")
@ExcelProperty("联系人")
private String contact;
@Schema(description = "手机号码", example = "15601691300")
@ExcelProperty("手机号码")
private String mobile;
@Schema(description = "联系电话", example = "18818288888")
@ExcelProperty("联系电话")
private String telephone;
@Schema(description = "电子邮箱", example = "76853@qq.com")
@ExcelProperty("电子邮箱")
private String email;
@Schema(description = "传真", example = "20 7123 4567")
@ExcelProperty("传真")
private String fax;
@Schema(description = "备注", example = "你猜")
@ExcelProperty("备注")
private String remark;
@Schema(description = "开启状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@ExcelProperty(value = "开启状态", converter = DictConvert.class)
@DictFormat(DictTypeConstants.COMMON_STATUS)
private Integer status;
@Schema(description = "排序", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
@ExcelProperty("排序")
private Integer sort;
@Schema(description = "纳税人识别号", example = "91130803MA098BY05W")
@ExcelProperty("纳税人识别号")
private String taxNo;
@Schema(description = "税率", example = "10")
@ExcelProperty("税率")
private BigDecimal taxPercent;
@Schema(description = "开户行", example = "张三")
@ExcelProperty("开户行")
private String bankName;
@Schema(description = "开户账号", example = "622908212277228617")
@ExcelProperty("开户账号")
private String bankAccount;
@Schema(description = "开户地址", example = "兴业银行浦东支行")
@ExcelProperty("开户地址")
private String bankAddress;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("创建时间")
private LocalDateTime createTime;
}

View File

@ -0,0 +1,71 @@
package cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.supplier;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.validation.InEnum;
import cn.iocoder.yudao.framework.common.validation.Mobile;
import cn.iocoder.yudao.framework.common.validation.Telephone;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import java.math.BigDecimal;
@Schema(description = "管理后台 - ERP 供应商新增/修改 Request VO")
@Data
public class ErpSupplierSaveReqVO {
@Schema(description = "供应商编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "17791")
private Long id;
@Schema(description = "供应商名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道源码")
@NotEmpty(message = "供应商名称不能为空")
private String name;
@Schema(description = "联系人", example = "芋艿")
private String contact;
@Schema(description = "手机号码", example = "15601691300")
@Mobile
private String mobile;
@Schema(description = "联系电话", example = "18818288888")
@Telephone
private String telephone;
@Schema(description = "电子邮箱", example = "76853@qq.com")
@Email
private String email;
@Schema(description = "传真", example = "20 7123 4567")
private String fax;
@Schema(description = "备注", example = "你猜")
private String remark;
@Schema(description = "开启状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@NotNull(message = "开启状态不能为空")
@InEnum(value = CommonStatusEnum.class)
private Integer status;
@Schema(description = "排序", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
@NotNull(message = "排序不能为空")
private Integer sort;
@Schema(description = "纳税人识别号", example = "91130803MA098BY05W")
private String taxNo;
@Schema(description = "税率", example = "10")
private BigDecimal taxPercent;
@Schema(description = "开户行", example = "张三")
private String bankName;
@Schema(description = "开户账号", example = "622908212277228617")
private String bankAccount;
@Schema(description = "开户地址", example = "兴业银行浦东支行")
private String bankAddress;
}

View File

@ -15,7 +15,9 @@ import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in.ErpStockInSaveRe
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockDO; import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockInDO; import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockInDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockInItemDO; import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockInItemDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.supplier.ErpSupplierDO;
import cn.iocoder.yudao.module.erp.service.product.ErpProductService; import cn.iocoder.yudao.module.erp.service.product.ErpProductService;
import cn.iocoder.yudao.module.erp.service.purchase.ErpSupplierService;
import cn.iocoder.yudao.module.erp.service.stock.ErpStockInService; import cn.iocoder.yudao.module.erp.service.stock.ErpStockInService;
import cn.iocoder.yudao.module.erp.service.stock.ErpStockService; import cn.iocoder.yudao.module.erp.service.stock.ErpStockService;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi; import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
@ -52,6 +54,8 @@ public class ErpStockInController {
private ErpStockService stockService; private ErpStockService stockService;
@Resource @Resource
private ErpProductService productService; private ErpProductService productService;
@Resource
private ErpSupplierService supplierService;
@Resource @Resource
private AdminUserApi adminUserApi; private AdminUserApi adminUserApi;
@ -90,7 +94,7 @@ public class ErpStockInController {
return success(null); return success(null);
} }
List<ErpStockInItemDO> stockInItems = stockInService.getStockInItemListByInId(id); List<ErpStockInItemDO> stockInItems = stockInService.getStockInItemListByInId(id);
// TODO 芋艿有个锤子
return success(BeanUtils.toBean(stockIn, ErpStockInRespVO.class, stockInVO -> return success(BeanUtils.toBean(stockIn, ErpStockInRespVO.class, stockInVO ->
stockInVO.setItems(BeanUtils.toBean(stockInItems, ErpStockInRespVO.Item.class, item -> { stockInVO.setItems(BeanUtils.toBean(stockInItems, ErpStockInRespVO.Item.class, item -> {
ErpStockDO stock = stockService.getStock(item.getProductId(), item.getWarehouseId()); ErpStockDO stock = stockService.getStock(item.getProductId(), item.getWarehouseId());
@ -129,7 +133,10 @@ public class ErpStockInController {
// 1.2 商品信息 // 1.2 商品信息
Map<Long, ErpProductRespVO> productMap = productService.getProductVOMap( Map<Long, ErpProductRespVO> productMap = productService.getProductVOMap(
convertSet(stockInItemList, ErpStockInItemDO::getProductId)); convertSet(stockInItemList, ErpStockInItemDO::getProductId));
// 1.3 管理员信息 // 1.3 供应商信息
Map<Long, ErpSupplierDO> supplierMap = supplierService.getSupplierMap(
convertSet(pageResult.getList(), ErpStockInDO::getSupplierId));
// 1.4 管理员信息
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap( Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(
convertSet(pageResult.getList(), erpStockRecordDO -> Long.parseLong(erpStockRecordDO.getCreator()))); convertSet(pageResult.getList(), erpStockRecordDO -> Long.parseLong(erpStockRecordDO.getCreator())));
// 2. 开始拼接 // 2. 开始拼接
@ -138,6 +145,7 @@ public class ErpStockInController {
item -> MapUtils.findAndThen(productMap, item.getProductId(), item -> MapUtils.findAndThen(productMap, item.getProductId(),
product -> item.setProductName(product.getName()).setProductUnitName(product.getUnitName())))); product -> item.setProductName(product.getName()).setProductUnitName(product.getUnitName()))));
stockIn.setProductNames(CollUtil.join(stockIn.getItems(), "", ErpStockInRespVO.Item::getProductName)); stockIn.setProductNames(CollUtil.join(stockIn.getItems(), "", ErpStockInRespVO.Item::getProductName));
MapUtils.findAndThen(supplierMap, stockIn.getSupplierId(), supplier -> stockIn.setSupplierName(supplier.getName()));
MapUtils.findAndThen(userMap, Long.parseLong(stockIn.getCreator()), user -> stockIn.setCreatorName(user.getNickname())); MapUtils.findAndThen(userMap, Long.parseLong(stockIn.getCreator()), user -> stockIn.setCreatorName(user.getNickname()));
}); });
} }

View File

@ -39,4 +39,10 @@ public class ErpStockInPageReqVO extends PageParam {
@Schema(description = "创建者") @Schema(description = "创建者")
private String creator; private String creator;
@Schema(description = "产品编号", example = "1")
private Long productId;
@Schema(description = "仓库编号", example = "1")
private Long warehouseId;
} }

View File

@ -27,8 +27,10 @@ public class ErpStockInRespVO {
private String no; private String no;
@Schema(description = "供应商编号", example = "3113") @Schema(description = "供应商编号", example = "3113")
@ExcelProperty("供应商编号")
private Long supplierId; private Long supplierId;
@Schema(description = "供应商名称", example = "芋道")
@ExcelProperty("供应商名称")
private String supplierName;
@Schema(description = "入库时间", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "入库时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("入库时间") @ExcelProperty("入库时间")

View File

@ -0,0 +1,90 @@
package cn.iocoder.yudao.module.erp.dal.dataobject.supplier;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.*;
import java.math.BigDecimal;
/**
* ERP 供应商 DO
*
* @author 芋道源码
*/
@TableName("erp_supplier")
@KeySequence("erp_supplier_seq") // 用于 OraclePostgreSQLKingbaseDB2H2 数据库的主键自增如果是 MySQL 等数据库可不写
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ErpSupplierDO extends BaseDO {
/**
* 供应商编号
*/
@TableId
private Long id;
/**
* 供应商名称
*/
private String name;
/**
* 联系人
*/
private String contact;
/**
* 手机号码
*/
private String mobile;
/**
* 联系电话
*/
private String telephone;
/**
* 电子邮箱
*/
private String email;
/**
* 传真
*/
private String fax;
/**
* 备注
*/
private String remark;
/**
* 开启状态
*
* 枚举 {@link cn.iocoder.yudao.framework.common.enums.CommonStatusEnum}
*/
private Integer status;
/**
* 排序
*/
private Integer sort;
/**
* 纳税人识别号
*/
private String taxNo;
/**
* 税率
*/
private BigDecimal taxPercent;
/**
* 开户行
*/
private String bankName;
/**
* 开户账号
*/
private String bankAccount;
/**
* 开户地址
*/
private String bankAddress;
}

View File

@ -0,0 +1,32 @@
package cn.iocoder.yudao.module.erp.dal.mysql.purchase;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.supplier.ErpSupplierPageReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.supplier.ErpSupplierDO;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* ERP 供应商 Mapper
*
* @author 芋道源码
*/
@Mapper
public interface ErpSupplierMapper extends BaseMapperX<ErpSupplierDO> {
default PageResult<ErpSupplierDO> selectPage(ErpSupplierPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<ErpSupplierDO>()
.likeIfPresent(ErpSupplierDO::getName, reqVO.getName())
.likeIfPresent(ErpSupplierDO::getMobile, reqVO.getMobile())
.likeIfPresent(ErpSupplierDO::getTelephone, reqVO.getTelephone())
.orderByDesc(ErpSupplierDO::getId));
}
default List<ErpSupplierDO> selectListByStatus(Integer status) {
return selectList(ErpSupplierDO::getStatus, status);
}
}

View File

@ -2,9 +2,10 @@ package cn.iocoder.yudao.module.erp.dal.mysql.stock;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.framework.mybatis.core.query.MPJLambdaWrapperX;
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in.ErpStockInPageReqVO; import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in.ErpStockInPageReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockInDO; import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockInDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockInItemDO;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
/** /**
@ -16,14 +17,21 @@ import org.apache.ibatis.annotations.Mapper;
public interface ErpStockInMapper extends BaseMapperX<ErpStockInDO> { public interface ErpStockInMapper extends BaseMapperX<ErpStockInDO> {
default PageResult<ErpStockInDO> selectPage(ErpStockInPageReqVO reqVO) { default PageResult<ErpStockInDO> selectPage(ErpStockInPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<ErpStockInDO>() MPJLambdaWrapperX<ErpStockInDO> query = new MPJLambdaWrapperX<ErpStockInDO>()
.eqIfPresent(ErpStockInDO::getNo, reqVO.getNo()) .eqIfPresent(ErpStockInDO::getNo, reqVO.getNo())
.eqIfPresent(ErpStockInDO::getSupplierId, reqVO.getSupplierId()) .eqIfPresent(ErpStockInDO::getSupplierId, reqVO.getSupplierId())
.betweenIfPresent(ErpStockInDO::getInTime, reqVO.getInTime()) .betweenIfPresent(ErpStockInDO::getInTime, reqVO.getInTime())
.eqIfPresent(ErpStockInDO::getStatus, reqVO.getStatus()) .eqIfPresent(ErpStockInDO::getStatus, reqVO.getStatus())
.likeIfPresent(ErpStockInDO::getRemark, reqVO.getRemark()) .likeIfPresent(ErpStockInDO::getRemark, reqVO.getRemark())
.eqIfPresent(ErpStockInDO::getCreator, reqVO.getCreator()) .eqIfPresent(ErpStockInDO::getCreator, reqVO.getCreator())
.orderByDesc(ErpStockInDO::getId)); .orderByDesc(ErpStockInDO::getId);
if (reqVO.getWarehouseId() != null || reqVO.getProductId() != null) {
query.leftJoin(ErpStockInItemDO.class, ErpStockInItemDO::getInId, ErpStockInDO::getId)
.eq(reqVO.getWarehouseId() != null, ErpStockInItemDO::getWarehouseId, reqVO.getWarehouseId())
.eq(reqVO.getProductId() != null, ErpStockInItemDO::getProductId, reqVO.getProductId())
.groupBy(ErpStockInDO::getId); // 避免 1 对多查询产生相同的 1
}
return selectJoinPage(reqVO, ErpStockInDO.class, query);
} }
} }

View File

@ -41,6 +41,7 @@ public class ErpProductServiceImpl implements ErpProductService {
@Override @Override
public Long createProduct(ProductSaveReqVO createReqVO) { public Long createProduct(ProductSaveReqVO createReqVO) {
// TODO 芋艿校验分类
// 插入 // 插入
ErpProductDO product = BeanUtils.toBean(createReqVO, ErpProductDO.class); ErpProductDO product = BeanUtils.toBean(createReqVO, ErpProductDO.class);
productMapper.insert(product); productMapper.insert(product);
@ -50,6 +51,7 @@ public class ErpProductServiceImpl implements ErpProductService {
@Override @Override
public void updateProduct(ProductSaveReqVO updateReqVO) { public void updateProduct(ProductSaveReqVO updateReqVO) {
// TODO 芋艿校验分类
// 校验存在 // 校验存在
validateProductExists(updateReqVO.getId()); validateProductExists(updateReqVO.getId());
// 更新 // 更新

View File

@ -0,0 +1,94 @@
package cn.iocoder.yudao.module.erp.service.purchase;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.supplier.ErpSupplierPageReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.supplier.ErpSupplierSaveReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.supplier.ErpSupplierDO;
import jakarta.validation.Valid;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
/**
* ERP 供应商 Service 接口
*
* @author 芋道源码
*/
public interface ErpSupplierService {
/**
* 创建供应商
*
* @param createReqVO 创建信息
* @return 编号
*/
Long createSupplier(@Valid ErpSupplierSaveReqVO createReqVO);
/**
* 更新供应商
*
* @param updateReqVO 更新信息
*/
void updateSupplier(@Valid ErpSupplierSaveReqVO updateReqVO);
/**
* 删除供应商
*
* @param id 编号
*/
void deleteSupplier(Long id);
/**
* 获得供应商
*
* @param id 编号
* @return 供应商
*/
ErpSupplierDO getSupplier(Long id);
/**
* 校验供应商
*
* @param id 编号
* @return 供应商
*/
ErpSupplierDO validateSupplier(Long id);
/**
* 获得供应商列表
*
* @param ids 编号列表
* @return 供应商列表
*/
List<ErpSupplierDO> getSupplierList(Collection<Long> ids);
/**
* 获得供应商 Map
*
* @param ids 编号列表
* @return 供应商 Map
*/
default Map<Long, ErpSupplierDO> getSupplierMap(Collection<Long> ids) {
return convertMap(getSupplierList(ids), ErpSupplierDO::getId);
}
/**
* 获得供应商分页
*
* @param pageReqVO 分页查询
* @return 供应商分页
*/
PageResult<ErpSupplierDO> getSupplierPage(ErpSupplierPageReqVO pageReqVO);
/**
* 获得指定状态的供应商列表
*
* @param status 状态
* @return 供应商列表
*/
List<ErpSupplierDO> getSupplierListByStatus(Integer status);
}

View File

@ -0,0 +1,94 @@
package cn.iocoder.yudao.module.erp.service.purchase;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.supplier.ErpSupplierPageReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.supplier.ErpSupplierSaveReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.supplier.ErpSupplierDO;
import cn.iocoder.yudao.module.erp.dal.mysql.purchase.ErpSupplierMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import java.util.Collection;
import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.*;
/**
* ERP 供应商 Service 实现类
*
* @author 芋道源码
*/
@Service
@Validated
public class ErpSupplierServiceImpl implements ErpSupplierService {
@Resource
private ErpSupplierMapper supplierMapper;
@Override
public Long createSupplier(ErpSupplierSaveReqVO createReqVO) {
ErpSupplierDO supplier = BeanUtils.toBean(createReqVO, ErpSupplierDO.class);
supplierMapper.insert(supplier);
return supplier.getId();
}
@Override
public void updateSupplier(ErpSupplierSaveReqVO updateReqVO) {
// 校验存在
validateSupplierExists(updateReqVO.getId());
// 更新
ErpSupplierDO updateObj = BeanUtils.toBean(updateReqVO, ErpSupplierDO.class);
supplierMapper.updateById(updateObj);
}
@Override
public void deleteSupplier(Long id) {
// 校验存在
validateSupplierExists(id);
// 删除
supplierMapper.deleteById(id);
}
private void validateSupplierExists(Long id) {
if (supplierMapper.selectById(id) == null) {
throw exception(SUPPLIER_NOT_EXISTS);
}
}
@Override
public ErpSupplierDO getSupplier(Long id) {
return supplierMapper.selectById(id);
}
@Override
public ErpSupplierDO validateSupplier(Long id) {
ErpSupplierDO supplier = supplierMapper.selectById(id);
if (supplier == null) {
throw exception(WAREHOUSE_NOT_EXISTS);
}
if (CommonStatusEnum.isDisable(supplier.getStatus())) {
throw exception(WAREHOUSE_NOT_ENABLE, supplier.getName());
}
return supplier;
}
@Override
public List<ErpSupplierDO> getSupplierList(Collection<Long> ids) {
return supplierMapper.selectBatchIds(ids);
}
@Override
public PageResult<ErpSupplierDO> getSupplierPage(ErpSupplierPageReqVO pageReqVO) {
return supplierMapper.selectPage(pageReqVO);
}
@Override
public List<ErpSupplierDO> getSupplierListByStatus(Integer status) {
return supplierMapper.selectListByStatus(status);
}
}

View File

@ -12,6 +12,7 @@ import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockInItemMapper;
import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockInMapper; import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockInMapper;
import cn.iocoder.yudao.module.erp.enums.ErpAuditStatus; import cn.iocoder.yudao.module.erp.enums.ErpAuditStatus;
import cn.iocoder.yudao.module.erp.service.product.ErpProductService; import cn.iocoder.yudao.module.erp.service.product.ErpProductService;
import cn.iocoder.yudao.module.erp.service.purchase.ErpSupplierService;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -46,13 +47,16 @@ public class ErpStockInServiceImpl implements ErpStockInService {
private ErpProductService productService; private ErpProductService productService;
@Resource @Resource
private ErpWarehouseService warehouseService; private ErpWarehouseService warehouseService;
@Resource
private ErpSupplierService supplierService;
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Long createStockIn(ErpStockInSaveReqVO createReqVO) { public Long createStockIn(ErpStockInSaveReqVO createReqVO) {
// 1.1 校验入库项的有效性 // 1.1 校验入库项的有效性
List<ErpStockInItemDO> stockInItems = validateStockInItems(createReqVO.getItems()); List<ErpStockInItemDO> stockInItems = validateStockInItems(createReqVO.getItems());
// 1.2 TODO 芋艿校验供应商 // 1.2 校验供应商
supplierService.validateSupplier(createReqVO.getSupplierId());
// 2.1 插入入库单 // 2.1 插入入库单
ErpStockInDO stockIn = BeanUtils.toBean(createReqVO, ErpStockInDO.class, in -> in ErpStockInDO stockIn = BeanUtils.toBean(createReqVO, ErpStockInDO.class, in -> in
@ -71,7 +75,8 @@ public class ErpStockInServiceImpl implements ErpStockInService {
public void updateStockIn(ErpStockInSaveReqVO updateReqVO) { public void updateStockIn(ErpStockInSaveReqVO updateReqVO) {
// 1.1 校验存在 // 1.1 校验存在
validateStockInExists(updateReqVO.getId()); validateStockInExists(updateReqVO.getId());
// 1.2 TODO 芋艿校验供应商 // 1.2 校验供应商
supplierService.validateSupplier(updateReqVO.getSupplierId());
// 1.3 校验入库项的有效性 // 1.3 校验入库项的有效性
List<ErpStockInItemDO> stockInItems = validateStockInItems(updateReqVO.getItems()); List<ErpStockInItemDO> stockInItems = validateStockInItems(updateReqVO.getItems());

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.iocoder.yudao.module.erp.dal.mysql.purchase.ErpSupplierMapper">
<!--
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
文档可见https://www.iocoder.cn/MyBatis/x-plugins/
-->
</mapper>

View File

@ -188,6 +188,7 @@ logging:
cn.iocoder.yudao.module.promotion.dal.mysql: debug cn.iocoder.yudao.module.promotion.dal.mysql: debug
cn.iocoder.yudao.module.statistics.dal.mysql: debug cn.iocoder.yudao.module.statistics.dal.mysql: debug
cn.iocoder.yudao.module.crm.dal.mysql: debug cn.iocoder.yudao.module.crm.dal.mysql: debug
cn.iocoder.yudao.module.erp.dal.mysql: debug
org.springframework.context.support.PostProcessorRegistrationDelegate: ERROR # TODO 芋艿先禁用Spring Boot 3.X 存在部分错误的 WARN 提示 org.springframework.context.support.PostProcessorRegistrationDelegate: ERROR # TODO 芋艿先禁用Spring Boot 3.X 存在部分错误的 WARN 提示
debug: false debug: false