## 全网产品管理;

This commit is contained in:
cabbage 2025-08-09 13:49:43 +08:00
parent bc4cf1653f
commit 42e3866fcc
17 changed files with 672 additions and 0 deletions

View File

@ -0,0 +1,145 @@
package com.hzs.sale.all.controller;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hzs.common.core.utils.StringUtils;
import com.hzs.common.core.utils.poi.ExcelUtil;
import com.hzs.common.core.web.controller.BaseController;
import com.hzs.common.core.web.domain.AjaxResult;
import com.hzs.common.core.web.page.TableDataInfo;
import com.hzs.common.domain.sale.all.AllProduct;
import com.hzs.common.security.utils.SecurityUtils;
import com.hzs.sale.all.param.AllProductQueryParam;
import com.hzs.sale.all.service.IAllProductService;
import com.hzs.sale.all.vo.AllProductQueryVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* 全网产品控制器
*/
@RestController
@RequestMapping("/manage/all-product")
@Slf4j
public class AllProductController extends BaseController {
@Autowired
private IAllProductService iAllProductService;
/**
* 产品列表
*/
@GetMapping("/list")
public TableDataInfo list(AllProductQueryParam param) {
List<AllProductQueryVO> resultList = new ArrayList<>();
startPage();
LambdaQueryWrapper<AllProduct> queryWrapper = new LambdaQueryWrapper<>();
if (StringUtils.isNotEmpty(param.getWmsCode())) {
queryWrapper.like(AllProduct::getWmsCode, param.getWmsCode());
}
if (StringUtils.isNotEmpty(param.getProductName())) {
queryWrapper.like(AllProduct::getProductName, param.getProductName());
}
queryWrapper.orderByAsc(AllProduct::getInventory);
List<AllProduct> productList = iAllProductService.list(queryWrapper);
if (CollectionUtil.isNotEmpty(productList)) {
resultList = BeanUtil.copyToList(productList, AllProductQueryVO.class);
}
return getDataTable(resultList);
}
/**
* 产品导出
*
* @param response
* @param param
*/
@PostMapping("/export")
public void export(HttpServletResponse response, AllProductQueryParam param) {
List<AllProductQueryVO> resultList = new ArrayList<>();
LambdaQueryWrapper<AllProduct> queryWrapper = new LambdaQueryWrapper<>();
if (StringUtils.isNotEmpty(param.getWmsCode())) {
queryWrapper.like(AllProduct::getWmsCode, param.getWmsCode());
}
if (StringUtils.isNotEmpty(param.getProductName())) {
queryWrapper.like(AllProduct::getProductName, param.getProductName());
}
queryWrapper.orderByAsc(AllProduct::getInventory);
List<AllProduct> productList = iAllProductService.list(queryWrapper);
if (CollectionUtil.isNotEmpty(productList)) {
resultList = BeanUtil.copyToList(productList, AllProductQueryVO.class);
}
ExcelUtil<AllProductQueryVO> util = new ExcelUtil<>(AllProductQueryVO.class);
util.exportExcel(response, resultList, "产品导出");
}
/**
* 保存产品信息
*
* @param param
* @return
*/
@PostMapping("/save")
public AjaxResult save(@RequestBody AllProduct param) {
if (iAllProductService.count(Wrappers.<AllProduct>lambdaQuery()
.eq(AllProduct::getWmsCode, param.getWmsCode())
) > 0) {
return AjaxResult.error("仓储编号已存在");
}
param.setPkCreator(SecurityUtils.getUserId());
return AjaxResult.success(iAllProductService.save(param));
}
/**
* 修改产品信息
*
* @param param
* @return
*/
@PostMapping("/update")
public AjaxResult update(@RequestBody AllProduct param) {
if (null == param.getPkId()) {
return AjaxResult.error("缺少参数");
}
if (iAllProductService.count(Wrappers.<AllProduct>lambdaQuery()
.eq(AllProduct::getWmsCode, param.getWmsCode())
.ne(AllProduct::getPkId, param.getPkId())
) > 0) {
return AjaxResult.error("仓储编号已存在");
}
param.setInventory(null);
param.setPkModified(SecurityUtils.getUserId());
param.setModifiedTime(new Date());
return AjaxResult.success(iAllProductService.updateById(param));
}
/**
* 修改库存数量
*
* @param param
* @return
*/
@PostMapping("/change-inventory")
public AjaxResult changeInventory(@RequestBody AllProduct param) {
if (null == param.getPkId() || null == param.getInventory()) {
return AjaxResult.error("缺少参数");
}
param.setPkModified(SecurityUtils.getUserId());
iAllProductService.changeInventory(param);
return AjaxResult.success();
}
}

