商品模块代码提交
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
package com.czg.service.product.mapper;
|
||||
|
||||
import com.czg.product.entity.ProdConsRelation;
|
||||
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 ProdConsRelationMapper extends BaseMapper<ProdConsRelation> {
|
||||
|
||||
}
|
||||
@@ -3,12 +3,14 @@ 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.CrudEnum;
|
||||
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.param.ConsSubUnitParam;
|
||||
import com.czg.product.service.ConsInfoService;
|
||||
import com.czg.sa.StpKit;
|
||||
import com.czg.service.product.mapper.ConsGroupRelationMapper;
|
||||
@@ -153,4 +155,26 @@ public class ConsInfoServiceImpl extends ServiceImpl<ConsInfoMapper, ConsInfo> i
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void modifySubUnit(ConsSubUnitParam param) {
|
||||
Long shopId = StpKit.USER.getShopId(0L);
|
||||
if (CrudEnum.ADD.value().equals(param.getModifyFlag())) {
|
||||
UpdateChain.of(ConsInfo.class)
|
||||
.set(ConsInfo::getConUnitTwo, param.getConUnitTwo())
|
||||
.set(ConsInfo::getConUnitTwoConvert, param.getConUnitTwoConvert())
|
||||
.set(ConsInfo::getDefaultUnit, param.getDefaultUnit())
|
||||
.eq(ConsInfo::getId, param.getId())
|
||||
.eq(ConsInfo::getShopId, shopId)
|
||||
.update();
|
||||
} else if (CrudEnum.DELETE.value().equals(param.getModifyFlag())) {
|
||||
UpdateChain.of(ConsInfo.class)
|
||||
.set(ConsInfo::getConUnitTwo, null)
|
||||
.set(ConsInfo::getConUnitTwoConvert, null)
|
||||
.set(ConsInfo::getDefaultUnit, null)
|
||||
.eq(ConsInfo::getId, param.getId())
|
||||
.eq(ConsInfo::getShopId, shopId)
|
||||
.update();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package com.czg.service.product.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.czg.exception.CzgException;
|
||||
import com.czg.product.dto.ProdConsBindDTO;
|
||||
import com.czg.product.dto.ProdConsRelationDTO;
|
||||
import com.czg.product.entity.ProdConsRelation;
|
||||
import com.czg.product.entity.Product;
|
||||
import com.czg.product.service.ProdConsRelationService;
|
||||
import com.czg.sa.StpKit;
|
||||
import com.czg.service.product.mapper.ProdConsRelationMapper;
|
||||
import com.czg.service.product.mapper.ProductMapper;
|
||||
import com.czg.utils.PageUtil;
|
||||
import com.czg.validator.ValidatorUtil;
|
||||
import com.czg.validator.group.DefaultGroup;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
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
|
||||
*/
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class ProdConsRelationServiceImpl extends ServiceImpl<ProdConsRelationMapper, ProdConsRelation> implements ProdConsRelationService {
|
||||
|
||||
private final ProductMapper productMapper;
|
||||
|
||||
private QueryWrapper buildQueryWrapper(ProdConsRelationDTO param) {
|
||||
QueryWrapper queryWrapper = PageUtil.buildSortQueryWrapper();
|
||||
Long shopId = StpKit.USER.getLoginIdAsLong();
|
||||
queryWrapper.eq(ProdConsRelation::getShopId, shopId);
|
||||
queryWrapper.orderBy(ProdConsRelation::getId, false);
|
||||
return queryWrapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ProdConsRelationDTO> getProdConsRelationList(ProdConsRelationDTO param) {
|
||||
QueryWrapper queryWrapper = buildQueryWrapper(param);
|
||||
return super.listAs(queryWrapper, ProdConsRelationDTO.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean saveProdConsRelation(ProdConsBindDTO dto) {
|
||||
Long shopId = StpKit.USER.getLoginIdAsLong();
|
||||
long count = productMapper.selectCountByQuery(query().eq(Product::getShopId, shopId).eq(Product::getId, dto.getId()));
|
||||
if (count == 0) {
|
||||
throw new CzgException("商品不存在");
|
||||
}
|
||||
super.remove(query().eq(ProdConsRelation::getShopId, shopId).eq(ProdConsRelation::getProductId, dto.getId()));
|
||||
if (CollUtil.isEmpty(dto.getConsList())) {
|
||||
return true;
|
||||
}
|
||||
ValidatorUtil.validateEntityList(dto.getConsList(), DefaultGroup.class);
|
||||
List<ProdConsRelationDTO> consList = dto.getConsList();
|
||||
for (ProdConsRelationDTO con : consList) {
|
||||
con.setShopId(shopId);
|
||||
}
|
||||
List<Long> list = consList.stream().map(ProdConsRelationDTO::getProductId).distinct().toList();
|
||||
if (CollUtil.isNotEmpty(list) && list.size() > 1) {
|
||||
throw new CzgException("只能绑定同一商品下的耗材");
|
||||
}
|
||||
if (!dto.getId().equals(list.getFirst())) {
|
||||
throw new CzgException("非法操作,绑定关系商品不一致");
|
||||
}
|
||||
List<ProdConsRelation> entityList = BeanUtil.copyToList(consList, ProdConsRelation.class);
|
||||
return super.saveBatch(entityList);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.ProdConsRelationMapper">
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user