package com.zjrs.ggfw.portal.bpo.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.yinhai.bcpcs.exceptions.ClientException;
import jakarta.annotation.Resource;
import org.mohrss.leaf.core.framework.context.Consts;
import org.mohrss.leaf.core.framework.domain.bpo.impl.BPOImpl;
import org.mohrss.leaf.core.framework.persistens.PageResult;
import org.mohrss.leaf.core.framework.util.CurrentUser;
import org.mohrss.leaf.core.framework.util.SecurityUtils;
import org.mohrss.leaf.core.framework.web.controller.AjaxResponse;
import com.zjrs.ggfw.config.CaptchaAutoConfiguration;
import com.zjrs.ggfw.portal.blo.UserBLO;
import com.zjrs.ggfw.portal.bpo.UserBPO;
import com.zjrs.ggfw.portal.dto.*;
import com.zjrs.ggfw.portal.dto.common.PageDTO;
import com.zjrs.ggfw.portal.entity.SendSmsMapper;
import com.zjrs.ggfw.portal.po.*;
import com.zjrs.ggfw.sggfw.bpo.QueryBusinessBPO;
import com.zjrs.ggfw.sggfw.dto.TywtGrjbxxGgcx01DTO;
import com.zjrs.ggfw.utils.GgfwSpringContextUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Service;

import javax.imageio.ImageIO;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;

@Service
public class UserBPOImpl extends BPOImpl implements UserBPO {

    private static final Logger LOG = LoggerFactory.getLogger(UserBPOImpl.class);

    private static final String IMGCACHENAME="ggfw-imgkaptcha";
    private static final String PHONECACHENAME="ggfw-phonekaptcha";

    @Resource
    private UserBLO userBLO;

    @Resource
    private QueryBusinessBPO queryBusinessBPO;

    @Autowired
    private CacheManager leafCacheManager;

    @Autowired
    private HttpServletResponse response;

    @Autowired
    private SendSmsMapper sendSmsMapper;


    @Override
    public PageResult getSjdzList(SjdzQueryDTO dto) {
        CurrentUser cUser = SecurityUtils.getCurrentUser();//获取当前用户
        dto.setYhid(cUser.getUsername());
        return userBLO.getSjdzList(dto);
    }

    @Override
    public VRsWbSjdz getSjdzDetail(SjdzDetailQueryDTO dto) {
        return userBLO.getSjdzDetail(dto);
    }

    @Override
    public AjaxResponse saveSjdz(SjdzDTO dto) {
        AjaxResponse ajaxResponse = new AjaxResponse();

        CurrentUser cUser = SecurityUtils.getCurrentUser();//获取当前用户
        dto.setYhid(cUser.getUsername());
        //复制PO
        VRsWbSjdz vRsWbSjdz = new VRsWbSjdz();
        BeanUtils.copyProperties(dto, vRsWbSjdz);
        vRsWbSjdz.setTsyxbz("1");//有效标志
        //保存收件地址
        vRsWbSjdz = userBLO.saveSjdz(vRsWbSjdz);

        //返回主键
        ajaxResponse.setData("data", vRsWbSjdz);

        return ajaxResponse;
    }

    @Override
    public void setMrSjdz(SjdzDetailQueryDTO dto) {
        userBLO.setMrSjdz(dto);
    }

    @Override
    public VRsWbSjdz getMrSjdz(String userid) {
        return userBLO.getMrSjdz(userid);
    }

    @Override
    public void deleteSjdz(SjdzDetailQueryDTO dto) {
        userBLO.deleteSjdz(dto);
    }

    @Override
    public int getNewsCnt() {
        CurrentUser cUser = SecurityUtils.getCurrentUser();
        return userBLO.getNewsCnt(cUser.getUsername());
    }

    @Override
    public PageResult getNewsList(SjxxQueryDTO dto) {
        CurrentUser cUser = SecurityUtils.getCurrentUser();//获取当前用户
        dto.setUserid(cUser.getUsername());
        return userBLO.getNewsList(dto);
    }

