package com.project.zcustom.service.service.smart.impl;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.project.common.core.domain.search.PageParamVo;
import com.project.zcustom.domain.smart.PlatGreenSmart;
import com.project.zcustom.mapper.service.smart.PlatGreenSmartMapper;
import com.project.zcustom.service.service.smart.IPlatGreenSmartService;
import net.sourceforge.pinyin4j.PinyinHelper;
import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.project.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;

import java.text.Collator;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 绿智食堂Service业务层处理
 *
 * @author change
 * @date 2024-10-31
 */
@Service
public class PlatGreenSmartServiceImpl extends ServiceImpl<PlatGreenSmartMapper, PlatGreenSmart> implements IPlatGreenSmartService {

    /**
     * 组装查询条件
     */
    private LambdaQueryWrapper<PlatGreenSmart> getLambdaQueryWrapper(PlatGreenSmart platGreenSmart) {
        LambdaQueryWrapper<PlatGreenSmart> lqw = new LambdaQueryWrapper<PlatGreenSmart>();
        if (StringUtils.isNotBlank(platGreenSmart.getAppOrg())) {
            lqw.eq(PlatGreenSmart::getAppOrg, platGreenSmart.getAppOrg());
        }
        if (StringUtils.isNotBlank(platGreenSmart.getCanteenNum())) {
            lqw.like(PlatGreenSmart::getCanteenNum, platGreenSmart.getCanteenNum());
        }

        return lqw;
    }

    /**
     * 分页查询绿智食堂列表
     *
     * @param platGreenSmart 绿智食堂
     * @return 绿智食堂集合
     */
    @Override
    public IPage<PlatGreenSmart> pagingPlatGreenSmartList(PlatGreenSmart platGreenSmart) {
        IPage<PlatGreenSmart> page = new Page<>(platGreenSmart.getPageNum(), platGreenSmart.getPageSize());
        LambdaQueryWrapper<PlatGreenSmart> lqw = getLambdaQueryWrapper(platGreenSmart);
        // 排序 默认时间倒序
        lqw.orderByDesc(PlatGreenSmart::getCreateTime);
        return baseMapper.selectPage(page, lqw);
    }

    /**
     * 分页查询绿智食堂列表
     *
     * @param lqw
     * @return 绿智食堂集合
     */
    @Override
    public IPage<PlatGreenSmart> pagingPlatGreenSmartList(PageParamVo pageParamVo, LambdaQueryWrapper<PlatGreenSmart> lqw) {
        IPage<PlatGreenSmart> page = new Page<>(pageParamVo.getPageNum(), pageParamVo.getPageSize());
        // 排序 默认时间倒序
        lqw.orderByDesc(PlatGreenSmart::getCreateTime);
        return baseMapper.selectPage(page, lqw);
    }

    /**
     * 查询绿智食堂列表
     *
     * @param platGreenSmart 绿智食堂
     * @return 绿智食堂
     */
    @Override
    public List<PlatGreenSmart> selectPlatGreenSmartList(PlatGreenSmart platGreenSmart) {
        LambdaQueryWrapper<PlatGreenSmart> lqw = getLambdaQueryWrapper(platGreenSmart);
        // 排序 默认时间倒序
        lqw.orderByDesc(PlatGreenSmart::getCreateTime);
        return baseMapper.selectList(lqw);
    }

    /**
     * 查询绿智食堂列表
     *
     * @param platGreenSmart 绿智食堂
     * @return 绿智食堂
     */
    @Override
    public List<PlatGreenSmart> selectPlatGreenSmartList(PlatGreenSmart platGreenSmart, Long limitNum) {
        LambdaQueryWrapper<PlatGreenSmart> lqw = getLambdaQueryWrapper(platGreenSmart);
        // 排序 默认时间倒序
        lqw.orderByDesc(PlatGreenSmart::getCreateTime);
        lqw.last("limit " + limitNum);
        return baseMapper.selectList(lqw);
    }

