|
@@ -5,8 +5,11 @@ 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;
|
8
|
9
|
import com.shigongli.constants.StatusConstant;
|
9
|
10
|
import com.shigongli.entity.TaPerson;
|
|
11
|
+import com.shigongli.entity.TaShopKeeper;
|
|
12
|
+import com.shigongli.service.ITaShopKeeperService;
|
10
|
13
|
import io.swagger.annotations.Api;
|
11
|
14
|
import io.swagger.annotations.ApiOperation;
|
12
|
15
|
import io.swagger.annotations.ApiParam;
|
|
@@ -23,6 +26,7 @@ import com.shigongli.entity.TaHouse;
|
23
|
26
|
import org.springframework.web.bind.annotation.RestController;
|
24
|
27
|
|
25
|
28
|
import javax.servlet.http.HttpServletRequest;
|
|
29
|
+import java.util.List;
|
26
|
30
|
|
27
|
31
|
/**
|
28
|
32
|
* <p>
|
|
@@ -43,6 +47,9 @@ public class TaHouseController extends BaseController {
|
43
|
47
|
@Autowired
|
44
|
48
|
public ITaHouseService iTaHouseService;
|
45
|
49
|
|
|
50
|
+ @Autowired
|
|
51
|
+ ITaShopKeeperService iTaShopKeeperService;
|
|
52
|
+
|
46
|
53
|
//
|
47
|
54
|
// /**
|
48
|
55
|
// * 分页查询列表
|
|
@@ -94,11 +101,36 @@ public class TaHouseController extends BaseController {
|
94
|
101
|
*/
|
95
|
102
|
@RequestMapping(value="/ma/taHouse",method= RequestMethod.POST)
|
96
|
103
|
@ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
|
97
|
|
- public ResponseBean taHouseAdd(@ApiParam("保存内容") @RequestBody TaHouse taHouse) throws Exception{
|
|
104
|
+ public ResponseBean taHouseAdd(@ApiParam("保存内容") @RequestBody TaHouse taHouse,
|
|
105
|
+ HttpServletRequest request) throws Exception{
|
|
106
|
+ TaPerson taPerson = getPerson(request);
|
|
107
|
+ List<TaShopKeeper> shopKeeperList = iTaShopKeeperService.getByPerson(taPerson.getPersonId());
|
|
108
|
+ if (null == shopKeeperList || shopKeeperList.size() < 1) {
|
|
109
|
+ return ResponseBean.error("您无权新增房源", ResponseBean.ERROR_UNAVAILABLE);
|
|
110
|
+ }
|
|
111
|
+
|
|
112
|
+ if (!StringUtils.isEmpty(taHouse.getShopId())) {
|
|
113
|
+ boolean found = false;
|
|
114
|
+ for (TaShopKeeper keeper: shopKeeperList) {
|
|
115
|
+ if (taHouse.getShopId().equals(keeper.getShopId())) {
|
|
116
|
+ found = true;
|
|
117
|
+ }
|
|
118
|
+ }
|
|
119
|
+
|
|
120
|
+ if (!found) {
|
|
121
|
+ return ResponseBean.error("您无权新增房源, 或房源所属民宿出错", ResponseBean.ERROR_UNAVAILABLE);
|
|
122
|
+ }
|
|
123
|
+ } else {
|
|
124
|
+ if (shopKeeperList.size() > 1) {
|
|
125
|
+ return ResponseBean.error("请设置房源所属民宿", ResponseBean.ERROR_UNAVAILABLE);
|
|
126
|
+ }
|
|
127
|
+
|
|
128
|
+ taHouse.setShopId(shopKeeperList.get(0).getShopId());
|
|
129
|
+ }
|
98
|
130
|
|
99
|
131
|
if (iTaHouseService.save(taHouse)){
|
100
|
132
|
return ResponseBean.success(taHouse);
|
101
|
|
- }else {
|
|
133
|
+ } else {
|
102
|
134
|
return ResponseBean.error("保存失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
|
103
|
135
|
}
|
104
|
136
|
}
|
|
@@ -131,6 +163,9 @@ public class TaHouseController extends BaseController {
|
131
|
163
|
public ResponseBean taHouseUpdate(@ApiParam("对象ID") @PathVariable String id,
|
132
|
164
|
@ApiParam("更新内容") @RequestBody TaHouse taHouse) throws Exception{
|
133
|
165
|
|
|
166
|
+ // 不允许修改所属民宿
|
|
167
|
+ taHouse.setShopId(null);
|
|
168
|
+
|
134
|
169
|
if (iTaHouseService.updateById(taHouse)){
|
135
|
170
|
return ResponseBean.success(iTaHouseService.getById(id));
|
136
|
171
|
}else {
|