    @Override
    public void saveNews(XxglDTO dto) {
        //复制PO
        VRsWbXxgl vRsWbXxgl = new VRsWbXxgl();
        BeanUtils.copyProperties(dto, vRsWbXxgl);

        String uuid = UUID.randomUUID().toString().replace("-", "");
        vRsWbXxgl.setRsWbXxglLsh(uuid);
        //获取当前用户
        CurrentUser cUser = SecurityUtils.getCurrentUser();
        if ("2".equals(dto.getFlag())) {//外网用户
            vRsWbXxgl.setFjrid(cUser.getUsername());
        } else {
            vRsWbXxgl.setFjrid(cUser.getUserid());
        }
        DateTimeFormatter formatters = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        //获取当前时间
        String czsj = LocalDateTime.now().format(formatters);
        vRsWbXxgl.setTsCzsj(czsj);
        userBLO.saveNews(vRsWbXxgl);

        //消息收件
        String sjrids = dto.getSjrids();
        String[] sjrid = sjrids.split(",");
        for (int i = 0; i < sjrid.length; i++) {
            VRsWbSjxx vRsWbSjxx = new VRsWbSjxx();
            vRsWbSjxx.setRsWbXxglLsh(uuid);
            vRsWbSjxx.setSjrid(sjrid[i]);
            vRsWbSjxx.setYdzt("0");//默认阅读状态为未读
            vRsWbSjxx.setTsyxbz("1");//默认有效标记为1
            userBLO.saveNewsSj(vRsWbSjxx);
        }
    }

    @Override
    public AjaxResponse setNewsYdzt(SjxxDTO dto) {
        AjaxResponse ajaxResponse = new AjaxResponse();

        if (StringUtils.isEmpty(dto.getYdzt())) {
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("阅读状态不可为空！");
        }

        String sjxxids = dto.getRsWbSjxxLsh();
        String[] sjxxid = sjxxids.split(",");
        for (int i = 0; i < sjxxid.length; i++) {
            VRsWbSjxx vRsWbSjxx = new VRsWbSjxx();
            vRsWbSjxx.setRsWbSjxxLsh(sjxxid[i]);
            vRsWbSjxx.setYdzt(dto.getYdzt());
            vRsWbSjxx.setTsyxbz("1");
            userBLO.setNewsZt(vRsWbSjxx);
        }

        return ajaxResponse;
    }

    @Override
    public AjaxResponse setNewsYxbz(SjxxDTO dto) {
        AjaxResponse ajaxResponse = new AjaxResponse();

        if (StringUtils.isEmpty(dto.getTsyxbz())) {
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("有效标志不可为空！");
        }

        String sjxxids = dto.getRsWbSjxxLsh();
        String[] sjxxid = sjxxids.split(",");
        for (int i = 0; i < sjxxid.length; i++) {
            VRsWbSjxx vRsWbSjxx = new VRsWbSjxx();
            vRsWbSjxx.setRsWbSjxxLsh(sjxxid[i]);
            vRsWbSjxx.setTsyxbz(dto.getTsyxbz());
            userBLO.setNewsZt(vRsWbSjxx);
        }

        return ajaxResponse;
    }

    @Override
    public void setNewsClear() {
        //获取当前用户
        CurrentUser cUser = SecurityUtils.getCurrentUser();
        userBLO.setNewsClear(cUser.getUsername());
    }

    @Override
    public AjaxResponse getUserInfo(String flag) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        Map<String, Object> userMap = new HashMap<String, Object>();

