fhx
2024-10-08 c80410cb34c2c2facc2dede1b1abe54aee7deb88
1.修改crm自助预约接口返回
1个文件已修改
178 ■■■■ 已修改文件
phi_platform_user/src/main/java/com/hx/phip/controller/appointment/CrmSelfV2Controller.java 178 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
phi_platform_user/src/main/java/com/hx/phip/controller/appointment/CrmSelfV2Controller.java
@@ -11,6 +11,7 @@
import com.hx.phiappt.constants.tool.user.UserTool;
import com.hx.phiappt.dao.mapper.*;
import com.hx.phiappt.model.*;
import com.hx.phiappt.model.market.MarketActivityLimitEc;
import com.hx.phip.config.GlobalExceptionHandler;
import com.hx.resultTool.Result;
import com.hx.util.DateUtil;
@@ -26,6 +27,8 @@
import javax.annotation.Resource;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
 * CRM自助预约v2
@@ -56,7 +59,7 @@
        return Result.success(data);
    }
    /** 医生排班 */
    /** 医生排班(按日期选医生) */
    @RequestMapping("/doctor/time/list")
    public Result doctorTimeList(@RequestBody AppointmentAutoMateDto dto){
        if(StringUtils.isEmpty(dto.getShopId())){
@@ -71,54 +74,12 @@
            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);
//        //版本1返回
//        return Result.success(doctorTimeListV1(dto));
        //版本2返回
        return Result.success(doctorTimeListV2(dto));
    }
    /** 预约项目SPU */
    @RequestMapping("/spu/list")
@@ -182,6 +143,7 @@
    }
    //////////////////////////////////////////////////////////////////////////////////////////
    /** 自助预约匹配时间 */
    @RequestMapping("/mate/time")
@@ -285,8 +247,9 @@
        sqlSentence.setM(values);
        values.put("id", data.getString("id"));
        StringBuilder sql = new StringBuilder();
        sql.append(" select a.id, a.startTime, a.endTime, s.name as shopName , d.cnName as doctorName, a.doctorId ")
        sql.append(" select a.id, a.startTime, a.endTime , d.cnName as doctorName, a.doctorId ")
                .append(" , a.status, a.isArrive, a.projectNames, a.projectJson, a.addMode, a.createManName, a.createManType, remark ")
                .append(" , s.name as shopName, s.province, s.city, s.area, s.addr")
                .append(" from appointment a ")
                .append(" left join shop s on s.id = a.shopId ")
                .append(" left join employee d on d.id = a.doctorId ")
@@ -322,8 +285,9 @@
        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, a.addMode ")
        sql.append(" select a.id, a.startTime, a.endTime, d.cnName as doctorName, a.doctorId, a.addMode ")
                .append(" , a.status, a.isArrive, a.projectJson, a.addMode, a.createManName, a.createManType, a.remark ")
                .append(" , s.name as shopName, s.province, s.city, s.area, s.addr")
                .append(" from appointment a ")
                .append(" left join shop s on s.id = a.shopId ")
                .append(" left join employee d on d.id = a.doctorId ")
@@ -358,4 +322,118 @@
//        if(hour ){}
//    }
    /** 医生排班(按日期选医生) */
    private Map<String, Object> doctorTimeListV1(AppointmentAutoMateDto dto){
        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 null;
        }
        //先遍历按日期归类
        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);
        json.put("version", "1");
        return json;
    }
    /** 医生排班(按医生选日期) */
    private Map<String, Object> doctorTimeListV2(AppointmentAutoMateDto dto){
        SqlSentence sqlSentence = new SqlSentence();
        Map<String, Object> values = new HashMap<>();
        sqlSentence.setM(values);
        values.put("shopId", dto.getShopId());
        StringBuilder sql = new StringBuilder();
        //查询门店下的医生员工
        sql.append(" select e.id as doctorId, e.cnName as doctorName, e.imgUrl ")
                .append(" from employee_role r ")
                .append(" join employee e on e.id = r.employeeId ")
                .append(" where r.isDel = 0 and e.isDel = 0 and e.isJob = 1 ")
                .append(" and r.shopId = #{m.shopId} and r.roleUniqueStr = #{m.roleUniqueStr} ");
        sqlSentence.setSqlSentence(sql.toString());
        List<Map<String, Object>> doctorList = commonService.selectListMap(EmployeeMapper.class, sqlSentence);
        Map<String, Object> dataMap = new HashMap<>();
        dataMap.put("list", doctorList);
        dataMap.put("version", "2");
        if(doctorList == null || doctorList.size() < 1){
            return dataMap;
        }
        //查询门店下对应日期范围的医生排班
        values.put("timeType", DoctorTime.TIME_TYPE_WORK);
        values.put("startTime", dto.getStartTime());
        values.put("endTime", dto.getEndTime());
        sql.setLength(0);
        sql.append(" select dt.doctorId, 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>> doctorTimeList = commonService.selectListMap(DoctorTimeMapper.class, sqlSentence);
        if(doctorTimeList == null || doctorTimeList.size() < 1){
            return dataMap;
        }
        //按医生id分组归类排班数据
        Map<String, List<Map<String, Object>>> doctorTimeMap = doctorTimeList.stream().collect(Collectors.groupingBy(m->m.get("doctorId").toString()));
        //先遍历按日期归类
        List<Map<String, Object>> dateList;
        for(Map<String, Object> doctorMap : doctorList){
            dateList = doctorTimeMap.get(doctorMap.get("doctorId"));
            if(dateList == null || dateList.size() < 1){
                continue;
            }
            //按时间排序
            dateList.sort(Comparator.comparing((Map<String, Object> h) -> ((String) h.get("startTime"))));
            dataMap.put("dateList", dateList);
        }
        return dataMap;
    }
}