package cn.pluss.platform.deviceMerchantBuy.impl;

import java.util.Collections;
import java.util.List;
import java.util.Map;

import cn.pluss.platform.openAccount.OpenAccountRecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.Setter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.pluss.platform.deviceMerchantBuy.DeviceMerchantBuyService;
import cn.pluss.platform.deviceMerchantBuyDetail.DeviceMerchantBuyDetailService;
import cn.pluss.platform.entity.DeviceMerchantBuy;
import cn.pluss.platform.vo.DeviceMerchantBuyDetailVO;
import cn.pluss.platform.vo.DeviceMerchantBuyVO;
import cn.pluss.platform.mapper.DeviceMerchantBuyMapper;

import javax.annotation.Resource;

@Transactional
@Service("deviceMerchantBuyService")
public class DeviceMerchantBuyServiceImpl extends ServiceImpl<DeviceMerchantBuyMapper,DeviceMerchantBuy> implements DeviceMerchantBuyService {

    private static final Logger logger = LoggerFactory.getLogger(DeviceMerchantBuyServiceImpl.class);


    @Setter(onMethod_ = {@Autowired})
    private DeviceMerchantBuyMapper deviceMerchantBuyMapper;

    @Setter(onMethod_ = {@Autowired})
    private DeviceMerchantBuyDetailService deviceMerchantBuyDetailService;

    @Resource
    private OpenAccountRecordService openAccountRecordService;

    @Override
    public DeviceMerchantBuy queryDeviceMerchantBuy(DeviceMerchantBuy deviceMerchantBuy) {
        return deviceMerchantBuyMapper.queryDeviceMerchantBuy(deviceMerchantBuy);
    }

    @Override
    public List<DeviceMerchantBuy> queryDeviceMerchantBuyList(DeviceMerchantBuy deviceMerchantBuy) {
        return deviceMerchantBuyMapper.queryDeviceMerchantBuyList(deviceMerchantBuy);
    }

    @Override
    public void saveDeviceMerchantBuy(DeviceMerchantBuy deviceMerchantBuy) {
        deviceMerchantBuyMapper.saveDeviceMerchantBuy(deviceMerchantBuy);
    }

    @Override
    public void updateDeviceMerchantBuy(DeviceMerchantBuy deviceMerchantBuy) {
        deviceMerchantBuyMapper.updateDeviceMerchantBuy(deviceMerchantBuy);
    }

    @Override
    public void deleteDeviceMerchantBuy(DeviceMerchantBuy deviceMerchantBuy) {
        deviceMerchantBuyMapper.deleteDeviceMerchantBuy(deviceMerchantBuy);
    }

    @Override
    public List<DeviceMerchantBuy> queryDeviceMerchantBuyPage(Map map) {
        return deviceMerchantBuyMapper.queryDeviceMerchantBuyPage(map);
    }

    @Override
    public Integer queryDeviceMerchantBuyPageCount(Map map) {
        return deviceMerchantBuyMapper.queryDeviceMerchantBuyPageCount(map);
    }

    @Override
    public List<DeviceMerchantBuyVO> deviceOrderShowPage(Map<String, Object> map) {
        List<DeviceMerchantBuyVO> deviceOrderShowPage = deviceMerchantBuyMapper.deviceOrderShowPage(map);
        //TODO 以下代码，下次版本删除
        for (DeviceMerchantBuyVO deviceMerchantBuyVO : deviceOrderShowPage) {
            String status = deviceMerchantBuyVO.getStatus();
            // 同步app订单设备状态
            status = "2".equals(status) ? "2" : "0";
            DeviceMerchantBuyDetailVO detailVO = new DeviceMerchantBuyDetailVO();
            detailVO.setStatus(status);
            deviceMerchantBuyVO.setSoleCodeList(Collections.singletonList(detailVO));
        }

        return deviceOrderShowPage;
    }

    @Override
    public Integer deviceOrderShowPageCount(Map<String, Object> map) {
        return deviceMerchantBuyMapper.deviceOrderShowPageCount(map);
    }
}

