package com.yihu.wlyy.service.app.sign;

import java.util.*;

import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.entity.doctor.team.admin.AdminTeam;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.patient.SignFamily;
import com.yihu.wlyy.repository.patient.SignFamilyDao;
import com.yihu.wlyy.service.app.team.AdminTeamService;
import com.yihu.wlyy.service.common.account.DoctorService;
import com.yihu.wlyy.service.common.account.PatientService;
import com.yihu.wlyy.service.system.SystemDictService;
import com.yihu.wlyy.util.DateUtil;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.yihu.wlyy.entity.patient.SignWeb;
import com.yihu.wlyy.repository.patient.SignWebDao;
import com.yihu.wlyy.service.BaseService;

/**
 * 网络签约业务处理类
 *
 * @author George
 */
@Component
@Transactional
public class SignWebService extends BaseService {

    @Autowired
    private SignWebDao signWebDao;
    @Autowired
    private SignFamilyDao signFamilyDao;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private StringRedisTemplate redisTemplate;
    @Autowired
    private PatientService patientService;
    @Autowired
    private DoctorService doctorService;
    @Autowired
    private AdminTeamService adminTeamService;
    @Autowired
    private SystemDictService systemDictService;

    /**
     * 根据医生代码及签约状态编码 获取该医生签约患者的信息列表
     *
     * @param doctor
     * @param status
     * @param page
     * @param pageSize
     * @return
     */
    public List<Map<String, Object>> getSignWebByDoctor(String doctor, int status, int page, int pageSize) {
        // 查询语句
        String sql = "select " +
                "    a.code " +
                "    ,a.doctor " +
                "    ,b.code  as  patient" +
                "    ,b.idcard " +
                "    ,b.name " +
                "    ,b.province_name  as provinceName" +
                "    ,b.city_name  as cityName" +
                "    ,b.town_name  as townName" +
                "    ,b.address " +
                "    ,b.photo " +
                "    ,a.status " +
                "    ,a.id " +
                (status == 1 ? "    ,a.patient_apply_date as applyDate " : "    ,a.expenses_time as applyDate ") +
                "    ,a.reason " +
                "    ,b.street_name as streetName" +
                "    ,b.sex" +
                "    ,b.openid" +
                " from " +
                " ( select code,patient,doctor,status,id,apply_date,patient_apply_date,expenses_time,reason,begin from wlyy_sign_family where (doctor = ? or doctor_health = ?) and status = ? and type = 2" +
                (status == 3 ? " and expenses_status = '1'" : "") + " order by begin desc ) a " +
                " ,wlyy_patient b " +
                " where a.patient = b.code  order by a.begin desc limit " + page * pageSize + "," + pageSize;

        // 未缴费查询语句
        String sqlExpenses = "select " +
                "    a.code " +
                "    ,a.doctor " +
                "    ,b.code  as  patient" +
                "    ,b.name " +
                "    ,b.idcard " +
                "    ,b.province_name  as provinceName" +
                "    ,b.city_name  as cityName" +
                "    ,b.town_name  as townName" +
                "    ,b.address " +
                "    ,b.photo " +
                "    ,a.status " +
                "    ,a.id " +
                "    ,a.apply_date as applyDate " +
                "    ,a.reason " +
                "    ,b.street_name as streetName" +
                "    ,b.sex" +
                "    ,b.openid" +
                " from " +
                " ( select code,patient,doctor,status,id,apply_date,reason,begin,expenses_status,LENGTH(trim(ifnull(expenses_status,''))) len from wlyy_sign_family where (doctor = ? or doctor_health = ?) and status > ? and type = 2 order by begin desc ) a " +
                " ,wlyy_patient b " +
                " where a.patient = b.code and (a.expenses_status = '0' or a.len < 1) order by a.begin desc limit " + page * pageSize + "," + pageSize;

        // 已解约查询语句
        String surrSql = "select " +
                "    a.code " +
                "    ,a.doctor " +
                "    ,b.code  as  patient" +
                "    ,b.name " +
                "    ,b.idcard " +
                "    ,b.province_name  as provinceName" +
                "    ,b.city_name  as cityName" +
                "    ,b.town_name  as townName" +
                "    ,b.address " +
                "    ,b.photo " +
                "    ,a.status " +
                "    ,a.id " +
                "    ,a.apply_unsign_date as applyDate" +
                "    ,a.reason " +
                "    ,b.street_name as streetName" +
                "    ,b.sex" +
                "    ,b.openid" +
                " from " +
                " ( select code,patient,doctor,status,id,apply_date,apply_unsign_date,reason,begin from wlyy_sign_family where (doctor = ? or doctor_health = ?) and ( status = ? or status = ? ) and type = 2 order by begin desc ) a " +
                " ,wlyy_patient b " +
                " where a.patient = b.code  order by a.begin desc limit " + page * pageSize + "," + pageSize;

        // 分页信息
        //PageRequest pageRequest = new PageRequest(page - 1, pageSize);
        //1:待签约 2, 待解约 3 已签约,4已经解约
        Page<Object> list = null;
        List<Map<String, Object>> patients = null;
        switch (status) {
            case 1:// 待签约
                patients = jdbcTemplate.queryForList(sql, new Object[]{doctor, doctor, 0});
                break;
            case 2:// 待解约
                patients = jdbcTemplate.queryForList(sql, new Object[]{doctor, doctor, 2});
                break;
            case 3:// 已签约
                patients = jdbcTemplate.queryForList(sql, new Object[]{doctor, doctor, 1});
                break;
            case 4:// 4已经解约
                patients = jdbcTemplate.queryForList(surrSql, new Object[]{doctor, doctor, -3, -4});
                break;
            case 5: // 未缴费
                patients = jdbcTemplate.queryForList(sqlExpenses, new Object[]{doctor, doctor, 0});
        }

        return patients;
    }

