package org.ta.pddserver.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.ta.pdd.entity.CollectOrderEntity;
import org.ta.pddserver.mapper.CollectOrderMapper;
import org.ta.pddserver.model.api.request.CollectOrderListRequest;
import org.ta.pddserver.model.api.response.CollectOrderInfoResponse;
import org.ta.pddserver.model.api.response.CollectOrderListResponse;
import org.ta.pddserver.model.api.response.CollectOrderResponse;
import org.ta.pddserver.service.CollectOrderService;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CollectOrderImpl extends ServiceImpl<CollectOrderMapper, CollectOrderEntity> implements CollectOrderService {


    public CollectOrderResponse getByOrderCode(String orderCode) {
        return this.baseMapper.findByOrderCode(orderCode);
    }

    public int updateOrderStatus(int status, String uid) {
        return this.baseMapper.updateOrderStatusById(status, uid);
    }

    public Map getList(CollectOrderListRequest param) {
        if(param.getNum() == 0){
            param.setStr(" AND a.`num` = 0");
        }else if(param.getNum() == 1){
            param.setStr(" AND a.`num` > 0");
        }else {
            param.setStr("");
        }

        Integer count = baseMapper.countUsable(param);
        param.checkPage(count,20);
        List<CollectOrderListResponse> list = baseMapper.getListByRequest(param);
        Map<String, Object> map = new HashMap<>();
        map.put("total", count);
        map.put("list", list);
        map.put("page", param.getPage());
        return map;
    }

    public Map getUnprintList(CollectOrderListRequest param) {
        List<CollectOrderListResponse> list = baseMapper.getUnprintListByRequest(param);
        Map<String, Object> map = new HashMap<>();
        map.put("total", list.size());
        map.put("list", list);
        return map;
    }

    public CollectOrderInfoResponse getInfoByOrderCode(String orderCode) {
        return baseMapper.getInfoByOrderCode(orderCode);
    }

    public CollectOrderEntity getAllInfoByOrderCode(String orderCode) {
        return baseMapper.getAllInfoByOrderCode(orderCode);
    }

    public int updatePrintNum(int num, String orderCode) {
        return this.baseMapper.updatePrintNum(num, orderCode);
    }

    public int updateStatusByOrderCode(Integer status, String orderCode) {
        return this.baseMapper.updateStatusBuOrderCode(status, orderCode);
    }

    public Integer deleteByOrderCode(String orderCode) {
        return this.baseMapper.deleteByOrderCode(orderCode);
    }
}