add 通用增删查改基础
This commit is contained in:
+16
@@ -0,0 +1,16 @@
|
||||
package com.jero.modules.laws.common.constant;
|
||||
|
||||
/**
|
||||
* @Author: liao
|
||||
* @Date: 2023/8/24 14:01
|
||||
* @Description: 返回常量
|
||||
*/
|
||||
public class ResultCommon {
|
||||
|
||||
private ResultCommon() {}
|
||||
|
||||
public static final String OK = "message.ok"; // 操作成功
|
||||
|
||||
public static final String ERROR = "message.error"; // 操作失败
|
||||
|
||||
}
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
package com.jero.modules.laws.common.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.jero.common.api.vo.Result;
|
||||
import com.jero.common.aspect.annotation.AutoLog;
|
||||
import com.jero.modules.laws.common.service.ILawsCommonService;
|
||||
import com.jero.modules.tag.entity.LawsTag;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author: liao
|
||||
* @Date: 2023/8/24 10:26
|
||||
* @Description: 标准法规库-通用操作
|
||||
*/
|
||||
@Api(tags="通用操作")
|
||||
@RestController
|
||||
@RequestMapping("/laws/common")
|
||||
public class LawsCommonController {
|
||||
|
||||
@Autowired
|
||||
private ILawsCommonService lawsCommonService;
|
||||
|
||||
@AutoLog(value = "通用操作-分页列表查询")
|
||||
@ApiOperation(value="通用操作-分页列表查询", notes="通用操作-分页列表查询")
|
||||
@PostMapping(value = "/getCommonPage")
|
||||
public Result<IPage<Map<String,Object>>> getCommonPage(@RequestBody Map<String,Object> parameterMap) {
|
||||
return Result.OK(lawsCommonService.getCommonPage(parameterMap));
|
||||
}
|
||||
|
||||
@AutoLog(value = "通用操作-获取列表表头")
|
||||
@ApiOperation(value="通用操作-获取列表表头", notes="通用操作-获取列表表头")
|
||||
@GetMapping(value = "getCommonHeader")
|
||||
public Result<List<LawsTag>> getCommonHeader(@RequestParam(name="module") String module) {
|
||||
return Result.OK(lawsCommonService.getCommonHeader(module));
|
||||
}
|
||||
|
||||
@AutoLog(value = "通用操作-新增数据")
|
||||
@ApiOperation(value="通用操作-新增数据", notes="通用操作-新增数据")
|
||||
@PostMapping(value = "/commonAdd")
|
||||
public Result<String> commonAdd(@RequestBody Map<String,Object> parameterMap) {
|
||||
return Result.OK(lawsCommonService.commonAdd(parameterMap));
|
||||
}
|
||||
|
||||
@AutoLog(value = "通用操作-编辑数据")
|
||||
@ApiOperation(value="通用操作-编辑数据", notes="通用操作-编辑数据")
|
||||
@PostMapping(value = "/commonEdit")
|
||||
public Result<String> commonEdit(@RequestBody Map<String,Object> parameterMap) {
|
||||
return Result.OK(lawsCommonService.commonEdit(parameterMap));
|
||||
}
|
||||
|
||||
@AutoLog(value = "通用操作-获取查询条件")
|
||||
@ApiOperation(value="通用操作-获取查询条件", notes="通用操作-获取查询条件")
|
||||
@GetMapping(value = "getQueryCondition")
|
||||
public Result<List<Map<String,Object>>> getQueryCondition(@RequestParam(name="module") String module) {
|
||||
return Result.OK(lawsCommonService.getQueryCondition(module));
|
||||
}
|
||||
|
||||
@AutoLog(value = "通用操作-获取表单模型")
|
||||
@ApiOperation(value="通用操作-获取表单模型", notes="通用操作-获取表单模型")
|
||||
@GetMapping(value = "getFormModel")
|
||||
public Result<List<Map<String,Object>>> getFormModel(@RequestParam(name="module") String module) {
|
||||
return Result.OK(lawsCommonService.getFormModel(module));
|
||||
}
|
||||
|
||||
@AutoLog(value = "通用操作-根据id和模块标识获取信息")
|
||||
@ApiOperation(value="通用操作-根据id和模块标识获取信息", notes="通用操作-根据id和模块标识获取信息")
|
||||
@GetMapping(value = "getByIdAndModule")
|
||||
public Result<Map<String,Object>> getByIdAndModule(@RequestParam(name="id") String id,
|
||||
@RequestParam(name="module") String module) {
|
||||
return Result.OK(lawsCommonService.getByIdAndModule(id, module));
|
||||
}
|
||||
|
||||
@AutoLog(value = "通用操作-根据ids和模块标识删除信息")
|
||||
@ApiOperation(value="通用操作-根据ids和模块标识删除信息", notes="通用操作-根据ids和模块标识删除信息")
|
||||
@GetMapping(value = "deleteByIdsAndModule")
|
||||
public Result<String> deleteByIdsAndModule(@RequestParam(name="ids") String ids,
|
||||
@RequestParam(name="module") String module) {
|
||||
return Result.OK(lawsCommonService.deleteByIdsAndModule(ids, module));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package com.jero.modules.laws.common.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.jero.modules.tag.entity.LawsTag;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author: liao
|
||||
* @Date: 2023/8/23 16:49
|
||||
* @Description: 通用
|
||||
*/
|
||||
@Mapper
|
||||
public interface CommonMapper {
|
||||
|
||||
/**
|
||||
* @Author: liao
|
||||
* @Date: 2023/8/23 17:02
|
||||
* @Description: 根据表名获取该表全部字段
|
||||
**/
|
||||
List<LawsTag> getFieldList(@Param("tableName") String tableName);
|
||||
|
||||
IPage<Map<String,Object>> getInfoPage(@org.apache.ibatis.annotations.Param("page") IPage<Map<String,Object>> page,
|
||||
@org.apache.ibatis.annotations.Param("table") String table,
|
||||
@org.apache.ibatis.annotations.Param("field") String field,
|
||||
@org.apache.ibatis.annotations.Param("condition") String condition);
|
||||
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
package com.jero.modules.laws.common.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.jero.modules.tag.entity.LawsTag;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author: liao
|
||||
* @Date: 2023/8/23 16:49
|
||||
* @Description: 通用
|
||||
*/
|
||||
@Mapper
|
||||
public interface LawsCommonMapper {
|
||||
|
||||
/**
|
||||
* @Author: liao
|
||||
* @Date: 2023/8/23 17:02
|
||||
* @Description: 获取全部字段
|
||||
**/
|
||||
List<LawsTag> getFieldList(@org.apache.ibatis.annotations.Param("tableName") String tableName);
|
||||
|
||||
/**
|
||||
* @Author: liao
|
||||
* @Date: 2023/8/24 10:10
|
||||
* @Description: 通用分页查询
|
||||
**/
|
||||
IPage<Map<String,Object>> getCommonPage(@org.apache.ibatis.annotations.Param("page") IPage<Map<String,Object>> page,
|
||||
@org.apache.ibatis.annotations.Param("table") String table,
|
||||
@org.apache.ibatis.annotations.Param("field") String field,
|
||||
@org.apache.ibatis.annotations.Param("condition") String condition);
|
||||
|
||||
/**
|
||||
* @Author: liao
|
||||
* @Date: 2023/8/24 10:15
|
||||
* @Description: 通用新增数据
|
||||
**/
|
||||
int commonAdd(@org.apache.ibatis.annotations.Param("tableName") String tableName,
|
||||
@org.apache.ibatis.annotations.Param("fields") String fields,
|
||||
@org.apache.ibatis.annotations.Param("values") String values);
|
||||
|
||||
|
||||
/**
|
||||
* @Author: liao
|
||||
* @Date: 2023/8/24 15:00
|
||||
* @Description: 根据id和模块标识获取信息
|
||||
**/
|
||||
Map<String, Object> getByIdAndModule(@org.apache.ibatis.annotations.Param("tableName") String tableName,
|
||||
@org.apache.ibatis.annotations.Param("selectField") String selectField,
|
||||
@org.apache.ibatis.annotations.Param("id") String id);
|
||||
|
||||
|
||||
/**
|
||||
* @Author: liao
|
||||
* @Date: 2023/8/24 15:00
|
||||
* @Description: 根据ids和模块标识删除信息
|
||||
**/
|
||||
int deleteByIdsAndModule(@org.apache.ibatis.annotations.Param("tableName") String tableName,
|
||||
@org.apache.ibatis.annotations.Param("idList") List<String> idList);
|
||||
|
||||
/**
|
||||
* @Author: liao
|
||||
* @Date: 2023/8/24 15:00
|
||||
* @Description: 编辑数据
|
||||
**/
|
||||
int commonEdit(@org.apache.ibatis.annotations.Param("tableName") String tableName,
|
||||
@org.apache.ibatis.annotations.Param("updateSql") String updateSql,
|
||||
@org.apache.ibatis.annotations.Param("id") String id);
|
||||
}
|
||||
-18
@@ -1,18 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.jero.modules.laws.common.mapper.CommonMapper">
|
||||
|
||||
<select id="getFieldList" resultType="com.jero.modules.tag.entity.LawsTag">
|
||||
select *
|
||||
from laws_tag tag
|
||||
left join laws_area area on tag.show_area = area.id
|
||||
where tag.table_name = #{tableName}
|
||||
and tag.is_delete = 0
|
||||
order by area.sort asc, tag.order_num asc, tag.create_time asc
|
||||
</select>
|
||||
|
||||
<select id="getInfoPage" resultType="java.util.Map">
|
||||
select ${field} from ${table} ${condition}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.jero.modules.laws.common.mapper.LawsCommonMapper">
|
||||
|
||||
<select id="getFieldList" resultType="com.jero.modules.tag.entity.LawsTag">
|
||||
SELECT * FROM laws_tag tag
|
||||
LEFT JOIN laws_area area ON tag.show_area = area.id
|
||||
WHERE tag.table_name = #{tableName} AND tag.is_delete = 0
|
||||
ORDER BY area.sort ASC, tag.order_num ASC, tag.create_time ASC
|
||||
</select>
|
||||
|
||||
<select id="getCommonPage" resultType="java.util.Map">
|
||||
SELECT ${field} FROM ${table} ${condition}
|
||||
</select>
|
||||
|
||||
<insert id="commonAdd">
|
||||
INSERT INTO ${tableName} (${fields}) VALUES (${values})
|
||||
</insert>
|
||||
|
||||
<select id="getByIdAndModule" resultType="java.util.Map">
|
||||
SELECT ${selectField} FROM ${tableName} WHERE id = #{id}
|
||||
</select>
|
||||
|
||||
<delete id="deleteByIdsAndModule">
|
||||
DELETE FROM ${tableName} WHERE id IN
|
||||
<foreach collection="idList" item="id" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<update id="commonEdit">
|
||||
UPDATE ${tableName}
|
||||
SET ${updateSql}
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
-21
@@ -1,21 +0,0 @@
|
||||
package com.jero.modules.laws.common.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author: liao
|
||||
* @Date: 2023/8/23 16:54
|
||||
* @Description: 通用
|
||||
*/
|
||||
public interface ICommonService {
|
||||
|
||||
/**
|
||||
* @Author: liao
|
||||
* @Date: 2023/8/23 16:56
|
||||
* @Description: 通用分页查询
|
||||
**/
|
||||
IPage<Map<String,Object>> getCommonPage(Map<String, Object> parameterMap);
|
||||
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
package com.jero.modules.laws.common.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.jero.modules.tag.entity.LawsTag;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author: liao
|
||||
* @Date: 2023/8/23 16:54
|
||||
* @Description: 通用
|
||||
*/
|
||||
public interface ILawsCommonService {
|
||||
|
||||
/**
|
||||
* @Author: liao
|
||||
* @Date: 2023/8/23 16:56
|
||||
* @Description: 通用分页查询
|
||||
**/
|
||||
IPage<Map<String,Object>> getCommonPage(Map<String, Object> parameterMap);
|
||||
|
||||
/**
|
||||
* @Author: liao
|
||||
* @Date: 2023/8/24 9:09
|
||||
* @Description: 获取通用表头
|
||||
**/
|
||||
List<LawsTag> getCommonHeader(String module);
|
||||
|
||||
/**
|
||||
* @Author: liao
|
||||
* @Date: 2023/8/24 9:33
|
||||
* @Description: 通用新增数据
|
||||
**/
|
||||
String commonAdd(Map<String, Object> parameterMap);
|
||||
|
||||
/**
|
||||
* @Author: liao
|
||||
* @Date: 2023/8/24 14:12
|
||||
* @Description: 编辑数据
|
||||
**/
|
||||
String commonEdit(Map<String, Object> parameterMap);
|
||||
|
||||
/**
|
||||
* @Author: liao
|
||||
* @Date: 2023/8/24 10:41
|
||||
* @Description: 获取查询条件
|
||||
**/
|
||||
List<Map<String, Object>> getQueryCondition(String module);
|
||||
|
||||
/**
|
||||
* @Author: liao
|
||||
* @Date: 2023/8/24 10:53
|
||||
* @Description: 获取表单模型
|
||||
**/
|
||||
List<Map<String, Object>> getFormModel(String module);
|
||||
|
||||
/**
|
||||
* @Author: liao
|
||||
* @Date: 2023/8/24 11:49
|
||||
* @Description: 根据id和模块标识获取信息
|
||||
**/
|
||||
Map<String, Object> getByIdAndModule(String id, String module);
|
||||
|
||||
/**
|
||||
* @Author: liao
|
||||
* @Date: 2023/8/24 13:52
|
||||
* @Description: 根据ids和模块标识删除信息
|
||||
**/
|
||||
String deleteByIdsAndModule(String ids, String module);
|
||||
|
||||
}
|
||||
-204
@@ -1,204 +0,0 @@
|
||||
package com.jero.modules.laws.common.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.jero.common.constant.enums.LanguageEnum;
|
||||
import com.jero.common.constant.enums.YesOrNoEnum;
|
||||
import com.jero.common.util.MessageUtils;
|
||||
import com.jero.modules.document.enums.FieldTypeEnum;
|
||||
import com.jero.modules.laws.common.mapper.CommonMapper;
|
||||
import com.jero.modules.laws.common.service.ICommonService;
|
||||
import com.jero.modules.tag.entity.LawsTag;
|
||||
import com.jero.modules.tag.enums.FileTableIdEnum;
|
||||
import com.spire.ms.System.Collections.ArrayList;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @Author: liao
|
||||
* @Date: 2023/8/23 16:54
|
||||
* @Description: 通用
|
||||
*/
|
||||
@Component
|
||||
public class CommonServiceImpl implements ICommonService {
|
||||
|
||||
@Autowired
|
||||
private CommonMapper commonMapper;
|
||||
|
||||
/**
|
||||
* @Author: liao
|
||||
* @Date: 2023/8/23 16:57
|
||||
* @Description: 通用分页查询
|
||||
**/
|
||||
@Override
|
||||
public IPage<Map<String, Object>> getCommonPage(Map<String, Object> parameterMap) {
|
||||
// 获取操作模块
|
||||
String module = parameterMap.get("module").toString();
|
||||
// 获取要操作的表名
|
||||
String tableName = FileTableIdEnum.getTableName(module);
|
||||
// 获取操作语言
|
||||
LanguageEnum language = MessageUtils.getLanguage();
|
||||
// 获取分页参数
|
||||
Integer pageNo = Integer.valueOf(parameterMap.get("pageNo").toString());
|
||||
Integer pageSize = Integer.valueOf(parameterMap.get("pageSize").toString());
|
||||
IPage<Map<String,Object>> page = new Page<>(pageNo, pageSize);
|
||||
// 封装查询返回字段
|
||||
String selectField = getSelectField(parameterMap, tableName);
|
||||
// 封装查询条件
|
||||
String selectCondition = getSelectCondition(parameterMap, tableName);
|
||||
// 获取分页查询结果
|
||||
IPage<Map<String, Object>> infoPage = commonMapper.getInfoPage(page, tableName, selectField, selectCondition);
|
||||
// 对一些字段做翻译(如文件ids、树型选择ids)
|
||||
return infoPage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author: liao
|
||||
* @Date: 2023/8/23 17:10
|
||||
* @Description: 封装查询返回字段
|
||||
**/
|
||||
private String getSelectField(Map<String, Object> parameterMap, String tableName) {
|
||||
// 获取全部字段
|
||||
List<LawsTag> fieldList = commonMapper.getFieldList(tableName);
|
||||
// 筛选出查询列表显示的字段
|
||||
fieldList = fieldList.stream().filter(lawsTag -> YesOrNoEnum.YES.getValue()
|
||||
.equals(lawsTag.getIsShowList().toString())).collect(Collectors.toList());
|
||||
// 筛选获取日期类型字段
|
||||
List<String> dateFieldList = fieldList.stream().filter(lawsTag -> FieldTypeEnum.DATE_SINGLE
|
||||
.equals(lawsTag.getFieldShowType())).collect(Collectors.toList())
|
||||
.stream().map(LawsTag::getDbFieldName).collect(Collectors.toList());
|
||||
// 获取全部的字段列表
|
||||
List<String> tempFieldList = fieldList.stream().map(LawsTag::getDbFieldName).collect(Collectors.toList());
|
||||
// 创建一个新的用于返回的字段列表
|
||||
List<String> selectFieldList = new ArrayList();
|
||||
// 查询主键
|
||||
selectFieldList.add("id");
|
||||
tempFieldList.forEach(tempField -> {
|
||||
String endField;
|
||||
// 对日期格式和普通格式做处理
|
||||
if (dateFieldList.contains(tempField)) {
|
||||
// 如果是日期格式
|
||||
String newField = "date_format(" + tempField + ", '%Y-%m-%d')";
|
||||
endField = "case when " + newField + " is null then \"\" else " + newField + " end " + tempField;
|
||||
selectFieldList.add(endField);
|
||||
} else {
|
||||
// 如果是普通格式
|
||||
endField = "case when " + tempField + " is null then \"\" else " + tempField + " end " + tempField;
|
||||
selectFieldList.add(endField);
|
||||
}
|
||||
});
|
||||
return StringUtils.join(selectFieldList, ",");
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author: liao
|
||||
* @Date: 2023/8/23 17:16
|
||||
* @Description: 封装查询条件
|
||||
**/
|
||||
private String getSelectCondition(Map<String, Object> parameterMap, String tableName) {
|
||||
// 获取全部字段
|
||||
List<LawsTag> fieldList = commonMapper.getFieldList(tableName);
|
||||
// 筛选出用于查询的字段
|
||||
fieldList = fieldList.stream().filter(lawsTag -> YesOrNoEnum.YES.getValue()
|
||||
.equals(lawsTag.getIsQuery().toString())).collect(Collectors.toList());
|
||||
//查询条件
|
||||
StringBuilder selectCondition = new StringBuilder("where 1 = 1");
|
||||
// 删除pageNo和pageSize,不参与条件查询
|
||||
parameterMap.remove("pageNo");
|
||||
parameterMap.remove("pageSize");
|
||||
// 查询条件处理
|
||||
for (Map.Entry<String, Object> entryMap : parameterMap.entrySet()) {
|
||||
String key = entryMap.getKey();
|
||||
String value = "";
|
||||
if (!Objects.isNull(entryMap.getValue())) {
|
||||
value = entryMap.getValue().toString();
|
||||
}
|
||||
// 如果value不为null和"",则拼接查询条件
|
||||
if (StringUtils.isNotBlank(value)) {
|
||||
jointSelectCondition(fieldList, selectCondition, key, value);
|
||||
}
|
||||
}
|
||||
//处理列表表头排序
|
||||
if (StringUtils.isNotBlank((String) parameterMap.get("orderByField"))) {
|
||||
selectCondition.append(" order by " + parameterMap.get("orderByField"));
|
||||
orderBySort(parameterMap, selectCondition);
|
||||
} else {
|
||||
selectCondition.append(" order by create_time desc");
|
||||
}
|
||||
return selectCondition.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author: liao
|
||||
* @Date: 2023/8/22 11:41
|
||||
* @Description: 给拼装的查询条件排序
|
||||
**/
|
||||
private void orderBySort(Map<String, Object> parameter, StringBuilder conditionSb) {
|
||||
if ("1".equals(parameter.get("orderBy"))) {
|
||||
conditionSb.append(" asc");//正序
|
||||
} else if ("2".equals(parameter.get("orderBy"))) {
|
||||
conditionSb.append(" desc");//倒序
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author: liao
|
||||
* @Date: 2023/8/23 17:57
|
||||
* @Description: 组装单个查询条件
|
||||
**/
|
||||
private void jointSelectCondition(List<LawsTag> fieldList, StringBuilder selectCondition, String key, String value) {
|
||||
for (LawsTag lawsTag : fieldList) {
|
||||
// 获取字段名
|
||||
String dbFieldName = lawsTag.getDbFieldName();
|
||||
if (Objects.equals(key, dbFieldName)) {
|
||||
// 获取字段类型
|
||||
String fieldShowType = lawsTag.getFieldShowType();
|
||||
if (FieldTypeEnum.TEXT_STRING.getValue().equals(fieldShowType)
|
||||
|| FieldTypeEnum.TEXT_NUMBER.getValue().equals(fieldShowType)
|
||||
|| FieldTypeEnum.STANDARD.getValue().equals(fieldShowType)) {
|
||||
if (value.contains("%")) {
|
||||
// 字段内容可能包含%,是转义字符,做一下处理
|
||||
value = value.replace("%", "/%");
|
||||
}
|
||||
selectCondition.append(" and " + key + " like concat(concat('%','" + value + "'),'%')");
|
||||
} else if (FieldTypeEnum.PULL_SINGLE.getValue().equals(fieldShowType)
|
||||
|| FieldTypeEnum.PULL_MORE.getValue().equals(fieldShowType)
|
||||
|| FieldTypeEnum.TREE.getValue().equals(fieldShowType)) {
|
||||
StringBuilder valueSb = new StringBuilder();
|
||||
StringBuilder condition = new StringBuilder();
|
||||
for (String valueTemp : value.split(",")) {
|
||||
valueSb.append("'" + valueTemp + "',");
|
||||
condition.append(" or " + key + " like binary concat(concat('%','" + valueTemp + "'),'%')");
|
||||
}
|
||||
condition.append(")");
|
||||
String substring = valueSb.substring(0, valueSb.length() - 1);
|
||||
//下拉单选或下拉多选
|
||||
selectCondition.append(" and (" + key + " in(" + substring + ")" + condition);
|
||||
|
||||
} else if (FieldTypeEnum.DATE_SINGLE.getValue().equals(fieldShowType)) {
|
||||
//日期(区分单日期还时间范围)
|
||||
if (value.contains(",")) {
|
||||
selectCondition.append(" and " + "date_format(" + key + ",'%Y-%m-%d') >= '" + value.split(",")[0] + "'"
|
||||
+ " and " + "date_format(" + key + ",'%Y-%m-%d') <= '" + value.split(",")[1] + "'");
|
||||
} else {
|
||||
selectCondition.append(" and " + "date_format(" + key + ",'%Y-%m-%d') = '" + value + "'");
|
||||
}
|
||||
} else if (FieldTypeEnum.PERSON.getValue().equals(fieldShowType)) {
|
||||
if (value.contains("%")) {
|
||||
// 字段内容可能包含%,是转义字符,做一下处理
|
||||
value = value.replace("%", "/%");
|
||||
}
|
||||
selectCondition.append(" and " + key + " like concat(concat('%','" + value + "'),'%')");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+529
@@ -0,0 +1,529 @@
|
||||
package com.jero.modules.laws.common.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.jero.common.constant.enums.LanguageEnum;
|
||||
import com.jero.common.constant.enums.YesOrNoEnum;
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
import com.jero.common.system.vo.LoginUser;
|
||||
import com.jero.common.util.MessageUtils;
|
||||
import com.jero.modules.document.enums.FieldTypeEnum;
|
||||
import com.jero.modules.laws.common.constant.ResultCommon;
|
||||
import com.jero.modules.laws.common.mapper.LawsCommonMapper;
|
||||
import com.jero.modules.laws.common.service.ILawsCommonService;
|
||||
import com.jero.modules.ocr.enums.FileTypeEnum;
|
||||
import com.jero.modules.system.entity.SysCategoryTreeVO;
|
||||
import com.jero.modules.system.util.MyStringUtils;
|
||||
import com.jero.modules.tag.entity.LawsArea;
|
||||
import com.jero.modules.tag.entity.LawsTag;
|
||||
import com.jero.modules.tag.enums.FileTableIdEnum;
|
||||
import com.jero.modules.tag.service.ILawsAreaService;
|
||||
import com.spire.ms.System.Collections.ArrayList;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @Author: liao
|
||||
* @Date: 2023/8/23 16:54
|
||||
* @Description: 通用
|
||||
*/
|
||||
@Component
|
||||
public class LawsCommonServiceImpl implements ILawsCommonService {
|
||||
|
||||
@Autowired
|
||||
private LawsCommonMapper lawsCommonMapper;
|
||||
@Autowired
|
||||
private ILawsAreaService lawsAreaService;
|
||||
|
||||
/**
|
||||
* @Author: liao
|
||||
* @Date: 2023/8/23 16:57
|
||||
* @Description: 通用分页查询
|
||||
**/
|
||||
@Override
|
||||
public IPage<Map<String, Object>> getCommonPage(Map<String, Object> parameterMap) {
|
||||
// 获取操作模块
|
||||
String module = parameterMap.get("module").toString();
|
||||
// 获取要操作的表名
|
||||
String tableName = FileTableIdEnum.getTableName(module);
|
||||
// 获取分页参数
|
||||
Integer pageNo = Integer.valueOf(parameterMap.get("pageNo").toString());
|
||||
Integer pageSize = Integer.valueOf(parameterMap.get("pageSize").toString());
|
||||
IPage<Map<String,Object>> page = new Page<>(pageNo, pageSize);
|
||||
// 封装查询返回字段
|
||||
String selectField = getSelectField(tableName, null);
|
||||
// 封装查询条件
|
||||
String selectCondition = getSelectCondition(parameterMap, tableName);
|
||||
// 获取分页查询结果
|
||||
IPage<Map<String, Object>> infoPage = lawsCommonMapper.getCommonPage(page, tableName, selectField, selectCondition);
|
||||
// 对一些字段做翻译(如文件ids、树型选择ids)
|
||||
// 待处理
|
||||
return infoPage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author: liao
|
||||
* @Date: 2023/8/24 9:09
|
||||
* @Description: 获取通用表头
|
||||
**/
|
||||
@Override
|
||||
public List<LawsTag> getCommonHeader(String module) {
|
||||
// 获取要操作的表名
|
||||
String tableName = FileTableIdEnum.getTableName(module);
|
||||
// 获取全部字段
|
||||
List<LawsTag> fieldList = lawsCommonMapper.getFieldList(tableName);
|
||||
// 筛选出用于列表显示的字段(isShowList **列表是否显示0否 1是*)
|
||||
fieldList = fieldList.stream().filter(lawsTag -> YesOrNoEnum.YES.getInteger()
|
||||
.equals(lawsTag.getIsShowList())).collect(Collectors.toList());
|
||||
return fieldList;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author: liao
|
||||
* @Date: 2023/8/24 9:34
|
||||
* @Description: 通用新增数据
|
||||
**/
|
||||
@Override
|
||||
public String commonAdd(Map<String, Object> parameterMap) {
|
||||
// 获取操作模块
|
||||
String module = parameterMap.get("module").toString();
|
||||
// 获取要操作的表名
|
||||
String tableName = FileTableIdEnum.getTableName(module);
|
||||
// 获取全部字段
|
||||
List<LawsTag> fieldList = lawsCommonMapper.getFieldList(tableName);
|
||||
// 筛选出表单显示的
|
||||
fieldList = fieldList.stream().filter(lawsTag -> YesOrNoEnum.YES.getInteger()
|
||||
.equals(lawsTag.getIsShowForm())).collect(Collectors.toList());
|
||||
// 新增字段
|
||||
StringBuilder fieldsBuilder = new StringBuilder();
|
||||
// 新增数据值
|
||||
StringBuilder valuesBuilder = new StringBuilder();
|
||||
// 对默认的字段赋值
|
||||
getCommonInsertValue(fieldsBuilder, valuesBuilder);
|
||||
// 拼接要添加的数据
|
||||
for (Map.Entry<String, Object> entryMap : parameterMap.entrySet()) {
|
||||
String key = entryMap.getKey();
|
||||
String value = "";
|
||||
if (!Objects.isNull(entryMap.getValue())) {
|
||||
value = entryMap.getValue().toString();
|
||||
}
|
||||
// 如果value不为null和"",则拼接查询条件
|
||||
if (StringUtils.isNotBlank(value)) {
|
||||
jointInsertFieldAndValue(fieldList, fieldsBuilder, valuesBuilder, key, value);
|
||||
}
|
||||
}
|
||||
// 操作数据库进行新增数据
|
||||
int rowsInserted = lawsCommonMapper.commonAdd(tableName, fieldsBuilder.toString(), valuesBuilder.toString());
|
||||
if (rowsInserted > 0) {
|
||||
return MessageUtils.getMessage(ResultCommon.OK);
|
||||
}
|
||||
return MessageUtils.getMessage(ResultCommon.ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author: liao
|
||||
* @Date: 2023/8/24 14:12
|
||||
* @Description: 编辑数据
|
||||
**/
|
||||
@Override
|
||||
public String commonEdit(Map<String, Object> parameterMap) {
|
||||
// 获取操作模块
|
||||
String module = parameterMap.get("module").toString();
|
||||
parameterMap.remove("module");
|
||||
// 获取id
|
||||
String id = parameterMap.get("id").toString();
|
||||
parameterMap.remove("id");
|
||||
// 获取要操作的表名
|
||||
String tableName = FileTableIdEnum.getTableName(module);
|
||||
// 获取全部字段
|
||||
List<LawsTag> fieldList = lawsCommonMapper.getFieldList(tableName);
|
||||
// 筛选出表单显示的
|
||||
fieldList = fieldList.stream().filter(lawsTag -> YesOrNoEnum.YES.getInteger()
|
||||
.equals(lawsTag.getIsShowForm())).collect(Collectors.toList());
|
||||
// 更新语句
|
||||
StringBuilder updateBuilder = new StringBuilder();
|
||||
// 拼接默认的更新语句
|
||||
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
updateBuilder.append("update_time = " + "str_to_date('" + sdf.format(new Date()) + "','%Y-%m-%d %H:%i:%s')," +
|
||||
" update_by = " + "'" + sysUser.getUsername() + "'");
|
||||
// 封装参数的更新语句
|
||||
for (Map.Entry<String, Object> entryMap : parameterMap.entrySet()) {
|
||||
String key = entryMap.getKey();
|
||||
String value = "";
|
||||
if (!Objects.isNull(entryMap.getValue())) {
|
||||
value = entryMap.getValue().toString();
|
||||
}
|
||||
// 如果value不为null和"",则拼接sql语句
|
||||
if (StringUtils.isNotBlank(value)) {
|
||||
jointUpdateFieldAndValue(fieldList, updateBuilder, key, value);
|
||||
}
|
||||
}
|
||||
// 操作数据库进行更新数据
|
||||
int rowsUpdated = lawsCommonMapper.commonEdit(tableName, updateBuilder.toString(), id);
|
||||
if (rowsUpdated > 0) {
|
||||
return MessageUtils.getMessage(ResultCommon.OK);
|
||||
}
|
||||
return MessageUtils.getMessage(ResultCommon.ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author: liao
|
||||
* @Date: 2023/8/24 10:41
|
||||
* @Description: 获取查询条件
|
||||
**/
|
||||
@Override
|
||||
public List<Map<String, Object>> getQueryCondition(String module) {
|
||||
// 获取操作语言
|
||||
LanguageEnum language = MessageUtils.getLanguage();
|
||||
// 获取要操作的表名
|
||||
String tableName = FileTableIdEnum.getTableName(module);
|
||||
// 获取全部字段
|
||||
List<LawsTag> fieldList = lawsCommonMapper.getFieldList(tableName);
|
||||
fieldList = fieldList.stream().filter(lawsTag -> YesOrNoEnum.YES.getInteger()
|
||||
.equals(lawsTag.getIsQuery())).collect(Collectors.toList());
|
||||
List<Map<String, Object>> resultList = new java.util.ArrayList<>();
|
||||
for (LawsTag lawsTag : fieldList) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("field_show_type", lawsTag.getFieldShowType());// 字段类型
|
||||
map.put("dict_field", lawsTag.getDictField());
|
||||
map.put("db_field_name", lawsTag.getDbFieldName()); // 字段名
|
||||
if (LanguageEnum.CN.equals(language)) {
|
||||
map.put("db_field_txt", lawsTag.getDbFieldTxt());//字段中文名
|
||||
} else {
|
||||
map.put("db_field_txt", lawsTag.getDbFieldEnName());//字段英文名
|
||||
}
|
||||
// 树型结构的集合
|
||||
if (FieldTypeEnum.TREE.equals(lawsTag.getFieldShowType())) {
|
||||
// 对树型结构做处理
|
||||
map.put("tree", new java.util.ArrayList<>());
|
||||
} else {
|
||||
map.put("tree", new java.util.ArrayList<>());
|
||||
}
|
||||
resultList.add(map);
|
||||
}
|
||||
return resultList;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author: liao
|
||||
* @Date: 2023/8/24 10:53
|
||||
* @Description: 获取表单模型
|
||||
**/
|
||||
@Override
|
||||
public List<Map<String, Object>> getFormModel(String module) {
|
||||
// 获取操作语言
|
||||
LanguageEnum language = MessageUtils.getLanguage();
|
||||
// 获取要操作的表名
|
||||
String tableName = FileTableIdEnum.getTableName(module);
|
||||
// 获取全部字段
|
||||
List<LawsTag> fieldList = lawsCommonMapper.getFieldList(tableName);
|
||||
// 筛选表单显示的字段
|
||||
fieldList = fieldList.stream().filter(lawsTag -> YesOrNoEnum.YES.getValue()
|
||||
.equals(lawsTag.getIsShowForm().toString())).collect(Collectors.toList());
|
||||
// 获取区域管理
|
||||
LawsArea lawsArea = new LawsArea();
|
||||
lawsArea.setIsModel(module);
|
||||
List<LawsArea> areaList = lawsAreaService.queryList(lawsArea);
|
||||
// 用于返回的集合
|
||||
List<Map<String, Object>> resultList = new java.util.ArrayList<>();
|
||||
// 区域集合
|
||||
Map<String, Object> areaMap = new HashMap<>();
|
||||
// 遍历每个区域做处理
|
||||
for (LawsArea area : areaList) {
|
||||
// 获取该区域的所有字段
|
||||
List<LawsTag> areaFieldList = fieldList.stream().filter(lawsTag -> area.getId()
|
||||
.equals(lawsTag.getShowArea())).collect(Collectors.toList());
|
||||
// 获取展示区域名称
|
||||
String areaName = area.getShowArea();
|
||||
if (LanguageEnum.EN.equals(language)) {
|
||||
areaName = area.getEnName();
|
||||
}
|
||||
// 字段的列表
|
||||
List<Map<String, Object>> fieldMapList = new java.util.ArrayList<>();
|
||||
// 对字段进行遍历处理
|
||||
for (LawsTag lawsTag : areaFieldList) {
|
||||
// 每个区域下面字段的集合
|
||||
Map<String, Object> fieldMap = new HashMap<>();
|
||||
// 对返回的字段做处理
|
||||
fieldMap.put("dbFieldName", lawsTag.getDbFieldName()); // 字段名
|
||||
// 字段中英文显示
|
||||
if (LanguageEnum.CN.equals(language)) {
|
||||
fieldMap.put("db_field_txt", lawsTag.getDbFieldTxt());//字段中文名
|
||||
} else {
|
||||
fieldMap.put("db_field_txt", lawsTag.getDbFieldEnName());//字段英文名
|
||||
}
|
||||
fieldMap.put("field_show_type", lawsTag.getFieldShowType()); // 字段类型
|
||||
fieldMap.put("dict_field", lawsTag.getDictField()); // 字典编码
|
||||
fieldMap.put("show_area", lawsTag.getShowArea()); // 显示区域
|
||||
fieldMap.put("field_must_input", lawsTag.getFieldMustInput()); // 是否必填
|
||||
fieldMap.put("db_length", lawsTag.getDbLength()); // 字段长度
|
||||
fieldMap.put("isReadOnly", lawsTag.getIsReadOnly()); // 是否只读
|
||||
// 树型结构做处理
|
||||
if (FieldTypeEnum.TREE.equals(lawsTag.getFieldShowType())) {
|
||||
fieldMap.put("tree", new java.util.ArrayList<>());
|
||||
} else {
|
||||
fieldMap.put("tree", new java.util.ArrayList<>());
|
||||
}
|
||||
fieldMapList.add(fieldMap);
|
||||
}
|
||||
areaMap.put(areaName, fieldMapList);
|
||||
}
|
||||
resultList.add(areaMap);
|
||||
return resultList;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author: liao
|
||||
* @Date: 2023/8/24 11:49
|
||||
* @Description: 根据id和模块标识获取信息
|
||||
**/
|
||||
@Override
|
||||
public Map<String, Object> getByIdAndModule(String id, String module) {
|
||||
// 获取要操作的表名
|
||||
String tableName = FileTableIdEnum.getTableName(module);
|
||||
// 封装查询显示的字段
|
||||
String selectField = getSelectField(tableName, id);
|
||||
// 封装查询条件
|
||||
Map<String, Object> resultMap = lawsCommonMapper.getByIdAndModule(tableName, selectField, id);
|
||||
// 对一些字段做翻译(如文件ids、树型选择ids)
|
||||
// ...
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author: liao
|
||||
* @Date: 2023/8/24 13:52
|
||||
* @Description: 根据ids和模块标识删除信息
|
||||
**/
|
||||
@Override
|
||||
public String deleteByIdsAndModule(String ids, String module) {
|
||||
// 获取要操作的表名
|
||||
String tableName = FileTableIdEnum.getTableName(module);
|
||||
// 获取要删除的id集合
|
||||
if (StringUtils.isBlank(ids)) {
|
||||
throw new JeroBootException(MessageUtils.getMessage(ResultCommon.ERROR));
|
||||
}
|
||||
List<String> idList = Arrays.asList(ids.split(","));
|
||||
// 操作数据库进行删除操作
|
||||
int rowsDeleted = lawsCommonMapper.deleteByIdsAndModule(tableName, idList);
|
||||
if (rowsDeleted > 0) {
|
||||
return MessageUtils.getMessage(ResultCommon.OK);
|
||||
}
|
||||
return MessageUtils.getMessage(ResultCommon.ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author: liao
|
||||
* @Date: 2023/8/24 9:53
|
||||
* @Description: 拼接添加字段和数据值
|
||||
**/
|
||||
private void jointInsertFieldAndValue(List<LawsTag> fieldList, StringBuilder fieldsBuilder,
|
||||
StringBuilder valuesBuilder, String key, String value) {
|
||||
for (LawsTag lawsTag : fieldList) {
|
||||
if (key.equals(lawsTag.getDbFieldName())) {
|
||||
// 拼接新增字段
|
||||
fieldsBuilder.append("," + key);
|
||||
// 对数据值做格式处理
|
||||
valuesBuilder.append("," + setValue(lawsTag.getFieldShowType(), value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author: liao
|
||||
* @Date: 2023/8/24 9:53
|
||||
* @Description: 拼接更新语句字段和数据值
|
||||
**/
|
||||
private void jointUpdateFieldAndValue(List<LawsTag> fieldList, StringBuilder updateBuilder,
|
||||
String key, String value) {
|
||||
for (LawsTag lawsTag : fieldList) {
|
||||
if (key.equals(lawsTag.getDbFieldName())) {
|
||||
// 做格式处理
|
||||
updateBuilder.append("," + key + " = " + setValue(lawsTag.getFieldShowType(), value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author: liao
|
||||
* @Date: 2023/8/24 14:43
|
||||
* @Description: 对数据值做格式处理
|
||||
**/
|
||||
private String setValue(String fieldShowType, String value) {
|
||||
if (FieldTypeEnum.DATE_SINGLE.equals(fieldShowType)) {
|
||||
// 如果是单日期格式,做格式处理
|
||||
value = "str_to_date('" + value + "','%Y-%m-%d %H:%i:%s')";
|
||||
} else {
|
||||
// 字符串做处理
|
||||
value = "'" + value + "'";
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author: liao
|
||||
* @Date: 2023/8/24 9:37
|
||||
* @Description: 获取新增默认值
|
||||
**/
|
||||
private void getCommonInsertValue(StringBuilder fieldsBuilder, StringBuilder valuesBuilder) {
|
||||
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||
String id = UUID.randomUUID().toString().replace("-", "");
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
String commonInsertValues = "'" + id + "','" + sysUser.getUsername() + "',"
|
||||
+ "str_to_date('" + sdf.format(new Date()) + "','%Y-%m-%d %H:%i:%s')" + ",'" + sysUser.getUsername() + "',"
|
||||
+ "str_to_date('" + sdf.format(new Date()) + "','%Y-%m-%d %H:%i:%s')" + ",'" + sysUser.getOrgCode() + "'";
|
||||
fieldsBuilder.append("id,create_by,create_time,update_by,update_time,sys_code");
|
||||
valuesBuilder.append(commonInsertValues);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author: liao
|
||||
* @Date: 2023/8/23 17:10
|
||||
* @Description: 封装查询返回字段
|
||||
**/
|
||||
private String getSelectField(String tableName, String id) {
|
||||
// 获取全部字段
|
||||
List<LawsTag> fieldList = lawsCommonMapper.getFieldList(tableName);
|
||||
if (StringUtils.isBlank(id)) {
|
||||
// 筛选出查询列表显示的字段(不传id查列表)
|
||||
fieldList = fieldList.stream().filter(lawsTag -> YesOrNoEnum.YES.getValue()
|
||||
.equals(lawsTag.getIsShowList().toString())).collect(Collectors.toList());
|
||||
} else {
|
||||
// 筛选表单显示的字段(传id查表单)
|
||||
fieldList = fieldList.stream().filter(lawsTag -> YesOrNoEnum.YES.getValue()
|
||||
.equals(lawsTag.getIsShowForm().toString())).collect(Collectors.toList());
|
||||
}
|
||||
// 筛选获取日期类型字段
|
||||
List<String> dateFieldList = fieldList.stream().filter(lawsTag -> FieldTypeEnum.DATE_SINGLE
|
||||
.equals(lawsTag.getFieldShowType())).collect(Collectors.toList())
|
||||
.stream().map(LawsTag::getDbFieldName).collect(Collectors.toList());
|
||||
// 获取全部的字段列表
|
||||
List<String> tempFieldList = fieldList.stream().map(LawsTag::getDbFieldName).collect(Collectors.toList());
|
||||
// 创建一个新的用于返回的字段列表
|
||||
List<String> selectFieldList = new ArrayList();
|
||||
// 查询主键
|
||||
selectFieldList.add("id");
|
||||
tempFieldList.forEach(tempField -> {
|
||||
String endField;
|
||||
// 对日期格式和普通格式做处理
|
||||
if (dateFieldList.contains(tempField)) {
|
||||
// 如果是日期格式
|
||||
String newField = "date_format(" + tempField + ", '%Y-%m-%d')";
|
||||
endField = "case when " + newField + " is null then \"\" else " + newField + " end " + tempField;
|
||||
selectFieldList.add(endField);
|
||||
} else {
|
||||
// 如果是普通格式
|
||||
endField = "case when " + tempField + " is null then \"\" else " + tempField + " end " + tempField;
|
||||
selectFieldList.add(endField);
|
||||
}
|
||||
});
|
||||
return StringUtils.join(selectFieldList, ",");
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author: liao
|
||||
* @Date: 2023/8/23 17:16
|
||||
* @Description: 封装查询条件
|
||||
**/
|
||||
private String getSelectCondition(Map<String, Object> parameterMap, String tableName) {
|
||||
// 获取全部字段
|
||||
List<LawsTag> fieldList = lawsCommonMapper.getFieldList(tableName);
|
||||
// 筛选出用于查询的字段
|
||||
fieldList = fieldList.stream().filter(lawsTag -> YesOrNoEnum.YES.getValue()
|
||||
.equals(lawsTag.getIsQuery().toString())).collect(Collectors.toList());
|
||||
//查询条件
|
||||
StringBuilder selectCondition = new StringBuilder("where 1 = 1");
|
||||
// 删除pageNo和pageSize,不参与条件查询
|
||||
parameterMap.remove("pageNo");
|
||||
parameterMap.remove("pageSize");
|
||||
// 查询条件处理
|
||||
for (Map.Entry<String, Object> entryMap : parameterMap.entrySet()) {
|
||||
String key = entryMap.getKey();
|
||||
String value = "";
|
||||
if (!Objects.isNull(entryMap.getValue())) {
|
||||
value = entryMap.getValue().toString();
|
||||
}
|
||||
// 如果value不为null和"",则拼接查询条件
|
||||
if (StringUtils.isNotBlank(value)) {
|
||||
jointSelectCondition(fieldList, selectCondition, key, value);
|
||||
}
|
||||
}
|
||||
//处理列表表头排序
|
||||
if (StringUtils.isNotBlank((String) parameterMap.get("orderByField"))) {
|
||||
selectCondition.append(" order by " + parameterMap.get("orderByField"));
|
||||
orderBySort(parameterMap, selectCondition);
|
||||
} else {
|
||||
selectCondition.append(" order by create_time desc");
|
||||
}
|
||||
return selectCondition.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author: liao
|
||||
* @Date: 2023/8/22 11:41
|
||||
* @Description: 给拼装的查询条件排序
|
||||
**/
|
||||
private void orderBySort(Map<String, Object> parameter, StringBuilder conditionSb) {
|
||||
if ("1".equals(parameter.get("orderBy"))) {
|
||||
conditionSb.append(" asc");//正序
|
||||
} else if ("2".equals(parameter.get("orderBy"))) {
|
||||
conditionSb.append(" desc");//倒序
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author: liao
|
||||
* @Date: 2023/8/23 17:57
|
||||
* @Description: 组装单个查询条件
|
||||
**/
|
||||
private void jointSelectCondition(List<LawsTag> fieldList, StringBuilder selectCondition, String key, String value) {
|
||||
for (LawsTag lawsTag : fieldList) {
|
||||
// 获取字段名
|
||||
String dbFieldName = lawsTag.getDbFieldName();
|
||||
if (Objects.equals(key, dbFieldName)) {
|
||||
// 获取字段类型
|
||||
String fieldShowType = lawsTag.getFieldShowType();
|
||||
if (FieldTypeEnum.TEXT_STRING.getValue().equals(fieldShowType)
|
||||
|| FieldTypeEnum.TEXT_NUMBER.getValue().equals(fieldShowType)) {
|
||||
if (value.contains("%")) {
|
||||
// 字段内容可能包含%,是转义字符,做一下处理
|
||||
value = value.replace("%", "/%");
|
||||
}
|
||||
selectCondition.append(" and " + key + " like concat(concat('%','" + value + "'),'%')");
|
||||
} else if (FieldTypeEnum.PULL_SINGLE.getValue().equals(fieldShowType)
|
||||
|| FieldTypeEnum.PULL_MORE.getValue().equals(fieldShowType)
|
||||
|| FieldTypeEnum.TREE.getValue().equals(fieldShowType)
|
||||
|| FieldTypeEnum.PERSON.getValue().equals(fieldShowType)
|
||||
|| FieldTypeEnum.STANDARD.getValue().equals(fieldShowType)) {
|
||||
StringBuilder valueSb = new StringBuilder();
|
||||
StringBuilder condition = new StringBuilder();
|
||||
for (String valueTemp : value.split(",")) {
|
||||
valueSb.append("'" + valueTemp + "',");
|
||||
condition.append(" or " + key + " like binary concat(concat('%','" + valueTemp + "'),'%')");
|
||||
}
|
||||
condition.append(")");
|
||||
String substring = valueSb.substring(0, valueSb.length() - 1);
|
||||
//下拉单选或下拉多选
|
||||
selectCondition.append(" and (" + key + " in(" + substring + ")" + condition);
|
||||
|
||||
} else if (FieldTypeEnum.DATE_SINGLE.getValue().equals(fieldShowType)) {
|
||||
//日期(区分单日期还时间范围)
|
||||
if (value.contains(",")) {
|
||||
selectCondition.append(" and " + "date_format(" + key + ",'%Y-%m-%d') >= '" + value.split(",")[0] + "'"
|
||||
+ " and " + "date_format(" + key + ",'%Y-%m-%d') <= '" + value.split(",")[1] + "'");
|
||||
} else {
|
||||
selectCondition.append(" and " + "date_format(" + key + ",'%Y-%m-%d') = '" + value + "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+7
-7
@@ -4,7 +4,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.jero.common.api.vo.Result;
|
||||
import com.jero.common.aspect.annotation.AutoLog;
|
||||
import com.jero.common.system.base.controller.JeroController;
|
||||
import com.jero.modules.laws.common.service.ICommonService;
|
||||
import com.jero.common.util.MessageUtils;
|
||||
import com.jero.modules.laws.regulation.entity.LawsBasicInfo;
|
||||
import com.jero.modules.laws.regulation.service.ILawsBasicInfoService;
|
||||
import io.swagger.annotations.Api;
|
||||
@@ -68,12 +68,12 @@ public class LawsBasicInfoController extends JeroController<LawsBasicInfo, ILaws
|
||||
return Result.OK(list);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private ICommonService commonService;
|
||||
|
||||
@PostMapping(value = "/getCommon")
|
||||
public Result<IPage<Map<String,Object>>> getCommon(@RequestBody Map<String,Object> parameter) {
|
||||
return Result.OK(commonService.getCommonPage(parameter));
|
||||
@AutoLog(value = "新增数据")
|
||||
@ApiOperation(value="新增数据", notes="新增数据")
|
||||
@PostMapping(value = "/addData")
|
||||
public Result<String> addData(@RequestBody Map<String,Object> parameterMap) {
|
||||
lawsBasicInfoService.addData(parameterMap);
|
||||
return Result.OK(MessageUtils.getMessage("message.ok"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+7
@@ -48,4 +48,11 @@ public interface ILawsBasicInfoService extends IService<LawsBasicInfo> {
|
||||
* @Description: 获取查询条件
|
||||
**/
|
||||
List<Map<String, Object>> getQueryCondition(String flag);
|
||||
|
||||
/**
|
||||
* @Author: liao
|
||||
* @Date: 2023/8/24 9:27
|
||||
* @Description: 新增数据
|
||||
**/
|
||||
void addData(Map<String, Object> parameterMap);
|
||||
}
|
||||
|
||||
+20
-3
@@ -4,12 +4,11 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.jero.common.constant.enums.LanguageEnum;
|
||||
import com.jero.common.constant.enums.ModuleEnum;
|
||||
import com.jero.common.constant.enums.YesOrNoEnum;
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
import com.jero.common.util.MessageUtils;
|
||||
import com.jero.generater.modules.online.cgform.entity.OnlCgformField;
|
||||
import com.jero.modules.document.enums.FieldTypeEnum;
|
||||
import com.jero.modules.laws.common.mapper.LawsCommonMapper;
|
||||
import com.jero.modules.laws.regulation.entity.LawsBasicInfo;
|
||||
import com.jero.modules.laws.regulation.mapper.LawsBasicInfoMapper;
|
||||
import com.jero.modules.laws.regulation.service.ILawsBasicInfoService;
|
||||
@@ -65,6 +64,8 @@ public class LawsBasicInfoServiceImpl extends ServiceImpl<LawsBasicInfoMapper, L
|
||||
private IOSSFileService ossFileService;
|
||||
@Autowired
|
||||
private ILawsAreaService lawsAreaService;
|
||||
@Autowired
|
||||
private LawsCommonMapper lawsCommonMapper;
|
||||
|
||||
/**
|
||||
* @Author: liao
|
||||
@@ -489,7 +490,7 @@ public class LawsBasicInfoServiceImpl extends ServiceImpl<LawsBasicInfoMapper, L
|
||||
//树形数据字典
|
||||
Map<String,Object> params = new HashedMap();
|
||||
params.put("cut",cut);
|
||||
//List<SysCategoryTreeVO> sysCategoryTree = sysCategoryService.getSysCategoryTree(null,params);
|
||||
List<SysCategoryTreeVO> sysCategoryTree = sysCategoryService.getSysCategoryTree(null,params);
|
||||
List<Map<String, Object>> list = new java.util.ArrayList<>();
|
||||
for (LawsTag lawsTag : fieldList) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
@@ -515,6 +516,22 @@ public class LawsBasicInfoServiceImpl extends ServiceImpl<LawsBasicInfoMapper, L
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author: liao
|
||||
* @Date: 2023/8/24 9:27
|
||||
* @Description: 新增数据
|
||||
**/
|
||||
@Override
|
||||
public void addData(Map<String, Object> parameterMap) {
|
||||
// 获取操作模块
|
||||
String module = parameterMap.get("module").toString();
|
||||
// 获取要操作的表名
|
||||
String tableName = FileTableIdEnum.getTableName(module);
|
||||
// 获取全部字段
|
||||
List<LawsTag> fieldList = lawsCommonMapper.getFieldList(tableName);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author: liao
|
||||
* @Date: 2023/8/21 17:33
|
||||
|
||||
@@ -4,4 +4,6 @@ tag.add.\u5B57\u6BB5\u540D\u79F0\u592A\u957F=The field name you set is {0}, with
|
||||
tag.delete.\u5305\u542B\u56FA\u5B9A\u5B57\u6BB5,\u4E0D\u53EF\u5220\u9664=It contains fixed fields and cannot be deleted.
|
||||
tag.edit.\u56FA\u5B9A\u5B57\u6BB5,\u4E0D\u53EF\u4FEE\u6539=Fixed field, which cannot be modified.
|
||||
tag.edit.\u56FA\u5B9A\u5B57\u6BB5,\u4E0D\u53EF\u5220\u9664=Fixed field, cannot be deleted.
|
||||
tag.edit.\u5C5E\u6027\u5DF2\u5B58\u5728,\u8BF7\u68C0\u67E5=Attribute already exists, please check!
|
||||
tag.edit.\u5C5E\u6027\u5DF2\u5B58\u5728,\u8BF7\u68C0\u67E5=Attribute already exists, please check!
|
||||
message.ok=Successful operation
|
||||
message.error=Operation failure
|
||||
@@ -4,4 +4,6 @@ tag.add.\u5B57\u6BB5\u540D\u79F0\u592A\u957F=\u60A8\u8BBE\u7F6E\u7684\u5B57\u6BB
|
||||
tag.delete.\u5305\u542B\u56FA\u5B9A\u5B57\u6BB5,\u4E0D\u53EF\u5220\u9664=\u5305\u542B\u56FA\u5B9A\u5B57\u6BB5,\u4E0D\u53EF\u5220\u9664
|
||||
tag.edit.\u56FA\u5B9A\u5B57\u6BB5,\u4E0D\u53EF\u4FEE\u6539=\u56FA\u5B9A\u5B57\u6BB5,\u4E0D\u53EF\u4FEE\u6539
|
||||
tag.edit.\u56FA\u5B9A\u5B57\u6BB5,\u4E0D\u53EF\u5220\u9664=\u56FA\u5B9A\u5B57\u6BB5,\u4E0D\u53EF\u5220\u9664
|
||||
tag.edit.\u5C5E\u6027\u5DF2\u5B58\u5728,\u8BF7\u68C0\u67E5=\u5C5E\u6027\u5DF2\u5B58\u5728,\u8BF7\u68C0\u67E5
|
||||
tag.edit.\u5C5E\u6027\u5DF2\u5B58\u5728,\u8BF7\u68C0\u67E5=\u5C5E\u6027\u5DF2\u5B58\u5728,\u8BF7\u68C0\u67E5
|
||||
message.ok=\u64cd\u4f5c\u6210\u529f
|
||||
message.error=\u64cd\u4f5c\u5931\u8d25
|
||||
Reference in New Issue
Block a user