    /**
     * 查询家庭签约已缴费未关注人数
     *
     * @param doctor
     * @return
     */
    public int isRemindFocusAll(String doctor) {
        boolean isAll = true;
        // 查询语句
        String sql = "select distinct b.code" +
                " from " +
                "     wlyy_sign_family f" +
                "     ,wlyy_patient b " +
                " where " +
                "     f.patient = b.code " +
                "     and (f.doctor = ? or f.doctor_health = ?)" +
                "     and f.expenses_status = '1' " +
                "     and f.status > 0 " +
                "     and f.type = 2 " +
                "     and LENGTH(trim(ifnull(b.openid,''))) < 1";

        List<String> result = jdbcTemplate.queryForList(sql, new Object[]{doctor, doctor},String.class);

        if (result != null && result.size() > 0) {
            Set<String> set = redisTemplate.opsForSet().members("wechat:focus:remind:set");
            if (set == null) {
                isAll = false;
            } else if(!set.containsAll(result)) {
                isAll = false;
            }
        } else {
            isAll = true;
        }

        return isAll ? 1 : 0;
    }

    /**
     * 查询家庭签约已缴费未关注人数
     *
     * @param doctor
     * @return
     */
    public int isRemindExpensesAll(String doctor) {
        boolean isAll = true;
        // 查询语句
        String sql = "select distinct f.patient" +
                " from " +
                "     wlyy_sign_family f" +
                " where " +
                "     (f.doctor = ? or f.doctor_health = ?)" +
                "     and f.status > 0 " +
                "     and f.type = 2 " +
                "     and (f.expenses_status = 0 or LENGTH(trim(ifnull(f.expenses_status,''))) < 1)";

        List<String> result = jdbcTemplate.queryForList(sql, new Object[]{doctor, doctor},String.class);

        if (result != null && result.size() > 0) {
            Set<String> set = redisTemplate.opsForSet().members("expenses:remind:set");
            if (set == null) {
                isAll = false;
            } else if(!set.containsAll(result)) {
                isAll = false;
            }
        } else {
            isAll = true;
        }

        return isAll ? 1 : 0;
    }

    /**
     * 根据代码查找签约信息明细
     *
     * @param code
     * @return
     */
    public SignWeb getSignWebByCode(String code) {
        return signWebDao.findByCode(code);
    }

    /**
     * 更新签约信息
     *
     * @return
     */
    public boolean saveSignWeb(SignWeb signWeb) {
        if (StringUtils.isEmpty(signWeb.getCode())) {
            signWeb.setCode(getCode());
            // 计算签约 月数
            if (signWeb.getBeginDate() != null && signWeb.getEndDate() != null) {
                Calendar startDate = Calendar.getInstance();
                Calendar endDate = Calendar.getInstance();
                startDate.setTime(signWeb.getBeginDate());
                endDate.setTime(signWeb.getEndDate());

                int startYear = startDate.get(Calendar.YEAR);
                int startMonth = startDate.get(Calendar.MONTH);

                int endYear = endDate.get(Calendar.YEAR);
                int endMonth = endDate.get(Calendar.MONTH);

                int result = Math.abs(endMonth - startMonth);
                if (startYear != endYear) {
                    result = 12 * (endYear - startYear) + result;
                }
                signWeb.setMonths(result);
            }
        }
        signWebDao.save(signWeb);
        return true;
    }

