sinCloud-2021-12-30
一、后端开发规范
1、QueryInfo
1)field返回所需要的查询字段:queryInfo.setField(“a1,a2…”)
2)dic 用于枚举
3)dicName 用于枚举
4)size 分页大小
5)page 分页页数
6)order 数据库order by: queryInfo.setOrder(“a1 desc”):根据字段a1 desc排序
7)group 数据库group by:queryInfo.setGroup(“a1”):根据a1分组
8)simple—简单查询(当在复杂查询时,简单查询不会生效)
oper 字段与字段之间的关系 枚举[OperEnum]:and ,or: simple.setOper(OperEnum.and)
calc字段与值之间的查询关系,简单查询支持"=",“like”:simple.setCalc("=")
query所需查询的实体对象:simple.setQuery(user)
User user=new User();
user.username='123456'
user.pwd='1111'
simple.setQuery(user)
simple.setCalc("=")
simple.setOper(OperEnum.and)
===========================
后台拼装的sql结果:(field是已定义好的查询列表)
select field from t_user where username='123456' and pwd='1111'
前端简单构造结构
{
"page":1,
"size":10,
"field":"Holiday_ID,Holiday_Name,Holiday_Startdate,Holiday_Enddate,Holiday_status,Holiday_Desc",
"order":null,
"simple":{
"oper":"or",
"calc":"like",
"query":{
"Holiday_Name":"哈哈哈"
}
},
"dic":"Holiday_Type",
"dicName":"Holiday_Type as Holiday_TypeName"
}
后端简单查询构造
private List<ProDefPo> getProDefList(ProDefPo queryproDefPo) {
QueryInfo<ProDefPo> proDefPoQueryInfo = QueryInfoBuilder.BuildSimpleQuery(ProDefPo.class, "=", OperEnum.and);//使用QueryInfoBuilder
proDefPoQueryInfo.setSize(-1);///后面加的全部数据 默认不写20条
proDefPoQueryInfo.setQueryResult(QueryResultEnum.List);//返回list
proDefPoQueryInfo.getSimple().setQuery(queryproDefPo);//塞进来需要查询对象
proDefPoQueryInfo.setField("ProDef_ID,ProDef_Name,ProDef_Desc,ProDefType_ID");//需要查询的字段
proDefPoQueryInfo.setOrder("ProDef_Index asc");//排序字段
List<ProDefPo> proDefs = JsonHelper.ConvertToEntity(ProDefPo.class, (List<Map>) superRepository.findAll(ProDefPo.class, proDefPoQueryInfo));
return proDefs;
}
9)special----复杂查询
复杂查询支持 : “=”、">"、">="、"<"、"<="、“like”、“not like”、“is null”、“is not null”、“between”、“not between”、“in”、“not in”.
Special (oper = **and**)
SpecialQuery1 (oper = **and**)
SpecialQuery1-1
SpecialQuery1-2
SpecialQuery2 (oper = **or**)
SpecialQuery2-1
SpecialQuery2-2
SpecialQuery3(field =**"abc"**,calc=**“=”**,value1=**“hello”**)
sql : select ? from ? where SpecialQuery1 and SpecialQuery2 and (abc = ‘hello’)
sql : select ? from ? where (SpecialQuery1-1 and SpecialQuery1-2) and (SpecialQuery2-1 or SpecialQuery2-2) and (abc = ‘hello’)
前端复杂查询构造
{
"page":1,
"size":10,
"field":"Holiday_ID,Holiday_Name,Holiday_Startdate,Holiday_Enddate,Holiday_status,Holiday_Desc",
"order":null,
"dic":"Holiday_Type",
"dicName":"Holiday_Type as Holiday_TypeName",
"special":{
"oper":"and",
"queries":[
{
"field":"Holiday_Name",
"calc":"like",
"value1":"哈哈哈"
},
{
"field":"Holiday_Startdate",
"calc":"=",
"value1":"2020-08-04 00:00:00"
},
{
"field":"Holiday_Type",
"calc":"=",
"value1":"1"
},
{
"field":"Holiday_status",
"calc":"=",
"value1":"1"
}
]
}
}
后端复杂查询构造
private List<ProDefPo> getProDefListByProDefTypeID(List<Long> proDefTypeIDs) {
QueryInfo<ProDefPo> proDefPoQueryInfo = new QueryInfo<>();
List<SpecialQuery> specialQueries = new ArrayList<>();
specialQueries.add(QueryInfoBuilder.BuildSpecialQueriesByFields("ProDefType_ID", "=", OperEnum.or, proDefTypeIDs));
Special special = new Special();
special.setOper(OperEnum.and);
special.setQueries(specialQueries);
proDefPoQueryInfo.setSize(-1);///后面加的全部数据
proDefPoQueryInfo.setQueryResult(QueryResultEnum.List);
proDefPoQueryInfo.setSpecial(special);
proDefPoQueryInfo.setField("ProDef_ID,ProDef_Name,ProDef_Desc,ProDefType_ID");
proDefPoQueryInfo.setOrder("ProDef_Index asc");
List<ProDefPo> proDefs = JsonHelper.ConvertToEntity(ProDefPo.class, (List<Map>) superRepository.findAll(ProDefPo.class, proDefPoQueryInfo));
return proDefs;
}
后端复杂in查询快速构造
QueryInfo<NowActInstPo> queryInfo = new QueryInfo<>();
queryInfo.setSize(-1);
Special special = new Special(OperEnum.and)
.addQueries(QueryInfoBuilder
.BuildSpecialQueryByIn("ProInst_ID", "in",strings));
queryInfo.setSpecial(special);
10)queryResult 查询返回结果 枚举[QueryResultEnum]:List,Page,Pojo 分别对应 列表,分页,单对象
总结:
了解并使用queryInfo的基本用法,还有服务器上项目的部署