    /**
     * 根据指定字段查询信息
     *
     * @param field      字段名称
     * @param filedValue 字段值
     * @return 绿智食堂
     */
    @Override
    public PlatGreenSmart getPlatGreenSmartByField(String field, String filedValue) {
        QueryWrapper<PlatGreenSmart> lqw = new QueryWrapper<PlatGreenSmart>();
        lqw.eq(field, filedValue);
        lqw.last("limit 1");
        return this.getOne(lqw, false);
    }

    /**
     * 根据指定字段查询信息
     *
     * @param field      字段名称
     * @param filedValue 字段值
     * @return 绿智食堂
     */
    @Override
    public PlatGreenSmart getPlatGreenSmartByField(String field, String filedValue, String fieldString) {
        QueryWrapper<PlatGreenSmart> lqw = new QueryWrapper<PlatGreenSmart>();
        if(!(Objects.equals(field,"app_org") && Objects.equals(filedValue,"0000"))){
            lqw.eq(field, filedValue);
        }
        lqw.select(fieldString);
        lqw.last("limit 1");
        return this.getOne(lqw, false);
    }

    /**
     * 根据指定字段查询信息列表
     *
     * @param field      字段名称
     * @param filedValue 字段值
     * @return 绿智食堂
     */
    @Override
    public List<PlatGreenSmart> selectPlatGreenSmartListByField(String field, String filedValue, Long limitNum) {
        QueryWrapper<PlatGreenSmart> lqw = new QueryWrapper<PlatGreenSmart>();
        lqw.eq(field, filedValue);
        lqw.last("limit " + limitNum);
        return this.list(lqw);
    }

    /**
     * 根据指定字段查询信息列表
     *
     * @param field      字段名称
     * @param filedValue 字段值
     * @return 绿智食堂
     */
    @Override
    public List<PlatGreenSmart> selectPlatGreenSmartListByField(String field, String filedValue) {
        QueryWrapper<PlatGreenSmart> lqw = new QueryWrapper<PlatGreenSmart>();
        lqw.eq(field, filedValue);
        return this.list(lqw);
    }

    /**
     * 判断指定字段值是否存在
     *
     * @param field      字段名称
     * @param filedValue 字段值
     */
    @Override
    public void checkFieldExist(String field, String filedValue, String tips, Long id) {
        QueryWrapper<PlatGreenSmart> lqw = new QueryWrapper<PlatGreenSmart>();
        lqw.eq(field, filedValue);
        lqw.ne("id", id);
        if (this.getOne(lqw, false) != null) {
            throw new RuntimeException(tips + "已存在");
        }
    }

    /**
     * 真删接口
     */
    @Override
    public void reallyDeletePlatGreenSmart(LambdaQueryWrapper<PlatGreenSmart> lqw) {
        baseMapper.reallyDeleteByWrapper(lqw);
    }

