InspectController.java
3.82 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package vion.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import vion.Global;
import vion.enums.ResultEnum;
import vion.model.Inspect;
import vion.service.IInspectSerrvice;
import vion.utils.ResultUtil;
import java.util.Date;
import java.util.List;
@RestController
@RequestMapping(Global.BASE_URL)
@Slf4j
public class InspectController {
@Autowired
private IInspectSerrvice inspectSerrvice;
@GetMapping("/inspects")
@ResponseBody
public Object getProductList(@RequestParam(name = "store_id")Integer store_id,
@RequestParam(name = "status",required=false)Integer status,
@RequestParam(name = "startdate",required=false) Date startdate,
@RequestParam(name = "enddate",required=false)Date enddate,
@RequestParam(name = "pageNum")Integer pageNum,
@RequestParam(name = "pageSize")Integer pageSize){
//pageNum当前页,pageSize每页条数
PageHelper.startPage(pageNum,pageSize);
QueryWrapper<Inspect> wrapper=new QueryWrapper<>();
wrapper.eq("store_id",store_id);
if(status!=null)
wrapper.eq("status",status);
if(startdate!=null)
wrapper.ge("inspect_date",startdate);
if(enddate!=null)
wrapper.le("inspect_date",enddate);
List<Inspect> inspectList=inspectSerrvice.list(wrapper);
PageInfo pageInfo=new PageInfo(inspectList,10);
if (inspectList != null) {
return ResultUtil.success(pageInfo);
} else {
return ResultUtil.error(ResultEnum.SELECT_ERROR);
}
}
@GetMapping("/inspect")
@ResponseBody
public Object getProductByID(@RequestParam(name = "id")Integer id){
Inspect inspect=inspectSerrvice.getById(id);
if (inspect != null) {
return ResultUtil.success(inspect);
} else {
return ResultUtil.error(ResultEnum.SELECT_ERROR);
}
}
@PostMapping("/inspects")
@ResponseBody
public Object saveOrUpdate(@RequestBody Inspect data) {
try {
if(data.getId()==null){
inspectSerrvice.save(data);
return ResultUtil.success();
}else{
data.setModifyTime(new Date());
Inspect inspect=inspectSerrvice.saveAndReturn(data);
return ResultUtil.success(inspect);
}
}catch (Exception e) {
return ResultUtil.error(ResultEnum.SELECT_ERROR);
}
}
@PostMapping("/updateInspectStatus")
@ResponseBody
public Object UpdateStatus(@RequestBody Inspect data) {
Date current=new Date();
UpdateWrapper updateWrapper=new UpdateWrapper();
updateWrapper.eq("id",data.getId());
updateWrapper.set("status",data.getStatus());
updateWrapper.set("modify_time",current);
updateWrapper.set("audit_date",current);
updateWrapper.set("reviewer",data.getReviewer());
//审核状态为已完成的时候更新完成时间(0进行中、1待审核、2已完成、3、驳回)
if(data.getStatus()==2){
updateWrapper.set("finish_date",current);
}else{
updateWrapper.set("finish_date",null);
}
boolean result= inspectSerrvice.update(updateWrapper);
if(result){
return ResultUtil.success();
}else {
return ResultUtil.error(ResultEnum.SELECT_ERROR);
}
}
}