package com.mosty.yjzl.service.Impl;


import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mosty.base.model.dto.qwzx.TbQwXfbbQueryByJlDto;
import com.mosty.base.model.dto.yjzl.*;
import com.mosty.base.model.dto.yszx.TbYsSxtDto;
import com.mosty.base.model.entity.qwzx.TbQwXfbb;
import com.mosty.base.model.entity.rh.RhMyhtWarn;
import com.mosty.base.model.entity.yjzl.*;
import com.mosty.base.model.query.afjcsj.VwSyrkJzgjGxListQuery;
import com.mosty.base.model.query.yjzl.*;
import com.mosty.base.model.vo.base.DeptInfoVo;
import com.mosty.base.utils.DateUtils;
import com.mosty.base.utils.IDCardUtil;
import com.mosty.base.utils.UUIDGenerator;
import com.mosty.common.base.exception.BusinessException;
import com.mosty.common.core.business.entity.SysUser;
import com.mosty.common.core.util.http.HttpUtils;
import com.mosty.common.token.UserInfo;
import com.mosty.common.token.UserInfoManager;
import com.mosty.yjzl.mapper.*;
import com.mosty.yjzl.remote.TbBaseAdaptRemoteService;
import com.mosty.yjzl.remote.TbQwzxAdaptRemoteService;
import com.mosty.yjzl.remote.TbYszxAdaptRemoteService;
import com.mosty.yjzl.service.TbYjxxService;
import com.mosty.yjzl.service.TbZlxxService;
import com.mosty.yjzl.utils.OkHttpUtils;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @author dw
 * @since 2022-10-21
 */
@Service
@AllArgsConstructor
public class TbYjxxServiceImpl extends ServiceImpl<TbYjxxMapper, TbYjxx> implements TbYjxxService {

    private final TbYjxxClMapper tbYjxxClMapper;
    private final TbYjxxClBqMapper tbYjxxClBqMapper;
    private final TbYjxxRyMapper tbYjxxRyMapper;
    private final TbYjxxRyBqMapper tbYjxxRyBqMapper;
    private final TbYszxAdaptRemoteService tbYszxAdaptRemoteService;
    private final TbZlxxService tbZlxxService;
    private final TbZlxxMapper tbZlxxMapper;
    private final TbYjxxMapper tbYjxxMapper;
    private final TbQwzxAdaptRemoteService tbQwzxAdaptRemoteService;
    private final TbBaseAdaptRemoteService tbBaseAdaptRemoteService;

    @Override
    public IPage<TbYjxx> getPageList(TbYjxxQuery dto) {
        dto.setSsbmdm(this.tbBaseAdaptRemoteService.getSsbm(dto.getSsbmdm(), null));
        Map<String, Object> map = new HashMap<>();
        List<String> yjlxList = new ArrayList<>();
        if (StringUtils.isNotBlank(dto.getYjLx())) {
            yjlxList = Arrays.asList(dto.getYjLx().split(","));
        }
        //预警来源
        List<String> yjlyList = new ArrayList<>();
        if (StringUtils.isNotBlank(dto.getYjlyids())) {
            yjlyList = Arrays.asList(dto.getYjlyids().split(","));
        }


        map.put("dto", dto);
        map.put("yjlxList", yjlxList);
        map.put("yjlyList", yjlyList);
        map.put("pageIndex", (dto.getPageNum() - 1) * dto.getPageSize());
        map.put("pageSize", dto.getPageSize());
        IPage<TbYjxx> page = new Page<>(dto.getPageNum(), dto.getPageSize());
        int count = this.baseMapper.getCount(map);
        List<TbYjxx> list = this.baseMapper.getListPage(map);
        page.setTotal(count);
        page.setRecords(list);
        return page;
    }

    @Override
    public List<TbYjxx> getList(TbYjxxNoPageQuery dto) {
        if (com.mosty.common.base.util.StringUtils.isNotBlank(dto.getStartTime()) && dto.getStartTime().length() < 19) {
            dto.setStartTime(dto.getStartTime() + " 00:00:00");
        }
        if (com.mosty.common.base.util.StringUtils.isNotBlank(dto.getEndTime()) && dto.getEndTime().length() < 19) {
            dto.setEndTime(dto.getEndTime() + " 23:59:59");
        }


        dto.setSsbmdm(this.tbBaseAdaptRemoteService.getSsbm(dto.getSsbmdm(), null));
        Map<String, Object> map = new HashMap<>();
        map.put("dto", dto);
        List<String> yjlxList = new ArrayList<>();
        if (StringUtils.isNotBlank(dto.getYjLx())) {
            yjlxList = Arrays.asList(dto.getYjLx().split(","));
        }
        map.put("yjlxList", yjlxList);
        List<TbYjxx> list = this.baseMapper.getList(map);
        return list;
    }

    @Override
    public List<Map<String, Object>> getListHotMapEs(TbYjxxNoPageQuery dto) {
        if (StringUtils.isNotBlank(dto.getStartTime())) {
            dto.setStartTime(dto.getStartTime() + " 00:00:00");
        }
        if (StringUtils.isNotBlank(dto.getEndTime())) {
            dto.setEndTime(dto.getEndTime() + " 23:59:59");
        }
        dto.setSsbmdm(this.tbBaseAdaptRemoteService.getSsbm(dto.getSsbmdm(), null));
        List<Map<String, Object>> rList = new ArrayList<>();
        Map<String, Object> map = new HashMap<>();
        map.put("dto", dto);
        List<TbYjxx> list = this.baseMapper.getList(map);
        if (!CollectionUtils.isEmpty(list)) {
            list.forEach(item -> {
                Map<String, Object> mp = new HashMap<>();
                mp.put("lng", item.getJd());
                mp.put("lat", item.getWd());
                mp.put("count", 1);
                rList.add(mp);
            });
        }
        return rList;
    }

