Commit 1d91c26e by songyinghui

feat: 分组名称支持实时去重校验

parent a1fcec0b
......@@ -5,6 +5,8 @@ import com.gic.api.base.commons.ServiceResponse;
import com.gic.haoban.manage.api.dto.hm.HmGroupDTO;
import com.gic.haoban.manage.api.dto.hm.HmGroupQueryDTO;
import java.util.List;
/**
* @Author MUSI
* @Date 2022/7/1 2:35 PM
......@@ -52,4 +54,11 @@ public interface HmGroupApiService {
* @return
*/
ServiceResponse<HmGroupDTO> queryGroupDetail(Long groupId);
/**
* 根据名称查询groupName
* @param groupName
* @return
*/
ServiceResponse<List<HmGroupDTO>> queryGroupListByName(String groupName);
}
\ No newline at end of file
......@@ -34,4 +34,11 @@ public interface TabHaobanHmGroupSettingMapper {
*/
int updateGroupSettingCount(@Param("groupId") Long groupId, @Param("changeCount") Integer changeCount);
/**
* 根据名称精确查询
* @param groupName
* @return
*/
List<TabHaobanHmGroupSetting> queryHmGroupSettingByName(@Param("groupName") String groupName);
}
\ No newline at end of file
......@@ -53,4 +53,11 @@ public interface HmGroupService {
*/
Long saveOrUpdateGroupSetting(HmGroupDTO groupDTO);
/**
* 根据名称精确查询分组
* @param groupName
* @return
*/
List<HmGroupSettingBO> queryGroupSettingByName(String groupName);
}
......@@ -2,6 +2,7 @@ package com.gic.haoban.manage.service.service.hm.impl;
import com.gic.api.base.commons.Page;
import com.gic.commons.util.UniqueIdUtils;
import com.gic.haoban.common.utils.EntityUtil;
import com.gic.haoban.common.utils.PageUtil;
import com.gic.haoban.manage.api.dto.hm.HmGroupDTO;
import com.gic.haoban.manage.api.enums.hm.HmGroupStatus;
......@@ -22,6 +23,8 @@ import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.List;
......@@ -132,4 +135,12 @@ public class HmGroupServiceImpl implements HmGroupService {
return tempGroupSetting.getGroupId();
}
}
public List<HmGroupSettingBO> queryGroupSettingByName(String groupName){
List<TabHaobanHmGroupSetting> tabHaobanHmGroupSettings = haobanHmGroupSettingMapper.queryHmGroupSettingByName(groupName);
if (CollectionUtils.isEmpty(tabHaobanHmGroupSettings)){
return Collections.emptyList();
}
return EntityUtil.changeEntityListByOrika(HmGroupSettingBO.class, tabHaobanHmGroupSettings);
}
}
......@@ -61,27 +61,22 @@ public class HmGroupApiServiceImpl implements HmGroupApiService {
if (StringUtils.equals(DEFAULT_GROUP_NAME, hmGroupDTO.getGroupName())) {
return ServiceResponse.failure(HaoBanErrCodeCommon.ERR_9.getCode() + "", "分组名称不可使用默认分组名称");
}
HmGroupInfoQO groupInfoQo = new HmGroupInfoQO();
groupInfoQo.setGroupName(hmGroupDTO.getGroupName());
groupInfoQo.setStatus(HmGroupStatus.ENABLE.getCode());
groupInfoQo.setEnterpriseId(hmGroupDTO.getEnterpriseId());
groupInfoQo.setWxEnterpriseId(groupInfoQo.getWxEnterpriseId());
Page<HmGroupSettingBO> hmGroupSettingPage = groupService.queryGroupSettingList(groupInfoQo);
List<HmGroupSettingBO> groupSettingBos = groupService.queryGroupSettingByName(hmGroupDTO.getGroupName());
if (hmGroupDTO.getGroupId() == null) {
// insert
// check groupName unique
if (CollectionUtils.isNotEmpty(hmGroupSettingPage.getResult())) {
if (CollectionUtils.isNotEmpty(groupSettingBos)) {
return ServiceResponse.failure(HaoBanErrCodeCommon.ERR_5.getCode() + "", "该分组名称已存在,请重新输入");
}
} else {
// update
if (CollectionUtils.isNotEmpty(hmGroupSettingPage.getResult())
&& hmGroupSettingPage.getTotalCount() > 1) {
if (CollectionUtils.isNotEmpty(groupSettingBos)
&& groupSettingBos.size() > 1) {
// 名称重复
return ServiceResponse.failure(HaoBanErrCodeCommon.ERR_5.getCode() + "", "该分组名称已存在,请重新输入");
}
if (CollectionUtils.isNotEmpty(hmGroupSettingPage.getResult())
&& !hmGroupSettingPage.getResult().get(0).getGroupId().equals(hmGroupDTO.getGroupId())) {
if (CollectionUtils.isNotEmpty(groupSettingBos)
&& !groupSettingBos.get(0).getGroupId().equals(hmGroupDTO.getGroupId())) {
// 名称重复
return ServiceResponse.failure(HaoBanErrCodeCommon.ERR_5.getCode() + "", "该分组名称已存在,请重新输入");
}
......@@ -187,4 +182,16 @@ public class HmGroupApiServiceImpl implements HmGroupApiService {
HmGroupDTO groupDTO = EntityUtil.changeEntityByOrika(HmGroupDTO.class, groupSettingBO);
return ServiceResponse.success(groupDTO);
}
/**
* 根据名称查询groupName
*
* @param groupName
* @return
*/
@Override
public ServiceResponse<List<HmGroupDTO>> queryGroupListByName(String groupName) {
List<HmGroupSettingBO> hmGroupSettingBos = groupService.queryGroupSettingByName(groupName);
return ServiceResponse.success(EntityUtil.changeEntityListByOrika(HmGroupDTO.class, hmGroupSettingBos));
}
}
......@@ -204,4 +204,11 @@
set refer_num = if(refer_num + #{changeCount} >= 0, refer_num + #{changeCount}, 0)
where group_id = #{groupId,jdbcType=BIGINT}
</update>
<select id="queryHmGroupSettingByName" resultMap="BaseResultMap">
select <include refid="Base_Column_List"/>
from tab_haoban_hm_group_setting
where group_name = #{groupName}
and `status` = 1
</select>
</mapper>
\ No newline at end of file
......@@ -134,4 +134,10 @@ public class HmPageServiceTest {
System.out.println(JSON.toJSONString(serviceResponse));
}
@Test
public void groupNameCheckTest(){
ServiceResponse<List<HmGroupDTO>> ms = groupService.queryGroupListByName("MS");
System.out.println(JSON.toJSONString(ms));
}
}
......@@ -5,6 +5,7 @@ import com.gic.api.base.commons.ServiceResponse;
import com.gic.commons.webapi.reponse.RestResponse;
import com.gic.haoban.base.api.common.pojo.dto.WebLoginDTO;
import com.gic.haoban.common.utils.AuthWebRequestUtil;
import com.gic.haoban.common.utils.StringUtil;
import com.gic.haoban.manage.api.dto.hm.HmGroupDTO;
import com.gic.haoban.manage.api.dto.hm.HmGroupQueryDTO;
import com.gic.haoban.manage.api.service.hm.HmGroupApiService;
......@@ -17,12 +18,15 @@ import com.gic.log.record.anno.GicLogRecord;
import com.gic.log.record.util.GicLogRecordCategoryEnum;
import com.gic.log.record.util.GicLogRecordEvaluationContext;
import com.gic.log.record.util.GicLogRecordOptTypeEnum;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.Valid;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
/**
......@@ -130,4 +134,17 @@ public class HmGroupController extends WebBaseController {
ServiceResponse<Integer> serviceResponse = groupApiService.queryGroupTotalReferCount(loginUser.getEnterpriseId(), loginUser.getWxEnterpriseId());
return RestResponse.successResult(serviceResponse.getResult());
}
@RequestMapping(path = "/check/name")
public RestResponse<?> checkGroupName(HmGroupSettingVO groupSettingVO){
if (StringUtils.isBlank(groupSettingVO.getGroupName())){
return RestResponse.successResult(Collections.emptyList());
}
ServiceResponse<List<HmGroupDTO>> serviceResponse = groupApiService.queryGroupListByName(groupSettingVO.getGroupName());
if (serviceResponse.isSuccess()){
return RestResponse.successResult(serviceResponse.getResult());
}
return RestResponse.failure(serviceResponse.getCode(), serviceResponse.getMessage());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment