商品模块代码提交

This commit is contained in:
Tankaikai 2025-02-20 16:03:54 +08:00
parent 00a92905b9
commit 758be911b7
18 changed files with 618 additions and 166 deletions

View File

@ -0,0 +1,149 @@
package com.czg.controller;
import com.czg.log.annotation.OperationLog;
import com.czg.product.dto.ConsInfoDTO;
import com.czg.product.service.ConsInfoService;
import com.czg.resp.CzgResult;
import com.czg.utils.AssertUtil;
import com.czg.validator.group.DefaultGroup;
import com.czg.validator.group.InsertGroup;
import com.czg.validator.group.UpdateGroup;
import com.mybatisflex.core.paginate.Page;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 耗材信息
*
* @author Tankaikai tankaikai@aliyun.com
* @since 1.0 2025-02-20
*/
@AllArgsConstructor
@RestController
@RequestMapping("/admin/product/cons")
public class ConsInfoController {
private final ConsInfoService consInfoService;
/**
* 分页
*/
@GetMapping("page")
@OperationLog("耗材信息-分页")
//@SaAdminCheckPermission("consInfo:page")
public CzgResult<Page<ConsInfoDTO>> getConsInfoPage(ConsInfoDTO param) {
Page<ConsInfoDTO> data = consInfoService.getConsInfoPage(param);
return CzgResult.success(data);
}
/**
* 列表
*/
@GetMapping("list")
@OperationLog("耗材信息-列表")
//@SaAdminCheckPermission("consInfo:list")
public CzgResult<List<ConsInfoDTO>> getConsInfoList(ConsInfoDTO param) {
List<ConsInfoDTO> data = consInfoService.getConsInfoList(param);
return CzgResult.success(data);
}
/**
* 详情
* param id 耗材信息id
*/
@GetMapping("{id}")
@OperationLog("耗材信息-详情")
//@SaAdminCheckPermission("consInfo:info")
public CzgResult<ConsInfoDTO> getConsInfoById(@PathVariable("id") Long id) {
AssertUtil.isNull(id, "{}不能为空", "id");
ConsInfoDTO data = consInfoService.getConsInfoById(id);
return CzgResult.success(data);
}
/**
* 新增
*/
@PostMapping
@OperationLog("耗材信息-新增")
//@SaAdminCheckPermission("consInfo:add")
public CzgResult<Void> addConsInfo(@RequestBody @Validated({InsertGroup.class, DefaultGroup.class}) ConsInfoDTO dto) {
consInfoService.addConsInfo(dto);
return CzgResult.success();
}
/**
* 修改
*/
@PutMapping
@OperationLog("耗材信息-修改")
//@SaAdminCheckPermission("consInfo:update")
public CzgResult<Void> updateConsInfo(@RequestBody @Validated({UpdateGroup.class, DefaultGroup.class}) ConsInfoDTO dto) {
consInfoService.updateConsInfo(dto);
return CzgResult.success();
}
/**
* 删除
*
* @param id 耗材信息id
*/
//@DeleteMapping("{id}")
//@OperationLog("耗材信息-删除")
//@SaAdminCheckPermission("consInfo:delete")
public CzgResult<Void> deleteConsInfo(@PathVariable("id") Long id) {
//效验数据
AssertUtil.isNull(id, "{}不能为空", "id");
consInfoService.deleteConsInfo(id);
return CzgResult.success();
}
/**
* 禁用
*
* @param id 耗材信息id
*/
@PostMapping("disable/{id}")
@OperationLog("耗材信息-禁用")
//@SaAdminCheckPermission("consInfo:able")
public CzgResult<Void> disableConsInfo(@PathVariable("id") Long id) {
//效验数据
AssertUtil.isNull(id, "{}不能为空", "id");
consInfoService.disableConsInfo(id);
return CzgResult.success();
}
/**
* 启用
*
* @param id 耗材信息id
*/
@PostMapping("enable/{id}")
@OperationLog("耗材信息-启用")
//@SaAdminCheckPermission("consInfo:able")
public CzgResult<Void> enableConsInfo(@PathVariable("id") Long id) {
//效验数据
AssertUtil.isNull(id, "{}不能为空", "id");
consInfoService.enableConsInfo(id);
return CzgResult.success();
}
/**
* 库存开关
*
* @param id 耗材信息id
* @param isStock 库存开关 1-开启 0-关闭
*/
@PostMapping("on-off")
@OperationLog("耗材信息-库存开关")
//@SaAdminCheckPermission("consInfo:on-off")
public CzgResult<Void> onOffConsInfo(@RequestParam Long id, @RequestParam Integer isStock) {
//效验数据
AssertUtil.isNull(id, "{}不能为空", "id");
AssertUtil.isNull(isStock, "库存开关值不能为空");
consInfoService.onOffConsInfo(id, isStock);
return CzgResult.success();
}
}

View File

@ -11,7 +11,7 @@ spring:
port: 6379
password: chaozg123
timeout: 5000
database: 1
database: 2
lettuce:
pool:
min-idle: 0

View File

@ -62,4 +62,9 @@ public class ConsGroupDTO implements Serializable {
*/
private List<Long> consIds;
/**
* 耗材集合
*/
private List<ConsInfoDTO> consInfoList;
}

View File

