package org.jeecg.modules.duxiaoman.service.impl;

import cn.com.ctop.common.module.entity.MaterialAscription;
import cn.com.ctop.common.module.entity.MaterialInfo;
import cn.com.ctop.common.module.entity.MaterialParameter;
import cn.com.ctop.common.module.entity.MaterialTagInfo;
import cn.com.ctop.common.module.entity.Product;
import cn.com.ctop.common.module.entity.Project;
import cn.com.ctop.common.module.entity.TagInfo;
import cn.com.ctop.common.module.mapper.MaterialAscriptionMapper;
import cn.com.ctop.common.module.mapper.MaterialInfoMapper;
import cn.com.ctop.common.module.mapper.MaterialParameterMapper;
import cn.com.ctop.common.module.service.IMaterialCutFrameService;
import cn.com.ctop.common.module.service.IMaterialImageInfoService;
import cn.com.ctop.common.module.service.IMaterialInfoService;
import cn.com.ctop.common.module.service.IMaterialTagInfoService;
import cn.com.ctop.common.module.service.IMessageTemplate;
import cn.com.ctop.common.module.service.IProductService;
import cn.com.ctop.common.module.service.IProjectService;
import cn.com.ctop.common.module.service.ISendMessageService;
import cn.com.ctop.common.module.service.ISysUserService;
import cn.com.ctop.common.module.service.ITagInfoService;
import cn.com.ctop.common.module.utils.Check;
import cn.com.ctop.common.module.utils.CloudVideoProcessUtil;
import cn.com.ctop.common.module.utils.HttpUtils;
import cn.com.ctop.common.module.utils.KuaishouDuXiaoManAPIConstant;
import cn.com.ctop.common.module.utils.KuaishouInterfaceConstant;
import cn.com.ctop.common.module.utils.LoadFileUtil;
import cn.com.ctop.common.module.utils.PropertiesUtils;
import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import it.sauronsoftware.jave.Encoder;
import it.sauronsoftware.jave.MultimediaInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.entity.SysUser;
import org.jeecg.common.util.DateUtils;
import org.jeecg.modules.duxiaoman.entity.DuxiaomanMaterialInfo;
import org.jeecg.modules.duxiaoman.mapper.DuxiaomanMaterialInfoMapper;
import org.jeecg.modules.duxiaoman.service.IDuxiaomanMaterialInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URLDecoder;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 度小满素材信息
 *
 * @author jeecg-boot
 * 2022-08-15
 * @version V1.0
 */
@Slf4j
@Service
public class DuxiaomanMaterialInfoServiceImpl extends ServiceImpl<DuxiaomanMaterialInfoMapper, DuxiaomanMaterialInfo> implements IDuxiaomanMaterialInfoService {

    @Value("${duxiaoman.url}")
    private String duUrl;

    @Value("${duxiaoman.appId}")
    private String duAppId;

    @Value("${duxiaoman.token}")
    private String duToken;

    @Value("${oss.replace.download}")
    private String downloadUrl;

    @Autowired
    private IMaterialInfoService materialInfoService;

    @Autowired
    private IMaterialImageInfoService materialImageInfoService;

    @Resource
    private IMaterialCutFrameService materialCutFrameService;

    @Autowired
    private IMaterialTagInfoService materialTagInfoService;

    @Autowired
    private ITagInfoService tagInfoService;

    @Resource
    private MaterialParameterMapper materialParameterMapper;

    @Resource
    private MaterialInfoMapper materialInfoMapper;

    @Resource
    private MaterialAscriptionMapper materialAscriptionMapper;

    @Autowired
    private ISysUserService userService;

    @Autowired
    private IProjectService projectService;

    @Autowired
    private IProductService productService;

    @Autowired
    private IMessageTemplate messageTemplate;

    @Autowired
    private ISendMessageService sendMessageService;


    static ExecutorService uploadService = Executors.newFixedThreadPool(3);
    private static ExecutorService uploadExecutorService = Executors.newFixedThreadPool(5);

