商品模块代码提交
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
package com.czg.service.product.mapper;
|
||||
|
||||
import com.czg.product.entity.ConsGroup;
|
||||
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 ConsGroupMapper extends BaseMapper<ConsGroup> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.czg.service.product.mapper;
|
||||
|
||||
import com.czg.product.entity.ConsGroupRelation;
|
||||
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 ConsGroupRelationMapper extends BaseMapper<ConsGroupRelation> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.czg.service.product.service.impl;
|
||||
|
||||
import com.czg.product.entity.ConsGroupRelation;
|
||||
import com.czg.product.service.ConsGroupRelationService;
|
||||
import com.czg.service.product.mapper.ConsGroupRelationMapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 耗材分组关联关系
|
||||
*
|
||||
* @author Tankaikai tankaikai@aliyun.com
|
||||
* @since 1.0 2025-02-20
|
||||
*/
|
||||
@Service
|
||||
public class ConsGroupRelationServiceImpl extends ServiceImpl<ConsGroupRelationMapper, ConsGroupRelation> implements ConsGroupRelationService {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
package com.czg.service.product.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
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.entity.ConsGroup;
|
||||
import com.czg.product.entity.ConsGroupRelation;
|
||||
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.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.util.List;
|
||||
|
||||
/**
|
||||
* 耗材分组
|
||||
*
|
||||
* @author Tankaikai tankaikai@aliyun.com
|
||||
* @since 1.0 2025-02-20
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Service
|
||||
public class ConsGroupServiceImpl extends ServiceImpl<ConsGroupMapper, ConsGroup> implements ConsGroupService {
|
||||
|
||||
private final ConsGroupRelationMapper consGroupRelationMapper;
|
||||
|
||||
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();
|
||||
queryWrapper.eq(ConsGroup::getShopId, shopId);
|
||||
queryWrapper.orderBy(ConsGroup::getId, false);
|
||||
return queryWrapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<ConsGroupDTO> getConsGroupPage(ConsGroupDTO param) {
|
||||
QueryWrapper queryWrapper = buildQueryWrapper(param);
|
||||
return super.pageAs(PageUtil.buildPage(), queryWrapper, ConsGroupDTO.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ConsGroupDTO> getConsGroupList(ConsGroupDTO param) {
|
||||
QueryWrapper queryWrapper = buildQueryWrapper(param);
|
||||
queryWrapper.eq(ConsGroup::getStatus, StatusEnum.ENABLED.value());
|
||||
return super.listAs(queryWrapper, ConsGroupDTO.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConsGroupDTO getConsGroupById(Long id) {
|
||||
Long shopId = StpKit.USER.getLoginIdAsLong();
|
||||
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);
|
||||
return dto;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean addConsGroup(ConsGroupDTO dto) {
|
||||
Long shopId = StpKit.USER.getLoginIdAsLong();
|
||||
boolean exists = super.exists(query().eq(ConsGroup::getName, dto.getName()).eq(ConsGroup::getShopId, shopId));
|
||||
if (exists) {
|
||||
throw new CzgException("耗材分组已存在");
|
||||
}
|
||||
ConsGroup entity = BeanUtil.copyProperties(dto, ConsGroup.class);
|
||||
entity.setStatus(StatusEnum.ENABLED.value());
|
||||
entity.setShopId(shopId);
|
||||
super.save(entity);
|
||||
List<Long> consIds = dto.getConsIds();
|
||||
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);
|
||||
consGroupRelationMapper.insert(relation);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateConsGroup(ConsGroupDTO dto) {
|
||||
Long shopId = StpKit.USER.getLoginIdAsLong();
|
||||
dto.setShopId(shopId);
|
||||
boolean exists = super.exists(query().eq(ConsGroup::getName, dto.getName()).eq(ConsGroup::getShopId, shopId).ne(ConsGroup::getId, dto.getId()));
|
||||
if (exists) {
|
||||
throw new CzgException("耗材分组已存在");
|
||||
}
|
||||
ConsGroup entity = BeanUtil.copyProperties(dto, ConsGroup.class);
|
||||
super.updateById(entity);
|
||||
List<Long> consIds = dto.getConsIds();
|
||||
if (CollUtil.isEmpty(consIds)) {
|
||||
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);
|
||||
consGroupRelationMapper.insert(relation);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteConsGroup(Long id) {
|
||||
Long shopId = StpKit.USER.getLoginIdAsLong();
|
||||
return super.remove(query().eq(ConsGroup::getId, id).eq(ConsGroup::getShopId, shopId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean disableConsGroup(Long id) {
|
||||
Long shopId = StpKit.USER.getLoginIdAsLong();
|
||||
return UpdateChain.of(ConsGroup.class)
|
||||
.set(ConsGroup::getStatus, StatusEnum.DISABLE.value())
|
||||
.eq(ConsGroup::getId, id)
|
||||
.eq(ConsGroup::getShopId, shopId)
|
||||
.update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enableConsGroup(Long id) {
|
||||
Long shopId = StpKit.USER.getLoginIdAsLong();
|
||||
return UpdateChain.of(ConsGroup.class)
|
||||
.set(ConsGroup::getStatus, StatusEnum.ENABLED.value())
|
||||
.eq(ConsGroup::getId, id)
|
||||
.eq(ConsGroup::getShopId, shopId)
|
||||
.update();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.ConsGroupMapper">
|
||||
|
||||
</mapper>
|
||||
@@ -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.ConsGroupRelationMapper">
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user