|
|
|
@ -0,0 +1,523 @@
|
|
|
|
|
package com.rabbiter.market.service.goods_management.goods.impl;
|
|
|
|
|
|
|
|
|
|
// 导入必要的类和包
|
|
|
|
|
import com.rabbiter.market.common.exception.BusinessException; // 业务异常类
|
|
|
|
|
import com.rabbiter.market.common.redis.constants.RedisKeys; // Redis键常量
|
|
|
|
|
import com.rabbiter.market.common.redis.service.RedisTemplateService; // Redis服务
|
|
|
|
|
import com.rabbiter.market.domain.goods_management.goods.Goods; // 商品实体
|
|
|
|
|
import com.rabbiter.market.domain.goods_management.goods_category.GoodsCategory; // 商品分类实体
|
|
|
|
|
import com.rabbiter.market.domain.inventory_management.detail_store_goods.DetailStoreGoods; // 库存明细实体
|
|
|
|
|
import com.rabbiter.market.domain.inventory_management.notice.NoticeIn; // 入库通知单
|
|
|
|
|
import com.rabbiter.market.domain.inventory_management.notice.NoticeOut; // 出库通知单
|
|
|
|
|
import com.rabbiter.market.domain.inventory_management.store.GoodsStore; // 商品库存
|
|
|
|
|
import com.rabbiter.market.domain.inventory_management.store.Store; // 仓库
|
|
|
|
|
import com.rabbiter.market.domain.personnel_management.employee.Employee; // 员工
|
|
|
|
|
import com.rabbiter.market.mapper.goods_management.goods.GoodsMapper; // 商品Mapper
|
|
|
|
|
import com.rabbiter.market.qo.goods_management.goods.QueryGoods; // 商品查询对象
|
|
|
|
|
import com.rabbiter.market.qo.goods_management.goods_store.QueryGoodsStore; // 商品库存查询
|
|
|
|
|
import com.rabbiter.market.qo.goods_management.statistic_sale.QueryStatisticSale; // 销售统计查询
|
|
|
|
|
import com.rabbiter.market.qo.inventory_management.notice.QueryNoticeIn; // 入库通知查询
|
|
|
|
|
import com.rabbiter.market.qo.inventory_management.notice.QueryNoticeOut; // 出库通知查询
|
|
|
|
|
import com.rabbiter.market.service.goods_management.goods.IGoodsService; // 商品服务接口
|
|
|
|
|
import com.rabbiter.market.service.goods_management.goods_category.IGoodsCategoryService; // 分类服务
|
|
|
|
|
import com.rabbiter.market.service.inventory_management.detail_store_goods.IDetailStoreGoodsService; // 库存明细服务
|
|
|
|
|
import com.rabbiter.market.service.inventory_management.store.IGoodsStoreService; // 商品库存服务
|
|
|
|
|
import com.rabbiter.market.service.inventory_management.store.IStoreService; // 仓库服务
|
|
|
|
|
import com.rabbiter.market.vo.detail_store_goods.notice.NoticeInNotNormalVo; // 异常入库VO
|
|
|
|
|
import com.rabbiter.market.vo.goods.GoodsListVo; // 商品列表VO
|
|
|
|
|
import com.rabbiter.market.vo.goods_management.goods_store.GoodsStoreVo; // 商品库存VO
|
|
|
|
|
import com.rabbiter.market.vo.statistics.sale_management.SaleGoodsVo; // 销售商品VO
|
|
|
|
|
import com.rabbiter.market.vo.statistics.sale_management.SalesStatisticsVo; // 销售统计VO
|
|
|
|
|
import com.alibaba.fastjson.JSONObject; // JSON处理
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; // 查询条件构造器
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; // 更新条件构造器
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker; // ID生成器
|
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; // 分页
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; // MyBatis-Plus服务实现
|
|
|
|
|
import org.springframework.beans.BeanUtils; // 属性拷贝
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; // 自动注入
|
|
|
|
|
import org.springframework.stereotype.Service; // 服务注解
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional; // 事务注解
|
|
|
|
|
import org.springframework.util.StringUtils; // 字符串工具
|
|
|
|
|
|
|
|
|
|
import java.util.*; // 集合工具
|
|
|
|
|
|
|
|
|
|
@Service // 标识这是一个Spring服务组件
|
|
|
|
|
public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements IGoodsService {
|
|
|
|
|
@Autowired // 自动注入Redis服务
|
|
|
|
|
private RedisTemplateService redisTemplateService;
|
|
|
|
|
@Autowired // 自动注入商品分类服务
|
|
|
|
|
private IGoodsCategoryService goodsCategoryService;
|
|
|
|
|
|
|
|
|
|
@Autowired // 自动注入仓库服务
|
|
|
|
|
private IStoreService storeService;
|
|
|
|
|
@Autowired // 自动注入库存明细服务
|
|
|
|
|
private IDetailStoreGoodsService detailStoreGoodsService;
|
|
|
|
|
@Autowired // 自动注入商品库存服务
|
|
|
|
|
private IGoodsStoreService goodsStoreService;
|
|
|
|
|
@Autowired // 自动注入商品Mapper
|
|
|
|
|
private GoodsMapper goodsMapper;
|
|
|
|
|
|
|
|
|
|
@Override // 实现分页查询商品方法
|
|
|
|
|
public Page<GoodsListVo> queryPageByQo(QueryGoods qo) {
|
|
|
|
|
// 创建分页对象,设置当前页和每页大小
|
|
|
|
|
Page<GoodsListVo> page = new Page<>(qo.getCurrentPage(), qo.getPageSize());
|
|
|
|
|
// 创建商品VO列表
|
|
|
|
|
ArrayList<GoodsListVo> volists = new ArrayList<>();
|
|
|
|
|
// 创建商品分页对象
|
|
|
|
|
Page<Goods> goodsPage = new Page<>(qo.getCurrentPage(), qo.getPageSize());
|
|
|
|
|
// 构建查询条件
|
|
|
|
|
QueryWrapper<Goods> wrapper = new QueryWrapper<Goods>()
|
|
|
|
|
.eq(qo.getId() != null, "id", qo.getId()) // ID相等条件
|
|
|
|
|
.eq(qo.getSellPrice() != null, "sell_price", qo.getSellPrice()) // 价格相等条件
|
|
|
|
|
.like(StringUtils.hasText(qo.getName()), "name", qo.getName()) // 名称模糊查询
|
|
|
|
|
.eq(qo.getCategoryId() != null, "category_id", qo.getCategoryId()) // 分类ID相等
|
|
|
|
|
.eq(StringUtils.hasText(qo.getState()), "state", qo.getState()) // 状态相等
|
|
|
|
|
.ge(StringUtils.hasText(qo.getOperateStartTime()), "update_time", qo.getOperateStartTime()) // 更新时间大于等于
|
|
|
|
|
.le(StringUtils.hasText(qo.getOperateEndTime()), "update_time", qo.getOperateEndTime()); // 更新时间小于等于
|
|
|
|
|
// 执行分页查询
|
|
|
|
|
super.page(goodsPage, wrapper);
|
|
|
|
|
// 遍历查询结果
|
|
|
|
|
for (Goods record : goodsPage.getRecords()) {
|
|
|
|
|
GoodsListVo vo = new GoodsListVo(); // 创建商品VO对象
|
|
|
|
|
BeanUtils.copyProperties(record, vo); // 复制属性
|
|
|
|
|
// 查询商品剩余库存数量
|
|
|
|
|
Long residueNum=storeService.getResidueNumByGoodsId(record.getId());
|
|
|
|
|
vo.setResidueStoreNum(residueNum); // 设置剩余库存
|
|
|
|
|
volists.add(vo); // 添加到列表
|
|
|
|
|
}
|
|
|
|
|
// 设置分页结果
|
|
|
|
|
page.setRecords(volists);
|
|
|
|
|
page.setTotal(goodsPage.getTotal()); // 设置总记录数
|
|
|
|
|
return page;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override // 保存商品方法
|
|
|
|
|
public void saveGoods(Goods goods, String token) {
|
|
|
|
|
// 从Redis中获取员工信息
|
|
|
|
|
Employee employee = JSONObject.parseObject(redisTemplateService.getCacheObject(token), Employee.class);
|
|
|
|
|
goods.setState(Goods.STATE_UP); // 设置商品状态为上架
|
|
|
|
|
goods.setCreateby(employee.getNickName()); // 设置创建人
|
|
|
|
|
goods.setUpdateby(employee.getNickName()); // 设置更新人
|
|
|
|
|
goods.setCreateTime(new Date()); // 设置创建时间
|
|
|
|
|
goods.setUpdateTime(new Date()); // 设置更新时间
|
|
|
|
|
if (goods.getCategoryId() != null) { // 如果有分类ID
|
|
|
|
|
/*从缓存中获取分类的信息*/
|
|
|
|
|
if (redisTemplateService.hasKey(RedisKeys.GOODS_CATEGORY.join())) { // 检查Redis中是否有分类缓存
|
|
|
|
|
Map<String, Object> categoryCache = redisTemplateService.getCacheMap(RedisKeys.GOODS_CATEGORY.join());
|
|
|
|
|
GoodsCategory category = (GoodsCategory) categoryCache.get(goods.getCategoryId().toString());
|
|
|
|
|
if (category != null) {
|
|
|
|
|
goods.setCategoryName(category.getName()); // 设置分类名称
|
|
|
|
|
}
|
|
|
|
|
} else { // 如果Redis中没有缓存
|
|
|
|
|
GoodsCategory category = goodsCategoryService.getById(goods.getCategoryId()); // 从数据库查询
|
|
|
|
|
if (category != null) {
|
|
|
|
|
goods.setCategoryName(category.getName()); // 设置分类名称
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
super.save(goods); // 保存商品
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Transactional // 事务注解
|
|
|
|
|
@Override // 商品上架/下架方法
|
|
|
|
|
public void upOrdown(Long gid, String state,String token) {
|
|
|
|
|
UpdateWrapper<Goods> wrapper = new UpdateWrapper<>(); // 创建更新条件
|
|
|
|
|
wrapper.eq("id", gid); // 设置更新条件为ID相等
|
|
|
|
|
if (Goods.STATE_UP.equals(state)) { // 如果是上架操作
|
|
|
|
|
Employee employee = JSONObject.parseObject(redisTemplateService.getCacheObject(token), Employee.class);
|
|
|
|
|
wrapper.set("state", Goods.STATE_DOWN); // 设置状态为下架
|
|
|
|
|
Goods goods = super.getById(gid); // 获取商品信息
|
|
|
|
|
// 查询商品在各仓库的库存
|
|
|
|
|
QueryWrapper<GoodsStore> goodsStoreQueryWrapper = new QueryWrapper<GoodsStore>().eq("goods_id", gid);
|
|
|
|
|
List<GoodsStore> list = goodsStoreService.list(goodsStoreQueryWrapper);
|
|
|
|
|
// 为每个仓库创建下架记录
|
|
|
|
|
for (GoodsStore goodsStore : list) {
|
|
|
|
|
DetailStoreGoods detailStoreGoods = new DetailStoreGoods();
|
|
|
|
|
detailStoreGoods.setCreateid(employee.getId()); // 设置创建人ID
|
|
|
|
|
detailStoreGoods.setCreateby(employee.getNickName()); // 设置创建人名称
|
|
|
|
|
detailStoreGoods.setCreateTime(new Date()); // 设置创建时间
|
|
|
|
|
detailStoreGoods.setGoodsId(gid); // 设置商品ID
|
|
|
|
|
detailStoreGoods.setGoodsName(goods.getName()); // 设置商品名称
|
|
|
|
|
detailStoreGoods.setType(DetailStoreGoods.TYPE_IN); // 设置类型为入库
|
|
|
|
|
detailStoreGoods.setState1(DetailStoreGoods.STATE1_UNTREATED); // 设置状态为未处理
|
|
|
|
|
detailStoreGoods.setState(DetailStoreGoods.STATE_DOWN); // 设置状态为下架
|
|
|
|
|
detailStoreGoods.setCn(IdWorker.getIdStr()); // 生成唯一编号
|
|
|
|
|
detailStoreGoods.setInfo(goods.getName()+"下架处理"); // 设置描述信息
|
|
|
|
|
detailStoreGoods.setGoodsNum(goodsStore.getResidueNum()); // 设置商品数量
|
|
|
|
|
detailStoreGoods.setUntreatedNum(goodsStore.getResidueNum()); // 设置未处理数量
|
|
|
|
|
detailStoreGoods.setStoreId(goodsStore.getStoreId()); // 设置仓库ID
|
|
|
|
|
detailStoreGoodsService.save(detailStoreGoods); // 保存下架记录
|
|
|
|
|
}
|
|
|
|
|
} else { // 如果是上架操作
|
|
|
|
|
wrapper.set("residue_num",0); // 设置剩余数量为0
|
|
|
|
|
wrapper.set("state", Goods.STATE_UP); // 设置状态为上架
|
|
|
|
|
// 删除未处理的下架记录
|
|
|
|
|
QueryWrapper<DetailStoreGoods> queryWrapper = new QueryWrapper<DetailStoreGoods>().eq("goods_id", gid)
|
|
|
|
|
.eq("state", DetailStoreGoods.STATE_DOWN)
|
|
|
|
|
.eq("state1", DetailStoreGoods.STATE1_UNTREATED);
|
|
|
|
|
detailStoreGoodsService.remove(queryWrapper);
|
|
|
|
|
}
|
|
|
|
|
super.update(wrapper); // 执行更新
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override // 更新商品方法
|
|
|
|
|
public void updateGoods(Goods goods, String token) {
|
|
|
|
|
Employee employee = JSONObject.parseObject(redisTemplateService.getCacheObject(token), Employee.class);
|
|
|
|
|
goods.setUpdateby(employee.getNickName()); // 设置更新人
|
|
|
|
|
goods.setUpdateTime(new Date()); // 设置更新时间
|
|
|
|
|
if (goods.getCategoryId() != null) { // 如果有分类ID
|
|
|
|
|
/*从缓存中获取分类的信息*/
|
|
|
|
|
if (redisTemplateService.hasKey(RedisKeys.GOODS_CATEGORY.join())) { // 检查Redis缓存
|
|
|
|
|
Map<String, Object> categoryCache = redisTemplateService.getCacheMap(RedisKeys.GOODS_CATEGORY.join());
|
|
|
|
|
GoodsCategory category = (GoodsCategory) categoryCache.get(goods.getCategoryId().toString());
|
|
|
|
|
if (category != null) {
|
|
|
|
|
goods.setCategoryName(category.getName()); // 设置分类名称
|
|
|
|
|
}
|
|
|
|
|
} else { // 如果缓存中没有
|
|
|
|
|
GoodsCategory category = goodsCategoryService.getById(goods.getCategoryId()); // 从数据库查询
|
|
|
|
|
if (category != null) {
|
|
|
|
|
goods.setCategoryName(category.getName()); // 设置分类名称
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
super.updateById(goods); // 更新商品
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override // 查询所有上架商品方法
|
|
|
|
|
public List<Map<String, Object>> selected_goodsAll() {
|
|
|
|
|
QueryWrapper<Goods> wrapper = new QueryWrapper<Goods>().eq("state", Goods.STATE_UP); // 查询上架商品
|
|
|
|
|
List<Goods> list = super.list(wrapper);
|
|
|
|
|
if (list==null||list.size()==0){ // 如果结果为空
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
List<Map<String, Object>> listVo = new ArrayList<>(); // 创建结果列表
|
|
|
|
|
for (Goods goods : list) {
|
|
|
|
|
Map<String, Object> map = new HashMap<>(); // 创建结果Map
|
|
|
|
|
map.put("id",goods.getId()); // 设置商品ID
|
|
|
|
|
map.put("name",goods.getName()); // 设置商品名称
|
|
|
|
|
listVo.add(map); // 添加到结果列表
|
|
|
|
|
}
|
|
|
|
|
return listVo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override // 查询所有正常状态的仓库
|
|
|
|
|
public List<Map<String, Object>> selected_storeAll() {
|
|
|
|
|
List<Map<String, Object>> list = new ArrayList<>(); // 创建结果列表
|
|
|
|
|
QueryWrapper<Store> wrapper = new QueryWrapper<Store>().eq("state", Store.STATE_NORMAL); // 查询正常状态的仓库
|
|
|
|
|
List<Store> list1 = storeService.list(wrapper);
|
|
|
|
|
if (list1!=null &&list1.size()>0){ // 如果有结果
|
|
|
|
|
for (Store store : list1) {
|
|
|
|
|
Map<String, Object> map = new HashMap<>(); // 创建结果Map
|
|
|
|
|
map.put("id",store.getId()); // 设置仓库ID
|
|
|
|
|
map.put("name",store.getName()); // 设置仓库名称
|
|
|
|
|
list.add(map); // 添加到结果列表
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override // 商品退货方法
|
|
|
|
|
public void returnGoods(DetailStoreGoods detailStoreGoods, String token) {
|
|
|
|
|
Employee employee = JSONObject.parseObject(redisTemplateService.getCacheObject(token), Employee.class);
|
|
|
|
|
Goods goods = super.getById(detailStoreGoods.getGoodsId()); // 获取商品信息
|
|
|
|
|
|
|
|
|
|
/*补全入库订单信息*/
|
|
|
|
|
detailStoreGoods.setCn(IdWorker.getIdStr()); // 生成唯一编号
|
|
|
|
|
detailStoreGoods.setCreateby(employee.getNickName()); // 设置创建人
|
|
|
|
|
detailStoreGoods.setCreateid(employee.getId()); // 设置创建人ID
|
|
|
|
|
detailStoreGoods.setType(DetailStoreGoods.TYPE_IN); // 设置类型为入库
|
|
|
|
|
if (DetailStoreGoods.STATE_EXPIRY.equals(detailStoreGoods.getState())){ // 如果是过期商品
|
|
|
|
|
//如果是过期,将入库订单的state1修改成2:待处理的状态
|
|
|
|
|
detailStoreGoods.setState1(DetailStoreGoods.STATE1_UNTREATED); // 设置状态为未处理
|
|
|
|
|
}else {
|
|
|
|
|
detailStoreGoods.setState1(DetailStoreGoods.STATE1_NORMAL); // 设置状态为正常
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*获取仓库的信息*/
|
|
|
|
|
QueryWrapper<GoodsStore> goodsStoreQueryWrapper = new QueryWrapper<GoodsStore>()
|
|
|
|
|
.eq("goods_id", detailStoreGoods.getGoodsId()) // 商品ID条件
|
|
|
|
|
.eq("store_id", detailStoreGoods.getStoreId()); // 仓库ID条件
|
|
|
|
|
GoodsStore goodsStore = goodsStoreService.getOne(goodsStoreQueryWrapper);
|
|
|
|
|
if (goodsStore==null){ // 如果商品在该仓库没有库存记录
|
|
|
|
|
goodsStore = new GoodsStore(); // 创建新的库存记录
|
|
|
|
|
goodsStore.setGoodsId(detailStoreGoods.getGoodsId()); // 设置商品ID
|
|
|
|
|
goodsStore.setStoreId(detailStoreGoods.getStoreId()); // 设置仓库ID
|
|
|
|
|
Store store = storeService.getById(detailStoreGoods.getStoreId()); // 获取仓库信息
|
|
|
|
|
goodsStore.setStoreName(store.getName()); // 设置仓库名称
|
|
|
|
|
goodsStore.setInNum(0L); // 设置入库数量为0
|
|
|
|
|
goodsStore.setResidueNum(0L); // 设置剩余数量为0
|
|
|
|
|
goodsStoreService.save(goodsStore); // 保存库存记录
|
|
|
|
|
}
|
|
|
|
|
long num = goods.getResidueNum() - detailStoreGoods.getGoodsNum(); // 计算货架剩余数量
|
|
|
|
|
if (num>=0){ // 如果货架还有足够商品
|
|
|
|
|
//货架还有商品数量
|
|
|
|
|
/*更改商品信息*/
|
|
|
|
|
UpdateWrapper<Goods> goodsUpdateWrapper = new UpdateWrapper<Goods>()
|
|
|
|
|
.set("residue_num", num) // 更新剩余数量
|
|
|
|
|
.eq("id", detailStoreGoods.getGoodsId());
|
|
|
|
|
super.update(goodsUpdateWrapper);
|
|
|
|
|
/*更改商品库存信息*/
|
|
|
|
|
UpdateWrapper<GoodsStore> goodsStoreUpdateWrapper = new UpdateWrapper<GoodsStore>()
|
|
|
|
|
.set("residue_num", goodsStore.getResidueNum() + detailStoreGoods.getGoodsNum()) // 增加库存数量
|
|
|
|
|
.eq("goods_id", detailStoreGoods.getGoodsId())
|
|
|
|
|
.eq("store_id", detailStoreGoods.getStoreId());
|
|
|
|
|
goodsStoreService.update(goodsStoreUpdateWrapper);
|
|
|
|
|
detailStoreGoods.setUntreatedNum(detailStoreGoods.getGoodsNum()); // 设置未处理数量
|
|
|
|
|
|
|
|
|
|
}else { // 如果货架商品不足
|
|
|
|
|
//货架没有商品数量
|
|
|
|
|
/*更改商品信息*/
|
|
|
|
|
UpdateWrapper<Goods> goodsUpdateWrapper = new UpdateWrapper<Goods>()
|
|
|
|
|
.set("residue_num", 0) // 设置剩余数量为0
|
|
|
|
|
.eq("id", detailStoreGoods.getGoodsId());
|
|
|
|
|
super.update(goodsUpdateWrapper);
|
|
|
|
|
/*更改商品库存信息*/
|
|
|
|
|
UpdateWrapper<GoodsStore> goodsStoreUpdateWrapper = new UpdateWrapper<GoodsStore>()
|
|
|
|
|
.set("residue_num", goodsStore.getResidueNum() + goods.getResidueNum()) // 增加库存数量
|
|
|
|
|
.eq("goods_id", detailStoreGoods.getGoodsId())
|
|
|
|
|
.eq("store_id", detailStoreGoods.getStoreId());
|
|
|
|
|
goodsStoreService.update(goodsStoreUpdateWrapper);
|
|
|
|
|
detailStoreGoods.setGoodsNum(goods.getResidueNum()); // 设置商品数量为货架剩余数量
|
|
|
|
|
detailStoreGoods.setUntreatedNum(goods.getResidueNum()); // 设置未处理数量
|
|
|
|
|
}
|
|
|
|
|
detailStoreGoodsService.save(detailStoreGoods); // 保存退货记录
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override // 分页查询商品库存
|
|
|
|
|
public Page<GoodsStoreVo> queryPageGoodsStore(QueryGoodsStore qo) {
|
|
|
|
|
Page<GoodsStoreVo> page = new Page<>(qo.getCurrentPage(),qo.getPageSize()); // 创建分页对象
|
|
|
|
|
Page<Goods> goodsPage = new Page<>(qo.getCurrentPage(), qo.getPageSize()); // 创建商品分页对象
|
|
|
|
|
QueryWrapper<Goods> wrapper = new QueryWrapper<Goods>().eq("state", Goods.STATE_UP) // 查询上架商品
|
|
|
|
|
.like(StringUtils.hasText(qo.getName()), "name", qo.getName()); // 名称模糊查询
|
|
|
|
|
super.page(goodsPage,wrapper); // 执行分页查询
|
|
|
|
|
if (goodsPage.getTotal()<=0) { // 如果没有结果
|
|
|
|
|
page.setRecords(new ArrayList<>()); // 设置空列表
|
|
|
|
|
page.setTotal(0); // 设置总数为0
|
|
|
|
|
return page;
|
|
|
|
|
}
|
|
|
|
|
List<GoodsStoreVo> list = new ArrayList<>(); // 创建结果列表
|
|
|
|
|
for (Goods record : goodsPage.getRecords()) {
|
|
|
|
|
GoodsStoreVo vo = new GoodsStoreVo(); // 创建VO对象
|
|
|
|
|
BeanUtils.copyProperties(record,vo); // 复制属性
|
|
|
|
|
list.add(vo); // 添加到结果列表
|
|
|
|
|
}
|
|
|
|
|
page.setTotal(goodsPage.getTotal()); // 设置总数
|
|
|
|
|
page.setRecords(list); // 设置记录
|
|
|
|
|
return page;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override // 根据ID查询商品库存
|
|
|
|
|
public GoodsStoreVo queryGoodsStoreById(Long id) {
|
|
|
|
|
GoodsStoreVo vo = new GoodsStoreVo(); // 创建VO对象
|
|
|
|
|
Goods goods = super.getById(id); // 根据ID查询商品
|
|
|
|
|
BeanUtils.copyProperties(goods,vo); // 复制属性
|
|
|
|
|
return vo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override // 更新库存信息
|
|
|
|
|
public void updateInventory(GoodsStoreVo vo) {
|
|
|
|
|
if (vo.getInventory()==null){ // 如果库存为空
|
|
|
|
|
vo.setInventory(0L); // 设置为0
|
|
|
|
|
}
|
|
|
|
|
if(vo.getShelves()==null){ // 如果货架数量为空
|
|
|
|
|
vo.setShelves(0L); // 设置为0
|
|
|
|
|
}
|
|
|
|
|
UpdateWrapper<Goods> updateWrapper = new UpdateWrapper<Goods>()
|
|
|
|
|
.set("inventory",vo.getInventory()) // 设置库存
|
|
|
|
|
.set("shelves",vo.getShelves()) // 设置货架数量
|
|
|
|
|
.eq("id",vo.getId()); // ID条件
|
|
|
|
|
super.update(updateWrapper); // 执行更新
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override // 分页查询入库通知单
|
|
|
|
|
public Page<NoticeIn> queryPageNoticeIn(QueryNoticeIn qo) {
|
|
|
|
|
Page<NoticeIn> noticeInPage = new Page<>(qo.getCurrentPage(), qo.getPageSize()); // 创建分页对象
|
|
|
|
|
List<NoticeIn> list = new ArrayList<>(); // 创建结果列表
|
|
|
|
|
int start=(qo.getCurrentPage()-1)*qo.getPageSize(); // 计算起始位置
|
|
|
|
|
Map<String, Object> map = new HashMap<>(); // 创建查询参数Map
|
|
|
|
|
map.put("start",start); // 设置起始位置
|
|
|
|
|
map.put("size",qo.getPageSize()); // 设置每页大小
|
|
|
|
|
if (StringUtils.hasLength(qo.getName())){ // 如果有名称条件
|
|
|
|
|
map.put("name",qo.getName()); // 设置名称参数
|
|
|
|
|
}
|
|
|
|
|
int totalCount=goodsMapper.getNoticeInTotalCount(map); // 获取总数
|
|
|
|
|
list=goodsMapper.getNoticePageList(map); // 获取分页列表
|
|
|
|
|
noticeInPage.setTotal(totalCount); // 设置总数
|
|
|
|
|
noticeInPage.setRecords(list); // 设置记录
|
|
|
|
|
return noticeInPage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override // 分页查询货架出库通知单
|
|
|
|
|
public Page<NoticeOut> queryPageNoticeOut_shelves(QueryNoticeOut qo) {
|
|
|
|
|
Page<NoticeOut> noticeOutPage = new Page<>(qo.getCurrentPage(), qo.getPageSize()); // 创建分页对象
|
|
|
|
|
List<NoticeOut> list = new ArrayList<>(); // 创建结果列表
|
|
|
|
|
int start=(qo.getCurrentPage()-1)*qo.getPageSize(); // 计算起始位置
|
|
|
|
|
Map<String, Object> map = new HashMap<>(); // 创建查询参数Map
|
|
|
|
|
map.put("start",start); // 设置起始位置
|
|
|
|
|
map.put("size",qo.getPageSize()); // 设置每页大小
|
|
|
|
|
if (StringUtils.hasLength(qo.getName())){ // 如果有名称条件
|
|
|
|
|
map.put("name",qo.getName()); // 设置名称参数
|
|
|
|
|
}
|
|
|
|
|
int totalCount=goodsMapper.getNoticeOutShelvesTotalCount(map); // 获取总数
|
|
|
|
|
list=goodsMapper.getNoticeShelvesPageList(map); // 获取分页列表
|
|
|
|
|
noticeOutPage.setTotal(totalCount); // 设置总数
|
|
|
|
|
noticeOutPage.setRecords(list); // 设置记录
|
|
|
|
|
return noticeOutPage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override // 保存货架出库记录
|
|
|
|
|
public void saveOut_shelves(DetailStoreGoods detailStoreGoods,String token) {
|
|
|
|
|
Employee employee = JSONObject.parseObject(redisTemplateService.getCacheObject(token), Employee.class);
|
|
|
|
|
// 查询商品在指定仓库的库存
|
|
|
|
|
QueryWrapper<GoodsStore> detailStoreGoodsQueryWrapper = new QueryWrapper<GoodsStore>().eq("goods_id", detailStoreGoods.getGoodsId())
|
|
|
|
|
.eq("store_id", detailStoreGoods.getStoreId());
|
|
|
|
|
GoodsStore goodsStore = goodsStoreService.getOne(detailStoreGoodsQueryWrapper);
|
|
|
|
|
if (goodsStore==null || goodsStore.getResidueNum()==null ||goodsStore.getResidueNum()==0){ // 如果没有库存
|
|
|
|
|
throw new BusinessException("出库失败,库存中没有该商品的库存"); // 抛出业务异常
|
|
|
|
|
}
|
|
|
|
|
/*补全出库单的信息*/
|
|
|
|
|
detailStoreGoods.setCn(IdWorker.getIdStr()); // 生成唯一编号
|
|
|
|
|
detailStoreGoods.setCreateby(employee.getNickName()); // 设置创建人
|
|
|
|
|
detailStoreGoods.setCreateid(employee.getId()); // 设置创建人ID
|
|
|
|
|
detailStoreGoods.setType(DetailStoreGoods.TYPE_OUT); // 设置类型为出库
|
|
|
|
|
detailStoreGoods.setState1(DetailStoreGoods.STATE1_NORMAL); // 设置状态为正常
|
|
|
|
|
long num = goodsStore.getResidueNum() - detailStoreGoods.getGoodsNum(); // 计算库存剩余数量
|
|
|
|
|
Goods goods = super.getById(detailStoreGoods.getGoodsId()); // 获取商品信息
|
|
|
|
|
if (num>=0){ // 如果库存足够
|
|
|
|
|
/*修改货架商品数量*/
|
|
|
|
|
UpdateWrapper<Goods> goodsUpdateWrapper = new UpdateWrapper<Goods>()
|
|
|
|
|
.set("residue_num", goods.getResidueNum() == null ? detailStoreGoods.getGoodsNum() : goods.getResidueNum() + detailStoreGoods.getGoodsNum()) // 增加货架数量
|
|
|
|
|
.eq("id",detailStoreGoods.getGoodsId());
|
|
|
|
|
super.update(goodsUpdateWrapper);
|
|
|
|
|
/*修改商品库存数量*/
|
|
|
|
|
UpdateWrapper<GoodsStore> goodsStoreUpdateWrapper = new UpdateWrapper<GoodsStore>()
|
|
|
|
|
.set("residue_num", goodsStore.getResidueNum() - detailStoreGoods.getGoodsNum()) // 减少库存数量
|
|
|
|
|
.eq("goods_id", detailStoreGoods.getGoodsId())
|
|
|
|
|
.eq("store_id", detailStoreGoods.getStoreId());
|
|
|
|
|
goodsStoreService.update(goodsStoreUpdateWrapper);
|
|
|
|
|
/*添加出库记录*/
|
|
|
|
|
detailStoreGoodsService.save(detailStoreGoods); // 保存出库记录
|
|
|
|
|
}else { // 如果库存不足
|
|
|
|
|
/*修改货架商品数量*/
|
|
|
|
|
UpdateWrapper<Goods> goodsUpdateWrapper = new UpdateWrapper<Goods>()
|
|
|
|
|
.set("residue_num", goods.getResidueNum() == null ? goodsStore.getResidueNum() : goods.getResidueNum() + goodsStore.getResidueNum()) // 增加货架数量
|
|
|
|
|
.eq("id",detailStoreGoods.getGoodsId());
|
|
|
|
|
super.update(goodsUpdateWrapper);
|
|
|
|
|
/*修改商品库存数量*/
|
|
|
|
|
UpdateWrapper<GoodsStore> goodsStoreUpdateWrapper = new UpdateWrapper<GoodsStore>()
|
|
|
|
|
.set("residue_num",0L) // 设置库存为0
|
|
|
|
|
.eq("goods_id", detailStoreGoods.getGoodsId())
|
|
|
|
|
.eq("store_id", detailStoreGoods.getStoreId());
|
|
|
|
|
goodsStoreService.update(goodsStoreUpdateWrapper);
|
|
|
|
|
/*添加出库记录*/
|
|
|
|
|
detailStoreGoods.setGoodsNum(goodsStore.getResidueNum()); // 设置出库数量为库存剩余数量
|
|
|
|
|
detailStoreGoodsService.save(detailStoreGoods); // 保存出库记录
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override // 分页查询销售统计
|
|
|
|
|
public SalesStatisticsVo queryPageStatisticSaleByQo(QueryStatisticSale qo) {
|
|
|
|
|
Long total=goodsMapper.queryPageStatisticSaleByQo(qo.getName()); // 获取销售总量
|
|
|
|
|
SalesStatisticsVo vo = new SalesStatisticsVo(); // 创建销售统计VO
|
|
|
|
|
vo.setTotal(total); // 设置总量
|
|
|
|
|
QueryWrapper<Goods> wrapper = new QueryWrapper<Goods>().eq("state", Goods.STATE_UP) // 查询上架商品
|
|
|
|
|
.like(StringUtils.hasText(qo.getName()), "name", qo.getName()); // 名称模糊查询
|
|
|
|
|
Page<Goods> page = new Page<>(qo.getCurrentPage(), qo.getPageSize()); // 创建分页对象
|
|
|
|
|
super.page(page,wrapper); // 执行分页查询
|
|
|
|
|
Page<SaleGoodsVo> saleGoodsVoPage = new Page<>(qo.getCurrentPage(), qo.getPageSize()); // 创建销售商品分页
|
|
|
|
|
saleGoodsVoPage.setTotal(page.getTotal()); // 设置总数
|
|
|
|
|
List<SaleGoodsVo> saleGoodsVos = new ArrayList<>(); // 创建销售商品列表
|
|
|
|
|
for (Goods record : page.getRecords()) {
|
|
|
|
|
SaleGoodsVo goodsVo = new SaleGoodsVo(); // 创建销售商品VO
|
|
|
|
|
goodsVo.setGoodsId(record.getId()); // 设置商品ID
|
|
|
|
|
goodsVo.setGoodsName(record.getName()); // 设置商品名称
|
|
|
|
|
goodsVo.setSalesVolume(record.getSalesVolume()); // 设置销售量
|
|
|
|
|
goodsVo.setPercentage(total); // 设置占比
|
|
|
|
|
goodsVo.setCoverUrl(record.getCoverUrl()); // 设置封面URL
|
|
|
|
|
saleGoodsVos.add(goodsVo); // 添加到列表
|
|
|
|
|
}
|
|
|
|
|
saleGoodsVoPage.setRecords(saleGoodsVos); // 设置记录
|
|
|
|
|
vo.setVos(saleGoodsVoPage); // 设置分页结果
|
|
|
|
|
return vo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override // 分页查询未处理的异常出库通知单
|
|
|
|
|
public Page<NoticeInNotNormalVo> queryPageNoticeOut_untreated(QueryNoticeOut qo) {
|
|
|
|
|
Page<NoticeInNotNormalVo> page = new Page<>(qo.getCurrentPage(), qo.getPageSize()); // 创建分页对象
|
|
|
|
|
List<NoticeInNotNormalVo> vos = new ArrayList<>(); // 创建结果列表
|
|
|
|
|
QueryWrapper<DetailStoreGoods> queryWrapper = new QueryWrapper<DetailStoreGoods>().eq("state1", DetailStoreGoods.STATE1_UNTREATED); // 查询未处理记录
|
|
|
|
|
queryWrapper.eq(StringUtils.hasText(qo.getState()),"state",qo.getState()); // 状态条件
|
|
|
|
|
queryWrapper.like(StringUtils.hasText(qo.getName()),"goods_name",qo.getName()); // 商品名称模糊查询
|
|
|
|
|
queryWrapper.eq("type",DetailStoreGoods.TYPE_IN); // 类型为入库
|
|
|
|
|
queryWrapper.orderByDesc("create_time"); // 按创建时间降序
|
|
|
|
|
List<DetailStoreGoods> list = detailStoreGoodsService.list(queryWrapper); // 执行查询
|
|
|
|
|
for (DetailStoreGoods detailStoreGoods : list) {
|
|
|
|
|
NoticeInNotNormalVo vo = new NoticeInNotNormalVo(); // 创建VO对象
|
|
|
|
|
vo.setCn(detailStoreGoods.getCn()); // 设置编号
|
|
|
|
|
vo.setCreateTime(detailStoreGoods.getCreateTime()); // 设置创建时间
|
|
|
|
|
vo.setGoodsId(detailStoreGoods.getGoodsId()); // 设置商品ID
|
|
|
|
|
vo.setGoodsName(detailStoreGoods.getGoodsName()); // 设置商品名称
|
|
|
|
|
vo.setUntreatedNum(detailStoreGoods.getUntreatedNum()); // 设置未处理数量
|
|
|
|
|
vo.setState(detailStoreGoods.getState()); // 设置状态
|
|
|
|
|
vo.setStoreId(detailStoreGoods.getStoreId()); // 设置仓库ID
|
|
|
|
|
Store store = storeService.getById(detailStoreGoods.getStoreId()); // 查询仓库信息
|
|
|
|
|
vo.setStoreName(store.getName()); // 设置仓库名称
|
|
|
|
|
Goods goods = super.getById(detailStoreGoods.getGoodsId()); // 查询商品信息
|
|
|
|
|
vo.setCoverUrl(goods.getCoverUrl()); // 设置商品封面URL
|
|
|
|
|
vos.add(vo); // 添加到结果列表
|
|
|
|
|
}
|
|
|
|
|
page.setRecords(vos); // 设置记录
|
|
|
|
|
return page;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override // 处理未处理的异常出库单
|
|
|
|
|
public void resolveOutUntreatedForm(NoticeInNotNormalVo vo, String token) {
|
|
|
|
|
Employee employee = JSONObject.parseObject(redisTemplateService.getCacheObject(token), Employee.class);
|
|
|
|
|
// 查询未处理的出库记录
|
|
|
|
|
QueryWrapper<DetailStoreGoods> queryWrapper = new QueryWrapper<DetailStoreGoods>()
|
|
|
|
|
.eq("cn", vo.getCn()) // 编号条件
|
|
|
|
|
.eq("state1", DetailStoreGoods.STATE1_UNTREATED); // 未处理状态
|
|
|
|
|
DetailStoreGoods detailStoreGoods = detailStoreGoodsService.getOne(queryWrapper);
|
|
|
|
|
if (detailStoreGoods==null){ // 如果记录不存在
|
|
|
|
|
throw new BusinessException("该订单已被处理"); // 抛出业务异常
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
long num = detailStoreGoods.getUntreatedNum() - vo.getUntreatedNum(); // 计算剩余未处理数量
|
|
|
|
|
// 查询商品库存
|
|
|
|
|
QueryWrapper<GoodsStore> goodsStoreQueryWrapper = new QueryWrapper<GoodsStore>()
|
|
|
|
|
.eq("goods_id", vo.getGoodsId()) // 商品ID条件
|
|
|
|
|
.eq("store_id", vo.getStoreId()); // 仓库ID条件
|
|
|
|
|
GoodsStore goodsStore = goodsStoreService.getOne(goodsStoreQueryWrapper);
|
|
|
|
|
if (num>0){ // 如果还有剩余未处理
|
|
|
|
|
//未处理完毕
|
|
|
|
|
UpdateWrapper<DetailStoreGoods> updateWrapper = new UpdateWrapper<DetailStoreGoods>()
|
|
|
|
|
.eq("cn", detailStoreGoods.getCn()) // 编号条件
|
|
|
|
|
.set("untreated_num",num); // 更新未处理数量
|
|
|
|
|
detailStoreGoodsService.update(updateWrapper);
|
|
|
|
|
//改变库存
|
|
|
|
|
UpdateWrapper<GoodsStore> goodsStoreUpdateWrapper = new UpdateWrapper<GoodsStore>()
|
|
|
|
|
.eq("goods_id", vo.getGoodsId()) // 商品ID条件
|
|
|
|
|
.eq("store_id", vo.getStoreId()) // 仓库ID条件
|
|
|
|
|
.set("residue_num",goodsStore.getResidueNum()-vo.getUntreatedNum()); // 减少库存
|
|
|
|
|
goodsStoreService.update(goodsStoreUpdateWrapper);
|
|
|
|
|
}else { // 如果全部处理完毕
|
|
|
|
|
//处理完毕
|
|
|
|
|
UpdateWrapper<DetailStoreGoods> updateWrapper = new UpdateWrapper<DetailStoreGoods>()
|
|
|
|
|
.eq("cn", detailStoreGoods.getCn()) // 编号条件
|
|
|
|
|
.set("untreated_num",0L) // 设置未处理数量为0
|
|
|
|
|
.set("state1",DetailStoreGoods.STATE1_NORMAL) // 设置状态为正常
|
|
|
|
|
.set("createid",employee.getId()) // 设置处理人ID
|
|
|
|
|
.set("createby",employee.getNickName()) // 设置处理人名称
|
|
|
|
|
.set("create_time",new Date()) // 设置处理时间
|
|
|
|
|
.set("type",DetailStoreGoods.TYPE_OUT); // 设置类型为出库
|
|
|
|
|
detailStoreGoodsService.update(updateWrapper);//改变库存
|
|
|
|
|
UpdateWrapper goodsStoreUpdateWrapper = new UpdateWrapper()
|
|
|
|
|
.eq("goods_id", vo.getGoodsId()) // 商品ID条件
|
|
|
|
|
.eq("store_id", vo.getStoreId()) // 仓库ID条件
|
|
|
|
|
.set("residue_num",0L); // 设置库存为0
|
|
|
|
|
goodsStoreService.update(goodsStoreUpdateWrapper);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|