View File

@ -0,0 +1,100 @@
package com.hzs.sale.all.controller;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hzs.common.core.enums.EProductSource;
import com.hzs.common.core.utils.StringUtils;
import com.hzs.common.core.utils.poi.ExcelUtil;
import com.hzs.common.core.web.controller.BaseController;
import com.hzs.common.core.web.page.TableDataInfo;
import com.hzs.common.domain.sale.all.AllProductDetail;
import com.hzs.sale.all.param.AllProductQueryParam;
import com.hzs.sale.all.service.IAllProductDetailService;
import com.hzs.sale.all.vo.AllProductDetailQueryVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
/**
* 全网产品明细控制器
*/
@RestController
@RequestMapping("/manage/all-product-detail")
@Slf4j
public class AllProductDetailController extends BaseController {
@Autowired
private IAllProductDetailService iAllProductDetailService;
/**
* 产品明细列表
*/
@GetMapping("/list")
public TableDataInfo productList(AllProductQueryParam param) {
List<AllProductDetailQueryVO> resultList = new ArrayList<>();
startPage();
LambdaQueryWrapper<AllProductDetail> queryWrapper = new LambdaQueryWrapper<>();
if (null != param.getPkAllProduct()) {
queryWrapper.eq(AllProductDetail::getPkAllProduct, param.getPkAllProduct());
}
if (StringUtils.isNotEmpty(param.getSource())) {
queryWrapper.eq(AllProductDetail::getSource, param.getSource());
}
if (StringUtils.isNotEmpty(param.getOrderCode())) {
queryWrapper.like(AllProductDetail::getOrderCode, param.getOrderCode());
}
queryWrapper.orderByDesc(AllProductDetail::getCreationTime);
List<AllProductDetail> productList = iAllProductDetailService.list(queryWrapper);
if (CollectionUtil.isNotEmpty(productList)) {
for (AllProductDetail allProductDetail : productList) {
AllProductDetailQueryVO vo = BeanUtil.copyProperties(allProductDetail, AllProductDetailQueryVO.class);
vo.setSourceVal(EProductSource.getLabelByValue(vo.getSource()));
resultList.add(vo);
}
}
return getDataTable(resultList);
}
/**
* 产品明细导出
*
* @param response
* @param param
*/
@PostMapping("/export")
public void productListExport(HttpServletResponse response, AllProductQueryParam param) {
List<AllProductDetailQueryVO> resultList = new ArrayList<>();
LambdaQueryWrapper<AllProductDetail> queryWrapper = new LambdaQueryWrapper<>();
if (null != param.getPkAllProduct()) {
queryWrapper.eq(AllProductDetail::getPkAllProduct, param.getPkAllProduct());
}
if (StringUtils.isNotEmpty(param.getSource())) {
queryWrapper.eq(AllProductDetail::getSource, param.getSource());
}
if (StringUtils.isNotEmpty(param.getOrderCode())) {
queryWrapper.like(AllProductDetail::getOrderCode, param.getOrderCode());
}
queryWrapper.orderByDesc(AllProductDetail::getCreationTime);
List<AllProductDetail> productList = iAllProductDetailService.list(queryWrapper);
if (CollectionUtil.isNotEmpty(productList)) {
for (AllProductDetail allProductDetail : productList) {
AllProductDetailQueryVO vo = BeanUtil.copyProperties(allProductDetail, AllProductDetailQueryVO.class);
vo.setSourceVal(EProductSource.getLabelByValue(vo.getSource()));
resultList.add(vo);
}
}
ExcelUtil<AllProductDetailQueryVO> util = new ExcelUtil<>(AllProductDetailQueryVO.class);
util.exportExcel(response, resultList, "产品明细导出");
}
}

