package com.chinaweal.aiccs.aiccs.writs.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.chinaweal.aiccs.aiccs.abnormal.entity.EBaseinfo;
import com.chinaweal.aiccs.aiccs.abnormal.entity.Gzaiccode;
import com.chinaweal.aiccs.aiccs.abnormal.entity.TSBizRemList;
import com.chinaweal.aiccs.aiccs.abnormal.service.EBaseinfoService;
import com.chinaweal.aiccs.aiccs.abnormal.service.IGzaiccodeService;
import com.chinaweal.aiccs.aiccs.abnormal.service.TSBizRemListService;
import com.chinaweal.aiccs.aiccs.punishment.entity.TBizRemPunishment;
import com.chinaweal.aiccs.aiccs.punishment.service.ITBizRemPunishmentService;
import com.chinaweal.aiccs.aiccs.seriousillegal.entity.TSBizSerIllegalRem;
import com.chinaweal.aiccs.aiccs.seriousillegal.entity.TSSerIllegalList;
import com.chinaweal.aiccs.aiccs.seriousillegal.service.TSBizSerIllegalRemService;
import com.chinaweal.aiccs.aiccs.seriousillegal.service.TSSerIllegalListService;
import com.chinaweal.aiccs.aiccs.seriousillegalPerson.entity.XrSeriousIllegalPersonRemList;
import com.chinaweal.aiccs.aiccs.system.entity.TRBaseCode;
import com.chinaweal.aiccs.aiccs.system.service.TRBaseCodeService;
import com.chinaweal.aiccs.aiccs.writs.entity.Tswrittemplate;
import com.chinaweal.aiccs.aiccs.writs.entity.dto.WritTempEntInfoDto;
import com.chinaweal.aiccs.aiccs.writs.mapper.TswrittemplateMapper;
import com.chinaweal.aiccs.aiccs.writs.service.TswrittemplateService;
import com.chinaweal.aiccs.common.util.ConstantsUtil;
import com.chinaweal.aiccs.common.util.DateUtils;
import com.chinaweal.aiccs.common.util.StringUtils;
import com.chinaweal.aiccs.common.util.WorkNoUtil;
import com.chinaweal.aiccs.crgs.punish.entity.TbIlcPunInfoQuery;
import com.chinaweal.aiccs.crgs.punish.service.TbIlcPunInfoQueryService;
import com.chinaweal.aiccs.org.service.AicorgService;
import com.chinaweal.aicorg.model.AICUser;
import com.chinaweal.youfool.framework.springboot.mybatis.plus.BaseServiceImpl;
import com.chinaweal.youfool.framework.springboot.rest.RestResult;
import com.chinaweal.youfool.framework.springboot.util.SpringUtil;
import com.chinaweal.youfool.framework.sso.util.SSOUtil;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.UUID;

/**
 * <p>
 * 文书通用模板 服务实现类
 * </p>
 *
 * @author Lee
 * @since 2021-09-26
 */
@Service
public class TswrittemplateServiceImpl extends BaseServiceImpl<TswrittemplateMapper, Tswrittemplate> implements TswrittemplateService {

    @Autowired
    private TRBaseCodeService baseCodeService;
    @Autowired
    private AicorgService aicorgService;
    @Resource
    @Lazy
    private IGzaiccodeService iGzaiccodeService;

    @Override
    public String contentFormatter(String content) {
        Document htmldoc = Jsoup.parse(content);
        Elements links = htmldoc.getElementsByTag("p");
        StringBuffer text = new StringBuffer("");
        for (Element link : links) {
            text.append("<p>");
            text.append(link.text());
            text.append("</p>");
        }
        return text.toString();
    }

    @Override
    public String revDecContentFormatter(String content, Map<String, Object> map) {
        StringBuilder text = new StringBuilder("");
        text.append("<p>" + "当事人：").append(map.get("entName") == null ? "" : map.get("entName")).append("</p>");
        text.append("<p>" + "主体资格证照名称：").append(map.get("entCerName") == null ? "" : map.get("entCerName")).append("</p>");
        text.append("<p>" + "统一社会信用代码：").append(map.get("uniscid") == null ? "" : map.get("uniscid")).append("</p>");
        text.append("<p>" + "住所（住址）：").append(map.get("dom") == null ? "" : map.get("dom")).append("</p>");
//        text.append("<p>" + "法定代表人（负责人、经营者）：").append(map.get("lerep") == null ? "" : map.get("lerep")).append("</p>");
//        text.append("<p>" + "身份证件号码：").append(map.get("cerno") == null ? "" : map.get("cerno")).append("</p>");
        Document htmldoc = Jsoup.parse(content);
        Elements links = htmldoc.getElementsByTag("p");
        for (Element link : links) {
            text.append("<p>");
            text.append(link.text());
            text.append("</p>");
        }
        return text.toString();
    }

