科室名称重复修改

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) @Log(title = "科室信息", businessType = BusinessType.INSERT)
@PostMapping("/add") @PostMapping("/add")
public AjaxResult add(@RequestBody Department department) { 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) @Log(title = "科室信息", businessType = BusinessType.UPDATE)
@PutMapping("/edit") @PutMapping("/edit")
public AjaxResult edit(@RequestBody Department department) { 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 机构信息 * @return 机构信息
*/ */
List<Department> selectDepartmentByParentId(Long[] id); 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 科室信息 * @param department 科室信息
* @return 结果 * @return 结果
*/ */
int insertDepartment(Department department); AjaxResult insertDepartment(Department department);
/** /**
* 修改科室信息 * 修改科室信息
@ -60,7 +60,7 @@ public interface IDepartmentService {
* @param department 科室信息 * @param department 科室信息
* @return 结果 * @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.DepartmentListVO;
import com.xinelu.manage.vo.department.DepartmentVO; import com.xinelu.manage.vo.department.DepartmentVO;
import com.xinelu.system.mapper.SysUserMapper; 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.collections4.CollectionUtils;
import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; 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业务层处理 * 科室信息Service业务层处理
@ -46,8 +47,8 @@ public class DepartmentServiceImpl implements IDepartmentService {
private RegexUtil regexUtil; private RegexUtil regexUtil;
@Resource @Resource
private SysUserMapper sysUserMapper; private SysUserMapper sysUserMapper;
@Resource @Resource
private AgencyMapper agencyMapper; private AgencyMapper agencyMapper;
@Resource @Resource
private GenerateSystemCodeUtil generateSystemCodeUtil; private GenerateSystemCodeUtil generateSystemCodeUtil;
@ -111,14 +112,28 @@ public class DepartmentServiceImpl implements IDepartmentService {
* @return 结果 * @return 结果
*/ */
@Override @Override
public int insertDepartment(Department department) { public AjaxResult insertDepartment(Department department) {
if (Objects.isNull(department.getParentDepartmentId())) { if (Objects.isNull(department.getParentDepartmentId())) {
department.setParentDepartmentId(0L); department.setParentDepartmentId(0L);
} }
department.setCreateTime(LocalDateTime.now()); department.setCreateTime(LocalDateTime.now());
department.setCreateBy(SecurityUtils.getUsername()); 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)); //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 结果 * @return 结果
*/ */
@Override @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())) { if (Objects.nonNull(department) && Objects.nonNull(department.getId()) && Objects.nonNull(department.getParentDepartmentId()) && department.getId().equals(department.getParentDepartmentId())) {
department.setParentDepartmentId(null); 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.setUpdateBy(SecurityUtils.getUsername());
department.setUpdateTime(LocalDateTime.now()); 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() + " 格式不正确,请重新录入!"); return AjaxResult.error("当前科室电话:" + department.getDepartmentPhone() + " 格式不正确,请重新录入!");
} }
List<String> departmentName = importDataList.stream().filter(item -> StringUtils.isNotBlank(item.getDepartmentName())).map(Department::getDepartmentName).distinct().collect(Collectors.toList()); 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> allDepartment = departmentMapper.getAllDepartmentInfo(departmentName);
//做差集去除数据库中已经存在的护理站信息 //做差集去除数据库中已经存在的科室信息
List<Department> subtractList = new ArrayList<>(CollectionUtils.subtract(importDataList, allDepartment)); List<Department> subtractList = new ArrayList<>(CollectionUtils.subtract(importDataList, allDepartment));
if (CollectionUtils.isEmpty(subtractList)) { if (CollectionUtils.isEmpty(subtractList)) {
return AjaxResult.success(); return AjaxResult.success();
@ -279,9 +309,9 @@ public class DepartmentServiceImpl implements IDepartmentService {
@DataScope(agencyAlias = "d", deptAlias = "sp") @DataScope(agencyAlias = "d", deptAlias = "sp")
@Override @Override
public DepartmentBaseVo selectListServicePackageNum(DepartmentDTO departmentDto) { public DepartmentBaseVo selectListServicePackageNum(DepartmentDTO departmentDto) {
Agency agency = agencyMapper.selectAgencyById(departmentDto.getHospitalAgencyId()); Agency agency = agencyMapper.selectAgencyById(departmentDto.getHospitalAgencyId());
List<DepartmentVO> departmentVOList = departmentMapper.selectListServicePackageNum(departmentDto); List<DepartmentVO> departmentVOList = departmentMapper.selectListServicePackageNum(departmentDto);
return DepartmentBaseVo.builder().hospitalAgencyName(ObjectUtils.isEmpty(agency) ? "" : agency.getAgencyName()) return DepartmentBaseVo.builder().hospitalAgencyName(ObjectUtils.isEmpty(agency) ? "" : agency.getAgencyName())
.deptNumList(departmentVOList).build(); .deptNumList(departmentVOList).build();
} }
} }

View File

@ -496,76 +496,76 @@
update department update department
<trim prefix="SET" suffixOverrides=","> <trim prefix="SET" suffixOverrides=",">
<if test="parentDepartmentId != null">parent_department_id = <if test="parentDepartmentId != null">parent_department_id =
#{parentDepartmentId}, #{parentDepartmentId},
</if> </if>
<if test="hospitalAgencyId != null">hospital_agency_id = <if test="hospitalAgencyId != null">hospital_agency_id =
#{hospitalAgencyId}, #{hospitalAgencyId},
</if> </if>
<if test="hospitalAgencyName != null">hospital_agency_name = <if test="hospitalAgencyName != null">hospital_agency_name =
#{hospitalAgencyName}, #{hospitalAgencyName},
</if> </if>
<if test="departmentName != null">department_name = <if test="departmentName != null">department_name =
#{departmentName}, #{departmentName},
</if> </if>
<if test="departmentCode != null">department_code = <if test="departmentCode != null">department_code =
#{departmentCode}, #{departmentCode},
</if> </if>
<if test="departmentType != null">department_type = <if test="departmentType != null">department_type =
#{departmentType}, #{departmentType},
</if> </if>
<if test="departmentAbbreviation != null">department_abbreviation = <if test="departmentAbbreviation != null">department_abbreviation =
#{departmentAbbreviation}, #{departmentAbbreviation},
</if> </if>
<if test="departmentPersonId != null">department_person_id = <if test="departmentPersonId != null">department_person_id =
#{departmentPersonId}, #{departmentPersonId},
</if> </if>
<if test="departmentPersonName != null">department_person_name = <if test="departmentPersonName != null">department_person_name =
#{departmentPersonName}, #{departmentPersonName},
</if> </if>
<if test="nodeType != null">node_type = <if test="nodeType != null">node_type =
#{nodeType}, #{nodeType},
</if> </if>
<if test="provideServiceCategory != null">provide_service_category = <if test="provideServiceCategory != null">provide_service_category =
#{provideServiceCategory}, #{provideServiceCategory},
</if> </if>
<if test="subdivisionCategoryId != null">subdivision_category_id = <if test="subdivisionCategoryId != null">subdivision_category_id =
#{subdivisionCategoryId}, #{subdivisionCategoryId},
</if> </if>
<if test="subdivisionCategoryName != null">subdivision_category_name = <if test="subdivisionCategoryName != null">subdivision_category_name =
#{subdivisionCategoryName}, #{subdivisionCategoryName},
</if> </if>
<if test="normDepartmentCompareId != null">norm_department_compare_id = <if test="normDepartmentCompareId != null">norm_department_compare_id =
#{normDepartmentCompareId}, #{normDepartmentCompareId},
</if> </if>
<if test="normDepartmentCompareName != null">norm_department_compare_name = <if test="normDepartmentCompareName != null">norm_department_compare_name =
#{normDepartmentCompareName}, #{normDepartmentCompareName},
</if> </if>
<if test="prepareBedsCount != null">prepare_beds_count = <if test="prepareBedsCount != null">prepare_beds_count =
#{prepareBedsCount}, #{prepareBedsCount},
</if> </if>
<if test="departmentPhone != null">department_phone = <if test="departmentPhone != null">department_phone =
#{departmentPhone}, #{departmentPhone},
</if> </if>
<if test="departmentMail != null">department_mail = <if test="departmentMail != null">department_mail =
#{departmentMail}, #{departmentMail},
</if> </if>
<if test="establishDate != null">establish_date = <if test="establishDate != null">establish_date =
#{establishDate}, #{establishDate},
</if> </if>
<if test="revokeDate != null">revoke_date = <if test="revokeDate != null">revoke_date =
#{revokeDate}, #{revokeDate},
</if> </if>
<if test="createBy != null">create_by = <if test="createBy != null">create_by =
#{createBy}, #{createBy},
</if> </if>
<if test="createTime != null">create_time = <if test="createTime != null">create_time =
#{createTime}, #{createTime},
</if> </if>
<if test="updateBy != null">update_by = <if test="updateBy != null">update_by =
#{updateBy}, #{updateBy},
</if> </if>
<if test="updateTime != null">update_time = <if test="updateTime != null">update_time =
#{updateTime}, #{updateTime},
</if> </if>
</trim> </trim>
where id = #{id} where id = #{id}
@ -624,4 +624,13 @@
#{id} #{id}
</foreach> </foreach>
</select> </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> </mapper>