package org.ta.pddserver.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.ta.pdd.entity.UnpackNoticeEntity;
import org.ta.pddserver.mapper.UnpackNoticeMapper;
import org.ta.pddserver.model.api.request.UnpackNoticeListRequest;
import org.ta.pddserver.model.api.response.UnpackNoticeListResponse;
import org.ta.pddserver.service.UnpackNoticeService;

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

@Service
public class UnpackNoticeImpl extends ServiceImpl<UnpackNoticeMapper, UnpackNoticeEntity> implements UnpackNoticeService {


    public UnpackNoticeEntity getByCode(String orderCode) {
        return this.baseMapper.selectByOrderCode(orderCode);
    }

    public Map<String, Object> getListByRequest(UnpackNoticeListRequest param) {
        if(param.getNum() == 0){
            param.setStr("`num` = 0");
        }else if(param.getNum() == 1){
            param.setStr("`num` > 0");
        }else {
            param.setStr("");
        }

        Integer count = baseMapper.countUsable(param);
        param.checkPage(count,20);
        List<UnpackNoticeListResponse> 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<String, Object> getUnprintListByRequest(UnpackNoticeListRequest param) {
        List<UnpackNoticeListResponse> list = baseMapper.getUnprintListByRequest(param);
        Map<String, Object> map = new HashMap<>();
        map.put("total", list.size());
        map.put("list", list);
        return map;
    }

    public void updateStatusByOrderCode(String orderCode, int status) {
        baseMapper.updateStatusByOrderCode(orderCode, status);
    }

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

    public Long countFromDate(String today) {
        return this.baseMapper.countFromDate(today);
    }

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