二、 通过url 传参@RequestMapping(value = "appLogin", method = RequestMethod.POST)
@ResponseBody
public JSonObject appLogin(@RequestBody Map map) {
JSonObject results=new JSonObject();
Subject subject = SecurityUtils.getSubject();
UsernamePasswordToken usernamePasswordToken = new UsernamePasswordToken(
map.get("username").toString(),
map.get("password").toString(),
"app");
String msg = "登录成功!";
int code = 0;
String username=map.get("username").toString();
//进行验证,这里可以捕获异常,然后返回对应信息
Map result = new HashMap();
try {
subject.login(usernamePasswordToken);
User user =null;
if(!"".equals(username)){user = accountmanager.findByUsername(username);}
ListgroupsList =user.getGroupsList();
List
三、 通过request 获取json串@ResponseBody
@RequestMapping("/branch/findOne/{branchId}")
public String branchFindOne( @PathVariable String branchId) {
String msg = "error";//返回信息
int code = 1;
ListList result = Arrays.asList(list.toArray());
return JSON.toJSonString(ResponseResult.result(code, msg, result));
}
@ResponseBody
@RequestMapping("/task/overhaulJournal")
public void overhaulJournal(
HttpServletRequest request, HttpServletResponse response) throws IOException {
JSonObject result = new JSonObject();
BufferedReader br;
StringBuilder sb = new StringBuilder("");
br = new BufferedReader(new InputStreamReader((ServletInputStream) request.getInputStream(), "utf-8"));
response.setContentType("text/plain;charset=UTF-8");
String temp;
while ((temp = br.readLine()) != null) {
sb.append(temp);
}
br.close();
if (sb != null) {
String msg = "error";//返回信息
int code = 1;
try {
//解析构造对象
JSonObject obj = JSONObject.parseObject(sb.toString());
if (obj != null) {
mainTenanceInterfaceService.insertTaskJournal(obj);
msg = "success";//返回信息
code = 0;
}
} catch (Exception e) {
e.printStackTrace();
}
result.put("code", code);
result.put("message", msg);
result.put("result", "");
response.getOutputStream().write(result.toString().getBytes(), 0, result.toString().getBytes().length);
}
}
四、根据对象获取public void insertTaskJournal(String returnUrl, String path,JSonObject obj){
String taskJournalstr=obj.getString("taskJournal");
TaskJournal taskJournal=JSONObject.parseObject(taskJournalstr,TaskJournal.class);
taskJournal.setTime(new Date());
TaskJournal journal=taskJournalRepository.save(taskJournal);
String questions = obj.getString("questions");
JSonArray mapList=JSONArray.fromObject(questions);
if (mapList != null && !mapList.isEmpty()) {
for(int i=0;iString questionstr=mapList.getJSonObject(i).getString("question");
Question question=JSONObject.parseObject(questionstr,Question.class);
question.setTaskJournal(journal);
question.setDiscoverTime(new Date());
questionRepository.save(question);
List imageList = (List) JSONArray.toList(JSONArray.fromObject(mapList.getJSonObject(i).get("imageList").toString()), Imgbase64Entity.class);
if (imageList != null && !imageList.isEmpty()) {
for (Imgbase64Entity ele : imageList) {
//base64图片数据
String img = ele.getImg();
//base64 转成图片,返回图片地址
Mapmap = base64ToByteUtils.savebase64(returnUrl, path, img);
//入库
String fileName = map.get("fileName");
String imgPath = map.get("imgPath");
DefectPicture defectPicture = new DefectPicture();
defectPicture.setCreateTime(new Date());
defectPicture.setPictureAddress(imgPath);
defectPicture.setPictureName(fileName);
defectPicture.setPictureCode(ele.getRemark());
if(ele.getId()!=null && ele.getId()!=""){
defectPicture.setId(Long.parseLong(ele.getId()));
}
defectPicture.setQuestion(question);
defectPicture.setType(1);
defectPictureRepository.save(defectPicture);
}
}
}
}
}
@RequestMapping("/task/createTaskProcess")
@ResponseBody
public JSonObject createTaskProcess(@RequestBody TaskProcess taskProcess
) throws IOException {
JSonObject result = new JSonObject();
String msg = "error";//返回信息
int code = 1;
try {
taskProcess.setStartTime(new Date());
maintenanceService.saveTaskProcess(taskProcess);
msg = "success";
code = 0;
} catch (Exception e) {
e.printStackTrace();
}
result.put("code", code);
result.put("msg", msg);
result.put("result", "");
//response.getOutputStream().write(result.toString().getBytes(), 0, result.toString().getBytes().length);
return result;
}



