Commit ce49205a authored by 鲁鑫's avatar 鲁鑫

整合mybatis-plus3.5.4;

资源库代码迁移
parent 9bed4c77
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
<task:annotation-driven executor="annotationExecutor" /> <task:annotation-driven executor="annotationExecutor" />
<!-- 支持 @Async 注解 --> <!-- 支持 @Async 注解 -->
<task:executor id="annotationExecutor" pool-size="2000"/> <task:executor id="annotationExecutor" pool-size="2000"/>
<import resource="classpath:config/spring/spring-cxf.xml" /> <import resource="classpath:config/spring/spring-cxf.xml" />
<import resource="classpath:activiti-context.xml" /> <import resource="classpath:activiti-context.xml" />
<import resource="classpath:config/spring/spring-dataSource.xml" /> <import resource="classpath:config/spring/spring-dataSource.xml" />
...@@ -55,4 +55,6 @@ ...@@ -55,4 +55,6 @@
&lt;!&ndash; 上科大 &ndash;&gt; &lt;!&ndash; 上科大 &ndash;&gt;
<import resource="classpath:config/spring/spring-tech.xml" />--> <import resource="classpath:config/spring/spring-tech.xml" />-->
<import resource="classpath:config/spring/spring-mybatis-plus.xml"/>
</beans> </beans>
\ No newline at end of file
...@@ -345,6 +345,26 @@ ...@@ -345,6 +345,26 @@
<artifactId>jedis</artifactId> <artifactId>jedis</artifactId>
<version>2.9.0</version> <version>2.9.0</version>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/com.baomidou/mybatis-plus -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus</artifactId>
<version>3.5.4</version>
</dependency>
<!--自3.5.4开始,传统Spring项目集成需要手动引入一下mybatis-spring.-->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.16</version>
</dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>
......
...@@ -184,9 +184,14 @@ ...@@ -184,9 +184,14 @@
<version>4.12</version> <version>4.12</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus</artifactId>
</dependency>
</dependencies> </dependencies>
<build> <build>
<finalName>SSRF-xt</finalName> <finalName>topsun-xt</finalName>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
......
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!-- SqlSessionFactory Config -->
<bean id="sqlSessionFactory" class="com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<!-- <property name="configuration" ref="configuration"/>-->
<property name="mapperLocations" value="classpath:com/huigou/topsun/**/mapper/xml/*.xml"/>
<property name="globalConfig" ref="globalConfig"/>
<property name="plugins">
<array>
<ref bean="mybatisPlusInterceptor"/>
</array>
</property>
</bean>
<!-- <bean id="configuration" class="com.baomidou.mybatisplus.core.MybatisConfiguration">-->
<!-- <property name="useDeprecatedExecutor" value="false"/>-->
<!-- </bean>-->
<bean id="mybatisPlusInterceptor" class="com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor">
<property name="interceptors">
<list>
<ref bean="paginationInnerInterceptor"/>
</list>
</property>
</bean>
<bean id="paginationInnerInterceptor"
class="com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor">
<constructor-arg name="dbType" value="H2"/>
<property name="optimizeJoin" value="true"/>
</bean>
<!-- <bean id="countSqlParser"-->
<!-- class="com.baomidou.mybatisplus.extension.plugins.pagination.optimize.JsqlParserCountOptimize">-->
<!-- <property name="optimizeJoin" value="true"/>-->
<!-- </bean>-->
<bean id="globalConfig" class="com.baomidou.mybatisplus.core.config.GlobalConfig">
<property name="dbConfig" ref="dbConfig"/>
</bean>
<bean id="dbConfig" class="com.baomidou.mybatisplus.core.config.GlobalConfig.DbConfig">
<property name="keyGenerators">
<list>
<bean class="com.baomidou.mybatisplus.extension.incrementer.H2KeyGenerator"/>
</list>
</property>
</bean>
<!-- MyBatis Mapper Scan Config -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.huigou.topsun.**.mapper"/>
</bean>
</beans>
\ No newline at end of file
<%@ page contentType="text/html; charset=utf-8" language="java" %>
<%@ taglib uri="/WEB-INF/taglib.tld" prefix="x" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<x:base include="dialog,grid,combox,comboDialog,attachment"/>
<x:i18n name="topsun"/>
</head>
<body>
<div class="container-fluid">
<h1>hhhhh哈哈哈哈</h1>
</div>
</body>
</html>
...@@ -133,14 +133,6 @@ ...@@ -133,14 +133,6 @@
<groupId>javax.jms</groupId> <groupId>javax.jms</groupId>
<artifactId>jms</artifactId> <artifactId>jms</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-pool</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.springframework</groupId> <groupId>org.springframework</groupId>
<artifactId>spring-jms</artifactId> <artifactId>spring-jms</artifactId>
...@@ -154,6 +146,16 @@ ...@@ -154,6 +146,16 @@
<artifactId>huigou-data</artifactId> <artifactId>huigou-data</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus</artifactId>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
</dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>
......
package com.huigou.topsun.common;
public class CommonController {
public CommonController() {
// TODO Auto-generated constructor stub
}
}
package com.huigou.topsun.config;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.core.config.GlobalConfig;
import com.baomidou.mybatisplus.core.incrementer.IKeyGenerator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.Arrays;
@Configuration
public class MyBatisConfig {
@Bean
public GlobalConfig globalConfiguration() {
GlobalConfig conf = new GlobalConfig();
conf.setDbConfig(new GlobalConfig.DbConfig().setKeyGenerators(Arrays.asList(
// h2 1.x 的写法(默认 2.x 的写法)
new IKeyGenerator() {
@Override
public String executeSql(String incrementerName) {
return "select " + incrementerName + ".nextval";
}
@Override
public DbType dbType() {
return DbType.POSTGRE_SQL;
}
}
)));
return conf;
}
}
package com.huigou.topsun.resource.controller;
import com.huigou.topsun.resource.service.ResourceTypeService;
import com.huigou.topsun.resource.vo.ResourceTypeVo;
import com.huigou.uasp.annotation.ControllerMapping;
import com.huigou.uasp.client.CommonController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
/**
* @Auther: xin.lu
* @Date: 2023/10/25/16:34
* @Description:
*/
//@Tag(name = "资源库")
@Controller
@ControllerMapping("/resource")
public class ResourceController extends CommonController {
protected String getPagePath() {
return "/biz/topsun/resource/";
}
@Resource
private ResourceTypeService resourceTypeService;
public String forwardResourceList(){
return forward("resourceList");
}
//@Operation(summary = "保存资源类型")
public String saveResourceType(@RequestBody ResourceTypeVo resourceTypeVo){
resourceTypeService.saveResourceTypeMain(resourceTypeVo);
return toResult(resourceTypeVo);
}
//@Operation(summary = "修改资源类型")
public String updateResourceType(@RequestBody ResourceTypeVo resourceTypeVo){
resourceTypeService.updateResourceTypeMain(resourceTypeVo);
return toResult(resourceTypeVo);
}
//@Operation(summary = "根据id删除资源")
public String deleteResourceType(@RequestParam("id") Long id){
resourceTypeService.deleteById(id);
return success();
}
//@Operation(summary = "根据id查询资源")
public String findById(@RequestParam("id") Long id){
ResourceTypeVo resourceTypeVo = resourceTypeService.findById(id);
return toResult(resourceTypeVo);
}
//@Operation(summary = "查询全部资源")
public String findList(){
return toResult(resourceTypeService.findList());
}
/*@Operation(summary = "根据表名,递归查询该表及父类字段")
@GetMapping("/findParentResourceFields")
public Result<Set<ResourceFiled>> findParentResourceFields(@RequestParam String tableName){
return Result.ok(resourceTypeService.findParentResourceFileds(tableName));
}*/
//@Operation(summary = "新增资源类型时,根据对象的父类表名,返回父类和超类及所属的字段")
public String findParentResourceTypeAndFields(@RequestParam String tableName){
return toResult(resourceTypeService.findParentResourceTypeAndFields(tableName));
}
//@Operation(summary = "修改/查看资源类型时,根据当前表名,返回自己和父类和超类及所属的字段")
public String findResourceTypeAndFields(@RequestParam String tableName){
return toResult(resourceTypeService.findResourceTypeAndFields(tableName));
}
}
package com.huigou.topsun.resource.controller;
import com.huigou.topsun.resource.service.ResourceFiledService;
import com.huigou.uasp.annotation.ControllerMapping;
import com.huigou.uasp.client.CommonController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.HashMap;
/**
* @Auther: xin.lu
* @Date: 2023/10/31/9:07
* @Description:
*/
//@Tag(name = "资源字段")
@Controller
@ControllerMapping("/resourceField")
public class ResourceFieldController extends CommonController {
@Resource
private ResourceFiledService resourceFiledService;
//@Operation(summary = "根据资源类型id,查询资源字段")
public String getResourceField(@RequestParam("resourceTypeId") Long resourceTypeId){
return toResult(resourceFiledService.findByResourceTypeId(resourceTypeId));
}
//@Operation(summary = "保存资源字段值")
public String saveResourceFiledValue(@RequestBody HashMap<String,Object> map){
return toResult(resourceFiledService.saveResourceFiledValue(map));
}
//@Operation(summary = "修改资源字段值")
public String updateResourceFiledValue(@RequestBody HashMap<String,Object> map){
return toResult(resourceFiledService.saveResourceFiledValue(map));
}
//@Operation(summary = "根据资源类型id,获取资源值")
public String getResourceFieldValue(@RequestParam("resourceTypeId") Long resourceTypeId){
return toResult(resourceFiledService.getResourceFieldValue(resourceTypeId));
}
//@Operation(summary = "根据资源类型id和数据id删除资源值")
public String deleteResourceFiledValue(@RequestParam("resourceTypeId") Long resourceTypeId, @RequestParam("id") Long id){
return toResult(resourceFiledService.deleteResourceFieldValue(resourceTypeId,id));
}
public String getResourceFieldType(@RequestParam("id") Long id){
return toResult(resourceFiledService.findById(id));
}
}
package com.huigou.topsun.resource.domain;
import lombok.Data;
/**
* @Auther: xin.lu
* @Date: 2023/11/03/17:27
* @Description:
*/
@Data
public class ResourceFieldValue {
private String field;
private Object value;
}
package com.huigou.topsun.resource.domain;
import com.baomidou.mybatisplus.annotation.*;
import java.io.Serializable;
import lombok.Data;
/**
* 资源字段设置
* @TableName resource_filed
*/
//@Schema(description = "资源字段设置")
@TableName(value ="resource_filed")
@Data
public class ResourceFiled implements Serializable {
/**
* 资源字段ID
*/
//@Schema(description = "资源字段ID")
@TableId(value = "resource_field_id")
private Long resourceFieldId;
/**
* 所属资源类型
*/
//@Schema(description = "所属资源类型ID")
@TableField(value = "resource_type_id")
private Long resourceTypeId;
/**
* 字段名
*/
//@Schema(description = "字段名")
@TableField(value = "resource_field_name")
private String resourceFieldName;
/**
* 字段显示名
*/
//@Schema(description = "字段显示名")
@TableField(value = "resource_filed_title")
private String resourceFiledTitle;
/**
* 字段类型
*/
//@Schema(description = "字段类型,码表(resourceFieldType))")
@TableField(value = "resource_field_type")
private String resourceFieldType;
/**
* 是否可见
*/
//@Schema(description = "是否可见,码表(resourceFieldShow))")
@TableField(value = "resource_field_show")
private String resourceFieldShow;
/**
* 字段大小
*/
//@Schema(description = "字段大小")
@TableField(value = "resource_field_size")
private Integer resourceFieldSize;
/**
* 整型长度
*/
//@Schema(description = "整型长度")
@TableField(value = "integer_length")
private Integer integerLength;
/**
* 小数点位数
*/
//@Schema(description = "小数点位数")
@TableField(value = "decimal_precision")
private Integer decimalPrecision;
/**
* 序号
*/
//@Schema(description = "序号")
@TableField(value = "sort_num")
private Integer sortNum;
/**
* 对应码表的编码/选择的表的关联字段
*/
//@Schema(description = "对应码表的编码")
@TableField(value = "dict_code")
private String dictCode;
//@Schema(description = "假删除标记(-1已删除,0正常)")
@TableField(value = "deleted")
@TableLogic //逻辑删除
private Integer deleted;
@TableField(exist = false)
private static final long serialVersionUID = 1L;
}
\ No newline at end of file
package com.huigou.topsun.resource.domain;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.util.List;
import lombok.Data;
/**
* 资源分类
* @TableName resource_type
*/
//@Schema(description = "资源类型")
@TableName(value ="resource_type")
@Data
public class ResourceType implements Serializable {
/**
* 资源库类型ID
*/
//@Schema(description = "资源库类型ID")
@TableId(value = "resource_type_id")
private Long resourceTypeId;
/**
* 资源库类型表名
*/
//@Schema(description = "资源库类型表名")
@TableField(value = "resource_table_name")
private String resourceTableName;
/**
* 资源库类型表名称
*/
//@Schema(description = "资源库类型表名称")
@TableField(value = "resource_table_title")
private String resourceTableTitle;
/**
* 父类表名
*/
//@Schema(description = "父类表名")
@TableField(value = "parent_table_name")
private String parentTableName;
/**
* 父类显示名
*/
//@Schema(description = "父类显示名")
@TableField(value = "parent_table_title")
private String parentTableTitle;
/**
* 超类名
*/
//@Schema(description = "超类表名")
@TableField(value = "super_table_name")
private String superTableName;
/**
* 超类显示名
*/
//@Schema(description = "超类显示名")
@TableField(value = "super_table_title")
private String superTableTitle;
@TableField(exist = false)
private static final long serialVersionUID = 1L;
}
\ No newline at end of file
package com.huigou.topsun.resource.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.huigou.topsun.resource.domain.ResourceFieldValue;
import com.huigou.topsun.resource.domain.ResourceFiled;
import com.huigou.topsun.resource.vo.ResourceFiledVo;
import org.apache.ibatis.annotations.Param;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author 16508
* @description 针对表【resource_filed(资源字段设置)】的数据库操作Mapper
* @createDate 2023-10-25 16:08:43
* @Entity com.topsun.resource.domain.ResourceFiled
*/
public interface ResourceFiledMapper extends BaseMapper<ResourceFiled> {
void deleteByResourceTypeId(@Param("resourceTypeId") Long resourceTypeId);
List<ResourceFiled> findByResourceTypeId(@Param("resourceTypeId") Long resourceTypeId);
void createTable(@Param("tableName")String tableName,@Param("tableTile")String tableTile, @Param("resourceFields")List<ResourceFiledVo> resourceFields);
int updateTableAddColumn(@Param("tableName")String tableName, @Param("resourceFields")List<ResourceFiledVo> resourceFields);
int updateTableChangeColumn(@Param("tableName")String tableName, @Param("resourceFields")List<ResourceFiledVo> resourceFields);
int insertData(@Param("tableName")String tableName,@Param("resourceFieldValues")List<ResourceFieldValue> resourceFieldValues);
int updateData(@Param("id") Long id, @Param("tableName")String tableName,@Param("resourceFieldValues")List<ResourceFieldValue> resourceFieldValues);
List<Map<String,Object>> selectDataList(@Param("tableName")String tableName);
int deleteDataById(@Param("tableName")String tableName,@Param("id") Long id);
void dropTableByResourceTableName(@Param("tableName") String tableName);
}
package com.huigou.topsun.resource.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.huigou.topsun.resource.domain.ResourceType;
import com.huigou.topsun.resource.vo.ResourceTypeVo;
import java.util.List;
/**
* @author 16508
* @description 针对表【resource_type(资源分类)】的数据库操作Mapper
* @createDate 2023-10-25 16:08:43
* @Entity com.topsun.resource.domain.ResourceType
*/
public interface ResourceTypeMapper extends BaseMapper<ResourceType> {
List<ResourceTypeVo> noteTree();
}
<?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.huigou.topsun.resource.mapper.ResourceFiledMapper">
<resultMap id="BaseResultMap" type="com.huigou.topsun.resource.domain.ResourceFiled">
<id property="resourceFieldId" column="resource_field_id" jdbcType="BIGINT"/>
<result property="resourceTypeId" column="resource_type_id" jdbcType="BIGINT"/>
<result property="resourceFieldName" column="resource_field_name" jdbcType="VARCHAR"/>
<result property="resourceFiledTitle" column="resource_filed_title" jdbcType="VARCHAR"/>
<result property="resourceFieldType" column="resource_field_type" jdbcType="VARCHAR"/>
<result property="resourceFieldShow" column="resource_field_show" jdbcType="VARCHAR"/>
<result property="sortNum" column="sort_num" jdbcType="INTEGER"/>
<result property="dictCode" column="dict_code" jdbcType="VARCHAR"/>
</resultMap>
<sql id="Base_Column_List">
resource_field_id,resource_type_id,resource_field_name,
resource_filed_title,resource_field_type,resource_field_show,
sort_num,dict_table,dict_code,
dict_text
</sql>
<sql id="matchFieldType">
<if test="resourceField.resourceFieldName != null and resourceField.resourceFieldName != ''">
${resourceField.resourceFieldName}
</if>
<if test="resourceField.resourceFieldType != null and resourceField.resourceFieldType != ''">
<if test="resourceField.resourceFieldType == 'string'">
varchar( ${resourceField.resourceFieldSize} )
</if>
<if test="resourceField.resourceFieldType == 'decimal' or resourceField.resourceFieldType == 'float' or resourceField.resourceFieldType == 'double'">
decimal( ${resourceField.integerLength},${resourceField.decimalPrecision} )
</if>
<if test="resourceField.resourceFieldType == 'datetime'">
datetime(0)
</if>
<if test="resourceField.resourceFieldType == 'text'">
text(0)
</if>
</if>
COMMENT '${resourceField.resourceFiledTitle}'
</sql>
<delete id="deleteByResourceTypeId">
delete from resource_filed where resource_type_id = #{resourceTypeId}
</delete>
<select id="findByResourceTypeId" resultType="com.huigou.topsun.resource.domain.ResourceFiled">
select <include refid="Base_Column_List"/> from resource_filed where resource_type_id = #{resourceTypeId}
</select>
<update id="createTable">
create table ${tableName}
( id bigint(0) COMMENT '主键ID',
<foreach collection="resourceFields" item="resourceField" separator=",">
<include refid="matchFieldType"/>
</foreach>
,PRIMARY KEY (id) USING BTREE
) COMMENT '${tableTile}';
</update>
<update id="updateTableAddColumn">
alter table ${tableName} add column
<foreach collection="resourceFields" item="resourceField" separator=",">
<include refid="matchFieldType"/>
</foreach>
</update>
<update id="updateTableChangeColumn">
alter table ${tableName}
<foreach collection="resourceFields" item="resourceField" separator=",">
change column
<if test="resourceField.dbResourceFieldName != null and resourceField.dbResourceFieldName != ''">
${resourceField.dbResourceFieldName}
</if>
<include refid="matchFieldType"/>
</foreach>
</update>
<insert id="insertData">
insert into ${tableName}
<foreach collection="resourceFieldValues" item="resourceFieldValue" separator="," open="(" close=")">
<if test="resourceFieldValue.field != null and resourceFieldValue.field != ''">
${resourceFieldValue.field}
</if>
</foreach>
values
<foreach collection="resourceFieldValues" item="resourceFieldValue" separator="," open="(" close=")">
<if test="resourceFieldValue.value != null and resourceFieldValue.value != ''">
${resourceFieldValue.value}
</if>
</foreach>
</insert>
<update id="updateData">
update ${tableName} set
<foreach collection="resourceFieldValues" item="resourceFieldValue" separator=",">
${resourceFieldValue.field} = ${resourceFieldValue.value}
</foreach>
where id = #{id}
</update>
<select id="selectDataList" resultType="java.util.Map" parameterType="java.lang.String">
select * from ${tableName}
</select>
<delete id="deleteDataById">
delete from ${tableName} where id = #{id}
</delete>
<update id="dropTableByResourceTableName" parameterType="java.lang.String">
drop table ${tableName}
</update>
</mapper>
<?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.huigou.topsun.resource.mapper.ResourceTypeMapper">
<resultMap id="BaseResultMap" type="com.huigou.topsun.resource.domain.ResourceType">
<id property="resourceTypeId" column="resource_type_id" jdbcType="BIGINT"/>
<result property="resourceTableName" column="resource_table_name" jdbcType="VARCHAR"/>
<result property="resourceTableTitle" column="resource_table_title" jdbcType="VARCHAR"/>
<result property="parentTableName" column="parent_table_name" jdbcType="VARCHAR"/>
<result property="parentTableTitle" column="parent_table_title" jdbcType="VARCHAR"/>
<result property="superTableName" column="super_table_name" jdbcType="VARCHAR"/>
<result property="superTableTitle" column="super_table_title" jdbcType="VARCHAR"/>
</resultMap>
<resultMap id="NodeTreeResult" type="com.huigou.topsun.resource.vo.ResourceTypeVo"
extends="BaseResultMap">
<collection property="childNode" column="resource_table_name" ofType="com.huigou.topsun.resource.vo.ResourceTypeVo"
javaType="java.util.ArrayList" select="nextNoteTree">
</collection>
</resultMap>
<sql id="Base_Column_List">
resource_type_id,resource_table_name,resource_table_title,
parent_table_name,parent_table_title,super_table_name,
super_table_title
</sql>
<select id="noteTree" resultMap="NodeTreeResult">
select
<include refid="Base_Column_List"/>
from resource_type
where parent_table_name is null or parent_table_name = ''
</select>
<select id="nextNoteTree" resultMap="NodeTreeResult">
select
<include refid="Base_Column_List"/>
from resource_type
where parent_table_name=#{resource_table_name}
</select>
</mapper>
package com.huigou.topsun.resource.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.huigou.topsun.resource.domain.ResourceFiled;
import com.huigou.topsun.resource.vo.ResourceFiledVo;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author 16508
* @description 针对表【resource_filed(资源字段设置)】的数据库操作Service
* @createDate 2023-10-25 16:08:43
*/
public interface ResourceFiledService extends IService<ResourceFiled> {
ResourceFiledVo saveResourceFiled(ResourceFiledVo resourceFiledVo);
void createTable(List<ResourceFiledVo> resourceFileds, String tableName, String tableTile);
void updateTableAddColumn(List<ResourceFiledVo> resourceFileds, String tableName);
void updateTableChangeColumn(List<ResourceFiledVo> resourceFileds, String tableName);
StringBuffer matchFieldType(ResourceFiledVo resourceFiledVo, StringBuffer sql);
ResourceFiledVo updateResourceFiled(ResourceFiledVo resourceFiled);
void deleteById(Long id);
void deleteByResourceTypeId(Long resourceFieldId);
ResourceFiledVo findById(Long id);
List<ResourceFiledVo> findList();
List<ResourceFiledVo> findByResourceTypeId(Long resourceTypeId);
int saveResourceFiledValue(HashMap<String,Object> obj);
List<Map<String, Object>> getResourceFieldValue(Long resourceTypeId);
int deleteResourceFieldValue(Long resourceTypeId, Long id);
void dropTableByResourceName(String tableName);
}
package com.huigou.topsun.resource.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.huigou.topsun.resource.domain.ResourceType;
import com.huigou.topsun.resource.vo.ResourceFiledVo;
import com.huigou.topsun.resource.vo.ResourceTypeVo;
import java.util.List;
import java.util.Set;
/**
* @author 16508
* @description 针对表【resource_type(资源分类)】的数据库操作Service
* @createDate 2023-10-25 16:08:43
*/
public interface ResourceTypeService extends IService<ResourceType> {
ResourceTypeVo saveResourceTypeMain(ResourceTypeVo resourceTypeVo);
ResourceTypeVo updateResourceTypeMain(ResourceTypeVo resourceType);
void deleteById(Long id);
ResourceTypeVo findById(Long id);
List<ResourceTypeVo> findList();
ResourceTypeVo findByTableName(String tableName);
List<ResourceFiledVo> findParentResourceFileds(String tableName);
void findParentMenusRecursively(String tableName, Set<ResourceFiledVo> resourceFileds);
ResourceTypeVo findParentResourceTypeAndFields(String tableName);
ResourceTypeVo findResourceTypeAndFields(String tableName);
}
package com.huigou.topsun.resource.service.impl;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huigou.topsun.resource.domain.ResourceFieldValue;
import com.huigou.topsun.resource.domain.ResourceFiled;
import com.huigou.topsun.resource.domain.ResourceType;
import com.huigou.topsun.resource.mapper.ResourceFiledMapper;
import com.huigou.topsun.resource.mapper.ResourceTypeMapper;
import com.huigou.topsun.resource.service.ResourceFiledService;
//import com.huigou.topsun.resource.util.IdGenerator;
import com.huigou.topsun.resource.vo.ResourceFiledVo;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.*;
/**
* @author 16508
* @description 针对表【resource_filed(资源字段设置)】的数据库操作Service实现
* @createDate 2023-10-25 16:08:43
*/
@Service
public class ResourceFiledServiceImpl extends ServiceImpl<ResourceFiledMapper, ResourceFiled>
implements ResourceFiledService {
@Resource
private ResourceFiledMapper resourceFiledMapper;
@Resource
private ResourceTypeMapper resourceTypeMapper;
//@Resource
//private IdGenerator idGenerator;
@Override
public ResourceFiledVo saveResourceFiled(ResourceFiledVo resourceFiledVo) {
ResourceFiled resourceFiled = ResourceFiledVo.getResourceFiled(resourceFiledVo);
this.save(resourceFiled);
resourceFiledVo.setResourceFieldId(resourceFiled.getResourceFieldId());
return resourceFiledVo;
}
@Override
public void createTable(List<ResourceFiledVo> resourceFileds, String tableName, String tableTile){
resourceFiledMapper.createTable(tableName,tableTile,resourceFileds);
}
@Override
public void updateTableAddColumn(List<ResourceFiledVo> resourceFileds, String tableName) {
resourceFiledMapper.updateTableAddColumn(tableName,resourceFileds);
}
@Override
public void updateTableChangeColumn(List<ResourceFiledVo> resourceFileds, String tableName){
resourceFiledMapper.updateTableChangeColumn(tableName,resourceFileds);
}
@Override
public StringBuffer matchFieldType(ResourceFiledVo resourceField,StringBuffer sql){
/*//默认或者自定义字符串大小
if ("string".equals(resourceField.getResourceFieldType())){
sql.append(" varchar(").append(resourceField.getResourceFieldSize() == null ? 255 : resourceField.getResourceFieldSize()).append(")");
} else if ("number".equals(resourceField.getResourceFieldType())) {//数字
sql.append(" int(0)");
}else if ("datetime".equals(resourceField.getResourceFieldType())){//日期
sql.append(" datetime(0)");
}else if ("long".equals(resourceField.getResourceFieldType())){//长整形
sql.append(" bigint(0)");
} else if ("text".equals(resourceField.getResourceFieldType())) {//文本
sql.append(" text");
} else if ("decimal".equals(resourceField.getResourceFieldType())) {//数值
sql.append(" decimal(").append(resourceField.getIntegerLength()).append(",").append(resourceField.getDecimalPrecision()).append(")");
} else if ("float".equals(resourceField.getResourceFieldType())) {//单精度
sql.append(" float(").append(resourceField.getIntegerLength()).append(",").append(resourceField.getDecimalPrecision()).append(")");
} else if ("double".equals(resourceField.getResourceFieldType())) {//双精度
sql.append(" double(").append(resourceField.getIntegerLength()).append(",").append(resourceField.getDecimalPrecision()).append(")");
}*/
return sql;
}
@Override
public ResourceFiledVo updateResourceFiled(ResourceFiledVo resourceFiledVo) {
this.save(ResourceFiledVo.getResourceFiled(resourceFiledVo));
return resourceFiledVo;
}
@Override
public void deleteById(Long id) {
this.removeById(id);
}
@Override
public void deleteByResourceTypeId(Long resourceTypeId) {
LambdaQueryWrapper<ResourceFiled> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(ResourceFiled::getResourceTypeId,resourceTypeId);
this.remove(queryWrapper);
}
@Override
public ResourceFiledVo findById(Long id) {
ResourceFiled resourceFiled = this.getById(id);
return ResourceFiledVo.getResourceFiledVo(resourceFiled);
}
@Override
public List<ResourceFiledVo> findList() {
List<ResourceFiled> list = this.list();
return JSON.parseArray(JSON.toJSONString(list),ResourceFiledVo.class);
}
@Override
public List<ResourceFiledVo> findByResourceTypeId(Long resourceTypeId) {
LambdaQueryWrapper<ResourceFiled> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(ResourceFiled::getResourceTypeId,resourceTypeId);
List<ResourceFiled> list = this.list(queryWrapper);
return JSON.parseArray(JSON.toJSONString(list), ResourceFiledVo.class);
}
@Override
public int saveResourceFiledValue(HashMap<String,Object> map) {
Long resourceTypeId = (Long) map.get("resourceTypeId");
ResourceType resourceType = resourceTypeMapper.selectById(resourceTypeId);
//获取表名
String tableName = resourceType.getResourceTableName();
//获取字段
List<ResourceFiledVo> resourceFiledList = this.findByResourceTypeId(resourceTypeId);
//自动生成长整型id值
List<ResourceFieldValue> resourceFieldValues = this.dealFieldAndValue(resourceFiledList, map);
Long id = (Long) map.get("id");
if (id == null){
return resourceFiledMapper.insertData(tableName,resourceFieldValues);
}else {
return resourceFiledMapper.updateData((Long) map.get("id"),tableName,resourceFieldValues);
}
}
/**
* 组装字段和值
* @param resourceFiledList
* @param map
* @return
*/
public List<ResourceFieldValue> dealFieldAndValue(List<ResourceFiledVo> resourceFiledList, HashMap<String, Object> map){
Set<String> keySet = map.keySet();
List<ResourceFieldValue> resourceFieldValues = new ArrayList<>();
resourceFiledList
.stream()
.forEach(resourceFiled -> {
for (String key : keySet) {
if (resourceFiled.getResourceFieldName().equals(key)){
ResourceFieldValue resourceFieldValue = new ResourceFieldValue();
resourceFieldValue.setField(key);
//如果值是字符串,文本,日期格式的需要加英文状态下的引号: ''
if ("string".equals(resourceFiled.getResourceFieldType()) ||
"datetime".equals(resourceFiled.getResourceFieldType()) ||
"text".equals(resourceFiled.getResourceFieldType()) ){
resourceFieldValue.setValue("'" + map.get(key) + "'");
}else {
resourceFieldValue.setValue(map.get(key));
}
resourceFieldValues.add(resourceFieldValue);
}
}
});
Long id = (Long) map.get("id");
if (id == null){
ResourceFieldValue resourceFieldValue = new ResourceFieldValue();
resourceFieldValue.setField("id");
//Long nextedId = idGenerator.nextId(resourceFieldValue);
resourceFieldValue.setValue(null);
resourceFieldValues.add(resourceFieldValue);
}
return resourceFieldValues;
}
@Override
public List<Map<String, Object>> getResourceFieldValue(Long resourceTypeId){
ResourceType resourceType = resourceTypeMapper.selectById(resourceTypeId);
//获取表名
String tableName = resourceType.getResourceTableName();
List<Map<String, Object>> maps = resourceFiledMapper.selectDataList(tableName);
return maps;
}
@Override
public int deleteResourceFieldValue(Long resourceTypeId, Long id){
ResourceType resourceType = resourceTypeMapper.selectById(resourceTypeId);
//获取表名
String tableName = resourceType.getResourceTableName();
return resourceFiledMapper.deleteDataById(tableName,id);
}
@Override
public void dropTableByResourceName(String tableName) {
resourceFiledMapper.dropTableByResourceTableName(tableName);
}
}
//package com.huigou.topsun.resource.util;
//
//import cn.hutool.core.lang.Snowflake;
//import cn.hutool.core.util.IdUtil;
//import com.baomidou.mybatisplus.core.incrementer.IKeyGenerator;
//import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
//import org.hibernate.HibernateException;
//import org.hibernate.engine.spi.SessionImplementor;
//import org.hibernate.id.IdentifierGenerator;
//import org.springframework.stereotype.Component;
//
//import java.io.Serializable;
//
//@Component
//public class IdGenerator implements IdentifierGenerator {
// @Override
// public Long nextId(Object entity) {
// //使用 hutools 雪花算法生成分布式ID
// //参数1为终端ID
// //参数2为数据中心ID
// Snowflake snowflake = IdUtil.getSnowflake(1, 1);
// return snowflake.nextId();
// }
//
// @Override
// public Serializable generate(SessionImplementor sessionImplementor, Object o) throws HibernateException {
// return null;
// }
//}
package com.huigou.topsun.resource.util;
import net.sourceforge.pinyin4j.PinyinHelper;
public class PinyinHelperUtil {
/**
* 返回中文的首字母
*
* @param str
* @return
*/
public static String getPinYinHeadChar(String str) {
String convert = "";
for (int j = 0; j < str.length(); j++) {
char word = str.charAt(j);
String[] pinyinArray = PinyinHelper.toHanyuPinyinStringArray(word);
if (pinyinArray != null) {
convert += pinyinArray[0].charAt(0);
} else {
convert += word;
}
}
return convert;
}
}
\ No newline at end of file
package com.huigou.topsun.resource.vo;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.huigou.topsun.resource.domain.ResourceFiled;
import lombok.Data;
import java.io.Serializable;
/**
* 资源字段设置
* @TableName resource_filed
*/
//@Schema(description = "资源字段设置")
@Data
public class ResourceFiledVo implements Serializable {
/**
* 资源字段ID
*/
//@Schema(description = "资源字段ID")
private Long resourceFieldId;
/**
* 所属资源类型
*/
//@Schema(description = "所属资源类型ID")
private Long resourceTypeId;
/**
* 字段名
*/
//@Schema(description = "字段名")
private String resourceFieldName;
/**
* 字段显示名
*/
//@Schema(description = "字段显示名")
private String resourceFiledTitle;
/**
* 字段类型
*/
//@Schema(description = "字段类型,码表(resourceFieldType))")
private String resourceFieldType;
/**
* 是否可见
*/
//@Schema(description = "是否可见,码表(resourceFieldShow))")
private String resourceFieldShow;
/**
* 字段大小
*/
//@Schema(description = "字段大小")
private Integer resourceFieldSize;
/**
* 整型长度
*/
//@Schema(description = "整型长度")
private Integer integerLength;
/**
* 小数点位数
*/
//@Schema(description = "小数点位数")
private Integer decimalPrecision;
/**
* 序号
*/
//@Schema(description = "序号")
private Integer sortNum;
/**
* 对应码表的编码/选择的表的关联字段
*/
//@Schema(description = "对应码表的编码")
private String dictCode;
//@Schema(description = "假删除标记(-1已删除,0正常)")
@TableLogic() //逻辑删除
private Integer deleted;
private String dbResourceFieldName;
public static ResourceFiledVo getResourceFiledVo(ResourceFiled resourceFiled){
return JSON.parseObject(JSON.toJSONString(resourceFiled),ResourceFiledVo.class);
}
public static ResourceFiled getResourceFiled(ResourceFiledVo resourceFiledVo){
return JSON.parseObject(JSON.toJSONString(resourceFiledVo),ResourceFiled.class);
}
}
\ No newline at end of file
package com.huigou.topsun.resource.vo;
import com.alibaba.fastjson.JSON;
import com.huigou.topsun.resource.domain.ResourceType;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
* 资源分类
* @TableName resource_type
*/
//@Schema(description = "资源类型")
@Data
public class ResourceTypeVo implements Serializable {
/**
* 资源库类型ID
*/
//@Schema(description = "资源库类型ID")
private Long resourceTypeId;
/**
* 资源库类型表名
*/
//@Schema(description = "资源库类型表名")
private String resourceTableName;
/**
* 资源库类型表名称
*/
//@Schema(description = "资源库类型表名称")
private String resourceTableTitle;
/**
* 父类表名
*/
//@Schema(description = "父类表名")
private String parentTableName;
/**
* 父类显示名
*/
//@Schema(description = "父类显示名")
private String parentTableTitle;
/**
* 超类名
*/
//@Schema(description = "超类表名")
private String superTableName;
/**
* 超类显示名
*/
//@Schema(description = "超类显示名")
private String superTableTitle;
List<ResourceFiledVo> resourceFileds;
/**
* 子节点
*/
private List<ResourceTypeVo> childNode;
public static ResourceTypeVo getResourceTypeVo(ResourceType resourceType){
return JSON.parseObject(JSON.toJSONString(resourceType),ResourceTypeVo.class);
}
public static ResourceType getResourceType(ResourceTypeVo resourceTypeVo){
return JSON.parseObject(JSON.toJSONString(resourceTypeVo),ResourceType.class);
}
}
\ 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