    /**
     * 根据患者Code 获取患者当前签约的医生信息
     *
     * @param patient
     * @return
     */
    public SignWeb getSignWebByPatient(String patient) {
        return signWebDao.findSignWebByPatient(patient);
    }

    /**
     * 根据患者Code 查询条件 以及签约状态获取签约信息
     *
     * @param patient 患者Code
     * @param status  签约状态
     * @return
     */
    public Page<Object> getSignInfoByPatient(String patient, int status, long id, int pageSize) {
        if (pageSize <= 0) {
            pageSize = 10;
        }
        // 分页信息
        PageRequest pageRequest = new PageRequest(0, pageSize);

        Page<Object> listInfo = null;
        if (id > 0) {
            switch (status) {
                case 0:// 待签约
                    listInfo = signWebDao.findToBedSignInfoByPatient(patient, id, pageRequest);
                    break;
                case 1:// 已解约
                    listInfo = signWebDao.findCancelledSignInfoByPatient(patient, id, pageRequest);
                    break;
                case 2:// 已签约
                    listInfo = signWebDao.findSignedSignInfoByPatient(patient, id, pageRequest);
                    break;
                case 3:// 待解约
                    listInfo = signWebDao.findToCancelSignInfoByPatient(patient, id, pageRequest);
                    break;
                default:
                    listInfo = signWebDao.findSignInfoByPatient(patient, id, pageRequest);
            }
        } else {
            switch (status) {
                case 0:// 待签约
                    listInfo = signWebDao.findToBedSignInfoByPatient(patient, pageRequest);
                    break;
                case 1:// 已解约
                    listInfo = signWebDao.findCancelledSignInfoByPatient(patient, pageRequest);
                    break;
                case 2:// 已签约
                    listInfo = signWebDao.findSignedSignInfoByPatient(patient, pageRequest);
                    break;
                case 3:// 待解约
                    listInfo = signWebDao.findToCancelSignInfoByPatient(patient, pageRequest);
                    break;
                default:
                    listInfo = signWebDao.findSignInfoByPatient(patient, pageRequest);
            }
        }
        return listInfo;
    }

    /**
     * 获取已签约信息
     *
     * @param patient
     * @return
     */
    public List<Object> getSignInfoByStatus(String patient) {
        return signWebDao.findSignedSignInfoBystatus(patient);
    }

    /**
     * 通过身份证获取签约信息
     */
    public List<SignFamily> getSignInfoByIdcard(String idcard) {
        return signFamilyDao.findAllByIdcard(idcard);
    }

    public JSONArray getSigns(String patient){
        List<SignFamily> signFamilys =  signFamilyDao.findAllActiveSignByPatient(patient);
        JSONArray jsonArray = new JSONArray();
        for(SignFamily signFamily: signFamilys){
            AdminTeam adminTeam = null;
            Doctor doctor = null;
            if(signFamily.getAdminTeamId()!=null){
                adminTeam = adminTeamService.getTeam(signFamily.getAdminTeamId());
                doctor = doctorService.findDoctorByCode(adminTeam.getLeaderCode());
            }
            if(adminTeam==null)adminTeam = new AdminTeam();
            if(doctor==null)doctor = new Doctor();
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("hospitalName",signFamily.getHospitalName());
            jsonObject.put("hospital",signFamily.getHospital());
            jsonObject.put("code",signFamily.getCode());
            jsonObject.put("teamCode",signFamily.getTeamCode());
            jsonObject.put("begin",signFamily.getBegin());
            jsonObject.put("end",signFamily.getEnd());
            jsonObject.put("status",signFamily.getStatus());
            jsonObject.put("leader",adminTeam.getLeaderCode());
            jsonObject.put("leaderName",doctor.getName());
            jsonObject.put("doctor",signFamily.getDoctor());
            jsonObject.put("doctorHealth",signFamily.getDoctorHealth());
            jsonObject.put("doctorName",signFamily.getDoctorName());
            jsonObject.put("doctorHealthName",signFamily.getDoctorHealthName());
            jsonObject.put("expensesStatus",StringUtils.isNotBlank(signFamily.getExpensesStatus())?signFamily.getExpensesStatus():"1");
            jsonObject.put("applyDate",signFamily.getApplyDate());
            jsonObject.put("createTime",signFamily.getCzrq());
            jsonObject.put("type",signFamily.getType());
            jsonObject.put("typeName",signFamily.getType()==1?"三师签约":"家庭签约");
            String statusName = "";
            switch (jsonObject.getInt("status")){
                case -4 : statusName = "已到期";break;
                case -3 : statusName ="已解约";break;
                case 0 : statusName ="待签约";break;
                case 1 : if(jsonObject.getInt("expensesStatus")==1){statusName ="已签约";}else{statusName ="待缴费";} break;
                case 2 : statusName ="患者申请取消签约";break;
                case 3 : statusName ="医生申请取消签约";break;
            }
            jsonObject.put("statusName",statusName);
            jsonArray.put(jsonObject);
        }
        return jsonArray;
    }