View File

@ -0,0 +1,11 @@
package com.hzs.sale.all.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hzs.common.domain.sale.all.AllProductDetail;
/**
* 全系统产品明细 Mapper 接口
*/
public interface AllProductDetailMapper extends BaseMapper<AllProductDetail> {
}

View File

@ -0,0 +1,20 @@
package com.hzs.sale.all.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hzs.common.domain.sale.all.AllProduct;
import org.apache.ibatis.annotations.Param;
/**
* 全系统产品 Mapper 接口
*/
public interface AllProductMapper extends BaseMapper<AllProduct> {
/**
* 更新产品库存
*
* @param param
* @return
*/
int changeInventory(@Param("param") AllProduct param);
}

View File

@ -0,0 +1,4 @@
package com.hzs.sale.all.param;
public class AllProductParam {
}

View File

@ -0,0 +1,31 @@
package com.hzs.sale.all.param;
import lombok.Data;
@Data
public class AllProductQueryParam {
/**
* 仓储编号
*/
private String wmsCode;
/**
* 产品名称
*/
private String productName;
/**
* 产品ID
*/
private Integer pkAllProduct;
/**
* 变动来源
*/
private String source;
/**
* 来源订单号
*/
private String orderCode;
}

View File

@ -0,0 +1,11 @@
package com.hzs.sale.all.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.hzs.common.domain.sale.all.AllProductDetail;
/**
* 全系统产品明细 服务类
*/
public interface IAllProductDetailService extends IService<AllProductDetail> {
}

View File

@ -0,0 +1,18 @@
package com.hzs.sale.all.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.hzs.common.domain.sale.all.AllProduct;
/**
* 全系统产品 服务类
*/
public interface IAllProductService extends IService<AllProduct> {
/**
* 修改库存
*
* @param param
*/
void changeInventory(AllProduct param);
}

View File

@ -0,0 +1,15 @@
package com.hzs.sale.all.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzs.common.domain.sale.all.AllProductDetail;
import com.hzs.sale.all.mapper.AllProductDetailMapper;
import com.hzs.sale.all.service.IAllProductDetailService;
import org.springframework.stereotype.Service;
/**
* 全系统产品明细 服务实现类
*/
@Service
public class AllProductDetailServiceImpl extends ServiceImpl<AllProductDetailMapper, AllProductDetail> implements IAllProductDetailService {
}

View File

@ -0,0 +1,37 @@
package com.hzs.sale.all.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzs.common.core.enums.EProductSource;
import com.hzs.common.domain.sale.all.AllProduct;
import com.hzs.common.domain.sale.all.AllProductDetail;
import com.hzs.sale.all.mapper.AllProductMapper;
import com.hzs.sale.all.service.IAllProductDetailService;
import com.hzs.sale.all.service.IAllProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
* 全系统产品 服务实现类
*/
@Service
public class AllProductServiceImpl extends ServiceImpl<AllProductMapper, AllProduct> implements IAllProductService {
@Autowired
private IAllProductDetailService iAllProductDetailService;
@Transactional(rollbackFor = Exception.class)
@Override
public void changeInventory(AllProduct param) {
baseMapper.changeInventory(param);
AllProductDetail productDetail = AllProductDetail.builder()
.pkAllProduct(param.getPkId())
.source(EProductSource.MANAGE.getValue())
.changeNum(param.getInventory())
.remark(param.getRemark())
.build();
productDetail.setPkCreator(param.getPkModified());
iAllProductDetailService.save(productDetail);
}
}

View File

@ -0,0 +1,36 @@
package com.hzs.sale.all.vo;
import com.hzs.common.core.annotation.Excel;
import lombok.Data;
import java.io.Serializable;
@Data
public class AllProductDetailQueryVO implements Serializable {
/**
* 来源系统
*/
private String source;
@Excel(name = "来源系统")
private String sourceVal;
/**
* 来源订单号
*/
@Excel(name = "来源订单号")
private String orderCode;
/**
* 变动数量
*/
@Excel(name = "变动数量")
private Integer changeNum;
/**
* 变动说明
*/
@Excel(name = "变动说明")
private String remark;
}