@ -0,0 +1,106 @@
package com.czg.product.dto;
import com.alibaba.fastjson2.annotation.JSONField;
import com.czg.validator.group.DefaultGroup;
import com.czg.validator.group.InsertGroup;
import com.czg.validator.group.UpdateGroup;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Null;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
/**
* 耗材信息
*
* @author Tankaikai tankaikai@aliyun.com
* @since 1.0 2025-02-20
*/
@Data
public class ConsInfoDTO implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* id
*/
@Null(message = "ID必须为空", groups = InsertGroup.class)
@NotNull(message = "ID不能为空", groups = UpdateGroup.class)
private Long id;
/**
* 耗材分组id
*/
@NotNull(message = "耗材分组id不能为空", groups = DefaultGroup.class)
private Long consGroupId;
/**
* 店铺id
*/
private Long shopId;
/**
* 耗材名称
*/
@NotBlank(message = "耗材名称不能为空", groups = DefaultGroup.class)
private String conName;
/**
* 价格
*/
@NotNull(message = "价格不能为空", groups = DefaultGroup.class)
private BigDecimal price;
/**
* 库存值
*/
private BigDecimal stockNumber;
/**
* 状态 1 启用 0 禁用
*/
private Integer status;
/**
* 单位值
*/
@NotBlank(message = "单位不能为空", groups = DefaultGroup.class)
private String conUnit;
/**
* 耗材预警值
*/
private BigDecimal conWarning;
/**
* 是否检测耗材: 1 检测 0 不检测
*/
private Integer isStock;
/**
* 第二单位
*/
private String conUnitTwo;
/**
* 第二单位转换数量
*/
private BigDecimal conUnitTwoConvert;
/**
* 默认入库单位
*/
private String defaultUnit;
/**
* 创建时间
*/
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime createTime;
/**
* 更新时间
*/
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime updateTime;
/**
* 开始时间 yyyy-MM-dd HH:mm:ss
*/
private String beginTime;
/**
* 结束时间 yyyy-MM-dd HH:mm:ss
*/
private String endTime;
}

View File

@ -0,0 +1,90 @@
package com.czg.product.entity;
import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.KeyType;
import com.mybatisflex.annotation.Table;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
/**
* 耗材信息
*
* @author Tankaikai tankaikai@aliyun.com
* @since 1.0 2025-02-20
*/
@Data
@Table("tb_cons_info")
public class ConsInfo implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* id
*/
@Id(keyType = KeyType.Auto)
private Long id;
/**
* 耗材分组id
*/
private Long consGroupId;
/**
* 店铺id
*/
private Long shopId;
/**
* 耗材名称
*/
private String conName;
/**
* 价格
*/
private BigDecimal price;
/**
* 库存值
*/
private BigDecimal stockNumber;
/**
* 状态 1 启用 0 禁用
*/
private Integer status;
/**
* 单位值
*/
private String conUnit;
/**
* 耗材预警值
*/
private BigDecimal conWarning;
/**
* 是否检测耗材: 1 检测 0 不检测
*/
private Integer isStock;
/**
* 第二单位
*/
private String conUnitTwo;
/**
* 第二单位转换数量
*/
private BigDecimal conUnitTwoConvert;
/**
* 默认入库单位
*/
private String defaultUnit;
/**
* 创建时间
*/
@Column(onInsertValue = "now()")
private LocalDateTime createTime;
/**
* 更新时间
*/
@Column(onInsertValue = "now()", onUpdateValue = "now()")
private LocalDateTime updateTime;
}

View File

@ -0,0 +1,35 @@
package com.czg.product.service;
import com.czg.product.dto.ConsInfoDTO;
import com.czg.product.entity.ConsInfo;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.service.IService;
import java.util.List;
/**
* 耗材信息
*
* @author Tankaikai tankaikai@aliyun.com
* @since 1.0 2025-02-20
*/
public interface ConsInfoService extends IService<ConsInfo> {
Page<ConsInfoDTO> getConsInfoPage(ConsInfoDTO param);
List<ConsInfoDTO> getConsInfoList(ConsInfoDTO param);
ConsInfoDTO getConsInfoById(Long id);
boolean addConsInfo(ConsInfoDTO dto);
boolean updateConsInfo(ConsInfoDTO dto);
boolean deleteConsInfo(Long id);
boolean disableConsInfo(Long id);
boolean enableConsInfo(Long id);
boolean onOffConsInfo(Long id, Integer isStock);
}

View File

@ -1,12 +1,8 @@
package com.czg.product.service;
import com.czg.product.dto.ProdSkuDTO;
import com.czg.product.entity.ProdSku;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.service.IService;
import java.util.List;
/**
* 商品SKU
*
@ -14,20 +10,5 @@ import java.util.List;
* @since 1.0 2025-02-16
*/
public interface ProdSkuService extends IService<ProdSku> {
Page<ProdSkuDTO> getProdSkuPage(ProdSkuDTO param);
List<ProdSkuDTO> getProdSkuList(ProdSkuDTO param);
ProdSkuDTO getProdSkuById(Long id);
boolean addProdSku(ProdSkuDTO dto);
boolean deleteProdSku(Long id);
boolean updateProdSku(ProdSkuDTO dto);
boolean disableProdSku(Long id);
boolean enableProdSku(Long id);
}

View File

@ -0,0 +1,16 @@
package com.czg.service.product.mapper;
import com.czg.product.entity.ConsInfo;
import com.mybatisflex.core.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
/**
* 耗材信息
*
* @author Tankaikai tankaikai@aliyun.com
* @since 1.0 2025-02-20
*/
@Mapper
public interface ConsInfoMapper extends BaseMapper<ConsInfo> {
}

View File

