package com.dgtly.order.controller;

import java.util.List;

import com.dgtly.order.domain.DiySalesorgtree;
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.DiysalesorgStart;
import com.dgtly.order.service.IDiysalesorgStartService;
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-19
 */
@Controller
@RequestMapping("/order/salesorgStart")
public class DiysalesorgStartController extends BaseController
{
    private String prefix = "order/salesorgStart";

    @Autowired
    private IDiysalesorgStartService diysalesorgStartService;

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

    /**
     * 查询销售组织架构启用管理列表
     */
    @RequiresPermissions("order:salesorgStart:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DiysalesorgStart diysalesorgStart)
    {
        startPage();
        List<DiysalesorgStart> list = diysalesorgStartService.selectDiysalesorgStartList(diysalesorgStart);
        return getDataTable(list);
    }

    /**
     * 导出销售组织架构启用管理列表
     */
    @RequiresPermissions("order:salesorgStart:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DiysalesorgStart diysalesorgStart)
    {
        List<DiysalesorgStart> list = diysalesorgStartService.selectDiysalesorgStartList(diysalesorgStart);
        ExcelUtil<DiysalesorgStart> util = new ExcelUtil<DiysalesorgStart>(DiysalesorgStart.class);
        return util.exportExcel(list, "salesorgStart");
    }

    /**
     * 新增销售组织架构启用管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存销售组织架构启用管理
     */
    @RequiresPermissions("order:salesorgStart:add")
    @Log(title = "销售组织架构启用管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DiysalesorgStart diysalesorgStart)
    {
        return toAjax(diysalesorgStartService.insertDiysalesorgStart(diysalesorgStart));
    }

    /**
     * 修改销售组织架构启用管理
     */
    @GetMapping("/edit/{salesorgCode}")
    public String edit(@PathVariable("salesorgCode") String salesorgCode, ModelMap mmap)
    {
        DiysalesorgStart diysalesorgStart = diysalesorgStartService.selectDiysalesorgStartById(salesorgCode);
        mmap.put("diysalesorgStart", diysalesorgStart);
        return prefix + "/edit";
    }

    /**
     * 修改保存销售组织架构启用管理
     */
    @RequiresPermissions("order:salesorgStart:edit")
    @Log(title = "销售组织架构启用管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DiysalesorgStart diysalesorgStart)
    {
        return toAjax(diysalesorgStartService.updateDiysalesorgStart(diysalesorgStart));
    }

    /**
     * 删除销售组织架构启用管理
     */
    @RequiresPermissions("order:salesorgStart:remove")
    @Log(title = "销售组织架构启用管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(diysalesorgStartService.deleteDiysalesorgStartByIds(ids));
    }

    /**
     * 返回销售组织架构列表
     * @param salesorgtree
     * @return
     */
    @PostMapping("/salesOrgList")
    @ResponseBody
    public TableDataInfo salesOrgList(DiySalesorgtree salesorgtree)
    {
        startPage();
        List<DiySalesorgtree> usercustomersList = diysalesorgStartService.findSalesOrgList(salesorgtree);
        return getDataTable(usercustomersList);
    }


    /**
     * 新增保存销售组织架构启用
     */
    @RequiresPermissions("order:salesorgStart:add")
    @PostMapping("/addSalesorgStart")
    @ResponseBody
    public AjaxResult addSalesorgStart(String org6names,String org6codes) {
        if (org6codes == null || org6names == null) {
            return AjaxResult.error("参数缺失，不支持操作");
        }
        return toAjax(diysalesorgStartService.saveSalesorgStart(org6codes, org6names));
    }
}
