/**
 * Copyright 2019 DH
 * All right reserved.
 * 项目名称: 大恒泰山系统
 * 创建日期:2022/8/22
 */
package org.springblade.modules.business.check.process.wrapper;

import org.springblade.common.cache.DictBizCache;
import org.springblade.core.mp.support.BaseEntityWrapper;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.business.check.process.entity.OrderProcessInfoEntity;
import org.springblade.modules.business.check.process.vo.OrderProcessInfoVO;
import org.springblade.modules.system.entity.DictBiz;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/***
 * Date:2022/8/22
 * Title:文件所属模块（必须填写）
 * Description：对本文件的详细描述，原则上不能少于30字
 * @author dylan
 * @version 1.0
 * Remark：认为有必要的其他信息
 */
public class RtuOrderProcessWrapper extends BaseEntityWrapper<OrderProcessInfoEntity, OrderProcessInfoVO> {
    public static RtuOrderProcessWrapper build() {
        return new RtuOrderProcessWrapper();
    }

    @Override
    public OrderProcessInfoVO entityVO(OrderProcessInfoEntity entity) {
        OrderProcessInfoVO orderProcessInfoVO = Objects.requireNonNull(BeanUtil.copy(entity, OrderProcessInfoVO.class));
        return this.entityVO(orderProcessInfoVO);
    }

    public OrderProcessInfoVO entityVO(OrderProcessInfoVO orderProcessInfoVO) {
        if (Func.notNull(orderProcessInfoVO.getOrderStatusKey())) {
            DictBiz biz = DictBizCache.getById(orderProcessInfoVO.getOrderStatusKey());
            orderProcessInfoVO.setOrderStatusCode(biz.getDictKey());
            orderProcessInfoVO.setOrderStatusName(biz.getDictValue());
        }
        if (Func.notNull(orderProcessInfoVO.getFailureProcessPhotos())) {
            String[] photos = orderProcessInfoVO.getFailureProcessPhotos().split(",");
            List<String> photoList = new ArrayList<>();
            for (String p : photos) {
                photoList.add(p);
            }
            orderProcessInfoVO.setFailureProcessPhotoList(photoList);
        }
        if (Func.notNull(orderProcessInfoVO.getFailureProcessVideos())) {
            String[] videos = orderProcessInfoVO.getFailureProcessVideos().split(",");
            List<String> videoList = new ArrayList<>();
            for (String p : videos) {
                videoList.add(p);
            }
            orderProcessInfoVO.setFailureProcessVideoList(videoList);
        }
        return orderProcessInfoVO;
    }
}
