LogginController.java
2.23 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
package cn.com.glsx.loggin.modules.controller;
import cn.com.glsx.loggin.modules.model.SysLogSearch;
import cn.com.glsx.loggin.modules.service.LogginService;
import com.glsx.plat.common.utils.DateUtils;
import com.glsx.plat.core.web.R;
import com.glsx.plat.loggin.entity.SysLogEntity;
import com.glsx.plat.office.excel.EasyExcelUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.data.domain.Page;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.WebRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
@RestController
@RequestMapping("loggin")
public class LogginController {
@Autowired
private LogginService logginService;
//只需要加上下面这段即可,注意不能忘记注解
@InitBinder
public void initBinder(WebDataBinder binder, WebRequest request) {
//转换日期
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));// CustomDateEditor为自定义日期编辑器
}
@GetMapping("/search")
public R search(SysLogSearch search) {
Page<SysLogEntity> pageInfo = logginService.search(search);
return R.ok().putPageData(pageInfo);
}
@GetMapping(value = "/export")
public void export(HttpServletResponse response, @Validated SysLogSearch search) throws Exception {
List<SysLogEntity> list = logginService.export(search);
EasyExcelUtils.writeExcel(response, list, "操作日志_" + DateUtils.formatSerial(new Date()), "Sheet1", SysLogEntity.class);
}
@GetMapping("/updateBelongOrg")
public R updateBelongOrg() {
logginService.updateOldDataBelongOrg();
return R.ok();
}
}