package com.dxhy.extend.controller;

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

import javax.annotation.Resource;

import com.dxhy.api.model.config.Tax;
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.util.UserInfoUtil;
import com.dxhy.common.utils.R;
import com.dxhy.extend.service.bb.ExtRecordInvoiceService;

import lombok.extern.slf4j.Slf4j;

/**
 * 逾期预警控制层 Created by alfred.zong on 2018/04/12.
 *
 * @author dxhy
 */
@RestController
@RequestMapping("monit/record/")
@Slf4j
public class ExtRecordInvoiceController extends AbstractController {

    @Resource
    private ExtRecordInvoiceService recordInvoiceservice;

    /**
     * 逾期预警
     *
     * @param pramsMap
     *            为前台穿的条件集合
     * @return map集合；
     */

    @RequestMapping("/search")
    public ResponseEntity<R> queryRecord(@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);
            // 购方税号
            List<String> gfshList = UserInfoUtil.getGfshAll(getUserInfo().getOrg());
            pramsMap.put("gfsh", gfshList);
            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", recordInvoiceservice.queryInvoice(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;
    }

}
