package com.qianwen.smartman.modules.smis.service.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import java.lang.invoke.SerializedLambda;
|
import java.util.List;
|
import com.qianwen.smartman.common.utils.MessageUtils;
|
import com.qianwen.core.log.exception.ServiceException;
|
import com.qianwen.core.mp.base.BaseServiceImpl;
|
import com.qianwen.core.tool.utils.Func;
|
import com.qianwen.smartman.modules.smis.entity.Product;
|
import com.qianwen.smartman.modules.smis.entity.ProductType;
|
import com.qianwen.smartman.modules.smis.mapper.ProductMapper;
|
import com.qianwen.smartman.modules.smis.mapper.ProductTypeMapper;
|
import com.qianwen.smartman.modules.smis.service.IProductTypeService;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
@Transactional(rollbackFor = {Exception.class})
|
@Service
|
public class ProductTypeServiceImpl extends BaseServiceImpl<ProductTypeMapper, ProductType> implements IProductTypeService {
|
private final ProductMapper productMapper;
|
|
|
public ProductTypeServiceImpl(final ProductMapper productMapper) {
|
this.productMapper = productMapper;
|
}
|
|
|
public Boolean removeIds(List<Long> ids) {
|
ids.forEach(id -> {
|
Long count = this.productMapper.selectCount(Wrappers.<Product>lambdaQuery().eq(Product::getTypeId, id));
|
/*
|
Long count = this.productMapper.selectCount((Wrapper) Wrappers.lambdaQuery().eq((v0) -> {
|
return v0.getTypeId();
|
}, id));*/
|
if (count.longValue() > 0) {
|
throw new ServiceException(MessageUtils.message("cps.product.type.not.delete", new Object[0]));
|
}
|
});
|
return Boolean.valueOf(removeByIds(ids));
|
}
|
|
|
public void insertOrUpdate(ProductType productType) {
|
checkProductTypeName(productType);
|
saveOrUpdate(productType);
|
}
|
|
private void checkProductTypeName(ProductType productType) {
|
long count = count(Wrappers.<ProductType>lambdaQuery().ne(Func.isNotEmpty(productType.getId()), ProductType::getId, productType.getId())
|
.eq(ProductType::getName, productType.getName()));
|
/*
|
long count = count((Wrapper) Wrappers.lambdaQuery().ne(Func.isNotEmpty(productType.getId()), (v0) -> {
|
return v0.getId();
|
}, productType.getId()).eq((v0) -> {
|
return v0.getName();
|
}, productType.getName()));*/
|
if (count > 0) {
|
throw new ServiceException(MessageUtils.message("cps.product.type.name.exists", new Object[0]));
|
}
|
}
|
}
|