Commit 88873369 authored by zhaochengming's avatar zhaochengming

服务名称重复问题

parent a0fae7fb
...@@ -12,6 +12,7 @@ import com.pms.ocp.service.OcpApiTreeService; ...@@ -12,6 +12,7 @@ import com.pms.ocp.service.OcpApiTreeService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
...@@ -48,7 +49,11 @@ public class OcpApiTreeController { ...@@ -48,7 +49,11 @@ public class OcpApiTreeController {
@ApiOperation("服务树分类--新增") @ApiOperation("服务树分类--新增")
public ResponseVO inseter(@RequestBody OcpApiGroup ocpApiGroup){ public ResponseVO inseter(@RequestBody OcpApiGroup ocpApiGroup){
OcpApiGroup ocpApiGroup1 = service.insertTree(ocpApiGroup); OcpApiGroup ocpApiGroup1 = service.insertTree(ocpApiGroup);
if (StringUtils.isBlank(ocpApiGroup1.getApiGroupName())){
return ResponseVO.error("服务名称已经存在");
}else {
return ResponseVO.ok(ocpApiGroup1); return ResponseVO.ok(ocpApiGroup1);
}
} }
......
...@@ -42,4 +42,8 @@ public interface OcpApiTreeMapper extends BaseMapper<OcpApiGroup> { ...@@ -42,4 +42,8 @@ public interface OcpApiTreeMapper extends BaseMapper<OcpApiGroup> {
//根据code查询是否含有下级服务 //根据code查询是否含有下级服务
List<OcpApiGroup> selectGroupPcode(String apiGroupCode); List<OcpApiGroup> selectGroupPcode(String apiGroupCode);
//groupName重复问题
List<OcpApiGroup> selectGroupName(String apiGroupName);
} }
...@@ -78,11 +78,13 @@ public class OcpApiTreeServiceImpl extends ServiceImpl<OcpApiTreeMapper, OcpApiG ...@@ -78,11 +78,13 @@ public class OcpApiTreeServiceImpl extends ServiceImpl<OcpApiTreeMapper, OcpApiG
Timestamp timestamp = new Timestamp(System.currentTimeMillis()); Timestamp timestamp = new Timestamp(System.currentTimeMillis());
String code = RandomStringUtils.getRandomString(6); String code = RandomStringUtils.getRandomString(6);
boolean flag = true; boolean flag = true;
List<OcpApiGroup> ocpApiGroups = mapper.selectList(null); // List<OcpApiGroup> ocpApiGroups = mapper.selectList(null);
Stream<OcpApiGroup> ocpApiGroupStream = ocpApiGroups.stream().filter(item -> item.getApiGroupCode().equals(ocpApiGroup.getApiGroupPcode())); // Stream<OcpApiGroup> ocpApiGroupStream = ocpApiGroups.stream().filter(item -> item.getApiGroupCode().equals(ocpApiGroup.getApiGroupPcode()));
Stream<OcpApiGroup> apiGroupStream1 = ocpApiGroupStream.filter(ocp -> ocp.getApiGroupName().equals(ocpApiGroup.getApiGroupName())); // Stream<OcpApiGroup> apiGroupStream1 = ocpApiGroupStream.filter(ocp -> ocp.getApiGroupName().equals(ocpApiGroup.getApiGroupName()));
List<OcpApiGroup> ocpApiGroups1 = mapper.selectGroupName(ocpApiGroup.getApiGroupName());
OcpApiGroup ocpApi = new OcpApiGroup(); OcpApiGroup ocpApi = new OcpApiGroup();
if (!(StringUtils.isBlank(apiGroupStream1.toString()))) {
if (ocpApiGroups1.size() == 0) {
ocpApi.setApiGroupPromotionType(ocpApiGroup.getApiGroupPromotionType()); ocpApi.setApiGroupPromotionType(ocpApiGroup.getApiGroupPromotionType());
BeanUtils.copyProperties(ocpApiGroup, ocpApi); BeanUtils.copyProperties(ocpApiGroup, ocpApi);
......
...@@ -35,4 +35,10 @@ ...@@ -35,4 +35,10 @@
SELECT * FROM ocp_api_group where api_group_pcode = #{apiGroupCode}; SELECT * FROM ocp_api_group where api_group_pcode = #{apiGroupCode};
</select> </select>
<!-- 根据名称查询名称是否重复-->
<select id="selectGroupName" resultType="com.pms.ocp.model.entity.OcpApiGroup">
SELECT * FROM ocp_api_group where api_group_name = #{apiGroupName};
</select>
</mapper> </mapper>
\ No newline at end of file
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