Commit 24095d03 by zhiwj

模块分组

parent 4ba539f4
package com.gic.cloud.dto;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
* @author zhiwj
* @Description:
* @date 2020-07-13 15:32
*/
public class IndexGroupDTO implements Serializable {
private static final long serialVersionUID = -3805956042154485116L;
/**
*
*/
private Integer indexGroupId;
/**
*
*/
private String indexGroupName;
/**
*
*/
private Integer parentId;
/**
*
*/
private String groupChain;
/**
*
*/
private Date createTime;
/**
*
*/
private Date updateTime;
/**
*
*/
private Integer status;
private List<IndexGroupDTO> childList;
public Integer getIndexGroupId() {
return indexGroupId;
}
public void setIndexGroupId(Integer indexGroupId) {
this.indexGroupId = indexGroupId;
}
public String getIndexGroupName() {
return indexGroupName;
}
public void setIndexGroupName(String indexGroupName) {
this.indexGroupName = indexGroupName;
}
public Integer getParentId() {
return parentId;
}
public void setParentId(Integer parentId) {
this.parentId = parentId;
}
public String getGroupChain() {
return groupChain;
}
public void setGroupChain(String groupChain) {
this.groupChain = groupChain;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Date getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public List<IndexGroupDTO> getChildList() {
return childList;
}
public void setChildList(List<IndexGroupDTO> childList) {
this.childList = childList;
}
}
package com.gic.cloud.service;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.cloud.dto.IndexGroupDTO;
import java.util.List;
/**
* @author zhiwj
* @Description:
* @date 2020-07-13 15:31
*/
public interface IndexGroupApiService {
/**
* @Title: save
* @Description:
* @author zhiwj
* @param indexGroupDTO
* @return com.gic.api.base.commons.ServiceResponse<java.lang.Void>
* @throws
*/
ServiceResponse<Void> save(IndexGroupDTO indexGroupDTO);
/**
* @Title: update
* @Description:
* @author zhiwj
* @param indexGroupDTO
* @return com.gic.api.base.commons.ServiceResponse<java.lang.Void>
* @throws
*/
ServiceResponse<Void> update(IndexGroupDTO indexGroupDTO);
/**
* @Title: tree
* @Description:
* @author zhiwj
* @return com.gic.api.base.commons.ServiceResponse<java.util.List<com.gic.cloud.dto.IndexGroupDTO>>
* @throws
*/
ServiceResponse<List<IndexGroupDTO>> tree();
/**
* @Title: delete
* @Description:
* @author zhiwj
* @param indexGroupId
* @return com.gic.api.base.commons.ServiceResponse<java.lang.Void>
* @throws
*/
ServiceResponse<Void> delete(Integer indexGroupId);
}
package com.gic.cloud.operation.web.controller;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.cloud.dto.IndexGroupDTO;
import com.gic.cloud.service.IndexGroupApiService;
import com.gic.commons.webapi.reponse.RestResponse;
import com.gic.enterprise.error.ErrorCode;
import com.gic.enterprise.utils.ResultControllerUtils;
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.RestController;
import java.util.List;
/**
* @author zhiwj
* @Description:
* @date 2020-07-13 16:26
*/
@RestController
public class IndexGroupController {
@Autowired
private IndexGroupApiService indexGroupApiService;
@RequestMapping("/saveIndexGroup")
public RestResponse saveIndexGroup(IndexGroupDTO indexGroupDTO) {
if (StringUtils.isBlank(indexGroupDTO.getIndexGroupName()) || indexGroupDTO.getParentId() == null) {
return RestResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), ErrorCode.PARAMETER_ERROR.getMsg());
}
ServiceResponse<Void> serviceResponse = indexGroupApiService.save(indexGroupDTO);
return ResultControllerUtils.commonResult(serviceResponse);
}
@RequestMapping("/updateIndexGroup")
public RestResponse updateIndexGroup(IndexGroupDTO indexGroupDTO) {
if (StringUtils.isBlank(indexGroupDTO.getIndexGroupName()) || indexGroupDTO.getParentId() == null) {
return RestResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), ErrorCode.PARAMETER_ERROR.getMsg());
}
ServiceResponse<Void> serviceResponse = indexGroupApiService.update(indexGroupDTO);
return ResultControllerUtils.commonResult(serviceResponse);
}
@RequestMapping("/treeIndexGroup")
public RestResponse tree() {
ServiceResponse<List<IndexGroupDTO>> serviceResponse = indexGroupApiService.tree();
return ResultControllerUtils.commonResult(serviceResponse);
}
@RequestMapping("/deleteIndexGroup")
public RestResponse tree(Integer indexGroupId) {
ServiceResponse<Void> serviceResponse = indexGroupApiService.delete(indexGroupId);
return ResultControllerUtils.commonResult(serviceResponse);
}
}
......@@ -95,6 +95,7 @@
<dubbo:reference interface="com.gic.cloud.service.IndexApiService" id="indexApiService" timeout="6000" retries="0"/>
<dubbo:reference interface="com.gic.cloud.service.IndexLogApiService" id="indexLogApiService" timeout="6000" retries="0"/>
<dubbo:reference interface="com.gic.cloud.service.IndexGroupApiService" id="indexGroupApiService" timeout="6000" retries="0"/>
<dubbo:reference interface="com.gic.cloud.service.DataExplainApiService" id="dataExplainApiService" timeout="6000" retries="0"/>
......
package com.gic.cloud.dao.mapper;
import com.gic.cloud.entity.TabIndexGroup;
import java.util.List;
public interface TabIndexGroupMapper {
/**
* 根据主键删除
*
* @param indexGroupId 主键
* @return 更新条目数
*/
int deleteByPrimaryKey(Integer indexGroupId);
/**
* 插入一条记录
*
* @param record 实体对象
* @return 更新条目数
*/
int insert(TabIndexGroup record);
/**
* 动态插入一条记录
*
* @param record 实体对象
* @return 更新条目数
*/
int insertSelective(TabIndexGroup record);
/**
* 根据主键查询
*
* @param indexGroupId 主键
* @return 实体对象
*/
TabIndexGroup selectByPrimaryKey(Integer indexGroupId);
/**
* 根据主键动态更新记录
*
* @param record 实体对象
* @return 更新条目数
*/
int updateByPrimaryKeySelective(TabIndexGroup record);
/**
* 根据主键更新记录
*
* @param record 实体对象
* @return 更新条目数
*/
int updateByPrimaryKey(TabIndexGroup record);
TabIndexGroup getBySelective(TabIndexGroup indexGroup);
List<TabIndexGroup> listIndexGroup();
}
\ No newline at end of file
package com.gic.cloud.entity;
import java.util.Date;
/**
* tab_index_group
*/
public class TabIndexGroup {
/**
*
*/
private Integer indexGroupId;
/**
*
*/
private String indexGroupName;
/**
*
*/
private Integer parentId;
/**
*
*/
private String groupChain;
/**
*
*/
private Date createTime;
/**
*
*/
private Date updateTime;
/**
*
*/
private Integer status;
public Integer getIndexGroupId() {
return indexGroupId;
}
public void setIndexGroupId(Integer indexGroupId) {
this.indexGroupId = indexGroupId;
}
public String getIndexGroupName() {
return indexGroupName;
}
public void setIndexGroupName(String indexGroupName) {
this.indexGroupName = indexGroupName;
}
public Integer getParentId() {
return parentId;
}
public void setParentId(Integer parentId) {
this.parentId = parentId;
}
public String getGroupChain() {
return groupChain;
}
public void setGroupChain(String groupChain) {
this.groupChain = groupChain;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Date getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
}
\ No newline at end of file
package com.gic.cloud.service;
import com.gic.cloud.dto.IndexGroupDTO;
import com.gic.cloud.entity.TabIndexGroup;
import java.util.List;
/**
* @author zhiwj
* @Description:
* @date 2020-07-13 15:37
*/
public interface IndexGroupService {
boolean isNameRepeat(String indexGroupName, Integer indexGroupId);
Integer save(IndexGroupDTO indexGroupDTO);
TabIndexGroup getById(Integer indexGroupId);
void update(IndexGroupDTO indexGroupDTO);
void delete(Integer indexGroupId);
List<TabIndexGroup> listIndexGroup();
}
package com.gic.cloud.service.impl;
import com.gic.cloud.dao.mapper.TabIndexGroupMapper;
import com.gic.cloud.dto.IndexGroupDTO;
import com.gic.cloud.entity.TabIndexGroup;
import com.gic.cloud.service.IndexGroupService;
import com.gic.commons.util.EntityUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
/**
* @author zhiwj
* @Description:
* @date 2020-07-13 15:38
*/
@Service
public class IndexGroupServiceImpl implements IndexGroupService {
@Autowired
private TabIndexGroupMapper tabIndexGroupMapper;
@Override
public boolean isNameRepeat(String indexGroupName, Integer indexGroupId) {
TabIndexGroup indexGroup = new TabIndexGroup();
indexGroup.setIndexGroupName(indexGroupName);
indexGroup.setIndexGroupId(indexGroupId);
return tabIndexGroupMapper.getBySelective(indexGroup) != null;
}
@Override
public Integer save(IndexGroupDTO indexGroupDTO) {
TabIndexGroup indexGroup = EntityUtil.changeEntityByJSON(TabIndexGroup.class, indexGroupDTO);
indexGroup.setStatus(1);
indexGroup.setCreateTime(new Date());
tabIndexGroupMapper.insertSelective(indexGroup);
return indexGroup.getIndexGroupId();
}
@Override
public TabIndexGroup getById(Integer indexGroupId) {
return tabIndexGroupMapper.selectByPrimaryKey(indexGroupId);
}
@Override
public void update(IndexGroupDTO indexGroupDTO) {
tabIndexGroupMapper.updateByPrimaryKeySelective(EntityUtil.changeEntityByJSON(TabIndexGroup.class, indexGroupDTO));
}
@Override
public void delete(Integer indexGroupId) {
TabIndexGroup tabIndexGroup = new TabIndexGroup();
tabIndexGroup.setIndexGroupId(indexGroupId);
tabIndexGroup.setStatus(0);
tabIndexGroupMapper.updateByPrimaryKeySelective(EntityUtil.changeEntityByJSON(TabIndexGroup.class, tabIndexGroup));
}
@Override
public List<TabIndexGroup> listIndexGroup() {
return tabIndexGroupMapper.listIndexGroup();
}
}
package com.gic.cloud.service.outer.impl;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.cloud.dto.IndexGroupDTO;
import com.gic.cloud.entity.TabIndexGroup;
import com.gic.cloud.service.IndexGroupApiService;
import com.gic.cloud.service.IndexGroupService;
import com.gic.commons.util.EntityUtil;
import com.gic.enterprise.error.ErrorCode;
import com.gic.enterprise.response.EnterpriseServiceResponse;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
/**
* @author zhiwj
* @Description:
* @date 2020-07-13 15:37
*/
@Service("indexGroupApiService")
public class IndexGroupApiServiceImpl implements IndexGroupApiService {
@Autowired
private IndexGroupService indexGroupService;
@Override
public ServiceResponse<Void> save(IndexGroupDTO indexGroupDTO) {
// 校验参数
if (indexGroupService.isNameRepeat(indexGroupDTO.getIndexGroupName(), null)) {
return ServiceResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "名称重复");
}
Integer indexGroupId = indexGroupService.save(indexGroupDTO);
indexGroupDTO.setIndexGroupId(indexGroupId);
TabIndexGroup parentIndexGroup = indexGroupService.getById(indexGroupDTO.getParentId());
indexGroupDTO.setGroupChain(parentIndexGroup.getGroupChain() + "_" + indexGroupId + "_");
indexGroupService.update(indexGroupDTO);
return ServiceResponse.success();
}
@Override
public ServiceResponse<Void> update(IndexGroupDTO indexGroupDTO) {
// 校验参数
if (indexGroupService.isNameRepeat(indexGroupDTO.getIndexGroupName(), null)) {
return ServiceResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "名称重复");
}
TabIndexGroup parentIndexGroup = indexGroupService.getById(indexGroupDTO.getParentId());
indexGroupDTO.setGroupChain(parentIndexGroup.getGroupChain() + "_" + indexGroupDTO.getIndexGroupId() + "_");
indexGroupService.update(indexGroupDTO);
return ServiceResponse.success();
}
@Override
public ServiceResponse<List<IndexGroupDTO>> tree() {
List<TabIndexGroup> groupList = this.indexGroupService.listIndexGroup();
List<IndexGroupDTO> groupDTOList = EntityUtil.changeEntityListByJSON(IndexGroupDTO.class, groupList);
List<IndexGroupDTO> tree = toTree(groupDTOList);
return EnterpriseServiceResponse.success(tree);
}
private List<IndexGroupDTO> toTree(List<IndexGroupDTO> groupDTOList) {
return toTree(0, groupDTOList);
}
private List<IndexGroupDTO> toTree(Integer parentIndexGroupId, List<IndexGroupDTO> groupDTOList) {
if (CollectionUtils.isEmpty(groupDTOList)) {
return null;
}
List<IndexGroupDTO> resultList = new ArrayList<>();
for (IndexGroupDTO indexGroupDTO : groupDTOList) {
if (parentIndexGroupId.equals(indexGroupDTO.getParentId())) {
resultList.add(indexGroupDTO);
indexGroupDTO.setChildList(toTree(indexGroupDTO.getIndexGroupId(), groupDTOList));
}
}
return resultList;
}
@Override
public ServiceResponse<Void> delete(Integer indexGroupId) {
indexGroupService.delete(indexGroupId);
return ServiceResponse.success();
}
}
......@@ -24,4 +24,5 @@
<dubbo:service interface="com.gic.cloud.service.IndexApiService" ref="indexApiService" timeout="6000" />
<dubbo:service interface="com.gic.cloud.service.IndexLogApiService" ref="indexLogApiService" timeout="6000" />
<dubbo:service interface="com.gic.cloud.service.TempStoreConditionApiService" ref="tempStoreConditionApiService" timeout="6000" />
<dubbo:service interface="com.gic.cloud.service.IndexGroupApiService" ref="indexGroupApiService" 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.TabIndexGroupMapper">
<resultMap id="BaseResultMap" type="com.gic.cloud.entity.TabIndexGroup">
<id column="index_group_id" jdbcType="INTEGER" property="indexGroupId" />
<result column="index_group_name" jdbcType="VARCHAR" property="indexGroupName" />
<result column="parent_id" jdbcType="INTEGER" property="parentId" />
<result column="group_chain" jdbcType="VARCHAR" property="groupChain" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
<result column="status" jdbcType="INTEGER" property="status" />
</resultMap>
<sql id="Base_Column_List">
index_group_id, index_group_name, parent_id, group_chain, create_time, update_time,
status
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from tab_index_group
where index_group_id = #{indexGroupId,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from tab_index_group
where index_group_id = #{indexGroupId,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.gic.cloud.entity.TabIndexGroup">
insert into tab_index_group (index_group_id, index_group_name, parent_id,
group_chain, create_time, update_time,
status)
values (#{indexGroupId,jdbcType=INTEGER}, #{indexGroupName,jdbcType=VARCHAR}, #{parentId,jdbcType=INTEGER},
#{groupChain,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP},
#{status,jdbcType=INTEGER})
</insert>
<insert id="insertSelective" parameterType="com.gic.cloud.entity.TabIndexGroup">
<selectKey keyProperty="indexGroupId" order="AFTER" resultType="java.lang.Integer">
SELECT LAST_INSERT_ID()
</selectKey>
insert into tab_index_group
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="indexGroupId != null">
index_group_id,
</if>
<if test="indexGroupName != null">
index_group_name,
</if>
<if test="parentId != null">
parent_id,
</if>
<if test="groupChain != null">
group_chain,
</if>
<if test="createTime != null">
create_time,
</if>
<if test="updateTime != null">
update_time,
</if>
<if test="status != null">
status,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="indexGroupId != null">
#{indexGroupId,jdbcType=INTEGER},
</if>
<if test="indexGroupName != null">
#{indexGroupName,jdbcType=VARCHAR},
</if>
<if test="parentId != null">
#{parentId,jdbcType=INTEGER},
</if>
<if test="groupChain != null">
#{groupChain,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
#{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null">
#{updateTime,jdbcType=TIMESTAMP},
</if>
<if test="status != null">
#{status,jdbcType=INTEGER},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.gic.cloud.entity.TabIndexGroup">
update tab_index_group
<set>
<if test="indexGroupName != null">
index_group_name = #{indexGroupName,jdbcType=VARCHAR},
</if>
<if test="parentId != null">
parent_id = #{parentId,jdbcType=INTEGER},
</if>
<if test="groupChain != null">
group_chain = #{groupChain,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=TIMESTAMP},
</if>
<if test="status != null">
status = #{status,jdbcType=INTEGER},
</if>
</set>
where index_group_id = #{indexGroupId,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.gic.cloud.entity.TabIndexGroup">
update tab_index_group
set index_group_name = #{indexGroupName,jdbcType=VARCHAR},
parent_id = #{parentId,jdbcType=INTEGER},
group_chain = #{groupChain,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=TIMESTAMP},
update_time = #{updateTime,jdbcType=TIMESTAMP},
status = #{status,jdbcType=INTEGER}
where index_group_id = #{indexGroupId,jdbcType=INTEGER}
</update>
<select id="getBySelective" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from tab_index_group
where status = 1
<if test="indexGroupName != null ">
and index_group_name = #{indexGroupName}
</if>
<if test="indexGroupId != null ">
and index_group_id &lt;&gt; #{indexGroupId}
</if>
limit 1
</select>
<select id="listIndexGroup" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from tab_index_group where status = 1
</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