StoreController.java
7.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
package vion.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
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.*;
import vion.service.IAddressSerrvice;
import vion.service.IFileSerrvice;
import vion.service.IStoreSerrvice;
import vion.utils.ResultUtil;
import vion.vo.StatusVO;
import vion.vo.StoreVO;
import java.util.Date;
import java.util.List;
@RestController
@RequestMapping(Global.BASE_URL)
@Slf4j
public class StoreController {
@Autowired
private IStoreSerrvice storeSerrvice;
@Autowired
private IFileSerrvice fileSerrvice;
@Autowired
private IAddressSerrvice addressSerrvice;
@GetMapping("/stores")
@ResponseBody
public Object getStoreList(@RequestParam(name = "account_id")Integer account_id,
@RequestParam(name = "store_id")Integer store_id,
@RequestParam(name = "storenum",required=false)String storenum,
@RequestParam(name = "project_state",required=false)Integer project_state,
@RequestParam(name = "salesperson",required=false)String salesperson,
@RequestParam(name = "implement_type",required=false)Integer implement_type,
@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<Store> wrapper=new QueryWrapper<>();
wrapper.eq("store_id",store_id);
wrapper.eq("account_id",account_id);
if(storenum!=null)
wrapper.eq("storenum",storenum);
if(project_state!=null)
wrapper.eq("project_state",project_state);
if(salesperson!=null)
wrapper.eq("salesperson",salesperson);
if(implement_type!=null)
wrapper.eq("implement_type",implement_type);
if(startdate!=null)
wrapper.ge("orderdate",startdate);
if(enddate!=null)
wrapper.le("orderdate",enddate);
List<Store> storeList=storeSerrvice.list(wrapper);
PageInfo pageInfo=new PageInfo(storeList,10);
if (pageInfo != null) {
return ResultUtil.success(pageInfo);
} else {
return ResultUtil.error(ResultEnum.SELECT_ERROR);
}
}
@GetMapping("/store")
@ResponseBody
public Object getStoreByID(@RequestParam(name = "id")Integer id){
StoreVO storeVo=new StoreVO();//storeDao.getStoreByID(store_id);
Store store=storeSerrvice.getById(id);
storeVo.setId(store.getId());
storeVo.setNumber(store.getNumber());
storeVo.setName(store.getName());
storeVo.setStorenum(store.getStorenum());
storeVo.setAmount(store.getAmount());
storeVo.setOrderdate(store.getOrderdate());
storeVo.setSalesperson(store.getSalesperson());
storeVo.setWarranty_period(store.getWarrantyPeriod());
storeVo.setCustomer_name(store.getCustomerName());
storeVo.setProject_stage(store.getProjectStage());
storeVo.setProject_state(store.getProjectState());
storeVo.setContacts(store.getContacts());
storeVo.setRemark(store.getRemark());
//获取地址信息
Address address=addressSerrvice.getOne(Wrappers.<Address>lambdaQuery()
.eq(Address::getStoreId,id));
if(address!=null){
storeVo.setConsignee_name(address.getConsigneeName());
storeVo.setConsignee_phone(address.getConsigneePhone());
storeVo.setConsignee_address(address.getConsigneeAddress());
storeVo.setContract_name(address.getContractName());
storeVo.setContract_phone(address.getContractPhone());
storeVo.setContract_address(address.getContractAddress());
storeVo.setInvoice_name(address.getInvoiceName());
storeVo.setInvoice_phone(address.getInvoicePhone());
storeVo.setInvoice_address(address.getInvoiceAddress());
storeVo.setInvoice_info(address.getInvoiceInfo());
}
if (storeVo != null) {
return ResultUtil.success(storeVo);
} else {
return ResultUtil.error(ResultEnum.SELECT_ERROR);
}
}
@PostMapping("/stores")
@ResponseBody
public Object saveOrUpdate(@RequestBody StoreVO storeVo) {
Store store=new Store();
store.setId(storeVo.getId());
store.setNumber(storeVo.getNumber());
store.setName(storeVo.getName());
store.setStorenum(storeVo.getStorenum());
store.setAmount(storeVo.getAmount());
store.setOrderdate(storeVo.getOrderdate());
store.setSalesperson(storeVo.getSalesperson());
store.setWarrantyPeriod(storeVo.getWarranty_period());
store.setCustomerName(storeVo.getCustomer_name());
store.setProjectStage(storeVo.getProject_stage());
store.setProjectState(storeVo.getProject_state());
store.setContacts(storeVo.getContacts());
store.setRemark(storeVo.getRemark());
Address address=addressSerrvice.getOne(Wrappers.<Address>lambdaQuery()
.eq(Address::getStoreId,storeVo.getId()));
address.setConsigneeName(storeVo.getConsignee_name());
address.setConsigneePhone(storeVo.getConsignee_phone());
address.setConsigneeAddress(storeVo.getConsignee_address());
address.setContractName(storeVo.getContract_name());
address.setContractPhone(storeVo.getContract_phone());
address.setContractAddress(storeVo.getContract_address());
address.setInvoiceName(storeVo.getInvoice_name());
address.setInvoicePhone(storeVo.getInvoice_phone());
address.setInvoiceAddress(storeVo.getInvoice_address());
address.setInvoiceInfo(storeVo.getInvoice_info());
try {
storeSerrvice.saveOrUpdate(store);
addressSerrvice.saveOrUpdate(address);
return ResultUtil.success();
}catch (Exception e) {
return ResultUtil.error(ResultEnum.SELECT_ERROR);
}
}
@PostMapping("/updateStoreStatus")
@ResponseBody
public Object updateStoreStage(@RequestBody StatusVO statusVo) {
try {
//更新项目阶段
//storeDao.updateStoreStage(statusVo.getSource_id(),statusVo.getProject_stage());
UpdateWrapper updateWrapper=new UpdateWrapper();
updateWrapper.eq("id",statusVo.getSource_id());
updateWrapper.set("project_stage",statusVo.getProject_stage());
storeSerrvice.update(updateWrapper);
//添加文件附件
File file=new File();
file.setStoreId(statusVo.getStore_id());
file.setSourceId(statusVo.getSource_id());
file.setSourceType(statusVo.getSource_type());//1项目、2工单预处理,3工单操作,4巡检
file.setName(statusVo.getName());
file.setUrl(statusVo.getUrl());
file.setType(statusVo.getFile_type());
fileSerrvice.save(file);
return ResultUtil.success();
}catch (Exception e) {
return ResultUtil.error(ResultEnum.SELECT_ERROR);
}
}
}