    public JSONObject getSignInfo(String teamCode){
          SignFamily signFamily = signFamilyDao.findByTeamCode(teamCode);
          if(signFamily==null){
              throw new RuntimeException("找不到签约关系！");
          }
          Patient p = patientService.findByCode(signFamily.getPatient());
          String patient = p.getCode();
          JSONObject resultObject = new JSONObject();

          AdminTeam adminTeam = adminTeamService.getTeam(signFamily.getAdminTeamId());
          //查找到团队领导
          Doctor leader = doctorService.findDoctorByCode(adminTeam.getLeaderCode());
          JSONObject leaderObj = this.doctorParse(leader);
          resultObject.put("leader",leaderObj);
          String doctorHealth = signFamily.getDoctorHealth();
          String doctor = signFamily.getDoctor();
          //签约团队的健管师
          if(StringUtils.isNotBlank(doctorHealth)){
              Doctor health = doctorService.findDoctorByCode(doctorHealth);
              JSONObject healthObj = this.doctorParse(health);
              resultObject.put("doctorHealth",healthObj);
          }
         //签约团队的全科医生
          if(StringUtils.isNotBlank(doctor)){
              Doctor qk = doctorService.findDoctorByCode(doctor);
              JSONObject qkObj = this.doctorParse(qk);
              resultObject.put("doctor",qkObj);
          }
          Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT+08:00"));
          int year = calendar.get(Calendar.YEAR);
          //统计当年咨询数量
          String consult_sql = "select count(1) as count from wlyy_consult_team  w where w.doctor = ? and w.patient =? and YEAR(w.czrq) = ? ";
         //统计随访数量
          String followup_sql = "select count(1) as count from wlyy_followup  w where (w.doctor_code = ? or w.doctor_code =?) and w.patient_code =? and YEAR(w.create_time) = ?  and w.followup_class is not null ";
         //统计待预约数量
          String reservation_sql = "select count(1) as count from wlyy_patient_reservation  w where (w.doctor = ? or w.doctor =?) and w.patient =? and YEAR(w.czrq) = ? ";
        //统计健康教育数量
          String article_sql = "select count(1) as count from wlyy_health_edu_article_patient  w where (w.doctor = ? or w.doctor =?) and w.patient =? and YEAR(w.czrq) = ? ";
        //统计健康指导数量
          String guidance_sql = "select count(1) as count from wlyy_patient_health_guidance  w where (w.doctor = ? or w.doctor =?) and w.patient =? and YEAR(w.czrq) = ? ";

          StringBuffer countSql = new StringBuffer();
          countSql.append(consult_sql).append(" union all ").append(followup_sql).append(" union all ").append(reservation_sql).append(" union all ").append(article_sql).append(" union all ").append(guidance_sql);
          List<Map<String, Object>> resultCount  = jdbcTemplate.queryForList(countSql.toString(), new Object[]{doctorHealth, patient, year,doctorHealth,doctor,patient,year,doctorHealth,doctor,patient,year,doctorHealth,doctor,patient,year,doctorHealth,doctor,patient,year});
          resultObject.put("consultNum",resultCount.get(0).get("count"));
          resultObject.put("followupNum",resultCount.get(1).get("count"));
          resultObject.put("reservationNum",resultCount.get(2).get("count"));
          resultObject.put("articleNum",resultCount.get(3).get("count"));
          resultObject.put("guidanceNum",resultCount.get(4).get("count"));
          return resultObject;
    }

