商品模块代码提交
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
package com.czg.service.product.mapper;
|
||||
|
||||
import com.czg.product.entity.ShopVendor;
|
||||
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 ShopVendorMapper extends BaseMapper<ShopVendor> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package com.czg.service.product.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.czg.enums.DeleteEnum;
|
||||
import com.czg.exception.CzgException;
|
||||
import com.czg.product.dto.ShopVendorDTO;
|
||||
import com.czg.product.entity.ShopVendor;
|
||||
import com.czg.product.service.ShopVendorService;
|
||||
import com.czg.sa.StpKit;
|
||||
import com.czg.service.product.mapper.ShopVendorMapper;
|
||||
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;
|
||||
|
||||
/**
|
||||
* 供应商
|
||||
*
|
||||
* @author Tankaikai tankaikai@aliyun.com
|
||||
* @since 1.0 2025-02-20
|
||||
*/
|
||||
@Service
|
||||
public class ShopVendorServiceImpl extends ServiceImpl<ShopVendorMapper, ShopVendor> implements ShopVendorService {
|
||||
|
||||
private QueryWrapper buildQueryWrapper(ShopVendorDTO param) {
|
||||
QueryWrapper queryWrapper = PageUtil.buildSortQueryWrapper();
|
||||
if (StrUtil.isNotEmpty(param.getName())) {
|
||||
queryWrapper.like(ShopVendor::getName, param.getName());
|
||||
}
|
||||
Long shopId = StpKit.USER.getLoginIdAsLong();
|
||||
queryWrapper.eq(ShopVendor::getShopId, shopId);
|
||||
queryWrapper.orderBy(ShopVendor::getSort, true);
|
||||
queryWrapper.orderBy(ShopVendor::getId, false);
|
||||
return queryWrapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<ShopVendorDTO> getShopVendorPage(ShopVendorDTO param) {
|
||||
QueryWrapper queryWrapper = buildQueryWrapper(param);
|
||||
return super.pageAs(PageUtil.buildPage(), queryWrapper, ShopVendorDTO.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ShopVendorDTO> getShopVendorList(ShopVendorDTO param) {
|
||||
QueryWrapper queryWrapper = buildQueryWrapper(param);
|
||||
queryWrapper.eq(ShopVendor::getIsDel, DeleteEnum.NORMAL.value());
|
||||
return super.listAs(queryWrapper, ShopVendorDTO.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ShopVendorDTO getShopVendorById(Long id) {
|
||||
Long shopId = StpKit.USER.getLoginIdAsLong();
|
||||
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();
|
||||
boolean exists = super.exists(query().eq(ShopVendor::getName, dto.getName()).eq(ShopVendor::getShopId, shopId));
|
||||
if (exists) {
|
||||
throw new CzgException("供应商已存在");
|
||||
}
|
||||
ShopVendor entity = BeanUtil.copyProperties(dto, ShopVendor.class);
|
||||
entity.setIsDel(DeleteEnum.NORMAL.value());
|
||||
entity.setShopId(shopId);
|
||||
return super.save(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateShopVendor(ShopVendorDTO dto) {
|
||||
Long shopId = StpKit.USER.getLoginIdAsLong();
|
||||
dto.setShopId(shopId);
|
||||
boolean exists = super.exists(query().eq(ShopVendor::getName, dto.getName()).eq(ShopVendor::getShopId, shopId).ne(ShopVendor::getId, dto.getId()));
|
||||
if (exists) {
|
||||
throw new CzgException("供应商已存在");
|
||||
}
|
||||
ShopVendor entity = BeanUtil.copyProperties(dto, ShopVendor.class);
|
||||
return super.updateById(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteShopVendor(Long id) {
|
||||
Long shopId = StpKit.USER.getLoginIdAsLong();
|
||||
return UpdateChain.of(ShopVendor.class)
|
||||
.set(ShopVendor::getIsDel, DeleteEnum.DELETED.value())
|
||||
.eq(ShopVendor::getId, id)
|
||||
.eq(ShopVendor::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.ShopVendorMapper">
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user