        //获取当前用户
        LOG.info("getUserInfo...获取当前用户");
        CurrentUser cUser = SecurityUtils.getCurrentUser();
        VRsGgfwUser vRsGgfwUser = userBLO.getVRsGgfwUser(cUser.getUsername());
        //查询参保状态
        try {
            if ("1".equals(vRsGgfwUser.getFwdx()) && "01".equals(vRsGgfwUser.getZjlx())) {
                TywtGrjbxxGgcx01DTO dto = new TywtGrjbxxGgcx01DTO();
                dto.setAac002(vRsGgfwUser.getZjhm());
                dto.setAac003(vRsGgfwUser.getMc());
                AjaxResponse ajaxResponseCb = queryBusinessBPO.queryJbxx(dto);
                if ("0".equals(ajaxResponseCb.getAppcode())) {
                    Map<String, Object> cbMap = ajaxResponseCb.getMap();
                    userMap.putAll((Map<String, Object>) cbMap.get("data"));
                } else {
                    LOG.error("查询参保状态异常："+ajaxResponseCb.getMsg());
//                    return ajaxResponseCb;
                }
            }
        } catch (ClientException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception e) {
            LOG.error("查询参保状态出错", e);
        }
        userMap.put("userid", vRsGgfwUser.getUserid());
        userMap.put("username", vRsGgfwUser.getMc());
        userMap.put("fwdx", vRsGgfwUser.getFwdx());
        userMap.put("sjhm", vRsGgfwUser.getSjhm());
        //关联省厅基本信息
        LOG.info("getUserInfo...关联省厅基本信息");
        boolean isHaveJbxx = false;
        if (StringUtils.isEmpty(vRsGgfwUser.getZtid())) {
            if ("1".equals(vRsGgfwUser.getFwdx())) {//个人
                if (!StringUtils.isEmpty(vRsGgfwUser.getZjlx())) {
                    VAc01 vAc01 = userBLO.getAc01ByZj(vRsGgfwUser.getZjlx(), vRsGgfwUser.getZjhm());
                    if (vAc01 != null) {
                        vRsGgfwUser.setZtid(vAc01.getZtid());
                        userBLO.updateRsGgfwUser(vRsGgfwUser);
                        isHaveJbxx = true;
                    }
                    userMap.put("aac058", vRsGgfwUser.getZjlx());//证件类型
                }
                userMap.put("aac147", vRsGgfwUser.getZjhm());//证件号码
            } else if ("2".equals(vRsGgfwUser.getFwdx())) {//单位
                VAb01 vAb01 = userBLO.getAb01ByAab998OrAab004(vRsGgfwUser.getZjhm(), vRsGgfwUser.getMc());
                if (vAb01 != null) {
                    vRsGgfwUser.setZtid(vAb01.getZtid());
                    userBLO.updateRsGgfwUser(vRsGgfwUser);
                    isHaveJbxx = true;
                }
                userMap.put("aab998", vRsGgfwUser.getZjhm());
            }
        } else {
            isHaveJbxx = true;
        }

        //获取基本信息
        LOG.info("getUserInfo...获取基本信息");
        if (isHaveJbxx) {
            if ("1".equals(vRsGgfwUser.getFwdx())) {//个人
                VAc01 vAc01 = userBLO.getAc01ById(vRsGgfwUser.getZtid());
                userMap.put("aac058", vAc01.getAac058());//证件类型
                userMap.put("aac147", vAc01.getAac147());//证件号码
                userMap.put("aac161", vAc01.getAac161());//国家/地区代码
                userMap.put("aac003", vAc01.getAac003());//姓名
                userMap.put("aac004", vAc01.getAac004());//性别
                userMap.put("aac005", vAc01.getAac005());//民族
                userMap.put("aac006", vAc01.getAac006());//出生日期
                userMap.put("aac067", vAc01.getAac067());//手机号码
            } else if ("2".equals(vRsGgfwUser.getFwdx())) {//单位
                VAb01 vAb01 = userBLO.getAb01ById(vRsGgfwUser.getZtid());
                userMap.put("aab003", vAb01.getAab003());//组织机构代码
                userMap.put("aab004", vAb01.getAab004());//单位名称
                userMap.put("aab998", vAb01.getAab998());//统一社会信用代码
                userMap.put("aab019", vAb01.getAab019());//单位类型
                userMap.put("aab011", vAb01.getAab011());//批准日期
                userMap.put("aab013", vAb01.getAab013());//法定代表人姓名
                userMap.put("aae005", vAb01.getAae005());//联系电话
                userMap.put("aae006", vAb01.getAae006());//联系地址
                userMap.put("aab301", vAb01.getAab301());//所属地区
            }
        }
        //脱敏处理
        LOG.info("getUserInfo...脱敏处理");
        String aac147 = userMap.get("aac147") == null ?"":(String)userMap.get("aac147");
        String sjhm = userMap.get("sjhm") == null ?"":(String)userMap.get("sjhm");
        String aae005 = userMap.get("aae005") == null ?"":(String)userMap.get("aae005");
        String username = userMap.get("username") == null ?"":(String)userMap.get("username");
        String aac003 = userMap.get("aac003") == null ?"":(String)userMap.get("aac003");
        String aab013 = userMap.get("aab013") == null ?"":(String)userMap.get("aab013");

