New file |
| | |
| | | package com.hx.phip.controller.appointment; |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.hx.common.BaseController; |
| | | import com.hx.exception.TipsException; |
| | | import com.hx.guide.util.CommonQueryUtil; |
| | | import com.hx.mybatisTool.SqlSentence; |
| | | import com.hx.phiappt.common.OperatorConstants; |
| | | import com.hx.phiappt.constants.enums.GroupTypeEnum; |
| | | import com.hx.phiappt.constants.tool.user.UserTool; |
| | | import com.hx.phiappt.dao.mapper.*; |
| | | import com.hx.phiappt.model.*; |
| | | import com.hx.phiappt.model.user.UserCard; |
| | | import com.hx.phip.config.GlobalExceptionHandler; |
| | | import com.hx.phip.tool.user.UserCardTool; |
| | | import com.hx.resultTool.Result; |
| | | import com.hx.util.DateUtil; |
| | | import com.hx.util.StringUtils; |
| | | import com.hz.his.dto.PageDto; |
| | | import com.hz.his.dto.appointment.AppointmentAutoMateDto; |
| | | import com.hz.his.dto.appointment.AppointmentDto; |
| | | import com.hz.his.dto.appointment.AppointmentV2Dto; |
| | | import com.hz.his.dto.user.UserDto; |
| | | import com.hz.his.vo.user.card.UserCardEquityVo; |
| | | import com.hz.his.vo.user.card.UserCardItemVo; |
| | | import com.hz.his.vo.user.card.UserCardVo; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * CRM自助预约v2 |
| | | * 按phis医生排班和预约项目进行预约 |
| | | * @USER: fhx |
| | | * @DATE: 2024/4/3 |
| | | **/ |
| | | @Slf4j |
| | | @RestController |
| | | @RequestMapping("/appointment/crm/self/v2") |
| | | public class CrmSelfV2Controller extends BaseController { |
| | | |
| | | @Resource |
| | | private AppAutoMateController appAutoMateController; |
| | | @Resource |
| | | private AppointmentController appointmentController; |
| | | |
| | | public static final String FORMAT = "yyyy-MM-dd HH:mm"; |
| | | |
| | | /** 预约门店 */ |
| | | @RequestMapping("/shop/list") |
| | | public Result shopList(){ |
| | | SqlSentence sqlSentence = new SqlSentence(); |
| | | sqlSentence.setSqlSentence(" select id, name from shop where isDel = 0 and isUp = 1 "); |
| | | List<Map<String, Object>> list = commonService.selectListMap(ShopMapper.class, sqlSentence); |
| | | Map<String, Object> data = new HashMap<>(); |
| | | data.put("list", list); |
| | | return Result.success(data); |
| | | } |
| | | |
| | | /** 医生排班 */ |
| | | @RequestMapping("/doctor/time/list") |
| | | public Result doctorTimeList(@RequestBody AppointmentAutoMateDto dto){ |
| | | if(StringUtils.isEmpty(dto.getShopId())){ |
| | | throw new TipsException("门店标识为空!"); |
| | | } |
| | | |
| | | if(StringUtils.isEmpty(dto.getStartTime())){ |
| | | throw new TipsException("开始时间为空!"); |
| | | } |
| | | |
| | | if(StringUtils.isEmpty(dto.getEndTime())){ |
| | | throw new TipsException("结束时间为空!"); |
| | | } |
| | | |
| | | SqlSentence sqlSentence = new SqlSentence(); |
| | | Map<String, Object> values = new HashMap<>(); |
| | | sqlSentence.setM(values); |
| | | values.put("timeType", DoctorTime.TIME_TYPE_WORK); |
| | | values.put("shopId", dto.getShopId()); |
| | | values.put("startTime", dto.getStartTime()); |
| | | values.put("endTime", dto.getEndTime()); |
| | | StringBuilder sql = new StringBuilder(); |
| | | sql.append(" select dt.doctorId, e.cnName as doctorName, e.imgUrl ") |
| | | .append(" , date_format(dt.startTime, '%Y-%m-%d') as startTime ") |
| | | .append(" from doctor_time dt ") |
| | | .append(" left join employee e on e.id = dt.doctorId ") |
| | | .append(" where dt.isDel = 0 and dt.timeType = #{m.timeType} and dt.shopId = #{m.shopId} ") |
| | | .append(" and dt.dayTime >= #{m.startTime} and dt.endTime <= #{m.endTime} ") |
| | | .append(" order by dt.dayTime asc "); |
| | | sqlSentence.setSqlSentence(sql.toString()); |
| | | |
| | | List<Map<String, Object>> list = commonService.selectListMap(DoctorTimeMapper.class, sqlSentence); |
| | | if(list == null || list.size() < 1){ |
| | | return Result.success(); |
| | | } |
| | | |
| | | //先遍历按日期归类 |
| | | List<Map<String, Object>> dataList; |
| | | TreeMap<Object, List<Map<String, Object>>> treeMap = new TreeMap<>(); |
| | | for(Map<String, Object> map : list){ |
| | | dataList = treeMap.get(map.get("startTime")); |
| | | if(!treeMap.containsKey(map.get("startTime"))){ |
| | | dataList = new ArrayList<>(); |
| | | treeMap.put(map.get("startTime"), dataList); |
| | | } |
| | | dataList.add(map); |
| | | } |
| | | |
| | | //然后再组装 |
| | | JSONArray arr = new JSONArray(); |
| | | JSONObject json; |
| | | for(Map.Entry<Object, List<Map<String, Object>>> entry : treeMap.entrySet()){ |
| | | json = new JSONObject(); |
| | | json.put("dateTime", entry.getKey()); |
| | | json.put("doctorList", entry.getValue()); |
| | | arr.add(json); |
| | | } |
| | | |
| | | json = new JSONObject(); |
| | | json.put("list", arr); |
| | | return Result.success(json); |
| | | } |
| | | |
| | | /** 预约项目SPU */ |
| | | @RequestMapping("/spu/list") |
| | | public Result spuList(){ |
| | | SqlSentence sqlSentence = new SqlSentence(); |
| | | Map<String, Object> values = new HashMap<>(); |
| | | sqlSentence.setM(values); |
| | | values.put("type", ProjectType.TYPE_APPOINTMENT); |
| | | sqlSentence.setSqlSentence(" select id, name from project_general where isDel = 0 and type = #{m.type} and isUp = 1 order by orderNum asc "); |
| | | List<Map<String, Object>> list = commonService.selectListMap(ProjectGeneralMapper.class, sqlSentence); |
| | | Map<String, Object> data = new HashMap<>(); |
| | | data.put("list", list); |
| | | return Result.success(data); |
| | | } |
| | | |
| | | /** 预约项目 */ |
| | | @RequestMapping("/project/list") |
| | | public Result projectList(@RequestBody AppointmentDto dto){ |
| | | |
| | | if(dto.getPageSize() == null || dto.getPageSize() > 20){ |
| | | dto.setPageSize(20); |
| | | } |
| | | |
| | | SqlSentence sqlSentence = new SqlSentence(); |
| | | Map<String, Object> values = new HashMap<>(); |
| | | sqlSentence.setM(values); |
| | | values.put("type", ProjectType.TYPE_APPOINTMENT); |
| | | StringBuilder sql = new StringBuilder(); |
| | | sql.append(" select p.id, p.name ") |
| | | .append(", (p.useDuration + p.palsyDuration) / 60 as duration ") |
| | | // .append(", (p.useDuration + p.palsyDuration + p.intervalDuration + p.readyDuration) / 60 as duration") |
| | | .append(" from project p ") |
| | | .append(" where p.isDel = 0 and p.isUp = 1 and p.isShow = 1 ") |
| | | .append(" and p.type = #{m.type} "); |
| | | |
| | | if(StringUtils.noNull(dto.getKeyWord())){ |
| | | sql.append(" and p.name like '%").append(dto.getKeyWord()).append("%' "); |
| | | } |
| | | |
| | | //spuId查询 |
| | | if(StringUtils.noNull(dto.getSpuId())){ |
| | | sql.append(" and p.projectGeneralId = '").append(dto.getSpuId()).append("' "); |
| | | } |
| | | |
| | | sql.append(" order by p.orderNum asc "); |
| | | PageHelper.startPage(dto.getPageNum(), dto.getPageSize()); |
| | | List<Map<String, Object>> list = commonService.selectListMap(ProjectMapper.class, sqlSentence); |
| | | PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(list); |
| | | |
| | | Map<String, Object> data = new HashMap<>(); |
| | | data.put("list", pageInfo.getList()); |
| | | data.put("pageNum", pageInfo.getPageNum()); |
| | | data.put("pageSize", pageInfo.getPageSize()); |
| | | data.put("pages", pageInfo.getPages()); |
| | | data.put("total", pageInfo.getTotal()); |
| | | data.put("isLastPage", pageInfo.isIsLastPage()); |
| | | return Result.success(data); |
| | | } |
| | | |
| | | |
| | | |
| | | /** 自助预约匹配时间 */ |
| | | @RequestMapping("/mate/time") |
| | | public Result mateTime(@RequestBody AppointmentAutoMateDto dto){ |
| | | |
| | | if(StringUtils.isEmpty(dto.getUserId())){ |
| | | throw new TipsException("预约用户标识为空!"); |
| | | } |
| | | |
| | | if(StringUtils.isEmpty(dto.getShopId())){ |
| | | throw new TipsException("预约门店标识为空!"); |
| | | } |
| | | |
| | | if(StringUtils.isEmpty(dto.getDoctorId())){ |
| | | throw new TipsException("预约医生标识为空!"); |
| | | } |
| | | |
| | | if(StringUtils.isEmpty(dto.getArriveDate())){ |
| | | throw new TipsException("预约日期为空!"); |
| | | } |
| | | |
| | | if(StringUtils.isEmpty(dto.getStartTime())){ |
| | | throw new TipsException("预约到店时间为空!"); |
| | | } |
| | | |
| | | if(StringUtils.isEmpty(dto.getProjectJson())){ |
| | | throw new TipsException("预约项目为空!"); |
| | | } |
| | | |
| | | Date startTime = DateUtil.parseString(dto.getArriveDate() + dto.getStartTime(), FORMAT); |
| | | if(startTime == null){ |
| | | throw new TipsException("预约到店时间错误!"); |
| | | } |
| | | |
| | | //查询用户是否有到店记录 |
| | | dto.setOpType(OperatorConstants.OP_TYPE_USER); |
| | | dto.setOpId(dto.getUserId()); |
| | | dto.setVisitType("医美"); |
| | | //判断用户没到店过,则初诊 |
| | | if(UserTool.getUserArrivalNum(commonService, dto.getUserId()) == 0){ |
| | | dto.setAppType(Appointment.APP_TYPE_FIRST); |
| | | }else{ |
| | | dto.setAppType(Appointment.APP_TYPE_TREATMENT); |
| | | } |
| | | dto.setMateNum(3); |
| | | // dto.setDaySpace(true); |
| | | |
| | | Result result; |
| | | try{ |
| | | result = appAutoMateController.addApplyBland(dto); |
| | | }catch (Exception e){ |
| | | log.info("获取用户自助预约时间失败:{}", GlobalExceptionHandler.getExceptionInformation(e)); |
| | | throw new TipsException("获取预约时间失败!"); |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |
| | | /** 新增预约 */ |
| | | @RequestMapping("/add") |
| | | public Result add(@RequestBody AppointmentV2Dto dto){ |
| | | if(StringUtils.isEmpty(dto.getUserId())){ |
| | | throw new TipsException("用户标识为空!"); |
| | | } |
| | | dto.setOpId(dto.getUserId()); |
| | | dto.setOpType(OperatorConstants.OP_TYPE_USER); //操作人类型:用户 |
| | | dto.setAddMode(Appointment.ADD_MODE_CRM_SELF); //crm自助预约 |
| | | dto.setVisitType("医美"); |
| | | //判断用户没到店过,则初诊 |
| | | if(UserTool.getUserArrivalNum(commonService, dto.getUserId()) == 0){ |
| | | dto.setAppType(Appointment.APP_TYPE_FIRST); |
| | | }else{ |
| | | dto.setAppType(Appointment.APP_TYPE_TREATMENT); |
| | | } |
| | | dto.setIsMicApprove(BaseEntity.NO); //无需MIC同意 |
| | | dto.setIsSendMsg(BaseEntity.YES); //发送短信通知 |
| | | dto.setIsArriveSendMsg(BaseEntity.YES); //发送短信通知 |
| | | return appointmentController.add(dto); |
| | | } |
| | | |
| | | /** 取消预约 */ |
| | | @RequestMapping("/cancel") |
| | | public Result cancel(@RequestBody AppointmentV2Dto dto){ |
| | | if(StringUtils.isEmpty(dto.getUserId())){ |
| | | throw new TipsException("用户标识为空!"); |
| | | } |
| | | dto.setOpType(OperatorConstants.OP_TYPE_USER); |
| | | return appointmentController.cancel(dto); |
| | | } |
| | | |
| | | /** 用户预约列表 */ |
| | | @RequestMapping("/list") |
| | | public Result list(@RequestBody UserDto dto){ |
| | | |
| | | if(StringUtils.isEmpty(dto.getUserId())){ |
| | | throw new TipsException("用户标识为空!"); |
| | | } |
| | | |
| | | SqlSentence sqlSentence = new SqlSentence(); |
| | | Map<String, Object> values = new HashMap<>(); |
| | | sqlSentence.setM(values); |
| | | values.put("userId", dto.getUserId()); |
| | | values.put("status1", Appointment.STATUS_SUC); |
| | | // values.put("addMode9", Appointment.ADD_MODE_CRM_CREATE); |
| | | |
| | | StringBuilder sql = new StringBuilder(); |
| | | sql.append(" select a.id, a.startTime, a.endTime, s.name as shopName , d.cnName as doctorName, a.doctorId ") |
| | | .append(" , a.status, a.isArrive, a.projectJson, a.addMode, a.createManName, a.createManType ") |
| | | .append(" from appointment a ") |
| | | .append(" left join shop s on s.id = a.shopId ") |
| | | .append(" left join employee d on d.id = a.doctorId ") |
| | | .append(" where a.isDel = 0 and a.userId = #{m.userId} ") |
| | | // .append(" and a.addMode != #{m.addMode9} ") |
| | | .append(" order by a.startTime desc "); |
| | | sqlSentence.setSqlSentence(sql.toString()); |
| | | |
| | | //分页插件 |
| | | PageHelper.startPage(dto.getPageNum(), dto.getPageSize()); |
| | | List<Map<String, Object>> list = commonService.selectListMap(AppointmentMapper.class, sqlSentence); |
| | | PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(list); |
| | | |
| | | Map<String, Object> data = new HashMap<>(); |
| | | data.put("list", pageInfo.getList()); |
| | | data.put("pageNum", pageInfo.getPageNum()); |
| | | data.put("pageSize", pageInfo.getPageSize()); |
| | | data.put("pages", pageInfo.getPages()); |
| | | data.put("total", pageInfo.getTotal()); |
| | | data.put("isLastPage", pageInfo.isIsLastPage()); |
| | | return Result.success(data); |
| | | } |
| | | |
| | | /////////////////////////////////////////////////////////////////////////////////////////// |
| | | |
| | | // private void checkTime(Date startTime){ |
| | | // Calendar calendar = Calendar.getInstance(); |
| | | // calendar.setTime(startTime); |
| | | // int hour = calendar.get(Calendar.HOUR); |
| | | // if(hour ){} |
| | | // } |
| | | |
| | | } |