package vip.xiaonuo.money.controller;


import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import vip.xiaonuo.common.exception.CommonException;
import vip.xiaonuo.common.pojo.CommonResult;
import vip.xiaonuo.hr.modular.baseemployeeinfo.entity.HrBaseEmployeeInfo;
import vip.xiaonuo.hr.modular.baseemployeeinfo.param.HrBaseEmployeeInfoPageParam;
import vip.xiaonuo.money.entity.MoneyBusiness;
import vip.xiaonuo.money.entity.vo.MoneyBusinessVo;
import vip.xiaonuo.money.param.*;
import vip.xiaonuo.money.service.IMoneyBusinessService;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 财务营业情况 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-11-19
 */
@Api(tags = "财务指标卡控制器")
@ApiSupport(author = "wang", order = 1)
@RestController
@Validated
public class MoneyBusinessController {
    @Autowired
    private IMoneyBusinessService businessService;


    @ApiOperationSupport(order = 1)
    @ApiOperation("指标卡")
    @PostMapping("/money/listBusiness")
    public CommonResult<JSONArray> listBusiness(@RequestBody  MoneyBusinessParam moneyBusinessParam) {
        return CommonResult.data(businessService.listBusiness(moneyBusinessParam));
    }


    @ApiOperationSupport(order = 2)
    @ApiOperation("指标卡列表")
    @PostMapping("/money/getPage")
    public CommonResult<Page<MoneyBusiness>> getPage(@RequestBody MoneyBusinessPageParam pageParam) {
        return CommonResult.data(businessService.getPage(pageParam));
    }

    @ApiOperationSupport(order = 3)
    @ApiOperation("财务指标卡填报")
    @PostMapping("/money/addBusiness")
    public CommonResult<String> addBusiness(@RequestBody  MoneyBusiness business) {
        businessService.addBusiness(business);
        return CommonResult.ok();
    }

    @ApiOperationSupport(order = 4)
    @ApiOperation("财务指标卡修改")
    @PostMapping("/money/updateBusiness")
    public CommonResult<String> updateBusiness(@RequestBody  MoneyBusiness business) {
        businessService.updateBusiness(business);
        return CommonResult.ok();
    }

    @ApiOperationSupport(order = 5)
    @ApiOperation("财务指标卡删除")
    @PostMapping("/money/deleteBusiness")
    public CommonResult<String> deleteBusiness(@RequestBody  MoneyBusiness business) {
        businessService.deleteBusiness(business);
        return CommonResult.ok();
    }


    @ApiOperation("董事长页面指标卡")
    @PostMapping("/money/dsBusAll")
    public CommonResult< DsBusAllParam> dsBusAll(@RequestBody MoneyAnalysisParam moneyAnalysisParam) {
        DsBusAllParam dsBusAllParam =  businessService.dsBusAll(moneyAnalysisParam);
        return CommonResult.data(dsBusAllParam);
    }

    @ApiOperation("董事长页面营业收入，净利润，已交税金 详情")
    @PostMapping("/money/getDsBusYyJlYjDetail")
    public CommonResult<List<DsBusAllParam>> getDsBusYyJlYjDetail(@RequestBody DsBusParam dsBusParam) {
        List<DsBusAllParam> endMap =  businessService.getDsBusYyJlYjDetail(dsBusParam);
        return CommonResult.data(endMap);
    }

    @ApiOperation("董事长页面资余额")
    @PostMapping("/money/getBalanceDetail")
    public CommonResult<List<DsBusAllParam>> getBalanceDetail(@RequestBody DsBusParam dsBusParam) {
        List<DsBusAllParam> endMap =  businessService.getBalanceDetail(dsBusParam);
        return CommonResult.data(endMap);
    }


    @ApiOperation("董事长页面借款趋势")
    @PostMapping("/money/getBorrowDetail")
    public CommonResult<List<DsBusAllParam>> getBorrowDetail(@RequestBody DsBusParam dsBusParam) {
        List<DsBusAllParam> endMap =  businessService.getBorrowDetail(dsBusParam);
        return CommonResult.data(endMap);
    }

    @ApiOperation("董事长页面期间费用")
    @PostMapping("/money/getMoneyDetail")
    public CommonResult<List<DsBusSaleMoneyParam>> getMoneyDetail(@RequestBody DsBusParam dsBusParam) {
        List<DsBusSaleMoneyParam> endMap =  businessService.getMoneyDetail(dsBusParam);
        return CommonResult.data(endMap);
    }

    @ApiOperationSupport(order = 1)
    @ApiOperation("已交税金填报")
    @PostMapping("/money/addBusines")
    public CommonResult<JSONArray> listBusiness(@RequestBody MoneyBusinessVo moneyBusinessParam) {
        String orgId = moneyBusinessParam.getOrgId();
        if (StringUtils.isBlank(orgId)){
            throw new CommonException("请选择公司");
        }
        MoneyBusiness moneyBusiness = new MoneyBusiness();
        moneyBusiness.setOrgId(moneyBusinessParam.getOrgId());
        moneyBusiness.setTaxes(moneyBusinessParam.getTaxes());
        moneyBusiness.setCreateTime(DateUtil.parse(moneyBusinessParam.getCreateTime(),"yyyy-MM"));
        businessService.save(moneyBusiness);
        return CommonResult.ok();
    }

    @ApiOperationSupport(order = 1)
    @ApiOperation("已交税金列表")
    @PostMapping("/money/listBusines")
    public CommonResult<Page<MoneyBusiness>> listBusines(@RequestBody  MoneyOverduePageParam pageParam) {
        return  CommonResult.data(businessService.listBusines(pageParam));
    }

    @ApiOperationSupport(order = 5)
    @ApiOperation("已交税金删除")
    @PostMapping("/money/deleteBusines")
    public CommonResult<String> deleteBusines(@RequestBody  MoneyBusiness business) {
        businessService.deleteBusiness(business);
        return CommonResult.ok();
    }

    @ApiOperationSupport(order = 4)
    @ApiOperation("已交税金修改")
    @PostMapping("/money/updateBusines")
    public CommonResult<String> updateBusines(@RequestBody MoneyBusinessVo moneyBusinessParam) {

        MoneyBusiness moneyBusiness = new MoneyBusiness();
        moneyBusiness.setTaxes(moneyBusinessParam.getTaxes());
        moneyBusiness.setId(moneyBusinessParam.getId());
        moneyBusiness.setCreateTime(DateUtil.parse(moneyBusinessParam.getCreateTime(),"yyyy-MM"));
        businessService.updateById(moneyBusiness);
        return CommonResult.ok();
    }


}
