package com.benyun.project.third.kingdeeDict.controller;

import java.util.List;
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.benyun.framework.aspectj.lang.annotation.Log;
import com.benyun.framework.aspectj.lang.enums.BusinessType;
import com.benyun.project.third.kingdeeDict.domain.KingdeeDict;
import com.benyun.project.third.kingdeeDict.service.IKingdeeDictService;
import com.benyun.framework.web.controller.BaseController;
import com.benyun.framework.web.domain.AjaxResult;
import com.benyun.common.utils.poi.ExcelUtil;
import com.benyun.framework.web.page.TableDataInfo;

/**
 * 金蝶单据类型字典Controller
 *
 * @author 冯旺
 * @date 2024-01-04
 */
@Controller
@RequestMapping("/system/kingdeeDict")
public class KingdeeDictController extends BaseController
{
    private String prefix = "system/third/kingdeeDict";

    @Autowired
    private IKingdeeDictService kingdeeDictService;

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

    /**
     * 查询金蝶单据类型字典列表
     */
    @RequiresPermissions("system:kingdeeDict:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(KingdeeDict kingdeeDict)
    {
        startPage();
        List<KingdeeDict> list = kingdeeDictService.selectKingdeeDictList(kingdeeDict);
        return getDataTable(list);
    }

    /**
     * 导出金蝶单据类型字典列表
     */
    @RequiresPermissions("system:kingdeeDict:export")
    @Log(title = "金蝶单据类型字典", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(KingdeeDict kingdeeDict)
    {
        List<KingdeeDict> list = kingdeeDictService.selectKingdeeDictList(kingdeeDict);
        ExcelUtil<KingdeeDict> util = new ExcelUtil<KingdeeDict>(KingdeeDict.class);
        return util.exportExcel(list, "金蝶单据类型字典数据");
    }

    /**
     * 新增金蝶单据类型字典
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存金蝶单据类型字典
     */
    @RequiresPermissions("system:kingdeeDict:add")
    @Log(title = "金蝶单据类型字典", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(KingdeeDict kingdeeDict)
    {
        return toAjax(kingdeeDictService.insertKingdeeDict(kingdeeDict));
    }

    /**
     * 修改金蝶单据类型字典
     */
    @RequiresPermissions("system:kingdeeDict:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        KingdeeDict kingdeeDict = kingdeeDictService.selectKingdeeDictById(id);
        mmap.put("kingdeeDict", kingdeeDict);
        return prefix + "/edit";
    }

    /**
     * 修改保存金蝶单据类型字典
     */
    @RequiresPermissions("system:kingdeeDict:edit")
    @Log(title = "金蝶单据类型字典", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(KingdeeDict kingdeeDict)
    {
        return toAjax(kingdeeDictService.updateKingdeeDict(kingdeeDict));
    }

    /**
     * 删除金蝶单据类型字典
     */
    @RequiresPermissions("system:kingdeeDict:remove")
    @Log(title = "金蝶单据类型字典", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(kingdeeDictService.deleteKingdeeDictByIds(ids));
    }



    /**
     * 同步金蝶单据类型字典
     */
    @Log(title = "金蝶单据类型字典", businessType = BusinessType.UPDATE)
    @PostMapping( "/sync")
    @ResponseBody
    public AjaxResult sync()
    {
        return toAjax(kingdeeDictService.syncKingdeeDict());
    }
}