    @Override
    public JSONObject getMaterialChannel() {
        String datetime = new Date().getTime() + "";
        TreeMap<String, Object> params = new TreeMap<>();
        params.put("app_id", duAppId);
        params.put("datetime", datetime);
        StringBuffer md5Str = new StringBuffer();
        md5Str.append("app_id=").append(duAppId)
                .append("&datetime=").append(datetime).append(duToken);
        String sign = DigestUtils.md5Hex(md5Str.toString());
        params.put("sign", sign);
        String resultStr = HttpUtils.httpGetRequest(duUrl + KuaishouDuXiaoManAPIConstant.MATERIAL_CHANNEL, null, params);
        JSONObject resultJson = JSONObject.parseObject(resultStr);
        log.info("----------查询渠道:{}", resultJson);
        return resultJson;
    }

    @Override
    public JSONObject getMaterialType() {
        String datetime = new Date().getTime() + "";
        TreeMap<String, Object> params = new TreeMap<>();
        params.put("app_id", duAppId);
        params.put("datetime", datetime);
        StringBuffer md5Str = new StringBuffer();
        md5Str.append("app_id=").append(duAppId)
                .append("&datetime=").append(datetime).append(duToken);
        String sign = DigestUtils.md5Hex(md5Str.toString());
        params.put("sign", sign);
        String resultStr = HttpUtils.httpGetRequest(duUrl + KuaishouDuXiaoManAPIConstant.MATERIAL_TYPE, null, params);
        JSONObject resultJson = JSONObject.parseObject(resultStr);
        log.info("----------查询通用素材分类:{}", resultJson);
        return resultJson;
    }

