package com.yijia.customer.controller;

import java.util.List;

import com.yijia.common.constant.HttpStatus;
import com.yijia.common.core.domain.entity.SysDept;
import com.yijia.common.core.domain.model.LoginUser;
import com.yijia.common.utils.SecurityUtils;
import com.yijia.system.service.ISysDeptService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
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.yijia.common.annotation.Log;
import com.yijia.common.core.controller.BaseController;
import com.yijia.common.core.domain.AjaxResult;
import com.yijia.common.enums.BusinessType;
import com.yijia.customer.domain.CustomerCardRecordRecharge;
import com.yijia.customer.service.ICustomerCardRecordRechargeService;
import com.yijia.common.utils.poi.ExcelUtil;
import com.yijia.common.core.page.TableDataInfo;

/**
 * 客户电子会员卡充值记录Controller
 * 
 * @author yijia
 * @date 2021-04-13
 */
@RestController
@RequestMapping("/customer/recharge")
public class CustomerCardRecordRechargeController extends BaseController
{
    @Autowired
    private ICustomerCardRecordRechargeService customerCardRecordRechargeService;
    @Autowired
    private ISysDeptService deptService;
    /**
     * 查询客户电子会员卡充值记录列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CustomerCardRecordRecharge customerCardRecordRecharge)
    {
        LoginUser currentUser = SecurityUtils.getLoginUser();
        SysDept dept =new SysDept();
        dept.setDeptId(currentUser.getUser().getDeptId());
        List<String> list = deptService.selectDeptId(dept);
        if(list!=null && list.size()>0){
            customerCardRecordRecharge.setStationIdList(list);
            customerCardRecordRecharge.setStationId(null);
        }
        startPage();
        List<CustomerCardRecordRecharge> rechargeList = customerCardRecordRechargeService.selectCustomerCardRecordRechargeList(customerCardRecordRecharge);
        return getDataTable(rechargeList);
    }

    /**
     * 导出客户电子会员卡充值记录列表
     */
    @Log(title = "客户电子会员卡充值记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CustomerCardRecordRecharge customerCardRecordRecharge)
    {
        LoginUser currentUser = SecurityUtils.getLoginUser();
        SysDept dept =new SysDept();
        dept.setDeptId(currentUser.getUser().getDeptId());
        List<String> list = deptService.selectDeptId(dept);
        if(list!=null && list.size()>0){
            customerCardRecordRecharge.setStationIdList(list);
            customerCardRecordRecharge.setStationId(null);
        }
        List<CustomerCardRecordRecharge> rechargeList = customerCardRecordRechargeService.selectCustomerCardRecordRechargeList(customerCardRecordRecharge);
        ExcelUtil<CustomerCardRecordRecharge> util = new ExcelUtil<CustomerCardRecordRecharge>(CustomerCardRecordRecharge.class);
        return util.exportExcel(rechargeList, "recharge");
    }

    /**
     * 获取客户电子会员卡充值记录详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(customerCardRecordRechargeService.selectCustomerCardRecordRechargeById(id));
    }

    /**
     * 新增客户电子会员卡充值记录
     */
    @Log(title = "客户电子会员卡充值记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CustomerCardRecordRecharge customerCardRecordRecharge)
    {
        return toAjax(customerCardRecordRechargeService.insertCustomerCardRecordRecharge(customerCardRecordRecharge));
    }

    /**
     * 修改客户电子会员卡充值记录
     */
    @Log(title = "客户电子会员卡充值记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CustomerCardRecordRecharge customerCardRecordRecharge)
    {
        return toAjax(customerCardRecordRechargeService.updateCustomerCardRecordRecharge(customerCardRecordRecharge));
    }

    /**
     * 删除客户电子会员卡充值记录
     */
    @Log(title = "客户电子会员卡充值记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(customerCardRecordRechargeService.deleteCustomerCardRecordRechargeByIds(ids));
    }

    /**
     * 获取客户电子会员卡充值汇总金额
     */
    @GetMapping(value = "czAmtQuery")
    public AjaxResult czAmtQuery(CustomerCardRecordRecharge customerCardRecordRecharge)
    {
        LoginUser currentUser = SecurityUtils.getLoginUser();
        SysDept dept =new SysDept();
        dept.setDeptId(currentUser.getUser().getDeptId());
        List<String> list = deptService.selectDeptId(dept);
        if(list!=null && list.size()>0){
            customerCardRecordRecharge.setStationIdList(list);
            customerCardRecordRecharge.setStationId(null);
        }
        return AjaxResult.success(customerCardRecordRechargeService.czAmtQuery(customerCardRecordRecharge));
    }


    /**
     * 获取客户电子会员卡消费汇总折线图消费数据
     */
    @GetMapping(value = "listQydataCZ")
    public TableDataInfo listQydataCZ(CustomerCardRecordRecharge customerCardRecordRecharge)
    {
        LoginUser currentUser = SecurityUtils.getLoginUser();
        SysDept dept =new SysDept();
        dept.setDeptId(currentUser.getUser().getDeptId());
        List<String> list = deptService.selectDeptId(dept);
        if(list!=null && list.size()>0){
            customerCardRecordRecharge.setStationIdList(list);
            customerCardRecordRecharge.setStationId(null);
        }
        List<CustomerCardRecordRecharge> rechargelist =customerCardRecordRechargeService.listQydataCZ(customerCardRecordRecharge);
        return getTable(rechargelist);
    }
    @GetMapping("/selectCardDetail")
    public TableDataInfo selectCardDetail(CustomerCardRecordRecharge customerCardRecordRecharge)
    {
        LoginUser currentUser = SecurityUtils.getLoginUser();
        SysDept dept =new SysDept();
        dept.setDeptId(currentUser.getUser().getDeptId());
        List<String> list = deptService.selectDeptId(dept);
        if(list!=null && list.size()>0){
            customerCardRecordRecharge.setStationIdList(list);
            customerCardRecordRecharge.setStationId(null);
        }
        List<CustomerCardRecordRecharge> querylist = customerCardRecordRechargeService.selectCardDetail(customerCardRecordRecharge) ;
        List<CustomerCardRecordRecharge> pagelist = customerCardRecordRechargeService.selectCardDetailPage(customerCardRecordRecharge) ;
        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(HttpStatus.SUCCESS);
        rspData.setMsg("查询成功");
        rspData.setRows(querylist);
        rspData.setTotal(pagelist.size());
        return rspData;
    }

    @GetMapping(value = "/listCZData")
    public AjaxResult listCZData(CustomerCardRecordRecharge customerCardRecordRecharge)
    {
        LoginUser currentUser = SecurityUtils.getLoginUser();
        SysDept dept =new SysDept();
        dept.setDeptId(currentUser.getUser().getDeptId());
        List<String> list = deptService.selectDeptId(dept);
        if(list!=null && list.size()>0){
            customerCardRecordRecharge.setStationIdList(list);
            customerCardRecordRecharge.setStationId(null);
        }
        customerCardRecordRecharge.setStatus("1");
        return AjaxResult.success(customerCardRecordRechargeService.listCZData(customerCardRecordRecharge));
    }
}