View File

@ -0,0 +1,45 @@
package com.hzs.sale.all.vo;
import com.hzs.common.core.annotation.Excel;
import lombok.Data;
import java.io.Serializable;
@Data
public class AllProductQueryVO implements Serializable {
/**
* 主键ID
*/
private Integer pkId;
/**
* 封面图
*/
private String cover;
/**
* 仓储编号
*/
@Excel(name = "仓储编号")
private String wmsCode;
/**
* 产品名称
*/
@Excel(name = "产品名称")
private String productName;
/**
* 库存数量
*/
@Excel(name = "库存数量")
private Integer inventory;
/**
* 备注
*/
@Excel(name = "备注")
private String remark;
}

View File

@ -0,0 +1,6 @@
<?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="com.hzs.sale.all.mapper.AllProductDetailMapper">
</mapper>

View File

@ -0,0 +1,14 @@
<?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="com.hzs.sale.all.mapper.AllProductMapper">
<!-- 更新产品库存 -->
<update id="changeInventory">
update ALL_PRODUCT ap
set ap.inventory = ap.inventory + #{param.inventory},
ap.pk_modified = #{param.pkModified},
ap.modified_time = sysdate
where ap.pk_id = #{param.pkId}
</update>
</mapper>

View File

@ -0,0 +1,55 @@
package com.hzs.common.core.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* 产品数据来源
*/
@AllArgsConstructor
@Getter
public enum EProductSource {
/**
* 管理后台
*/
MANAGE("MANAGE", "管理后台"),
/**
* 乐学
*/
CN("CN", "CN"),
/**
* 北大
*/
BD("BD", "BD"),
/**
* 新零售
*/
BF("BF", "BF"),
/**
* 新零售店铺
*/
BL("BL", "BL"),
;
/**
* 实际值
*/
private final String value;
/**
* 显示标签
*/
private final String label;
public static String getLabelByValue(String value) {
for (EProductSource enums : EProductSource.values()) {
if (enums.getValue().equals(value)) {
return enums.getLabel();
}
}
return "";
}
}

View File

@ -0,0 +1,61 @@
package com.hzs.common.domain.sale.all;
import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableField;
import com.hzs.common.core.web.domain.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
/**
* 全系统产品
*/
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
@KeySequence("ALL_PRODUCT_SEQ")
@TableName("ALL_PRODUCT")
public class AllProduct extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* 主键ID
*/
@TableId("PK_ID")
private Integer pkId;
/**
* 仓储产品编号
*/
@TableField("WMS_CODE")
private String wmsCode;
/**
* 产品名称
*/
@TableField("PRODUCT_NAME")
private String productName;
/**
* 封面图
*/
@TableField("COVER")
private String cover;
/**
* 备注
*/
@TableField("REMARK")
private String remark;
/**
* 库存数量
*/
@TableField("INVENTORY")
private Integer inventory;
}

View File

@ -0,0 +1,63 @@
package com.hzs.common.domain.sale.all;
import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableField;
import com.hzs.common.core.web.domain.BaseEntity;
import lombok.*;
import lombok.experimental.Accessors;
/**
* 全系统产品明细
*/
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
@KeySequence("ALL_PRODUCT_DETAIL_SEQ")
@TableName("ALL_PRODUCT_DETAIL")
public class AllProductDetail extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* 主键ID
*/
@TableId("PK_ID")
private Long pkId;
/**
* 全网商品主键
*/
@TableField("PK_ALL_PRODUCT")
private Integer pkAllProduct;
/**
* 来源系统
*/
@TableField("SOURCE")
private String source;
/**
* 来源订单号
*/
@TableField("ORDER_CODE")
private String orderCode;
/**
* 变动数量
*/
@TableField("CHANGE_NUM")
private Integer changeNum;
/**
* 变动说明
*/
@TableField("REMARK")
private String remark;
}