package com.yijia.customer.controller;

import java.util.List;

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.customer.domain.CustomerCardSetting;
import com.yijia.system.service.ISysDeptService;
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.CustomerCardSettingDetail;
import com.yijia.customer.service.ICustomerCardSettingDetailService;
import com.yijia.common.utils.poi.ExcelUtil;
import com.yijia.common.core.page.TableDataInfo;

/**
 * 客户电子会员卡充值优惠设置明细Controller
 *
 * @author yijia
 * @date 2021-04-06
 */
@RestController
@RequestMapping("/customer/detail")
public class CustomerCardSettingDetailController extends BaseController
{
    @Autowired
    private ICustomerCardSettingDetailService customerCardSettingDetailService;
    @Autowired
    private ISysDeptService deptService;
    /**
     * 查询客户电子会员卡充值优惠设置明细列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CustomerCardSettingDetail customerCardSettingDetail)
    {

        startPage();
        List<CustomerCardSettingDetail> detailList = customerCardSettingDetailService.selectCustomerCardSettingDetailList(customerCardSettingDetail);
        return getDataTable(detailList);
    }

    /**
     * 查询客户电子会员卡充值优惠设置明细列表
     */
//    @GetMapping("/listDetailInfo")
//    public TableDataInfo listDetailInfo(CustomerCardSettingDetail customerCardSettingDetail)
//    {
//        startPage();
//        List<CustomerCardSettingDetail> list = customerCardSettingDetailService.listDetailInfo(customerCardSettingDetail);
//        return getDataTable(list);
//    }
    @GetMapping("/listDetailInfo")
    public TableDataInfo listDetailInfo(CustomerCardSetting customerCardSetting)
    {
        startPage();
        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){
//            customerCardSetting.setStationIdList(list);
//            customerCardSetting.setStationId(null);
//        }

        customerCardSetting.setStationId(currentUser.getUser().getDeptId());
        customerCardSetting.setDelFlag("0");
        List<CustomerCardSettingDetail> detailList = customerCardSettingDetailService.listDetailInfo(customerCardSetting);
        return getDataTable(detailList);
    }
    /**
     * 获取客户电子会员卡充值优惠设置明细详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(customerCardSettingDetailService.selectCustomerCardSettingDetailById(id));
    }

    /**
     * 新增客户电子会员卡充值优惠设置明细
     */
    @Log(title = "客户电子会员卡充值优惠设置明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CustomerCardSettingDetail customerCardSettingDetail)
    {
        return toAjax(customerCardSettingDetailService.insertCustomerCardSettingDetail(customerCardSettingDetail));
    }

    /**
     * 修改客户电子会员卡充值优惠设置明细
     */
    @Log(title = "客户电子会员卡充值优惠设置明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CustomerCardSettingDetail customerCardSettingDetail)
    {
        return toAjax(customerCardSettingDetailService.updateCustomerCardSettingDetail(customerCardSettingDetail));
    }

    /**
     * 删除客户电子会员卡充值优惠设置明细
     */
    @Log(title = "客户电子会员卡充值优惠设置明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(customerCardSettingDetailService.deleteCustomerCardSettingDetailByIds(ids));
    }
}