    /**
     * 添加智慧食堂数据
     * 食堂概览
     */
    @Override
    @Transactional
    public void addPlatGreenSmart(String appOrg, Map<String, Object> mapField){
        // 食堂名称 食堂类型（自建、外包） 食堂面积 座位数量 管理人员 厨师人数 服务人员 健康证数量 许可证数量 菜品卫生 菜品口味 服务态度 餐具卫生 菜品种类 就餐体验 其它人员 服务就餐人数
        List<String> keyList = Arrays.asList("canteenName","canteenType","area","seats","management","chefs","service","firstHealth","firstLicence","dishHygiene","tasteDishes","attitude","tableware","typesDishes","dining","personnel","serviceDiners");
        // 先删除所有食堂信息数据
        LambdaQueryWrapper<PlatGreenSmart> lqw = new LambdaQueryWrapper<>();
        lqw.eq(PlatGreenSmart::getAppOrg, appOrg);
        this.reallyDeletePlatGreenSmart(lqw);
        try {
            if(mapField.containsKey("canList")){
                JSONArray canList = JSONArray.parseArray(mapField.get("canList").toString());
                List<PlatGreenSmart> addList = new ArrayList<>();
                for (Object o : canList){
                    Map<String, Object> temp = JSONObject.parseObject(o.toString(), Map.class);
                    PlatGreenSmart smartInfo = new PlatGreenSmart();
                    smartInfo.setAppOrg(appOrg);
                    StringUtils.setFieldValue(smartInfo,temp,keyList,0, PlatGreenSmart::setCanteenNum,String.class);
                    StringUtils.setFieldValue(smartInfo,temp,keyList,1, PlatGreenSmart::setCanteenType,String.class);
                    StringUtils.setFieldValue(smartInfo,temp,keyList,2, PlatGreenSmart::setAreaNum,Long.class);
                    StringUtils.setFieldValue(smartInfo,temp,keyList,3, PlatGreenSmart::setSeatsNum,Long.class);
                    StringUtils.setFieldValue(smartInfo,temp,keyList,4, PlatGreenSmart::setManagementNum,Long.class);
                    StringUtils.setFieldValue(smartInfo,temp,keyList,5, PlatGreenSmart::setChefsNum,Long.class);
                    StringUtils.setFieldValue(smartInfo,temp,keyList,6, PlatGreenSmart::setServiceNum,Long.class);
                    StringUtils.setFieldValue(smartInfo,temp,keyList,7, PlatGreenSmart::setHealthNum,Long.class);
                    StringUtils.setFieldValue(smartInfo,temp,keyList,8, PlatGreenSmart::setLicenceNum,Long.class);
                    StringUtils.setFieldValue(smartInfo,temp,keyList,9, PlatGreenSmart::setDishHygieneScore,Integer.class);
                    StringUtils.setFieldValue(smartInfo,temp,keyList,10, PlatGreenSmart::setTasteDishesScore,Integer.class);
                    StringUtils.setFieldValue(smartInfo,temp,keyList,11, PlatGreenSmart::setAttitudeScore,Integer.class);
                    StringUtils.setFieldValue(smartInfo,temp,keyList,12, PlatGreenSmart::setTablewareScore,Integer.class);
                    StringUtils.setFieldValue(smartInfo,temp,keyList,13, PlatGreenSmart::setTypesDishesScore,Integer.class);
                    StringUtils.setFieldValue(smartInfo,temp,keyList,14, PlatGreenSmart::setDiningScore,Integer.class);
                    StringUtils.setFieldValue(smartInfo,temp,keyList,15, PlatGreenSmart::setPersonnelNum,Long.class);
                    StringUtils.setFieldValue(smartInfo,temp,keyList,16, PlatGreenSmart::setServiceDinersNum,Long.class);
                    addList.add(smartInfo);
                }
                this.saveBatch(addList);
            }
        }catch (Exception e){}

    }

