/**
 * Copyright 2019 DH
 * All right reserved.
 * 项目名称: 大恒泰山系统
 * 创建日期:2022/8/22
 */
package org.springblade.modules.business.check.order.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.order.entity.CheckOrderInfoEntity;
import org.springblade.modules.business.check.order.vo.CheckOrderInfoVO;
import org.springblade.modules.business.project.base.entity.ProjectInfoEntity;
import org.springblade.modules.business.project.base.vo.ProjectInfoVO;
import org.springblade.modules.business.project.base.wrapper.ProjectInfoWrapper;
import org.springblade.modules.business.rtu.base.vo.RtuInfoVO;
import org.springblade.modules.system.entity.DictBiz;

import java.time.Duration;
import java.util.*;

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

	@Override
	public CheckOrderInfoVO entityVO(CheckOrderInfoEntity entity) {
		CheckOrderInfoVO checkOrderInfoVO = Objects.requireNonNull(BeanUtil.copy(entity, CheckOrderInfoVO.class));
		DictBiz biz=DictBizCache.getById(checkOrderInfoVO.getOrderFromKey());
		checkOrderInfoVO.setOrderFromName(biz.getDictValue());
		biz=DictBizCache.getById(checkOrderInfoVO.getOrderStatusKey());
		checkOrderInfoVO.setOrderStatusName(biz.getDictValue());
		if (checkOrderInfoVO.getOrderConfirmUser() != null){
			checkOrderInfoVO.setIsConfirm(1);
		}else{
			checkOrderInfoVO.setIsConfirm(0);
		}
		if (checkOrderInfoVO.getOrderConfirmTime()!=null) {
			Duration duration = Func.between(checkOrderInfoVO.getOrderConfirmTime(), new Date());
			long second = duration.getSeconds();
			String taskTime = "";
			if (second >= 60 * 60) {
				if (second >= 24 * 60 * 60) {
					taskTime = "" + second / (24 * 60 * 60) + "天";
					second = second % (24 * 60 * 60);
				}
				if (second >= 60 * 60) {
					taskTime += "" + second / (60 * 60) + "小时";
					second = second % (60 * 60);
				}
				if (second >= 60) {
					taskTime += "" + second / (60) + "分";
				}
			} else {
				taskTime = "1小时内";
			}
			checkOrderInfoVO.setTaskTime(taskTime);
		}
		return checkOrderInfoVO;
	}

	public CheckOrderInfoVO addInfoVO(CheckOrderInfoVO checkOrderInfoVO) {
		checkOrderInfoVO.setAreaName(checkOrderInfoVO.getAdCity() + "/" + checkOrderInfoVO.getAdDist());
		DictBiz biz=DictBizCache.getById(checkOrderInfoVO.getOrderFromKey());
		checkOrderInfoVO.setOrderFromName(biz.getDictValue());
		biz=DictBizCache.getById(checkOrderInfoVO.getOrderStatusKey());
		checkOrderInfoVO.setOrderStatusName(biz.getDictValue());
		if (checkOrderInfoVO.getOrderConfirmUser() != null){
			checkOrderInfoVO.setIsConfirm(1);
		}else{
			checkOrderInfoVO.setIsConfirm(0);
		}
		if (checkOrderInfoVO.getOrderConfirmTime()!=null) {
			Duration duration = Func.between(checkOrderInfoVO.getOrderConfirmTime(), new Date());
			long second = duration.getSeconds();
			String taskTime = "";
			if (second >= 60 * 60) {
				if (second >= 24 * 60 * 60) {
					taskTime = "" + second / (24 * 60 * 60) + "天";
					second = second % (24 * 60 * 60);
				}
				if (second >= 60 * 60) {
					taskTime += "" + second / (60 * 60) + "小时";
					second = second % (60 * 60);
				}
				if (second >= 60) {
					taskTime += "" + second / (60) + "分";
				}
			} else {
				taskTime = "1小时内";
			}
			checkOrderInfoVO.setTaskTime(taskTime);
		}
		return checkOrderInfoVO;
	}

}
