package com.mosty.qwzx.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mosty.base.model.dto.qwzx.TbQwMfjSearchDto;
import com.mosty.common.token.UserInfo;
import com.mosty.common.token.UserInfoManager;
import com.mosty.common.util.PermissionsUtil;
import com.mosty.qwzx.mapper.QwzxQwlbMapper;
import com.mosty.qwzx.mapper.QwzxStatisticsMapper;
import com.mosty.qwzx.remote.TbBaseAdaptRemoteService;
import com.mosty.qwzx.service.QwzxQwlbService;
import com.mosty.qwzx.service.QwzxStatisticsService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

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

@Service
@AllArgsConstructor
public class QwzxQwlbServiceImpl implements QwzxQwlbService {

    private final QwzxQwlbMapper qwzxQwlbMapper;
    private final TbBaseAdaptRemoteService tbBaseAdaptRemoteService;

    @Override
    public List<Map<String, Object>> bzgjlqd(TbQwMfjSearchDto dto) {
        Map<String, Object> map = new HashMap<>();
//        UserInfo user = UserInfoManager.get();
//        map.put("useSql", PermissionsUtil.createSql("", user));
        dto.setSsbmdm(tbBaseAdaptRemoteService.getSsbm(dto.getSsbmdm(), null));
        map.put("dto", dto);
        return this.qwzxQwlbMapper.qxjMjlb(map);
    }

    @Override
    public IPage<Map<String, Object>> jmxz(TbQwMfjSearchDto dto) {
        dto.setSsbmdm(tbBaseAdaptRemoteService.getSsbm(dto.getSsbmdm(), null));
        Map<String, Object> map = new HashMap<>();
//        UserInfo user = UserInfoManager.get();
        map.put("pageIndex", (dto.getPageCurrent() - 1) * dto.getPageSize());
        map.put("pageSize", dto.getPageSize());
//        map.put("useSql", PermissionsUtil.createSql("", user));
        map.put("dto", dto);
        List<Map<String, Object>> list = this.qwzxQwlbMapper.jmxz(map);
        int count = this.qwzxQwlbMapper.jmxzCount(map);
        IPage<Map<String, Object>> page = new Page<>(dto.getPageCurrent(), dto.getPageSize());
        page.setRecords(list);
        page.setTotal(count);
        return page;
    }
}