@ -6,12 +6,15 @@ import cn.hutool.core.util.StrUtil;
import com.czg.enums.StatusEnum;
import com.czg.exception.CzgException;
import com.czg.product.dto.ConsGroupDTO;
import com.czg.product.dto.ConsInfoDTO;
import com.czg.product.entity.ConsGroup;
import com.czg.product.entity.ConsGroupRelation;
import com.czg.product.entity.ConsInfo;
import com.czg.product.service.ConsGroupService;
import com.czg.sa.StpKit;
import com.czg.service.product.mapper.ConsGroupMapper;
import com.czg.service.product.mapper.ConsGroupRelationMapper;
import com.czg.service.product.mapper.ConsInfoMapper;
import com.czg.utils.PageUtil;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
@ -34,13 +37,14 @@ import java.util.List;
public class ConsGroupServiceImpl extends ServiceImpl<ConsGroupMapper, ConsGroup> implements ConsGroupService {
private final ConsGroupRelationMapper consGroupRelationMapper;
private final ConsInfoMapper consInfoMapper;
private QueryWrapper buildQueryWrapper(ConsGroupDTO param) {
QueryWrapper queryWrapper = PageUtil.buildSortQueryWrapper();
if (StrUtil.isNotEmpty(param.getName())) {
queryWrapper.like(ConsGroup::getName, param.getName());
}
Long shopId = StpKit.USER.getLoginIdAsLong();
Long shopId = StpKit.USER.getShopId(0L);
queryWrapper.eq(ConsGroup::getShopId, shopId);
queryWrapper.orderBy(ConsGroup::getId, false);
return queryWrapper;
@ -61,17 +65,19 @@ public class ConsGroupServiceImpl extends ServiceImpl<ConsGroupMapper, ConsGroup
@Override
public ConsGroupDTO getConsGroupById(Long id) {
Long shopId = StpKit.USER.getLoginIdAsLong();
Long shopId = StpKit.USER.getShopId(0L);
ConsGroupDTO dto = super.getOneAs(query().eq(ConsGroup::getId, id).eq(ConsGroup::getShopId, shopId), ConsGroupDTO.class);
List<Long> consIds = consGroupRelationMapper.selectListByQueryAs(query().select(ConsGroupRelation::getConsId).eq(ConsGroupRelation::getGroupId, dto.getId()), Long.class);
dto.setConsIds(consIds);
List<ConsInfoDTO> consInfoList = consInfoMapper.selectListByQueryAs(query().eq(ConsInfo::getConsGroupId, dto.getId()), ConsInfoDTO.class);
dto.setConsInfoList(consInfoList);
return dto;
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean addConsGroup(ConsGroupDTO dto) {
Long shopId = StpKit.USER.getLoginIdAsLong();
Long shopId = StpKit.USER.getShopId(0L);
boolean exists = super.exists(query().eq(ConsGroup::getName, dto.getName()).eq(ConsGroup::getShopId, shopId));
if (exists) {
throw new CzgException("耗材分组已存在");
@ -84,13 +90,11 @@ public class ConsGroupServiceImpl extends ServiceImpl<ConsGroupMapper, ConsGroup
if (CollUtil.isEmpty(consIds)) {
return true;
}
int index = 0;
for (Long consId : consIds) {
index++;
ConsGroupRelation relation = new ConsGroupRelation();
relation.setConsId(consId);
relation.setGroupId(entity.getId());
relation.setSort(index);
relation.setSort(consId.intValue());
consGroupRelationMapper.insert(relation);
}
return true;
@ -98,7 +102,7 @@ public class ConsGroupServiceImpl extends ServiceImpl<ConsGroupMapper, ConsGroup
@Override
public boolean updateConsGroup(ConsGroupDTO dto) {
Long shopId = StpKit.USER.getLoginIdAsLong();
Long shopId = StpKit.USER.getShopId(0L);
dto.setShopId(shopId);
boolean exists = super.exists(query().eq(ConsGroup::getName, dto.getName()).eq(ConsGroup::getShopId, shopId).ne(ConsGroup::getId, dto.getId()));
if (exists) {
@ -111,13 +115,11 @@ public class ConsGroupServiceImpl extends ServiceImpl<ConsGroupMapper, ConsGroup
return true;
}
consGroupRelationMapper.deleteByQuery(query().eq(ConsGroupRelation::getGroupId, entity.getId()));
int index = 0;
for (Long consId : consIds) {
index++;
ConsGroupRelation relation = new ConsGroupRelation();
relation.setConsId(consId);
relation.setGroupId(entity.getId());
relation.setSort(index);
relation.setSort(consId.intValue());
consGroupRelationMapper.insert(relation);
}
return true;
@ -125,13 +127,13 @@ public class ConsGroupServiceImpl extends ServiceImpl<ConsGroupMapper, ConsGroup
@Override
public boolean deleteConsGroup(Long id) {
Long shopId = StpKit.USER.getLoginIdAsLong();
Long shopId = StpKit.USER.getShopId(0L);
return super.remove(query().eq(ConsGroup::getId, id).eq(ConsGroup::getShopId, shopId));
}
@Override
public boolean disableConsGroup(Long id) {
Long shopId = StpKit.USER.getLoginIdAsLong();
Long shopId = StpKit.USER.getShopId(0L);
return UpdateChain.of(ConsGroup.class)
.set(ConsGroup::getStatus, StatusEnum.DISABLE.value())
.eq(ConsGroup::getId, id)
@ -141,7 +143,7 @@ public class ConsGroupServiceImpl extends ServiceImpl<ConsGroupMapper, ConsGroup
@Override
public boolean enableConsGroup(Long id) {
Long shopId = StpKit.USER.getLoginIdAsLong();
Long shopId = StpKit.USER.getShopId(0L);
return UpdateChain.of(ConsGroup.class)
.set(ConsGroup::getStatus, StatusEnum.ENABLED.value())
.eq(ConsGroup::getId, id)

View File

@ -0,0 +1,156 @@
package com.czg.service.product.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import com.czg.enums.StatusEnum;
import com.czg.enums.YesNoEnum;
import com.czg.exception.CzgException;
import com.czg.product.dto.ConsInfoDTO;
import com.czg.product.entity.ConsGroupRelation;
import com.czg.product.entity.ConsInfo;
import com.czg.product.service.ConsInfoService;
import com.czg.sa.StpKit;
import com.czg.service.product.mapper.ConsGroupRelationMapper;
import com.czg.service.product.mapper.ConsInfoMapper;
import com.czg.utils.PageUtil;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.core.update.UpdateChain;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.List;
/**
* 耗材信息
*
* @author Tankaikai tankaikai@aliyun.com
* @since 1.0 2025-02-20
*/
@Service
@AllArgsConstructor
public class ConsInfoServiceImpl extends ServiceImpl<ConsInfoMapper, ConsInfo> implements ConsInfoService {
private final ConsGroupRelationMapper consGroupRelationMapper;
private QueryWrapper buildQueryWrapper(ConsInfoDTO param) {
QueryWrapper queryWrapper = PageUtil.buildSortQueryWrapper();
if (ObjUtil.isNotNull(param.getConsGroupId())) {
queryWrapper.eq(ConsInfo::getConsGroupId, param.getConsGroupId());
}
if (StrUtil.isNotEmpty(param.getConName())) {
queryWrapper.like(ConsInfo::getConName, param.getConName());
}
if (StrUtil.isNotEmpty(param.getBeginTime())) {
queryWrapper.ge(ConsInfo::getCreateTime, param.getBeginTime());
}
if (StrUtil.isNotEmpty(param.getEndTime())) {
queryWrapper.le(ConsInfo::getCreateTime, param.getEndTime());
}
Long shopId = StpKit.USER.getShopId(0L);
queryWrapper.eq(ConsInfo::getShopId, shopId);
queryWrapper.orderBy(ConsInfo::getId, false);
return queryWrapper;
}
@Override
public Page<ConsInfoDTO> getConsInfoPage(ConsInfoDTO param) {
QueryWrapper queryWrapper = buildQueryWrapper(param);
return super.pageAs(PageUtil.buildPage(), queryWrapper, ConsInfoDTO.class);
}
@Override
public List<ConsInfoDTO> getConsInfoList(ConsInfoDTO param) {
QueryWrapper queryWrapper = buildQueryWrapper(param);
queryWrapper.eq(ConsInfo::getStatus, StatusEnum.ENABLED.value());
return super.listAs(queryWrapper, ConsInfoDTO.class);
}
@Override
public ConsInfoDTO getConsInfoById(Long id) {
Long shopId = StpKit.USER.getShopId(0L);
return super.getOneAs(query().eq(ConsInfo::getId, id).eq(ConsInfo::getShopId, shopId), ConsInfoDTO.class);
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean addConsInfo(ConsInfoDTO dto) {
Long shopId = StpKit.USER.getShopId(0L);
boolean exists = super.exists(query().eq(ConsInfo::getConName, dto.getConName()).eq(ConsInfo::getShopId, shopId));
if (exists) {
throw new CzgException("耗材信息已存在");
}
ConsInfo entity = BeanUtil.copyProperties(dto, ConsInfo.class);
entity.setStockNumber(BigDecimal.ZERO);
entity.setStatus(StatusEnum.ENABLED.value());
//entity.setConWarning(BigDecimal.ZERO);
entity.setIsStock(YesNoEnum.NO.value());
entity.setShopId(shopId);
super.save(entity);
ConsGroupRelation relation = new ConsGroupRelation();
relation.setConsId(entity.getId());
relation.setGroupId(dto.getConsGroupId());
relation.setSort(entity.getId().intValue());
consGroupRelationMapper.insert(relation);
return true;
}
@Override
public boolean updateConsInfo(ConsInfoDTO dto) {
Long shopId = StpKit.USER.getShopId(0L);
dto.setShopId(shopId);
boolean exists = super.exists(query().eq(ConsInfo::getConName, dto.getConName()).eq(ConsInfo::getShopId, shopId).ne(ConsInfo::getId, dto.getId()));
if (exists) {
throw new CzgException("耗材信息已存在");
}
ConsInfo entity = BeanUtil.copyProperties(dto, ConsInfo.class);
super.updateById(entity);
consGroupRelationMapper.deleteByQuery(query().eq(ConsGroupRelation::getConsId, dto.getId()));
ConsGroupRelation relation = new ConsGroupRelation();
relation.setConsId(entity.getId());
relation.setGroupId(dto.getConsGroupId());
relation.setSort(entity.getId().intValue());
consGroupRelationMapper.insert(relation);
return true;
}
@Override
public boolean deleteConsInfo(Long id) {
Long shopId = StpKit.USER.getShopId(0L);
return super.remove(query().eq(ConsInfo::getId, id).eq(ConsInfo::getShopId, shopId));
}
@Override
public boolean disableConsInfo(Long id) {
Long shopId = StpKit.USER.getShopId(0L);
return UpdateChain.of(ConsInfo.class)
.set(ConsInfo::getStatus, StatusEnum.DISABLE.value())
.eq(ConsInfo::getId, id)
.eq(ConsInfo::getShopId, shopId)
.update();
}
@Override
public boolean enableConsInfo(Long id) {
Long shopId = StpKit.USER.getShopId(0L);
return UpdateChain.of(ConsInfo.class)
.set(ConsInfo::getStatus, StatusEnum.ENABLED.value())
.eq(ConsInfo::getId, id)
.eq(ConsInfo::getShopId, shopId)
.update();
}
@Override
public boolean onOffConsInfo(Long id, Integer isStock) {
Long shopId = StpKit.USER.getShopId(0L);
ConsInfo entity = super.getOne(query().eq(ConsInfo::getId, id).eq(ConsInfo::getShopId, shopId));
entity.setIsStock(isStock);
super.updateById(entity);
return false;
}
}

View File

@ -47,7 +47,7 @@ public class ProdGroupServiceImpl extends ServiceImpl<ProdGroupMapper, ProdGroup
if (StrUtil.isNotEmpty(param.getName())) {
queryWrapper.like(ProdGroup::getName, param.getName());
}
Long shopId = StpKit.USER.getLoginIdAsLong();
Long shopId = StpKit.USER.getShopId(0L);
queryWrapper.eq(ProdGroup::getShopId, shopId);
queryWrapper.orderBy(ProdGroup::getId, false);
return queryWrapper;
@ -68,7 +68,7 @@ public class ProdGroupServiceImpl extends ServiceImpl<ProdGroupMapper, ProdGroup
@Override
public ProdGroupDTO getProdGroupById(Long id) {
Long shopId = StpKit.USER.getLoginIdAsLong();
Long shopId = StpKit.USER.getShopId(0L);
ProdGroupDTO dto = super.getOneAs(query().eq(ProdGroup::getId, id).eq(ProdGroup::getShopId, shopId), ProdGroupDTO.class);
List<Long> productIdList = prodGroupRelationMapper.selectObjectListByQueryAs(query().select(ProdGroupRelation::getProductId).eq(ProdGroupRelation::getProdGroupId, id), Long.class);
if (CollUtil.isNotEmpty(productIdList)) {
@ -83,7 +83,7 @@ public class ProdGroupServiceImpl extends ServiceImpl<ProdGroupMapper, ProdGroup
@Override
@Transactional(rollbackFor = Exception.class)
public boolean addProdGroup(ProdGroupDTO dto) {
Long shopId = StpKit.USER.getLoginIdAsLong();
Long shopId = StpKit.USER.getShopId(0L);
boolean exists = super.exists(query().eq(ProdGroup::getName, dto.getName()).eq(ProdGroup::getShopId, shopId));
if (exists) {
throw new CzgException("商品分组已存在");
@ -109,7 +109,7 @@ public class ProdGroupServiceImpl extends ServiceImpl<ProdGroupMapper, ProdGroup
@Override
@Transactional(rollbackFor = Exception.class)
public boolean updateProdGroup(ProdGroupDTO dto) {
Long shopId = StpKit.USER.getLoginIdAsLong();
Long shopId = StpKit.USER.getShopId(0L);
dto.setShopId(shopId);
boolean exists = super.exists(query().eq(ProdGroup::getName, dto.getName()).eq(ProdGroup::getShopId, shopId).ne(ProdGroup::getId, dto.getId()));
if (exists) {
@ -136,7 +136,7 @@ public class ProdGroupServiceImpl extends ServiceImpl<ProdGroupMapper, ProdGroup
@Override
@Transactional(rollbackFor = Exception.class)
public boolean deleteProdGroup(Long id) {
Long shopId = StpKit.USER.getLoginIdAsLong();
Long shopId = StpKit.USER.getShopId(0L);
super.remove(query().eq(ProdGroup::getId, id).eq(ProdGroup::getShopId, shopId));
prodGroupRelationMapper.deleteByQuery(query().eq(ProdGroupRelation::getProdGroupId, id));
return true;
@ -144,7 +144,7 @@ public class ProdGroupServiceImpl extends ServiceImpl<ProdGroupMapper, ProdGroup
@Override
public boolean disableProdGroup(Long id) {
Long shopId = StpKit.USER.getLoginIdAsLong();
Long shopId = StpKit.USER.getShopId(0L);
return UpdateChain.of(ProdGroup.class)
.set(ProdGroup::getStatus, StatusEnum.DISABLE.value())
.eq(ProdGroup::getId, id)
@ -154,7 +154,7 @@ public class ProdGroupServiceImpl extends ServiceImpl<ProdGroupMapper, ProdGroup
@Override
public boolean enableProdGroup(Long id) {
Long shopId = StpKit.USER.getLoginIdAsLong();
Long shopId = StpKit.USER.getShopId(0L);
return UpdateChain.of(ProdGroup.class)
.set(ProdGroup::getStatus, StatusEnum.ENABLED.value())
.eq(ProdGroup::getId, id)

View File

@ -1,21 +1,11 @@
package com.czg.service.product.service.impl;
import cn.hutool.core.bean.BeanUtil;
import com.czg.exception.CzgException;
import com.czg.product.dto.ProdSkuDTO;
import com.czg.product.entity.ProdSku;
import com.czg.product.service.ProdSkuService;
import com.czg.sa.StpKit;
import com.czg.service.product.mapper.ProdSkuMapper;
import com.czg.utils.PageUtil;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.core.update.UpdateChain;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 商品SKU
*
@ -25,88 +15,4 @@ import java.util.List;
@Service
public class ProdSkuServiceImpl extends ServiceImpl<ProdSkuMapper, ProdSku> implements ProdSkuService {
private QueryWrapper buildQueryWrapper(ProdSkuDTO param) {
QueryWrapper queryWrapper = PageUtil.buildSortQueryWrapper();
/*if (StrUtil.isNotEmpty(param.getName())) {
queryWrapper.like(ProdSku::getName, param.getName());
}*/
Long shopId = StpKit.USER.getLoginIdAsLong();
queryWrapper.eq(ProdSku::getShopId, shopId);
queryWrapper.orderBy(ProdSku::getId, false);
return queryWrapper;
}
@Override
public Page<ProdSkuDTO> getProdSkuPage(ProdSkuDTO param) {
QueryWrapper queryWrapper = buildQueryWrapper(param);
return super.pageAs(PageUtil.buildPage(), queryWrapper, ProdSkuDTO.class);
}
@Override
public List<ProdSkuDTO> getProdSkuList(ProdSkuDTO param) {
QueryWrapper queryWrapper = buildQueryWrapper(param);
//queryWrapper.eq(ProdSku::getStatus, StatusEnum.ENABLED.value());
return super.listAs(queryWrapper, ProdSkuDTO.class);
}
@Override
public ProdSkuDTO getProdSkuById(Long id) {
Long shopId = StpKit.USER.getLoginIdAsLong();
return super.getOneAs(query().eq(ProdSku::getId, id).eq(ProdSku::getShopId, shopId), ProdSkuDTO.class);
}
@Override
public boolean addProdSku(ProdSkuDTO dto) {
Long shopId = StpKit.USER.getLoginIdAsLong();
boolean exists = true;
//super.exists(query().eq(ProdSku::getName, dto.getName()).eq(ProdSku::getShopId, shopId));
if (exists) {
throw new CzgException("商品SKU已存在");
}
ProdSku entity = BeanUtil.copyProperties(dto, ProdSku.class);
//entity.setStatus(StatusEnum.ENABLED.value());
entity.setShopId(shopId);
return super.save(entity);
}
@Override
public boolean updateProdSku(ProdSkuDTO dto) {
Long shopId = StpKit.USER.getLoginIdAsLong();
dto.setShopId(shopId);
//boolean exists = super.exists(query().eq(ProdSku::getName, dto.getName()).eq(ProdSku::getShopId, shopId).ne(ProdSku::getId, dto.getId()));
boolean exists = true;
if (exists) {
throw new CzgException("商品SKU已存在");
}
ProdSku entity = BeanUtil.copyProperties(dto, ProdSku.class);
return super.updateById(entity);
}
@Override
public boolean deleteProdSku(Long id) {
Long shopId = StpKit.USER.getLoginIdAsLong();
//return super.remove(query().eq(ClassName}::getId, id).eq(ClassName}::getShopId, shopId));
return true;
}
@Override
public boolean disableProdSku(Long id) {
Long shopId = StpKit.USER.getLoginIdAsLong();
return UpdateChain.of(ProdSku.class)
//.set(ProdSku::getStatus, StatusEnum.DISABLE.value())
.eq(ProdSku::getId, id)
.eq(ProdSku::getShopId, shopId)
.update();
}
@Override
public boolean enableProdSku(Long id) {
Long shopId = StpKit.USER.getLoginIdAsLong();
return UpdateChain.of(ProdSku.class)
//.set(ProdSku::getStatus, StatusEnum.ENABLED.value())
.eq(ProdSku::getId, id)
.eq(ProdSku::getShopId, shopId)
.update();
}
}

View File

@ -73,7 +73,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
if (ObjUtil.isNotNull(param.getCreateEndTime())) {
queryWrapper.le(Product::getCreateTime, param.getCreateEndTime());
}
Long shopId = StpKit.USER.getLoginIdAsLong();
Long shopId = StpKit.USER.getShopId(0L);
queryWrapper.eq(Product::getShopId, shopId);
queryWrapper.eq(Product::getIsDel, DeleteEnum.NORMAL.value());
queryWrapper.orderBy(Product::getSort, false);
@ -149,7 +149,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
@Override
@Transactional(rollbackFor = Exception.class)
public boolean addProduct(ProductDTO dto) {
Long shopId = StpKit.USER.getLoginIdAsLong();
Long shopId = StpKit.USER.getShopId(0L);
boolean exists = super.exists(query().eq(Product::getName, dto.getName()).eq(Product::getShopId, shopId));
if (exists) {
throw new CzgException("商品已存在");
@ -189,7 +189,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
@Override
public boolean updateProduct(ProductDTO dto) {
Long shopId = StpKit.USER.getLoginIdAsLong();
Long shopId = StpKit.USER.getShopId(0L);
dto.setShopId(shopId);
boolean exists = super.exists(query().eq(Product::getName, dto.getName()).eq(Product::getShopId, shopId).ne(Product::getId, dto.getId()));
if (exists) {
@ -242,7 +242,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
@Override
public boolean deleteProduct(Long id) {
Long shopId = StpKit.USER.getLoginIdAsLong();
Long shopId = StpKit.USER.getShopId(0L);
return UpdateChain.of(Product.class)
.set(Product::getIsDel, DeleteEnum.DELETED.value())
.eq(Product::getId, id)
@ -253,7 +253,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
@Override
@Transactional(rollbackFor = Exception.class)
public boolean onOffProduct(ProductIsSaleParam param) {
Long shopId = StpKit.USER.getLoginIdAsLong();
Long shopId = StpKit.USER.getShopId(0L);
String type = param.getType();
Long id = param.getId();
Integer isSale = param.getIsSale();
@ -274,7 +274,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
@Override
@Transactional(rollbackFor = Exception.class)
public boolean markProductIsSoldOut(ProductIsSoldOutParam param) {
Long shopId = StpKit.USER.getLoginIdAsLong();
Long shopId = StpKit.USER.getShopId(0L);
String type = param.getType();
Long id = param.getId();
Integer isSoldOut = param.getIsSoldOut();

View File

@ -32,7 +32,7 @@ public class ShopProdCategoryServiceImpl extends ServiceImpl<ShopProdCategoryMap
if (StrUtil.isNotEmpty(param.getName())) {
queryWrapper.like(ShopProdCategory::getName, param.getName());
}
Long shopId = StpKit.USER.getLoginIdAsLong();
Long shopId = StpKit.USER.getShopId(0L);
queryWrapper.eq(ShopProdCategory::getShopId, shopId);
queryWrapper.orderBy(ShopProdCategory::getId, false);
return queryWrapper;
@ -53,13 +53,13 @@ public class ShopProdCategoryServiceImpl extends ServiceImpl<ShopProdCategoryMap
@Override
public ShopProdCategoryDTO getShopProdCategoryById(Long id) {
Long shopId = StpKit.USER.getLoginIdAsLong();
Long shopId = StpKit.USER.getShopId(0L);
return super.getOneAs(query().eq(ShopProdCategory::getId, id).eq(ShopProdCategory::getShopId, shopId), ShopProdCategoryDTO.class);
}
@Override
public boolean addShopProdCategory(ShopProdCategoryDTO dto) {
Long shopId = StpKit.USER.getLoginIdAsLong();
Long shopId = StpKit.USER.getShopId(0L);
boolean exists = super.exists(query().eq(ShopProdCategory::getName, dto.getName()).eq(ShopProdCategory::getShopId, shopId));
if (exists) {
throw new CzgException("商品分类已存在");
@ -77,7 +77,7 @@ public class ShopProdCategoryServiceImpl extends ServiceImpl<ShopProdCategoryMap
@Override
public boolean updateShopProdCategory(ShopProdCategoryDTO dto) {
Long shopId = StpKit.USER.getLoginIdAsLong();
Long shopId = StpKit.USER.getShopId(0L);
dto.setShopId(shopId);
boolean exists = super.exists(query().eq(ShopProdCategory::getName, dto.getName()).eq(ShopProdCategory::getShopId, shopId).ne(ShopProdCategory::getId, dto.getId()));
if (exists) {
@ -89,13 +89,13 @@ public class ShopProdCategoryServiceImpl extends ServiceImpl<ShopProdCategoryMap
@Override
public boolean deleteShopProdCategory(Long id) {
Long shopId = StpKit.USER.getLoginIdAsLong();
Long shopId = StpKit.USER.getShopId(0L);
return super.remove(query().eq(ShopProdCategory::getId, id).eq(ShopProdCategory::getShopId, shopId));
}
@Override
public boolean disableShopProdCategory(Long id) {
Long shopId = StpKit.USER.getLoginIdAsLong();
Long shopId = StpKit.USER.getShopId(0L);
return UpdateChain.of(ShopProdCategory.class)
.set(ShopProdCategory::getStatus, StatusEnum.DISABLE.value())
.eq(ShopProdCategory::getId, id)
@ -105,7 +105,7 @@ public class ShopProdCategoryServiceImpl extends ServiceImpl<ShopProdCategoryMap
@Override
public boolean enableShopProdCategory(Long id) {
Long shopId = StpKit.USER.getLoginIdAsLong();
Long shopId = StpKit.USER.getShopId(0L);
return UpdateChain.of(ShopProdCategory.class)
.set(ShopProdCategory::getStatus, StatusEnum.ENABLED.value())
.eq(ShopProdCategory::getId, id)

View File

@ -35,7 +35,7 @@ public class ShopProdUnitServiceImpl extends ServiceImpl<ShopProdUnitMapper, Sho
if (StrUtil.isNotEmpty(param.getName())) {
queryWrapper.like(ShopProdUnit::getName, param.getName());
}
Long shopId = StpKit.USER.getLoginIdAsLong();
Long shopId = StpKit.USER.getShopId(0L);
queryWrapper.eq(ShopProdUnit::getShopId, shopId);
queryWrapper.orderBy(ShopProdUnit::getId, false);
return queryWrapper;
@ -56,13 +56,13 @@ public class ShopProdUnitServiceImpl extends ServiceImpl<ShopProdUnitMapper, Sho
@Override
public ShopProdUnitDTO getShopProdUnitById(Long id) {
Long shopId = StpKit.USER.getLoginIdAsLong();
Long shopId = StpKit.USER.getShopId(0L);
return super.getOneAs(query().eq(ShopProdUnit::getId, id).eq(ShopProdUnit::getShopId, shopId), ShopProdUnitDTO.class);
}
@Override
public boolean addShopProdUnit(ShopProdUnitDTO dto) {
Long shopId = StpKit.USER.getLoginIdAsLong();
Long shopId = StpKit.USER.getShopId(0L);
boolean exists = super.exists(query().eq(ShopProdUnit::getName, dto.getName()).eq(ShopProdUnit::getShopId, shopId));
if (exists) {
throw new CzgException("单位名称已存在");
@ -79,7 +79,7 @@ public class ShopProdUnitServiceImpl extends ServiceImpl<ShopProdUnitMapper, Sho
@Override
public boolean updateShopProdUnit(ShopProdUnitDTO dto) {
Long shopId = StpKit.USER.getLoginIdAsLong();
Long shopId = StpKit.USER.getShopId(0L);
dto.setShopId(shopId);
boolean exists = super.exists(query().eq(ShopProdUnit::getName, dto.getName()).eq(ShopProdUnit::getShopId, shopId).ne(ShopProdUnit::getId, dto.getId()));
if (exists) {
@ -91,13 +91,13 @@ public class ShopProdUnitServiceImpl extends ServiceImpl<ShopProdUnitMapper, Sho
@Override
public boolean deleteShopProdUnit(Long id) {
Long shopId = StpKit.USER.getLoginIdAsLong();
Long shopId = StpKit.USER.getShopId(0L);
return super.remove(query().eq(ShopProdUnit::getId, id).eq(ShopProdUnit::getShopId, shopId));
}
@Override
public boolean disableShopProdUnit(Long id) {
Long shopId = StpKit.USER.getLoginIdAsLong();
Long shopId = StpKit.USER.getShopId(0L);
return UpdateChain.of(ShopProdUnit.class)
.set(ShopProdUnit::getStatus, StatusEnum.DISABLE.value())
.eq(ShopProdUnit::getId, id)
@ -107,7 +107,7 @@ public class ShopProdUnitServiceImpl extends ServiceImpl<ShopProdUnitMapper, Sho
@Override
public boolean enableShopProdUnit(Long id) {
Long shopId = StpKit.USER.getLoginIdAsLong();
Long shopId = StpKit.USER.getShopId(0L);
return UpdateChain.of(ShopProdUnit.class)
.set(ShopProdUnit::getStatus, StatusEnum.ENABLED.value())
.eq(ShopProdUnit::getId, id)

View File

@ -39,7 +39,7 @@ public class ShopProductSpecServiceImpl extends ServiceImpl<ShopProdSpecMapper,
if (StrUtil.isNotEmpty(param.getName())) {
queryWrapper.like(ShopProdSpec::getName, param.getName());
}
Long shopId = StpKit.USER.getLoginIdAsLong();
Long shopId = StpKit.USER.getShopId(0L);
queryWrapper.eq(ShopProdSpec::getShopId, shopId);
queryWrapper.orderBy(ShopProdSpec::getSort, true);
queryWrapper.orderBy(ShopProdSpec::getId, false);
@ -62,13 +62,13 @@ public class ShopProductSpecServiceImpl extends ServiceImpl<ShopProdSpecMapper,
@Override
public ShopProdSpecDTO getShopProdSpecById(Long id) {
Long shopId = StpKit.USER.getLoginIdAsLong();
Long shopId = StpKit.USER.getShopId(0L);
return super.getOneAs(query().eq(ShopProdSpec::getId, id).eq(ShopProdSpec::getShopId, shopId), ShopProdSpecDTO.class);
}
@Override
public boolean addShopProdSpec(ShopProdSpecDTO dto) {
Long shopId = StpKit.USER.getLoginIdAsLong();
Long shopId = StpKit.USER.getShopId(0L);
boolean exists = super.exists(query()
.eq(ShopProdSpec::getName, dto.getName())
.eq(ShopProdSpec::getPid, dto.getPid())
@ -98,7 +98,7 @@ public class ShopProductSpecServiceImpl extends ServiceImpl<ShopProdSpecMapper,
if (dto.getId().equals(dto.getPid())) {
throw new CzgException("上级规格不能为自身");
}
Long shopId = StpKit.USER.getLoginIdAsLong();
Long shopId = StpKit.USER.getShopId(0L);
dto.setShopId(shopId);
boolean exists = super.exists(query()
.eq(ShopProdSpec::getName, dto.getName())
@ -129,7 +129,7 @@ public class ShopProductSpecServiceImpl extends ServiceImpl<ShopProdSpecMapper,
@Override
public boolean deleteShopProdSpec(Long id) {
Long shopId = StpKit.USER.getLoginIdAsLong();
Long shopId = StpKit.USER.getShopId(0L);
return super.remove(query()
.where(SHOP_PROD_SPEC.SHOP_ID.eq(shopId)
.and(SHOP_PROD_SPEC.ID.eq(id).or(SHOP_PROD_SPEC.PIDS.like("," + id + ","))))
@ -138,7 +138,7 @@ public class ShopProductSpecServiceImpl extends ServiceImpl<ShopProdSpecMapper,
@Override
public boolean disableShopProdSpec(Long id) {
Long shopId = StpKit.USER.getLoginIdAsLong();
Long shopId = StpKit.USER.getShopId(0L);
return UpdateChain.of(ShopProdSpec.class)
.set(SHOP_PROD_SPEC.STATUS, StatusEnum.DISABLE.value())
.where(SHOP_PROD_SPEC.SHOP_ID.eq(shopId)
@ -147,7 +147,7 @@ public class ShopProductSpecServiceImpl extends ServiceImpl<ShopProdSpecMapper,
@Override
public boolean enableShopProdSpec(Long id) {
Long shopId = StpKit.USER.getLoginIdAsLong();
Long shopId = StpKit.USER.getShopId(0L);
return UpdateChain.of(ShopProdSpec.class)
.set(SHOP_PROD_SPEC.STATUS, StatusEnum.ENABLED.value())
.where(SHOP_PROD_SPEC.SHOP_ID.eq(shopId)

View File

@ -32,7 +32,7 @@ public class ShopVendorServiceImpl extends ServiceImpl<ShopVendorMapper, ShopVen
if (StrUtil.isNotEmpty(param.getName())) {
queryWrapper.like(ShopVendor::getName, param.getName());
}
Long shopId = StpKit.USER.getLoginIdAsLong();
Long shopId = StpKit.USER.getShopId(0L);
queryWrapper.eq(ShopVendor::getShopId, shopId);
queryWrapper.orderBy(ShopVendor::getSort, true);
queryWrapper.orderBy(ShopVendor::getId, false);
@ -54,13 +54,13 @@ public class ShopVendorServiceImpl extends ServiceImpl<ShopVendorMapper, ShopVen
@Override
public ShopVendorDTO getShopVendorById(Long id) {
Long shopId = StpKit.USER.getLoginIdAsLong();
Long shopId = StpKit.USER.getShopId(0L);
return super.getOneAs(query().eq(ShopVendor::getId, id).eq(ShopVendor::getShopId, shopId), ShopVendorDTO.class);
}
@Override
public boolean addShopVendor(ShopVendorDTO dto) {
Long shopId = StpKit.USER.getLoginIdAsLong();
Long shopId = StpKit.USER.getShopId(0L);
boolean exists = super.exists(query().eq(ShopVendor::getName, dto.getName()).eq(ShopVendor::getShopId, shopId));
if (exists) {
throw new CzgException("供应商已存在");
@ -73,7 +73,7 @@ public class ShopVendorServiceImpl extends ServiceImpl<ShopVendorMapper, ShopVen
@Override
public boolean updateShopVendor(ShopVendorDTO dto) {
Long shopId = StpKit.USER.getLoginIdAsLong();
Long shopId = StpKit.USER.getShopId(0L);
dto.setShopId(shopId);
boolean exists = super.exists(query().eq(ShopVendor::getName, dto.getName()).eq(ShopVendor::getShopId, shopId).ne(ShopVendor::getId, dto.getId()));
if (exists) {
@ -85,7 +85,7 @@ public class ShopVendorServiceImpl extends ServiceImpl<ShopVendorMapper, ShopVen
@Override
public boolean deleteShopVendor(Long id) {
Long shopId = StpKit.USER.getLoginIdAsLong();
Long shopId = StpKit.USER.getShopId(0L);
return UpdateChain.of(ShopVendor.class)
.set(ShopVendor::getIsDel, DeleteEnum.DELETED.value())
.eq(ShopVendor::getId, id)

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.czg.service.product.mapper.ConsInfoMapper">
</mapper>