package com.dxhy.extend.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.dxhy.common.controller.AbstractController;
import com.dxhy.common.utils.R;
import com.dxhy.common.vo.Tax;
import com.dxhy.extend.service.bb.ExtAbnormalInvoiceCopService;

import lombok.extern.slf4j.Slf4j;

/**
 * 异常发票预警控制器 Created by alfred.zong on 2018/04/13.
 *
 * @author dxhy
 */
@RestController
@RequestMapping("monit/abnormalinvoice")
@Slf4j
public class ExtAbnormalInvoiceController extends AbstractController {
    @Resource
    private ExtAbnormalInvoiceCopService abnormalInvoiceCopService;

    @RequestMapping("/searchlist")
    public ResponseEntity<R> queryAbnormalInvoice(@RequestParam Map<String, Object> pramsMap) {
        log.info("首页-异常发票预警,params {}", pramsMap);
        pramsMap.put("dbName", getUserInfo().getDbName());
        List<String> taxno = getTaxno();
        if (taxno != null && taxno.size() > 0) {

            pramsMap.put("taxno", taxno);
            int curr = Integer.parseInt(String.valueOf(pramsMap.get("curr")));
            int size = Integer.parseInt(String.valueOf(pramsMap.get("size")));

            return ResponseEntity
                .ok(R.ok().put("data", abnormalInvoiceCopService.queryAbnormalInvoice(pramsMap, curr, size)));

        } else {
            return ResponseEntity.ok(R.ok().put("data", ""));
        }
    }

    public List<String> getTaxno() {
        List<Tax> listTax = getUserInfo().getOrg();
        List<String> resultList = new ArrayList<>();
        for (Tax ta : listTax) {
            resultList.add(ta.getTaxno());
        }
        return resultList;
    }
}
