提交 | 用户 | age
|
eb5947
|
1 |
package com.hx.phip.controller.appointment; |
F |
2 |
|
|
3 |
import com.alibaba.fastjson.JSONArray; |
|
4 |
import com.alibaba.fastjson.JSONObject; |
|
5 |
import com.github.pagehelper.PageHelper; |
|
6 |
import com.github.pagehelper.PageInfo; |
|
7 |
import com.hx.common.BaseController; |
|
8 |
import com.hx.exception.TipsException; |
|
9 |
import com.hx.guide.util.CommonQueryUtil; |
|
10 |
import com.hx.mybatisTool.SqlSentence; |
|
11 |
import com.hx.phiappt.common.OperatorConstants; |
|
12 |
import com.hx.phiappt.constants.enums.GroupTypeEnum; |
|
13 |
import com.hx.phiappt.dao.mapper.*; |
|
14 |
import com.hx.phiappt.model.*; |
|
15 |
import com.hx.phiappt.model.user.UserCard; |
|
16 |
import com.hx.phip.config.GlobalExceptionHandler; |
|
17 |
import com.hx.phip.tool.user.UserCardTool; |
|
18 |
import com.hx.resultTool.Result; |
|
19 |
import com.hx.util.DateUtil; |
|
20 |
import com.hx.util.StringUtils; |
|
21 |
import com.hz.his.dto.appointment.AppointmentAutoMateDto; |
|
22 |
import com.hz.his.dto.user.UserDto; |
|
23 |
import com.hz.his.vo.user.card.UserCardEquityVo; |
|
24 |
import com.hz.his.vo.user.card.UserCardItemVo; |
|
25 |
import com.hz.his.vo.user.card.UserCardVo; |
|
26 |
import lombok.extern.slf4j.Slf4j; |
|
27 |
import org.springframework.web.bind.annotation.RequestBody; |
|
28 |
import org.springframework.web.bind.annotation.RequestMapping; |
|
29 |
import org.springframework.web.bind.annotation.RestController; |
|
30 |
|
|
31 |
import javax.annotation.Resource; |
|
32 |
import java.util.*; |
|
33 |
|
|
34 |
/** |
|
35 |
* CRM自助预约 |
|
36 |
* @USER: fhx |
|
37 |
* @DATE: 2024/4/3 |
|
38 |
**/ |
|
39 |
@Slf4j |
|
40 |
@RestController |
|
41 |
@RequestMapping("/appointment/crm/self") |
|
42 |
public class CrmSelfController extends BaseController { |
|
43 |
|
|
44 |
/** VIP等级字符 */ |
|
45 |
public static final String VIP_STR = "金卡|钻石卡|黑卡"; |
|
46 |
/** 门店标识(静安店) */ |
|
47 |
public static final List<String> SHOP_ID_LIST = Arrays.asList("bb4e8a7d620d11ebb06bb8599f4cafbe"); |
|
48 |
|
|
49 |
@Resource |
|
50 |
private AppAutoMateController appAutoMateController; |
|
51 |
|
|
52 |
/** 预约页面数据 */ |
|
53 |
@RequestMapping("/page/data") |
|
54 |
public Result pageData(@RequestBody UserDto dto){ |
|
55 |
JSONObject data = handleUserData(dto.getUserId()); |
|
56 |
return Result.success(data); |
|
57 |
} |
|
58 |
|
|
59 |
/** CRM首页预约列表 */ |
|
60 |
@RequestMapping("/index/app/list") |
|
61 |
public Result indexAppList(@RequestBody UserDto dto){ |
|
62 |
SqlSentence sqlSentence = new SqlSentence(); |
|
63 |
Map<String, Object> values = new HashMap<>(); |
|
64 |
sqlSentence.setM(values); |
|
65 |
//查询用户最近一条预约信息 |
|
66 |
values.put("userId", dto.getUserId()); |
|
67 |
values.put("status1", Appointment.STATUS_SUC); |
|
68 |
values.put("addMode10", Appointment.ADD_MODE_CRM_SELF); |
|
69 |
StringBuilder sql = new StringBuilder(); |
|
70 |
sql.append(" select a.id, a.startTime, a.endTime , s.name as shopName , d.cnName as doctorName, a.doctorId, a.isArrive, a.projectJson ") |
|
71 |
.append(" from appointment a ") |
|
72 |
.append(" left join shop s on s.id = a.shopId ") |
|
73 |
.append(" left join employee d on d.id = a.doctorId ") |
|
74 |
.append(" where a.isDel = 0 and a.userId = #{m.userId} and a.startTime > now() ") |
|
75 |
.append(" and a.status = #{m.status1} and a.addMode = #{m.addMode10} ") |
|
76 |
.append(" order by a.startTime asc limit 1 "); |
|
77 |
sqlSentence.setSqlSentence(sql.toString()); |
|
78 |
List<Map<String, Object>> list = commonService.selectListMap(AppointmentMapper.class, sqlSentence); |
|
79 |
if(list != null && list.size() > 0){ |
|
80 |
JSONArray arr; |
|
81 |
StringBuilder nameSb = new StringBuilder(); |
|
82 |
for(Map<String, Object> m : list){ |
|
83 |
nameSb.setLength(0); |
|
84 |
arr = JSONArray.parseArray(m.get("projectJson").toString()); |
|
85 |
if(arr ==null || arr.size() < 1){ |
|
86 |
continue; |
|
87 |
} |
|
88 |
for(int i = 0 ; i < arr.size(); i++){ |
|
89 |
if(nameSb.length() > 0){ |
|
90 |
nameSb.append(","); |
|
91 |
} |
|
92 |
nameSb.append(arr.getJSONObject(i).getString("commonName")); |
|
93 |
} |
|
94 |
m.remove("projectJson"); |
|
95 |
m.put("projectNames", nameSb.toString()); |
|
96 |
} |
|
97 |
} |
|
98 |
JSONObject data = new JSONObject(); |
|
99 |
data.put("list", list); |
|
100 |
return Result.success(data); |
|
101 |
} |
|
102 |
|
|
103 |
/** 用户预约列表 */ |
|
104 |
@RequestMapping("/list") |
|
105 |
public Result selfList(@RequestBody UserDto dto){ |
|
106 |
|
|
107 |
if(StringUtils.isEmpty(dto.getUserId())){ |
|
108 |
throw new TipsException("用户标识为空!"); |
|
109 |
} |
|
110 |
|
|
111 |
SqlSentence sqlSentence = new SqlSentence(); |
|
112 |
Map<String, Object> values = new HashMap<>(); |
|
113 |
sqlSentence.setM(values); |
|
114 |
values.put("userId", dto.getUserId()); |
|
115 |
values.put("status1", Appointment.STATUS_SUC); |
|
116 |
values.put("addMode9", Appointment.ADD_MODE_CRM_CREATE); |
|
117 |
|
|
118 |
StringBuilder sql = new StringBuilder(); |
|
119 |
sql.append(" select a.id, a.startTime, a.endTime, s.name as shopName , d.cnName as doctorName, a.doctorId ") |
|
120 |
.append(" , a.status, a.isArrive, a.projectJson, a.addMode ") |
|
121 |
.append(" from appointment a ") |
|
122 |
.append(" left join shop s on s.id = a.shopId ") |
|
123 |
.append(" left join employee d on d.id = a.doctorId ") |
|
124 |
.append(" where a.isDel = 0 and a.userId = #{m.userId} ") |
|
125 |
.append(" and a.addMode != #{m.addMode9} ") |
|
126 |
.append(" order by a.startTime desc "); |
|
127 |
sqlSentence.setSqlSentence(sql.toString()); |
|
128 |
|
|
129 |
//分页插件 |
|
130 |
PageHelper.startPage(dto.getPageNum(), dto.getPageSize()); |
|
131 |
List<Map<String, Object>> list = commonService.selectListMap(AppointmentMapper.class, sqlSentence); |
|
132 |
PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(list); |
|
133 |
|
|
134 |
Map<String, Object> data = new HashMap<>(); |
|
135 |
data.put("list", pageInfo.getList()); |
|
136 |
data.put("pageNum", pageInfo.getPageNum()); |
|
137 |
data.put("pageSize", pageInfo.getPageSize()); |
|
138 |
data.put("pages", pageInfo.getPages()); |
|
139 |
data.put("total", pageInfo.getTotal()); |
|
140 |
data.put("isLastPage", pageInfo.isIsLastPage()); |
|
141 |
return Result.success(data); |
|
142 |
} |
|
143 |
|
|
144 |
/** 用户自助预约项目 */ |
|
145 |
@RequestMapping("/project/list") |
|
146 |
public Result projectList(@RequestBody UserDto dto){ |
|
147 |
|
|
148 |
if(StringUtils.isEmpty(dto.getUserId())){ |
|
149 |
throw new TipsException("用户标识为空!"); |
|
150 |
} |
|
151 |
|
|
152 |
SqlSentence sqlSentence = new SqlSentence(); |
|
153 |
Map<String, Object> values = new HashMap<>(); |
|
154 |
sqlSentence.setM(values); |
|
155 |
values.put("userId", dto.getUserId()); |
|
156 |
StringBuilder sql = new StringBuilder(); |
|
157 |
|
|
158 |
//查询用户项目 |
|
159 |
sql.append(" SELECT '1' as commonType, ui.id as commonId, ui.goodsId as commonSubId, ui.goodsName as commonName ") |
|
160 |
.append(" , p.id as projectId, p.name as projectName, p.unit, p.specification ") |
|
161 |
.append(" , p.isLifeBeauty,p.useDuration, p.palsyDuration ") |
|
162 |
.append(" , spu.id as spuId, spu.name as spuName, pi.departmentCode, pi.departmentName ") |
|
163 |
.append(" FROM user_project_item ui ") |
|
164 |
.append(" join project_type_relation tr on tr.isDel = 0 and tr.skuId = ui.goodsId and tr.moduleType = 2 ") |
|
165 |
.append(" JOIN project_assoc_sku pas ON pas.skuId = ui.goodsId ") |
|
166 |
.append(" JOIN project p ON p.id = pas.projectId ") |
|
167 |
.append(" join project_general spu on spu.id = p.projectGeneralId ") |
|
168 |
.append(" join project_info pi on pi.projectId = pas.skuId and pi.departmentCode is not null ") |
|
169 |
.append(" WHERE ui.notUsedNum > 0 AND ui.isDel = 0 AND ui.effectiveStatus = 1 ") |
|
170 |
.append(" and ui.userId = #{m.userId} AND ui.goodsType = 'project' AND p.type = 1 ") |
|
171 |
.append(" group by ui.id "); |
|
172 |
sqlSentence.setSqlSentence(sql.toString()); |
|
173 |
List<Map<String, Object>> userProjectList = commonService.selectListMap(UserProjectItemMapper.class, sqlSentence); |
|
174 |
|
|
175 |
//查询用户卡项下的项目 |
|
176 |
sqlSentence.setSqlSentence(" select * from user_card where isDel = 0 and userId = #{m.userId} and effectiveStatus = 1 "); |
|
177 |
List<UserCard> userCardList = commonService.selectList(UserCardMapper.class, sqlSentence); |
|
178 |
// log.info("用户卡项数据:{}", JSONObject.toJSONString(userCardList)); |
|
179 |
List<UserCardVo> userCardVoList = new ArrayList<>(); |
|
180 |
//遍历查询用户卡项条目是否可用 |
|
181 |
for(UserCard userCard : userCardList){ |
|
182 |
userCardVoList.add(UserCardTool.getUserCardSurplus(userCard,commonService)); |
|
183 |
} |
|
184 |
|
|
185 |
sql.setLength(0); |
|
186 |
sql.append(" SELECT '2' as commonType, i.id as commonSubId, i.commonName ") |
|
187 |
.append(" , p.id as projectId, p.name as projectName, p.unit, p.specification ") |
|
188 |
.append(" , p.isLifeBeauty, p.useDuration, p.palsyDuration ") |
|
189 |
.append(" , spu.id as spuId, spu.name as spuName, pi.departmentCode, pi.departmentName ") |
|
190 |
.append(" FROM card_item_info i ") |
|
191 |
//基于项目映射表查对应打卡项目的卡项类型,而不是到sku(commonId) |
|
192 |
.append(" join project_type_relation tr on tr.isDel = 0 and tr.skuId = i.cardItemId and tr.moduleType = 2 ") |
|
193 |
.append(" JOIN project_assoc_sku pas ON pas.skuId = i.commonId ") |
|
194 |
.append(" JOIN project p ON p.id = pas.projectId ") |
|
195 |
.append(" join project_general spu on spu.id = p.projectGeneralId ") |
|
196 |
.append(" join project_info pi on pi.projectId = pas.skuId and pi.departmentCode is not null ") |
|
197 |
.append(" WHERE i.isDel = 0 and i.commonType = 'project' and i.id = #{m.id} ") |
|
198 |
.append(" GROUP by i.id "); |
|
199 |
String userCardSql = sql.toString(); |
|
200 |
sqlSentence.setSqlSentence(userCardSql); |
|
201 |
|
|
202 |
JSONArray arr = new JSONArray(); |
|
203 |
JSONArray groupArr = null; |
|
204 |
JSONObject json; |
|
205 |
Map<String, Object> map; |
|
206 |
List<Map<String, Object>> cardProjectList; |
|
207 |
|
|
208 |
//先遍历用户卡项 |
|
209 |
// log.info("卡项vo数据:{}", JSONObject.toJSONString(userCardVoList)); |
|
210 |
for(UserCardVo userCardVo : userCardVoList){ |
|
211 |
//再遍历卡项权益 |
|
212 |
groupArr = new JSONArray(); |
|
213 |
for(UserCardEquityVo userCardEquityVo : userCardVo.getUserCardEquityVoList()) { |
|
214 |
cardProjectList = new ArrayList<>(); |
|
215 |
//再遍历卡项权益下对应的条目 |
|
216 |
for(UserCardItemVo userCardItemVo : userCardEquityVo.getUserCardItemVoList()){ |
|
217 |
//非项目类型的条目跳过 |
|
218 |
if(!GroupTypeEnum.PROJECT.getCode().equals(userCardItemVo.getItemType())){ |
|
219 |
continue; |
|
220 |
} |
|
221 |
values.put("id", userCardItemVo.getItemId()); |
|
222 |
map = commonService.selectOneMap(CardItemInfoMapper.class, sqlSentence); |
|
223 |
if(map == null || map.size() < 1){ |
|
224 |
continue; |
|
225 |
} |
|
226 |
map.put("deductionNum", userCardItemVo.getDeductionNum()); //总抵扣次数 |
|
227 |
map.put("deductionSingle", userCardItemVo.getDeductionSingle()); //单次抵扣次数 |
|
228 |
map.put("usedNum", userCardItemVo.getUsedNum()); //已抵扣次数 |
|
229 |
map.put("surplusNum", userCardItemVo.getSurplusNum()); //剩余可抵扣总次数 |
|
230 |
cardProjectList.add(map); |
|
231 |
} |
|
232 |
|
|
233 |
//卡项权益没有查询项目的跳过 |
|
234 |
if(cardProjectList.size() == 0){ |
|
235 |
continue; |
|
236 |
} |
|
237 |
|
|
238 |
json = new JSONObject(); |
|
239 |
json.put("equityName", userCardEquityVo.getEquityName()); |
|
240 |
json.put("equityType", userCardEquityVo.getEquityType()); |
|
241 |
json.put("conditionValue", userCardEquityVo.getConditionValue()); //条件值 |
|
242 |
json.put("projectList", cardProjectList); |
|
243 |
groupArr.add(json); |
|
244 |
} |
|
245 |
|
|
246 |
//卡项权益分组不为空 |
|
247 |
if(groupArr.size() > 0){ |
|
248 |
json = new JSONObject(); |
|
249 |
json.put("commonId", userCardVo.getUserCardId()); |
|
250 |
json.put("cardName", userCardVo.getCardName()); |
|
251 |
json.put("groupList", groupArr); |
|
252 |
arr.add(json); |
|
253 |
} |
|
254 |
} |
|
255 |
|
|
256 |
json = new JSONObject(); |
|
257 |
json.put("projectList", userProjectList); |
|
258 |
json.put("cardList", arr); |
|
259 |
json.put("notDeptTips", "当前项目无科室医生,请联系您的专属顾问进行预约!"); |
|
260 |
return Result.success(json); |
|
261 |
} |
|
262 |
|
|
263 |
/** 自助预约时间 */ |
|
264 |
@RequestMapping("/getTime") |
|
265 |
public Result getTime(@RequestBody AppointmentAutoMateDto dto){ |
|
266 |
|
|
267 |
if(StringUtils.isEmpty(dto.getUserId())){ |
|
268 |
throw new TipsException("预约用户标识为空!"); |
|
269 |
} |
|
270 |
|
|
271 |
if(StringUtils.isEmpty(dto.getShopId())){ |
|
272 |
throw new TipsException("预约门店标识为空!"); |
|
273 |
} |
|
274 |
|
|
275 |
if(StringUtils.isEmpty(dto.getDoctorId())){ |
|
276 |
throw new TipsException("预约医生标识为空!"); |
|
277 |
} |
|
278 |
|
|
279 |
if(StringUtils.isEmpty(dto.getArriveDate())){ |
|
280 |
throw new TipsException("预约日期为空!"); |
|
281 |
} |
|
282 |
|
|
283 |
if(StringUtils.isEmpty(dto.getProjectJson())){ |
|
284 |
throw new TipsException("预约项目为空!"); |
|
285 |
} |
|
286 |
|
|
287 |
dto.setOpType(OperatorConstants.OP_TYPE_USER); |
|
288 |
dto.setOpId(dto.getUserId()); |
|
289 |
dto.setVisitType("医美"); |
|
290 |
dto.setAppType(Appointment.APP_TYPE_TREATMENT); |
|
291 |
dto.setStartTime("09:00"); |
|
292 |
dto.setDaySpace(true); |
|
293 |
|
|
294 |
Result result; |
|
295 |
try{ |
|
296 |
result = appAutoMateController.addApplyBland(dto); |
|
297 |
}catch (Exception e){ |
|
298 |
log.info("获取用户自助预约时间失败:{}", GlobalExceptionHandler.getExceptionInformation(e)); |
|
299 |
throw new TipsException("获取预约时间失败!"); |
|
300 |
} |
|
301 |
|
|
302 |
return result; |
|
303 |
} |
|
304 |
|
|
305 |
/** 获取一周内医生排班 */ |
|
306 |
@RequestMapping("/get/doctor/time") |
|
307 |
public Result getDoctorTime(@RequestBody AppointmentAutoMateDto dto){ |
|
308 |
|
|
309 |
if(StringUtils.isEmpty(dto.getShopId())){ |
|
310 |
throw new TipsException("预约门店标识为空!"); |
|
311 |
} |
|
312 |
|
|
313 |
if(StringUtils.isEmpty(dto.getDoctorId())){ |
|
314 |
throw new TipsException("预约医生标识为空!"); |
|
315 |
} |
|
316 |
|
|
317 |
Date now = new Date(); |
|
318 |
//当天时间 |
|
319 |
String startDay = DateUtil.formatDate(now); |
|
320 |
//一周后结束时间 |
|
321 |
String endDay = DateUtil.formatDate(DateUtil.addDay(now, 6)); |
|
322 |
|
|
323 |
SqlSentence sqlSentence = new SqlSentence(); |
|
324 |
Map<String, Object> values = new HashMap<>(); |
|
325 |
sqlSentence.setM(values); |
|
326 |
values.put("shopId", dto.getShopId()); |
|
327 |
values.put("doctorId", dto.getDoctorId()); |
|
328 |
values.put("startDay", startDay); |
|
329 |
values.put("endDay", endDay); |
|
330 |
values.put("timeType", DoctorTime.TIME_TYPE_WORK); |
|
331 |
|
|
332 |
StringBuffer sql = new StringBuffer(); |
|
333 |
sql.append(" select DATE_FORMAT(startTime, '%Y-%m-%d') as dateTime ") |
|
334 |
.append(" from doctor_Time ") |
|
335 |
.append(" where isDel = 0 and doctorId = #{m.doctorId} ") |
|
336 |
.append(" and shopId = #{m.shopId} and timeType = #{m.timeType} ") |
|
337 |
.append(" and dayTime >= #{m.startDay} and dayTime <= #{m.endDay} "); |
|
338 |
sqlSentence.setSqlSentence(sql.toString()); |
|
339 |
List<Map<String, Object>> list = commonService.selectListMap(DoctorTimeMapper.class, sqlSentence); |
|
340 |
|
|
341 |
JSONObject data = new JSONObject(); |
|
342 |
data.put("list", list); |
|
343 |
return Result.success(data); |
|
344 |
} |
|
345 |
|
|
346 |
//////////////////////////////////////////////////////////////////////////////////////// |
|
347 |
|
|
348 |
private JSONObject handleUserData(String userId){ |
|
349 |
|
|
350 |
if(StringUtils.isEmpty(userId)){ |
|
351 |
throw new TipsException("用户标识为空!"); |
|
352 |
} |
|
353 |
|
|
354 |
User user = commonService.selectOneByKey(UserMapper.class, userId); |
|
355 |
if(user == null){ |
|
356 |
throw new TipsException("查询不到用户信息!"); |
|
357 |
} |
|
358 |
|
|
359 |
JSONObject data = new JSONObject(); |
|
360 |
//是否能预约:0否1是,默认0 |
|
361 |
data.put("isCanApp", BaseEntity.NO); |
|
362 |
//预约门店 = 用户所属门店 |
|
363 |
data.put("shopId", user.getShopId()); |
|
364 |
data.put("shopName", CommonQueryUtil.getShopName(user.getShopId(), commonService)); |
|
365 |
|
|
366 |
//直接跳过:非VIP客户 |
|
367 |
if(!VIP_STR.contains(user.getUserLevel())){ |
|
368 |
data.put("notAppType", 1); |
|
369 |
return data; |
|
370 |
} |
|
371 |
|
|
372 |
//直接跳过:客户所属门店非规定的 |
|
373 |
if(!SHOP_ID_LIST.contains(user.getShopId())){ |
|
374 |
data.put("notAppType", 2); |
|
375 |
return data; |
|
376 |
} |
|
377 |
|
|
378 |
//对应条件成立,则用户能预约 |
|
379 |
data.put("isCanApp", BaseEntity.YES); |
|
380 |
|
|
381 |
SqlSentence sqlSentence = new SqlSentence(); |
|
382 |
Map<String, Object> values = new HashMap<>(); |
|
383 |
sqlSentence.setM(values); |
|
384 |
values.put("userId", userId); |
|
385 |
//查询用科室关系数量 |
|
386 |
sqlSentence.setSqlSentence(" select * from user_families_room where isDel = 0 and userId = #{m.userId} "); |
|
387 |
List<UserFamiliesRoom> userFamiliesRoomList = commonService.selectList(UserFamiliesRoomMapper.class, sqlSentence); |
|
388 |
//用户科室关系为空则跳过 |
|
389 |
if(userFamiliesRoomList == null && userFamiliesRoomList.size() < 1){ |
|
390 |
data.put("notAppType", 3); |
|
391 |
return data; |
|
392 |
} |
|
393 |
data.put("userFamiliesRoomList", userFamiliesRoomList); |
|
394 |
|
|
395 |
return data; |
|
396 |
} |
|
397 |
|
|
398 |
} |