    @Override
    public List<Map<String, Object>> getListHotMap(TbYjxxNoPageQuery dto) {
        if (StringUtils.isNotBlank(dto.getStartTime())) {
            dto.setStartTime(dto.getStartTime() + " 00:00:00");
        }
        if (StringUtils.isNotBlank(dto.getEndTime())) {
            dto.setEndTime(dto.getEndTime() + " 23:59:59");
        }
        dto.setSsbmdm(this.tbBaseAdaptRemoteService.getSsbm(dto.getSsbmdm(), null));
        Map<String, Object> map = new HashMap<>();
        map.put("dto", dto);
//        UserInfo user = UserInfoManager.get();
//        String useSql = PermissionsUtil.createSql("", user);
//        map.put("useSql", useSql);
        List<TbYjxx> list = this.baseMapper.getList(map);
        List<Map<String, Object>> rList = new ArrayList<>();
        list.forEach(item -> {
            Map<String, Object> mp = new HashMap<>();
            mp.put("lng", item.getJd());
            mp.put("lat", item.getWd());
            mp.put("count", 1);
            rList.add(mp);
        });
        return rList;
    }

    @Override
    public TbYjxx getInfo(String id) {
        return this.baseMapper.getInfoById(id);
    }

    @Override
    public int insert(TbYjxx yjxx) {
        UserInfo user = UserInfoManager.get();
        if (user != null) {
            yjxx.setSsbm(user.getDeptName());
            yjxx.setSsbmid(String.valueOf(user.getDeptId()));
            yjxx.setSsbmdm(user.getDeptCode());
            yjxx.setSsxgaj(user.getFxjDeptName());
            yjxx.setSsxgajid(String.valueOf(user.getFxjDeptId()));
            yjxx.setSsxgajdm(user.getFxjDeptCode());
            yjxx.setSssgaj(user.getDszDeptName());
            yjxx.setSssgajid(String.valueOf(user.getDszDeptId()));
            yjxx.setSssgajdm(user.getDszDeptCode());
        }
        return this.baseMapper.insert(yjxx);
    }

