package com.bootdo.data.controller;

import com.bootdo.common.annotation.Log;
import com.bootdo.common.utils.EhcacheUtil;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;
import com.bootdo.data.domain.DataInfoDO;
import com.bootdo.data.entity.TfInfoEnterprise;
import com.bootdo.data.service.TfInfoEnterpriseService;
import com.bootdo.datas.domain.DataDO;
import com.bootdo.portal.common.CommonConstants;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.UUID;

/**
 * 企业(TfInfoEnterprise)表控制层
 *
 * @author Mr.xiBel
 * @since 2022-05-09 15:51:40
 */
@Controller
@RequestMapping("/data/enterpriseInfo")
public class TfInfoEnterpriseController {
    /**
     * 服务对象
     */
    @Resource
    private TfInfoEnterpriseService tfInfoEnterpriseService;

    @Log("访问企业信息")
    @GetMapping()
    @RequiresPermissions("enterprise:info:list")
    String dataInfo() {
        return "data/enterpriseInfo/dataInfo";
    }

    /**
     * 分页获取数据
     *
     * @param params
     * @return
     */
    @ResponseBody
    @GetMapping("/list")
    @RequiresPermissions("enterprise:info:list")
    public PageUtils list(@RequestParam Map<String, Object> params) {
        // 查询列表数据
        Query query = new Query(params);
        List<TfInfoEnterprise> dataInfoList = tfInfoEnterpriseService.queryPage(query);
        int total = tfInfoEnterpriseService.queryPageCount(query);
        return new PageUtils(dataInfoList, total);
    }


    @PostMapping("/disabled")
    @RequiresPermissions("enterprise:info:disabled")
    @ResponseBody
    public R disable(Long id) {
        tfInfoEnterpriseService.disable(id);
        return R.ok();
    }


    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/edit")
    @RequiresPermissions("enterprise:info:update")
    public TfInfoEnterprise selectOne(Integer id) {
        return this.tfInfoEnterpriseService.queryById(id);
    }


    @GetMapping("/edit/{id}")
    @RequiresPermissions("enterprise:info:update")
    String edit(@PathVariable("id") Integer id, Model model) {
        TfInfoEnterprise data = this.tfInfoEnterpriseService.queryById(id);
        model.addAttribute("data", data);
        return "data/enterpriseInfo/edit";
    }
}