    @Override
    public Result<Object> upload(DuxiaomanMaterialInfo materialInfo) {
        try {
            String fileConfigId = "5";
            if ("VIDEO".equals(materialInfo.getType())) {
                fileConfigId = "3";
            }
            String requestUrl = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.VIDEO_UPLOAD;
            String localUrl = LoadFileUtil.downLoadFromUrl(materialInfo.getUrl(), downloadUrl);
            String md5 = LoadFileUtil.getMD5(localUrl);
            String datetime = new Date().getTime() + "";
            JSONObject params = new JSONObject();
            params.put("app_id", duAppId);
            params.put("datetime", datetime);
            params.put("signature", md5);
            params.put("file_config_id", fileConfigId);
            StringBuffer md5Str = new StringBuffer();
            md5Str.append("app_id=").append(duAppId)
                    .append("&datetime=").append(datetime)
                    .append("&file_config_id=").append(fileConfigId)
                    .append("&signature=").append(md5).append(duToken);
            String sign = DigestUtils.md5Hex(md5Str.toString());
            params.put("sign", sign);
            JSONObject resultJson = HttpUtils.fileUpload(duUrl + KuaishouDuXiaoManAPIConstant.MATERIAL_UPLOAD, localUrl, params);
            log.info("----------素材上传:{}", resultJson);
            if (!Check.isNull(resultJson) && resultJson.getInteger("retCode") == 0) {
                JSONObject result = resultJson.getJSONObject("result");
                materialInfo.setFileId(result.getString("file_id"));
                materialInfo.setStatus(7);
                baseMapper.updateById(materialInfo);
                materialReport(materialInfo);
                //7：上传成功
            } else {
                //8：上传失败
                materialInfo.setStatus(8);
                baseMapper.updateById(materialInfo);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Result.ok();
    }


    /**
     * 素材报备
     */
    @Override
    public void materialReport(DuxiaomanMaterialInfo materialInfo) {
        try {
            //素材分类: 1110004-视频,1110006-脚本
            String type = "1110006";
            if ("VIDEO".equals(materialInfo.getType())) {
                type = "1110004";
            }

            String datetime = new Date().getTime() + "";
            TreeMap<String, Object> params = new TreeMap<>();
            params.put("app_id", duAppId);
            params.put("datetime", datetime);
            //渠道id 快手-3715834215185534246 ,今日头条-3715778792927469631, 微信支付-3715834386984222891
            params.put("channel_id", "3715834215185534246");
            //素材分类: 1110004-视频,1110006-脚本
            params.put("type", type);
            //素材文件id
            params.put("file_ids", materialInfo.getFileId());
            //素材中使用的版权内容已获得有效书面授权书 默认值 1
            params.put("authorize", "1");
            params.put("description", materialInfo.getMaterialName());
            StringBuffer md5Str = new StringBuffer();
            if (Check.isNull(materialInfo.getAuditTaskId())) {
                md5Str.append("app_id=").append(duAppId)
                        .append("&authorize=1")
                        .append("&channel_id=").append("3715834215185534246")
                        .append("&datetime=").append(datetime)
                        .append("&description=").append(materialInfo.getMaterialName())
                        .append("&file_ids=").append(materialInfo.getFileId())
                        .append("&type=").append(type).append(duToken);
                String sign = DigestUtils.md5Hex(md5Str.toString());
                params.put("sign", sign);
                String resultStr = HttpUtils.httpPostRequest(duUrl + KuaishouDuXiaoManAPIConstant.MATERIAL_REPORT, params, null);
                JSONObject resultJson = JSONObject.parseObject(resultStr);
                log.info("----------素材报备:{}", resultJson);
                if ((!Check.isNull(resultJson) && resultJson.getInteger("retCode") == 0)
                        || (!Check.isNull(resultJson) && resultJson.getInteger("retCode") == 1 && resultJson.getString("retMsg").contains("已送审"))) {
                    //2：审批中
                    materialInfo.setStatus(2);
                    materialInfo.setAuditTaskId(resultJson.getString("result"));
                    baseMapper.updateById(materialInfo);
                }
            } else {
                md5Str.append("app_id=").append(duAppId)
                        .append("&authorize=1")
                        .append("&channel_id=").append("3715834215185534246")
                        .append("&datetime=").append(datetime)
                        .append("&description=").append(materialInfo.getMaterialName())
                        .append("&file_ids=").append(materialInfo.getFileId())
                        .append("&id=").append(materialInfo.getAuditTaskId())
                        .append("&type=").append(type).append(duToken);
                String sign = DigestUtils.md5Hex(md5Str.toString());
                params.put("sign", sign);
                params.put("id", materialInfo.getAuditTaskId());
                String resultStr = HttpUtils.httpPostRequest(duUrl + KuaishouDuXiaoManAPIConstant.MATERIAL_UPDATE, params, null);
                JSONObject resultJson = JSONObject.parseObject(resultStr);
                log.info("----------更新任务:{}", resultJson);
                if ((!Check.isNull(resultJson) && resultJson.getInteger("retCode") == 0)
                        || (!Check.isNull(resultJson) && resultJson.getInteger("retCode") == 1 && resultJson.getString("retMsg").contains("已送审"))) {
                    //2：审批中
                    materialInfo.setStatus(2);
//                    materialInfo.setAuditTaskId(resultJson.getString("result"));
                    baseMapper.updateById(materialInfo);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    /**
     * 查询报备状态
     */
    @Override
    public void materialDetail(DuxiaomanMaterialInfo materialInfo) {
        try {
            String datetime = new Date().getTime() + "";
            TreeMap<String, Object> params = new TreeMap<>();
            params.put("app_id", duAppId);
            params.put("datetime", datetime);
            //审核任务 id
            params.put("id", materialInfo.getAuditTaskId());
            StringBuffer md5Str = new StringBuffer();
            md5Str.append("app_id=").append(duAppId)
                    .append("&datetime=").append(datetime)
                    .append("&id=").append(materialInfo.getAuditTaskId()).append(duToken);
            String sign = DigestUtils.md5Hex(md5Str.toString());
            params.put("sign", sign);
            String resultStr = HttpUtils.httpPostRequest(duUrl + KuaishouDuXiaoManAPIConstant.MATERIAL_DETAIL, params, null);
            JSONObject resultJson = JSONObject.parseObject(resultStr);
            log.info("----------查询报备状态:{}", resultJson);
            if (!Check.isNull(resultJson) && resultJson.getInteger("retCode") == 0) {
                JSONObject result = resultJson.getJSONObject("result");
                Integer auditStatus = result.getInteger("audit_status");
                auditStatus = auditStatus == 1 ? 101 : auditStatus;
                QueryWrapper<DuxiaomanMaterialInfo> queryWrapper = new QueryWrapper<>();
                queryWrapper.eq("audit_task_id", materialInfo.getAuditTaskId());
                queryWrapper.orderByDesc("create_time");
                queryWrapper.last("limit 1");
                DuxiaomanMaterialInfo info = baseMapper.selectOne(queryWrapper);
                if (!Check.isNull(info) && auditStatus == info.getStatus()) {
                    return;
                }
                materialInfo.setStatus(auditStatus);
                materialInfo.setConfirmTime(result.getString("audit_time"));
                materialInfo.setRefuseReason(result.getString("audit_reason"));
                //3 审核通过 同步到素材表
                if (auditStatus == 3) {
                    syncMaterial(materialInfo);
                }
                if (auditStatus == 4) {
                    Project project = projectService.getById(materialInfo.getProjectId());
                    String text = messageTemplate.getDuXiaoManMaterialTemplate(materialInfo.getProductName(), project.getProjectName(), materialInfo.getMaterialName(), materialInfo.getRefuseReason(), false);
                    sendMessageService.sendMessage(materialInfo.getUserId(), text);
                    JSONArray auditImages = result.getJSONArray("audit_images");
                    if (!Check.isNull(auditImages)) {
                        String auditImagesIds = "";
                        for (int i = 0; i < auditImages.size(); i++) {
                            JSONObject json = auditImages.getJSONObject(i);
                            auditImagesIds += json.getString("id") + ",";
                        }
                        materialInfo.setAuditImagesId(auditImagesIds.substring(0, auditImagesIds.length() - 1));
                    }
                }

                if ("SCRIPT".equals(materialInfo.getType())) {
                    Project project = projectService.getById(materialInfo.getProjectId());
                    String text = null;
                    if (auditStatus == 4) {
                        text = messageTemplate.getDuXiaoManScriptTemplate(materialInfo.getProductName(), project.getProjectName(), materialInfo.getMaterialName(), materialInfo.getRefuseReason(), false);
                    } else if (auditStatus == 3) {
                        text = messageTemplate.getDuXiaoManScriptTemplate(materialInfo.getProductName(), project.getProjectName(), materialInfo.getMaterialName(), materialInfo.getRefuseReason(), true);
                    }
                    sendMessageService.sendMessage(materialInfo.getUserId(), text);
                }
            } else {
                JSONObject result = resultJson.getJSONObject("result");
                materialInfo.setStatus(result.getInteger("audit_status"));
                materialInfo.setConfirmTime(result.getString("audit_time"));
                materialInfo.setRefuseReason(result.getString("audit_reason"));
                if ("SCRIPT".equals(materialInfo.getType()) && materialInfo.getStatus() == 4) {
                    Project project = projectService.getById(materialInfo.getProjectId());
                    String text = messageTemplate.getDuXiaoManMaterialTemplate(materialInfo.getProductName(), project.getProjectName(), materialInfo.getMaterialName(), materialInfo.getRefuseReason(), false);
                    sendMessageService.sendMessage(materialInfo.getUserId(), text);
                }
            }
            baseMapper.updateById(materialInfo);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    /**
     * 将审核通过的素材同步到 ctop_material_info 表中
     */
    private void syncMaterial(DuxiaomanMaterialInfo materialInfo) {
        MaterialInfo info = new MaterialInfo();
        BeanUtil.copyProperties(materialInfo, info);
        info.setStatus(1);
        info.setCode(materialInfo.getSignature());
        info.setType("VIDEO");
        info.setId(UUID.randomUUID().toString());
        materialInfoService.save(info);
        getFile(info);

    }

    @Override
    public void uploadMaterial(DuxiaomanMaterialInfo materialInfo) {
        uploadService.submit(new Runnable() {
            @Override
            public void run() {
                upload(materialInfo);
            }
        });
    }


    @Override
    public Result<Object> add(JSONObject json) {
        try {
            String userId = json.getString("userId");
            String signature = json.getString("signature");
            String url = json.getString("url");
            if (!json.getString("url").contains("https")) {
                url = "https:" + json.getString("url");
            }
            DuxiaomanMaterialInfo info = new DuxiaomanMaterialInfo();
            Long projectId = json.getLong("projectId");
            Project project = projectService.getById(projectId);
            if (!Check.isNull(project)) {
                info.setProductId(project.getProductId());
                info.setProjectName(project.getProjectName());
                Product product = productService.getById(info.getProductId());
                if (!Check.isNull(product)) {
                    info.setProductName(product.getProductName());
                }
            }

            info.setId(UUID.randomUUID().toString().replace("-", ""));
            info.setStatDate(DateUtils.formatDate(new Date()));
            info.setSignature(signature);
            info.setUrl(url);
            info.setUserId(userId);
            info.setProjectId(projectId);
            info.setStatus(0);
            info.setMaterialName(json.getString("materialName"));
            info.setMaterialDescribe(json.getString("materialDescribe"));
            info.setType(json.getString("type"));
            String videoUrl = URLDecoder.decode(info.getUrl()).replace("https://media-1301855440.cos.ap-chongqing.myqcloud.com/", "");
            String loadImage = "cutFrame/" + signature + "/zero.jpg";
            try {
                String coverUrl = CloudVideoProcessUtil.videoCutPictureHandle(videoUrl, loadImage);
                info.setCoverUrl(coverUrl);
            } catch (Exception e) {
                e.printStackTrace();
            }
            this.save(info);

            Map<String, Object> deleteMap = new HashMap<>();
            deleteMap.put("material_id", info.getSignature());
            JSONObject ascription = json.getJSONObject("ascription");
            if (!Check.isNull(ascription)) {
                MaterialAscription materialAscription = new MaterialAscription();
                materialAscription.setMaterialId(info.getSignature());
                String clipId = ascription.getString("clipId");
                if (null != clipId && !"".equals(clipId.trim())) {
                    materialAscription.setClipId(clipId);
                }
                materialAscription.setShotId(ascription.getString("shotId"));
                materialAscription.setPlanId(ascription.getString("planId"));
                materialAscription.setPlaneId(ascription.getString("planeId"));
                materialAscription.setCode(info.getSignature());
                materialAscriptionMapper.deleteByMap(deleteMap);
                //TODO 需要添加获取设计负责人代码
                SysUser clip = userService.getById(clipId);
                String roleCode = userService.getRoleCodeByUserId(clipId);
                String leaderName = "";
                String leaderId = "";
                if ("designTeamLeader".equals(roleCode)) {
                    leaderId = clipId;

                    leaderName = clip.getRealname();
                } else {
                    leaderId = clip.getLeaderId();
                    leaderName = clip.getLeaderName();
                }
                materialAscription.setLeaderName(leaderName);
                materialAscription.setLeaderId(leaderId);
                int result = materialAscriptionMapper.insert(materialAscription);
            }
            materialTagInfoService.deleteByCode(signature);
            JSONArray modalityTagList = json.getJSONArray("modalityTagList");
            insertTagList(signature, userId, modalityTagList);
            JSONArray contentTagList = json.getJSONArray("contentTagList");
            insertTagList(signature, userId, contentTagList);
            JSONArray senceTagList = json.getJSONArray("senceTagList");
            insertTagList(signature, userId, senceTagList);
            JSONArray modTagList = json.getJSONArray("modTagList");
            insertTagList(signature, userId, modTagList);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("fail," + e.getMessage());
        }
        return Result.ok("success");
    }
    /**
     * 添加标签
     */
    private void insertTagList(String code, String userId, JSONArray tagList) {
        if (null != tagList && !tagList.isEmpty()) {
            for (int m = 0; m < tagList.size(); m++) {
                Long tagId = tagList.getLong(m);
                TagInfo tagInfo = tagInfoService.getById(tagId);
                MaterialTagInfo setTag = new MaterialTagInfo(code, tagInfo, userId);
                setTag.setCategoryId(tagInfo.getTagCategoryId());
                materialTagInfoService.save(setTag);
            }
        }
    }


    /**
     * 录入素材信息
     */
    public void getFile(MaterialInfo materialInfo) {
        uploadExecutorService.submit(new Runnable() {
            @Override
            public void run() {
                log.info("获取素材基本信息，code:{}", materialInfo.getCode());
                String url = materialInfo.getUrl();
                log.info("replaceUrl:{}", url);
                String localUrl = null;
                MultimediaInfo m = null;
                FileInputStream fis = null;
                try {
                    localUrl = LoadFileUtil.downLoadFromUrl(url, downloadUrl);
                    File file = new File(localUrl);
                    it.sauronsoftware.jave.Encoder encoder = new Encoder();
                    m = encoder.getInfo(file);
                    long duration = m.getDuration();
                    long secondDuration = duration / 1000;
                    MaterialParameter materialParameter = new MaterialParameter();
                    materialParameter.setMaterialId(materialInfo.getCode());
                    // 视频秒数
                    materialParameter.setSecond(secondDuration);
                    // 视频格式
                    materialParameter.setFormat(m.getFormat());
                    // 视频宽
                    String width = String.valueOf(m.getVideo().getSize().getWidth());
                    materialParameter.setWidth(width);
                    // 视频高
                    String height = String.valueOf(m.getVideo().getSize().getHeight());
                    materialParameter.setHeight(height);
                    fis = new FileInputStream(file);
                    FileChannel fc = fis.getChannel();
                    BigDecimal fileSize = new BigDecimal(fc.size());
                    String size = fileSize.divide(new BigDecimal(1048576), 2, RoundingMode.HALF_UP) + "MB";
                    materialParameter.setSize(size);
                    materialParameter.setUpdateTime(new Date());

                    Map<String, Object> deleteMap = new HashMap<>();
                    deleteMap.put("material_id", materialInfo.getId());
                    materialParameterMapper.deleteByMap(deleteMap);
                    int insert = materialParameterMapper.insert(materialParameter);
                    // 默认抽帧 素造供应商
                 /*   Long templateId = MaterialSupplierEnum.getTemplateIdBySize(Integer.valueOf(width), Integer.valueOf(height));
                    if (!Check.isNull(templateId)) {
                        Thread thread = new Thread() {
                            @Override
                            public void run() {
                                watermarkVideoBySupplierCode(materialInfo.getCode(), materialInfo.getUrl(), templateId);
                            }
                        };
                        thread.start();
                    }*/
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    try {
                        if (fis != null) {
                            fis.close();
                        }
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    LoadFileUtil.delFile(localUrl);
                }
            }
        });
    }

    @Override
    public Result<Object> getPersonnelInfo(DuxiaomanMaterialInfo info) {
        JSONObject obj = new JSONObject();
        if (!Check.isNull(info.getAuditorId())) {
            String auditorName = materialInfoMapper.selectUserNameById(info.getAuditorId());
            obj.put("auditorName", auditorName);
        } else {
            obj.put("auditorName", "");
        }
        obj.put("info", info);
        List<String> tagList = materialTagInfoService.getByCode(info.getSignature());
        if (!Check.isNull(tagList)) {
            obj.put("tag", tagList);
        }
        QueryWrapper<MaterialParameter> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("material_id", info.getSignature());
        queryWrapper.orderByDesc("create_time");
        queryWrapper.last("limit 1");
        MaterialParameter materialParameter = materialParameterMapper.selectOne(queryWrapper);
        if (!Check.isNull(materialParameter)) {
            obj.put("parameter", materialParameter);
        }
        JSONObject ascriptionJson = materialAscriptionMapper.selectByMaterialId(info.getSignature());
        if (!Check.isNull(ascriptionJson)) {
            obj.put("ascription", ascriptionJson);
        }
        return Result.ok(obj);
    }


    /**
     * 审核图片预览
     */
    @Override
    public Result<Object> materialBos(String ids) {
        try {
            List<String> idList = new ArrayList<>();
            String[] split = ids.split(",");
            for (String id : split) {
                String datetime = new Date().getTime() + "";
                StringBuffer md5Str = new StringBuffer();
                md5Str.append("app_id=").append("1660012052762")
                        .append("&datetime=").append(datetime)
                        .append("&id=").append(id).append("1f8a5a1cbd4d626a2aa197b86f6cab8a");
                String sign = DigestUtils.md5Hex(md5Str.toString());
                StringBuffer urlStr = new StringBuffer();
                urlStr.append(duUrl + KuaishouDuXiaoManAPIConstant.MATERIAL_BOS).append("?")
                        .append("app_id=").append("1660012052762")
                        .append("&datetime=").append(datetime)
                        .append("&sign=").append(sign)
                        .append("&id=").append(id);
                idList.add(urlStr.toString());
            }
            return Result.ok(idList);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

}
