|
@@ -1,30 +1,32 @@
|
|
|
package com.zkqy.business.service.impl;
|
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
-import com.fasterxml.jackson.databind.json.JsonMapper;
|
|
|
import com.zkqy.business.entity.MobilePageData;
|
|
|
+import com.zkqy.business.entity.MobilePageTableList;
|
|
|
import com.zkqy.business.mapper.MobilePageDataMapper;
|
|
|
+import com.zkqy.business.mapper.MobilePageTableListMapper;
|
|
|
import com.zkqy.business.service.IMobilePageDataService;
|
|
|
import com.zkqy.common.utils.SecurityUtils;
|
|
|
+import com.zkqy.common.utils.StringUtils;
|
|
|
+import com.zkqy.execution.produce.dispersed.entity.CommonEntity;
|
|
|
import com.zkqy.execution.produce.dispersed.mapper.CommonMapper;
|
|
|
-import com.zkqy.execution.produce.dispersed.service.impl.CommonServiceImpl;
|
|
|
-import net.bytebuddy.jar.asm.TypeReference;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.atomic.AtomicReference;
|
|
|
|
|
|
/**
|
|
|
* 移动端数据Service业务层处理
|
|
|
- *
|
|
|
+ *
|
|
|
* @author zkqy
|
|
|
* @date 2024-04-18
|
|
|
*/
|
|
|
@Service
|
|
|
-public class MobilePageDataServiceImpl implements IMobilePageDataService
|
|
|
-{
|
|
|
+public class MobilePageDataServiceImpl implements IMobilePageDataService {
|
|
|
|
|
|
@Autowired
|
|
|
private MobilePageDataMapper mobilePageDataMapper;
|
|
@@ -32,9 +34,12 @@ public class MobilePageDataServiceImpl implements IMobilePageDataService
|
|
|
@Autowired
|
|
|
private CommonMapper commonMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private MobilePageTableListMapper mobilePageTableListMapper;
|
|
|
+
|
|
|
/**
|
|
|
* 查询移动端数据
|
|
|
- *
|
|
|
+ *
|
|
|
* @param id 移动端数据主键
|
|
|
* @return 移动端数据
|
|
|
*/
|
|
@@ -46,48 +51,48 @@ public class MobilePageDataServiceImpl implements IMobilePageDataService
|
|
|
MobilePageData mobilePageData = mobilePageDataMapper.selectMobilePageDataById(id);
|
|
|
//下拉框限定的数据查询
|
|
|
String selectQualifiedField = mobilePageData.getSelectQualifiedField();
|
|
|
- List<Map<String,String>> selectQualifiedFieldListMap=objectMapper.readValue(selectQualifiedField, List.class);
|
|
|
+ List<Map<String, String>> selectQualifiedFieldListMap = objectMapper.readValue(selectQualifiedField, List.class);
|
|
|
//存下拉框回显数据的值
|
|
|
String selectMapValueList = mobilePageData.getSelectMapValueList();
|
|
|
//new 一个hashMap对象放数据 "{"下拉框数据key":[{"lable","111111,value":"2222"}]}"
|
|
|
- HashMap<String,Object> stringObjectHashMap=new HashMap<>();
|
|
|
+ HashMap<String, Object> stringObjectHashMap = new HashMap<>();
|
|
|
//循环映射条件
|
|
|
- selectQualifiedFieldListMap.forEach(item->{
|
|
|
+ selectQualifiedFieldListMap.forEach(item -> {
|
|
|
String tableName = item.get("tableName");
|
|
|
String label = item.get("label");
|
|
|
- String value=item.get("label");
|
|
|
+ String value = item.get("label");
|
|
|
try {
|
|
|
- List<Map<String,Object>> queryCondition= objectMapper.readValue(item.get("queryCondition"), List.class);
|
|
|
+ List<Map<String, Object>> queryCondition = objectMapper.readValue(item.get("queryCondition"), List.class);
|
|
|
HashMap<String, Object> objectObjectHashMap = new HashMap<>();
|
|
|
//有默认的用户信息值,就替换掉
|
|
|
- queryCondition.forEach(k->{
|
|
|
- k.forEach((key,vl)->{
|
|
|
- if(key.equals("#{userId}")){
|
|
|
- objectObjectHashMap.put(key,SecurityUtils.getUserId().toString());
|
|
|
- }else {
|
|
|
- objectObjectHashMap.put(key,vl);
|
|
|
+ queryCondition.forEach(k -> {
|
|
|
+ k.forEach((key, vl) -> {
|
|
|
+ if (key.equals("#{userId}")) {
|
|
|
+ objectObjectHashMap.put(key, SecurityUtils.getUserId().toString());
|
|
|
+ } else {
|
|
|
+ objectObjectHashMap.put(key, vl);
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
//查询下拉框数据值
|
|
|
List<Map<String, Object>> maps = commonMapper.selectDropDownList(tableName, label, value, objectObjectHashMap);
|
|
|
- //建立数据key和下拉框数据的对应关系
|
|
|
- stringObjectHashMap.put(item.get("selectDataKey").toString(),maps);
|
|
|
+ //建立数据key和下拉框数据的对应关系
|
|
|
+ stringObjectHashMap.put(item.get("selectDataKey").toString(), maps);
|
|
|
} catch (JsonProcessingException e) {
|
|
|
throw new RuntimeException(e);
|
|
|
}
|
|
|
});
|
|
|
//证明以前有默认数据
|
|
|
- if(selectMapValueList!=null&&selectMapValueList!=""){
|
|
|
+ if (selectMapValueList != null && selectMapValueList != "") {
|
|
|
//默认数据转map
|
|
|
- Map<String,Object> defaultJson= objectMapper.readValue(selectMapValueList, Map.class);
|
|
|
+ Map<String, Object> defaultJson = objectMapper.readValue(selectMapValueList, Map.class);
|
|
|
//查询出来的默认数据所用字段赋值为空
|
|
|
mobilePageData.setSelectMapValueList("");
|
|
|
//把默认数据往数据map里面堆
|
|
|
stringObjectHashMap.putAll(defaultJson);
|
|
|
//从新设置下拉框数据信息字段(这字段包含所有的下拉框数据)
|
|
|
mobilePageData.setSelectMapValueList(objectMapper.writeValueAsString(stringObjectHashMap));//mao对象转json放入到字段中
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
//直接放数据不存在默认数据
|
|
|
mobilePageData.setSelectMapValueList(objectMapper.writeValueAsString(stringObjectHashMap));//mao对象转json放入到字段中
|
|
|
}
|
|
@@ -95,39 +100,39 @@ public class MobilePageDataServiceImpl implements IMobilePageDataService
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public MobilePageData selectMobilePageDataIndexTrue() throws JsonProcessingException {
|
|
|
+ public MobilePageData selectMobilePageDataIndexTrue(CommonEntity commonEntity) throws JsonProcessingException {
|
|
|
//JSON转换器
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
//查询出来的总体数据
|
|
|
MobilePageData mobilePageData = mobilePageDataMapper.selectMobilePageDataIndexTrue();
|
|
|
//new 一个hashMap对象放数据 "{"下拉框数据key":[{"lable","111111,value":"2222"}]}"
|
|
|
- HashMap<String,Object> stringObjectHashMap=new HashMap<>();
|
|
|
+ HashMap<String, Object> stringObjectHashMap = new HashMap<>();
|
|
|
//下拉框限定的数据查询
|
|
|
- if(mobilePageData.getSelectQualifiedField()!=null&&mobilePageData.getSelectQualifiedField()!=""){
|
|
|
+ if (mobilePageData.getSelectQualifiedField() != null && mobilePageData.getSelectQualifiedField() != "") {
|
|
|
String selectQualifiedField = mobilePageData.getSelectQualifiedField();
|
|
|
- List<Map<String,String>> selectQualifiedFieldListMap=objectMapper.readValue(selectQualifiedField, List.class);
|
|
|
+ List<Map<String, String>> selectQualifiedFieldListMap = objectMapper.readValue(selectQualifiedField, List.class);
|
|
|
//循环映射条件
|
|
|
- selectQualifiedFieldListMap.forEach(item->{
|
|
|
+ selectQualifiedFieldListMap.forEach(item -> {
|
|
|
String tableName = item.get("tableName");
|
|
|
String label = item.get("label");
|
|
|
- String value=item.get("value");
|
|
|
+ String value = item.get("value");
|
|
|
try {
|
|
|
- List<Map<String,Object>> queryCondition= objectMapper.readValue(item.get("queryCondition"), List.class);
|
|
|
+ List<Map<String, Object>> queryCondition = objectMapper.readValue(item.get("queryCondition"), List.class);
|
|
|
HashMap<String, Object> objectObjectHashMap = new HashMap<>();
|
|
|
//有默认的用户信息值,就替换掉
|
|
|
- queryCondition.forEach(k->{
|
|
|
- k.forEach((key,vl)->{
|
|
|
- if(key.equals("#{userId}")){
|
|
|
- objectObjectHashMap.put(key,SecurityUtils.getUserId().toString());
|
|
|
- }else {
|
|
|
- objectObjectHashMap.put(key,vl);
|
|
|
+ queryCondition.forEach(k -> {
|
|
|
+ k.forEach((key, vl) -> {
|
|
|
+ if (key.equals("#{userId}")) {
|
|
|
+ objectObjectHashMap.put(key, SecurityUtils.getUserId().toString());
|
|
|
+ } else {
|
|
|
+ objectObjectHashMap.put(key, vl);
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
//查询下拉框数据值
|
|
|
List<Map<String, Object>> maps = commonMapper.selectDropDownList(tableName, label, value, objectObjectHashMap);
|
|
|
//建立数据key和下拉框数据的对应关系
|
|
|
- stringObjectHashMap.put(item.get("selectDataKey").toString(),maps);
|
|
|
+ stringObjectHashMap.put(item.get("selectDataKey").toString(), maps);
|
|
|
} catch (JsonProcessingException e) {
|
|
|
throw new RuntimeException(e);
|
|
|
}
|
|
@@ -136,79 +141,356 @@ public class MobilePageDataServiceImpl implements IMobilePageDataService
|
|
|
//存下拉框回显数据的值
|
|
|
String selectMapValueList = mobilePageData.getSelectMapValueList();
|
|
|
//证明以前有默认数据
|
|
|
- if(selectMapValueList!=null&&selectMapValueList!=""){
|
|
|
+ if (selectMapValueList != null && selectMapValueList != "") {
|
|
|
//默认数据转map
|
|
|
- Map<String,Object> defaultJson= objectMapper.readValue(selectMapValueList, Map.class);
|
|
|
+ Map<String, Object> defaultJson = objectMapper.readValue(selectMapValueList, Map.class);
|
|
|
//查询出来的默认数据所用字段赋值为空
|
|
|
mobilePageData.setSelectMapValueList("");
|
|
|
//把默认数据往数据map里面堆
|
|
|
stringObjectHashMap.putAll(defaultJson);
|
|
|
//从新设置下拉框数据信息字段(这字段包含所有的下拉框数据)
|
|
|
mobilePageData.setSelectMapValueList(objectMapper.writeValueAsString(stringObjectHashMap));//mao对象转json放入到字段中
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
//直接放数据不存在默认数据
|
|
|
mobilePageData.setSelectMapValueList(objectMapper.writeValueAsString(stringObjectHashMap));//mao对象转json放入到字段中
|
|
|
}
|
|
|
+ //等于0包含列表 等于1不包含列表
|
|
|
+ if (mobilePageData.getIsExistsList().equals("true")) {
|
|
|
+ //存在列表信息(未来一个页面上可能会有好多个list)
|
|
|
+ MobilePageTableList mobilePageTableList = this.getMobilePageTableList(mobilePageData.getId().toString(),commonEntity);
|
|
|
+ mobilePageData.setMobilePageTableList(mobilePageTableList);
|
|
|
+ }
|
|
|
return mobilePageData;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 查询移动端列表信息
|
|
|
+ */
|
|
|
+ private MobilePageTableList getMobilePageTableList(String pageId,CommonEntity commonEntity) throws JsonProcessingException {
|
|
|
+ //JSON转换器
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ //得到列表信息
|
|
|
+ MobilePageTableList mobilePageTableList = mobilePageTableListMapper.selectMobilePageTableListById(Long.valueOf(pageId));
|
|
|
+ //表名信息([{tableName:"studnet",asName:"stu",isMain:"true"},{"tableName":"greade",asName:"gr",isMain:"true"}])
|
|
|
+ String tableNames = mobilePageTableList.getTableNames();
|
|
|
+ //json解构成数组
|
|
|
+ List<HashMap<String, String>> tableNameList = objectMapper.readValue(tableNames, List.class);
|
|
|
+ //判断表的类型(0:单表,1:多表)
|
|
|
+ if (mobilePageTableList.getIsSingleTable().equals("0")) { //0、单表
|
|
|
+ HashMap<String, String> stringHashMap = tableNameList.get(0);
|
|
|
+ //得到表名
|
|
|
+ String tableName = stringHashMap.get("tableAsName");
|
|
|
+ //得到列信息
|
|
|
+ String tableColumnName = mobilePageTableList.getTableColumnName();
|
|
|
+ List<HashMap<String, String>> tableColumnNamelist = objectMapper.readValue(tableColumnName, List.class);
|
|
|
+ //fieldList
|
|
|
+ List<String> fieldList = new ArrayList<>();
|
|
|
+ //记录需要格式化的列数据
|
|
|
+ HashMap<String, String> formatting = new HashMap<>();
|
|
|
+ //表列信息循环
|
|
|
+ tableColumnNamelist.forEach(item -> {
|
|
|
+ //处理日期属性问题
|
|
|
+ String columnAttribute = item.get("column_attribute");
|
|
|
+ if (StringUtils.isNotEmpty(columnAttribute)) {
|
|
|
+ try {
|
|
|
+ Map<String, Object> columnAttributeMap = objectMapper.readValue(columnAttribute, Map.class);
|
|
|
+ boolean containsKey = columnAttributeMap.containsKey("dateFormat");//是否包含
|
|
|
+ boolean isDateColumn = (boolean) columnAttributeMap.get("isDateColumn");//判断是否是日志字段?
|
|
|
+ if (containsKey && isDateColumn) {
|
|
|
+ formatting.put(item.get("fieldAsName"), columnAttributeMap.get("dateFormat").toString()); //k=as 字段名->V=formattingValue
|
|
|
+ }
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
+ //处理日期格式化的问题--存在日器格式化的于日期格式化的map里
|
|
|
+ if (formatting.containsKey(item.get("fieldAsName"))) {
|
|
|
+ String formattingValue = formatting.get(item.get("fieldAsName"));//格式化类型
|
|
|
+ if (formattingValue.equals("yyyy-MM-dd")) {
|
|
|
+ //SELECT DATE_FORMAT(now(), "%Y-%m-%d" )
|
|
|
+ //一般的sql语句-:表名称.列名 as 对应的表名 DATE_FORMAT "%Y-%m-%d"|yyyy-MM-dd
|
|
|
+ StringBuffer fieldAppendString = sb.append("DATE_FORMAT(").append(item.get("tbname") + "." + item.get("fieldName")).append(",'").append("%Y-%m-%d").append("')")
|
|
|
+ .append(" as ").append(item.get("fieldAsName"));
|
|
|
+ fieldList.add(fieldAppendString.toString());
|
|
|
+ } else if (formattingValue.equals("yyyy-MM-dd hh:mm:ss")||formattingValue.equals("yyyy-MM-dd HH:mm:ss")) {
|
|
|
+ //SELECT DATE_FORMAT(now(), "%Y-%m-%d %H:%i:%s" )
|
|
|
+ //一般的sql语句-:表名称.列名 as 对应的表名 DATE_FORMAT "%Y-%m-%d %H:%i:%s"|yyyy-MM-dd HH:mm:ss
|
|
|
+ StringBuffer fieldAppendString = sb.append("DATE_FORMAT(").append(item.get("tbname") + "." + item.get("fieldName")).append(",'").append("%Y-%m-%d %H:%i:%s").append("')")
|
|
|
+ .append(" as ").append(item.get("fieldAsName"));
|
|
|
+ fieldList.add(fieldAppendString.toString());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //如果不存在证明就不是日期类型的字符串
|
|
|
+ StringBuffer fieldAppendString = sb.append(item.get("fieldName")).append(" as ").append(item.get("fieldAsName"));
|
|
|
+ fieldList.add(fieldAppendString.toString());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ //处理条件 默认值0、输入值:1,系统值2
|
|
|
+ String tableQueryConditions = mobilePageTableList.getTableQueryConditions();
|
|
|
+ //解析json([{fieldName:"tbname.fieldName":value:"xxx","operator": "eq",type:"0",},
|
|
|
+ // {fieldName:"tbname.fieldName":value:"#{x}","operator": "eq",type:"1"},
|
|
|
+ // {fieldName:"tbname.fieldName":value:"#{userID}","operator": "eq",type:"2"}])
|
|
|
+ List<HashMap<String, String>> tableQueryConditionsList = objectMapper.readValue(tableQueryConditions, List.class);
|
|
|
+ //转成对象包对象 {"key":"{fieldName:"tbname.fieldName":value:"xxx","operator": "eq",type:"0",}"}
|
|
|
+ HashMap<String, HashMap<String, String>> filedKMapValue = new HashMap();
|
|
|
+ //需要处理的默认值和系统值
|
|
|
+ List<String> conditionStringList = new ArrayList<>();
|
|
|
+ tableQueryConditionsList.forEach(item -> {
|
|
|
+ //方便参数映射条件查询
|
|
|
+ filedKMapValue.put(item.get("fieldName"), item);
|
|
|
+ //处理默认值,和系统值
|
|
|
+ String type = item.get("type");
|
|
|
+ if (type.equals("0")) {//默认值处理
|
|
|
+ conditionStringList.add(item.get("fieldName") + item.get("operator") + "'" + item.get("value") + "'");
|
|
|
+ }
|
|
|
+ if (type.equals("2")) {//系统值
|
|
|
+ if (item.get("value").equals("#{userId}")){
|
|
|
+ conditionStringList.add(item.get("fieldName") + item.get("operator") + SecurityUtils.getUserId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ //先写死条件后期改造为传递参数的的 @RequestBody CommonEntity commonEntity
|
|
|
+// CommonEntity common = new CommonEntity();
|
|
|
+ Map<String, Object> queryMap = commonEntity.getQueryMap();
|
|
|
+
|
|
|
+ //找到你传过来的条件
|
|
|
+ queryMap.forEach((k, v) -> {
|
|
|
+ HashMap<String, String> conditionMap = filedKMapValue.get(k);
|
|
|
+ conditionStringList.add(conditionMap.get("fieldName") + conditionMap.get("operator") + v);
|
|
|
+ });
|
|
|
+ //调用查询mapper[{别名:"数据"},{}]
|
|
|
+ List<HashMap<String, String>> commonEntities = commonMapper.mobileSelectList(tableName, fieldList, conditionStringList);
|
|
|
+ //封装展示描述
|
|
|
+// String tableColumnDesc = mobilePageTableList.getTableColumnDesc();
|
|
|
+// List<HashMap<String, String>> tableNamesDesMap = objectMapper.readValue(tableColumnDesc, List.class);
|
|
|
+// //存描述信息的map
|
|
|
+// HashMap<String, String> desName = new HashMap<>();
|
|
|
+// //列描述对应map
|
|
|
+// tableNamesDesMap.stream().parallel().forEach(item -> {
|
|
|
+// desName.put(item.get("column"), item.get("columnDes"));
|
|
|
+// });
|
|
|
+ //返回信息map
|
|
|
+ String listMapValue = mobilePageTableList.getListMapValue();
|
|
|
+ Map<String, Object> resultMap = objectMapper.readValue(listMapValue, Map.class);
|
|
|
+ resultMap.forEach((k, v) -> {
|
|
|
+ if (v.equals(tableName)) {
|
|
|
+ resultMap.put(k, commonEntities);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ //根据规则查询出来的数据信息
|
|
|
+ mobilePageTableList.setListMapValue(JSONObject.toJSONString(resultMap));
|
|
|
+ return mobilePageTableList;
|
|
|
+ } else if (mobilePageTableList.getIsSingleTable().equals("1")) {
|
|
|
+ //记录需要格式化的列数据--map
|
|
|
+ HashMap<String, String> formatting = new HashMap<>();
|
|
|
+
|
|
|
+ //最终查询用到的列信息: fieldList
|
|
|
+ List<String> fieldList = new ArrayList<>();
|
|
|
+
|
|
|
+ //转成对象包对象 {"key":"{fieldName:"tbname.fieldName":value:"xxx","operator": "eq",type:"0",}"}
|
|
|
+ HashMap<String, HashMap<String, String>> filedKMapValue = new HashMap();
|
|
|
+
|
|
|
+ //需要处理的默认值和系统值
|
|
|
+ List<String> conditionStringList = new ArrayList<>();
|
|
|
+
|
|
|
+ //存JoinOnString
|
|
|
+ List<String> strings=new ArrayList<>();
|
|
|
+
|
|
|
+ //取主表名称
|
|
|
+ AtomicReference<String> mainTable = new AtomicReference<>("");
|
|
|
+ //多表要循环
|
|
|
+ tableNameList.forEach(item -> {
|
|
|
+ //判断当前表是否为主表
|
|
|
+ if (item.get("isMain").equals("true")) {
|
|
|
+ mainTable.set(item.get("tableName"));
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ //处理查询列信息
|
|
|
+ //得到所有的列信息
|
|
|
+ String tableColumnName = mobilePageTableList.getTableColumnName();
|
|
|
+ //转换为一个列集合
|
|
|
+ List<HashMap<String, String>> tableColumnNamelist = objectMapper.readValue(tableColumnName, List.class);
|
|
|
+ //循环
|
|
|
+ tableColumnNamelist.forEach(item -> {
|
|
|
+ //处理日期属性问题
|
|
|
+ String columnAttribute = item.get("column_attribute");
|
|
|
+ //判断当前字段的的属性是否为空
|
|
|
+ if (StringUtils.isNotEmpty(columnAttribute)) {
|
|
|
+ try {
|
|
|
+ //得到属性map: {"isDateColumn":"false","dateFormat":"格式化格式","yyyy-MM-ddd",isshwo:"falsle"}
|
|
|
+ Map<String, Object> columnAttributeMap = objectMapper.readValue(columnAttribute, Map.class);
|
|
|
+ //是否包含当前字段的格式化规格信息
|
|
|
+ boolean containsKey = columnAttributeMap.containsKey("dateFormat");//是否包含
|
|
|
+ //是否是日期字段
|
|
|
+ boolean isDateColumn = (boolean) columnAttributeMap.get("isDateColumn");//判断是否是日志字段?
|
|
|
+ //containsKey: (true:包含||false:不包含) containsKey: (true:是||false:不是)
|
|
|
+ if (containsKey && isDateColumn) {
|
|
|
+ formatting.put(item.get("fieldAsName"), columnAttributeMap.get("dateFormat").toString()); //k=as 字段名->V=formattingValue
|
|
|
+ }
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //拼接需要查询的字段信息(线程安全的)
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
+ //处理日期格式化的问题--存在日器格式化的于日期格式化的map里
|
|
|
+ if (formatting.containsKey(item.get("fieldAsName"))) {
|
|
|
+ String formattingValue = formatting.get("fieldAsName");//格式化类型
|
|
|
+ if (formattingValue.equals("yyyy-MM-dd")) {
|
|
|
+ //SELECT DATE_FORMAT(now(), "%Y-%m-%d" )
|
|
|
+ //一般的sql语句-:表名称.列名 as 对应的表名 DATE_FORMAT "%Y-%m-%d"|yyyy-MM-dd
|
|
|
+ StringBuffer fieldAppendString = sb.append("DATE_FORMAT(").append(item.get("tbname") + "." + item.get("fieldName")).append(",'").append("%Y-%m-%d").append("')")
|
|
|
+ .append(" as ").append(item.get("fieldAsName"));
|
|
|
+ fieldList.add(fieldAppendString.toString());
|
|
|
+ } else if (formattingValue.equals("yyyy-MM-dd HH:mm:ss")) {
|
|
|
+ //SELECT DATE_FORMAT(now(), "%Y-%m-%d %H:%i:%s" )
|
|
|
+ //一般的sql语句-:表名称.列名 as 对应的表名 DATE_FORMAT "%Y-%m-%d %H:%i:%s"|yyyy-MM-dd HH:mm:ss
|
|
|
+ StringBuffer fieldAppendString = sb.append("DATE_FORMAT(").append(item.get("tbname") + "." + item.get("fieldName")).append(",'").append("%Y-%m-%d %H:%i:%s").append("')")
|
|
|
+ .append(" as ").append(item.get("fieldAsName"));
|
|
|
+ fieldList.add(fieldAppendString.toString());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //如果不存在证明就不是日期类型的字符串
|
|
|
+ StringBuffer fieldAppendString = sb.append(item.get("fieldName")).append(" as ").append(item.get("fieldAsName"));
|
|
|
+ fieldList.add(fieldAppendString.toString());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ //处理连表
|
|
|
+ String tableJoin = mobilePageTableList.getTableJoin();
|
|
|
+ //从表[{mainTable:{"tableName":"a1","tableAsName":"asA1"},"joinType":"left join","subTable:{"tableName":"a1","tableAsName":"asA1"},onWhere:["asA1.字段名"]}]
|
|
|
+ List<HashMap<String, String>> tableJoinList = objectMapper.readValue(tableJoin, List.class);
|
|
|
+ tableJoinList.forEach(item->{
|
|
|
+ try {
|
|
|
+ //取mainTable属性
|
|
|
+ String mainTable1 = item.get("mainTable");
|
|
|
+ //主表转map属性
|
|
|
+ HashMap<String, String> stringHashMap1 = objectMapper.readValue(mainTable1, HashMap.class);
|
|
|
+ //取mainTable属性
|
|
|
+ String subTable1 = item.get("subTable");
|
|
|
+ //主表转map属性
|
|
|
+ HashMap<String, String> stringHashMap2 = objectMapper.readValue(subTable1, HashMap.class);
|
|
|
+ //拼 left JOIN sale_order as so ON sp.sale_order_no = so.sale_no
|
|
|
+ //当前表的关联方式
|
|
|
+ String joinType = item.get("joinType");
|
|
|
+ //on的关联条件
|
|
|
+ String onWhere = item.get("onWhere");
|
|
|
+ //onWhereList集合信息
|
|
|
+ List<String> onWhereString = objectMapper.readValue(onWhere, List.class);
|
|
|
+ //当前
|
|
|
+ StringBuffer stringBuffer=new StringBuffer();
|
|
|
+ //连表语句中只可能存在一个主表信息(构建主体sql语句)--当前构建的是从表信息
|
|
|
+ stringBuffer.append(joinType).append(stringHashMap2.get("tableName")).append(" as ").append("tableAsName")
|
|
|
+ .append("on").append(onWhereString.get(0));
|
|
|
+ //所有的 left JOIN sale_order as so ON sp.sale_order_no = so.sale_no 都添加到一个集合里了
|
|
|
+ strings.add(stringBuffer.toString());
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ //处理查询条件的问题
|
|
|
+ //条件类型-默认值type=0、输入值:type=1,系统值:type=2
|
|
|
+ String tableQueryConditions = mobilePageTableList.getTableQueryConditions();
|
|
|
+ //解析json[{fieldName:"tbname.fieldName":value:"xxx","operator": "eq",type:"0",},{fieldName:"tbname.fieldName":value:"#{x}","operator": "eq",type:"1"},
|
|
|
+ // {fieldName:"tbname.fieldName":value:"#{userID}","operator": "eq",type:"2"}]) 备注: 查询条件用了别名就必须用别名点列名才可以
|
|
|
+ List<HashMap<String, String>> tableQueryConditionsList = objectMapper.readValue(tableQueryConditions, List.class);
|
|
|
+ //循环查询条件
|
|
|
+ tableQueryConditionsList.forEach(item -> {
|
|
|
+ //方便参数映射条件查询(字段名作为Key,当前字段信息作为值)
|
|
|
+ filedKMapValue.put(item.get("fieldName"), item); //现在fieldName=表名称.列名
|
|
|
+ //处理默认值,和系统值
|
|
|
+ Integer type = Integer.valueOf(item.get("type"));
|
|
|
+ if (type.equals("0")) {//逻辑删除条件的处理
|
|
|
+ conditionStringList.add(item.get("fieldName") + item.get("operator") + "'" + item.get("value") + "'");
|
|
|
+ }
|
|
|
+ if (type.equals("2")) {//系统user值
|
|
|
+ if (item.get("value").equals("#{userId}")) {
|
|
|
+ conditionStringList.add(item.get("fieldName") + item.get("operator") + SecurityUtils.getUserId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ //先写死条件后期改造为传递参数的的 @RequestBody CommonEntity commonEntity
|
|
|
+ CommonEntity common = new CommonEntity();
|
|
|
+ //得到前端的输入值
|
|
|
+ Map<String, Object> queryMap = common.getQueryMap();
|
|
|
+ //找到你传过来的条件
|
|
|
+ queryMap.forEach((k, v) -> {
|
|
|
+ HashMap<String, String> conditionMap = filedKMapValue.get(k);
|
|
|
+ conditionStringList.add(conditionMap.get("fieldName") + conditionMap.get("operator") + v);
|
|
|
+ });
|
|
|
+ //拼接执行对应的SQL
|
|
|
+ List<HashMap<String, String>> commonEntities = commonMapper.mobileSelectListJoin(mainTable.get(), fieldList, strings, conditionStringList);
|
|
|
+ //封装展示描述
|
|
|
+// String tableColumnDesc = mobilePageTableList.getTableColumnDesc();
|
|
|
+// List<HashMap<String, String>> tableNamesDesMap = objectMapper.readValue(tableColumnDesc, List.class);
|
|
|
+ //返回信息map
|
|
|
+ String listMapValue = mobilePageTableList.getListMapValue();
|
|
|
+ Map<String, Object> resultMap = objectMapper.readValue(listMapValue, Map.class);
|
|
|
+ resultMap.forEach((k, v) -> {
|
|
|
+ if (v.equals(mainTable.get())) {
|
|
|
+ resultMap.put(k, commonEntities);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ //根据规则查询出来的数据信息
|
|
|
+ mobilePageTableList.setListMapValue(JSONObject.toJSONString(resultMap));
|
|
|
+ return mobilePageTableList;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 查询移动端数据列表
|
|
|
- *
|
|
|
+ *
|
|
|
* @param mobilePageData 移动端数据
|
|
|
* @return 移动端数据
|
|
|
*/
|
|
|
@Override
|
|
|
- public List<MobilePageData> selectMobilePageDataList(MobilePageData mobilePageData)
|
|
|
- {
|
|
|
+ public List<MobilePageData> selectMobilePageDataList(MobilePageData mobilePageData) {
|
|
|
return mobilePageDataMapper.selectMobilePageDataList(mobilePageData);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 新增移动端数据
|
|
|
- *
|
|
|
+ *
|
|
|
* @param mobilePageData 移动端数据
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int insertMobilePageData(MobilePageData mobilePageData)
|
|
|
- {
|
|
|
+ public int insertMobilePageData(MobilePageData mobilePageData) {
|
|
|
return mobilePageDataMapper.insertMobilePageData(mobilePageData);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 修改移动端数据
|
|
|
- *
|
|
|
+ *
|
|
|
* @param mobilePageData 移动端数据
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int updateMobilePageData(MobilePageData mobilePageData)
|
|
|
- {
|
|
|
+ public int updateMobilePageData(MobilePageData mobilePageData) {
|
|
|
return mobilePageDataMapper.updateMobilePageData(mobilePageData);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 批量删除移动端数据
|
|
|
- *
|
|
|
+ *
|
|
|
* @param ids 需要删除的移动端数据主键
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int deleteMobilePageDataByIds(Long[] ids)
|
|
|
- {
|
|
|
+ public int deleteMobilePageDataByIds(Long[] ids) {
|
|
|
return mobilePageDataMapper.deleteMobilePageDataByIds(ids);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 删除移动端数据信息
|
|
|
- *
|
|
|
+ *
|
|
|
* @param id 移动端数据主键
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int deleteMobilePageDataById(Long id)
|
|
|
- {
|
|
|
+ public int deleteMobilePageDataById(Long id) {
|
|
|
return mobilePageDataMapper.deleteMobilePageDataById(id);
|
|
|
}
|
|
|
|