feat:智能柜商品分类

This commit is contained in:
dzc committed 2025-04-03 10:58:01 +08:00
1 parent a343c72431
commit 5e3c63e8a4
9 files changed
+172 -48

No files matched your search

+4
View File
@@ -290,6 +290,8 @@ CREATE TABLE hard_spu
ks_status char(1) DEFAULT '0' COMMENT '旷世审核状态',
ks_status_title varchar(64) NOT NULL COMMENT '旷世审核状态标题',
ks_comments varchar(512) DEFAULT NULL COMMENT '旷世审核状态描述',
mch_id bigint DEFAULT NULL COMMENT '商户id',
mch_dept_id bigint DEFAULT NULL COMMENT '商户部门id',
create_by varchar(64) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '创建人',
create_time datetime DEFAULT NULL COMMENT '创建时间',
update_by varchar(64) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '修改人',
@@ -308,6 +310,8 @@ CREATE TABLE hard_spu_category
id bigint NOT NULL AUTO_INCREMENT COMMENT '编号',
name varchar(64) NOT NULL COMMENT '分类名',
sort int DEFAULT 0 NOT NULL COMMENT '排序',
mch_id bigint DEFAULT NULL COMMENT '商户id',
mch_dept_id bigint DEFAULT NULL COMMENT '商户部门id',
create_by varchar(64) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '创建人',
create_time datetime DEFAULT NULL COMMENT '创建时间',
update_by varchar(64) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '修改人',
@@ -6,6 +6,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import com.bsd.pjcloud.common.core.util.TenantTable;
import java.time.LocalDateTime;
/**
@@ -19,64 +20,76 @@ import java.time.LocalDateTime;
public class HardSpuCategoryEntity extends Model<HardSpuCategoryEntity> {
/**
* 编号
*/
/**
* 编号
*/
@TableId(type = IdType.ASSIGN_ID)
@Schema(description="编号")
@Schema(description = "编号")
private Long id;
/**
* 分类名
*/
@Schema(description="分类名")
/**
* 分类名
*/
@Schema(description = "分类名")
private String name;
/**
* 排序
*/
@Schema(description="排序")
/**
* 排序
*/
@Schema(description = "排序")
private Integer sort;
/**
* 创建人
*/
@TableField(fill = FieldFill.INSERT)
@Schema(description="创建人")
/**
* 商户id
*/
@Schema(description = "商户id")
private Long mchId;
/**
* 商户部门id
*/
@Schema(description = "商户部门id")
private Long mchDeptId;
/**
* 创建人
*/
@TableField(fill = FieldFill.INSERT)
@Schema(description = "创建人")
private String createBy;
/**
* 创建时间
*/
@TableField(fill = FieldFill.INSERT)
@Schema(description="创建时间")
/**
* 创建时间
*/
@TableField(fill = FieldFill.INSERT)
@Schema(description = "创建时间")
private LocalDateTime createTime;
/**
* 修改人
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
@Schema(description="修改人")
/**
* 修改人
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
@Schema(description = "修改人")
private String updateBy;
/**
* 修改时间
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
@Schema(description="修改时间")
/**
* 修改时间
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
@Schema(description = "修改时间")
private LocalDateTime updateTime;
/**
* 删除标记
*/
/**
* 删除标记
*/
@TableLogic
@TableField(fill = FieldFill.INSERT)
@Schema(description="删除标记")
@TableField(fill = FieldFill.INSERT)
@Schema(description = "删除标记")
private String delFlag;
/**
* 租户ID
*/
@Schema(description="租户ID")
/**
* 租户ID
*/
@Schema(description = "租户ID")
private Long tenantId;
}
@@ -99,6 +99,18 @@ public class HardSpuEntity extends Model<HardSpuEntity> {
@Schema(description = "旷世审核状态描述")
private String ksComments;
/**
* 商户id
*/
@Schema(description = "商户id")
private Long mchId;
/**
* 商户部门id
*/
@Schema(description = "商户部门id")
private Long mchDeptId;
/**
* 创建人
*/
@@ -1,9 +1,19 @@
package com.bsd.pjcloud.hard.api.vo.spu;
import com.bsd.pjcloud.hard.api.entity.spu.HardSpuCategoryEntity;
import com.bsd.pjcloud.wallet.api.vo.base.BaseMchInterface;
import lombok.Data;
@Data
public class HardSpuCategoryVo extends HardSpuCategoryEntity {
public class HardSpuCategoryVo extends HardSpuCategoryEntity implements BaseMchInterface {
/**
* 商户相关
*/
private Long merchantId;
private String merchantName;
private String logoPic;
}
@@ -1,14 +1,23 @@
package com.bsd.pjcloud.hard.api.vo.spu;
import com.bsd.pjcloud.hard.api.entity.spu.HardSpuEntity;
import com.bsd.pjcloud.wallet.api.vo.base.BaseMchInterface;
import lombok.Data;
@Data
public class HardSpuVo extends HardSpuEntity {
public class HardSpuVo extends HardSpuEntity implements BaseMchInterface {
/**
* 分类相关
*/
private String categoryName;
/**
* 商户相关
*/
private Long merchantId;
private String merchantName;
private String logoPic;
}
@@ -1,11 +1,26 @@
package com.bsd.pjcloud.hard.mapper.spu;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bsd.pjcloud.common.core.util.BeanUtils;
import com.bsd.pjcloud.common.data.datascope.DataScope;
import com.bsd.pjcloud.common.data.datascope.PjcloudBaseMapper;
import com.bsd.pjcloud.hard.api.dto.spu.HardSpuCategoryDto;
import com.bsd.pjcloud.hard.api.entity.spu.HardSpuCategoryEntity;
import com.bsd.pjcloud.hard.api.vo.spu.HardSpuCategoryVo;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface HardSpuCategoryMapper extends PjcloudBaseMapper<HardSpuCategoryEntity> {
default Page<HardSpuCategoryVo> scopPageJoin(Page page, HardSpuCategoryDto dto, DataScope dataScope) {
LambdaQueryWrapper<HardSpuCategoryEntity> wrapper = new LambdaQueryWrapper<HardSpuCategoryEntity>()
.like(ObjectUtil.isNotEmpty(dto.getName()), HardSpuCategoryEntity::getName, dto.getName())
.orderByDesc(HardSpuCategoryEntity::getSort)
.orderByDesc(HardSpuCategoryEntity::getCreateTime);
Page pageList = selectPageByScope(page, wrapper, dataScope);
pageList.setRecords(BeanUtils.toBean(pageList.getRecords(), HardSpuCategoryVo.class));
return pageList;
}
}
@@ -4,18 +4,23 @@ import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bsd.pjcloud.common.core.util.CollectionUtils;
import com.bsd.pjcloud.common.data.datascope.DataScope;
import com.bsd.pjcloud.hard.api.dto.spu.HardSpuCategoryDto;
import com.bsd.pjcloud.hard.api.entity.spu.HardSpuCategoryEntity;
import com.bsd.pjcloud.hard.api.vo.spu.HardSpuCategoryVo;
import com.bsd.pjcloud.hard.mapper.spu.HardSpuCategoryMapper;
import com.bsd.pjcloud.hard.service.HardSpuCategoryService;
import com.bsd.pjcloud.wallet.api.feign.RemoteMchService;
import com.bsd.pjcloud.wallet.api.utils.WalletDataUtil;
import com.bsd.pjcloud.wallet.api.vo.MchManageVo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import java.util.ArrayList;
import java.util.List;
/**
* 硬件商品分类
@@ -26,12 +31,16 @@ import java.util.ArrayList;
@Service
public class HardSpuCategoryServiceImpl extends ServiceImpl<HardSpuCategoryMapper, HardSpuCategoryEntity> implements HardSpuCategoryService {
private final RemoteMchService remoteMchService;
/**
* 分页查询
*/
@Override
public Page<HardSpuCategoryVo> scopPageJoin(Page page, HardSpuCategoryDto dto, DataScope dataScope) {
return null;
Page<HardSpuCategoryVo> pageList = baseMapper.scopPageJoin(page, dto, dataScope);
disposeList(pageList.getRecords(), dto);
return pageList;
}
/**
@@ -72,6 +81,7 @@ public class HardSpuCategoryServiceImpl extends ServiceImpl<HardSpuCategoryMappe
*/
private boolean existName(HardSpuCategoryEntity dto) {
Long count = baseMapper.selectCount(new LambdaQueryWrapper<HardSpuCategoryEntity>()
.eq(ObjectUtil.isNotEmpty(dto.getMchId()), HardSpuCategoryEntity::getMchId, dto.getMchId())
.eq(ObjectUtil.isNotEmpty(dto.getName()), HardSpuCategoryEntity::getName, dto.getName())
.ne(ObjectUtil.isNotEmpty(dto.getId()), HardSpuCategoryEntity::getId, dto.getId())
);
@@ -80,4 +90,17 @@ public class HardSpuCategoryServiceImpl extends ServiceImpl<HardSpuCategoryMappe
}
return count > 0;
}
private void disposeList(List<HardSpuCategoryVo> list, HardSpuCategoryDto dto) {
if (ObjectUtil.isEmpty(list)) return;
// 商户
List<Long> mchIds = list.stream().map(HardSpuCategoryVo::getMchId).filter(ObjectUtil::isNotEmpty).distinct().toList();
if (ObjectUtil.isNotEmpty(mchIds)) {
list.forEach(v -> v.setMerchantId(v.getMchId()));
List<MchManageVo> mchList = remoteMchService.getByIds(mchIds).getData();
if (ObjectUtil.isNotEmpty(mchList)) {
WalletDataUtil.convertMchList(list, CollectionUtils.convertMap(mchList, MchManageVo::getId));
}
}
}
}
@@ -4,18 +4,23 @@ import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bsd.pjcloud.common.core.util.CollectionUtils;
import com.bsd.pjcloud.common.data.datascope.DataScope;
import com.bsd.pjcloud.hard.api.dto.spu.HardSpuDto;
import com.bsd.pjcloud.hard.api.entity.spu.HardSpuEntity;
import com.bsd.pjcloud.hard.api.vo.spu.HardSpuVo;
import com.bsd.pjcloud.hard.mapper.spu.HardSpuMapper;
import com.bsd.pjcloud.hard.service.HardSpuService;
import com.bsd.pjcloud.wallet.api.feign.RemoteMchService;
import com.bsd.pjcloud.wallet.api.utils.WalletDataUtil;
import com.bsd.pjcloud.wallet.api.vo.MchManageVo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import java.util.ArrayList;
import java.util.List;
/**
* 硬件商品
@@ -26,12 +31,16 @@ import java.util.ArrayList;
@Service
public class HardSpuServiceImpl extends ServiceImpl<HardSpuMapper, HardSpuEntity> implements HardSpuService {
private final RemoteMchService remoteMchService;
/**
* 分页查询
*/
@Override
public Page<HardSpuVo> scopPageJoin(Page page, HardSpuDto dto, DataScope dataScope) {
return baseMapper.scopPageJoin(page, dto, dataScope);
Page<HardSpuVo> pageList = baseMapper.scopPageJoin(page, dto, dataScope);
disposeList(pageList.getRecords(), dto);
return pageList;
}
/**
@@ -42,6 +51,12 @@ public class HardSpuServiceImpl extends ServiceImpl<HardSpuMapper, HardSpuEntity
if (existName(entity)) {
throw new RuntimeException("商品名不能重复");
}
// 查询商户
MchManageVo mchDetail = remoteMchService.getById(entity.getMchId()).getData();
if (ObjectUtil.isEmpty(mchDetail)) {
throw new RuntimeException("商户不存在");
}
entity.setMchDeptId(mchDetail.getDeptId());
baseMapper.insert(entity);
return entity.getId();
}
@@ -54,6 +69,12 @@ public class HardSpuServiceImpl extends ServiceImpl<HardSpuMapper, HardSpuEntity
if (existName(entity)) {
throw new RuntimeException("商品名不能重复");
}
// 查询商户
MchManageVo mchDetail = remoteMchService.getById(entity.getMchId()).getData();
if (ObjectUtil.isEmpty(mchDetail)) {
throw new RuntimeException("商户不存在");
}
entity.setMchDeptId(mchDetail.getDeptId());
baseMapper.updateById(entity);
return entity.getId();
}
@@ -81,4 +102,17 @@ public class HardSpuServiceImpl extends ServiceImpl<HardSpuMapper, HardSpuEntity
return count > 0;
}
private void disposeList(List<HardSpuVo> list, HardSpuDto dto) {
if (ObjectUtil.isEmpty(list)) return;
// 商户
List<Long> mchIds = list.stream().map(HardSpuVo::getMchId).filter(ObjectUtil::isNotEmpty).distinct().toList();
if (ObjectUtil.isNotEmpty(mchIds)) {
list.forEach(v -> v.setMerchantId(v.getMchId()));
List<MchManageVo> mchList = remoteMchService.getByIds(mchIds).getData();
if (ObjectUtil.isNotEmpty(mchList)) {
WalletDataUtil.convertMchList(list, CollectionUtils.convertMap(mchList, MchManageVo::getId));
}
}
}
}
@@ -16,6 +16,8 @@
<result property="ksStatus" column="ks_status"/>
<result property="ksStatusTitle" column="ks_status_title"/>
<result property="ksComments" column="ks_comments"/>
<result property="mchId" column="mch_id"/>
<result property="mchDeptId" column="mch_dept_id"/>
<result property="createBy" column="create_by"/>
<result property="createTime" column="create_time"/>
<result property="updateBy" column="update_by"/>
@@ -38,6 +40,8 @@
a.ks_status,
a.ks_status_title,
a.ks_comments,
a.mch_id,
a.mch_dept_id,
a.create_by,
a.create_time,
a.update_by,
@@ -48,7 +52,7 @@
<sql id="whereA">
a.del_flag = '0'
<if test="dto.name != null ">
<if test="dto.name != null ">
and a.name like concat('%', #{dto.name}, '%')
</if>
<if test="dto.spuCategoryId != null ">