Commit f1822143 by guojuxing

功能权限集接口

parent 5dfc6a2b
package com.gic.cloud.constants;
/**
* 功能权限集
* @ClassName: FunctionEnum

* @Description: 

* @author guojuxing

* @date 2020/7/7 4:15 PM

*/
public enum FunctionEnum {
RANK_LIST(1, "排行榜"),
MEMBER_PROFILE(2, "会员概况"),
RECRUITMENT_ANALYSIS(3, "招募分析"),
MEMBER_PORTRAIT(4, "会员画像"),
PERFORMANCE_OVERVIEW(5, "业绩概览"),
CONSUME_COMPOSITION(6, "消费构成"),
ITEM_RANK(7, "单品排行"),
BASIC_PERFORMANCE(8, "基础业绩");
private int code;
private String name;
private FunctionEnum(int code, String name) {
this.code = code;
this.name = name;
}
public static boolean isRightCode(Integer code) {
if (code == null) {
return false;
}
for (FunctionEnum functionEnum : values()) {
if (code.intValue() == functionEnum.getCode()) {
return true;
}
}
return false;
}
public int getCode() {
return code;
}
public FunctionEnum setCode(int code) {
this.code = code;
return this;
}
public String getName() {
return name;
}
public FunctionEnum setName(String name) {
this.name = name;
return this;
}
}
package com.gic.cloud.dto;
import java.io.Serializable;
import java.util.Date;
/**
* 功能权限集
* @ClassName: FunctionDTO

* @Description: 

* @author guojuxing

* @date 2020/7/7 4:59 PM

*/
public class FunctionDTO implements Serializable{
private static final long serialVersionUID = 6490187238101502822L;
/**
* ID
*/
private Integer functionId;
/**
* 名称
*/
private String functionName;
/**
*
*/
private Integer enterpriseId;
/**
* 功能组件,_1_2_数据格式。1:排行榜 2:会员概况 3:招募分析 4:会员画像 5:业绩概览 6:消费构成 7:单品排行 8:基础业绩
*/
private String functionComponent;
/**
* 1:有效 0:无效
*/
private Integer status;
/**
* 创建时间
*/
private Date createTime;
/**
* 更新时间
*/
private Date updateTime;
/**
* 授权用户人数
*/
private Integer memberCount;
public Integer getFunctionId() {
return functionId;
}
public FunctionDTO setFunctionId(Integer functionId) {
this.functionId = functionId;
return this;
}
public String getFunctionName() {
return functionName;
}
public FunctionDTO setFunctionName(String functionName) {
this.functionName = functionName;
return this;
}
public Integer getEnterpriseId() {
return enterpriseId;
}
public FunctionDTO setEnterpriseId(Integer enterpriseId) {
this.enterpriseId = enterpriseId;
return this;
}
public String getFunctionComponent() {
return functionComponent;
}
public FunctionDTO setFunctionComponent(String functionComponent) {
this.functionComponent = functionComponent;
return this;
}
public Integer getStatus() {
return status;
}
public FunctionDTO setStatus(Integer status) {
this.status = status;
return this;
}
public Date getCreateTime() {
return createTime;
}
public FunctionDTO setCreateTime(Date createTime) {
this.createTime = createTime;
return this;
}
public Date getUpdateTime() {
return updateTime;
}
public FunctionDTO setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
return this;
}
public Integer getMemberCount() {
return memberCount;
}
public FunctionDTO setMemberCount(Integer memberCount) {
this.memberCount = memberCount;
return this;
}
}
package com.gic.cloud.service;
import com.gic.api.base.commons.Page;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.cloud.dto.FunctionDTO;
public interface FunctionApiService {
/**
* 新增功能权限集
* @Title: saveFunction

* @Description:

* @author guojuxing
* @param dto

* @return com.gic.api.base.commons.ServiceResponse<java.lang.Integer>


*/
ServiceResponse<Integer> saveFunction(FunctionDTO dto);
ServiceResponse<Void> editFunction(FunctionDTO dto);
ServiceResponse<Void> deleteFunction(Integer functionId);
ServiceResponse<Page<FunctionDTO>> pageFunction(Integer enterpriseId, String functionName, Integer currentPage, Integer pageSize);
}
package com.gic.cloud.dao.mapper;
import com.gic.cloud.entity.TabSysFunction;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface TabSysFunctionMapper {
/**
* 根据主键删除
*
* @param functionId 主键
* @return 更新条目数
*/
int deleteByPrimaryKey(Integer functionId);
/**
* 插入一条记录
*
* @param record 实体对象
* @return 更新条目数
*/
int insert(TabSysFunction record);
/**
* 动态插入一条记录
*
* @param record 实体对象
* @return 更新条目数
*/
int insertSelective(TabSysFunction record);
/**
* 根据主键查询
*
* @param functionId 主键
* @return 实体对象
*/
TabSysFunction selectByPrimaryKey(Integer functionId);
/**
* 根据主键动态更新记录
*
* @param record 实体对象
* @return 更新条目数
*/
int updateByPrimaryKeySelective(TabSysFunction record);
/**
* 根据主键更新记录
*
* @param record 实体对象
* @return 更新条目数
*/
int updateByPrimaryKey(TabSysFunction record);
int countByRepeatFunctionName(@Param("enterpriseId") Integer enterpriseId,
@Param("functionId") Integer functionId,
@Param("functionName") String functionName);
void deleteFunction(@Param("functionId") Integer functionId);
List<TabSysFunction> listFunction(@Param("enterpriseId")Integer enterpriseId, @Param("functionName") String functionName);
}
\ No newline at end of file
......@@ -69,5 +69,8 @@ public interface TabSysUserMapper {
void bulkTransferAccountGroup(@Param("userIdList") List<Integer> userIdList, @Param("targetAccountGroupId") Integer targetAccountGroupId);
List<UserDTO> countGroupByAccountGroupId(@Param("enterpriseId")Integer enterpriseId);
List<UserDTO> countGroupByAccountGroupId(@Param("enterpriseId") Integer enterpriseId);
List<UserDTO> countGroupByFunctionAuthId(@Param("enterpriseId")Integer enterpriseId,
@Param("functionIdList") List<Integer> functionIdList);
}
\ No newline at end of file
package com.gic.cloud.entity;
import java.util.Date;
/**
* tab_sys_function
*/
public class TabSysFunction {
/**
* ID
*/
private Integer functionId;
/**
* 名称
*/
private String functionName;
/**
*
*/
private Integer enterpriseId;
/**
* 功能组件,_1_2_数据格式。1:排行榜 2:会员概况 3:招募分析 4:会员画像 5:业绩概览 6:消费构成 7:单品排行 8:基础业绩
*/
private String functionComponent;
/**
* 1:有效 0:无效
*/
private Integer status;
/**
* 创建时间
*/
private Date createTime;
/**
* 更新时间
*/
private Date updateTime;
public Integer getFunctionId() {
return functionId;
}
public TabSysFunction setFunctionId(Integer functionId) {
this.functionId = functionId;
return this;
}
public String getFunctionName() {
return functionName;
}
public TabSysFunction setFunctionName(String functionName) {
this.functionName = functionName;
return this;
}
public Integer getEnterpriseId() {
return enterpriseId;
}
public TabSysFunction setEnterpriseId(Integer enterpriseId) {
this.enterpriseId = enterpriseId;
return this;
}
public String getFunctionComponent() {
return functionComponent;
}
public TabSysFunction setFunctionComponent(String functionComponent) {
this.functionComponent = functionComponent;
return this;
}
public Integer getStatus() {
return status;
}
public TabSysFunction setStatus(Integer status) {
this.status = status;
return this;
}
public Date getCreateTime() {
return createTime;
}
public TabSysFunction setCreateTime(Date createTime) {
this.createTime = createTime;
return this;
}
public Date getUpdateTime() {
return updateTime;
}
public TabSysFunction setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
return this;
}
}
\ No newline at end of file
package com.gic.cloud.service;
import com.gic.cloud.dto.FunctionDTO;
import com.gic.cloud.entity.TabSysFunction;
import com.github.pagehelper.Page;
public interface FunctionService {
Integer saveFunction(FunctionDTO dto);
void editFunction(FunctionDTO dto);
TabSysFunction getFunction(Integer functionId);
boolean isRepeatFunctionName(Integer enterpriseId, Integer functionId, String functionName);
void deleteFunction(Integer functionId);
Page<TabSysFunction> pageFunction(Integer enterpriseId, String functionName,
Integer currentPage, Integer pageSize);
}
......@@ -34,4 +34,6 @@ public interface UserService {
void bulkTransferAccountGroup(List<Integer> userIdList, Integer targetAccountGroupId);
List<UserDTO> countGroupByAccountGroupId(Integer enterpriseId);
List<UserDTO> countGroupByFunctionAuthId(Integer enterpriseId, List<Integer> functionIdList);
}
package com.gic.cloud.service.impl;
import com.gic.cloud.dao.mapper.TabSysFunctionMapper;
import com.gic.cloud.dto.FunctionDTO;
import com.gic.cloud.entity.TabSysFunction;
import com.gic.cloud.service.FunctionService;
import com.gic.commons.util.EntityUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
@Service("functionService")
public class FunctionServiceImpl implements FunctionService{
@Autowired
private TabSysFunctionMapper tabSysFunctionMapper;
@Override
public Integer saveFunction(FunctionDTO dto) {
TabSysFunction record = EntityUtil.changeEntityNew(TabSysFunction.class, dto);
Date now = new Date();
record.setCreateTime(now);
record.setUpdateTime(now);
record.setStatus(1);
tabSysFunctionMapper.insert(record);
return record.getFunctionId();
}
@Override
public void editFunction(FunctionDTO dto) {
TabSysFunction record = EntityUtil.changeEntityNew(TabSysFunction.class, dto);
record.setUpdateTime(new Date());
tabSysFunctionMapper.updateByPrimaryKeySelective(record);
}
@Override
public TabSysFunction getFunction(Integer functionId) {
return tabSysFunctionMapper.selectByPrimaryKey(functionId);
}
@Override
public boolean isRepeatFunctionName(Integer enterpriseId, Integer functionId, String functionName) {
if (tabSysFunctionMapper.countByRepeatFunctionName(enterpriseId, functionId, functionName) > 0) {
return true;
}
return false;
}
@Override
public void deleteFunction(Integer functionId) {
tabSysFunctionMapper.deleteFunction(functionId);
}
@Override
public Page<TabSysFunction> pageFunction(Integer enterpriseId, String functionName, Integer currentPage, Integer pageSize) {
if (currentPage == null) {
currentPage = 1;
}
if (pageSize == null) {
pageSize = 20;
}
PageHelper.startPage(currentPage, pageSize);
List<TabSysFunction> list = tabSysFunctionMapper.listFunction(enterpriseId, functionName);
return (Page<TabSysFunction>) list;
}
}
......@@ -79,4 +79,9 @@ public class UserServiceImpl implements UserService{
public List<UserDTO> countGroupByAccountGroupId(Integer enterpriseId) {
return tabSysUserMapper.countGroupByAccountGroupId(enterpriseId);
}
@Override
public List<UserDTO> countGroupByFunctionAuthId(Integer enterpriseId, List<Integer> functionIdList) {
return tabSysUserMapper.countGroupByFunctionAuthId(enterpriseId, functionIdList);
}
}
package com.gic.cloud.service.outer.impl;
import com.gic.api.base.commons.Page;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.cloud.constants.FunctionEnum;
import com.gic.cloud.dto.FunctionDTO;
import com.gic.cloud.dto.UserDTO;
import com.gic.cloud.entity.TabSysFunction;
import com.gic.cloud.service.FunctionApiService;
import com.gic.cloud.service.FunctionService;
import com.gic.cloud.service.UserService;
import com.gic.commons.util.PageHelperUtils;
import com.gic.enterprise.error.ErrorCode;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@Service("functionApiService")
public class FunctionApiServiceImpl implements FunctionApiService{
@Autowired
private FunctionService functionService;
@Autowired
private UserService userService;
@Override
public ServiceResponse<Integer> saveFunction(FunctionDTO dto) {
dto.setFunctionId(null);
ServiceResponse validParamResult = validParam(dto);
if (!validParamResult.isSuccess()) {
return ServiceResponse.failure(validParamResult.getCode(), validParamResult.getMessage());
}
return ServiceResponse.success(functionService.saveFunction(dto));
}
@Override
public ServiceResponse<Void> editFunction(FunctionDTO dto) {
ServiceResponse validParamResult = validParam(dto);
if (!validParamResult.isSuccess()) {
return ServiceResponse.failure(validParamResult.getCode(), validParamResult.getMessage());
}
functionService.editFunction(dto);
return ServiceResponse.success();
}
@Override
public ServiceResponse<Void> deleteFunction(Integer functionId) {
functionService.deleteFunction(functionId);
return ServiceResponse.success();
}
@Override
public ServiceResponse<Page<FunctionDTO>> pageFunction(Integer enterpriseId, String functionName,
Integer currentPage, Integer pageSize) {
com.github.pagehelper.Page page = functionService.pageFunction(enterpriseId, functionName, currentPage, pageSize);
Page<FunctionDTO> resultPage = PageHelperUtils.changePageHelperToCurrentPage(page, FunctionDTO.class);
if (resultPage != null) {
List<FunctionDTO> list = resultPage.getResult();
if (CollectionUtils.isNotEmpty(list)) {
Stream<FunctionDTO> stream = list.stream();
//获取授权人数数据
List<UserDTO> userList = userService.countGroupByFunctionAuthId(enterpriseId, stream.map(e -> e.getFunctionId())
.collect(Collectors.toList()));
if (CollectionUtils.isNotEmpty(userList)) {
Map<String, Integer> map = userList
.stream()
.collect(Collectors.toMap(e -> e.getFunctionAuthId().toString(), e -> e.getMemberCount()));
list.forEach(e -> e.setMemberCount(map.get(e.getFunctionId().toString())));
}
}
return ServiceResponse.success(resultPage);
}
return ServiceResponse.success(new Page<>());
}
private ServiceResponse<Void> validParam(FunctionDTO dto) {
if (dto.getFunctionId() != null) {
TabSysFunction record = functionService.getFunction(dto.getFunctionId());
if (record == null) {
return ServiceResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "功能权限组ID错误,查无数据");
}
dto.setEnterpriseId(record.getEnterpriseId());
}
Integer enterpriseId = dto.getEnterpriseId();
if (enterpriseId == null) {
return ServiceResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "商户ID不能为空");
}
String functionName = dto.getFunctionName();
if (StringUtils.isBlank(functionName)) {
return ServiceResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "功能权限组名称不能为空");
}
if (functionService.isRepeatFunctionName(enterpriseId, dto.getFunctionId(), functionName)) {
return ServiceResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "功能权限组名称重复");
}
String functionComponent = dto.getFunctionComponent();
if (StringUtils.isBlank(functionComponent)) {
return ServiceResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "功能组件不能为空");
}
//一个流只能用一次
Stream<String> stream = Arrays.stream(functionComponent.split(","));
Stream<String> stream2 = Arrays.stream(functionComponent.split(","));
Stream<String> stream3 = Arrays.stream(functionComponent.split(","));
if (stream.anyMatch(e -> !StringUtils.isNumeric(e))) {
return ServiceResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "功能组件值非法");
}
if (stream2.anyMatch(e -> !FunctionEnum.isRightCode(Integer.parseInt(e)))) {
return ServiceResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "功能组件值非法");
}
StringBuilder temp = new StringBuilder("_");
stream3.mapToInt(e -> Integer.parseInt(e)).boxed().sorted().forEach(e -> {
temp.append(e).append("_");
});
dto.setFunctionComponent(temp.toString());
return ServiceResponse.success();
}
}
......@@ -16,4 +16,6 @@
<dubbo:protocol name="dubbo" port="20370"/>
<dubbo:service interface="com.gic.cloud.service.AccountGroupApiService" ref="accountGroupApiService" timeout="6000" />
<dubbo:service interface="com.gic.cloud.service.UserApiService" ref="userApiService" timeout="6000" />
<dubbo:service interface="com.gic.cloud.service.FunctionApiService" ref="functionApiService" timeout="6000" />
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.gic.cloud.dao.mapper.TabSysFunctionMapper">
<resultMap id="BaseResultMap" type="com.gic.cloud.entity.TabSysFunction">
<id column="function_id" jdbcType="INTEGER" property="functionId" />
<result column="function_name" jdbcType="VARCHAR" property="functionName" />
<result column="enterprise_id" jdbcType="INTEGER" property="enterpriseId" />
<result column="function_component" jdbcType="VARCHAR" property="functionComponent" />
<result column="status" jdbcType="INTEGER" property="status" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
</resultMap>
<sql id="Base_Column_List">
function_id, function_name, enterprise_id, function_component, status, create_time,
update_time
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from tab_sys_function
where function_id = #{functionId,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from tab_sys_function
where function_id = #{functionId,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.gic.cloud.entity.TabSysFunction" useGeneratedKeys="true" keyProperty="functionId">
insert into tab_sys_function (function_id, function_name, enterprise_id,
function_component, status, create_time,
update_time)
values (#{functionId,jdbcType=INTEGER}, #{functionName,jdbcType=VARCHAR}, #{enterpriseId,jdbcType=INTEGER},
#{functionComponent,jdbcType=VARCHAR}, #{status,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP},
#{updateTime,jdbcType=TIMESTAMP})
</insert>
<insert id="insertSelective" parameterType="com.gic.cloud.entity.TabSysFunction">
insert into tab_sys_function
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="functionId != null">
function_id,
</if>
<if test="functionName != null">
function_name,
</if>
<if test="enterpriseId != null">
enterprise_id,
</if>
<if test="functionComponent != null">
function_component,
</if>
<if test="status != null">
status,
</if>
<if test="createTime != null">
create_time,
</if>
<if test="updateTime != null">
update_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="functionId != null">
#{functionId,jdbcType=INTEGER},
</if>
<if test="functionName != null">
#{functionName,jdbcType=VARCHAR},
</if>
<if test="enterpriseId != null">
#{enterpriseId,jdbcType=INTEGER},
</if>
<if test="functionComponent != null">
#{functionComponent,jdbcType=VARCHAR},
</if>
<if test="status != null">
#{status,jdbcType=INTEGER},
</if>
<if test="createTime != null">
#{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null">
#{updateTime,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.gic.cloud.entity.TabSysFunction">
update tab_sys_function
<set>
<if test="functionName != null">
function_name = #{functionName,jdbcType=VARCHAR},
</if>
<if test="enterpriseId != null">
enterprise_id = #{enterpriseId,jdbcType=INTEGER},
</if>
<if test="functionComponent != null">
function_component = #{functionComponent,jdbcType=VARCHAR},
</if>
<if test="status != null">
status = #{status,jdbcType=INTEGER},
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=TIMESTAMP},
</if>
</set>
where function_id = #{functionId,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.gic.cloud.entity.TabSysFunction">
update tab_sys_function
set function_name = #{functionName,jdbcType=VARCHAR},
enterprise_id = #{enterpriseId,jdbcType=INTEGER},
function_component = #{functionComponent,jdbcType=VARCHAR},
status = #{status,jdbcType=INTEGER},
create_time = #{createTime,jdbcType=TIMESTAMP},
update_time = #{updateTime,jdbcType=TIMESTAMP}
where function_id = #{functionId,jdbcType=INTEGER}
</update>
<select id="countByRepeatFunctionName" resultType="int">
select count(1) from tab_sys_function
where enterprise_id = #{enterpriseId}
and function_name = #{functionName}
<if test="functionId != null">
and function_id &lt;&gt; #{functionId}
</if>
and status = 1
</select>
<update id="deleteFunction">
update tab_sys_function set status = 0
where function_id = #{functionId}
and status = 1
</update>
<select id="listFunction" resultMap="BaseResultMap">
select <include refid="Base_Column_List"></include>
from tab_sys_function
where enterprise_id = #{enterpriseId}
<if test="functionName != null and functionName != ''">
and function_name like concat('%', #{functionName}, '%')
</if>
and status = 1
order by create_time desc
</select>
</mapper>
\ No newline at end of file
......@@ -223,4 +223,18 @@
and status = 1
group by account_group_id
</select>
<select id="countGroupByFunctionAuthId" resultType="com.gic.cloud.dto.UserDTO">
select function_auth_id functionAuthId, count(user_id) memberCount
from tab_sys_user
where enterprise_id = #{enterpriseId}
and status = 1
<if test="functionIdList != null and functionIdList.size() > 0">
and function_auth_id in
<foreach collection="functionIdList" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
group by function_auth_id
</select>
</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