diff --git a/postdischarge-manage/src/main/java/com/xinelu/manage/controller/agency/AgencyController.java b/postdischarge-manage/src/main/java/com/xinelu/manage/controller/agency/AgencyController.java index fdee3e6d..960ba87a 100644 --- a/postdischarge-manage/src/main/java/com/xinelu/manage/controller/agency/AgencyController.java +++ b/postdischarge-manage/src/main/java/com/xinelu/manage/controller/agency/AgencyController.java @@ -99,7 +99,7 @@ public class AgencyController extends BaseController { @Log(title = "机构信息", businessType = BusinessType.UPDATE) @PutMapping public AjaxResult edit(@RequestBody Agency agency) { - return toAjax(agencyService.updateAgency(agency)); + return agencyService.updateAgency(agency); } /** diff --git a/postdischarge-manage/src/main/java/com/xinelu/manage/service/agency/IAgencyService.java b/postdischarge-manage/src/main/java/com/xinelu/manage/service/agency/IAgencyService.java index ce919d7a..de76ea33 100644 --- a/postdischarge-manage/src/main/java/com/xinelu/manage/service/agency/IAgencyService.java +++ b/postdischarge-manage/src/main/java/com/xinelu/manage/service/agency/IAgencyService.java @@ -61,7 +61,7 @@ public interface IAgencyService { * @param agency 机构信息 * @return 结果 */ - int updateAgency(Agency agency); + AjaxResult updateAgency(Agency agency); /** * 批量删除机构信息 diff --git a/postdischarge-manage/src/main/java/com/xinelu/manage/service/agency/impl/AgencyServiceImpl.java b/postdischarge-manage/src/main/java/com/xinelu/manage/service/agency/impl/AgencyServiceImpl.java index 5f12ccb9..f77bd166 100644 --- a/postdischarge-manage/src/main/java/com/xinelu/manage/service/agency/impl/AgencyServiceImpl.java +++ b/postdischarge-manage/src/main/java/com/xinelu/manage/service/agency/impl/AgencyServiceImpl.java @@ -4,7 +4,6 @@ import com.xinelu.common.core.domain.AjaxResult; import com.xinelu.common.exception.ServiceException; import com.xinelu.common.utils.DateUtils; import com.xinelu.common.utils.SecurityUtils; -import com.xinelu.common.utils.StringUtils; import com.xinelu.common.utils.bean.BeanUtils; import com.xinelu.common.utils.regex.RegexUtil; import com.xinelu.manage.domain.agency.Agency; @@ -16,14 +15,12 @@ import com.xinelu.manage.vo.agency.AgencyVO; import com.xinelu.manage.vo.sysarea.SysAreaVO; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.BooleanUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; -import java.util.ArrayList; -import java.util.Date; -import java.util.Iterator; -import java.util.List; +import java.util.*; import java.util.stream.Collectors; @@ -126,10 +123,20 @@ public class AgencyServiceImpl implements IAgencyService { * @return 结果 */ @Override - public int updateAgency(Agency agency) { + public AjaxResult updateAgency(Agency agency) { + if (Objects.isNull(agency.getId())) { + return AjaxResult.error("请选择机构信息!"); + } + Agency dataAgency = agencyMapper.selectAgencyById(agency.getId()); + if (StringUtils.isNotBlank(dataAgency.getAgencyName()) && !agency.getAgencyName().equals(dataAgency.getAgencyName())) { + int i = agencyMapper.selectAgencyNameByAgencyNameInt(agency.getAgencyName()); + if (i > 0) { + throw new ServiceException("该名称" + agency.getAgencyName() + "以重复!"); + } + } agency.setUpdateTime(DateUtils.getNowDate()); agency.setUpdateBy(SecurityUtils.getUsername()); - return agencyMapper.updateAgencyById(agency); + return AjaxResult.success(agencyMapper.updateAgencyById(agency)); } /** @@ -251,7 +258,7 @@ public class AgencyServiceImpl implements IAgencyService { Iterator it = list.iterator(); while (it.hasNext()) { AgencyVO n = (AgencyVO) it.next(); - if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getId().longValue()) { + if (Objects.nonNull(n.getParentId()) && n.getParentId().longValue() == t.getId().longValue()) { tlist.add(n); } }