        if("1".equals(flag)){
            userMap.put("aac147",change2TmComm(aac147));
            userMap.put("sjhm",change2TmComm(sjhm));
            userMap.put("aae005",change2TmComm(aae005));

            if ("1".equals(vRsGgfwUser.getFwdx())) {//个人
                userMap.put("username",change2Tm(username));
            }
            userMap.put("aac003",change2Tm(aac003));
            userMap.put("aab013",change2Tm(aab013));
        }

        //统一认证表，取手机号码
        LOG.info("getUserInfo...统一认证表，取手机号码,userid="+vRsGgfwUser.getUserid());
        String telephonenumber = userBLO.getTyrzPhoneNumber(vRsGgfwUser.getUserid());
        userMap.put("telephonenumber",change2TmComm(telephonenumber));

        ajaxResponse.setData("data", userMap);

        return ajaxResponse;
    }

    /**
     * 姓名脱敏处理
     * @param name
     * @return
     */
    private String change2Tm(String name){
        if(org.apache.commons.lang.StringUtils.isNotBlank(name)){
            return "****"+name.substring(name.length()-1,name.length());
        }
        return "";
    }

    /**
     * 通用脱敏处理
     * @param name
     * @return
     */
    private String change2TmComm(String name){
        String result = "";
        if(org.apache.commons.lang.StringUtils.isNotBlank(name)){
            if(name.length() >= 6){
                result = name.substring(0,3)+"****"+name.substring(name.length()-3,name.length());
            }else{
                result = name.substring(0,1)+"****";
            }
        }
        return result;
    }

    @Override
    public AjaxResponse saveRsWbYjfk(YjfkDTO dto) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        DateTimeFormatter formatters = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String dqsj = LocalDateTime.now().format(formatters);//当前时间
        CurrentUser cUser = SecurityUtils.getCurrentUser();//当前用户

        VRsWbYjfk vRsWbYjfk = new VRsWbYjfk();
        BeanUtils.copyProperties(dto, vRsWbYjfk);
        vRsWbYjfk.setFkr(cUser.getOrgname());//反馈人
        vRsWbYjfk.setFksj(dqsj);
        userBLO.saveRsWbYjfk(vRsWbYjfk);

        return ajaxResponse;
    }

    @Override
    public AjaxResponse saveRsZzzdLog(ZzzdLogDTO dto) {
        AjaxResponse ajaxResponse = new AjaxResponse();

        DateTimeFormatter formatters = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String dqsj = LocalDateTime.now().format(formatters);//当前时间

        VRsZzzdLog vRsZzzdLog = new VRsZzzdLog();
        BeanUtils.copyProperties(dto, vRsZzzdLog);
        vRsZzzdLog.setCjsj(dqsj);
        userBLO.saveRsZzzdLog(vRsZzzdLog);

        return ajaxResponse;
    }

    @Override
    public AjaxResponse getRsWbYjfkList(PageDTO dto) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        CurrentUser cUser = SecurityUtils.getCurrentUser();//获取当前用户

        PageResult pageResult = userBLO.getRsWbYjfkList(cUser.getUsername(), dto);
        ajaxResponse.setData("data", pageResult);
        ajaxResponse.setData("pagesize", dto.getPagesize());
        ajaxResponse.setData("pagenum", dto.getPagenum());

        return ajaxResponse;
    }

    @Override
    public AjaxResponse getRsWbYjfk(YjfkQueryDTO dto) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        VRsWbYjfk vRsWbYjfk = userBLO.getRsWbYjfkById(dto.getRsWbYjfkLsh());
        ajaxResponse.setData("data", vRsWbYjfk);
        return ajaxResponse;
    }

    @Override
    public AjaxResponse checkIdentity(CheckMsgCodeDTO dto) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        ajaxResponse.setAppcode("0");
        String result = "";
        //验证手机验证码
        result = this.checkMsg(dto);
        if(org.apache.commons.lang.StringUtils.isNotBlank(result)){
            ajaxResponse.setAppcode("1");
            ajaxResponse.setMsg(result);
            return ajaxResponse;
        }

        //取用户完整信息
        ajaxResponse =this.getUserInfo("0");

        return ajaxResponse;
    }

    /**
     * 验证图形验证码
     * @param dto
     * @return
     */
    private String checkImg(CheckImgCodeDTO dto){
        Cache cache=leafCacheManager.getCache(IMGCACHENAME);
        ValidCodeCacheDTO codeCacheDTO = null;
        String cacheKey = getCodeCacheKey(dto.getImgid());
        codeCacheDTO = cache.get(cacheKey,ValidCodeCacheDTO.class);
        if(codeCacheDTO == null || org.springframework.util.StringUtils.isEmpty(codeCacheDTO.getCode())){
            return "图形验证码找不到";
        }
        if (codeCacheDTO.getCode().equalsIgnoreCase(dto.getImgcode())) {
            long sessionTime = (long)codeCacheDTO.getStarttime();
            long duration = (System.currentTimeMillis() - sessionTime) / 1000;
            if (duration < 60) {
                //删除缓存
                cache.evict(cacheKey);
                return "";
            } else {
                //过期
                return "图形验证码已过期";
            }
        } else {
            //不正确
            return "图形验证码不正确";
        }
    }

    /**
     * 验证手机验证码
     * @param dto
     * @return
     */
    private String checkMsg(CheckMsgCodeDTO dto){
        Cache cache=leafCacheManager.getCache(PHONECACHENAME);
        ValidCodeCacheDTO codeCacheDTO = null;
        String cacheKey = getCodeCacheKey(dto.getMsgid());
        codeCacheDTO = cache.get(cacheKey,ValidCodeCacheDTO.class);
        if(codeCacheDTO == null || org.springframework.util.StringUtils.isEmpty(codeCacheDTO.getCode())){
            return "手机验证码找不到";
        }
        if (codeCacheDTO.getCode().equalsIgnoreCase(dto.getMsgcode())) {
            long sessionTime = (long)codeCacheDTO.getStarttime();
            long duration = (System.currentTimeMillis() - sessionTime) / 1000;
            if (duration < 300) {
                //删除缓存
                cache.evict(cacheKey);
                return "";
            } else {
                //过期
                return "手机验证码已过期";
            }
        } else {
            //不正确
            return "手机验证码不正确";
        }

    }

    /**
     * 生成图形验证码
     * @return
     */
    @Override
    public Map<String, String> render(){
        response.setDateHeader(HttpHeaders.EXPIRES, 0L);
        response.setHeader(HttpHeaders.CACHE_CONTROL, "no-store, no-cache, must-revalidate");
        response.addHeader(HttpHeaders.CACHE_CONTROL, "post-check=0, pre-check=0");
        response.setHeader(HttpHeaders.PRAGMA, "no-cache");
        response.setContentType("application/json;charset=UTF-8");

        CaptchaAutoConfiguration bean = GgfwSpringContextUtil.getBean ("captchaAutoConfiguration",CaptchaAutoConfiguration.class);
        DefaultKaptcha kaptcha = bean.defaultKaptcha();
        String code = kaptcha.createText();
        LOG.info("code="+code);

        Map<String, String> ajaxResponse = new HashMap<String, String>();

        ajaxResponse.put("appcode", Consts.APPCODE_SUCCESS);
        String reqid = UUID.randomUUID().toString();
        ajaxResponse.put("reqid", reqid);
        try (ServletOutputStream out = response.getOutputStream()) {
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            ImageIO.write(kaptcha.createImage(code), "jpg", os);
            ajaxResponse.put("codeimg", Base64.getEncoder().encodeToString(os.toByteArray()));
            StringBuilder sb = new StringBuilder(JSONObject.toJSONString(ajaxResponse));
            out.write(sb.toString().getBytes("utf-8"));
            //放入缓存
            ValidCodeCacheDTO codeCacheDTO = new ValidCodeCacheDTO();
            codeCacheDTO.setCode(code);
            codeCacheDTO.setStarttime(System.currentTimeMillis());
            Cache cache = leafCacheManager.getCache(IMGCACHENAME);

            cache.put(getCodeCacheKey(reqid), codeCacheDTO);
            return ajaxResponse;
        } catch (IOException e) {
            LOG.info("验证码生成失败");
        }
        return ajaxResponse;
    }
    private String getCodeCacheKey(String reqid){
        return "ValidCode"+reqid;
    }

    /**
     * 获取手机短信验证码
     * @return
     */
    @Override
    public AjaxResponse sendPhoneMsgCode(CheckImgCodeDTO dto){
        AjaxResponse ajaxResponse = new AjaxResponse();
        ajaxResponse.setAppcode("0");
        //验证图形验证码
        String result = this.checkImg(dto);
        if(org.apache.commons.lang.StringUtils.isNotBlank(result)){
            ajaxResponse.setAppcode("1");
            ajaxResponse.setMsg(result);
            return ajaxResponse;
        }

        //获取当前用户手机号码
        CurrentUser cUser = SecurityUtils.getCurrentUser();
        VRsGgfwUser vRsGgfwUser = userBLO.getVRsGgfwUser(cUser.getUsername());
        if(vRsGgfwUser == null){
            ajaxResponse.setAppcode("1");
            ajaxResponse.setMsg("获取当前用户信息失败");
            return ajaxResponse;
        }
        String telephonenumber = userBLO.getTyrzPhoneNumber(vRsGgfwUser.getUserid());
        //String telephonenumber = "18922086226";
        LOG.info("手机号码："+telephonenumber);
        if(org.apache.commons.lang.StringUtils.isBlank(telephonenumber)){
            ajaxResponse.setAppcode("1");
            ajaxResponse.setMsg("获取当前用户手机号码失败");
            return ajaxResponse;
        }
        if(telephonenumber.length() != 11){
            ajaxResponse.setAppcode("1");
            ajaxResponse.setMsg("获取当前用户手机号码不合法");
            return ajaxResponse;
        }

        //随机生成6位整数
        String code = this.getRandom6();
        LOG.info("手机验证码："+code);

        //放入缓存PHONECACHENAME
        String msgid = UUID.randomUUID().toString();
        ajaxResponse.setData("msgid", msgid);//返回缓存ID
        ValidCodeCacheDTO codeCacheDTO = new ValidCodeCacheDTO();
        codeCacheDTO.setCode(code);
        codeCacheDTO.setStarttime(System.currentTimeMillis());
        Cache cache = leafCacheManager.getCache(PHONECACHENAME);
        cache.put(getCodeCacheKey(msgid), codeCacheDTO);

        //发送手机短信
        DateTimeFormatter formatters = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String msg = "%s为您的登录验证码，请于5分钟内填写。如非本人操作，请忽略本短信。";
        Integer seq = sendSmsMapper.getSmsSeq();//获取序列号
        SendSmsPO smsPO = new SendSmsPO();
        smsPO.setSmscontent(String.format(msg, code));
        smsPO.setPhonenumber(telephonenumber);
        smsPO.setStatus(0);
        smsPO.setSmstime(new Date());//创建时间
        smsPO.setSmsindex(seq);
        sendSmsMapper.insert(smsPO);

        return ajaxResponse;
    }

    /**
     * 随机生成6位整数
     * @return
     */
    private String getRandom6(){
        Random random = new Random();
        int num = 0;
        num = random.nextInt(999999);
        if(num < 100000) {
            num += 100000;
        }
        return String.valueOf(num);
    }

}
