Commit 131a0920 by 陶光胜

Merge branch 'developer' of…

Merge branch 'developer' of http://115.159.76.241/base_platform_enterprise/gic-platform-auth into developer

# Conflicts:
#	gic-platform-auth-web/src/main/resources/dubbo-gic-platform-auth-web.xml
parents f62be843 6c456976
......@@ -49,6 +49,7 @@ public class ResourceDTO implements Serializable {
* 商品资源
*/
private Long goodsResource;
private Integer userResourceCount;
public Integer getResourceId() {
return resourceId;
......@@ -113,4 +114,12 @@ public class ResourceDTO implements Serializable {
public void setGoodsResource(Long goodsResource) {
this.goodsResource = goodsResource;
}
public void setUserResourceCount(Integer userResourceCount) {
this.userResourceCount = userResourceCount;
}
public Integer getUserResourceCount() {
return userResourceCount;
}
}
......@@ -3,6 +3,7 @@ package com.gic.auth.dao.mapper;
import com.gic.auth.dto.ResourceDTO;
import com.gic.auth.entity.TabSysResource;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Param;
public interface TabSysResourceMapper {
/**
......@@ -54,4 +55,6 @@ public interface TabSysResourceMapper {
int updateByPrimaryKey(TabSysResource record);
Page<TabSysResource> listResource(ResourceDTO resourceDTO);
TabSysResource getBySelective(@Param("enterpriseId") Integer enterpriseId, @Param("resourceName") String resourceName, @Param("resourceId") Integer resourceId);
}
\ No newline at end of file
package com.gic.auth.dao.mapper;
import com.gic.auth.entity.TabSysUserResource;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
public interface TabSysUserResourceMapper {
/**
......@@ -50,4 +54,8 @@ public interface TabSysUserResourceMapper {
* @return 更新条目数
*/
int updateByPrimaryKey(TabSysUserResource record);
TabSysUserResource existUserResource(@Param("enterpriseId") Integer enterpriseId, @Param("resourceId") Integer resourceId);
List<Map<String, Object>> countByResourceIds(@Param("enterpriseId") Integer enterpriseId, @Param("ids") List<Integer> resourceIds);
}
\ No newline at end of file
......@@ -20,4 +20,6 @@ public interface ResourceService {
Page<TabSysResource> listResource(ResourceDTO resourceDTO, Integer pageNum, Integer pageSize);
TabSysResource getResource(Integer resourceId);
boolean isRepeatByResourceName(Integer enterpriseId, String resourceName, Integer resourceId);
}
package com.gic.auth.service;
import java.util.List;
import java.util.Map;
/**
*
* @Description:
* @author zhiwj
* @date 2019/8/29 10:03
*/
public interface UserResourceService {
boolean existUserResource(Integer enterpriseId, Integer resourceId);
Map<Integer,Integer> countByResourceIds(Integer enterpriseId, List<Integer> resourceIds);
}
......@@ -57,4 +57,10 @@ public class ResourceServiceImpl implements ResourceService {
public TabSysResource getResource(Integer resourceId) {
return tabSysResourceMapper.selectByPrimaryKey(resourceId);
}
@Override
public boolean isRepeatByResourceName(Integer enterpriseId, String resourceName, Integer resourceId) {
TabSysResource resource = tabSysResourceMapper.getBySelective(enterpriseId, resourceName, resourceId);
return resource != null;
}
}
......@@ -6,13 +6,20 @@ import com.gic.auth.dto.ResourceDTO;
import com.gic.auth.entity.TabSysResource;
import com.gic.auth.service.ResourceApiService;
import com.gic.auth.service.ResourceService;
import com.gic.auth.service.UserResourceService;
import com.gic.commons.util.EntityUtil;
import com.gic.commons.util.PageHelperUtils;
import com.gic.enterprise.error.ErrorCode;
import org.apache.commons.collections.CollectionUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
*
* @Description:
......@@ -26,9 +33,16 @@ public class ResourceApiServiceImpl implements ResourceApiService {
@Autowired
private ResourceService resourceService;
@Autowired
private UserResourceService userResourceService;
@Override
public ServiceResponse<Integer> saveOrUpdateResource(ResourceDTO resourceDTO) {
boolean repeat = resourceService.isRepeatByResourceName(resourceDTO.getEnterpriseId(), resourceDTO.getResourceName(), resourceDTO.getResourceId());
if (repeat) {
logger.info("enterpriseId:{} , resourceName:{}, 资源组名称重复 ", resourceDTO.getEnterpriseId(), resourceDTO.getResourceName());
return ServiceResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "资源组名称重复");
}
if (resourceDTO.getResourceId() == null) {
// save
resourceService.save(resourceDTO);
......@@ -41,6 +55,11 @@ public class ResourceApiServiceImpl implements ResourceApiService {
@Override
public ServiceResponse<Integer> delResource(Integer resourceId) {
TabSysResource resource = resourceService.getResource(resourceId);
boolean exist = this.userResourceService.existUserResource(resource.getEnterpriseId(), resource.getResourceId());
if (exist) {
return ServiceResponse.failure(ErrorCode.OPERATION_FAILED.getCode(), "该资源组正在使用中,不能删除");
}
Integer line = resourceService.delResource(resourceId);
return ServiceResponse.success(line);
}
......@@ -49,6 +68,15 @@ public class ResourceApiServiceImpl implements ResourceApiService {
public ServiceResponse<Page<ResourceDTO>> listResource(ResourceDTO resourceDTO, Integer pageNum, Integer pageSize) {
com.github.pagehelper.Page<TabSysResource> page = resourceService.listResource(resourceDTO, pageNum, pageSize);
Page<ResourceDTO> resultPage = PageHelperUtils.changePageHelperToCurrentPage(page, ResourceDTO.class);
List<ResourceDTO> resourceList = resultPage.getResult();
if (CollectionUtils.isNotEmpty(resourceList)) {
List<Integer> resourceIds = resourceList.stream().map(ResourceDTO::getResourceId).collect(Collectors.toList());
Map<Integer, Integer> map = userResourceService.countByResourceIds(resourceDTO.getEnterpriseId(), resourceIds);
for (ResourceDTO resource : resourceList) {
Integer count = map.get(resource.getResourceId());
resource.setUserResourceCount(count == null ? 0 : count);
}
}
return ServiceResponse.success(resultPage);
}
......
package com.gic.auth.service.outer.impl;
import com.gic.auth.dao.mapper.TabSysUserResourceMapper;
import com.gic.auth.entity.TabSysUserResource;
import com.gic.auth.service.UserResourceService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
*
* @Description:
* @author zhiwj
* @date 2019/8/29 10:03
*/
@Service
public class UserResourceServiceImpl implements UserResourceService {
@Autowired
private TabSysUserResourceMapper tabSysUserResourceMapper;
@Override
public boolean existUserResource(Integer enterpriseId, Integer resourceId) {
TabSysUserResource userResource = tabSysUserResourceMapper.existUserResource(enterpriseId, resourceId);
return userResource != null;
}
@Override
public Map<Integer, Integer> countByResourceIds(Integer enterpriseId, List<Integer> resourceIds) {
if (CollectionUtils.isNotEmpty(resourceIds)) {
//
Map<Integer, Integer> map = new HashMap<>();
List<Map<String, Object>> list = tabSysUserResourceMapper.countByResourceIds(enterpriseId, resourceIds);
for (Map<String, Object> integerIntegerMap : list) {
map.put(Integer.valueOf(integerIntegerMap.get("resourceId").toString()), Integer.valueOf(integerIntegerMap.get("userResourceCount").toString()));
}
return map;
} else {
return Collections.emptyMap();
}
}
}
\ No newline at end of file
......@@ -18,5 +18,6 @@
<dubbo:service interface="com.gic.auth.service.UserApiService" ref="userApiService" timeout="6000" />
<dubbo:service interface="com.gic.auth.service.MenuApiService" ref="menuApiService" timeout="6000" />
<dubbo:reference interface="com.gic.log.api.service.LogApiService" id="logApiService" timeout="6000" />
<!--资源组-->
<dubbo:service interface="com.gic.auth.service.ResourceApiService" ref="resourceApiService" timeout="6000" />
</beans>
......@@ -167,7 +167,24 @@
from tab_sys_resource
where status = 1
<if test="resourceName != null and resourceName != '' ">
and resource_name like concat('%', #{resourceName}, '%')
</if>
</select>
<select id="getBySelective" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from tab_sys_resource
where status = 1
<if test="resourceId != null ">
and resource_id &lt;&gt; #{resourceId}
</if>
<if test="resourceName != null and resourceName != '' ">
and resource_name = #{resourceName}
</if>
<if test="enterpriseId != null ">
and enterprise_id = #{enterpriseId}
</if>
limit 1
</select>
</mapper>
\ No newline at end of file
......@@ -114,4 +114,27 @@
update_time = #{updateTime,jdbcType=TIMESTAMP}
where user_resource_id = #{userResourceId,jdbcType=INTEGER}
</update>
<select id="existUserResource" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from tab_sys_user_resource
where status = 1
<if test="resourceId != null ">
and resource_id = #{resourceId}
</if>
<if test="enterpriseId != null ">
and enterprise_id = #{enterpriseId}
</if>
</select>
<!--List<Map<String,Integer>> countByResourceIds(List<Integer> resourceIds);-->
<select id="countByResourceIds" resultType="java.util.HashMap">
select resource_id resourceId , count(1) userResourceCount from tab_sys_user_resource where
status = 1
<if test="null != ids">
and resource_id in
<foreach collection="ids" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
</select>
</mapper>
\ No newline at end of file
package com.gic.auth.web.controller;
import com.gic.api.base.commons.Page;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.auth.dto.ResourceDTO;
import com.gic.auth.service.ResourceApiService;
import com.gic.auth.web.qo.PageQO;
import com.gic.auth.web.qo.ResourceQO;
import com.gic.commons.util.EntityUtil;
import com.gic.commons.webapi.reponse.RestResponse;
import com.gic.enterprise.utils.ResultControllerUtils;
import com.gic.enterprise.utils.UserDetailUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
*
* @Description:
* @author zhiwj
* @date 2019/8/29 9:09
*/
@RestController
public class ResourceController {
@Autowired
private ResourceApiService resourceApiService;
@RequestMapping("/save-resource")
public RestResponse saveResource(ResourceQO resourceQO) {
ResourceDTO resourceDTO = EntityUtil.changeEntityByOrika(ResourceDTO.class, resourceQO);
resourceDTO.setEnterpriseId(UserDetailUtils.getUserDetail().getEnterpriseId());
ServiceResponse<Integer> serviceResponse = resourceApiService.saveOrUpdateResource(resourceDTO);
return ResultControllerUtils.commonResult(serviceResponse);
}
@RequestMapping("/del-resource")
public RestResponse delResource(Integer resourceId) {
ServiceResponse<Integer> serviceResponse = resourceApiService.delResource(resourceId);
return ResultControllerUtils.commonResult(serviceResponse);
}
@RequestMapping("/list-resource")
public RestResponse listResource(ResourceQO resourceQO, PageQO pageQO) {
ResourceDTO resourceDTO = EntityUtil.changeEntityByOrika(ResourceDTO.class, resourceQO);
resourceDTO.setEnterpriseId(UserDetailUtils.getUserDetail().getEnterpriseId());
ServiceResponse<Page<ResourceDTO>> serviceResponse = resourceApiService.listResource(resourceDTO, pageQO.getCurrentPage(), pageQO.getPageSize());
return ResultControllerUtils.commonResult(serviceResponse);
}
@RequestMapping("/get-resource")
public RestResponse getResource(Integer resourceId){
ServiceResponse<ResourceDTO> serviceResponse = resourceApiService.getResource(resourceId);
return ResultControllerUtils.commonResult(serviceResponse);
}
}
package com.gic.auth.web.qo;
import javax.validation.constraints.NotBlank;
import java.io.Serializable;
/**
*
* @Description:
* @author zhiwj
* @date 2019/8/29 10:54
*/
public class ResourceQO implements Serializable {
private static final long serialVersionUID = -2010270945608110479L;
public interface SaveValid{}
/**
*
*/
private Integer resourceId;
/**
* 资源名称
*/
@NotBlank(message = "资源名不能为空", groups = SaveValid.class)
private String resourceName;
/**
*
*/
private Integer enterpriseId;
/**
* 会员卡资源控件id
*/
private Long memberCardResource;
/**
* 服务号资源
*/
private Long fwhResource;
/**
* 小程序资源
*/
private Long appletResource;
/**
* 门店资源
*/
private Long storeResource;
/**
* 商品资源
*/
private Long goodsResource;
public Integer getResourceId() {
return resourceId;
}
public void setResourceId(Integer resourceId) {
this.resourceId = resourceId;
}
public String getResourceName() {
return resourceName;
}
public void setResourceName(String resourceName) {
this.resourceName = resourceName;
}
public Integer getEnterpriseId() {
return enterpriseId;
}
public void setEnterpriseId(Integer enterpriseId) {
this.enterpriseId = enterpriseId;
}
public Long getMemberCardResource() {
return memberCardResource;
}
public void setMemberCardResource(Long memberCardResource) {
this.memberCardResource = memberCardResource;
}
public Long getFwhResource() {
return fwhResource;
}
public void setFwhResource(Long fwhResource) {
this.fwhResource = fwhResource;
}
public Long getAppletResource() {
return appletResource;
}
public void setAppletResource(Long appletResource) {
this.appletResource = appletResource;
}
public Long getStoreResource() {
return storeResource;
}
public void setStoreResource(Long storeResource) {
this.storeResource = storeResource;
}
public Long getGoodsResource() {
return goodsResource;
}
public void setGoodsResource(Long goodsResource) {
this.goodsResource = goodsResource;
}
}
......@@ -38,4 +38,8 @@
<dubbo:reference interface="com.gic.auth.service.MenuApiService" id="menuApiService" timeout="6000" />
<dubbo:reference interface="com.gic.enterprise.service.EnterpriseApiService" id="enterpriseApiService" timeout="6000" />
<dubbo:reference interface="com.gic.auth.service.UserApiService" id="userApiService" timeout="6000" />
<!--资源组-->
<dubbo:reference interface="com.gic.auth.service.ResourceApiService" id="resourceApiService" timeout="6000" />
</beans>
\ 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