    /**
     * 获取食堂概览
     * @param appOrg
     * @return
     */
    @Override
    public Map<String, Object> getCanteenData(String appOrg){
        String fieldString = "count(id) as canteen_total_number," +
                "count(IF(canteen_type = '自建',true,NULL)) as self_canteen_number," +
                "count(IF(canteen_type = '外包',true,NULL)) as outsource_canteen_number," +
                "sum(seats_num) as seats_num," +
                "sum(area_num) as area_num," +
                "sum(health_num + licence_num) as licence_num," +
                "sum(health_num) as health_num," +
                "sum(service_diners_num) as service_diners_num," +
                "sum(management_num) as management_num," +
                "sum(chefs_num) as chefs_num," +
                "sum(service_num) as service_num,"+
                "sum(personnel_num) as personnel_num";
        PlatGreenSmart smartInfo = this.getPlatGreenSmartByField("app_org", appOrg,fieldString);
        Map<String, Object> tempMap = new HashMap<>();
        if (StringUtils.isNull(smartInfo)) {
            StringUtils.getMapData("食堂数量", "canteenTotalNumber", 0, tempMap);
            StringUtils.getMapData("自建食堂数量", "selfCanteenNumber", 0, tempMap);
            StringUtils.getMapData("外包食堂数量", "outsourceCanteenNumber", 0, tempMap);
            StringUtils.getMapData("座位数量", "seatsNum", 0, tempMap);
            StringUtils.getMapData("食堂面积", "areaNum", 0, tempMap);
            StringUtils.getMapData("许可证数量", "licenceNum", 0, tempMap);
            StringUtils.getMapData("健康证数量", "healthNum", 0, tempMap);
            StringUtils.getMapData("服务就餐人数", "serviceDinersNum", 0, tempMap);
            StringUtils.getMapData("管理人员", "managementNum", 0, tempMap);
            StringUtils.getMapData("厨师人数", "chefsNum", 0, tempMap);
            StringUtils.getMapData("服务人员", "serviceNum", 0, tempMap);
            StringUtils.getMapData("其他人员", "personnelNum", 0, tempMap);
        }else{
            StringUtils.getMapData("食堂数量", "canteenTotalNumber", smartInfo.getCanteenTotalNumber(), tempMap);
            StringUtils.getMapData("自建食堂数量", "selfCanteenNumber", smartInfo.getSelfCanteenNumber(), tempMap);
            StringUtils.getMapData("外包食堂数量", "outsourceCanteenNumber", smartInfo.getOutsourceCanteenNumber(), tempMap);
            StringUtils.getMapData("座位数量", "seatsNum", smartInfo.getSeatsNum(), tempMap);
            StringUtils.getMapData("食堂面积", "areaNum", smartInfo.getAreaNum(), tempMap);
            StringUtils.getMapData("许可证数量", "licenceNum", smartInfo.getLicenceNum(), tempMap);
            StringUtils.getMapData("健康证数量", "healthNum", smartInfo.getHealthNum(), tempMap);
            StringUtils.getMapData("服务就餐人数", "serviceDinersNum", smartInfo.getServiceDinersNum(), tempMap);
            StringUtils.getMapData("管理人员", "managementNum", smartInfo.getManagementNum(), tempMap);
            StringUtils.getMapData("厨师人数", "chefsNum", smartInfo.getChefsNum(), tempMap);
            StringUtils.getMapData("服务人员", "serviceNum", smartInfo.getServiceNum(), tempMap);
            StringUtils.getMapData("其他人员", "personnelNum", smartInfo.getPersonnelNum(), tempMap);
        }
        return tempMap;
    }

    /**
     * 食堂服务满意度
     * @param appOrg
     * @return
     */
    @Override
    public Map<String, Object> getCanteenScoreData(String appOrg){
//        List<String> nameList = Arrays.asList("菜品卫生", "菜品口味", "服务态度", "餐具卫生","菜品种类","就餐体验");
        QueryWrapper<PlatGreenSmart> queryWrapper = new QueryWrapper<>();
        if(!Objects.equals(appOrg,"0000")){
            queryWrapper.eq("app_org",appOrg);
        }
        queryWrapper.last("limit 1");
        PlatGreenSmart smartInfo = this.getOne(queryWrapper);
        Map<String, Object> tempMap = new HashMap<>();
        if (StringUtils.isNull(smartInfo)) {
            StringUtils.getMapData("菜品卫生", "dishScore", 0, tempMap);
            StringUtils.getMapData("菜品口味", "tasteScore", 0, tempMap);
            StringUtils.getMapData("服务态度", "attitudeScore", 0, tempMap);
            StringUtils.getMapData("餐具卫生", "tablewareScore", 0, tempMap);
            StringUtils.getMapData("菜品种类", "typesScore", 0, tempMap);
            StringUtils.getMapData("就餐体验", "diningScore", 0, tempMap);
        }else{
            StringUtils.getMapData("菜品卫生", "dishScore", smartInfo.getDishHygieneScore(), tempMap);
            StringUtils.getMapData("菜品口味", "tasteScore", smartInfo.getTasteDishesScore(), tempMap);
            StringUtils.getMapData("服务态度", "attitudeScore", smartInfo.getAttitudeScore(), tempMap);
            StringUtils.getMapData("餐具卫生", "tablewareScore", smartInfo.getTablewareScore(), tempMap);
            StringUtils.getMapData("菜品种类", "typesScore", smartInfo.getTypesDishesScore(), tempMap);
            StringUtils.getMapData("就餐体验", "diningScore", smartInfo.getDiningScore(), tempMap);
        }
        return tempMap;
    }