    private JSONObject doctorParse(Doctor doctor){
        JSONObject object = new JSONObject();
        object.put("code",doctor.getCode());
        object.put("jobName",doctor.getJobName());
        object.put("name",doctor.getName());
        object.put("photo",doctor.getPhoto());
        object.put("sex",doctor.getSex());
        object.put("hospitalName",doctor.getHospitalName());
        return object;
    }

    public JSONObject  getSignServiceInfo(String teamCode){
        SignFamily signFamily = signFamilyDao.findByTeamCode(teamCode);
        if(signFamily==null){
            throw new RuntimeException("找不到签约关系！");
        }
        Patient p = patientService.findByCode(signFamily.getPatient());
        String patient = p.getCode();
        //获取咨询
        String consult_sql = "select w.consult,w.symptoms,w.czrq,w.status,1 as type from wlyy_consult_team  w where w.doctor = ? and w.patient =? and YEAR(w.czrq) = ? ";
        //获取随访
        String followup_sql = "select w.id,w.followup_type,w.followup_class,w.followup_date as czrq,w.followup_manager_status,w.status,2 as type from wlyy_followup  w where (w.doctor_code = ? or w.doctor_code =?) and w.patient_code =? and YEAR(w.create_time) = ? and w.followup_class is not null ";
        //获取待预约
        String reservation_sql = "select w.code,w.id, w.doctor_name,w.doctor_code,w.doctor_job,w.doctor,w.dname,w.status,w.start_time as czrq,3 as type from wlyy_patient_reservation  w where (w.doctor = ? or w.doctor =?) and w.patient =? and YEAR(w.czrq) = ? ";
        //获取健康教育
        String article_sql = "select w.id,w.article,w2.title,w2.summary,w.czrq,w.doctor,w.doctor_name,w.is_read,4 as type from wlyy_health_edu_article_patient  w,wlyy_health_edu_article w2 where w.article = w2.code and  (w.doctor = ? or w.doctor =?) and w.patient =? and YEAR(w.czrq) = ? ";
        //获取健康指导
        String guidance_sql = "select w.id,w.doctor,w.content,w.czrq,w.read_status,5 as type  from wlyy_patient_health_guidance  w where (w.doctor = ? or w.doctor =?) and w.patient =? and YEAR(w.czrq) = ? ";

        String doctorHealth = signFamily.getDoctorHealth();
        String doctor = signFamily.getDoctor();
        Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT+08:00"));
        int year = calendar.get(Calendar.YEAR);
        //咨询量
        List<Map<String, Object>> consultResult = jdbcTemplate.queryForList(consult_sql, new Object[]{doctorHealth, patient, year});
        //随访量
        List<Map<String, Object>> followupResult = jdbcTemplate.queryForList(followup_sql, new Object[]{doctorHealth,doctor, patient, year});
        //待预约量
        List<Map<String, Object>> reservationResult = jdbcTemplate.queryForList(reservation_sql, new Object[]{doctorHealth,doctor, patient, year});
        //健康教育量
        List<Map<String, Object>> articleResult = jdbcTemplate.queryForList(article_sql, new Object[]{doctorHealth,doctor, patient, year});
        //健康指导量
        List<Map<String, Object>> guidanceResult = jdbcTemplate.queryForList(guidance_sql, new Object[]{doctorHealth,doctor, patient, year});
        List<JSONObject> objects = new ArrayList<>();
        int amount  = consultResult.size()+followupResult.size()+reservationResult.size()+articleResult.size()+guidanceResult.size();
        int activeAmount = 0;
        objects.addAll(convertResult(consultResult));
        objects.addAll(convertResult(followupResult));
        objects.addAll(convertResult(reservationResult));
        objects.addAll(convertResult(articleResult));
        objects.addAll(convertResult(guidanceResult));
        for(JSONObject object: objects){
            switch (object.get("type").toString()){
                case "1":activeAmount += ("1".equals(object.get("status"))?1:0);break;
                case "2":activeAmount += ("1".equals(object.get("status"))?1:0);break;
                case "3":activeAmount += ("1".equals(object.get("status"))?1:0);break;
                case "4":activeAmount += ("1".equals(object.get("is_read"))?1:0);break;
                case "5":activeAmount += ("1".equals(object.get("read_status"))?1:0);break;
            }
        }
        objects.sort(new Comparator<JSONObject>() {
            @Override
            public int compare(JSONObject o1, JSONObject o2) {
                Date begin = DateUtil.strToDateLong(o1.get("czrq").toString());
                Date end = DateUtil.strToDateLong(o2.get("czrq").toString());

                if(begin!=null&&end !=null&&begin.before(end)){
                    return 1;
                }else{
                    return -1;
                }
            }
        });
        JSONObject object = new JSONObject();
        object.put("list",objects);
        object.put("amount",amount);
        object.put("activeAmount",activeAmount);
        return object;
    }

