package com.chy.borrow.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.chy.borrow.entity.BorrowDownload;
import com.chy.borrow.mapper.BorrowApplyMapper;
import com.chy.borrow.mapper.BorrowDownloadMapper;
import com.chy.borrow.service.BorrowDownloadService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.shanghaigeography.entity.ResultMsg;
import com.shanghaigeography.eum.ResultState;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 沈晔浩
 * @since 2022-04-07
 */
@Service
public class BorrowDownloadServiceImpl extends ServiceImpl<BorrowDownloadMapper, BorrowDownload> implements BorrowDownloadService {


    @Autowired
    BorrowDownloadMapper borrowDownloadMapper;

    @Override
    public String getList(Map map) {
        try {
            Integer current = Integer.valueOf(map.get("current").toString());
            Integer pageSize = Integer.valueOf(map.get("pageSize").toString());
            PageHelper.startPage(current, pageSize);
            Page<Map> list = borrowDownloadMapper.getList(map);
            if (list!=null) {
                return new ResultMsg<>(ResultState.SUCCESS, null, JSONObject.toJSONString(list), list.getPageNum(), list.getTotal(), list.getPageSize(), list.getPages()).toPageJSON();
            }
        }catch (Exception e){
            return new ResultMsg<String>().setCode(ResultState.ERROR).setMsg("服务器出错").toJSON();
        }
        return new ResultMsg<String>().setCode(ResultState.SUCCESS).setMsg("无数据").toJSON();
    }
}
