package org.ta.pddserver.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.ta.pddserver.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(" AND `num` = 0");
        }else if(param.getNum() == 1){
            param.setStr(" AND `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 void updateStatusByOrderCode(String orderCode, int status) {
        baseMapper.updateStatusByOrderCode(orderCode, status);
    }
}