ReportRegisterController.java
3.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package com.bsth.controller.realcontrol;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.bsth.common.ResponseCode;
import com.bsth.controller.BaseController;
import com.bsth.data.report_register.ReportRegisterService;
import com.bsth.data.report_register.entity.ReportRegister;
import com.bsth.util.HttpClientUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.WebRequest;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
/**
* 报备登记
* Created by yrf on 2019/12/04.
*/
@RestController
@RequestMapping("reportRegister")
public class ReportRegisterController extends BaseController<ReportRegister, Long>{
Logger log = LoggerFactory.getLogger(this.getClass());
final static String url = "http://114.80.178.13/complaint/TsReport/input.do";
// final static String url = "http://192.168.168.228:8080/complaint/TsReport/input.do";
@Autowired
ReportRegisterService reportRegisterService;
@InitBinder
public void initBinder(WebDataBinder binder, WebRequest request) {
//转换日期 注意这里的转化要和传进来的字符串的格式一直 如2015-9-9 就应该为yyyy-MM-dd
DateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));// CustomDateEditor为自定义日期编辑器
}
@RequestMapping(value = "/findList", method = RequestMethod.GET)
public Map<String, Object> findList(@RequestParam Map<String, String> map) {
return reportRegisterService.findList(map);
}
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public ReportRegister findById(@PathVariable("id") Long id) {
ReportRegister reportRegister = reportRegisterService.findById(id);
return reportRegister;
}
@RequestMapping(value = "/delete", method = RequestMethod.POST)
public Map<String, Object> deleteInfo(ReportRegister t) {
Map<String, Object> map = new HashMap<>();
try{
// map = baseService.delete(id);
reportRegisterService.deleteInfo(t);
String data = "{ID:'"+t.getID()+"', STATUS:'2'}";
StringBuilder sb = HttpClientUtils.post(url,data);
JSONObject obj = JSON.parseObject(sb.toString());
map.put("status2", obj);
} catch (Exception e) {
log.error(e.toString(), e);
}
return map;
}
@RequestMapping(method = RequestMethod.POST)
public Map<String, Object> save(ReportRegister t) {
Map<String, Object> map = new HashMap<>();
try{
reportRegisterService.save(t);
map.put("status", ResponseCode.SUCCESS);
map.put("t", t);
StringBuilder sb = HttpClientUtils.post(url,t.toString());
JSONObject obj = JSON.parseObject(sb.toString());
map.put("status2", obj);
} catch (Exception e) {
log.error(e.toString(), e);
}
return map;
}
}