    /**
     * 食堂服务满意度排行
     * @param appOrg
     * @return
     */
    public Map<String, Object> getCanteenDegreeData(String appOrg){
        QueryWrapper<PlatGreenSmart> queryWrapper = new QueryWrapper<>();
        int limit = 3;
        if(!Objects.equals(appOrg,"0000")){
            limit = 4;
            queryWrapper.eq("app_org",appOrg);
        }else{
            queryWrapper.ne("app_org","10001");
        }
        queryWrapper.select("canteen_num","(sum(dish_hygiene_score+taste_dishes_score+attitude_score+tableware_score+types_dishes_score+dining_score) / count(id)) as total_score").groupBy("canteen_num").orderByDesc("total_score").last("limit "+limit);
        List<PlatGreenSmart> smartList = this.list(queryWrapper);
        if (smartList.isEmpty()) {
            Map<String,Object> tempMap = new HashMap<>();
            List<Long> canteenNum = new ArrayList<>();
            canteenNum.add(0L);
            List<String> canteenName = new ArrayList<>();
            canteenName.add("");
            StringUtils.createdTableData(canteenName,canteenNum,"#dd8b2c",tempMap);
            return tempMap;
        }

        // 创建一个中文语言环境的 Collator 实例
        Collator collator = Collator.getInstance(Locale.CHINA);

        // 提取 canteenNum 属性并收集到一个新的列表中，同时使用 Collator 进行排序
        List<String> canteenName = smartList.stream()
                .sorted(Comparator.comparing(PlatGreenSmart::getTotalScore).reversed()
                        .thenComparing(smart -> {
                            String firstChar = smart.getCanteenNum().substring(0, 1);
                            return getFirstLetters(firstChar,HanyuPinyinCaseType.UPPERCASE);
                        })
                        .thenComparing(smart -> collator.compare(smart.getCanteenNum(), "")))
                .map(PlatGreenSmart::getCanteenNum)
                .collect(Collectors.toList());

        List<Long> canteenScore = new ArrayList<>();
        for (String value:canteenName){
            for (PlatGreenSmart smart:smartList){
                if(Objects.equals(value,smart.getCanteenNum())){
                    canteenScore.add(smart.getTotalScore() / 6);
                }
            }

        }
        if(Objects.equals(appOrg,"0000")){
            QueryWrapper<PlatGreenSmart> smartQueryWrapper = new QueryWrapper<>();
            smartQueryWrapper.eq("app_org","10001");
            smartQueryWrapper.select("canteen_num","(sum(dish_hygiene_score+taste_dishes_score+attitude_score+tableware_score+types_dishes_score+dining_score) / count(id)) as total_score").groupBy("canteen_num").orderByDesc("total_score").last("limit 1");
            PlatGreenSmart proData = this.getOne(smartQueryWrapper);
            if(StringUtils.isNotNull(proData)){
                canteenScore.add(0,proData.getTotalScore() / 6);
                // 在 canteenName 列表第一位插入数据
                canteenName.add(0,proData.getCanteenNum());
            }

        }
        Map<String,Object> tempMap = new HashMap<>();
        StringUtils.createdTableData(canteenName,canteenScore,"#dd8b2c",tempMap);
        return tempMap;
    }