    private List<JSONObject> convertResult(List<Map<String, Object>> dataList){
        List<JSONObject> objects = new ArrayList<>();
        JSONObject resultObject = new JSONObject();
        for(Map<String, Object> map: dataList){
            switch (map.get("type").toString()){
                case "1":resultObject = convertConsult(map);break;
                case "2":resultObject = convertFollowup(map);break;
                case "3":resultObject = convertReservation(map);break;
                case "4":resultObject = convertArticle(map);break;
                case "5":resultObject = convertGuidance(map);break;
            }
            objects.add(resultObject);
        }
        return objects;
    }

    /**
     * 返回值装换
     * @param map
     * @return
     */
    private JSONObject convertConsult(Map<String, Object> map){
        JSONObject resultObject = new JSONObject();
        for(String key :map.keySet()){
            String value = map.get(key)+"";
            if("status".equals(key)){
                if("1".equals(value)){
                    resultObject.put("status_name","已完成");
                }else{
                    resultObject.put("status_name","进行中");
                }
            }
            resultObject.put(key,value);
        }
        return resultObject;
    }

    private JSONObject convertFollowup(Map<String, Object> map){
        JSONObject resultObject = new JSONObject();
        if(map.get("followup_manager_status")==null){
            map.put("followup_manager_status","0");
        }
        if(map.get("followup_class")==null){
            map.put("followup_class","0");
        }
        for(String key :map.keySet()){
            String value = map.get(key)+"";
            if("followup_type".equals(key)){
                String followupTypeName = systemDictService.getDictValue("FOLLOWUP_WAY_DICT", map.get(key)+"");
                resultObject.put("followup_type_name",followupTypeName);
            }
            if("followup_class".equals(key)){
                String followupClassName = systemDictService.getDictValue("FOLLOWUP_CLASS_DICT",map.get(key)+"");
                resultObject.put("followup_class_name",followupClassName);
            }
            if("followup_manager_status".equals(key)){
                String followupManagerStatusName = systemDictService.getDictValue("FOLLOWUP_MANAGER_STATUS",map.get(key)+"");
                resultObject.put("followup_manager_status_name",followupManagerStatusName);
            }
            if("status".equals(key)){
                if("1".equals(value)){
                    resultObject.put("status_name","已完成");
                }else if("2".equals(value)){
                    resultObject.put("status_name","未完成");
                }else if("3".equals(value)){
                    resultObject.put("status_name","进行中");
                }else{
                    resultObject.put("status_name","取消");
                }
            }
            resultObject.put(key,map.get(key)+"");
        }
        return resultObject;
    }

    private JSONObject convertReservation(Map<String, Object> map){
        JSONObject resultObject = new JSONObject();
        for(String key :map.keySet()){
            String value = map.get(key)+"";
            if("status".equals(key)){
                if("1".equals(value)){
                    resultObject.put("status_name","已完成");
                }else{
                    resultObject.put("status_name","已取消");
                }
            }
            resultObject.put(key,value);
        }
        return resultObject;
    }

    private JSONObject convertArticle(Map<String, Object> map){
        JSONObject resultObject = new JSONObject();
        for(String key :map.keySet()){
            String value = map.get(key)+"";
            if("is_read".equals(key)){
                if("1".equals(value)){
                    resultObject.put("status_name","已完成");
                }else{
                    resultObject.put("status_name","进行中");
                }
            }
            resultObject.put(key,value);
        }
        return resultObject;
    }

    private JSONObject convertGuidance(Map<String, Object> map){
        JSONObject resultObject = new JSONObject();
        for(String key :map.keySet()){
            String value = map.get(key)+"";
            if("read_status".equals(key)){
                if("1".equals(value)){
                    resultObject.put("status_name","已完成");
                }else{
                    resultObject.put("status_name","进行中");
                }
            }
            resultObject.put(key,value);
        }
        return resultObject;
    }

}
