parent
88d2830fdb
commit
a8ae3e0b1d
@ -0,0 +1,29 @@
|
||||
package org.opsli.api.wrapper.system.dict;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* @BelongsProject: opsli-boot
|
||||
* @BelongsPackage: org.opsli.modulars.test.entity
|
||||
* @Author: Parker
|
||||
* @CreateTime: 2020-09-16 17:33
|
||||
* @Description: 数据字典 - 工具类用
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class DictModel {
|
||||
|
||||
/** 类型编号 - 冗余 */
|
||||
private String typeCode;
|
||||
|
||||
/** 字典名称 */
|
||||
private String dictName;
|
||||
|
||||
/** 字典值 */
|
||||
private String dictValue;
|
||||
|
||||
/** 消息 */
|
||||
private SysDictDetailModel model;
|
||||
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
package org.opsli.api.wrapper.system.dict;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelIgnore;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.opsli.api.base.warpper.ApiWrapper;
|
||||
import org.opsli.common.annotation.validation.ValidationArgs;
|
||||
import org.opsli.common.annotation.validation.ValidationArgsMax;
|
||||
import org.opsli.common.enums.ValiArgsType;
|
||||
import org.opsli.plugins.excel.annotation.CellStyleFormat;
|
||||
|
||||
/**
|
||||
* @BelongsProject: opsli-boot
|
||||
* @BelongsPackage: org.opsli.modulars.test.entity
|
||||
* @Author: Parker
|
||||
* @CreateTime: 2020-09-16 17:33
|
||||
* @Description: 数据字典 - 明细
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class SysDictDetailModel extends ApiWrapper {
|
||||
|
||||
|
||||
/** 字典ID */
|
||||
@ApiModelProperty(value = "字典类型ID")
|
||||
@ExcelIgnore
|
||||
@ValidationArgs(ValiArgsType.IS_NOT_NULL)
|
||||
private String typeId;
|
||||
|
||||
/** 类型编号 - 冗余 */
|
||||
@ApiModelProperty(value = "字典类型Code")
|
||||
@ExcelIgnore
|
||||
// 验证器
|
||||
@ValidationArgs({ValiArgsType.IS_NOT_NULL, ValiArgsType.IS_GENERAL})
|
||||
@ValidationArgsMax(120)
|
||||
private String typeCode;
|
||||
|
||||
/** 字典名称 */
|
||||
@ApiModelProperty(value = "字典名称")
|
||||
@ExcelProperty(value = "字典名称", order = 1)
|
||||
@CellStyleFormat
|
||||
// 验证器
|
||||
@ValidationArgs({ValiArgsType.IS_NOT_NULL, ValiArgsType.IS_GENERAL_WITH_CHINESE})
|
||||
@ValidationArgsMax(120)
|
||||
private String dictName;
|
||||
|
||||
/** 字典值 */
|
||||
@ApiModelProperty(value = "字典值")
|
||||
@ExcelProperty(value = "字典值", order = 2)
|
||||
@CellStyleFormat
|
||||
// 验证器
|
||||
@ValidationArgs({ValiArgsType.IS_NOT_NULL})
|
||||
@ValidationArgsMax(120)
|
||||
private String dictValue;
|
||||
|
||||
/** 是否内置数据 */
|
||||
@ApiModelProperty(value = "是否内置数据")
|
||||
@ExcelProperty(value = "是否内置数据", order = 2)
|
||||
@CellStyleFormat
|
||||
// 验证器
|
||||
@ValidationArgs({ValiArgsType.IS_NOT_NULL})
|
||||
private Character izLock;
|
||||
|
||||
/** 排序 */
|
||||
@ApiModelProperty(value = "排序")
|
||||
@ExcelProperty(value = "排序", order = 2)
|
||||
@CellStyleFormat
|
||||
// 验证器
|
||||
@ValidationArgs({ValiArgsType.IS_NOT_NULL, ValiArgsType.IS_NUMBER})
|
||||
private Integer sortNo;
|
||||
|
||||
/** 备注 */
|
||||
@ApiModelProperty(value = "备注")
|
||||
@ExcelProperty(value = "备注", order = 2)
|
||||
@CellStyleFormat
|
||||
// 验证器
|
||||
@ValidationArgsMax(255)
|
||||
private String remark;
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
package org.opsli.api.wrapper.system.dict;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.opsli.api.base.warpper.ApiWrapper;
|
||||
import org.opsli.common.annotation.validation.ValidationArgs;
|
||||
import org.opsli.common.annotation.validation.ValidationArgsMax;
|
||||
import org.opsli.common.enums.ValiArgsType;
|
||||
import org.opsli.plugins.excel.annotation.CellStyleFormat;
|
||||
|
||||
/**
|
||||
* @BelongsProject: opsli-boot
|
||||
* @BelongsPackage: org.opsli.modulars.test.entity
|
||||
* @Author: Parker
|
||||
* @CreateTime: 2020-09-16 17:33
|
||||
* @Description: 数据字典
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class SysDictModel extends ApiWrapper {
|
||||
|
||||
|
||||
|
||||
/** 字典类型编号 */
|
||||
@ApiModelProperty(value = "字典类型编号")
|
||||
@ExcelProperty(value = "字典类型编号", order = 1)
|
||||
@CellStyleFormat
|
||||
// 验证器
|
||||
@ValidationArgs({ValiArgsType.IS_NOT_NULL, ValiArgsType.IS_GENERAL})
|
||||
@ValidationArgsMax(120)
|
||||
private String typeCode;
|
||||
|
||||
/** 字典类型名称 */
|
||||
@ApiModelProperty(value = "字典类型名称")
|
||||
@ExcelProperty(value = "字典类型名称", order = 2)
|
||||
@CellStyleFormat
|
||||
// 验证器
|
||||
@ValidationArgs({ValiArgsType.IS_NOT_NULL, ValiArgsType.IS_GENERAL_WITH_CHINESE})
|
||||
@ValidationArgsMax(120)
|
||||
private String typeName;
|
||||
|
||||
/** 是否内置数据 */
|
||||
@ApiModelProperty(value = "是否内置数据")
|
||||
@ExcelProperty(value = "是否内置数据", order = 3)
|
||||
@CellStyleFormat
|
||||
// 验证器
|
||||
@ValidationArgs(ValiArgsType.IS_NOT_NULL)
|
||||
private Character izLock;
|
||||
|
||||
/** 备注 */
|
||||
@ApiModelProperty(value = "备注")
|
||||
@ExcelProperty(value = "备注", order = 4)
|
||||
@CellStyleFormat
|
||||
// 验证器
|
||||
@ValidationArgsMax(255)
|
||||
private String remark;
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package org.opsli.common.constants;
|
||||
|
||||
/**
|
||||
* @BelongsProject: opsli-boot
|
||||
* @BelongsPackage: org.opsli.common.constants
|
||||
* @Author: Parker
|
||||
* @CreateTime: 2020-09-16 17:42
|
||||
* @Description: 字典缓存 常量
|
||||
*/
|
||||
public interface DictConstants {
|
||||
|
||||
/** 缓存前缀 */
|
||||
String CACHE_PREFIX_NAME = "dict:name:";
|
||||
|
||||
/** 缓存前缀 */
|
||||
String CACHE_PREFIX_VALUE = "dict:value:";
|
||||
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package org.opsli.core.cache.pushsub.enums;
|
||||
|
||||
/**
|
||||
* @BelongsProject: opsli-boot
|
||||
* @BelongsPackage: org.opsli.core.cache.pushsub.enums
|
||||
* @Author: Parker
|
||||
* @CreateTime: 2020-09-16 22:28
|
||||
* @Description: 缓存操作类型
|
||||
*/
|
||||
public enum DictModelType {
|
||||
|
||||
/** 对象 */
|
||||
OBJECT,
|
||||
|
||||
/** 集合 */
|
||||
COLLECTION,
|
||||
|
||||
;
|
||||
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package org.opsli.core.persistence.querybuilder;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import org.opsli.core.base.entity.BaseEntity;
|
||||
|
||||
/**
|
||||
* @BelongsProject: opsli-boot
|
||||
* @BelongsPackage: org.opsli.core.persistence.querybuilder
|
||||
* @Author: Parker
|
||||
* @CreateTime: 2020-09-21 23:57
|
||||
* @Description: Web 条件构造器
|
||||
*/
|
||||
public class GenQueryBuilder<T extends BaseEntity> implements QueryBuilder<T> {
|
||||
|
||||
|
||||
/**
|
||||
* 构造函数 只是生产 查询器
|
||||
*/
|
||||
public GenQueryBuilder(){
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryWrapper<T> build() {
|
||||
QueryWrapper<T> queryWrapper = new QueryWrapper<>();
|
||||
return queryWrapper;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package org.opsli.core.persistence.querybuilder;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import org.opsli.core.base.entity.BaseEntity;
|
||||
|
||||
|
||||
/**
|
||||
* @BelongsProject: opsli-boot
|
||||
* @BelongsPackage: org.opsli.core.persistence.querybuilder
|
||||
* @Author: Parker
|
||||
* @CreateTime: 2020-09-21 23:53
|
||||
* @Description: 查询构造器
|
||||
*/
|
||||
public interface QueryBuilder<T extends BaseEntity> {
|
||||
|
||||
/**
|
||||
* 构造器
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
QueryWrapper<T> build();
|
||||
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package org.opsli.core.persistence.querybuilder.chain;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import org.opsli.core.base.entity.BaseEntity;
|
||||
|
||||
/**
|
||||
* @BelongsProject: opsli-boot
|
||||
* @BelongsPackage: org.opsli.core.persistence.querybuilder.chain
|
||||
* @Author: Parker
|
||||
* @CreateTime: 2020-09-22 10:35
|
||||
* @Description: 查询构建器责任链
|
||||
*/
|
||||
public interface QueryBuilderChain {
|
||||
|
||||
/**
|
||||
* 执行
|
||||
* @param wrapper
|
||||
* @param <T>
|
||||
*/
|
||||
<T extends BaseEntity> QueryWrapper<T> handler(Class<T> entityClazz, QueryWrapper<T> wrapper);
|
||||
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
package org.opsli.core.persistence.querybuilder.chain;
|
||||
|
||||
import cn.hutool.core.util.ReflectUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.opsli.common.constants.MyBatisConstants;
|
||||
import org.opsli.common.utils.HumpUtil;
|
||||
import org.opsli.core.base.entity.BaseEntity;
|
||||
import org.opsli.core.utils.UserUtil;
|
||||
|
||||
/**
|
||||
* @BelongsProject: opsli-boot
|
||||
* @BelongsPackage: org.opsli.core.tenant
|
||||
* @Author: Parker
|
||||
* @CreateTime: 2020-09-22 00:50
|
||||
* @Description: 多租户赋值处理
|
||||
*/
|
||||
public class TenantHandler implements QueryBuilderChain{
|
||||
|
||||
/**
|
||||
* 子 责任链
|
||||
*/
|
||||
private QueryBuilderChain queryBuilderChain;
|
||||
|
||||
|
||||
public TenantHandler(){}
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
* @param queryBuilderChain 责任链
|
||||
*/
|
||||
public TenantHandler(QueryBuilderChain queryBuilderChain){
|
||||
this.queryBuilderChain = queryBuilderChain;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询构建器处理
|
||||
* @param entityClazz
|
||||
* @param wrapper
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public <T extends BaseEntity> QueryWrapper<T> handler(Class<T> entityClazz, QueryWrapper<T> wrapper) {
|
||||
// 执行责任链
|
||||
if(queryBuilderChain != null){
|
||||
wrapper = queryBuilderChain.handler(entityClazz, wrapper);
|
||||
}
|
||||
|
||||
// 判断多租户
|
||||
boolean tenantFlag = ReflectUtil.hasField(entityClazz, MyBatisConstants.FIELD_TENANT);
|
||||
if(tenantFlag) {
|
||||
String tenantId = UserUtil.getTenantId();
|
||||
if (StringUtils.isNotEmpty(tenantId)) {
|
||||
wrapper.eq(HumpUtil.humpToUnderline(MyBatisConstants.FIELD_TENANT), tenantId);
|
||||
}
|
||||
}
|
||||
return wrapper;
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,274 @@
|
||||
package org.opsli.core.utils;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.opsli.api.base.result.ResultVo;
|
||||
import org.opsli.api.web.system.dict.DictDetailApi;
|
||||
import org.opsli.api.wrapper.system.dict.DictModel;
|
||||
import org.opsli.api.wrapper.system.dict.SysDictDetailModel;
|
||||
import org.opsli.common.constants.DictConstants;
|
||||
import org.opsli.core.cache.local.CacheUtil;
|
||||
import org.opsli.plugins.redis.RedisLockPlugins;
|
||||
import org.opsli.plugins.redis.RedisPlugin;
|
||||
import org.opsli.plugins.redis.lock.RedisLock;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @BelongsProject: opsli-boot
|
||||
* @BelongsPackage: org.opsli.core.utils
|
||||
* @Author: Parker
|
||||
* @CreateTime: 2020-09-22 11:17
|
||||
* @Description: 字典工具类
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class DictUtil {
|
||||
|
||||
/** Redis插件 */
|
||||
private static RedisPlugin redisPlugin;
|
||||
|
||||
/** Redis分布式锁 */
|
||||
private static RedisLockPlugins redisLockPlugins;
|
||||
|
||||
/** 字典Service */
|
||||
private static DictDetailApi dictDetailApi;
|
||||
|
||||
|
||||
/**
|
||||
* 根据 字典值 取 字典名称
|
||||
* @param typeCode 字典类型Code
|
||||
* @param dictValue 字典值
|
||||
* @param defaultVal 默认值
|
||||
* @return
|
||||
*/
|
||||
public static String getDictNameByValue(String typeCode, String dictValue, String defaultVal){
|
||||
try {
|
||||
String dictName = "";
|
||||
SysDictDetailModel cacheModel = CacheUtil.getHash(DictConstants.CACHE_PREFIX_VALUE + typeCode,
|
||||
dictValue, SysDictDetailModel.class);
|
||||
if (cacheModel != null){
|
||||
dictName = cacheModel.getDictName();
|
||||
}
|
||||
if (StringUtils.isNotEmpty(dictName)) return dictName;
|
||||
|
||||
|
||||
// 防止缓存穿透判断
|
||||
boolean hasNilFlag = CacheUtil.hasNilFlag("dict:" + typeCode + ":" + dictValue);
|
||||
if(hasNilFlag){
|
||||
return defaultVal;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 锁凭证 redisLock 贯穿全程
|
||||
RedisLock redisLock = new RedisLock();
|
||||
redisLock.setLockName("dictLock:" + typeCode + ":" + dictValue)
|
||||
.setAcquireTimeOut(3000L)
|
||||
.setLockTimeOut(5000L);
|
||||
// 这里增加分布式锁 防止缓存击穿
|
||||
// ============ 尝试加锁
|
||||
redisLock = redisLockPlugins.tryLock(redisLock);
|
||||
if(redisLock == null){
|
||||
return defaultVal;
|
||||
}
|
||||
|
||||
// 查询数据库 并保存到缓存内
|
||||
ResultVo<List<SysDictDetailModel>> resultVo = dictDetailApi.findListByTypeCode(typeCode);
|
||||
if(resultVo.isSuccess()){
|
||||
List<SysDictDetailModel> sysDictDetailModels = resultVo.getData();
|
||||
for (SysDictDetailModel model : sysDictDetailModels) {
|
||||
if(model.getDictValue().equals(dictValue)){
|
||||
// 名称
|
||||
dictName = model.getDictName();
|
||||
DictModel dictModel = new DictModel();
|
||||
dictModel.setTypeCode(model.getTypeCode());
|
||||
dictModel.setDictName(model.getDictName());
|
||||
dictModel.setDictValue(model.getDictValue());
|
||||
dictModel.setModel(model);
|
||||
// 保存至缓存
|
||||
DictUtil.put(dictModel);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// ============ 释放锁
|
||||
redisLockPlugins.unLock(redisLock);
|
||||
redisLock = null;
|
||||
|
||||
// 如果名称还是 为空 则赋默认值
|
||||
if(StringUtils.isEmpty(dictName)){
|
||||
// 加入缓存防穿透
|
||||
// 设置空变量 用于防止穿透判断
|
||||
CacheUtil.putNilFlag("dict:" + typeCode + ":" + dictValue);
|
||||
dictName = defaultVal;
|
||||
}
|
||||
return dictName;
|
||||
}catch (Exception e){
|
||||
log.error(e.getMessage(),e);
|
||||
return defaultVal;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 字典名称 取 字典值
|
||||
* @param typeCode 字典类型Code
|
||||
* @param dictName 字典名称
|
||||
* @param defaultVal 默认值
|
||||
* @return
|
||||
*/
|
||||
public static String getDictValueByName(String typeCode, String dictName, String defaultVal){
|
||||
try {
|
||||
String dictValue = "";
|
||||
SysDictDetailModel cacheModel = CacheUtil.getHash(DictConstants.CACHE_PREFIX_NAME + typeCode,
|
||||
dictName, SysDictDetailModel.class);
|
||||
if (cacheModel != null){
|
||||
dictValue = cacheModel.getDictValue();
|
||||
}
|
||||
if (StringUtils.isNotEmpty(dictValue)) return dictValue;
|
||||
|
||||
// 防止缓存穿透判断
|
||||
boolean hasNilFlag = CacheUtil.hasNilFlag("dict:" + typeCode + ":" + dictName);
|
||||
if(hasNilFlag){
|
||||
return defaultVal;
|
||||
}
|
||||
|
||||
// 锁凭证 redisLock 贯穿全程
|
||||
RedisLock redisLock = new RedisLock();
|
||||
redisLock.setLockName("dictLock:" + typeCode + ":" + dictName)
|
||||
.setAcquireTimeOut(3000L)
|
||||
.setLockTimeOut(10000L);
|
||||
// 这里增加分布式锁 防止缓存击穿
|
||||
// ============ 尝试加锁
|
||||
redisLock = redisLockPlugins.tryLock(redisLock);
|
||||
if(redisLock == null){
|
||||
return defaultVal;
|
||||
}
|
||||
|
||||
// 查询数据库 并保存到缓存内
|
||||
ResultVo<List<SysDictDetailModel>> resultVo = dictDetailApi.findListByTypeCode(typeCode);
|
||||
if(resultVo.isSuccess()){
|
||||
List<SysDictDetailModel> sysDictDetailModels = resultVo.getData();
|
||||
for (SysDictDetailModel model : sysDictDetailModels) {
|
||||
if(model.getDictName().equals(dictName)){
|
||||
// 值
|
||||
dictValue = model.getDictValue();
|
||||
DictModel dictModel = new DictModel();
|
||||
dictModel.setTypeCode(model.getTypeCode());
|
||||
dictModel.setDictName(model.getDictName());
|
||||
dictModel.setDictValue(model.getDictValue());
|
||||
dictModel.setModel(model);
|
||||
// 保存至缓存
|
||||
DictUtil.put(dictModel);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// ============ 释放锁
|
||||
redisLockPlugins.unLock(redisLock);
|
||||
redisLock = null;
|
||||
|
||||
// 如果值还是 为空 则赋默认值
|
||||
if(StringUtils.isEmpty(dictValue)){
|
||||
// 加入缓存防穿透
|
||||
// 设置空变量 用于防止穿透判断
|
||||
CacheUtil.putNilFlag("dict:" + typeCode + ":" + dictName);
|
||||
dictValue = defaultVal;
|
||||
}
|
||||
return dictValue;
|
||||
}catch (Exception e){
|
||||
log.error(e.getMessage(),e);
|
||||
return defaultVal;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据字典code 获得字典列表
|
||||
* @param typeCode
|
||||
* @return
|
||||
*/
|
||||
public static List<DictModel> getDictList(String typeCode){
|
||||
List<DictModel> dictModels = Lists.newArrayList();
|
||||
try {
|
||||
Map<Object, Object> dictMap = redisPlugin.hGetAll(DictConstants.CACHE_PREFIX_VALUE + typeCode);
|
||||
Set<Map.Entry<Object, Object>> entries = dictMap.entrySet();
|
||||
for (Map.Entry<Object, Object> entry : entries) {
|
||||
// 赋值
|
||||
SysDictDetailModel model = (SysDictDetailModel) entry.getValue();
|
||||
DictModel dictModel = new DictModel();
|
||||
dictModel.setTypeCode(typeCode);
|
||||
dictModel.setDictName(model.getDictName());
|
||||
dictModel.setDictValue(model.getDictValue());
|
||||
dictModels.add(dictModel);
|
||||
}
|
||||
}catch (Exception e){
|
||||
log.error(e.getMessage(),e);
|
||||
dictModels = Lists.newArrayList();
|
||||
}
|
||||
return dictModels;
|
||||
}
|
||||
|
||||
|
||||
// ===============
|
||||
|
||||
|
||||
/**
|
||||
* 删除 字典
|
||||
* @param model 字典模型
|
||||
* @return
|
||||
*/
|
||||
public static void put(DictModel model){
|
||||
CacheUtil.putEdenHash(DictConstants.CACHE_PREFIX_NAME + model.getTypeCode(),
|
||||
model.getDictName(), model.getModel());
|
||||
CacheUtil.putEdenHash(DictConstants.CACHE_PREFIX_VALUE + model.getTypeCode(),
|
||||
model.getDictValue(), model.getModel());
|
||||
// 删除 空属性 拦截
|
||||
CacheUtil.putNilFlag("dict:" + model.getTypeCode() + ":" + model.getDictName());
|
||||
CacheUtil.putNilFlag("dict:" + model.getTypeCode() + ":" + model.getTypeCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除 字典
|
||||
* @param model 字典模型
|
||||
* @return
|
||||
*/
|
||||
public static void del(DictModel model){
|
||||
CacheUtil.delEdenHash(DictConstants.CACHE_PREFIX_NAME + model.getTypeCode(), model.getDictName());
|
||||
CacheUtil.delEdenHash(DictConstants.CACHE_PREFIX_VALUE + model.getTypeCode(), model.getDictValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除 typeCode 下所有字典
|
||||
* @param typeCode 字典编号
|
||||
* @return
|
||||
*/
|
||||
public static void delAll(String typeCode){
|
||||
List<DictModel> dictList = DictUtil.getDictList(typeCode);
|
||||
for (DictModel dictModel : dictList) {
|
||||
DictUtil.del(dictModel);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ===================================
|
||||
|
||||
@Autowired
|
||||
public void setRedisPlugin(RedisPlugin redisPlugin) {
|
||||
DictUtil.redisPlugin = redisPlugin;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setRedisLockPlugins(RedisLockPlugins redisLockPlugins) {
|
||||
DictUtil.redisLockPlugins = redisLockPlugins;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setDictDetailApi(DictDetailApi dictDetailApi) {
|
||||
DictUtil.dictDetailApi = dictDetailApi;
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>opsli-modulars</artifactId>
|
||||
<groupId>org.opsliframework.boot</groupId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>opsli-modulars-system</artifactId>
|
||||
|
||||
|
||||
</project>
|
@ -0,0 +1,41 @@
|
||||
package org.opsli.modulars.system;
|
||||
|
||||
import org.opsli.common.base.msg.BaseMsg;
|
||||
|
||||
/**
|
||||
* @BelongsProject: opsli-boot
|
||||
* @BelongsPackage: org.opsli.core.msg
|
||||
* @Author: Parker
|
||||
* @CreateTime: 2020-09-13 19:36
|
||||
* @Description: 核心类 - 消息
|
||||
*/
|
||||
public enum SystemMsg implements BaseMsg {
|
||||
|
||||
|
||||
/**
|
||||
* 数据字典
|
||||
*/
|
||||
EXCEL_DICT_UNIQUE(20000,"字典编号重复,该字典已存在!"),
|
||||
EXCEL_DICT_DETAIL_UNIQUE(20001,"字典名称或值重复,该字典已存在!"),
|
||||
|
||||
|
||||
;
|
||||
|
||||
private int code;
|
||||
private String message;
|
||||
|
||||
SystemMsg(int code, String message){
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getCode() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return this.message;
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
## 改造微服务时 将Feign 接口写在这里
|
@ -0,0 +1,40 @@
|
||||
package org.opsli.modulars.system.dict.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.opsli.core.base.entity.BaseEntity;
|
||||
|
||||
/**
|
||||
* @BelongsProject: opsli-boot
|
||||
* @BelongsPackage: org.opsli.modulars.test.entity
|
||||
* @Author: Parker
|
||||
* @CreateTime: 2020-09-16 17:33
|
||||
* @Description: 字典表
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class SysDict extends BaseEntity {
|
||||
|
||||
|
||||
|
||||
/** 字典类型编号 */
|
||||
private String typeCode;
|
||||
|
||||
/** 字典类型名称 */
|
||||
private String typeName;
|
||||
|
||||
/** 是否内置数据 */
|
||||
private Character izLock;
|
||||
|
||||
/** 备注 */
|
||||
private String remark;
|
||||
|
||||
|
||||
// ========================================
|
||||
|
||||
/** 逻辑删除字段 */
|
||||
@TableLogic
|
||||
private Integer deleted;
|
||||
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package org.opsli.modulars.system.dict.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.opsli.core.base.entity.BaseEntity;
|
||||
|
||||
/**
|
||||
* @BelongsProject: opsli-boot
|
||||
* @BelongsPackage: org.opsli.modulars.test.entity
|
||||
* @Author: Parker
|
||||
* @CreateTime: 2020-09-16 17:33
|
||||
* @Description: 字典表 - 明细
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class SysDictDetail extends BaseEntity {
|
||||
|
||||
|
||||
/** 字典类型ID */
|
||||
private String typeId;
|
||||
|
||||
/** 字典类型Code 冗余字段 */
|
||||
private String typeCode;
|
||||
|
||||
/** 字典文本 */
|
||||
private String dictName;
|
||||
|
||||
/** 字典值 */
|
||||
private String dictValue;
|
||||
|
||||
/** 是否内置数据 */
|
||||
private Character izLock;
|
||||
|
||||
/** 排序 */
|
||||
private Integer sortNo;
|
||||
|
||||
/** 备注 */
|
||||
private String remark;
|
||||
|
||||
|
||||
// ========================================
|
||||
|
||||
/** 逻辑删除字段 */
|
||||
@TableLogic
|
||||
private Integer deleted;
|
||||
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package org.opsli.modulars.system.dict.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.opsli.modulars.system.dict.entity.SysDictDetail;
|
||||
|
||||
/**
|
||||
* @BelongsProject: opsli-boot
|
||||
* @BelongsPackage: org.opsli.modulars.test.mapper
|
||||
* @Author: Parker
|
||||
* @CreateTime: 2020-09-17 13:01
|
||||
* @Description: 数据字典 明细 Mapper
|
||||
*/
|
||||
@Mapper
|
||||
public interface DictDetailMapper extends BaseMapper<SysDictDetail> {
|
||||
|
||||
/**
|
||||
* 唯一验证
|
||||
* @param entity
|
||||
* @return
|
||||
*/
|
||||
Integer uniqueVerificationByNameOrValue(SysDictDetail entity);
|
||||
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package org.opsli.modulars.system.dict.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.opsli.modulars.system.dict.entity.SysDict;
|
||||
|
||||
/**
|
||||
* @BelongsProject: opsli-boot
|
||||
* @BelongsPackage: org.opsli.modulars.test.mapper
|
||||
* @Author: Parker
|
||||
* @CreateTime: 2020-09-17 13:01
|
||||
* @Description: 数据字典 Mapper
|
||||
*/
|
||||
@Mapper
|
||||
public interface DictMapper extends BaseMapper<SysDict> {
|
||||
|
||||
/**
|
||||
* 唯一验证
|
||||
* @param entity
|
||||
* @return
|
||||
*/
|
||||
Integer uniqueVerificationByCode(SysDict entity);
|
||||
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
<?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="org.opsli.modulars.system.dict.mapper.DictDetailMapper">
|
||||
|
||||
<!-- 数据库字段 -->
|
||||
<sql id="SysDictDetailColumns">
|
||||
a.id as id,
|
||||
|
||||
a.type_id as typeId,
|
||||
a.type_code as typeCode,
|
||||
a.dict_name as dictName,
|
||||
a.dict_value as dictValue,
|
||||
a.iz_lock as izLock,
|
||||
a.sort_no as sortNo,
|
||||
a.remark as remark,
|
||||
|
||||
a.create_by as createBy,
|
||||
a.create_time as createTime,
|
||||
a.update_by as updateBy,
|
||||
a.update_time as updateTime,
|
||||
a.version as version,
|
||||
a.deleted as deleted
|
||||
</sql>
|
||||
|
||||
<sql id="SysDictDetailJoins">
|
||||
</sql>
|
||||
|
||||
|
||||
<select id="uniqueVerificationByNameOrValue" parameterType="SysDictDetail" resultType="Integer">
|
||||
select count(0)
|
||||
from sys_dict_detail a
|
||||
where
|
||||
(
|
||||
a.dict_name = #{dictName}
|
||||
or
|
||||
a.type_code = #{typeCode}
|
||||
)
|
||||
and a.deleted = 0
|
||||
<if test="id != null and id != ''">
|
||||
and a.id != #{id}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
</mapper>
|
@ -0,0 +1,36 @@
|
||||
<?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="org.opsli.modulars.system.dict.mapper.DictMapper">
|
||||
|
||||
<!-- 数据库字段 -->
|
||||
<sql id="SysDictColumns">
|
||||
a.id as id,
|
||||
|
||||
a.type_code as dictTypeCode,
|
||||
a.type_name as dictTypeName,
|
||||
a.iz_lock as izLock,
|
||||
a.remark as remark,
|
||||
|
||||
a.create_by as createBy,
|
||||
a.create_time as createTime,
|
||||
a.update_by as updateBy,
|
||||
a.update_time as updateTime,
|
||||
a.version as version,
|
||||
a.deleted as deleted
|
||||
</sql>
|
||||
|
||||
<sql id="SysDictJoins">
|
||||
</sql>
|
||||
|
||||
<select id="uniqueVerificationByCode" parameterType="SysDict" resultType="Integer">
|
||||
select count(0)
|
||||
from sys_dict a
|
||||
where
|
||||
a.type_code = #{typeCode}
|
||||
and a.deleted = 0
|
||||
<if test="id != null and id != ''">
|
||||
AND a.id != #{id}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
</mapper>
|
@ -0,0 +1,33 @@
|
||||
package org.opsli.modulars.system.dict.service;
|
||||
|
||||
import org.opsli.api.wrapper.system.dict.SysDictDetailModel;
|
||||
import org.opsli.core.base.service.interfaces.CrudServiceInterface;
|
||||
import org.opsli.modulars.system.dict.entity.SysDictDetail;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @BelongsProject: opsli-boot
|
||||
* @BelongsPackage: org.opsli.modulars.test.service
|
||||
* @Author: Parker
|
||||
* @CreateTime: 2020-09-17 13:07
|
||||
* @Description: 数据字典 明细 接口
|
||||
*/
|
||||
public interface IDictDetailService extends CrudServiceInterface<SysDictDetailModel, SysDictDetail> {
|
||||
|
||||
/**
|
||||
* 根据父类ID 删除
|
||||
* @param parentId 父类ID
|
||||
* @return
|
||||
*/
|
||||
boolean delByParent(String parentId);
|
||||
|
||||
/**
|
||||
* 根据字典类型编号 查询出所有字典
|
||||
*
|
||||
* @param typeCode 字典类型编号
|
||||
* @return
|
||||
*/
|
||||
List<SysDictDetailModel> findListByTypeCode(String typeCode);
|
||||
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package org.opsli.modulars.system.dict.service;
|
||||
|
||||
import org.opsli.api.wrapper.system.dict.SysDictModel;
|
||||
import org.opsli.core.base.service.interfaces.CrudServiceInterface;
|
||||
import org.opsli.modulars.system.dict.entity.SysDict;
|
||||
|
||||
|
||||
/**
|
||||
* @BelongsProject: opsli-boot
|
||||
* @BelongsPackage: org.opsli.modulars.test.service
|
||||
* @Author: Parker
|
||||
* @CreateTime: 2020-09-17 13:07
|
||||
* @Description: 数据字典 接口
|
||||
*/
|
||||
public interface IDictService extends CrudServiceInterface<SysDictModel, SysDict> {
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,334 @@
|
||||
package org.opsli.modulars.system.dict.service.impl;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.opsli.api.wrapper.system.dict.DictModel;
|
||||
import org.opsli.api.wrapper.system.dict.SysDictDetailModel;
|
||||
import org.opsli.api.wrapper.system.dict.SysDictModel;
|
||||
import org.opsli.common.constants.MyBatisConstants;
|
||||
import org.opsli.common.exception.ServiceException;
|
||||
import org.opsli.common.utils.HumpUtil;
|
||||
import org.opsli.common.utils.WrapperUtil;
|
||||
import org.opsli.core.base.service.impl.CrudServiceImpl;
|
||||
import org.opsli.core.cache.pushsub.enums.CacheType;
|
||||
import org.opsli.core.cache.pushsub.msgs.DictMsgFactory;
|
||||
import org.opsli.core.persistence.querybuilder.GenQueryBuilder;
|
||||
import org.opsli.core.persistence.querybuilder.QueryBuilder;
|
||||
import org.opsli.core.utils.DictUtil;
|
||||
import org.opsli.modulars.system.SystemMsg;
|
||||
import org.opsli.modulars.system.dict.entity.SysDictDetail;
|
||||
import org.opsli.modulars.system.dict.mapper.DictDetailMapper;
|
||||
import org.opsli.modulars.system.dict.service.IDictDetailService;
|
||||
import org.opsli.modulars.system.dict.service.IDictService;
|
||||
import org.opsli.plugins.redis.RedisPlugin;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* @BelongsProject: opsli-boot
|
||||
* @BelongsPackage: org.opsli.modulars.test.service
|
||||
* @Author: Parker
|
||||
* @CreateTime: 2020-09-16 17:34
|
||||
* @Description: 数据字典 明细 接口实现类
|
||||
*/
|
||||
@Service
|
||||
public class DictDetailServiceImpl extends CrudServiceImpl<DictDetailMapper, SysDictDetailModel, SysDictDetail> implements IDictDetailService {
|
||||
|
||||
@Autowired(required = false)
|
||||
private DictDetailMapper mapper;
|
||||
@Autowired
|
||||
private IDictService iDictService;
|
||||
@Autowired
|
||||
private RedisPlugin redisPlugin;
|
||||
|
||||
/**
|
||||
* 新增
|
||||
* @param model model 数据模型
|
||||
* @return
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public SysDictDetailModel insert(SysDictDetailModel model) {
|
||||
|
||||
SysDictDetail entity = WrapperUtil.transformInstance(model, SysDictDetail.class);
|
||||
// 唯一验证
|
||||
Integer count = mapper.uniqueVerificationByNameOrValue(entity);
|
||||
if(count != null && count > 0){
|
||||
// 重复
|
||||
throw new ServiceException(SystemMsg.EXCEL_DICT_UNIQUE);
|
||||
}
|
||||
|
||||
SysDictDetailModel ret = super.insert(model);
|
||||
if(ret != null){
|
||||
DictModel dictModel = new DictModel();
|
||||
dictModel.setTypeCode(model.getTypeCode());
|
||||
dictModel.setDictName(model.getDictName());
|
||||
dictModel.setDictValue(model.getDictValue());
|
||||
dictModel.setModel(ret);
|
||||
// 先删老缓存
|
||||
DictUtil.del(dictModel);
|
||||
// 广播缓存数据 - 通知其他服务器同步数据
|
||||
redisPlugin.sendMessage(
|
||||
DictMsgFactory.createMsg(dictModel, CacheType.DELETE)
|
||||
);
|
||||
|
||||
// 再存 防止脏数据
|
||||
DictUtil.put(dictModel);
|
||||
// 广播缓存数据 - 通知其他服务器同步数据
|
||||
redisPlugin.sendMessage(
|
||||
DictMsgFactory.createMsg(dictModel, CacheType.UPDATE)
|
||||
);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
* @param model model 数据模型
|
||||
* @return
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public SysDictDetailModel update(SysDictDetailModel model) {
|
||||
|
||||
SysDictDetail entity = WrapperUtil.transformInstance(model, SysDictDetail.class);
|
||||
// 唯一验证
|
||||
Integer count = mapper.uniqueVerificationByNameOrValue(entity);
|
||||
if(count != null && count > 0){
|
||||
// 重复
|
||||
throw new ServiceException(SystemMsg.EXCEL_DICT_DETAIL_UNIQUE);
|
||||
}
|
||||
|
||||
// 旧数据 用于删除老缓存
|
||||
SysDictDetailModel oldModel = this.get(model);
|
||||
|
||||
SysDictDetailModel ret = super.update(model);
|
||||
if(ret != null){
|
||||
// 先删老缓存
|
||||
DictModel oldDictModel = new DictModel();
|
||||
oldDictModel.setTypeCode(oldModel.getTypeCode());
|
||||
oldDictModel.setDictName(oldModel.getDictName());
|
||||
oldDictModel.setDictValue(oldModel.getDictValue());
|
||||
DictUtil.del(oldDictModel);
|
||||
// 广播缓存数据 - 通知其他服务器同步数据
|
||||
redisPlugin.sendMessage(
|
||||
DictMsgFactory.createMsg(oldDictModel, CacheType.DELETE)
|
||||
);
|
||||
|
||||
|
||||
// 再put新缓存
|
||||
DictModel dictModel = new DictModel();
|
||||
dictModel.setTypeCode(model.getTypeCode());
|
||||
dictModel.setDictName(model.getDictName());
|
||||
dictModel.setDictValue(model.getDictValue());
|
||||
dictModel.setModel(ret);
|
||||
DictUtil.put(dictModel);
|
||||
// 广播缓存数据 - 通知其他服务器同步数据
|
||||
redisPlugin.sendMessage(
|
||||
DictMsgFactory.createMsg(dictModel, CacheType.UPDATE)
|
||||
);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param id ID
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean delete(String id) {
|
||||
SysDictDetailModel sysDictDetailModel = this.get(id);
|
||||
boolean ret = super.delete(id);
|
||||
if(ret){
|
||||
DictModel dictModel = new DictModel();
|
||||
dictModel.setTypeCode(sysDictDetailModel.getTypeCode());
|
||||
dictModel.setDictName(sysDictDetailModel.getDictName());
|
||||
dictModel.setDictValue(sysDictDetailModel.getDictValue());
|
||||
// 删除缓存
|
||||
DictUtil.del(dictModel);
|
||||
// 广播缓存数据 - 通知其他服务器同步数据
|
||||
redisPlugin.sendMessage(
|
||||
DictMsgFactory.createMsg(dictModel, CacheType.DELETE)
|
||||
);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param model 数据模型
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean delete(SysDictDetailModel model) {
|
||||
SysDictDetailModel sysDictDetailModel = this.get(model);
|
||||
boolean ret = super.delete(model);
|
||||
if(ret){
|
||||
DictModel dictModel = new DictModel();
|
||||
dictModel.setTypeCode(sysDictDetailModel.getTypeCode());
|
||||
dictModel.setDictName(sysDictDetailModel.getDictName());
|
||||
dictModel.setDictValue(sysDictDetailModel.getDictValue());
|
||||
// 删除缓存
|
||||
DictUtil.del(dictModel);
|
||||
// 广播缓存数据 - 通知其他服务器同步数据
|
||||
redisPlugin.sendMessage(
|
||||
DictMsgFactory.createMsg(dictModel, CacheType.DELETE)
|
||||
);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除 - 多个
|
||||
* @param ids id数组
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean deleteAll(String[] ids) {
|
||||
QueryBuilder<SysDictDetail> queryBuilder = new GenQueryBuilder<>();
|
||||
QueryWrapper<SysDictDetail> queryWrapper = queryBuilder.build();
|
||||
List<?> idList = Convert.toList(ids);
|
||||
queryWrapper.in(HumpUtil.humpToUnderline(MyBatisConstants.FIELD_ID),idList);
|
||||
List<SysDictDetail> list = this.findList(queryWrapper);
|
||||
boolean ret = super.deleteAll(ids);
|
||||
|
||||
if(ret){
|
||||
if(list != null && list.size() > 0){
|
||||
List<DictModel> dictModels = Lists.newArrayListWithCapacity(list.size());
|
||||
// 删除缓存
|
||||
for (SysDictDetail sysDictDetail : list) {
|
||||
DictModel dictModel = new DictModel();
|
||||
dictModel.setTypeCode(sysDictDetail.getTypeCode());
|
||||
dictModel.setDictName(sysDictDetail.getDictName());
|
||||
dictModel.setDictValue(sysDictDetail.getDictValue());
|
||||
// 删除缓存
|
||||
DictUtil.del(dictModel);
|
||||
dictModels.add(dictModel);
|
||||
}
|
||||
// 广播缓存数据 - 通知其他服务器同步数据
|
||||
redisPlugin.sendMessage(
|
||||
DictMsgFactory.createMsg(dictModels, CacheType.DELETE)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除 - 多个
|
||||
* @param models 封装模型
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean deleteAll(Collection<SysDictDetailModel> models) {
|
||||
|
||||
QueryBuilder<SysDictDetail> queryBuilder = new GenQueryBuilder<>();
|
||||
QueryWrapper<SysDictDetail> queryWrapper = queryBuilder.build();
|
||||
|
||||
List<String> idList = Lists.newArrayListWithCapacity(models.size());
|
||||
for (SysDictDetailModel model : models) {
|
||||
idList.add(model.getId());
|
||||
}
|
||||
queryWrapper.in(HumpUtil.humpToUnderline(MyBatisConstants.FIELD_ID),idList);
|
||||
|
||||
List<SysDictDetail> list = this.findList(queryWrapper);
|
||||
|
||||
boolean ret = super.deleteAll(models);
|
||||
|
||||
if(ret){
|
||||
if(list != null && list.size() > 0){
|
||||
List<DictModel> dictModels = Lists.newArrayListWithCapacity(list.size());
|
||||
// 删除缓存
|
||||
for (SysDictDetail sysDictDetail : list) {
|
||||
DictModel dictModel = new DictModel();
|
||||
dictModel.setTypeCode(sysDictDetail.getTypeCode());
|
||||
dictModel.setDictName(sysDictDetail.getDictName());
|
||||
dictModel.setDictValue(sysDictDetail.getDictValue());
|
||||
// 删除缓存
|
||||
DictUtil.del(dictModel);
|
||||
dictModels.add(dictModel);
|
||||
}
|
||||
// 广播缓存数据 - 通知其他服务器同步数据
|
||||
redisPlugin.sendMessage(
|
||||
DictMsgFactory.createMsg(dictModels, CacheType.DELETE)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 父类ID 全部删除
|
||||
* @param parentId 父类ID
|
||||
* @return
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public boolean delByParent(String parentId) {
|
||||
if(StringUtils.isEmpty(parentId)) return false;
|
||||
|
||||
String key = HumpUtil.humpToUnderline("typeId");
|
||||
QueryBuilder<SysDictDetail> queryBuilder = new GenQueryBuilder<>();
|
||||
QueryWrapper<SysDictDetail> queryWrapper = queryBuilder.build();
|
||||
queryWrapper.eq(key, parentId);
|
||||
boolean removeFlag = super.remove(queryWrapper);
|
||||
if(removeFlag){
|
||||
SysDictModel sysDictModel = iDictService.get(parentId);
|
||||
List<SysDictDetailModel> listByTypeCode = this.findListByTypeCode(sysDictModel.getTypeCode());
|
||||
if(listByTypeCode != null && listByTypeCode.size() > 0){
|
||||
List<DictModel> dictList = Lists.newArrayListWithCapacity(listByTypeCode.size());
|
||||
for (SysDictDetailModel sysDictDetailModel : listByTypeCode) {
|
||||
DictModel dictModel = new DictModel();
|
||||
dictModel.setTypeCode(sysDictDetailModel.getTypeCode());
|
||||
dictModel.setDictName(sysDictDetailModel.getDictName());
|
||||
dictModel.setDictValue(sysDictDetailModel.getDictValue());
|
||||
dictList.add(dictModel);
|
||||
}
|
||||
// 删除缓存
|
||||
DictUtil.delAll(sysDictModel.getTypeCode());
|
||||
// 广播缓存数据 - 通知其他服务器同步数据
|
||||
redisPlugin.sendMessage(
|
||||
DictMsgFactory.createMsg(dictList, CacheType.DELETE)
|
||||
);
|
||||
}
|
||||
}
|
||||
return removeFlag;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据字典编号 查询出所有字典
|
||||
*
|
||||
* @param typeCode 字典编号
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<SysDictDetailModel> findListByTypeCode(String typeCode) {
|
||||
if(StringUtils.isEmpty(typeCode)) return null;
|
||||
|
||||
String key = HumpUtil.humpToUnderline("typeCode");
|
||||
String deleted = HumpUtil.humpToUnderline("deleted");
|
||||
|
||||
QueryBuilder<SysDictDetail> queryBuilder = new GenQueryBuilder<>();
|
||||
QueryWrapper<SysDictDetail> queryWrapper = queryBuilder.build();
|
||||
queryWrapper.eq(key, typeCode);
|
||||
queryWrapper.eq(deleted, '0');
|
||||
List<SysDictDetail> list = this.findList(queryWrapper);
|
||||
// 转化对象
|
||||
return WrapperUtil.transformInstance(list, SysDictDetailModel.class);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,136 @@
|
||||
package org.opsli.modulars.system.dict.service.impl;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.opsli.api.wrapper.system.dict.SysDictDetailModel;
|
||||
import org.opsli.api.wrapper.system.dict.SysDictModel;
|
||||
import org.opsli.common.exception.ServiceException;
|
||||
import org.opsli.common.utils.WrapperUtil;
|
||||
import org.opsli.core.base.service.impl.CrudServiceImpl;
|
||||
import org.opsli.modulars.system.SystemMsg;
|
||||
import org.opsli.modulars.system.dict.entity.SysDict;
|
||||
import org.opsli.modulars.system.dict.mapper.DictMapper;
|
||||
import org.opsli.modulars.system.dict.service.IDictDetailService;
|
||||
import org.opsli.modulars.system.dict.service.IDictService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* @BelongsProject: opsli-boot
|
||||
* @BelongsPackage: org.opsli.modulars.test.service
|
||||
* @Author: Parker
|
||||
* @CreateTime: 2020-09-16 17:34
|
||||
* @Description: 数据字典 接口实现类
|
||||
*/
|
||||
@Service
|
||||
public class DictServiceImpl extends CrudServiceImpl<DictMapper, SysDictModel, SysDict> implements IDictService {
|
||||
|
||||
@Autowired(required = false)
|
||||
private DictMapper mapper;
|
||||
@Autowired
|
||||
private IDictDetailService iDictDetailService;
|
||||
|
||||
@Override
|
||||
public SysDictModel insert(SysDictModel model) {
|
||||
if(model == null) return null;
|
||||
|
||||
SysDict entity = WrapperUtil.transformInstance(model, SysDict.class);
|
||||
// 唯一验证
|
||||
Integer count = mapper.uniqueVerificationByCode(entity);
|
||||
if(count != null && count > 0){
|
||||
// 重复
|
||||
throw new ServiceException(SystemMsg.EXCEL_DICT_UNIQUE);
|
||||
}
|
||||
|
||||
return super.insert(model);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public SysDictModel update(SysDictModel model) {
|
||||
if(model == null) return null;
|
||||
|
||||
SysDict entity = WrapperUtil.transformInstance(model, SysDict.class);
|
||||
// 唯一验证
|
||||
Integer count = mapper.uniqueVerificationByCode(entity);
|
||||
if(count != null && count > 0){
|
||||
// 重复
|
||||
throw new ServiceException(SystemMsg.EXCEL_DICT_UNIQUE);
|
||||
}
|
||||
|
||||
SysDictModel updateRet = super.update(model);
|
||||
|
||||
// 字典主表修改 子表跟着联动 (验证是否改了编号)/ 或者修改不允许改编号
|
||||
List<SysDictDetailModel> listByTypeCode = null;
|
||||
if(StringUtils.isNotEmpty(model.getTypeCode())){
|
||||
listByTypeCode = iDictDetailService.findListByTypeCode(model.getTypeCode());
|
||||
}
|
||||
if(listByTypeCode != null && listByTypeCode.size() > 0){
|
||||
for (SysDictDetailModel sysDictDetailModel : listByTypeCode) {
|
||||
sysDictDetailModel.setTypeCode(updateRet.getTypeCode());
|
||||
iDictDetailService.update(sysDictDetailModel);
|
||||
}
|
||||
}
|
||||
|
||||
return updateRet;
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public boolean delete(String id) {
|
||||
// 删除字典明细表
|
||||
iDictDetailService.delByParent(id);
|
||||
|
||||
// 删除自身数据
|
||||
return super.delete(id);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public boolean delete(SysDictModel model) {
|
||||
if(model == null || StringUtils.isEmpty(model.getId())){
|
||||
return false;
|
||||
}
|
||||
|
||||
// 删除字典明细表
|
||||
iDictDetailService.delByParent(model.getId());
|
||||
|
||||
// 删除自身数据
|
||||
return super.delete(model);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public boolean deleteAll(String[] ids) {
|
||||
if(ids == null) return false;
|
||||
|
||||
// 删除字典明细表
|
||||
for (String id : ids) {
|
||||
iDictDetailService.delByParent(id);
|
||||
}
|
||||
// 删除自身数据
|
||||
return super.deleteAll(ids);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public boolean deleteAll(Collection<SysDictModel> models) {
|
||||
if(models == null || models.isEmpty()) return false;
|
||||
|
||||
// 删除字典明细表
|
||||
for (SysDictModel model : models) {
|
||||
if(model == null || StringUtils.isEmpty(model.getId())){
|
||||
continue;
|
||||
}
|
||||
iDictDetailService.delByParent(model.getId());
|
||||
}
|
||||
// 删除自身数据
|
||||
return super.deleteAll(models);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,166 @@
|
||||
package org.opsli.modulars.system.dict.web;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.opsli.api.base.result.ResultVo;
|
||||
import org.opsli.api.web.system.dict.DictDetailApi;
|
||||
import org.opsli.api.wrapper.system.dict.SysDictDetailModel;
|
||||
import org.opsli.common.annotation.ApiRestController;
|
||||
import org.opsli.common.utils.WrapperUtil;
|
||||
import org.opsli.core.base.concroller.BaseRestController;
|
||||
import org.opsli.core.persistence.Page;
|
||||
import org.opsli.core.persistence.querybuilder.QueryBuilder;
|
||||
import org.opsli.core.persistence.querybuilder.WebQueryBuilder;
|
||||
import org.opsli.modulars.system.dict.entity.SysDictDetail;
|
||||
import org.opsli.modulars.system.dict.service.IDictDetailService;
|
||||
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* @BelongsProject: opsli-boot
|
||||
* @BelongsPackage: org.opsli.modulars.test.web
|
||||
* @Author: Parker
|
||||
* @CreateTime: 2020-09-13 17:40
|
||||
* @Description: 数据字典明细
|
||||
*/
|
||||
@Slf4j
|
||||
@ApiRestController("/dict/detail")
|
||||
public class DictDetailRestController extends BaseRestController<SysDictDetailModel, SysDictDetail, IDictDetailService>
|
||||
implements DictDetailApi {
|
||||
|
||||
|
||||
/**
|
||||
* 数据字典 查一条
|
||||
* @param model 模型
|
||||
* @return ResultVo
|
||||
*/
|
||||
@ApiOperation(value = "获得单条数据", notes = "获得单条数据 - ID")
|
||||
@Override
|
||||
public ResultVo<SysDictDetailModel> get(SysDictDetailModel model) {
|
||||
return ResultVo.success(model);
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据字典 查询分页
|
||||
* @param pageNo 当前页
|
||||
* @param pageSize 每页条数
|
||||
* @param request request
|
||||
* @return ResultVo
|
||||
*/
|
||||
@ApiOperation(value = "获得分页数据", notes = "获得分页数据 - 查询构造器")
|
||||
@Override
|
||||
public ResultVo<?> findPage(Integer pageNo, Integer pageSize, HttpServletRequest request) {
|
||||
|
||||
QueryBuilder<SysDictDetail> queryBuilder = new WebQueryBuilder<>(SysDictDetail.class, request.getParameterMap());
|
||||
Page<SysDictDetailModel, SysDictDetail> page = new Page<>(pageNo, pageSize);
|
||||
page.setQueryWrapper(queryBuilder.build());
|
||||
page = IService.findPage(page);
|
||||
|
||||
return ResultVo.success(page.getBootstrapData());
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据字典 新增
|
||||
* @param model 模型
|
||||
* @return ResultVo
|
||||
*/
|
||||
@ApiOperation(value = "新增数据", notes = "新增数据")
|
||||
@Override
|
||||
public ResultVo<?> insert(SysDictDetailModel model) {
|
||||
// 调用新增方法
|
||||
IService.insert(model);
|
||||
return ResultVo.success("新增成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据字典 修改
|
||||
* @param model 模型
|
||||
* @return ResultVo
|
||||
*/
|
||||
@ApiOperation(value = "修改数据", notes = "修改数据")
|
||||
@Override
|
||||
public ResultVo<?> update(SysDictDetailModel model) {
|
||||
// 调用修改方法
|
||||
IService.update(model);
|
||||
return ResultVo.success("修改成功");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 数据字典 删除
|
||||
* @param id ID
|
||||
* @return ResultVo
|
||||
*/
|
||||
@ApiOperation(value = "删除数据", notes = "删除数据")
|
||||
@Override
|
||||
public ResultVo<?> del(String id){
|
||||
IService.delete(id);
|
||||
return ResultVo.success("删除对象成功");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 数据字典 批量删除
|
||||
* @param ids ID 数组
|
||||
* @return ResultVo
|
||||
*/
|
||||
@ApiOperation(value = "删除全部数据", notes = "删除全部数据")
|
||||
@Override
|
||||
public ResultVo<?> delAll(String[] ids){
|
||||
IService.deleteAll(ids);
|
||||
return ResultVo.success("删除对象成功");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 数据字典 Excel 导出
|
||||
* @param request request
|
||||
* @param response response
|
||||
* @return ResultVo
|
||||
*/
|
||||
@ApiOperation(value = "导出Excel", notes = "导出Excel")
|
||||
@Override
|
||||
public ResultVo<?> exportExcel(HttpServletRequest request, HttpServletResponse response) {
|
||||
QueryBuilder<SysDictDetail> queryBuilder = new WebQueryBuilder<>(SysDictDetail.class, request.getParameterMap());
|
||||
return super.excelExport(DictDetailApi.TITLE, queryBuilder.build(), response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据字典 Excel 导入
|
||||
* @param request 文件流 request
|
||||
* @return ResultVo
|
||||
*/
|
||||
@ApiOperation(value = "导入Excel", notes = "导入Excel")
|
||||
@Override
|
||||
public ResultVo<?> excelImport(MultipartHttpServletRequest request) {
|
||||
return super.excelImport(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据字典 Excel 下载导入模版
|
||||
* @param response response
|
||||
* @return ResultVo
|
||||
*/
|
||||
@ApiOperation(value = "导出Excel模版", notes = "导出Excel模版")
|
||||
@Override
|
||||
public ResultVo<?> importTemplate(HttpServletResponse response) {
|
||||
return super.importTemplate(DictDetailApi.TITLE, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据字典类型编号 查询出所有字典
|
||||
*
|
||||
* @param typeCode 字典类型编号
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "根据字典类型编号 查询出所有字典", notes = "根据字典类型编号 查询出所有字典")
|
||||
// 权限
|
||||
@Override
|
||||
public ResultVo<List<SysDictDetailModel>> findListByTypeCode(String typeCode) {
|
||||
return ResultVo.success(IService.findListByTypeCode(typeCode));
|
||||
}
|
||||
}
|
@ -0,0 +1,153 @@
|
||||
package org.opsli.modulars.system.dict.web;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.opsli.api.base.result.ResultVo;
|
||||
import org.opsli.api.web.system.dict.DictApi;
|
||||
import org.opsli.api.web.system.dict.DictDetailApi;
|
||||
import org.opsli.api.wrapper.system.dict.SysDictModel;
|
||||
import org.opsli.common.annotation.ApiRestController;
|
||||
import org.opsli.core.base.concroller.BaseRestController;
|
||||
import org.opsli.core.persistence.Page;
|
||||
import org.opsli.core.persistence.querybuilder.QueryBuilder;
|
||||
import org.opsli.core.persistence.querybuilder.WebQueryBuilder;
|
||||
import org.opsli.modulars.system.dict.entity.SysDict;
|
||||
import org.opsli.modulars.system.dict.service.IDictService;
|
||||
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
|
||||
/**
|
||||
* @BelongsProject: opsli-boot
|
||||
* @BelongsPackage: org.opsli.modulars.test.web
|
||||
* @Author: Parker
|
||||
* @CreateTime: 2020-09-13 17:40
|
||||
* @Description: 数据字典
|
||||
*/
|
||||
@Slf4j
|
||||
@ApiRestController("/dict")
|
||||
public class DictRestController extends BaseRestController<SysDictModel, SysDict, IDictService>
|
||||
implements DictApi {
|
||||
|
||||
|
||||
/**
|
||||
* 数据字典 查一条
|
||||
* @param model 模型
|
||||
* @return ResultVo
|
||||
*/
|
||||
@ApiOperation(value = "获得单条数据", notes = "获得单条数据 - ID")
|
||||
@Override
|
||||
public ResultVo<SysDictModel> get(SysDictModel model) {
|
||||
return ResultVo.success(model);
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据字典 查询分页
|
||||
* @param pageNo 当前页
|
||||
* @param pageSize 每页条数
|
||||
* @param request request
|
||||
* @return ResultVo
|
||||
*/
|
||||
@ApiOperation(value = "获得分页数据", notes = "获得分页数据 - 查询构造器")
|
||||
@Override
|
||||
public ResultVo<?> findPage(Integer pageNo, Integer pageSize, HttpServletRequest request) {
|
||||
|
||||
QueryBuilder<SysDict> queryBuilder = new WebQueryBuilder<>(SysDict.class, request.getParameterMap());
|
||||
Page<SysDictModel, SysDict> page = new Page<>(pageNo, pageSize);
|
||||
page.setQueryWrapper(queryBuilder.build());
|
||||
page = IService.findPage(page);
|
||||
|
||||
return ResultVo.success(page.getBootstrapData());
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据字典 新增
|
||||
* @param model 模型
|
||||
* @return ResultVo
|
||||
*/
|
||||
@ApiOperation(value = "新增数据", notes = "新增数据")
|
||||
@Override
|
||||
public ResultVo<?> insert(SysDictModel model) {
|
||||
// 调用新增方法
|
||||
IService.insert(model);
|
||||
return ResultVo.success("新增成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据字典 修改
|
||||
* @param model 模型
|
||||
* @return ResultVo
|
||||
*/
|
||||
@ApiOperation(value = "修改数据", notes = "修改数据")
|
||||
@Override
|
||||
public ResultVo<?> update(SysDictModel model) {
|
||||
// 调用修改方法
|
||||
IService.update(model);
|
||||
return ResultVo.success("修改成功");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 数据字典 删除
|
||||
* @param id ID
|
||||
* @return ResultVo
|
||||
*/
|
||||
@ApiOperation(value = "删除数据", notes = "删除数据")
|
||||
@Override
|
||||
public ResultVo<?> del(String id){
|
||||
IService.delete(id);
|
||||
return ResultVo.success("删除对象成功");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 数据字典 批量删除
|
||||
* @param ids ID 数组
|
||||
* @return ResultVo
|
||||
*/
|
||||
@ApiOperation(value = "删除全部数据", notes = "删除全部数据")
|
||||
@Override
|
||||
public ResultVo<?> delAll(String[] ids){
|
||||
IService.deleteAll(ids);
|
||||
return ResultVo.success("删除对象成功");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 数据字典 Excel 导出
|
||||
* @param request request
|
||||
* @param response response
|
||||
* @return ResultVo
|
||||
*/
|
||||
@ApiOperation(value = "导出Excel", notes = "导出Excel")
|
||||
@Override
|
||||
public ResultVo<?> exportExcel(HttpServletRequest request, HttpServletResponse response) {
|
||||
QueryBuilder<SysDict> queryBuilder = new WebQueryBuilder<>(SysDict.class, request.getParameterMap());
|
||||
return super.excelExport(DictDetailApi.TITLE, queryBuilder.build(), response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据字典 Excel 导入
|
||||
* @param request 文件流 request
|
||||
* @return ResultVo
|
||||
*/
|
||||
@ApiOperation(value = "导入Excel", notes = "导入Excel")
|
||||
@Override
|
||||
public ResultVo<?> excelImport(MultipartHttpServletRequest request) {
|
||||
return super.excelImport(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据字典 Excel 下载导入模版
|
||||
* @param response response
|
||||
* @return ResultVo
|
||||
*/
|
||||
@ApiOperation(value = "导出Excel模版", notes = "导出Excel模版")
|
||||
@Override
|
||||
public ResultVo<?> importTemplate(HttpServletResponse response) {
|
||||
return super.importTemplate(DictDetailApi.TITLE, response);
|
||||
}
|
||||
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
package org.opsli.modulars.test.entity;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import com.alibaba.excel.annotation.write.style.*;
|
||||
import lombok.Data;
|
||||
import org.apache.poi.ss.usermodel.FillPatternType;
|
||||
import org.opsli.plugins.excel.annotation.CellStyleFormat;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Created Date by 2020/5/9 0009.
|
||||
*
|
||||
* Excel 导入 导出测试类
|
||||
* @author Parker
|
||||
*/
|
||||
@Data
|
||||
@ContentRowHeight(16)
|
||||
@HeadRowHeight(21)
|
||||
@HeadFontStyle(fontName = "Arial",color = 9,fontHeightInPoints = 10)
|
||||
@HeadStyle(fillPatternType = FillPatternType.SOLID_FOREGROUND, fillForegroundColor = 23)
|
||||
@ColumnWidth(22)
|
||||
public class Test implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 名称 */
|
||||
@ExcelProperty(value = "名称",index = 0)
|
||||
@CellStyleFormat
|
||||
private String name;
|
||||
|
||||
/** 编号 */
|
||||
@ExcelProperty(value = "编号",index = 1)
|
||||
@CellStyleFormat
|
||||
private String code;
|
||||
|
||||
/** 年龄 */
|
||||
@ExcelProperty(value = "年龄",index = 2)
|
||||
@CellStyleFormat
|
||||
private Integer age;
|
||||
|
||||
/** 性别 */
|
||||
@ExcelProperty(value = "性别",index = 3)
|
||||
@CellStyleFormat
|
||||
private Integer sex;
|
||||
|
||||
/** 金额 */
|
||||
// @ExcelProperty(value = "金额",index = 4)
|
||||
// @CellStyleFormat
|
||||
private Double amt;
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
public Test() {
|
||||
|
||||
}
|
||||
public Test(String name, String code, Integer age, Integer sex, Double amt) {
|
||||
this.name = name;
|
||||
this.code = code;
|
||||
this.age = age;
|
||||
this.sex = sex;
|
||||
this.amt = amt;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue