科室名称重复修改

This commit is contained in:
zhangheng 2024-08-01 16:31:43 +08:00
parent d8a5b60d36
commit 2613872722
5 changed files with 93 additions and 46 deletions

View File

@ -105,7 +105,7 @@ public class DepartmentController extends BaseController {
@Log(title = "科室信息", businessType = BusinessType.INSERT)
@PostMapping("/add")
public AjaxResult add(@RequestBody Department department) {
return toAjax(departmentService.insertDepartment(department));
return departmentService.insertDepartment(department);
}
/**
@ -115,7 +115,7 @@ public class DepartmentController extends BaseController {
@Log(title = "科室信息", businessType = BusinessType.UPDATE)
@PutMapping("/edit")
public AjaxResult edit(@RequestBody Department department) {
return toAjax(departmentService.updateDepartment(department));
return departmentService.updateDepartment(department);
}
/**

View File

@ -145,4 +145,12 @@ public interface DepartmentMapper {
* @return 机构信息
*/
List<Department> selectDepartmentByParentId(Long[] id);
/**
* 根据上级机构id和科室名称查询数量
*
* @param department 科室
* @return int
*/
List<Department> selectDepartmentNameCount(Department department);
}

View File

@ -52,7 +52,7 @@ public interface IDepartmentService {
* @param department 科室信息
* @return 结果
*/
int insertDepartment(Department department);
AjaxResult insertDepartment(Department department);
/**
* 修改科室信息
@ -60,7 +60,7 @@ public interface IDepartmentService {
* @param department 科室信息
* @return 结果
*/
int updateDepartment(Department department);
AjaxResult updateDepartment(Department department);
/**
* 批量删除科室信息

View File

@ -19,18 +19,19 @@ import com.xinelu.manage.vo.department.DepartmentBaseVo;
import com.xinelu.manage.vo.department.DepartmentListVO;
import com.xinelu.manage.vo.department.DepartmentVO;
import com.xinelu.system.mapper.SysUserMapper;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
* 科室信息Service业务层处理
@ -111,14 +112,28 @@ public class DepartmentServiceImpl implements IDepartmentService {
* @return 结果
*/
@Override
public int insertDepartment(Department department) {
public AjaxResult insertDepartment(Department department) {
if (Objects.isNull(department.getParentDepartmentId())) {
department.setParentDepartmentId(0L);
}
department.setCreateTime(LocalDateTime.now());
department.setCreateBy(SecurityUtils.getUsername());
//根据上级机构id查询
List<Department> departmentList = departmentMapper.selectDepartmentNameCount(department);
if (CollectionUtils.isNotEmpty(departmentList)) {
//重名
List<Department> departmentName = departmentList.stream().filter(Objects::nonNull).filter(item -> Objects.nonNull(item.getDepartmentName()) && department.getDepartmentName().equals(item.getDepartmentName())).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(departmentName)) {
return AjaxResult.error("" + department.getHospitalAgencyName() + "下,已存在名称为" + department.getDepartmentName() + "的科室!");
}
//重编号
List<Department> departmentCode = departmentList.stream().filter(Objects::nonNull).filter(item -> Objects.nonNull(item.getDepartmentCode()) && department.getDepartmentCode().equals(item.getDepartmentName())).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(departmentCode)) {
return AjaxResult.error("" + department.getHospitalAgencyName() + "下,已存在科室编号为" + department.getDepartmentName() + "的科室!");
}
}
//department.setDepartmentCode(Constants.DEPARTMENT_CODE + generateSystemCodeUtil.generateSystemCode(Constants.DEPARTMENT_CODE));
return departmentMapper.insertDepartment(department);
return AjaxResult.success(departmentMapper.insertDepartment(department));
}
/**
@ -128,13 +143,28 @@ public class DepartmentServiceImpl implements IDepartmentService {
* @return 结果
*/
@Override
public int updateDepartment(Department department) {
public AjaxResult updateDepartment(Department department) {
//上级科室是自己本身取消上级科室
if (Objects.nonNull(department) && Objects.nonNull(department.getId()) && Objects.nonNull(department.getParentDepartmentId()) && department.getId().equals(department.getParentDepartmentId())) {
department.setParentDepartmentId(null);
}
//根据上级机构id查询
List<Department> departmentList = departmentMapper.selectDepartmentNameCount(department);
if (CollectionUtils.isNotEmpty(departmentList)) {
//重名
List<Department> departmentName = departmentList.stream().filter(Objects::nonNull).filter(item -> Objects.nonNull(item.getDepartmentName()) && department.getDepartmentName().equals(item.getDepartmentName()) && !department.getId().equals(item.getId())).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(departmentName)) {
return AjaxResult.error("" + department.getHospitalAgencyName() + "下,已存在名称为" + department.getDepartmentName() + "的科室!");
}
//重编号
List<Department> departmentCode = departmentList.stream().filter(Objects::nonNull).filter(item -> Objects.nonNull(item.getDepartmentCode()) && department.getDepartmentCode().equals(item.getDepartmentName()) && !department.getId().equals(item.getId())).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(departmentCode)) {
return AjaxResult.error("" + department.getHospitalAgencyName() + "下,已存在科室编号为" + department.getDepartmentName() + "的科室!");
}
}
department.setUpdateBy(SecurityUtils.getUsername());
department.setUpdateTime(LocalDateTime.now());
return departmentMapper.updateDepartmentById(department);
return AjaxResult.success(departmentMapper.updateDepartmentById(department));
}
/**
@ -245,9 +275,9 @@ public class DepartmentServiceImpl implements IDepartmentService {
return AjaxResult.error("当前科室电话:" + department.getDepartmentPhone() + " 格式不正确,请重新录入!");
}
List<String> departmentName = importDataList.stream().filter(item -> StringUtils.isNotBlank(item.getDepartmentName())).map(Department::getDepartmentName).distinct().collect(Collectors.toList());
//根据名称查询护理站基本信息
//根据名称查询科室基本信息
List<Department> allDepartment = departmentMapper.getAllDepartmentInfo(departmentName);
//做差集去除数据库中已经存在的护理站信息
//做差集去除数据库中已经存在的科室信息
List<Department> subtractList = new ArrayList<>(CollectionUtils.subtract(importDataList, allDepartment));
if (CollectionUtils.isEmpty(subtractList)) {
return AjaxResult.success();

View File

@ -624,4 +624,13 @@
#{id}
</foreach>
</select>
<select id="selectDepartmentNameCount" resultType="com.xinelu.manage.domain.department.Department" resultMap="DepartmentResult">
<include refid="selectDepartmentVo"/>
<where>
<if test="hospitalAgencyId != null ">
and hospital_agency_id =#{hospitalAgencyId}
</if>
</where>
</select>
</mapper>