feat: 代码生成器模板 管理功能 (80%)

v1.4.1
Carina 4 years ago
parent 2b933d6f62
commit 595a2172e3

@ -51,6 +51,9 @@ import static org.opsli.common.constants.OrderConstants.UTIL_ORDER;
@Lazy(false) @Lazy(false)
public class DictUtil { public class DictUtil {
/** 增加初始状态开关 防止异常使用 */
private static boolean IS_INIT;
/** 字典Service */ /** 字典Service */
private static DictDetailApi dictDetailApi; private static DictDetailApi dictDetailApi;
@ -62,6 +65,10 @@ public class DictUtil {
* @return String * @return String
*/ */
public static String getDictNameByValue(String typeCode, String dictValue, String defaultVal){ public static String getDictNameByValue(String typeCode, String dictValue, String defaultVal){
// 判断 工具类是否初始化完成
ThrowExceptionUtil.isThrowException(!IS_INIT,
CoreMsg.OTHER_EXCEPTION_UTILS_INIT);
// 缓存Key // 缓存Key
String cacheKey = DictConstants.CACHE_PREFIX_VALUE + typeCode; String cacheKey = DictConstants.CACHE_PREFIX_VALUE + typeCode;
// 缓存Key + VALUE // 缓存Key + VALUE
@ -142,6 +149,10 @@ public class DictUtil {
* @return String * @return String
*/ */
public static String getDictValueByName(String typeCode, String dictName, String defaultVal){ public static String getDictValueByName(String typeCode, String dictName, String defaultVal){
// 判断 工具类是否初始化完成
ThrowExceptionUtil.isThrowException(!IS_INIT,
CoreMsg.OTHER_EXCEPTION_UTILS_INIT);
// 缓存Key // 缓存Key
String cacheKey = DictConstants.CACHE_PREFIX_NAME + typeCode; String cacheKey = DictConstants.CACHE_PREFIX_NAME + typeCode;
// 缓存Key + VALUE // 缓存Key + VALUE
@ -219,6 +230,10 @@ public class DictUtil {
* @return List * @return List
*/ */
public static List<DictWrapper> getDictList(String typeCode){ public static List<DictWrapper> getDictList(String typeCode){
// 判断 工具类是否初始化完成
ThrowExceptionUtil.isThrowException(!IS_INIT,
CoreMsg.OTHER_EXCEPTION_UTILS_INIT);
// 缓存Key // 缓存Key
String cacheKey = DictConstants.CACHE_PREFIX_NAME + typeCode; String cacheKey = DictConstants.CACHE_PREFIX_NAME + typeCode;
@ -336,6 +351,10 @@ public class DictUtil {
* @param model * @param model
*/ */
public static void put(DictWrapper model){ public static void put(DictWrapper model){
// 判断 工具类是否初始化完成
ThrowExceptionUtil.isThrowException(!IS_INIT,
CoreMsg.OTHER_EXCEPTION_UTILS_INIT);
// 清除缓存 // 清除缓存
DictUtil.del(model); DictUtil.del(model);
@ -351,6 +370,10 @@ public class DictUtil {
* @return boolean * @return boolean
*/ */
public static boolean del(DictWrapper model){ public static boolean del(DictWrapper model){
// 判断 工具类是否初始化完成
ThrowExceptionUtil.isThrowException(!IS_INIT,
CoreMsg.OTHER_EXCEPTION_UTILS_INIT);
if(model == null){ if(model == null){
return true; return true;
} }
@ -418,6 +441,10 @@ public class DictUtil {
* @return boolean * @return boolean
*/ */
public static boolean delAll(String typeCode){ public static boolean delAll(String typeCode){
// 判断 工具类是否初始化完成
ThrowExceptionUtil.isThrowException(!IS_INIT,
CoreMsg.OTHER_EXCEPTION_UTILS_INIT);
List<DictWrapper> dictWrapperList = DictUtil.getDictList(typeCode); List<DictWrapper> dictWrapperList = DictUtil.getDictList(typeCode);
if(CollUtil.isEmpty(dictWrapperList)){ if(CollUtil.isEmpty(dictWrapperList)){
return true; return true;
@ -465,9 +492,14 @@ public class DictUtil {
// =================================== // ===================================
/**
*
*/
@Autowired @Autowired
public void setDictDetailApi(DictDetailApi dictDetailApi) { public void init(DictDetailApi dictDetailApi) {
DictUtil.dictDetailApi = dictDetailApi; DictUtil.dictDetailApi = dictDetailApi;
IS_INIT = true;
} }
} }

@ -0,0 +1,144 @@
/**
* Copyright 2020 OPSLI https://www.opsli.com
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.opsli.modulars.generator.template.api;
import org.opsli.api.base.result.ResultVo;
import org.opsli.modulars.generator.template.wrapper.GenTemplateDetailModel;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
* Api
*
* API @GetMapping @PostMapping
* Mapping Controller
*
*
*
* @author
* @date 2021-05-28 17:12:38
*/
public interface GenTemplateDetailRestApi {
/** 标题 */
String TITLE = "代码模板详情";
/** 子标题 */
String SUB_TITLE = "代码模板详情";
/**
*
* @param model
* @return ResultVo
*/
@GetMapping("/get")
ResultVo<GenTemplateDetailModel> get(GenTemplateDetailModel model);
/**
*
* @param pageNo
* @param pageSize
* @param request request
* @return ResultVo
*/
@GetMapping("/findPage")
ResultVo<?> findPage(
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
HttpServletRequest request
);
/**
*
* @param model
* @return ResultVo
*/
@PostMapping("/insert")
ResultVo<?> insert(@RequestBody GenTemplateDetailModel model);
/**
*
* @param model
* @return ResultVo
*/
@PostMapping("/update")
ResultVo<?> update(@RequestBody GenTemplateDetailModel model);
/**
*
* @param id ID
* @return ResultVo
*/
@PostMapping("/del")
ResultVo<?> del(String id);
/**
*
* @param ids ID
* @return ResultVo
*/
@PostMapping("/delAll")
ResultVo<?> delAll(String ids);
/**
* Excel
*
* Token
*
* 使2
*
* socketJava
* response javascript alert
*
* @param request request
* @param response response
*/
@GetMapping("/exportExcel")
void exportExcel(HttpServletRequest request, HttpServletResponse response);
/**
* Excel
* @param request request
* @return ResultVo
*/
@PostMapping("/importExcel")
ResultVo<?> importExcel(MultipartHttpServletRequest request);
/**
* Excel
* @param response response
*/
@GetMapping("/importExcel/template")
void importTemplate(HttpServletResponse response);
/**
* Excel
* @param parentId parentId
* @return ResultVo
*/
@GetMapping("/findListByParentId")
ResultVo<List<GenTemplateDetailModel>> findListByParentId(String parentId);
}

@ -0,0 +1,152 @@
/**
* Copyright 2020 OPSLI https://www.opsli.com
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.opsli.modulars.generator.template.api;
import org.opsli.api.base.result.ResultVo;
import org.opsli.modulars.generator.template.wrapper.GenTemplateAndDetailModel;
import org.opsli.modulars.generator.template.wrapper.GenTemplateModel;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Api
*
* API @GetMapping @PostMapping
* Mapping Controller
*
*
*
* @author
* @date 2021-05-27 14:33:49
*/
public interface GenTemplateRestApi {
/** 标题 */
String TITLE = "代码模板";
/** 子标题 */
String SUB_TITLE = "代码模板";
/**
*
* @param model
* @return ResultVo
*/
@GetMapping("/get")
ResultVo<GenTemplateModel> get(GenTemplateModel model);
/**
*
* @param pageNo
* @param pageSize
* @param request request
* @return ResultVo
*/
@GetMapping("/findPage")
ResultVo<?> findPage(
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
HttpServletRequest request
);
/**
*
* @param model
* @return ResultVo
*/
@PostMapping("/insert")
ResultVo<?> insert(@RequestBody GenTemplateModel model);
/**
*
* @param model
* @return ResultVo
*/
@PostMapping("/insertAndDetail")
ResultVo<?> insertAndDetail(@RequestBody GenTemplateAndDetailModel model);
/**
*
* @param model
* @return ResultVo
*/
@PostMapping("/update")
ResultVo<?> update(@RequestBody GenTemplateModel model);
/**
*
* @param model
* @return ResultVo
*/
@PostMapping("/updateAndDetail")
ResultVo<?> updateAndDetail(@RequestBody GenTemplateAndDetailModel model);
/**
*
* @param id ID
* @return ResultVo
*/
@PostMapping("/del")
ResultVo<?> del(String id);
/**
*
* @param ids ID
* @return ResultVo
*/
@PostMapping("/delAll")
ResultVo<?> delAll(String ids);
/**
* Excel
*
* Token
*
* 使2
*
* socketJava
* response javascript alert
*
* @param request request
* @param response response
*/
@GetMapping("/exportExcel")
void exportExcel(HttpServletRequest request, HttpServletResponse response);
/**
* Excel
* @param request request
* @return ResultVo
*/
@PostMapping("/importExcel")
ResultVo<?> importExcel(MultipartHttpServletRequest request);
/**
* Excel
* @param response response
*/
@GetMapping("/importExcel/template")
void importTemplate(HttpServletResponse response);
}

@ -0,0 +1,54 @@
/**
* Copyright 2020 OPSLI https://www.opsli.com
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.opsli.modulars.generator.template.entity;
import java.math.BigDecimal;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.FieldStrategy;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableLogic;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.opsli.core.base.entity.BaseEntity;
/**
* Entity
*
* @author
* @date 2021-05-27 14:33:49
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class GenTemplate extends BaseEntity {
/** 模板名称 */
private String tempName;
/** 表类型 */
private String tableType;
/** 备注信息 */
private String remark;
// ========================================
}

@ -0,0 +1,58 @@
/**
* Copyright 2020 OPSLI https://www.opsli.com
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.opsli.modulars.generator.template.entity;
import java.math.BigDecimal;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.FieldStrategy;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableLogic;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.opsli.core.base.entity.BaseEntity;
/**
* Entity
*
* @author
* @date 2021-05-28 17:12:38
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class GenTemplateDetail extends BaseEntity {
/** 父级ID */
private String parentId;
/** 路径 */
private String path;
/** 文件名 */
private String fileName;
/** 文件内容 */
private String fileContent;
// ========================================
}

@ -0,0 +1,36 @@
/**
* Copyright 2020 OPSLI https://www.opsli.com
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.opsli.modulars.generator.template.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.opsli.modulars.generator.template.entity.GenTemplateDetail;
/**
* Mapper
*
* @author
* @date 2021-05-28 17:12:38
*/
@Mapper
public interface GenTemplateDetailMapper extends BaseMapper<GenTemplateDetail> {
}

@ -0,0 +1,36 @@
/**
* Copyright 2020 OPSLI https://www.opsli.com
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.opsli.modulars.generator.template.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.opsli.modulars.generator.template.entity.GenTemplate;
/**
* Mapper
*
* @author
* @date 2021-05-27 14:33:49
*/
@Mapper
public interface GenTemplateMapper extends BaseMapper<GenTemplate> {
}

@ -0,0 +1,7 @@
<?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.generator.template.mapper.GenTemplateDetailMapper">
</mapper>

@ -0,0 +1,8 @@
<?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.generator.template.mapper.GenTemplateMapper">
</mapper>

@ -0,0 +1,49 @@
/**
* Copyright 2020 OPSLI https://www.opsli.com
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.opsli.modulars.generator.template.service;
import org.opsli.core.base.service.interfaces.CrudServiceInterface;
import org.opsli.modulars.generator.template.entity.GenTemplateDetail;
import org.opsli.modulars.generator.template.wrapper.GenTemplateDetailModel;
import java.util.List;
/**
* Service
*
* @author
* @date 2021-05-28 17:12:38
*/
public interface IGenTemplateDetailService extends CrudServiceInterface<GenTemplateDetail, GenTemplateDetailModel> {
/**
* ID
* @param parentId ID
* @return boolean
*/
boolean delByParent(String parentId);
/**
* ID List
* @param parentId ID
* @return List
*/
List<GenTemplateDetailModel> findListByParent(String parentId);
}

@ -0,0 +1,52 @@
/**
* Copyright 2020 OPSLI https://www.opsli.com
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.opsli.modulars.generator.template.service;
import org.opsli.core.base.service.interfaces.CrudServiceInterface;
import org.opsli.modulars.generator.template.entity.GenTemplate;
import org.opsli.modulars.generator.template.wrapper.GenTemplateAndDetailModel;
import org.opsli.modulars.generator.template.wrapper.GenTemplateModel;
/**
* Service
*
* @author
* @date 2021-05-27 14:33:49
*/
public interface IGenTemplateService extends CrudServiceInterface<GenTemplate, GenTemplateModel> {
/**
*
* @param model model
* @return GenTemplateModel
*/
GenTemplateModel insertAndDetail(GenTemplateAndDetailModel model);
/**
*
* @param model model
* @return GenTemplateModel
*/
GenTemplateModel updateAndDetail(GenTemplateAndDetailModel model);
}

@ -0,0 +1,230 @@
/**
* Copyright 2020 OPSLI https://www.opsli.com
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.opsli.modulars.generator.template.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
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.common.constants.MyBatisConstants;
import org.opsli.common.exception.ServiceException;
import org.opsli.common.utils.FieldUtil;
import org.opsli.core.base.service.impl.CrudServiceImpl;
import org.opsli.core.msg.CoreMsg;
import org.opsli.core.persistence.querybuilder.GenQueryBuilder;
import org.opsli.core.persistence.querybuilder.QueryBuilder;
import org.opsli.modulars.generator.template.entity.GenTemplateDetail;
import org.opsli.modulars.generator.template.mapper.GenTemplateDetailMapper;
import org.opsli.modulars.generator.template.service.IGenTemplateDetailService;
import org.opsli.modulars.generator.template.wrapper.GenTemplateDetailModel;
import org.opsli.plugins.generator.utils.GenTemplateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* Service Impl
*
* @author
* @date 2021-05-28 17:12:38
*/
@Service
public class GenTemplateDetailServiceImpl extends CrudServiceImpl<GenTemplateDetailMapper, GenTemplateDetail, GenTemplateDetailModel>
implements IGenTemplateDetailService {
@Autowired(required = false)
private GenTemplateDetailMapper mapper;
/**
*
* @param model model
* @return DictDetailModel
*/
@Transactional(rollbackFor = Exception.class)
@Override
public GenTemplateDetailModel insert(GenTemplateDetailModel model) {
GenTemplateDetailModel ret = super.insert(model);
if(ret != null){
// 删除缓存
this.clearCache(Collections.singletonList(
ret.getParentId()
));
}
return ret;
}
/**
*
* @param model model
* @return GenTemplateDetailModel
*/
@Transactional(rollbackFor = Exception.class)
@Override
public GenTemplateDetailModel update(GenTemplateDetailModel model) {
// 旧数据 用于删除老缓存
GenTemplateDetailModel oldModel = this.get(model);
GenTemplateDetailModel ret = super.update(model);
if(ret != null){
// 删除缓存
this.clearCache(Collections.singletonList(
oldModel.getParentId()
));
}
return ret;
}
/**
*
* @param id ID
* @return boolean
*/
@Override
@Transactional(rollbackFor = Exception.class)
public boolean delete(String id) {
GenTemplateDetailModel baseModel = this.get(id);
boolean ret = super.delete(id);
if(ret){
// 删除缓存
this.clearCache(Collections.singletonList(
baseModel.getParentId()
));
}
return ret;
}
/**
* -
* @param ids id
* @return boolean
*/
@Override
@Transactional(rollbackFor = Exception.class)
public boolean deleteAll(String[] ids) {
QueryBuilder<GenTemplateDetail> queryBuilder = new GenQueryBuilder<>();
QueryWrapper<GenTemplateDetail> queryWrapper = queryBuilder.build();
List<?> idList = Convert.toList(ids);
queryWrapper.in(FieldUtil.humpToUnderline(MyBatisConstants.FIELD_ID),idList);
List<GenTemplateDetail> list = this.findList(queryWrapper);
boolean ret = super.deleteAll(ids);
if(ret){
if(CollUtil.isNotEmpty(list)){
Set<String> parentIds = new HashSet<>();
// 封装数据
for (GenTemplateDetail genTemplateDetail : list) {
parentIds.add(genTemplateDetail.getParentId());
}
List<String> parentIdList = Lists.newArrayListWithCapacity(parentIds.size());
// 删除缓存
this.clearCache(parentIdList);
}
}
return ret;
}
/**
* ID
* @param parentId ID
* @return boolean
*/
@Transactional(rollbackFor = Exception.class)
@Override
public boolean delByParent(String parentId) {
if(StringUtils.isEmpty(parentId)) {
return false;
}
String key = FieldUtil.humpToUnderline(MyBatisConstants.FIELD_PARENT_ID);
QueryBuilder<GenTemplateDetail> queryBuilder = new GenQueryBuilder<>();
QueryWrapper<GenTemplateDetail> queryWrapper = queryBuilder.build();
queryWrapper.eq(key, parentId);
boolean removeFlag = super.remove(queryWrapper);
if(removeFlag){
// 删除缓存
this.clearCache(Collections.singletonList(
parentId
));
}
return removeFlag;
}
/**
* ID
* @param parentId ID
* @return boolean
*/
@Transactional(rollbackFor = Exception.class)
@Override
public List<GenTemplateDetailModel> findListByParent(String parentId) {
if(StringUtils.isEmpty(parentId)) {
return ListUtil.empty();
}
String key = FieldUtil.humpToUnderline(MyBatisConstants.FIELD_PARENT_ID);
QueryBuilder<GenTemplateDetail> queryBuilder = new GenQueryBuilder<>();
QueryWrapper<GenTemplateDetail> queryWrapper = queryBuilder.build();
queryWrapper.eq(key, parentId);
return super.transformTs2Ms(this.findList(queryWrapper));
}
// ====================
/**
*
* @param parentIdList ID
*/
private void clearCache(List<String> parentIdList) {
// 删除缓存
if (CollUtil.isNotEmpty(parentIdList)) {
int cacheCount = 0;
for (String parentId : parentIdList) {
cacheCount++;
boolean tmp = GenTemplateUtil.delAll(parentId);
if(tmp){
cacheCount--;
}
}
// 判断删除状态
if(cacheCount != 0){
// 删除缓存失败
throw new ServiceException(CoreMsg.CACHE_DEL_EXCEPTION);
}
}
}
}

@ -0,0 +1,175 @@
/**
* Copyright 2020 OPSLI https://www.opsli.com
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.opsli.modulars.generator.template.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.opsli.common.constants.MyBatisConstants;
import org.opsli.common.exception.ServiceException;
import org.opsli.common.utils.WrapperUtil;
import org.opsli.core.base.service.impl.CrudServiceImpl;
import org.opsli.core.msg.CoreMsg;
import org.opsli.core.persistence.querybuilder.GenQueryBuilder;
import org.opsli.core.persistence.querybuilder.QueryBuilder;
import org.opsli.modulars.generator.template.entity.GenTemplate;
import org.opsli.modulars.generator.template.mapper.GenTemplateMapper;
import org.opsli.modulars.generator.template.service.IGenTemplateDetailService;
import org.opsli.modulars.generator.template.service.IGenTemplateService;
import org.opsli.modulars.generator.template.wrapper.GenTemplateAndDetailModel;
import org.opsli.modulars.generator.template.wrapper.GenTemplateDetailModel;
import org.opsli.modulars.generator.template.wrapper.GenTemplateModel;
import org.opsli.plugins.generator.utils.GenTemplateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Collections;
import java.util.List;
/**
* Service Impl
*
* @author
* @date 2021-05-27 14:33:49
*/
@Service
public class GenTemplateServiceImpl extends CrudServiceImpl<GenTemplateMapper, GenTemplate, GenTemplateModel>
implements IGenTemplateService {
@Autowired(required = false)
private GenTemplateMapper mapper;
@Autowired
private IGenTemplateDetailService iGenTemplateDetailService;
@Transactional(rollbackFor = Exception.class)
@Override
public GenTemplateModel insertAndDetail(GenTemplateAndDetailModel model) {
if(model == null){
return null;
}
GenTemplateModel insertModel = super.insert(
WrapperUtil.transformInstance(model, GenTemplateModel.class));
if(insertModel != null){
// 保存模型明细
List<GenTemplateDetailModel> detailList = model.getDetailList();
if(!CollUtil.isEmpty(detailList)){
for (GenTemplateDetailModel templateDetailModel : detailList) {
templateDetailModel.setParentId(insertModel.getId());
iGenTemplateDetailService.insert(templateDetailModel);
}
}
}
return insertModel;
}
@Transactional(rollbackFor = Exception.class)
@Override
public GenTemplateModel updateAndDetail(GenTemplateAndDetailModel model) {
if(model == null){
return null;
}
GenTemplateModel updateModel = super.update(
WrapperUtil.transformInstance(model, GenTemplateModel.class));
if(updateModel != null){
// 删除子表明细
iGenTemplateDetailService.delByParent(model.getId());
// 保存模型明细
List<GenTemplateDetailModel> detailList = model.getDetailList();
if(!CollUtil.isEmpty(detailList)){
for (GenTemplateDetailModel templateDetailModel : detailList) {
templateDetailModel.setParentId(updateModel.getId());
iGenTemplateDetailService.insert(templateDetailModel);
}
}
// 删除缓存
this.clearCache(Collections.singletonList(
updateModel.getId()
));
}
return updateModel;
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean delete(String id) {
GenTemplateModel base = this.get(id);
if (base == null) {
return false;
}
iGenTemplateDetailService.delByParent(id);
return this.delete(id);
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean deleteAll(String[] ids) {
QueryBuilder<GenTemplate> queryBuilder = new GenQueryBuilder<>();
QueryWrapper<GenTemplate> queryWrapper = queryBuilder.build();
queryWrapper.in(MyBatisConstants.FIELD_ID, Convert.toList(String.class, ids));
// 查询数据 抽取Map 字典 便于后续查询
List<GenTemplate> baseList = this.findList(queryWrapper);
for (GenTemplate base : baseList) {
// 先删除子数据
iGenTemplateDetailService.delByParent(base.getId());
}
return super.deleteAll(ids);
}
// ====================
/**
*
* @param parentIdList ID
*/
private void clearCache(List<String> parentIdList) {
// 删除缓存
if (CollUtil.isNotEmpty(parentIdList)) {
int cacheCount = 0;
for (String parentId : parentIdList) {
cacheCount++;
boolean tmp = GenTemplateUtil.delAll(parentId);
if(tmp){
cacheCount--;
}
}
// 判断删除状态
if(cacheCount != 0){
// 删除缓存失败
throw new ServiceException(CoreMsg.CACHE_DEL_EXCEPTION);
}
}
}
}

@ -0,0 +1,217 @@
/**
* Copyright 2020 OPSLI https://www.opsli.com
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.opsli.modulars.generator.template.web;
import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.convert.Convert;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.opsli.common.annotation.RequiresPermissionsCus;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.opsli.api.base.result.ResultVo;
import org.opsli.common.annotation.ApiRestController;
import org.opsli.common.annotation.EnableLog;
import org.opsli.core.base.controller.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.generator.template.api.GenTemplateDetailRestApi;
import org.opsli.modulars.generator.template.wrapper.GenTemplateDetailModel;
import org.opsli.plugins.generator.utils.GenTemplateUtil;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.Method;
import java.util.List;
import org.opsli.modulars.generator.template.entity.GenTemplateDetail;
import org.opsli.modulars.generator.template.service.IGenTemplateDetailService;
/**
* Controller
*
* @author
* @date 2021-05-28 17:12:38
*/
@Api(tags = GenTemplateDetailRestApi.TITLE)
@Slf4j
@ApiRestController("/generator/template/detail")
public class GenTemplateDetailRestController extends BaseRestController<GenTemplateDetail, GenTemplateDetailModel, IGenTemplateDetailService>
implements GenTemplateDetailRestApi {
/**
*
* @param model
* @return ResultVo
*/
@ApiOperation(value = "获得单条代码模板详情", notes = "获得单条代码模板详情 - ID")
@RequiresPermissions("generator_template_select")
@Override
public ResultVo<GenTemplateDetailModel> get(GenTemplateDetailModel model) {
// 如果系统内部调用 则直接查数据库
if(model != null && model.getIzApi() != null && model.getIzApi()){
model = IService.get(model);
}
return ResultVo.success(model);
}
/**
*
* @param pageNo
* @param pageSize
* @param request request
* @return ResultVo
*/
@ApiOperation(value = "获得分页数据", notes = "获得分页数据 - 查询构造器")
@RequiresPermissions("generator_template_select")
@Override
public ResultVo<?> findPage(Integer pageNo, Integer pageSize, HttpServletRequest request) {
QueryBuilder<GenTemplateDetail> queryBuilder = new WebQueryBuilder<>(entityClazz, request.getParameterMap());
Page<GenTemplateDetail, GenTemplateDetailModel> page = new Page<>(pageNo, pageSize);
page.setQueryWrapper(queryBuilder.build());
page = IService.findPage(page);
return ResultVo.success(page.getPageData());
}
/**
*
* @param model
* @return ResultVo
*/
@ApiOperation(value = "新增代码模板详情数据", notes = "新增代码模板详情数据")
@RequiresPermissions("generator_template_insert")
@EnableLog
@Override
public ResultVo<?> insert(GenTemplateDetailModel model) {
// 调用新增方法
IService.insert(model);
return ResultVo.success("新增代码模板详情成功");
}
/**
*
* @param model
* @return ResultVo
*/
@ApiOperation(value = "修改代码模板详情数据", notes = "修改代码模板详情数据")
@RequiresPermissions("generator_template_update")
@EnableLog
@Override
public ResultVo<?> update(GenTemplateDetailModel model) {
// 调用修改方法
IService.update(model);
return ResultVo.success("修改代码模板详情成功");
}
/**
*
* @param id ID
* @return ResultVo
*/
@ApiOperation(value = "删除代码模板详情数据", notes = "删除代码模板详情数据")
@RequiresPermissions("generator_template_update")
@EnableLog
@Override
public ResultVo<?> del(String id){
IService.delete(id);
return ResultVo.success("删除代码模板详情成功");
}
/**
*
* @param ids ID
* @return ResultVo
*/
@ApiOperation(value = "批量删除代码模板详情数据", notes = "批量删除代码模板详情数据")
@RequiresPermissions("generator_template_update")
@EnableLog
@Override
public ResultVo<?> delAll(String ids){
String[] idArray = Convert.toStrArray(ids);
IService.deleteAll(idArray);
return ResultVo.success("批量删除代码模板详情成功");
}
/**
* Excel
* RequiresPermissionsCus
*
* Token
*
* 使2
*
* socketJava
* response javascript alert
*
* @param request request
* @param response response
*/
@ApiOperation(value = "导出Excel", notes = "导出Excel")
@RequiresPermissionsCus("generator_template_export")
@EnableLog
@Override
public void exportExcel(HttpServletRequest request, HttpServletResponse response) {
// 当前方法
Method method = ReflectUtil.getMethodByName(this.getClass(), "exportExcel");
QueryBuilder<GenTemplateDetail> queryBuilder = new WebQueryBuilder<>(entityClazz, request.getParameterMap());
super.excelExport(GenTemplateDetailRestApi.SUB_TITLE, queryBuilder.build(), response, method);
}
/**
* Excel
* RequiresPermissions Shiro
* @param request request
* @return ResultVo
*/
@ApiOperation(value = "导入Excel", notes = "导入Excel")
@RequiresPermissions("generator_template_import")
@EnableLog
@Override
public ResultVo<?> importExcel(MultipartHttpServletRequest request) {
return super.importExcel(request);
}
/**
* Excel
* RequiresPermissionsCus
* @param response response
*/
@ApiOperation(value = "导出Excel模版", notes = "导出Excel模版")
@RequiresPermissionsCus("generator_template_import")
@Override
public void importTemplate(HttpServletResponse response) {
// 当前方法
Method method = ReflectUtil.getMethodByName(this.getClass(), "importTemplate");
super.importTemplate(GenTemplateDetailRestApi.SUB_TITLE, response, method);
}
@Override
public ResultVo<List<GenTemplateDetailModel>> findListByParentId(String parentId) {
return ResultVo.success(GenTemplateUtil.getTemplateDetailList(parentId));
}
}

@ -0,0 +1,241 @@
/**
* Copyright 2020 OPSLI https://www.opsli.com
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.opsli.modulars.generator.template.web;
import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.convert.Convert;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.opsli.common.annotation.RequiresPermissionsCus;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.opsli.api.base.result.ResultVo;
import org.opsli.common.annotation.ApiRestController;
import org.opsli.common.annotation.EnableLog;
import org.opsli.core.base.controller.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.generator.template.api.GenTemplateRestApi;
import org.opsli.modulars.generator.template.wrapper.GenTemplateAndDetailModel;
import org.opsli.modulars.generator.template.wrapper.GenTemplateModel;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.Method;
import org.opsli.modulars.generator.template.entity.GenTemplate;
import org.opsli.modulars.generator.template.service.IGenTemplateService;
/**
* Controller
*
* @author
* @date 2021-05-27 14:33:49
*/
@Api(tags = GenTemplateRestApi.TITLE)
@Slf4j
@ApiRestController("/generator/template")
public class GenTemplateRestController extends BaseRestController<GenTemplate, GenTemplateModel, IGenTemplateService>
implements GenTemplateRestApi {
/**
*
* @param model
* @return ResultVo
*/
@ApiOperation(value = "获得单条代码模板", notes = "获得单条代码模板 - ID")
@RequiresPermissions("generator_template_select")
@Override
public ResultVo<GenTemplateModel> get(GenTemplateModel model) {
// 如果系统内部调用 则直接查数据库
if(model != null && model.getIzApi() != null && model.getIzApi()){
model = IService.get(model);
}
return ResultVo.success(model);
}
/**
*
* @param pageNo
* @param pageSize
* @param request request
* @return ResultVo
*/
@ApiOperation(value = "获得分页数据", notes = "获得分页数据 - 查询构造器")
@RequiresPermissions("generator_template_select")
@Override
public ResultVo<?> findPage(Integer pageNo, Integer pageSize, HttpServletRequest request) {
QueryBuilder<GenTemplate> queryBuilder = new WebQueryBuilder<>(entityClazz, request.getParameterMap());
Page<GenTemplate, GenTemplateModel> page = new Page<>(pageNo, pageSize);
page.setQueryWrapper(queryBuilder.build());
page = IService.findPage(page);
return ResultVo.success(page.getPageData());
}
/**
*
* @param model
* @return ResultVo
*/
@ApiOperation(value = "新增代码模板数据", notes = "新增代码模板数据")
@RequiresPermissions("generator_template_insert")
@EnableLog
@Override
public ResultVo<?> insert(GenTemplateModel model) {
// 调用新增方法
IService.insert(model);
return ResultVo.success("新增代码模板成功");
}
/**
*
* @param model
* @return ResultVo
*/
@ApiOperation(value = "新增代码模板数据", notes = "新增代码模板数据")
@RequiresPermissions("generator_template_insert")
@EnableLog
@Override
public ResultVo<?> insertAndDetail(GenTemplateAndDetailModel model) {
// 调用新增方法
IService.insertAndDetail(model);
return ResultVo.success("新增代码模板成功");
}
/**
*
* @param model
* @return ResultVo
*/
@ApiOperation(value = "修改代码模板数据", notes = "修改代码模板数据")
@RequiresPermissions("generator_template_update")
@EnableLog
@Override
public ResultVo<?> update(GenTemplateModel model) {
// 调用修改方法
IService.update(model);
return ResultVo.success("修改代码模板成功");
}
/**
*
* @param model
* @return ResultVo
*/
@ApiOperation(value = "修改代码模板数据", notes = "修改代码模板数据")
@RequiresPermissions("generator_template_update")
@EnableLog
@Override
public ResultVo<?> updateAndDetail(GenTemplateAndDetailModel model) {
// 调用修改方法
IService.updateAndDetail(model);
return ResultVo.success("修改代码模板成功");
}
/**
*
* @param id ID
* @return ResultVo
*/
@ApiOperation(value = "删除代码模板数据", notes = "删除代码模板数据")
@RequiresPermissions("generator_template_update")
@EnableLog
@Override
public ResultVo<?> del(String id){
IService.delete(id);
return ResultVo.success("删除代码模板成功");
}
/**
*
* @param ids ID
* @return ResultVo
*/
@ApiOperation(value = "批量删除代码模板数据", notes = "批量删除代码模板数据")
@RequiresPermissions("generator_template_update")
@EnableLog
@Override
public ResultVo<?> delAll(String ids){
String[] idArray = Convert.toStrArray(ids);
IService.deleteAll(idArray);
return ResultVo.success("批量删除代码模板成功");
}
/**
* Excel
* RequiresPermissionsCus
*
* Token
*
* 使2
*
* socketJava
* response javascript alert
*
* @param request request
* @param response response
*/
@ApiOperation(value = "导出Excel", notes = "导出Excel")
@RequiresPermissionsCus("generator_template_export")
@EnableLog
@Override
public void exportExcel(HttpServletRequest request, HttpServletResponse response) {
// 当前方法
Method method = ReflectUtil.getMethodByName(this.getClass(), "exportExcel");
QueryBuilder<GenTemplate> queryBuilder = new WebQueryBuilder<>(entityClazz, request.getParameterMap());
super.excelExport(GenTemplateRestApi.SUB_TITLE, queryBuilder.build(), response, method);
}
/**
* Excel
* RequiresPermissions Shiro
* @param request request
* @return ResultVo
*/
@ApiOperation(value = "导入Excel", notes = "导入Excel")
@RequiresPermissions("generator_template_import")
@EnableLog
@Override
public ResultVo<?> importExcel(MultipartHttpServletRequest request) {
return super.importExcel(request);
}
/**
* Excel
* RequiresPermissionsCus
* @param response response
*/
@ApiOperation(value = "导出Excel模版", notes = "导出Excel模版")
@RequiresPermissionsCus("generator_template_import")
@Override
public void importTemplate(HttpServletResponse response) {
// 当前方法
Method method = ReflectUtil.getMethodByName(this.getClass(), "importTemplate");
super.importTemplate(GenTemplateRestApi.SUB_TITLE, response, method);
}
}

@ -0,0 +1,78 @@
/**
* Copyright 2020 OPSLI https://www.opsli.com
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.opsli.modulars.generator.template.wrapper;
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.validator.Validator;
import org.opsli.common.annotation.validator.ValidatorLenMax;
import org.opsli.common.enums.ValidatorType;
import org.opsli.plugins.excel.annotation.ExcelInfo;
import java.util.List;
/**
* Model
*
* @author
* @date 2021-05-27 14:33:49
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class GenTemplateAndDetailModel extends ApiWrapper {
/** 模板名称 */
@ApiModelProperty(value = "模板名称")
@ExcelProperty(value = "模板名称", order = 1)
@ExcelInfo
@Validator({
ValidatorType.IS_GENERAL_WITH_CHINESE,
ValidatorType.IS_NOT_NULL
})
@ValidatorLenMax(100)
private String tempName;
/** 表类型 */
@ApiModelProperty(value = "表类型")
@ExcelProperty(value = "表类型", order = 2)
@ExcelInfo( dictType = "table_type" )
@Validator({
ValidatorType.IS_NOT_NULL
})
@ValidatorLenMax(30)
private String tableType;
/** 备注信息 */
@ApiModelProperty(value = "备注信息")
@ExcelProperty(value = "备注信息", order = 3)
@ExcelInfo
@ValidatorLenMax(255)
private String remark;
/** 模板信息 */
@ApiModelProperty(value = "模板信息")
@ExcelProperty(value = "模板信息", order = 4)
@ExcelInfo
private List<GenTemplateDetailModel> detailList;
}

@ -0,0 +1,89 @@
/**
* Copyright 2020 OPSLI https://www.opsli.com
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.opsli.modulars.generator.template.wrapper;
import java.math.BigDecimal;
import java.util.Date;
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.validator.Validator;
import org.opsli.common.annotation.validator.ValidatorLenMax;
import org.opsli.common.annotation.validator.ValidatorLenMin;
import org.opsli.common.enums.ValidatorType;
import org.opsli.plugins.excel.annotation.ExcelInfo;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.format.annotation.DateTimeFormat;
/**
* Model
*
* @author
* @date 2021-05-28 17:12:38
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class GenTemplateDetailModel extends ApiWrapper {
/** 父级ID */
@ApiModelProperty(value = "父级ID")
@ExcelProperty(value = "父级ID", order = 1)
@ExcelInfo
@Validator({
ValidatorType.IS_NOT_NULL
})
@ValidatorLenMax(19)
private String parentId;
/** 路径 */
@ApiModelProperty(value = "路径")
@ExcelProperty(value = "路径", order = 2)
@ExcelInfo
@Validator({
ValidatorType.IS_NOT_NULL
})
@ValidatorLenMax(255)
private String path;
/** 文件名 */
@ApiModelProperty(value = "文件名")
@ExcelProperty(value = "文件名", order = 3)
@ExcelInfo
@Validator({
ValidatorType.IS_NOT_NULL
})
@ValidatorLenMax(100)
private String fileName;
/** 文件内容 */
@ApiModelProperty(value = "文件内容")
@ExcelProperty(value = "文件内容", order = 4)
@ExcelInfo
@Validator({
ValidatorType.IS_NOT_NULL
})
@ValidatorLenMax(20000)
private String fileContent;
}

@ -0,0 +1,77 @@
/**
* Copyright 2020 OPSLI https://www.opsli.com
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.opsli.modulars.generator.template.wrapper;
import java.math.BigDecimal;
import java.util.Date;
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.validator.Validator;
import org.opsli.common.annotation.validator.ValidatorLenMax;
import org.opsli.common.annotation.validator.ValidatorLenMin;
import org.opsli.common.enums.ValidatorType;
import org.opsli.plugins.excel.annotation.ExcelInfo;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.format.annotation.DateTimeFormat;
/**
* Model
*
* @author
* @date 2021-05-27 14:33:49
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class GenTemplateModel extends ApiWrapper {
/** 模板名称 */
@ApiModelProperty(value = "模板名称")
@ExcelProperty(value = "模板名称", order = 1)
@ExcelInfo
@Validator({
ValidatorType.IS_GENERAL_WITH_CHINESE,
ValidatorType.IS_NOT_NULL
})
@ValidatorLenMax(100)
private String tempName;
/** 表类型 */
@ApiModelProperty(value = "表类型")
@ExcelProperty(value = "表类型", order = 2)
@ExcelInfo( dictType = "table_type" )
@Validator({
ValidatorType.IS_NOT_NULL
})
@ValidatorLenMax(30)
private String tableType;
/** 备注信息 */
@ApiModelProperty(value = "备注信息")
@ExcelProperty(value = "备注信息", order = 3)
@ExcelInfo
@ValidatorLenMax(255)
private String remark;
}

@ -0,0 +1,294 @@
/**
* Copyright 2020 OPSLI https://www.opsli.com
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.opsli.plugins.generator.utils;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.comparator.CompareUtil;
import cn.hutool.core.convert.Convert;
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.DictDetailModel;
import org.opsli.api.wrapper.system.dict.DictWrapper;
import org.opsli.common.constants.DictConstants;
import org.opsli.core.cache.local.CacheUtil;
import org.opsli.core.msg.CoreMsg;
import org.opsli.core.utils.DictUtil;
import org.opsli.core.utils.DistributedLockUtil;
import org.opsli.core.utils.ThrowExceptionUtil;
import org.opsli.modulars.generator.template.service.IGenTemplateDetailService;
import org.opsli.modulars.generator.template.wrapper.GenTemplateDetailModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Map;
import static org.opsli.common.constants.OrderConstants.UTIL_ORDER;
/**
*
*
* @author parker
* @date 2020-09-22 11:17
*/
@Slf4j
@Order(UTIL_ORDER)
@Component
@Lazy(false)
public class GenTemplateUtil {
/** 增加初始状态开关 防止异常使用 */
private static boolean IS_INIT;
/** 缓存前缀 NAME */
private static final String CACHE_PREFIX_NAME = "gen:template:";
/** 代码模板明细 Service */
private static IGenTemplateDetailService genTemplateDetailService;
/**
* ID
* @param parentId ID
* @return List
*/
public static List<GenTemplateDetailModel> getTemplateDetailList(String parentId){
// 判断 工具类是否初始化完成
ThrowExceptionUtil.isThrowException(!IS_INIT,
CoreMsg.OTHER_EXCEPTION_UTILS_INIT);
// 缓存Key
String cacheKey = CACHE_PREFIX_NAME + parentId;
// 处理集合数据
List<GenTemplateDetailModel> wrapperModels = handleDictList(
CacheUtil.getHashAll(cacheKey), parentId);
if(CollUtil.isNotEmpty(wrapperModels)){
return sortWrappers(wrapperModels);
}
// 防止缓存穿透判断
boolean hasNilFlag = CacheUtil.hasNilFlag(cacheKey);
if(hasNilFlag){
return sortWrappers(wrapperModels);
}
try {
// 分布式加锁
if(!DistributedLockUtil.lock(cacheKey)){
// 无法申领分布式锁
log.error(CoreMsg.REDIS_EXCEPTION_LOCK.getMessage());
return sortWrappers(wrapperModels);
}
// 如果获得锁 则 再次检查缓存里有没有, 如果有则直接退出, 没有的话才发起数据库请求
// 处理集合数据
wrapperModels = handleDictList(
CacheUtil.getHashAll(cacheKey), parentId);
if(CollUtil.isNotEmpty(wrapperModels)){
return sortWrappers(wrapperModels);
}
List<GenTemplateDetailModel> listByParent = genTemplateDetailService.findListByParent(parentId);
// 处理数据库查询数据
if(CollUtil.isNotEmpty(listByParent)){
wrapperModels = listByParent;
// 计数器
int count = wrapperModels.size();
for (GenTemplateDetailModel model : wrapperModels) {
// 保存至缓存
boolean ret = GenTemplateUtil.put(model);
if(ret){
count--;
}
}
// 回滚 清空缓存
if(count != 0){
for (GenTemplateDetailModel model : wrapperModels) {
GenTemplateUtil.del(model);
}
}
return sortWrappers(wrapperModels);
}
}catch (Exception e){
log.error(e.getMessage(),e);
}finally {
// 释放锁
DistributedLockUtil.unlock(cacheKey);
}
// 如果值还是 为空 则赋默认值
if(CollUtil.isEmpty(wrapperModels)){
// 加入缓存防穿透
// 设置空变量 用于防止穿透判断
CacheUtil.putNilFlag(cacheKey);
}
// 排序
return sortWrappers(wrapperModels);
}
/**
*
* @param wrapperModels Model
* @return List
*/
private static List<GenTemplateDetailModel> sortWrappers(List<GenTemplateDetailModel> wrapperModels) {
// 非法判读
if(wrapperModels == null){
return null;
}
return ListUtil.sort(wrapperModels,
(o1, o2) -> CompareUtil.compare(o1.getFileName(), o2.getFileName()));
}
// ===============
/**
*
* @param model
*/
private static boolean put(GenTemplateDetailModel model){
// 判断 工具类是否初始化完成
ThrowExceptionUtil.isThrowException(!IS_INIT,
CoreMsg.OTHER_EXCEPTION_UTILS_INIT);
// 清除缓存
GenTemplateUtil.del(model);
return CacheUtil.putHash(CACHE_PREFIX_NAME + model.getParentId(),
model.getId(), model);
}
/**
*
* @param model
* @return boolean
*/
public static boolean del(GenTemplateDetailModel model){
// 判断 工具类是否初始化完成
ThrowExceptionUtil.isThrowException(!IS_INIT,
CoreMsg.OTHER_EXCEPTION_UTILS_INIT);
if(model == null){
return true;
}
boolean hasNilFlag = CacheUtil.hasNilFlag(CACHE_PREFIX_NAME +
model.getParentId() + ":" + model.getId());
GenTemplateDetailModel templateDetailModel = CacheUtil.getHash(GenTemplateDetailModel.class,
CACHE_PREFIX_NAME + model.getParentId(),
model.getId());
// 计数器
int count = 0;
if (hasNilFlag){
count++;
// 清除空拦截
boolean tmp = CacheUtil.delNilFlag(CACHE_PREFIX_NAME +
model.getParentId() + ":" + model.getId());
if(tmp){
count--;
}
}
if (templateDetailModel != null){
count++;
// 清除空拦截
boolean tmp = CacheUtil.delHash(CACHE_PREFIX_NAME +
model.getParentId(), model.getId());
if(tmp){
count--;
}
}
return count == 0;
}
/**
* parentId
* @param parentId ID
* @return boolean
*/
public static boolean delAll(String parentId){
// 判断 工具类是否初始化完成
ThrowExceptionUtil.isThrowException(!IS_INIT,
CoreMsg.OTHER_EXCEPTION_UTILS_INIT);
List<GenTemplateDetailModel> wrapperList = GenTemplateUtil.getTemplateDetailList(parentId);
if(CollUtil.isEmpty(wrapperList)){
return true;
}
// 计数器
int count = wrapperList.size();
for (GenTemplateDetailModel wrapperModel : wrapperList) {
boolean tmp = GenTemplateUtil.del(wrapperModel);
if(tmp){
count--;
}
}
return count == 0;
}
/***
*
* @param tempMap Map
* @param id ID
* @return List
*/
public static List<GenTemplateDetailModel> handleDictList(Map<String, Object> tempMap, String id){
List<GenTemplateDetailModel> wrapperModels = Lists.newArrayList();
if(CollUtil.isNotEmpty(tempMap)){
for (Map.Entry<String, Object> entry : tempMap.entrySet()) {
// 赋值
Object data = entry.getValue();
GenTemplateDetailModel templateDetailModel = Convert.convert(GenTemplateDetailModel.class, data);
wrapperModels.add(templateDetailModel);
}
}
// 返回排序后 list
return CollUtil.isNotEmpty(wrapperModels)?sortWrappers(wrapperModels):wrapperModels;
}
// ===================================
/**
*
*/
@Autowired
public void init(IGenTemplateDetailService genTemplateDetailService) {
GenTemplateUtil.genTemplateDetailService = genTemplateDetailService;
IS_INIT = true;
}
}

@ -5,6 +5,8 @@ opsli:
- gen_table - gen_table
- gen_table_column - gen_table_column
- gen_logs - gen_logs
- gen_template
- gen_template_detail
- sys_dict - sys_dict
- sys_dict_detail - sys_dict_detail
- sys_logs - sys_logs

@ -126,6 +126,7 @@ public interface #(data.model.tableHumpName)RestApi {
/** /**
* #(data.codeTitle) Excel * #(data.codeTitle) Excel
* @param request request * @param request request
* @return ResultVo
*/ */
@PostMapping("/importExcel") @PostMapping("/importExcel")
ResultVo<?> importExcel(MultipartHttpServletRequest request); ResultVo<?> importExcel(MultipartHttpServletRequest request);

@ -21,7 +21,6 @@ package #(data.packageName+"."+data.moduleName).web;
import cn.hutool.core.util.ReflectUtil; import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.convert.Convert; import cn.hutool.core.convert.Convert;
import org.opsli.core.base.service.interfaces.CrudServiceInterface;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;

@ -213,7 +213,7 @@
</el-button> </el-button>
#if(data.model.moreQueryList.size() > 0) #if(data.model.moreQueryList != null && data.model.moreQueryList.size() > 0)
<el-button icon="el-icon-search" @click="moreQuery"> <el-button icon="el-icon-search" @click="moreQuery">
</el-button> </el-button>

Loading…
Cancel
Save