package cn.com.countrygarden.bi.main.service.mediaResource.impl;


import cn.com.countrygarden.bi.main.constant.mediaResource.MediaResourceConstant;
import cn.com.countrygarden.bi.main.core.AbstractService;
import cn.com.countrygarden.bi.main.dao.mediaResource.MediaOrderBillMapper;
import cn.com.countrygarden.bi.main.dao.mediaResource.MediaOrderRunBillMapper;
import cn.com.countrygarden.bi.main.dto.mediaResource.MediaOrderRunBillDto;
import cn.com.countrygarden.bi.main.model.PageData;
import cn.com.countrygarden.bi.main.model.mediaResource.MediaOrderBill;
import cn.com.countrygarden.bi.main.model.mediaResource.MediaOrderRun;
import cn.com.countrygarden.bi.main.service.mediaResource.MediaOrderRunService;
import cn.com.countrygarden.bi.main.util.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <pre>
 *  媒体资源订单服务
 * </pre>
 *
 * @author ferren  liao-r@neusoft.com
 * @version 1.00.00
 * <p>
 * <p>
 * <pre>
 * 修改记录
 *    修改后版本:     修改人：  修改日期:     修改内容:
 * </pre>
 */
@Service
public class MediaOrderRunServiceImpl extends AbstractService<MediaOrderRun> implements MediaOrderRunService {
    @Autowired
    private MediaOrderBillMapper mediaOrderBillMapper;

    @Autowired
    private MediaOrderRunBillMapper mediaOrderRunBillMapper;

    @Override
    public PageData select(MediaOrderRunBillDto param) {
       /* PageUtil.setPageOffset(param);
        List<MediaOrderDto> list = mediaOrderRunMapper.findList(param);
        Long total = mediaOrderRunMapper.findCount(param);*/
        return null;// PageUtil.setPageData(param, total, list);
    }

    @Override
    public PageData selectBillPageList(MediaOrderRunBillDto param) {
        PageUtil.setPageOffset(param);
        List<MediaOrderRunBillDto> list = mediaOrderRunBillMapper.findList(param);
        setNameOfOrder(list);
        Long total = mediaOrderRunBillMapper.findCount(param);
        return PageUtil.setPageData(param, total, list);
    }

    /**
     * 转换码值
     *
     * @param list
     * @return
     */
    private List<MediaOrderRunBillDto> setNameOfOrder(List<MediaOrderRunBillDto> list) {
        for (MediaOrderRunBillDto orderDto : list) {
            // 媒体类型
            Integer mediaType = orderDto.getMediaType();
            String mediaTypeName = MediaResourceConstant.MEDIA_TYPE.DES.getOrDefault(mediaType, "");
            orderDto.setMediaTypeName(mediaTypeName);
            // 客户类型
            Integer customerType = orderDto.getCustomerType();
            String customerTypeName = MediaResourceConstant.CUSTOMER_TYPE.DES.getOrDefault(customerType, "");
            orderDto.setCustomerTypeName(customerTypeName);
            // 订单状态
            MediaOrderBill orderBill = mediaOrderBillMapper.selectByPrimaryKey(orderDto.getOrderBillId());
            if (orderBill != null) {
                if (Integer.valueOf(1).equals(orderBill.isFinal)) {
                    orderDto.setOrderStatus(MediaResourceConstant.ORDER_STATUS_TYPE.FINAL);
                }
            }

            Integer orderStatus = orderDto.getOrderStatus();
            String orderStatusName = MediaResourceConstant.ORDER_STATUS_TYPE.DES.getOrDefault(orderStatus, "");
            orderDto.setOrderStatusName(orderStatusName);
        }
        return list;
    }
}
