package com.dgtly.order.controller;

import java.util.List;

import com.dgtly.sync.service.HanaOrderComponent;
import com.dgtly.system.service.ISysUserOrderAuthorService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.dgtly.common.annotation.Log;
import com.dgtly.common.enums.BusinessType;
import com.dgtly.order.domain.CustomersStart;
import com.dgtly.order.service.ICustomersStartService;
import com.dgtly.common.core.controller.BaseController;
import com.dgtly.common.core.domain.AjaxResult;
import com.dgtly.common.utils.poi.ExcelUtil;
import com.dgtly.common.core.page.TableDataInfo;

/**
 * 经销商启用Controller
 * 
 * @author nsy
 * @date 2021-01-18
 */
@Controller
@RequestMapping("/order/customersStart")
public class CustomersStartController extends BaseController
{
    private String prefix = "order/customersStart";

    @Autowired
    private ICustomersStartService customersStartService;

    @Autowired
    private HanaOrderComponent hanaOrderComponent;

    @RequiresPermissions("order:customersStart:view")
    @GetMapping()
    public String customersStart()
    {
        return prefix + "/customersStart";
    }

    /**
     * 查询经销商启用列表
     */
    @RequiresPermissions("order:customersStart:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CustomersStart customersStart)
    {
        startPage();
        List<CustomersStart> list = customersStartService.selectCustomersStartList(customersStart);
        return getDataTable(list);
    }

    /**
     * 导出经销商启用列表
     */
    @RequiresPermissions("order:customersStart:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CustomersStart customersStart)
    {
        List<CustomersStart> list = customersStartService.selectCustomersStartList(customersStart);
        ExcelUtil<CustomersStart> util = new ExcelUtil<CustomersStart>(CustomersStart.class);
        return util.exportExcel(list, "启用经销商");
    }

    /**
     * 新增经销商启用
     */
    @RequiresPermissions("order:customersStart:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存经销商启用
     */
    @RequiresPermissions("order:customersStart:add")
    @PostMapping("/addCustomersStart")
    @ResponseBody
    public AjaxResult addCustomersStart(String ids) {
        if (ids == null) {
            return AjaxResult.error("参数缺失，不支持操作");
        }
        return toAjax(customersStartService.addCustomersStart(ids));
    }

    /**
     * 经销商解冻查询接口
     */
    @PostMapping("/addFreeCustomer")
    @ResponseBody
    public AjaxResult addFreeCustomer(String customer) {
        String str ="";
        try {
            str = hanaOrderComponent.getFreezeCustomer(customer);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return AjaxResult.success(str);
    }
    @Autowired
    private ISysUserOrderAuthorService sysUserOrderAuthorService;

    /**
     * 经销商解冻查询接口
     */
    @PostMapping("/customersStarts")
    public String addFreeCustomer() {
        try {
            sysUserOrderAuthorService.customersStart();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return "";
    }

    /**
     * 修改经销商启用
     */
    @GetMapping("/edit/{customersCode}")
    public String edit(@PathVariable("customersCode") String customersCode, ModelMap mmap)
    {
        CustomersStart customersStart = customersStartService.selectCustomersStartById(customersCode);
        mmap.put("customersStart", customersStart);
        return prefix + "/edit";
    }

    /**
     * 修改保存经销商启用
     */
    @RequiresPermissions("order:customersStart:edit")
    @Log(title = "经销商启用", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CustomersStart customersStart)
    {
        return toAjax(customersStartService.updateCustomersStart(customersStart));
    }

    /**
     * 删除经销商启用
     */
    @RequiresPermissions("order:customersStart:remove")
    @Log(title = "经销商启用", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(customersStartService.deleteCustomersStartByIds(ids));
    }
}
