提交 5dfd28df authored 作者: zjm's avatar zjm

fix(单位模块): 修改组、区域、库房单位名称可以重复的bug

修改组、区域、库房单位名称可以重复的bug
上级 3aec3368
......@@ -76,4 +76,11 @@ public class AreaExhibitionCache {
map.put(2,idMap.get(4).getAreaName());
return map;
}
/**
* 根据单位名称查询是否存在
*/
public boolean isNotName(String name){
return new ArrayList<>(idMap.values()).stream().noneMatch(areaExhibition -> areaExhibition.getAreaName().equals(name));
}
}
......@@ -8,4 +8,6 @@ import java.util.List;
public interface GroupDao extends JpaRepository<Groups, Integer>, JpaSpecificationExecutor<Groups> {
List<Groups> findAllByType(Integer type);
boolean existsByName(String name);
}
package com.tykj.dev.device.user.subject.dao;
import com.tykj.dev.device.user.subject.entity.UnitStoreLocation;
import org.springframework.context.annotation.Bean;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
......@@ -10,4 +11,6 @@ public interface UnitStoreLocationDao extends JpaRepository<UnitStoreLocation, I
List<UnitStoreLocation> findAllByUnitIdAndTypeName(Integer unitId,String typeName);
List<UnitStoreLocation> findAllByIdIn(List<Integer> ids);
boolean existsByStoreNameAndUnitId(String name,Integer unitId);
}
......@@ -8,6 +8,7 @@ import com.tykj.dev.device.user.subject.entity.Units;
import com.tykj.dev.device.user.subject.service.AreaExhibitionService;
import com.tykj.dev.misc.exception.ApiException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import java.util.Comparator;
......@@ -56,6 +57,9 @@ public class AreaExhibitionServiceImpl implements AreaExhibitionService {
@Override
public AreaExhibition save(AreaExhibition areaExhibition) {
if (!areaExhibitionCache.isNotName(areaExhibition.getAreaName())){
throw new ApiException(ResponseEntity.status(20020).body("区域名称重复"));
}
if (areaExhibition.getId()==null){
areaExhibition.setOrders(areaExhibitionCache.findAll().size()+1);
}else {
......
......@@ -31,6 +31,9 @@ public class GroupServiceImpl implements GroupService {
UnitsService unitsService;
@Override
public void saveGroup(Groups group) {
if (groupDao.existsByName(group.getName())){
throw new ApiException(ResponseEntity.status(20020).body("组名称重复"));
}
StringBuffer stringBuffer=new StringBuffer();
group.getMembers().forEach(
integer -> stringBuffer.append(",").append(integer)
......
......@@ -5,7 +5,9 @@ import com.tykj.dev.device.user.subject.dao.UnitStoreLocationDao;
import com.tykj.dev.device.user.subject.entity.UnitStoreLocation;
import com.tykj.dev.device.user.subject.service.UnitStoreLocationService;
import com.tykj.dev.misc.base.BaseEntity;
import com.tykj.dev.misc.exception.ApiException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import java.util.Comparator;
......@@ -49,6 +51,9 @@ public class UnitStoreLocationServiceImpl implements UnitStoreLocationService {
@Override
public UnitStoreLocation save(UnitStoreLocation unitStoreLocation) {
if (unitStoreLocationDao.existsByStoreNameAndUnitId(unitStoreLocation.getStoreName(),unitStoreLocation.getUnitId())){
throw new ApiException(ResponseEntity.status(20020).body("区域名称重复"));
}
return unitStoreLocationDao.save(unitStoreLocation);
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论