    public List<Map<String, Object>> getCanteenStaff(String appOrg){
        QueryWrapper<PlatGreenSmart> queryWrapper = new QueryWrapper<>();
        if(!Objects.equals(appOrg,"0000")){
            queryWrapper.eq("app_org",appOrg);
        }
        List<PlatGreenSmart> smartInfo = this.list(queryWrapper);
        List<Map<String, Object>> list = new ArrayList<>();
        if (smartInfo.isEmpty()) {
            Map<String, Object> tempMap = new HashMap<>();
            tempMap.put("canteenName", "");
            tempMap.put("service", 0);
            tempMap.put("chefs", 0);
            list.add(tempMap);
            return list;
        }
        for (PlatGreenSmart it : smartInfo){
            Map<String, Object> tempMap = new HashMap<>();
            if (StringUtils.isNull(it)) {
                tempMap.put("canteenName", "");
                tempMap.put("service", 0);
                tempMap.put("chefs", 0);
            }else{
                tempMap.put("canteenName", it.getCanteenNum());
                tempMap.put("service", it.getServiceNum());
                tempMap.put("chefs", it.getChefsNum());
            }
            list.add(tempMap);
        }
        return list;
    }

    /**
     * 各单位统计排行
     * @param appOrg
     * @return #e2963c  #43dcdb
     */
    public Map<String, Object> getCanteenTotalRank(String appOrg){
        QueryWrapper<PlatGreenSmart> queryWrapper = new QueryWrapper<>();
        int limit = 3;
        if(!Objects.equals(appOrg,"0000")){
            limit = 4;
            queryWrapper.eq("app_org",appOrg);
        }else{
            queryWrapper.ne("app_org","10001");
        }
        queryWrapper.select("sum(chefs_num + service_num) as total_person_num,chefs_num,service_num,canteen_num");
        queryWrapper.groupBy("canteen_num", "chefs_num", "service_num");
        queryWrapper.orderByDesc("total_person_num");
        queryWrapper.last("limit "+ limit);
        List<PlatGreenSmart> smartList = this.list(queryWrapper);
        if(smartList.isEmpty()){
            return new HashMap<>();
        }
        // 创建一个中文语言环境的 Collator 实例
        Collator collator = Collator.getInstance(Locale.CHINA);

        // 提取 canteenNum 属性并收集到一个新的列表中，同时使用 Collator 进行排序
        List<String> canteenNameList = smartList.stream()
                .sorted(Comparator.comparing(PlatGreenSmart::getTotalPersonNum).reversed()
                        .thenComparing(smart -> {
                            String firstChar = smart.getCanteenNum().substring(0, 1);
                            return getFirstLetters(firstChar,HanyuPinyinCaseType.UPPERCASE);
                        })
                        .thenComparing(smart -> collator.compare(smart.getCanteenNum(), "")))
                .map(PlatGreenSmart::getCanteenNum)
                .collect(Collectors.toList());

        List<Long> chefsNumList = new ArrayList<>();
        List<Long> serviceNumList = new ArrayList<>();
        for (String value:canteenNameList){
            for (PlatGreenSmart smart:smartList){
                if(Objects.equals(value,smart.getCanteenNum())){
                    chefsNumList.add(smart.getChefsNum());
                    serviceNumList.add(smart.getServiceNum());
                }
            }

        }
        if(Objects.equals(appOrg,"0000")){
            QueryWrapper<PlatGreenSmart> smartQueryWrapper = new QueryWrapper<>();
            smartQueryWrapper.eq("app_org","10001");
            smartQueryWrapper.select("sum(chefs_num + service_num) as total_person_num,chefs_num,service_num,canteen_num").last("limit 1");
            PlatGreenSmart proData = this.getOne(smartQueryWrapper);
            if(StringUtils.isNotNull(proData)){
                chefsNumList.add(0,proData.getChefsNum());
                serviceNumList.add(0,proData.getServiceNum());
                // 在 canteenName 列表第一位插入数据
                canteenNameList.add(0,proData.getCanteenNum());
            }

        }
        Map<String,Object> yMap = new HashMap<>();
        List<String> colorList = Arrays.asList("#e2963c","#43dcdb");
        List<String> keyList = Arrays.asList("chefs","service");
        List<String> xList = Arrays.asList("厨师","服务员");
        List<List<Long>> yList = Arrays.asList(chefsNumList,serviceNumList);
        for (int i = 0; i < xList.size(); i++){
            Map<String,Object> tempMap = new HashMap<>();
            tempMap.put("name",xList.get(i));
            tempMap.put("color",colorList.get(i));
            tempMap.put("dataList",yList.get(i));
            yMap.put(keyList.get(i),tempMap);
        }
        yMap.put("xList",canteenNameList);
        return yMap;
    }


