|
@@ -5,6 +5,14 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
5
|
5
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
6
|
6
|
import com.shigongli.common.BaseController;
|
7
|
7
|
import com.shigongli.common.ResponseBean;
|
|
8
|
+import com.shigongli.common.StringUtils;
|
|
9
|
+import com.shigongli.constants.StatusConstant;
|
|
10
|
+import com.shigongli.entity.TaHouseOrder;
|
|
11
|
+import com.shigongli.entity.TaHouseSetting;
|
|
12
|
+import com.shigongli.entity.TaPerson;
|
|
13
|
+import com.shigongli.service.ITaHouseOrderService;
|
|
14
|
+import com.shigongli.service.ITaHouseSettingService;
|
|
15
|
+import com.shigongli.vo.HousePersonParams;
|
8
|
16
|
import io.swagger.annotations.Api;
|
9
|
17
|
import io.swagger.annotations.ApiOperation;
|
10
|
18
|
import io.swagger.annotations.ApiParam;
|
|
@@ -20,6 +28,10 @@ import com.shigongli.service.ITaHousePersonService;
|
20
|
28
|
import com.shigongli.entity.TaHousePerson;
|
21
|
29
|
import org.springframework.web.bind.annotation.RestController;
|
22
|
30
|
|
|
31
|
+import javax.servlet.http.HttpServletRequest;
|
|
32
|
+import java.util.ArrayList;
|
|
33
|
+import java.util.List;
|
|
34
|
+
|
23
|
35
|
/**
|
24
|
36
|
* <p>
|
25
|
37
|
* 住房人 前端控制器
|
|
@@ -39,6 +51,12 @@ public class TaHousePersonController extends BaseController {
|
39
|
51
|
@Autowired
|
40
|
52
|
public ITaHousePersonService iTaHousePersonService;
|
41
|
53
|
|
|
54
|
+ @Autowired
|
|
55
|
+ ITaHouseOrderService iTaHouseOrderService;
|
|
56
|
+
|
|
57
|
+ @Autowired
|
|
58
|
+ ITaHouseSettingService iTaHouseSettingService;
|
|
59
|
+
|
42
|
60
|
|
43
|
61
|
/**
|
44
|
62
|
* 分页查询列表
|
|
@@ -46,13 +64,14 @@ public class TaHousePersonController extends BaseController {
|
46
|
64
|
* @param pageSize
|
47
|
65
|
* @return
|
48
|
66
|
*/
|
49
|
|
- @RequestMapping(value="/taHousePerson",method= RequestMethod.GET)
|
|
67
|
+ @RequestMapping(value="/ma/taHousePerson",method= RequestMethod.GET)
|
50
|
68
|
@ApiOperation(value="列表", notes = "列表", httpMethod = "GET", response = ResponseBean.class)
|
51
|
69
|
public ResponseBean taHousePersonList(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
|
52
|
|
- @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize) throws Exception{
|
|
70
|
+ @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize) throws Exception{
|
53
|
71
|
|
54
|
72
|
IPage<TaHousePerson> pg = new Page<>(pageNum, pageSize);
|
55
|
73
|
QueryWrapper<TaHousePerson> queryWrapper = new QueryWrapper<>();
|
|
74
|
+ queryWrapper.eq("status", StatusConstant.NORMAL);
|
56
|
75
|
queryWrapper.orderByDesc("create_date");
|
57
|
76
|
|
58
|
77
|
IPage<TaHousePerson> result = iTaHousePersonService.page(pg, queryWrapper);
|
|
@@ -60,16 +79,68 @@ public class TaHousePersonController extends BaseController {
|
60
|
79
|
}
|
61
|
80
|
|
62
|
81
|
/**
|
63
|
|
- * 保存对象
|
64
|
|
- * @param taHousePerson 实体对象
|
|
82
|
+ * 保存入住人
|
|
83
|
+ * @param housePersonParams 实体对象
|
65
|
84
|
* @return
|
66
|
85
|
*/
|
67
|
|
- @RequestMapping(value="/taHousePerson",method= RequestMethod.POST)
|
|
86
|
+ @RequestMapping(value="/ma/taHousePerson",method= RequestMethod.POST)
|
68
|
87
|
@ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
|
69
|
|
- public ResponseBean taHousePersonAdd(@ApiParam("保存内容") @RequestBody TaHousePerson taHousePerson) throws Exception{
|
|
88
|
+ public ResponseBean taHousePersonAdd(@ApiParam("保存内容") @RequestBody HousePersonParams housePersonParams,
|
|
89
|
+ HttpServletRequest request) throws Exception{
|
|
90
|
+
|
|
91
|
+ if (null == housePersonParams) {
|
|
92
|
+ return ResponseBean.error("请设置入住人员信息", ResponseBean.ERROR_MISSING_PARAMS);
|
|
93
|
+ }
|
|
94
|
+
|
|
95
|
+ if (StringUtils.isEmpty(housePersonParams.getHouseId()) || StringUtils.isEmpty(housePersonParams.getOrderId())) {
|
|
96
|
+ return ResponseBean.error("请设置房源或订单信息", ResponseBean.ERROR_MISSING_PARAMS);
|
|
97
|
+ }
|
|
98
|
+
|
|
99
|
+ if (null == housePersonParams.getPersonList() || housePersonParams.getPersonList().size() < 1) {
|
|
100
|
+ return ResponseBean.error("请设置入住人员信息", ResponseBean.ERROR_MISSING_PARAMS);
|
|
101
|
+ }
|
|
102
|
+
|
|
103
|
+ // 订单
|
|
104
|
+ TaHouseOrder taHouseOrder = iTaHouseOrderService.getById(housePersonParams.getOrderId());
|
|
105
|
+ if (null == taHouseOrder) {
|
|
106
|
+ return ResponseBean.error("校验订单信息出错", ResponseBean.ERROR_ILLEGAL_PARAMS);
|
|
107
|
+ }
|
|
108
|
+
|
|
109
|
+ if (!StringUtils.isEmpty(taHouseOrder.getPersonId())) {
|
|
110
|
+ return ResponseBean.error("该分享房源已经存在入住信息", ResponseBean.ERROR_ILLEGAL_PARAMS);
|
|
111
|
+ }
|
|
112
|
+
|
|
113
|
+ // 设置
|
|
114
|
+ TaHouseSetting taHouseSetting = iTaHouseSettingService.getById(taHouseOrder.getSettingId());
|
|
115
|
+ if (null == taHouseSetting) {
|
|
116
|
+ return ResponseBean.error("校验房源配置出错", ResponseBean.ERROR_ILLEGAL_PARAMS);
|
|
117
|
+ }
|
|
118
|
+
|
|
119
|
+ // 填写的入住人员数量必须与设置的人数一致
|
|
120
|
+ if (housePersonParams.getPersonList().size() != taHouseSetting.getPersonNum()) {
|
|
121
|
+ return ResponseBean.error("填写入住人员数量出错", ResponseBean.ERROR_ILLEGAL_PARAMS);
|
|
122
|
+ }
|
|
123
|
+
|
|
124
|
+ // 更新订单
|
|
125
|
+ TaPerson taPerson = getPerson(request);
|
|
126
|
+ taHouseOrder.setPersonId(taPerson.getPersonId());
|
|
127
|
+ taHouseOrder.setStatus(StatusConstant.NORMAL);
|
|
128
|
+ iTaHouseOrderService.updateById(taHouseOrder);
|
|
129
|
+
|
|
130
|
+ // 插入入住人
|
|
131
|
+ List<TaHousePerson> taHousePersonList = new ArrayList<>();
|
|
132
|
+ for (HousePersonParams.Person person: housePersonParams.getPersonList()) {
|
|
133
|
+ TaHousePerson taHousePerson = new TaHousePerson();
|
|
134
|
+ taHousePerson.setHouseId(housePersonParams.getHouseId());
|
|
135
|
+ taHousePerson.setOrderId(housePersonParams.getOrderId());
|
|
136
|
+ taHousePerson.setPhone(person.getPhone());
|
|
137
|
+ taHousePerson.setName(person.getName());
|
|
138
|
+ taHousePerson.setStatus(StatusConstant.NORMAL);
|
|
139
|
+ taHousePersonList.add(taHousePerson);
|
|
140
|
+ }
|
70
|
141
|
|
71
|
|
- if (iTaHousePersonService.save(taHousePerson)){
|
72
|
|
- return ResponseBean.success(taHousePerson);
|
|
142
|
+ if (iTaHousePersonService.saveBatch(taHousePersonList)){
|
|
143
|
+ return ResponseBean.success(taHousePersonList);
|
73
|
144
|
}else {
|
74
|
145
|
return ResponseBean.error("保存失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
|
75
|
146
|
}
|