|
@@ -1,6 +1,9 @@
|
|
|
package com.management.platform.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.management.platform.config.exception.CustomServiceException;
|
|
|
import com.management.platform.entity.ProdCategory;
|
|
|
import com.management.platform.entity.Product;
|
|
|
import com.management.platform.entity.User;
|
|
@@ -8,17 +11,17 @@ import com.management.platform.mapper.ProdCategoryMapper;
|
|
|
import com.management.platform.mapper.ProductMapper;
|
|
|
import com.management.platform.mapper.UserMapper;
|
|
|
import com.management.platform.service.ProdCategoryService;
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.management.platform.util.HttpRespMsg;
|
|
|
import io.micrometer.core.instrument.util.StringUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
|
- * 服务实现类
|
|
|
+ * 服务实现类
|
|
|
* </p>
|
|
|
*
|
|
|
* @author Seyason
|
|
@@ -34,52 +37,55 @@ public class ProdCategoryServiceImpl extends ServiceImpl<ProdCategoryMapper, Pro
|
|
|
private ProductMapper productMapper;
|
|
|
|
|
|
@Override
|
|
|
- public HttpRespMsg saveOrUpdateInfo(ProdCategory prodCategory, HttpServletRequest request) {
|
|
|
+ public HttpRespMsg saveOrUpdateInfo(ProdCategory prodCategory, HttpServletRequest request){
|
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
|
|
|
|
String token = request.getHeader("Token");
|
|
|
User user = userMapper.selectById(token);
|
|
|
prodCategory.setCompanyId(user.getCompanyId());
|
|
|
|
|
|
- Integer count = prodCategoryMapper.selectCount(new LambdaQueryWrapper<ProdCategory>().eq(StringUtils.isNotBlank(prodCategory.getName()), ProdCategory::getName, prodCategory.getName()));
|
|
|
+ ProdCategory prodCategory1 = prodCategoryMapper
|
|
|
+ .selectOne(new LambdaQueryWrapper<ProdCategory>()
|
|
|
+ .eq(StringUtils.isNotBlank(prodCategory.getName()), ProdCategory::getName, prodCategory.getName()));
|
|
|
|
|
|
- if(count==0){
|
|
|
- if(prodCategory.getId()==null){
|
|
|
- prodCategoryMapper.insert(prodCategory);
|
|
|
- }else{
|
|
|
- prodCategoryMapper.updateById(prodCategory);
|
|
|
- }
|
|
|
+ if (ObjectUtil.isNotNull(prodCategory1) && !prodCategory1.getId().equals(prodCategory.getId())) {
|
|
|
+ throw new CustomServiceException("分类已存在");
|
|
|
+ }
|
|
|
|
|
|
- msg.setData(prodCategory);
|
|
|
- }else{
|
|
|
- msg.setError("name is repeat !");
|
|
|
+ if (prodCategory.getId() == null) {
|
|
|
+ prodCategoryMapper.insert(prodCategory);
|
|
|
+ } else {
|
|
|
+ prodCategoryMapper.updateById(prodCategory);
|
|
|
}
|
|
|
|
|
|
+ msg.setData(prodCategory);
|
|
|
+
|
|
|
+
|
|
|
return msg;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public HttpRespMsg delete(Integer id, HttpServletRequest request) {
|
|
|
- HttpRespMsg msg=new HttpRespMsg();
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
String token = request.getHeader("Token");
|
|
|
User user = userMapper.selectById(token);
|
|
|
|
|
|
Integer count = productMapper.selectCount(
|
|
|
new LambdaQueryWrapper<Product>()
|
|
|
.eq(id != null, Product::getCategoryId, id)
|
|
|
- .eq(user.getCompanyId()!=null,Product::getCompanyId,user.getCompanyId())
|
|
|
+ .eq(user.getCompanyId() != null, Product::getCompanyId, user.getCompanyId())
|
|
|
);
|
|
|
|
|
|
|
|
|
- if(count==0){
|
|
|
+ if (count == 0) {
|
|
|
|
|
|
- if(prodCategoryMapper.selectCount(new LambdaQueryWrapper<ProdCategory>().eq(user.getCompanyId()!=null,ProdCategory::getCompanyId,user.getCompanyId()))==1){
|
|
|
- msg.setError("产品分类数量不能低于1");
|
|
|
- }else{
|
|
|
- prodCategoryMapper.deleteById(id);
|
|
|
- }
|
|
|
+ if (prodCategoryMapper.selectCount(new LambdaQueryWrapper<ProdCategory>().eq(user.getCompanyId() != null, ProdCategory::getCompanyId, user.getCompanyId())) == 1) {
|
|
|
+ msg.setError("产品分类数量不能低于1");
|
|
|
+ } else {
|
|
|
+ prodCategoryMapper.deleteById(id);
|
|
|
+ }
|
|
|
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
msg.setError("已有产品为此分类,无法删除");
|
|
|
}
|
|
|
|