StoreController.java
9.79 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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
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.Page;
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.format.annotation.DateTimeFormat;
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.StoreListVO;
import vion.vo.StoreVO;
import java.util.*;
@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 = "accountId",required=false)Integer account_id,
@RequestParam(name = "storeId",required=false)Integer store_id,
@RequestParam(name = "storenum",required=false)String storenum,
@RequestParam(name = "projectState",required=false)Integer project_state,
@RequestParam(name = "salesperson",required=false)String salesperson,
@RequestParam(name = "implementType",required=false)Integer implement_type,
@RequestParam(name = "startdate",required=false)
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") Date startdate,
@RequestParam(name = "enddate",required=false)
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") Date enddate,
@RequestParam(name = "pageNum")Integer pageNum,
@RequestParam(name = "pageSize")Integer pageSize){
//pageNum当前页,pageSize每页条数
Page page= PageHelper.startPage(pageNum,pageSize);
QueryWrapper<Store> wrapper=new QueryWrapper<>();
if(store_id!=null){
wrapper.eq("id",store_id);
}
if(account_id!=null)
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.between("orderdate",startdate,enddate);
List<Store> storeList=storeSerrvice.list(wrapper);
storeList.sort(Comparator.comparing(Store::getId));
PageInfo pageInfo=new PageInfo<>(page);
pageInfo.setList(storeList);
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();
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.setWarrantyPeriod(store.getWarrantyPeriod());
storeVo.setCustomerName(store.getCustomerName());
storeVo.setProjectStage(store.getProjectStage());
storeVo.setProjectState(store.getProjectState());
storeVo.setContacts(store.getContacts());
storeVo.setRemark(store.getRemark());
storeVo.setAccountId(store.getAccountId());
storeVo.setContractCode(store.getContractCode());
storeVo.setImplementType(store.getImplementType());
//获取地址信息
Address address=addressSerrvice.getOne(Wrappers.<Address>lambdaQuery()
.eq(Address::getStoreId,id));
if(address!=null){
storeVo.setConsigneeName(address.getConsigneeName());
storeVo.setConsigneePhone(address.getConsigneePhone());
storeVo.setConsigneeAddress(address.getConsigneeAddress());
storeVo.setContractName(address.getContractName());
storeVo.setContractPhone(address.getContractPhone());
storeVo.setContractAddress(address.getContractAddress());
storeVo.setInvoiceName(address.getInvoiceName());
storeVo.setInvoicePhone(address.getInvoicePhone());
storeVo.setInvoiceAddress(address.getInvoiceAddress());
storeVo.setInvoiceInfo(address.getInvoiceInfo());
}
if (storeVo != null) {
return ResultUtil.success(storeVo);
} else {
return ResultUtil.error(ResultEnum.SELECT_ERROR);
}
}
@GetMapping("/storeList")
@ResponseBody
public Object getStoreList(@RequestParam(name = "accountId",required=false)Integer account_id){
QueryWrapper<Store> wrapper=new QueryWrapper<>();
if(account_id!=null)
wrapper.eq("account_id",account_id);
List<Store> storeList=storeSerrvice.list(wrapper);
List<StoreListVO> storeListVOS=new ArrayList<>();
for (Store store : storeList){
StoreListVO storeListVO=new StoreListVO();
storeListVO.setId(store.getId());
storeListVO.setName(store.getName());
storeListVOS.add(storeListVO);
}
storeListVOS.sort(Comparator.comparing(StoreListVO::getId));
if (storeListVOS != null) {
return ResultUtil.success(storeListVOS);
} else {
return ResultUtil.error(ResultEnum.SELECT_ERROR);
}
}
@PostMapping("/stores")
@ResponseBody
public Object saveOrUpdate(@RequestBody StoreVO storeVo,@RequestAttribute String userid) {
User user=Global.USERNAME_MAP.get(userid);
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.getWarrantyPeriod());
store.setCustomerName(storeVo.getCustomerName());
store.setProjectStage(storeVo.getProjectStage());
store.setProjectState(storeVo.getProjectState());
store.setContacts(storeVo.getContacts());
store.setContractCode(storeVo.getContractCode());
store.setImplementType(storeVo.getImplementType());
store.setRemark(storeVo.getRemark());
store.setAccountId(storeVo.getAccountId());
if(storeVo.getId()!=null) {
store.setModifyUser(user.getId());
}else{
store.setCreateUser(user.getId());
}
try {
Store store1= storeSerrvice.saveAndReturn(store);
Address address=addressSerrvice.getOne(Wrappers.<Address>lambdaQuery()
.eq(Address::getStoreId,store1.getId()));
if(address==null){
address=new Address();
address.setStoreId(store1.getId());
}
address.setConsigneeName(storeVo.getConsigneeName());
address.setConsigneePhone(storeVo.getConsigneePhone());
address.setConsigneeAddress(storeVo.getConsigneeAddress());
address.setContractName(storeVo.getContractName());
address.setContractPhone(storeVo.getContractPhone());
address.setContractAddress(storeVo.getContractAddress());
address.setInvoiceName(storeVo.getInvoiceName());
address.setInvoicePhone(storeVo.getInvoicePhone());
address.setInvoiceAddress(storeVo.getInvoiceAddress());
address.setInvoiceInfo(storeVo.getInvoiceInfo());
addressSerrvice.saveOrUpdate(address);
return ResultUtil.success();
}catch (Exception e) {
// return ResultUtil.error(ResultEnum.SELECT_ERROR);
return e.getMessage().toString();
}
}
@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.getSourceId());
updateWrapper.set("project_stage",statusVo.getProjectStage());
storeSerrvice.update(updateWrapper);
//添加文件附件
File file=new File();
file.setStoreId(statusVo.getStoreId());
file.setSourceId(statusVo.getSourceId());
file.setSourceType(statusVo.getSourceType());//1项目、2工单预处理,3工单操作,4巡检
file.setName(statusVo.getName());
file.setUrl(statusVo.getUrl());
file.setType(statusVo.getType());
fileSerrvice.save(file);
return ResultUtil.success();
}catch (Exception e) {
// return ResultUtil.error(ResultEnum.SELECT_ERROR);
return e.getMessage().toString();
}
}
}