    public String getFirstLetters(String ChineseLanguage, HanyuPinyinCaseType caseType) {
        char[] cl_chars = ChineseLanguage.trim().toCharArray();
        String hanyupinyin = "";
        HanyuPinyinOutputFormat defaultFormat = new HanyuPinyinOutputFormat();
        defaultFormat.setCaseType(caseType);// 输出拼音全部大写
        defaultFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);// 不带声调
        if(ChineseLanguage.equals("长")){
            hanyupinyin = "C";
        }else{
            try {
                for (int i = 0; i < cl_chars.length; i++) {
                    String str = String.valueOf(cl_chars[i]);
                    if (str.matches("[\u4e00-\u9fa5]+")) {// 如果字符是中文,则将中文转为汉语拼音,并取第一个字母
                        hanyupinyin += PinyinHelper.toHanyuPinyinStringArray(cl_chars[i], defaultFormat)[0].substring(0, 1);
                    } else if (str.matches("[0-9]+")) {// 如果字符是数字,取数字
                        hanyupinyin += cl_chars[i];
                    } else if (str.matches("[a-zA-Z]+")) {// 如果字符是字母,取字母
                        hanyupinyin += cl_chars[i];
                    } else {// 否则不转换
                        hanyupinyin += cl_chars[i];//如果是标点符号的话，带着
                    }
                }
            } catch (BadHanyuPinyinOutputFormatCombination e) {
                System.out.println("字符不能转成汉语拼音");
            }
        }
        System.out.println("拼音+++++++++++++++++++++++" +hanyupinyin);
        return hanyupinyin;
    }


    /**
     * 资质证件
     */
    @Override
    public Map<String, Object> getQualificationData(String appOrg,String canteenName){
        QueryWrapper<PlatGreenSmart> queryWrapper = new QueryWrapper<>();
        if(!Objects.equals(appOrg,"0000")){
            queryWrapper.eq("app_org",appOrg);
        }
        queryWrapper.eq("canteen_num", canteenName);
        queryWrapper.select("sum(health_num) as health_num,sum(licence_num) as licence_num");
        queryWrapper.last("limit 1");
        PlatGreenSmart smartInfo = this.getOne(queryWrapper);
        Map<String, Object> tempMap = new HashMap<>();
        if(StringUtils.isNull(smartInfo)){
            StringUtils.getMapData("健康证", "healthNum", 0, tempMap);
            StringUtils.getMapData("许可证", "licenceNum", 0, tempMap);
        }else{
            StringUtils.getMapData("健康证", "healthNum", smartInfo.getHealthNum(), tempMap);
            StringUtils.getMapData("许可证", "licenceNum", smartInfo.getLicenceNum(), tempMap);
        }
        return tempMap;
    }

    @Override
    public List<PlatGreenSmart> getgreenSmartName(String appOrg) {
        QueryWrapper<PlatGreenSmart> queryWrapper = new QueryWrapper<>();
        List<PlatGreenSmart> smartList = new ArrayList<>();
        if(Objects.equals(appOrg,"0000")){
            queryWrapper.select("canteen_num").ne("app_org","10001").groupBy("canteen_num").last("limit 3");
            smartList = this.list(queryWrapper);
            PlatGreenSmart smartInfo = this.getOne((new QueryWrapper<PlatGreenSmart>()).eq("app_org","10001").select("canteen_num").last("limit 1"));
            if(StringUtils.isNotNull(smartInfo)){
                smartList.add(0,smartInfo);
            }
        }else{
            queryWrapper.select("canteen_num").eq("app_org", appOrg).groupBy("canteen_num").last("limit 4");
            smartList = this.list(queryWrapper);
        }
        return smartList;
    }
}