    @Override
    public TbYjxx queryYjxx(TbYjxx yjxx) {
        try {
            QueryWrapper<TbYjxx> qw = new QueryWrapper<>();
//            UserInfo user = UserInfoManager.get();
//
//            PermissionsUtil.queryWrapperUtil(qw, user);

            yjxx.setSsbmdm(this.tbBaseAdaptRemoteService.getSsbm(yjxx.getSsbmdm(), null));

            List<TbYjxx> list = baseMapper.selectList(
                    qw.lambda()
                            .eq(StringUtils.isNotBlank(yjxx.getYjGzyid()), TbYjxx::getYjGzyid, yjxx.getYjGzyid())
                            .likeRight(StringUtils.isNotBlank(yjxx.getSsbmdm()), TbYjxx::getSsbmdm, yjxx.getSsbmdm())
                            .eq(yjxx.getYjSj() != null, TbYjxx::getYjSj, yjxx.getYjSj())
                            .eq(TbYjxx::getXtScbz, "0")
            );
            if (list != null && list.size() > 0) {
                return list.get(0);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public List<TbYjxxDTO> selectYjByNr(String yjNr) {
        TbYjxxNoPageQuery dto = new TbYjxxNoPageQuery();
        dto.setYjNr(yjNr);
        dto.setSsbmdm(this.tbBaseAdaptRemoteService.getSsbm(dto.getSsbmdm(), null));
        Map<String, Object> map = new HashMap<>();
        map.put("dto", dto);
//        UserInfo user = UserInfoManager.get();
//        String useSql = PermissionsUtil.createSql("", user);
//        map.put("useSql", useSql);
        List<TbYjxx> list = this.baseMapper.getList(map);
        List<TbYjxxDTO> rList = new ArrayList<>();
        list.forEach(item -> {
            TbYjxxDTO dto1 = new TbYjxxDTO();
            BeanUtils.copyProperties(item, dto1);
            rList.add(dto1);
        });
        return rList;
    }

    @Override
    public IPage<TbYjxx> selectTrack(TbYjxxYjgjQuery dto) {
        IPage<TbYjxx> page = new Page<>(dto.getPageCurrent(), dto.getPageSize());
        dto.setSsbmdm(this.tbBaseAdaptRemoteService.getSsbm(dto.getSsbmdm(), null));
        QueryWrapper<TbYjxx> qw = new QueryWrapper();
        return this.baseMapper.selectPage(
                page,
                qw.eq(StringUtils.isNotBlank(dto.getYjRysfzh()), "yj_rysfzh", dto.getYjRysfzh())
//                        .eq(StringUtils.isNotBlank(dto.getYjClcph()), "yj_clcph", dto.getYjClcph())
//                            .likeRight(StringUtils.isNotBlank(dto.getSsbmdm()), "ssbmdm", dto.getSsbmdm())
//                        .eq(StringUtils.isNotBlank(dto.getYjHplx()), "yj_hplx", dto.getYjHplx())
                        .orderByDesc("yj_sj")
        );


    }

    // 解析kafka推送的预警消息
    @Override
    @Transactional
    public void setYjxxByKafka(String message) {
        JSONObject json = JSONObject.parseObject(message);
        if (json.containsKey("type")) {
            if ("0".equals(json.getString("type"))) {// 预警人员
                parseYjry(json);
            } else if ("1".equals(json.getString("type"))) {// 预警车辆
                parseYjcl(json);
            }
        }
    }

    @Override
    public IPage<TbYjxx> getYjgj(VwSyrkJzgjGxListQuery dto) {
        String tempSfz = StringUtils.isNotBlank(dto.getZjhm()) ? (dto.getZjhm().substring(0, 6) + "********"
                + dto.getZjhm().substring(16)) : null;
        QueryWrapper<TbYjxx> qw = new QueryWrapper<>();
//        UserInfo user = UserInfoManager.get();
//        PermissionsUtil.queryWrapperUtil(qw, user);
        dto.setSsbmdm(this.tbBaseAdaptRemoteService.getSsbm(dto.getSsbmdm(), null));
        IPage<TbYjxx> page = this.baseMapper.selectPage(
                new Page<>(dto.getPageCurrent(), dto.getPageSize()),
                qw.lambda().eq(TbYjxx::getXtSjzt, "1")
                        .likeRight(StringUtils.isNotBlank(dto.getSsbmdm()), TbYjxx::getSsbmdm, dto.getSsbmdm())
                        .and((StringUtils.isNotBlank(tempSfz) && StringUtils.isNotBlank(dto.getZjhm())
                                        || StringUtils.isNotBlank(dto.getCph())),
                                it -> it.eq(TbYjxx::getYjRysfzh, dto.getZjhm()).or()
                                        .eq(TbYjxx::getYjRysfzh, tempSfz).or()
                                        .eq(TbYjxx::getYjClcph, dto.getCph())
                        )
                        .last(StringUtils.isNotBlank(dto.getKssj()) && StringUtils.isNotBlank(dto.getJssj()),
                                " and date_format(yj_fsrq,'%Y-%m-%d') between '" + dto.getKssj() + "' and '" + dto.getJssj() + "' order by yj_fssj desc"
                        )
                        .orderByDesc(StringUtils.isBlank(dto.getKssj()) && StringUtils.isNotBlank(dto.getJssj()), TbYjxx::getYjFssj)
        );
//        if (!CollectionUtils.isEmpty(page.getRecords())) {
//            page.getRecords().forEach(item -> {
//                item.setZb(null);
//            });
//        }
        return page;
    }

    @Override
    public List<Map<String, Object>> getYjxxTj(TbYjxxYjjbStatisticsQuery dto) {
        dto.setSsbmdm(this.tbBaseAdaptRemoteService.getSsbm(dto.getSsbmdm(), null));
        Map<String, Object> map = new HashMap<>();
//        UserInfo user = UserInfoManager.get();
//        map.put("useSql", PermissionsUtil.createSql("", user));
        map.put("dto", dto);
        return this.baseMapper.getYjxxTj(map);
    }

    @Override
    public Map<String, Object> getStatistics(TbYjxxStatisticsQuery dto) {
        String tempSfz = StringUtils.isNotBlank(dto.getYjRysfzh()) ? (dto.getYjRysfzh().substring(0, 6) +
                "********" + dto.getYjRysfzh().substring(16)) : null;
        Map<String, Object> map = new HashMap<>();
        String jssj = DateUtils.getQueryDateString(new Date(), "01");
        String kssj = DateUtils.getQueryDateString(new Date(), "01");
//        UserInfo user = UserInfoManager.get();
//        PermissionsUtil.queryWrapperUtil(qw, user);
        dto.setSsbmdm(this.tbBaseAdaptRemoteService.getSsbm(dto.getSsbmdm(), null));
        QueryWrapper<TbYjxx> qw = new QueryWrapper<>();
        map.put("today", this.baseMapper.selectCount(
                qw.lambda().eq(TbYjxx::getXtSjzt, "1")
                        .likeRight(StringUtils.isNotBlank(dto.getSsbmdm()), TbYjxx::getSsbmdm, dto.getSsbmdm())

                        .and((StringUtils.isNotBlank(tempSfz) && StringUtils.isNotBlank(dto.getYjRysfzh())
                                        || StringUtils.isNotBlank(dto.getYjClcph())),
                                it -> it.eq(TbYjxx::getYjRysfzh, dto.getYjRysfzh()).or()
                                        .eq(TbYjxx::getYjRysfzh, tempSfz).or()
                                        .eq(StringUtils.isNotBlank(dto.getYjClcph()), TbYjxx::getYjClcph, dto.getYjClcph())
                        )
                        .last(" and date_format(yj_fsrq,'%Y-%m-%d') between '" + kssj + "' and '" + jssj + "'")
        ));
        kssj = DateUtils.getQueryDateString(DateUtils.getNextDate(new Date(), "D", -7), "01");
        qw = new QueryWrapper<>();
//        PermissionsUtil.queryWrapperUtil(qw, user);
        map.put("data7", this.baseMapper.selectCount(
                qw.lambda().eq(TbYjxx::getXtSjzt, "1")
                        .likeRight(StringUtils.isNotBlank(dto.getSsbmdm()), TbYjxx::getSsbmdm, dto.getSsbmdm())
                        .and((StringUtils.isNotBlank(tempSfz) && StringUtils.isNotBlank(dto.getYjRysfzh())
                                        || StringUtils.isNotBlank(dto.getYjClcph())),
                                it -> it.eq(TbYjxx::getYjRysfzh, dto.getYjRysfzh()).or()
                                        .eq(TbYjxx::getYjRysfzh, tempSfz).or()
                                        .eq(StringUtils.isNotBlank(dto.getYjClcph()), TbYjxx::getYjClcph, dto.getYjClcph())
                        )
                        .last(" and date_format(yj_fsrq,'%Y-%m-%d') between '" + kssj + "' and '" + jssj + "'")
        ));
        kssj = DateUtils.getQueryDateString(DateUtils.getNextDate(new Date(), "M", -1), "01");
        qw = new QueryWrapper<>();
//        PermissionsUtil.queryWrapperUtil(qw, user);
        map.put("data30", this.baseMapper.selectCount(
                qw.lambda().eq(TbYjxx::getXtSjzt, "1")
                        .likeRight(StringUtils.isNotBlank(dto.getSsbmdm()), TbYjxx::getSsbmdm, dto.getSsbmdm())
                        .and((StringUtils.isNotBlank(tempSfz) && StringUtils.isNotBlank(dto.getYjRysfzh())
                                        || StringUtils.isNotBlank(dto.getYjClcph())),
                                it -> it.eq(TbYjxx::getYjRysfzh, dto.getYjRysfzh()).or()
                                        .eq(TbYjxx::getYjRysfzh, tempSfz).or()
                                        .eq(StringUtils.isNotBlank(dto.getYjClcph()), TbYjxx::getYjClcph, dto.getYjClcph())
                        )
                        .last(" and date_format(yj_fsrq,'%Y-%m-%d') between '" + kssj + "' and '" + jssj + "'")
        ));
        qw = new QueryWrapper<>();
//        PermissionsUtil.queryWrapperUtil(qw, user);
        map.put("all", this.baseMapper.selectCount(
                qw.lambda().eq(TbYjxx::getXtSjzt, "1")
                        .likeRight(StringUtils.isNotBlank(dto.getSsbmdm()), TbYjxx::getSsbmdm, dto.getSsbmdm())
                        .and((StringUtils.isNotBlank(tempSfz) && StringUtils.isNotBlank(dto.getYjRysfzh())
                                        || StringUtils.isNotBlank(dto.getYjClcph())),
                                it -> it.eq(TbYjxx::getYjRysfzh, dto.getYjRysfzh()).or()
                                        .eq(TbYjxx::getYjRysfzh, tempSfz).or()
                                        .eq(StringUtils.isNotBlank(dto.getYjClcph()), TbYjxx::getYjClcph, dto.getYjClcph())
                        )
        ));
        return map;
    }

    @Override
    public List<Map<String, Object>> getYjxxTjYjlx(String kssj, String jssj) {
        UserInfo user = UserInfoManager.get();

        return this.baseMapper.getYjxxTjYjlx(kssj, jssj, this.tbBaseAdaptRemoteService.getSsbm(null, null));
    }

    @Override
    public Object gsdyj(String type) {
//        UserInfo user = UserInfoManager.get();
//        String useSql = PermissionsUtil.createSql("", user);
        String ssbm = this.tbBaseAdaptRemoteService.getSsbm(null, null);
        List<String> timeList = new ArrayList<>();
        List<Map<String, Object>> dataList = new ArrayList<>();
        if ("1".equals(type)) {
            return this.baseMapper.todayGsdyj(null);
        } else if ("2".equals(type)) {
            for (int i = 0; i < 8; i++) {
                timeList.add(DateUtils.getQueryDateString(DateUtils.getNextDate(new Date(), "D", -i), "02"));
            }
        } else if ("3".equals(type)) {
            for (int i = 0; i < 7; i++) {
                timeList.add(DateUtils.getQueryDateString(DateUtils.getNextDate(new Date(), "D", -i * 6), "02"));
            }
        } else if ("4".equals(type)) {
            for (int i = 0; i < 8; i++) {
                timeList.add(DateUtils.getQueryDateString(DateUtils.getNextDate(new Date(), "D", -i * 9), "02"));
            }
        }
        Collections.reverse(timeList);
        for (int i = 0; i < timeList.size() - 1; i++) {
            Map<String, Object> mp = new HashMap<>();
            mp.put("h", DateUtils.getQueryDateString(DateUtils.strToDate(timeList.get(i), "02"), "18"));
            mp.put("type", "1");
            QueryWrapper<TbYjxx> qw = new QueryWrapper<>();
//            PermissionsUtil.queryWrapperUtil(qw, user);
            mp.put("total", this.baseMapper.selectCount(
                    qw.lambda().eq(TbYjxx::getXtSjzt, "1")
                            .in(TbYjxx::getYjLx, "1", "3", "4")
                            .likeRight(StringUtils.isNotBlank(ssbm), TbYjxx::getSsbmdm, ssbm)
                            .last(" and yj_fsrq between '" +
                                    timeList.get(i) + "' and '" + timeList.get(i + 1) + "'")
            ));
            dataList.add(mp);
            mp = new HashMap<>();
            mp.put("h", DateUtils.getQueryDateString(DateUtils.strToDate(timeList.get(i), "02"), "18"));
            mp.put("type", "2");
            qw = new QueryWrapper<>();
//            PermissionsUtil.queryWrapperUtil(qw, user);
            mp.put("total", this.baseMapper.selectCount(
                    qw.lambda().eq(TbYjxx::getXtSjzt, "1")
                            .in(TbYjxx::getYjLx, "2", "4")
                            .likeRight(StringUtils.isNotBlank(ssbm), TbYjxx::getSsbmdm, ssbm)
                            .last(" and yj_fsrq between '" +
                                    timeList.get(i) + "' and '" + timeList.get(i + 1) + "'")
            ));
            dataList.add(mp);
            mp = new HashMap<>();
            mp.put("h", DateUtils.getQueryDateString(DateUtils.strToDate(timeList.get(i), "02"), "18"));
            mp.put("type", "3");
            qw = new QueryWrapper<>();
//            PermissionsUtil.queryWrapperUtil(qw, user);
            mp.put("total", this.baseMapper.selectCount(
                    qw.lambda().eq(TbYjxx::getXtSjzt, "1")
                            .eq(TbYjxx::getYjLx, "5")
                            .likeRight(StringUtils.isNotBlank(ssbm), TbYjxx::getSsbmdm, ssbm)
                            .last(" and yj_fsrq between '" +
                                    timeList.get(i) + "' and '" + timeList.get(i + 1) + "'")
            ));
            dataList.add(mp);
        }
        return dataList;
    }

    @Override
    @Transactional
    public void yjConvertZl(YjConvertZlDto dto) {
        TbYjxx yjxx = this.tbYjxxMapper.selectById(dto.getYjid());
        if (yjxx == null) {
            throw new BusinessException("未查询到预警信息");
        }
        if ("1".equals(yjxx.getYjLx()) || "3".equals(yjxx.getYjLx()) ||
                "4".equals(yjxx.getYjLx()) || "6".equals(yjxx.getYjLx())) {
            this.convertZl(yjxx, "02", dto.getZxrList());
        } else if ("5".equals(yjxx.getYjLx())) {
            this.convertZl(yjxx, "04", dto.getZxrList());
        } else if ("2".equals(yjxx.getYjLx())) {
            this.convertZl(yjxx, "03", dto.getZxrList());
        }
        yjxx.setSfFszl("1");
        yjxx.setBz("已手动转为指令");
        this.tbYjxxMapper.updateById(yjxx);
    }

    @Override
    public TbYjxx getLastYj(GetLastYjDto dto) {
        TbYjxx yj = this.baseMapper.selectOne(
                new LambdaQueryWrapper<TbYjxx>()
                        .eq(StringUtils.isNotBlank(dto.getYjlyid()), TbYjxx::getYjlyid, dto.getYjlyid())
                        .orderByDesc(TbYjxx::getYjSj)
                        .last(" limit 1")
        );
//        if (yj != null) yj.setZb(null);
        return yj;
    }

    @Override
    public void updateYjxxSffszl(String id) {
        TbYjxx yjxx = this.baseMapper.selectById(id);
        if (yjxx != null && "0".equals(yjxx.getSfFszl())) {
            yjxx.setSfFszl("0");
            this.baseMapper.updateEntity(yjxx);
        }
    }

    @Override
    public List<TbYjxx> getYjxx30Day(TbYjxxQuery dto) {
        return this.baseMapper.selectList(
                new LambdaQueryWrapper<TbYjxx>()
                        .ge(StringUtils.isNotBlank(dto.getStartTime()), TbYjxx::getYjFsrq, dto.getStartTime())
                        .le(StringUtils.isNotBlank(dto.getEndTime()), TbYjxx::getYjFsrq, dto.getEndTime())
                        .last("  and jd is not null and wd is not null and yjbqmc is not null")
        );
    }


    // 预警转指令
    private void convertZl(TbYjxx yjxx, String zllx, List<TbZlxxZxrDtoInsertDto> zxrList) {
        TbZlxxInsertDto zl = new TbZlxxInsertDto();
        zl.setId(UUIDGenerator.getUUID()).setYwId(yjxx.getId()).setZllx(zllx).setZlly(zllx).setZlzxlx("1")
                .setZlbt(yjxx.getYjBt()).setZlnr(yjxx.getYjNr())
                .setZldj(yjxx.getYjJb()).setJd(yjxx.getJd()).setWd(yjxx.getWd()).setZlfsddxzqh(yjxx.getYjDzXzqh())
                .setZlfsdd(yjxx.getYjDz()).setZltp(yjxx.getYjTp()).setSsbmid(yjxx.getSsbmid());
        zl.setZxrDtoList(zxrList);
        this.tbZlxxService.addZl(zl);
    }

    // 获取预警信息
    public TbYjxx getClYjxx(JSONObject obj, String yjlx) {
        JSONObject person = obj.getJSONObject("person");
        TbYjxx oldYjxx = this.baseMapper.queryTbYjxx(obj.getString("warningId"));
        if (oldYjxx != null) {
            return null;
        }
        String srcIndex = obj.getString("srcIndex");
        // String srcIndex = "51010944001320188550";
        TbYjxx yjxx = new TbYjxx();
        yjxx.setYjLx(yjlx);
        //预警时间(预警推送时间)
        String alertTime = obj.getString("date");
        Date captureTime = DateUtils.strToDate(alertTime, "02");
        //预警发生时间
        String waringTime = obj.getString("warningStartTime");
        Date yjfssj = DateUtils.strToDate(waringTime, "02");
        String yjFsnf = waringTime.substring(0, 4);
        String yjfsyf = waringTime.substring(5, 7);
        String yjFsxs = waringTime.substring(11, 13);
        String yjFsny = yjFsnf + yjfsyf;
        Calendar ca = Calendar.getInstance();//创建一个日期实例
        ca.setTime(yjfssj);//实例化一个日期
        Integer yjfszs = ca.get(Calendar.WEEK_OF_YEAR);
        yjxx.setId(UUIDGenerator.getUUID());
        yjxx.setYjGzyid(srcIndex);
        yjxx.setYjGzymc("");
        TbYsSxtDto sxt = this.tbYszxAdaptRemoteService.getInfoBySbbh(srcIndex);
        if (sxt != null) {
            yjxx.setYjGzyid(sxt.getSbbh());
            yjxx.setYjGzymc(sxt.getSbmc());
            yjxx.setYjDzXzqh(sxt.getXzqhdm());
            yjxx.setSsbm(sxt.getSsbm());
            yjxx.setSsbmid(sxt.getSsbmid());
            yjxx.setSsbmdm(sxt.getSsbmdm());
        }
        yjxx.setYjFsnf(Integer.valueOf(yjFsnf));
        yjxx.setYjFsyf(Integer.valueOf(yjfsyf));
        yjxx.setYjFsny(Integer.valueOf(yjFsny));
        yjxx.setYjFszs(yjfszs);
        yjxx.setYjFsxs(Integer.valueOf(yjFsxs));
        yjxx.setYjFsrq(yjfssj);
        yjxx.setYjFssj(yjfssj);
        yjxx.setYjSj(captureTime);
        yjxx.setYjJb("40");
        yjxx.setYjlyid(obj.getString("warningId"));
        String yjbt = "车辆(" + obj.getString("carNumber") + ")预警";
        String yjnr = "(" + obj.getString("carNumber") + ")于" + waringTime
                + "在经过感知源《" + (StringUtils.isBlank(yjxx.getYjGzymc()) ? "未知感知源" : yjxx.getYjGzymc()) +
                "》位置时发生预警！！";
        yjxx.setYjBt(yjbt);
        yjxx.setYjNr(yjnr);
        if (StringUtils.isNotBlank(obj.getString("lng"))) {
            yjxx.setJd(new BigDecimal(obj.getString("lng")));
        }
        if (StringUtils.isNotBlank(obj.getString("lat"))) {
            yjxx.setWd(new BigDecimal(obj.getString("lat")));
        }
//        if (yjxx.getJd() != null && yjxx.getWd() != null) {
//            // 计算hash值和经纬度坐标
//            yjxx.setZb(JtsUtils.getPoint(yjxx.getJd(), yjxx.getWd()));
//            yjxx.setZbhash(GeoHashKit.encode(yjxx.getJd(), yjxx.getWd()));
//        }

        yjxx.setYjClcph(obj.getString("carNumber"));
        yjxx.setYjTp(obj.getString("img"));
        yjxx.setYjXtp(obj.getString("compareImg"));
        String yjjb = getYjjb(person.getString("levelName"));
        yjxx.setYjJb(yjjb);
        int yjcs = this.baseMapper.countBySfzhOrCph(null, yjxx.getYjClcph());
        int yjjrcs = this.baseMapper.countCurrentBySfzhOrCph(null, yjxx.getYjClcph());
        yjcs = yjcs + 1;
        yjjrcs = yjjrcs + 1;
        yjxx.setYjCs(yjcs);
        yjxx.setYjJrcs(yjjrcs);
        yjxx.setYjDzXzqh("511421");
        yjxx.setSsxgaj("仁寿县公安局");
        yjxx.setSsxgajid("7");
        yjxx.setSsxgajdm("511421000000");
        yjxx.setSssgaj("眉山市公安局");
        yjxx.setSssgajdm("511400000000");
        yjxx.setSssgajid("2");
        yjxx.setXtSjly("1");
        yjxx.setSfFszl("0");
        return yjxx;
    }

    // 获取预警级别
    public String getYjjb(String yjjb) {
        if (StringUtils.isBlank(yjjb)) {
            return "";
        }
        switch (yjjb) {
            case "一级":
            case "红":
                return "10";
            case "二级":
            case "橙":
                return "20";
            case "三级":
            case "黄":
                return "30";
            default:
                return "40";
        }
    }

    // 解析预警车辆
    public void parseYjcl(JSONObject yjcl) {
        TbYjxx yjxx = getClYjxx(yjcl, "2");
        if (yjxx != null) {
            getYjxxCl(yjxx, yjcl);
            createZl(yjxx, "03");
        }
        this.baseMapper.insertEntity(yjxx);
    }

    // 获取车辆信息
    public void getYjxxCl(TbYjxx yjxx, JSONObject obj) {
        JSONObject person = obj.getJSONObject("person");
        TbYjxxCl clxx = new TbYjxxCl();
        clxx.setId(UUIDGenerator.getUUID());
        clxx.setYjId(yjxx.getId());
        clxx.setYjClbq(yjxx.getYjbq());
        clxx.setYjFssj(yjxx.getYjFssj());
        clxx.setYjSj(yjxx.getYjSj());
        clxx.setYjJb(yjxx.getYjJb());
        clxx.setYjBt(yjxx.getYjBt());
        clxx.setYjNr(yjxx.getYjNr());
        clxx.setYjClcph(yjxx.getYjClcph());
        clxx.setClCxsj(yjxx.getYjFssj());
        clxx.setYjGzyid(yjxx.getYjGzyid());
        clxx.setYjDz(yjxx.getYjDz());
        clxx.setTpId(yjxx.getYjXtp());
        clxx.setYjDzXzqh(yjxx.getYjDzXzqh());
        if (person != null) {
            clxx.setYjCljdcsyrhm(person.getString("idcard"));
            clxx.setYjCljdcsyr(person.getString("name"));
        }
        if (yjxx.getJd() != null) {
            clxx.setJd(yjxx.getJd());
        }
        if (yjxx.getWd() != null) {
            clxx.setWd(yjxx.getWd());
        }
//        if (clxx.getJd() != null && clxx.getWd() != null) {
//            clxx.setZbhash(yjxx.getZbhash());
//            clxx.setZb(yjxx.getZb());
//        }
        clxx.setSsbm(yjxx.getSsbm());
        clxx.setSsbmid(yjxx.getSsbmid());
        clxx.setSsbmdm(yjxx.getSsbmdm());
        clxx.setSsxgaj(yjxx.getSsxgaj());
        clxx.setSsxgajid(yjxx.getSsxgajid());
        clxx.setSsxgajdm(yjxx.getSsxgajdm());
        clxx.setSssgaj(yjxx.getSssgaj());
        clxx.setSssgajid(yjxx.getSssgajid());
        clxx.setSssgajdm(yjxx.getSssgajdm());
        clxx.setXtSjly("1");
        this.tbYjxxClMapper.insertEntity(clxx);
        saveTbYjxxClBq(clxx, obj);
    }

    // 保存车辆预警标签
    public void saveTbYjxxClBq(TbYjxxCl clxx, JSONObject obj) {
        JSONArray array = obj.getJSONArray("waring_tag");
        if (array != null) {
            for (int i = 0; i < array.size(); i++) {
                JSONObject json = array.getJSONObject(i);
                TbYjxxClBq clbq = new TbYjxxClBq();
                clbq.setId(UUIDGenerator.getUUID());
                clbq.setYjclId(clxx.getId());
                String bq = json.getString("text");
                clbq.setClbqdm(getYjclbqdm(bq));
                clbq.setXtSjly("1");
                this.tbYjxxClBqMapper.insert(clbq);
            }
        }
    }

    // 获取标签代码
    public static String getYjclbqdm(String bqmc) {
        if (bqmc.contains("临控")) {
            return "1";
        } else if (bqmc.contains("抢盗")) {
            return "2";
        } else if (bqmc.contains("套牌")) {
            return "3";
        } else if (bqmc.contains("假牌")) {
            return "4";
        }
        return "";
    }

    // 解析预警人员
    public void parseYjry(JSONObject yjry) {
        TbYjxx yjxx = getYjxxRy(yjry, "1");
        if (yjxx != null) {
            saveYjxxRy(yjxx, yjry);
            createZl(yjxx, "02");
        }
        this.baseMapper.insertEntity(yjxx);
    }

    // 创建指令
    public void createZl(TbYjxx yjxx, String zllx) {
        try {
            // 查询500米范围内的最近的巡组信息
            TbQwXfbbQueryByJlDto queryByJlDto = new TbQwXfbbQueryByJlDto();
            queryByJlDto.setJd(yjxx.getJd());
            queryByJlDto.setWd(yjxx.getWd());
            queryByJlDto.setRadius(new BigDecimal("500"));
            TbQwXfbb xfbb = this.tbQwzxAdaptRemoteService.getBbxxByJi(queryByJlDto);
            TbYsSxtDto sxt = this.tbYszxAdaptRemoteService.getInfoBySbbh(yjxx.getYjGzyid());
            // 新增
            TbZlxxInsertDto zl = new TbZlxxInsertDto();
            zl.setId(UUIDGenerator.getUUID()).setYwId(yjxx.getId()).setZllx(zllx).setZlly(zllx).setZlzxlx("1")
                    .setZlbt(yjxx.getYjBt() + "，请协助核查！！").setZlnr(yjxx.getYjNr() + "，请协助核查！！")
                    .setZldj(yjxx.getYjJb()).setJd(yjxx.getJd()).setWd(yjxx.getWd()).setZlfsddxzqh(yjxx.getYjDzXzqh())
                    .setZlfsdd(yjxx.getYjDz()).setZltp(yjxx.getYjTp());
            if (xfbb != null) {
                zl.setZljsdx("03");
                zl.setSsbmid(xfbb.getSsbmid());
                List<TbZlxxZxrDtoInsertDto> zxrDtoList = new ArrayList<>();
                TbZlxxZxrDtoInsertDto zxr = new TbZlxxZxrDtoInsertDto();
                zxr.setZlId(zl.getId()).setZxrLx("03").setZxrJllx(xfbb.getId()).setZxrXzid(xfbb.getId());
                zxrDtoList.add(zxr);
                yjxx.setBz("范围内500米查询到巡组《" + xfbb.getJzMc() + "》，已下发");
                zl.setZxrDtoList(zxrDtoList);
                this.tbZlxxService.addZl(zl);
                yjxx.setSfFszl("1");
            } else if (sxt != null && StringUtils.isNotBlank(sxt.getSsbmid())) {
                zl.setZljsdx("02");
                zl.setSsbmid(sxt.getSsbmid());
                List<TbZlxxZxrDtoInsertDto> zxrDtoList = new ArrayList<>();
                TbZlxxZxrDtoInsertDto zxr = new TbZlxxZxrDtoInsertDto();
                zxr.setZlId(zl.getId()).setZxrLx("02").setSsbmid(sxt.getSsbmid());
                zxrDtoList.add(zxr);
                zl.setZxrDtoList(zxrDtoList);
                this.tbZlxxService.addZl(zl);
                yjxx.setSfFszl("1");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    // 保存预警人员信息
    public void saveYjxxRy(TbYjxx yjxx, JSONObject obj) {
        TbYjxxRy ryxx = new TbYjxxRy();
        ryxx.setId(UUIDGenerator.getUUID());
        ryxx.setYjId(yjxx.getId());
        ryxx.setYjClid("");
        ryxx.setYjGzyid(yjxx.getYjGzyid());
        ryxx.setYjGzymc(yjxx.getYjGzymc());
        ryxx.setYjFssj(yjxx.getYjFssj());
        ryxx.setYjSj(yjxx.getYjSj());
        ryxx.setYjJb(yjxx.getYjJb());
        ryxx.setYjBt(yjxx.getYjBt());
        ryxx.setYjNr(yjxx.getYjNr());
        ryxx.setYjDzxzqh(yjxx.getYjDzXzqh());
        ryxx.setYjlyBqmc(yjxx.getYjlyBqmc());
        ryxx.setYjZjlx("1");
        ryxx.setYjZjhm(yjxx.getYjRysfzh());
        ryxx.setYjRyxm(yjxx.getYjRyxm());
        ryxx.setYjRyxb(IDCardUtil.getSex(yjxx.getYjRysfzh()));
        ryxx.setYjRynl(IDCardUtil.getAge(yjxx.getYjRysfzh()));
        ryxx.setYjRymz("");
        ryxx.setYjRyjg(yjxx.getYjDzXzqh());
        ryxx.setYjRyhjdXzqh(yjxx.getYjDzXzqh());
        ryxx.setYjRyhjd("");
        String similarity = obj.getString("similarity");
        if (StringUtils.isNotBlank(similarity)) {
            ryxx.setYjXsd(new BigDecimal(similarity));
        }
        ryxx.setYjDz(yjxx.getYjDz());
        ryxx.setJd(yjxx.getJd());
        ryxx.setWd(yjxx.getWd());
//        if (ryxx.getJd() != null && ryxx.getWd() != null) {
//            ryxx.setZb(yjxx.getZb());
//            ryxx.setZbhash(yjxx.getZbhash());
//        }

        ryxx.setCoverImage(obj.getString("img"));
        ryxx.setYjRybq(yjxx.getYjbq());
        ryxx.setYjRybqmc(yjxx.getYjbqmc());
        ryxx.setSsbm(yjxx.getSsbm());
        ryxx.setSsbmid(yjxx.getSsbmid());
        ryxx.setSsbmdm(yjxx.getSsbmdm());
        ryxx.setSsxgaj(yjxx.getSsxgaj());
        ryxx.setSsxgajid(yjxx.getSsxgajid());
        ryxx.setSsxgajdm(yjxx.getSsxgajdm());
        ryxx.setSssgaj(yjxx.getSssgaj());
        ryxx.setSssgajid(yjxx.getSssgajid());
        ryxx.setSssgajdm(yjxx.getSssgajdm());
        ryxx.setXtSjly("1");
        this.tbYjxxRyMapper.insertEntity(ryxx);
        saveTbYjxxRyBq(ryxx, obj);
    }

    // 保存预警人员标签
    public void saveTbYjxxRyBq(TbYjxxRy ryxx, JSONObject obj) {
        JSONObject person = obj.getJSONObject("person");
        JSONArray tags = person.getJSONArray("tag");
        if (tags != null && tags.size() > 0) {
            for (int i = 0; i < tags.size(); i++) {
                TbYjxxRyBq rybq = new TbYjxxRyBq();
                rybq.setId(UUIDGenerator.getUUID());
                rybq.setYjryId(ryxx.getId());
                rybq.setRybqmc(tags.getJSONObject(i).getString("tagName"));
                rybq.setRybqdm(this.getRybqdm(tags.getJSONObject(i).getString("tagName")));
                rybq.setXtSjly("1");
                this.tbYjxxRyBqMapper.insert(rybq);
            }
        }
    }

    private String getRybqdm(String tagName) {
        String bqdm = "";
        switch (tagName) {
            case "涉毒":
                bqdm = "3";
                break;
            case "涉稳人员":
                bqdm = "8";
                break;
            case "重点上访":
                bqdm = "7";
                break;
            case "精神病人":
                bqdm = "5";
                break;
            case "重型罪前科":
                bqdm = "4";
                break;
            case "在逃":
                bqdm = "2";
                break;
            case "涉恐":
                bqdm = "6";
                break;
            default:
                bqdm = "9";
                break;
        }
        return bqdm;
    }

    // 获取人员标签名称
    public String getRybqmc(JSONArray array) {
        StringBuilder clbq = new StringBuilder();
        if (array != null && array.size() > 0) {
            for (int i = 0; i < array.size(); i++) {
                JSONObject json = array.getJSONObject(i);
                String bq = json.getString("tagName");
                clbq.append(bq).append(",");
            }
        }
        if (clbq.length() > 0) {
            clbq = new StringBuilder(clbq.substring(0, clbq.length() - 1));
        }
        return clbq.toString();
    }

    // 获取人员标签名称
    public String getRybq(JSONArray array) {
        StringBuilder bq = new StringBuilder();
        if (array != null && array.size() > 0) {
            for (int i = 0; i < array.size(); i++) {
                JSONObject json = array.getJSONObject(i);
                String bqmc = json.getString("tagName");
                switch (bqmc) {
                    case "涉毒":
                        bq.append("3,");
                        break;
                    case "涉稳人员":
                        bq.append("8,");
                        break;
                    case "重点上访":
                        bq.append("7,");
                        break;
                    case "精神病人":
                        bq.append("5,");
                        break;
                    case "重型罪前科":
                        bq.append("4,");
                        break;
                    case "在逃":
                        bq.append("2,");
                        break;
                    case "涉恐":
                        bq.append("6,");
                        break;
                    default:
                        bq.append("9,");
                }
            }
        }
        if (bq.length() > 0) {
            bq = new StringBuilder(bq.substring(0, bq.length() - 1));
        }
        return bq.toString();
    }


    // 获取人员预警信息
    public TbYjxx getYjxxRy(JSONObject obj, String yjlx) {
        JSONObject person = obj.getJSONObject("person");
        TbYjxx oldYjxx = this.baseMapper.queryTbYjxx(obj.getString("warningId"));
        if (oldYjxx != null) {
            return null;
        }
        JSONArray tags = person.getJSONArray("tag");
        String yjbqmc = getRybqmc(tags);
        String yjbq = getRybq(tags);
        String srcIndex = obj.getString("srcIndex");
        // String srcIndex = "51010944001320188550";
        TbYjxx yjxx = new TbYjxx();
        yjxx.setYjLx(yjlx);
        yjxx.setYjLylx("01");
        //预警时间(预警推送时间)
        String alertTime = dateConvert(obj.getString("date"));
        Date captureTime = DateUtils.strToDate(alertTime, "02");
        // 预警发生时间
        String waringTime = dateConvert(obj.getString("warningStartTime"));
        if (StringUtils.isNotBlank(waringTime)) {
            Date yjfssj = DateUtils.strToDate(waringTime, "02");
            String yjFsnf = waringTime.substring(0, 4);
            String yjfsyf = waringTime.substring(5, 7);
            String yjFsxs = waringTime.substring(11, 13);
            String yjFsny = yjFsnf + yjfsyf;
            Calendar ca = Calendar.getInstance();//创建一个日期实例
            ca.setTime(yjfssj);//实例化一个日期
            int yjfszs = ca.get(Calendar.WEEK_OF_YEAR);
            yjxx.setYjFsnf(Integer.valueOf(yjFsnf));
            yjxx.setYjFsyf(Integer.valueOf(yjfsyf));
            yjxx.setYjFsny(Integer.valueOf(yjFsny));
            yjxx.setYjFszs(yjfszs);
            yjxx.setYjFsxs(Integer.valueOf(yjFsxs));
            yjxx.setYjFsrq(yjfssj);
            yjxx.setYjFssj(yjfssj);
        }
        yjxx.setId(UUIDGenerator.getUUID());
        yjxx.setYjGzyid(srcIndex);
        yjxx.setYjGzymc("");
        TbYsSxtDto sxt = this.tbYszxAdaptRemoteService.getInfoBySbbh(srcIndex);
        if (sxt != null) {
            yjxx.setYjGzyid(sxt.getSbbh());
            yjxx.setYjGzymc(sxt.getSbmc());
            yjxx.setYjDzXzqh(sxt.getXzqhdm());
            yjxx.setSsbm(sxt.getSsbm());
            yjxx.setSsbmdm(sxt.getSsbmdm());
            yjxx.setSsbmid(sxt.getSsbmid());
        }
        yjxx.setYjSj(captureTime);
        yjxx.setYjlyid(obj.getString("warningId"));
        if (StringUtils.isNotBlank(person.getString("zdrybkdj"))) {
            yjxx.setYjJb(person.getString("zdrybkdj") + "0");
        }
        String yjbt = yjbqmc + person.getString("name") + "(" + person.getString("idcard") + ")";
        String yjnr = yjbqmc + person.getString("name") + "(" + person.getString("idcard") + ")于" + waringTime
                + "在经过感知源《" + (StringUtils.isBlank(yjxx.getYjGzymc()) ? "未知感知源" : yjxx.getYjGzymc()) +
                "》位置时发生预警！！";
        yjxx.setYjBt(yjbt);
        yjxx.setYjNr(yjnr);
        if (StringUtils.isNotBlank(obj.getString("lng"))) {
            yjxx.setJd(new BigDecimal(obj.getString("lng")));
        }
        if (StringUtils.isNotBlank(obj.getString("lat"))) {
            yjxx.setWd(new BigDecimal(obj.getString("lat")));
        }
        if (person.containsKey("address")) {
            yjxx.setYjDz(person.getString("address"));
        }
        yjxx.setYjRyxm(person.getString("name"));
        yjxx.setYjRysfzh(person.getString("idcard"));
        yjxx.setYjbq(yjbq);
        yjxx.setYjbqmc(yjbqmc);
        yjxx.setYjlyBqmc("");
        yjxx.setYjTp(obj.getString("img"));
        yjxx.setYjXtp(obj.getString("compareImg"));
        String yjjb = getYjjb(person.getString("levelName"));
        yjxx.setYjJb(yjjb);
        int yjcs = this.baseMapper.countBySfzhOrCph(yjxx.getYjRysfzh(), null);
        int yjjrcs = this.baseMapper.countCurrentBySfzhOrCph(yjxx.getYjRysfzh(), null);
        yjcs = yjcs + 1;
        yjjrcs = yjjrcs + 1;
        yjxx.setYjCs(yjcs);
        yjxx.setYjJrcs(yjjrcs);
        yjxx.setYjDzXzqh("511421");
        yjxx.setSsxgaj("仁寿县公安局");
        yjxx.setSsxgajid("7");
        yjxx.setSsxgajdm("511421000000");
        yjxx.setSssgaj("眉山市公安局");
        yjxx.setSssgajdm("511400000000");
        yjxx.setSssgajid("2");
        yjxx.setXtCjsj(new Timestamp(System.currentTimeMillis()));
        yjxx.setXtZhgxsj(new Timestamp(System.currentTimeMillis()));
        yjxx.setXtScbz("0");
        yjxx.setXtSjzt("1");
        yjxx.setXtSjly("1");
        yjxx.setSfFszl("0");
        // 添加人员预警信息
        return yjxx;
    }

    // 日期格式化
    public String dateConvert(String dates) {
        try {
            if (dates.contains("T")) {
                if (dates.contains(".")) {
                    String[] strs = dates.split("\\.");
                    String sq = strs[1];
                    String[] times = sq.split("\\+");
                    dates = strs[0] + "+" + times[1];
                }
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
                Date date = sd.parse(dates);
                return sdf.format(date);
            }
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return dates;
    }

}

