Commit fe90e3f8 by 宋珺琪

多维入参修改态势分析入参修改

parent de2c67c5
......@@ -46,6 +46,9 @@ public class KshServicePojo extends Model<KshServicePojo> {
@ApiModelProperty(value = "get/post方式")
private String type;
@ApiModelProperty(value = "入参")
private String param;
@ApiModelProperty(value = "是否带时间参数:0表示否,1表示是")
private String sfdsjcs;
......
package com.founder.commonutils.util;
/**
* 用于校验一个字符串是否是合法的JSON格式
*
*/
import java.text.CharacterIterator;
import java.text.StringCharacterIterator;
public class JsonValidator {
private CharacterIterator it;
private char c;
private int col;
public JsonValidator(){
}
/**
* 验证一个字符串是否是合法的JSON串
*
* @param input 要验证的字符串
* @return true-合法 ,false-非法
*/
public boolean validate(String input) {
input = input.trim();
boolean ret = valid(input);
return ret;
}
private boolean valid(String input) {
if ("".equals(input)) return true;
boolean ret = true;
it = new StringCharacterIterator(input);
c = it.first();
col = 1;
if (!value()) {
ret = error("value", 1);
} else {
skipWhiteSpace();
if (c != CharacterIterator.DONE) {
ret = error("end", col);
}
}
return ret;
}
private boolean value() {
return literal("true") || literal("false") || literal("null") || string() || number() || object() || array();
}
private boolean literal(String text) {
CharacterIterator ci = new StringCharacterIterator(text);
char t = ci.first();
if (c != t) return false;
int start = col;
boolean ret = true;
for (t = ci.next(); t != CharacterIterator.DONE; t = ci.next()) {
if (t != nextCharacter()) {
ret = false;
break;
}
}
nextCharacter();
if (!ret) error("literal " + text, start);
return ret;
}
private boolean array() {
return aggregate('[', ']', false);
}
private boolean object() {
return aggregate('{', '}', true);
}
private boolean aggregate(char entryCharacter, char exitCharacter, boolean prefix) {
if (c != entryCharacter) return false;
nextCharacter();
skipWhiteSpace();
if (c == exitCharacter) {
nextCharacter();
return true;
}
for (;;) {
if (prefix) {
int start = col;
if (!string()) return error("string", start);
skipWhiteSpace();
if (c != ':') return error("colon", col);
nextCharacter();
skipWhiteSpace();
}
if (value()) {
skipWhiteSpace();
if (c == ',') {
nextCharacter();
} else if (c == exitCharacter) {
break;
} else {
return error("comma or " + exitCharacter, col);
}
} else {
return error("value", col);
}
skipWhiteSpace();
}
nextCharacter();
return true;
}
private boolean number() {
if (!Character.isDigit(c) && c != '-') return false;
int start = col;
if (c == '-') nextCharacter();
if (c == '0') {
nextCharacter();
} else if (Character.isDigit(c)) {
while (Character.isDigit(c))
nextCharacter();
} else {
return error("number", start);
}
if (c == '.') {
nextCharacter();
if (Character.isDigit(c)) {
while (Character.isDigit(c))
nextCharacter();
} else {
return error("number", start);
}
}
if (c == 'e' || c == 'E') {
nextCharacter();
if (c == '+' || c == '-') {
nextCharacter();
}
if (Character.isDigit(c)) {
while (Character.isDigit(c))
nextCharacter();
} else {
return error("number", start);
}
}
return true;
}
private boolean string() {
if (c != '"') return false;
int start = col;
boolean escaped = false;
for (nextCharacter(); c != CharacterIterator.DONE; nextCharacter()) {
if (!escaped && c == '\\') {
escaped = true;
} else if (escaped) {
if (!escape()) {
return false;
}
escaped = false;
} else if (c == '"') {
nextCharacter();
return true;
}
}
return error("quoted string", start);
}
private boolean escape() {
int start = col - 1;
if (" \\\"/bfnrtu".indexOf(c) < 0) {
return error("escape sequence \\\",\\\\,\\/,\\b,\\f,\\n,\\r,\\t or \\uxxxx ", start);
}
if (c == 'u') {
if (!ishex(nextCharacter()) || !ishex(nextCharacter()) || !ishex(nextCharacter())
|| !ishex(nextCharacter())) {
return error("unicode escape sequence \\uxxxx ", start);
}
}
return true;
}
private boolean ishex(char d) {
return "0123456789abcdefABCDEF".indexOf(c) >= 0;
}
private char nextCharacter() {
c = it.next();
++col;
return c;
}
private void skipWhiteSpace() {
while (Character.isWhitespace(c)) {
nextCharacter();
}
}
private boolean error(String type, int col) {
System.out.printf("type: %s, col: %s%s", type, col, System.getProperty("line.separator"));
return false;
}
public static void main(String[] args){
String s ="{\n" +
"\t\"param\":[\n" +
"\t\t{\"name\":\"身份证号\",\"id\":\"sfzh\",\"type\": \"text\"},{\"name\":\"类型\",\"id\":\"type\",\"type\":\"optional\",\"value\":[{\"lable\":\"配偶\",\"value\":\"01\"},{\"lable\":\"子女\",\"value\":\"02\"}]},{\"name\":\"开始时间\",\"id\":\"timeStart\",\"type\":\"time\",\"format\":\"yyyy-MM-dd\"},{\"name\":\"结束时间\",\"id\":\"timeEnd\",\"type\":\"time\",\"format\":\"yyyy-MM-dd\"}\n" +
"\t]\n" +
"\t\n" +
"}";
System.out.println(s+":"+new JsonValidator().validate(s));
}
}
......@@ -27,6 +27,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
......@@ -110,7 +111,8 @@ public class CodeYymcController {
@PostMapping("yymcSelect")
@ApiOperation(value = "查询code编码")
@OperLog(message = "查询code编码", operation = OperationType.QUERY)
public MapRestResult yymcSelect(@RequestBody SkCodeYymc skCodeYymc){
public MapRestResult yymcSelect(@RequestBody SkCodeYymc skCodeYymc,HttpServletResponse response){
QueryWrapper<SkCodeYymc> wrapper = new QueryWrapper<>();
......@@ -147,6 +149,7 @@ public class CodeYymcController {
wrapper.eq("is_deleted","0");
IPage iPage = codeYymcMapper.selectPage(new Page(skCodeYymc.getPage(), skCodeYymc.getLimit()), wrapper);
// response.setStatus(401); // 设置状态码为404,表示资源未找到
return new MapRestResult(200,"ok",iPage.getTotal(),iPage.getRecords());
......
......@@ -2,6 +2,7 @@ package com.founder.servicebase.controller;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
......@@ -15,6 +16,7 @@ import com.founder.commonutils.model.newPublicEntity.ztypEntity.KshServicePojo;
import com.founder.commonutils.model.newPublicEntity.ztypEntity.KsjResultCheck;
import com.founder.commonutils.model.newPublicEntity.ztypEntity.KsjResultPojo;
import com.founder.commonutils.util.ExportExcelUtil;
import com.founder.commonutils.util.JsonValidator;
import com.founder.commonutils.util.KeyUtil;
import com.founder.commonutils.util.StringUtil;
import com.founder.servicebase.logs.OperLog;
......@@ -63,14 +65,41 @@ public class KshServiceController extends ApiController {
KshServicePojo.setXxzjbh(KeyUtil.getUUIDKey("CS"));
KshServicePojo.setCjsj(new Date());
KshServicePojo.setIsdeleted("0");
String s = KshServicePojo.getParam();
//验证json格式
boolean validate = new JsonValidator().validate(s);
if (!validate){
return new MapRestResult().error("json格式有误");
}
//验证数据字段类型
boolean checkverify = checkverify(s);
if (!checkverify){
return new MapRestResult().error("数据字段类型有误");
}
boolean save = kshService.save(KshServicePojo);
if (save) {
return new MapRestResult();
} else {
return new MapRestResult().error("保存失败");
}
}
//验证类型
public static boolean checkverify(String s ){
JSONObject object = JSONObject.parseObject(s);
JSONArray param = object.getJSONArray("param");
for (int i = 0; i < param.size(); i++) {
JSONObject jsonObject = param.getJSONObject(i);
String type = jsonObject.getString("type");
//文本 下拉框 时间
if (!type.equals("text") && !type.equals("optional") && !type.equals("time")){
return false;
}
}
return true;
}
@PostMapping("update")
@ApiOperation(value = "修改可视化服务信息")
@OperLog(message = "修改可视化服务信息", operation = OperationType.UPDATE)
......
......@@ -107,7 +107,11 @@
and ZCJDDM not in ('0600','0700','0800')
</if>
<if test="ladwGajgjgdm!= null and ladwGajgjgdm!=''">
AND T.ladw_Gajgjgdm = #{ladwGajgjgdm , jdbcType=VARCHAR }
and T.ladw_Gajgjgdm in (SELECT code FROM sys_dictitem_xz
WHERE CODE_LEV1=#{ladwGajgjgdm, jdbcType=VARCHAR}
or CODE_LEV2 =#{ladwGajgjgdm, jdbcType=VARCHAR} or CODE_LEV3 =#{ladwGajgjgdm, jdbcType=VARCHAR}
or CODE_LEV4 =#{ladwGajgjgdm, jdbcType=VARCHAR} or CODE_LEV5 =#{ladwGajgjgdm, jdbcType=VARCHAR}
)
</if>
<if test="pageSize!=0">
limit #{page},#{pageSize}
......@@ -179,6 +183,11 @@
and ZCJDDM not in ('0600','0700','0800')
</if>
<if test="ladwGajgjgdm!= null and ladwGajgjgdm!=''">
and T.ladw_Gajgjgdm in (SELECT code FROM sys_dictitem_xz
WHERE CODE_LEV1 =#{ladwGajgjgdm, jdbcType=VARCHAR}
or CODE_LEV2 =#{ladwGajgjgdm, jdbcType=VARCHAR} or CODE_LEV3 =#{ladwGajgjgdm, jdbcType=VARCHAR}
or CODE_LEV4 =#{ladwGajgjgdm, jdbcType=VARCHAR} or CODE_LEV5 =#{ladwGajgjgdm, jdbcType=VARCHAR}
)
AND T.ladw_Gajgjgdm = #{ladwGajgjgdm , jdbcType=VARCHAR }
</if>
</select>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment