|
@@ -17,10 +17,13 @@ import org.apache.shiro.SecurityUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Propagation;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Service("departmentService")
|
|
|
public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Department> implements DepartmentService {
|
|
@@ -75,10 +78,15 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
|
|
@Override
|
|
|
@Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
|
|
|
public void addDepartment(DepartmentRequest departmentRequest) {
|
|
|
- // 查询所有的科室信息
|
|
|
-// baseMapper.selectList(new QueryWrapper<Department>().lambda().eq())
|
|
|
User user = (User) SecurityUtils.getSubject().getPrincipal();
|
|
|
Integer hospId = user.getHospId();
|
|
|
+ // 查询所有的科室信息
|
|
|
+ List<Department> departmentList = baseMapper.selectList(new QueryWrapper<Department>().lambda().eq(Department::getHospId, hospId));
|
|
|
+ Map<String, List<Department>> map =
|
|
|
+ departmentList.stream().collect(Collectors.groupingBy(Department::getDepartmentCode));
|
|
|
+ if (!CollectionUtils.isEmpty(map.get(departmentRequest.getDepartmentCode()))){
|
|
|
+ throw new CostException(500,"代码"+departmentRequest.getDepartmentCode()+"已存在");
|
|
|
+ }
|
|
|
departmentRequest.setHospId(hospId);
|
|
|
Department department = BeanUtil.convertObj(departmentRequest, Department.class);
|
|
|
department.setId(null);
|