    @Override
    public String illegalRepairDecContentFormatter(String content) {
        if (StringUtils.isEmpty(content)) return null;
        Document htmldoc = Jsoup.parse(content);
        Elements links = htmldoc.getElementsByTag("p");
        StringBuilder text = new StringBuilder("");
        for (Element link : links) {
            if (link.text().contains("身份证件号码") || link.text().contains("联系电话")) {
                continue;
            }
            text.append("<p>");
            text.append(link.text());
            text.append("</p>");
        }

        return text.toString();
    }

    @Override
    public Tswrittemplate generateWrits(String writsType, String bizseq, String type, AICUser user) {
        // 先查找业务中有没有编辑保存过的文书内容，有则返回
        LambdaQueryWrapper<Tswrittemplate> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Tswrittemplate::getBizseq, bizseq)
                .eq(Tswrittemplate::getWritsType, writsType)
                .eq(Tswrittemplate::getIsTemplate, "0");// 是否为模板 “0”否“1”是
        Tswrittemplate writtemplateBiz = lambdaQuery().eq(Tswrittemplate::getBizseq, bizseq)
                .eq(Tswrittemplate::getWritsType, writsType).eq(Tswrittemplate::getIsTemplate, "0").one();
        EBaseinfoService eBaseinfoService = SpringUtil.getBean(EBaseinfoService.class);
        if (writtemplateBiz == null) {// 没有则查找初始模板
            // 获取所在行政区划的码值
            String regionId = aicorgService.getRegionCodeByUser(user);

            // 不同文书类型对模板内容有 不同处理
            Tswrittemplate templateDB = lambdaQuery().eq(Tswrittemplate::getWritsType, writsType).eq(Tswrittemplate::getIsTemplate, "1").one();
            if (templateDB != null) {
                if (WorkNoUtil.WORKNOTYPE_51.equals(writsType)) {//信用修复不予受理决定书

//                } else if (WorkNoUtil.WORKNOTYPE_52.equals(writsType)) {//信用修复不予信用修复决定书

                } else if (WorkNoUtil.WORKNOTYPE_53.equals(writsType) || WorkNoUtil.WORKNOTYPE_52.equals(writsType)) {//信用修复准予信用修复决定书
                    TSBizSerIllegalRemService tsBizSerIllegalRemService = SpringUtil.getBean(TSBizSerIllegalRemService.class);
                    TSSerIllegalListService tsSerIllegalListService = SpringUtil.getBean(TSSerIllegalListService.class);
                    List<TSBizSerIllegalRem> bizSerIllegalRem = tsBizSerIllegalRemService.selectbizRembizseq(bizseq);
                    EBaseinfo eBaseinfo = eBaseinfoService.getOneByPripid(bizSerIllegalRem.get(0).getPriPID());
                    TSSerIllegalList illegalList = tsSerIllegalListService.getById(bizSerIllegalRem.get(0).getIllegalListID());
                    String content = templateDB.getContent();

                    LocalDate abntime = illegalList.getAbntime();
                    Map<String, TRBaseCode> codeMap = baseCodeService.getBaseCodeMapFormCache("CD73");
                    TRBaseCode code = codeMap.get(illegalList.getSerillrea());
                    LocalDateTime applyTime = bizSerIllegalRem.get(0).getApplyTime();
                    LocalDate acceptTime = LocalDate.now();
                    String abntimeStr = DateUtils.localDateFormat(abntime, "yyyy年MM月dd日");
                    String applyTimeStr = null;
                    if (applyTime != null) {
                        applyTimeStr = DateUtils.localDateFormat(applyTime.toLocalDate(), "yyyy年MM月dd日");
                    }
                    String acceptTimeStr = DateUtils.localDateFormat(acceptTime, "yyyy年MM月dd日");

//                    String areaName = ConstantsUtil.getAreaName(regionId);
                    LambdaQueryWrapper<Gzaiccode> lqw = Wrappers.lambdaQuery();
                    //查地市名称
                    lqw.eq(Gzaiccode::getScountrycode, regionId.substring(0, 4) + "00");
                    Gzaiccode gzaiccode = iGzaiccodeService.getOne(lqw);
                    String areaName = gzaiccode.getScountryextcode();

//                    String addr = ConstantsUtil.getAddr(regionId);
//                    String phoneDW = ConstantsUtil.getPhone(regionId);
                    String replaceContent = content.replace("{{party}}", StringUtils.isNotEmpty(eBaseinfo.getEntname()) ? eBaseinfo.getEntname() : StringUtils.EMPTY)
                            .replace("{{entCerName}}", StringUtils.isNotEmpty(eBaseinfo.getEntname()) ? eBaseinfo.getEntname() : StringUtils.EMPTY)
                            .replace("{{uniscid}}", StringUtils.isNotEmpty(eBaseinfo.getUniscid()) ? eBaseinfo.getUniscid() : StringUtils.EMPTY)
                            .replace("{{dom}}", StringUtils.isNotEmpty(eBaseinfo.getDom()) ? eBaseinfo.getDom() : StringUtils.EMPTY)
                            .replace("{{lerepname}}", StringUtils.isNotEmpty(eBaseinfo.getName()) ? eBaseinfo.getName() : StringUtils.EMPTY)
                            .replace("{{cerNo}}", StringUtils.isNotEmpty(eBaseinfo.getCerno()) ? eBaseinfo.getCerno() : StringUtils.EMPTY)
                            .replace("{{phone}}", StringUtils.isNotEmpty(eBaseinfo.getPhone()) ? eBaseinfo.getPhone() : StringUtils.EMPTY)
                            .replace("{{otherContact}}", StringUtils.EMPTY)
                            .replace("{{abntime}}", StringUtils.isNotEmpty(abntimeStr) ? abntimeStr : StringUtils.EMPTY)
                            .replace("{{serillreaStr}}", code != null ? code.getName() : StringUtils.EMPTY)
                            .replace("{{applyTime}}", StringUtils.isNotEmpty(applyTimeStr) ? applyTimeStr : StringUtils.EMPTY)
                            .replace("{{acceptTime}}", StringUtils.isNotEmpty(acceptTimeStr) ? acceptTimeStr : StringUtils.EMPTY)
                            .replace("{{deadline1}}", "60日")
                            .replace("{{deadline2}}", StringUtils.EMPTY)
                            .replace("{{reconsiderationOrg}}", StringUtils.isNotEmpty(areaName) ? areaName + "人民政府" : StringUtils.EMPTY)
                            .replace("{{government}}", StringUtils.isNotEmpty(areaName) ? areaName + "人民政府" : "内蒙古自治区人民政府");
//                            .replace("{{address}}", StringUtils.isNotEmpty(addr) ? addr : "广州市越秀区小北路183号金和大厦2楼");
                    templateDB.setContent(replaceContent);
                } else if (WorkNoUtil.WORKNOTYPE_55.equals(writsType) || WorkNoUtil.WORKNOTYPE_56.equals(writsType) ||
                        WorkNoUtil.WORKNOTYPE_58.equals(writsType) || WorkNoUtil.WORKNOTYPE_59.equals(writsType)) {//企业农专经营异常信用修复
                    TSBizRemListService tsBizRemListService = SpringUtil.getBean(TSBizRemListService.class);
                    List<TSBizRemList> tsBizRemLists = tsBizRemListService.selectbizRembizseq(bizseq);
                    TSBizRemList bizRemListModel = tsBizRemLists.get(0);
                    EBaseinfo eBaseinfo = eBaseinfoService.getOneByPripid(bizRemListModel.getPripid());
                    LocalDate abntime = bizRemListModel.getAbntime();

                    String content = templateDB.getContent();
                    String codeName = "";
                    if ("farmer".equals(type)) {
                        if (StringUtils.isNotBlank(bizRemListModel.getSpereasons())) {
                            codeName = bizRemListModel.getSpereasons();
                        } else {
                            Map<String, TRBaseCode> codeMap = baseCodeService.getBaseCodeMapFormCache("CD77");
                            TRBaseCode code = codeMap.get(bizRemListModel.getSpecause());
                            codeName = code.getName();
                        }

                    } else if ("company".equals(type)) {
                        if (StringUtils.isNotBlank(bizRemListModel.getSpereasons())) {
                            codeName = bizRemListModel.getSpereasons();
                        } else {
                            Map<String, TRBaseCode> codeMap = baseCodeService.getBaseCodeMapFormCache("CD71");
                            TRBaseCode code = codeMap.get(bizRemListModel.getSpecause());
                            codeName = code.getName();
                        }
                    } else if ("individual".equals(type)) {
                        if (StringUtils.isNotBlank(bizRemListModel.getSpereasons())) {
                            codeName = bizRemListModel.getSpereasons();
                        } else {
                            Map<String, TRBaseCode> codeMap = baseCodeService.getBaseCodeMapFormCache("CD75");
                            TRBaseCode code = codeMap.get(bizRemListModel.getSpecause());
                            codeName = code.getName();
                        }
                        eBaseinfo.setDom(eBaseinfo.getOploc());// 个体户地址字段不一样
                    }
                    String abntimeStr = DateUtils.localDateFormat(abntime, "yyyy年MM月dd日");
                    LocalDateTime applyTime = tsBizRemLists.get(0).getApplyTime();
                    LocalDate acceptTime = LocalDate.now();
                    String applyTimeStr = null;
                    if (applyTime != null) {
                        applyTimeStr = DateUtils.localDateFormat(applyTime.toLocalDate(), "yyyy年MM月dd日");
                    }
                    String acceptTimeStr = DateUtils.localDateFormat(acceptTime, "yyyy年MM月dd日");

//                    String areaName = ConstantsUtil.getAreaName(regionId);
                    LambdaQueryWrapper<Gzaiccode> lqw = Wrappers.lambdaQuery();
                    //查地市名称
                    lqw.eq(Gzaiccode::getScountrycode, regionId.substring(0, 4) + "00");
                    Gzaiccode gzaiccode = iGzaiccodeService.getOne(lqw);
                    String areaName = gzaiccode.getScountryextcode();

//                    String addr = ConstantsUtil.getAddr(regionId);
//                    String phoneDW = ConstantsUtil.getPhone(regionId);
                    String replaceContent = content.replace("{{party}}", StringUtils.isNotEmpty(eBaseinfo.getEntname()) ? eBaseinfo.getEntname() : StringUtils.EMPTY)
                            .replace("{{entCerName}}", StringUtils.isNotEmpty(eBaseinfo.getEntname()) ? eBaseinfo.getEntname() : StringUtils.EMPTY)
                            .replace("{{uniscid}}", StringUtils.isNotEmpty(eBaseinfo.getUniscid()) ? eBaseinfo.getUniscid() : StringUtils.EMPTY)
                            .replace("{{dom}}", StringUtils.isNotEmpty(eBaseinfo.getDom()) ? eBaseinfo.getDom() : StringUtils.EMPTY)
                            .replace("{{lerepname}}", StringUtils.isNotEmpty(eBaseinfo.getName()) ? eBaseinfo.getName() : StringUtils.EMPTY)
                            .replace("{{cerNo}}", StringUtils.isNotEmpty(eBaseinfo.getCerno()) ? eBaseinfo.getCerno() : StringUtils.EMPTY)
                            .replace("{{phone}}", StringUtils.isNotEmpty(eBaseinfo.getPhone()) ? eBaseinfo.getPhone() : StringUtils.EMPTY)
                            .replace("{{otherContact}}", StringUtils.EMPTY)
                            .replace("{{abntime}}", StringUtils.isNotEmpty(abntimeStr) ? abntimeStr : StringUtils.EMPTY)
                            .replace("{{serillreaStr}}", StringUtils.isNotEmpty(codeName) ? codeName : StringUtils.EMPTY)
                            .replace("{{applyTime}}", StringUtils.isNotEmpty(applyTimeStr) ? applyTimeStr : StringUtils.EMPTY)
                            .replace("{{acceptTime}}", StringUtils.isNotEmpty(acceptTimeStr) ? acceptTimeStr : StringUtils.EMPTY)
                            .replace("{{deadline1}}", "60日")
                            .replace("{{deadline2}}", StringUtils.EMPTY)
                            .replace("{{reconsiderationOrg}}", StringUtils.isNotEmpty(areaName) ? areaName + "人民政府" : StringUtils.EMPTY)
                            .replace("{{government}}", StringUtils.isNotEmpty(areaName) ? areaName + "人民政府" : "内蒙古自治区人民政府");
//                            .replace("{{address}}", StringUtils.isNotEmpty(addr) ? addr : "广州市越秀区小北路183号金和大厦2楼")
//                            .replace("{{shphone}}", StringUtils.isNotEmpty(phoneDW) ? phoneDW : regionId.equals("440114") || regionId.equals("440121") ? "" : "020-83555988");
                    templateDB.setContent(replaceContent);
                }
                return templateDB;
            }
        }
        return writtemplateBiz;
    }

    @Override
    public void savePersonRemTemplates(XrSeriousIllegalPersonRemList xrSeriousIllegalPersonRemList){
        String decisionContent = xrSeriousIllegalPersonRemList.getDecisionContent();
        if(StringUtils.isNotBlank(decisionContent)){
            //获取当前用户
            AICUser user = SSOUtil.getUser();

            Tswrittemplate xrTsWriteTemplate = new Tswrittemplate();
            xrTsWriteTemplate.setTemplateId(UUID.randomUUID().toString());
            xrTsWriteTemplate.setIsTemplate("0");
            xrTsWriteTemplate.setBizseq(xrSeriousIllegalPersonRemList.getBizSeqNo());
            if(xrSeriousIllegalPersonRemList.getIsAgreeRepair().equals("1")){
                xrTsWriteTemplate.setWritsType("p3");
            } else if(xrSeriousIllegalPersonRemList.getIsAgreeRepair().equals("2")){
                xrTsWriteTemplate.setWritsType("p2");
            }
            //自然人的用证件号码存
//            xrTsWriteTemplate.setPripId(xrSeriousIllegalPersonRemList.getCerNo());
            xrTsWriteTemplate.setAreaCode(user.getRegionID().substring(0, 6));
//            xrTsWriteTemplate.setRemId(xrSeriousIllegalPersonRemList.getBizSerRemId());
            xrTsWriteTemplate.setContent(decisionContent);
            saveOrUpdate(xrTsWriteTemplate);
        }
    }

    @Override
    public Tswrittemplate generateRemPunishmentWrits(WritTempEntInfoDto writTempEntInfoDto, AICUser user) {
        // 先查找业务中有没有编辑保存过的文书内容，有则返回
        LambdaQueryWrapper<Tswrittemplate> wrapper = new LambdaQueryWrapper<>();
        String bizseq = writTempEntInfoDto.getBizseq();
        String writsType = writTempEntInfoDto.getWritsType();

        wrapper.eq(Tswrittemplate::getBizseq, bizseq)
                .eq(Tswrittemplate::getWritsType, writsType)
                .eq(Tswrittemplate::getIsTemplate, "0");// 是否为模板 “0”否“1”是
        Tswrittemplate writtemplateBiz = lambdaQuery().eq(Tswrittemplate::getBizseq, bizseq)
                .eq(Tswrittemplate::getWritsType, writsType).eq(Tswrittemplate::getIsTemplate, "0").one();
        EBaseinfoService eBaseinfoService = SpringUtil.getBean(EBaseinfoService.class);
        if (writtemplateBiz == null) {// 没有则查找初始模板
            // 获取所在行政区划的码值
            String regionId = aicorgService.getRegionCodeByUser(user);

            // 不同文书类型对模板内容有 不同处理
            Tswrittemplate templateDB = lambdaQuery().eq(Tswrittemplate::getWritsType, writsType).eq(Tswrittemplate::getIsTemplate, "1").one();
            if (templateDB != null) {
                if (WorkNoUtil.WORKNOTYPE_65.equals(writsType) || WorkNoUtil.WORKNOTYPE_66.equals(writsType) ) { //行政处罚信用修复
                    ITBizRemPunishmentService bizRemPunishmentService = SpringUtil.getBean(ITBizRemPunishmentService.class);
                    TbIlcPunInfoQueryService tbIlcPunInfoQueryService = SpringUtil.getBean(TbIlcPunInfoQueryService.class);
                    List<TBizRemPunishment> tBizRemPunishments = bizRemPunishmentService.selectbizRembizseq(bizseq);
                    TBizRemPunishment tBizRemPunishment = tBizRemPunishments.get(0);
                    //查行政处罚信息
                    TbIlcPunInfoQuery tbIlcPunInfoQuery = tbIlcPunInfoQueryService.findById(tBizRemPunishment.getPunishmentId());
                    EBaseinfo eBaseinfo = eBaseinfoService.getOneByPripid(tBizRemPunishment.getPripid());

                    //处罚决定日期
                    LocalDateTime abntime = tbIlcPunInfoQuery.getCfjdsj();
                    String abntimeStr = DateUtils.localDateFormat(LocalDate.from(abntime), "yyyy年MM月dd日");
                    String content = templateDB.getContent();

                    //主体申请修复日期
                    LocalDate applyTime = writTempEntInfoDto.getApplyDate();
                    String applyTimeStr = DateUtils.localDateFormat(applyTime, "yyyy年MM月dd日");
                    //信用修复决定时间
                    LocalDate acceptTime = LocalDate.from(writTempEntInfoDto.getRepairDate());
                    String acceptTimeStr = DateUtils.localDateFormat(acceptTime, "yyyy年MM月dd日");

                    LambdaQueryWrapper<Gzaiccode> lqw = Wrappers.lambdaQuery();
                    //查地市名称
                    lqw.eq(Gzaiccode::getScountrycode, regionId.substring(0, 4) + "00");
                    Gzaiccode gzaiccode = iGzaiccodeService.getOne(lqw);
                    String areaName = gzaiccode.getScountryextcode();

//                    String addr = ConstantsUtil.getAddr(regionId);
//                    String phoneDW = ConstantsUtil.getPhone(regionId);
                    String replaceContent = content.replace("{{party}}", StringUtils.isNotEmpty(eBaseinfo.getEntname()) ? eBaseinfo.getEntname() : StringUtils.EMPTY)
                            .replace("{{entCerName}}", StringUtils.isNotEmpty(eBaseinfo.getEntname()) ? eBaseinfo.getEntname() : StringUtils.EMPTY)
                            .replace("{{uniscid}}", StringUtils.isNotEmpty(eBaseinfo.getUniscid()) ? eBaseinfo.getUniscid() : StringUtils.EMPTY)
                            .replace("{{dom}}", StringUtils.isNotEmpty(eBaseinfo.getDom()) ? eBaseinfo.getDom() : StringUtils.EMPTY)
                            .replace("{{lerepname}}", StringUtils.isNotEmpty(eBaseinfo.getName()) ? eBaseinfo.getName() : StringUtils.EMPTY)
                            .replace("{{cerNo}}", StringUtils.isNotEmpty(eBaseinfo.getCerno()) ? eBaseinfo.getCerno() : StringUtils.EMPTY)
                            .replace("{{phone}}", StringUtils.isNotEmpty(eBaseinfo.getPhone()) ? eBaseinfo.getPhone() : StringUtils.EMPTY)
                            .replace("{{otherContact}}", StringUtils.EMPTY)
                            .replace("{{abntime}}", StringUtils.isNotEmpty(abntimeStr) ? abntimeStr : StringUtils.EMPTY)
                            .replace("{{applyTime}}", StringUtils.isNotEmpty(applyTimeStr) ? applyTimeStr : StringUtils.EMPTY)
                            .replace("{{acceptTime}}", StringUtils.isNotEmpty(acceptTimeStr) ? acceptTimeStr : StringUtils.EMPTY)
                            .replace("{{reconsiderationOrg}}", StringUtils.isNotEmpty(areaName) ? areaName + "人民政府" : StringUtils.EMPTY)
                            .replace("{{government}}", StringUtils.isNotEmpty(areaName) ? areaName + "人民政府" : "内蒙古自治区人民政府");
//                            .replace("{{address}}", StringUtils.isNotEmpty(addr) ? addr : "广州市越秀区小北路183号金和大厦2楼")
//                            .replace("{{shphone}}", StringUtils.isNotEmpty(phoneDW) ? phoneDW : regionId.equals("440114") || regionId.equals("440121") ? "" : "020-83555988");;

                    templateDB.setContent(replaceContent);
                }
                return templateDB;
            }
        }
        return writtemplateBiz;
    }

}
