package com.dxhy.extend.controller;

import java.text.ParseException;
import java.util.Map;

import javax.annotation.Resource;

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

import com.alibaba.fastjson.JSONObject;
import com.dxhy.common.aspect.SysLog;
import com.dxhy.common.controller.AbstractController;
import com.dxhy.common.util.StringHelper;
import com.dxhy.common.util.UserInfoUtil;
import com.dxhy.common.utils.R;
import com.dxhy.extend.service.companypool.CompanyIndexService;

import lombok.extern.slf4j.Slf4j;

/**
 *
 * 发票统计报表入口
 *
 * @author dxhy
 */
@RestController
@RequestMapping("modules/companyIndex")
@Slf4j
public class ExtCompanyIndexController extends AbstractController {

    @Resource
    private CompanyIndexService companyIndexService;

    /**
     * 获取税号所属机构信息
     *
     * @param paramsMap
     *            查询条件
     * @return 返回
     */
    @RequestMapping("/queryList")
    @SysLog("获取税号所属机构信息")
    public ResponseEntity<R> companyPoolIndex(@RequestBody Map<String, Object> paramsMap) {
        paramsMap.put("gfshAll", StringHelper.listToString(UserInfoUtil.getGfshAll(getUserInfo().getOrg())));
        paramsMap.put("gfmcAll", StringHelper.listToString(UserInfoUtil.getGfmcAll(getUserInfo().getOrg())));
        String dbName = getUserInfo().getDbName();
        paramsMap.put("dbName", dbName);
        JSONObject jxObj = null;
        try {
            jxObj = companyIndexService.getTotal(paramsMap);
        } catch (ParseException e) {
           log.info("业务处理异常：{}", e);
        }
        return ResponseEntity.ok(R.ok().put("data", jxObj));
    }

    /**
     * 首页概览-风险发票
     *
     * @param paramsMap
     *            查询条件
     * @return 返回
     */
    @RequestMapping("/queryRiskList")
    @SysLog("首页风险发票概览")
    public ResponseEntity<R> queryRiskList(@RequestBody Map<String, Object> paramsMap) {
        paramsMap.put("gfshAll", StringHelper.listToString(UserInfoUtil.getGfshAll(getUserInfo().getOrg())));
        paramsMap.put("gfmcAll", StringHelper.listToString(UserInfoUtil.getGfmcAll(getUserInfo().getOrg())));
        String dbName = getUserInfo().getDbName();
        paramsMap.put("dbName", dbName);
        JSONObject jxObj = null;
        try {
            jxObj = companyIndexService.queryRiskList(paramsMap);
        } catch (Exception e) {
           log.info("业务处理异常：{}", e);
        }
        return ResponseEntity.ok(R.ok().put("data", jxObj));
    }

    /**
     * 首页概览-对账情况
     *
     * @param paramsMap
     *            查询条件
     * @return 返回
     */
    @RequestMapping("/queryAccountList")
    @SysLog("首页对账情况概览")
    public ResponseEntity<R> queryAccountList(@RequestBody Map<String, Object> paramsMap) {
        paramsMap.put("gfshAll", StringHelper.listToString(UserInfoUtil.getGfshAll(getUserInfo().getOrg())));
        paramsMap.put("gfmcAll", StringHelper.listToString(UserInfoUtil.getGfmcAll(getUserInfo().getOrg())));
        String dbName = getUserInfo().getDbName();
        paramsMap.put("dbName", dbName);
        JSONObject jxObj = null;
        try {
            jxObj = companyIndexService.queryAccountList(paramsMap);
        } catch (Exception e) {
           log.info("业务处理异常：{}", e);
        }
        return ResponseEntity.ok(R.ok().put("data", jxObj));
    }

}
