package com.fs.company.controller;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import com.fs.common.annotation.RepeatSubmit;
import com.fs.common.core.domain.R;
import com.fs.common.utils.ParseUtils;
import com.fs.common.utils.StringUtils;
import com.fs.company.domain.Company;

import com.fs.company.param.CompanyMoneyLogsParam;
import com.fs.company.service.ICompanyService;
import com.fs.company.vo.CompanyMoneyLogsExport1VO;
import com.fs.company.vo.CompanyMoneyLogsExport2VO;
import com.fs.company.vo.CompanyMoneyLogsExportVO;
import com.fs.company.vo.CompanyMoneyLogsVO;
import com.fs.voice.utils.StringUtil;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.enums.BusinessType;
import com.fs.company.domain.CompanyMoneyLogs;
import com.fs.company.service.ICompanyMoneyLogsService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 企业账户记录Controller
 *
 * @author fs
 * @date 2021-10-04
 */
@RestController
@RequestMapping("/company/companyMoneyLogs")
public class CompanyMoneyLogsController extends BaseController
{
    @Autowired
    private ICompanyMoneyLogsService companyMoneyLogsService;
    @Autowired
    private ICompanyService companyService;
    /**
     * 查询企业账户记录列表
     */
    @PreAuthorize("@ss.hasPermi('company:companyMoneyLogs:list')")
    @GetMapping("/list")
    public TableDataInfo list(CompanyMoneyLogsParam companyMoneyLogs)
    {
        startPage();
        if(companyMoneyLogs.getLogsType()!=null){
            if(companyMoneyLogs.getLogsType()==4 || companyMoneyLogs.getLogsType()==5){
                List<CompanyMoneyLogsVO> list = companyMoneyLogsService.selectCompanyMoneyLogsMallVOList(companyMoneyLogs);
                return getDataTable(list);
            }
            if(companyMoneyLogs.getLogsType()==8 || companyMoneyLogs.getLogsType()==9){
                List<CompanyMoneyLogsVO> list = companyMoneyLogsService.selectCompanyMoneyLogsMallVO1List(companyMoneyLogs);
                return getDataTable(list);
            }
        }
        List<CompanyMoneyLogsVO> list = companyMoneyLogsService.selectCompanyMoneyLogsVOList(companyMoneyLogs);
        return getDataTable(list);
    }


    //转账记录
    @PreAuthorize("@ss.hasPermi('company:companyMoneyLogs:list1')")
    @GetMapping("/list1")

    public TableDataInfo list1(CompanyMoneyLogsParam companyMoneyLogs)
    {
        startPage();
        companyMoneyLogs.setLogsType(1);
        List<CompanyMoneyLogsVO> list = companyMoneyLogsService.selectCompanyMoneyLogsVOList(companyMoneyLogs);
        return getDataTable(list);
    }
    //转账记录
    @PreAuthorize("@ss.hasPermi('company:companyMoneyLogs:list2')")
    @GetMapping("/list2")

    public TableDataInfo list2(CompanyMoneyLogsParam companyMoneyLogs) {
        startPage();
        companyMoneyLogs.setLogsType(2);
        List<CompanyMoneyLogsVO> list = companyMoneyLogsService.selectCompanyMoneyLogsVOList(companyMoneyLogs);
        return getDataTable(list);
    }
    //扣款
    @PreAuthorize("@ss.hasPermi('company:companyMoneyLogs:list3')")
    @GetMapping("/list3")
    public TableDataInfo list3(CompanyMoneyLogsParam companyMoneyLogs) {
        startPage();
        companyMoneyLogs.setLogsType(3);
        List<CompanyMoneyLogsVO> list = companyMoneyLogsService.selectCompanyMoneyLogsVOList(companyMoneyLogs);
        return getDataTable(list);
    }
    /**
     * 导出企业账户记录列表
     */
    @PreAuthorize("@ss.hasAnyPermi('company:companyMoneyLogs:export,company:companyMoneyLogs:export1,company:companyMoneyLogs:export2')")
    @Log(title = "企业账户记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CompanyMoneyLogs companyMoneyLogs)
    {
        if(companyMoneyLogs.getType()==0){
            List<CompanyMoneyLogsExportVO> list = companyMoneyLogsService.selectCompanyMoneyLogsExportVOList(companyMoneyLogs);
            ExcelUtil<CompanyMoneyLogsExportVO> util = new ExcelUtil<CompanyMoneyLogsExportVO>(CompanyMoneyLogsExportVO.class);
            return util.exportExcel(list, "全部流水");
        }
        else if(companyMoneyLogs.getType()==1){
            List<CompanyMoneyLogsExport1VO> list = companyMoneyLogsService.selectCompanyMoneyLogsExport1VOList(companyMoneyLogs);
            for (CompanyMoneyLogsExport1VO vo : list){
                vo.setUserPhone(ParseUtils.parsePhone(vo.getUserPhone()));
                vo.setUserAddress(ParseUtils.parseAddress(vo.getUserAddress()));
            }
            ExcelUtil<CompanyMoneyLogsExport1VO> util = new ExcelUtil<CompanyMoneyLogsExport1VO>(CompanyMoneyLogsExport1VO.class);
            return util.exportExcel(list, "商城订单");
        }
        else if(companyMoneyLogs.getType()==2){
            List<CompanyMoneyLogsExport2VO> list = companyMoneyLogsService.selectCompanyMoneyLogsExport2VOList(companyMoneyLogs);
            ExcelUtil<CompanyMoneyLogsExport2VO> util = new ExcelUtil<CompanyMoneyLogsExport2VO>(CompanyMoneyLogsExport2VO.class);
            return util.exportExcel(list, "收款订单");
        }
        return new AjaxResult(500,"操作失败");
    }

    /**
     * 获取企业账户记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('company:companyMoneyLogs:query')")
    @GetMapping(value = "/{logsId}")
    public AjaxResult getInfo(@PathVariable("logsId") Long logsId) {
        return AjaxResult.success(companyMoneyLogsService.selectCompanyMoneyLogsById(logsId));
    }

}
