package com.sooka.system.gas.zenner_gas_purchase_center_infor.controller;

import com.sooka.common.annotation.Log;
import com.sooka.common.core.controller.BaseController;
import com.sooka.common.core.domain.AjaxResult;
import com.sooka.common.core.page.PageDomain;
import com.sooka.common.core.page.TableDataInfo;
import com.sooka.common.core.page.TableSupport;
import com.sooka.common.core.text.Convert;
import com.sooka.common.enums.BusinessType;
import com.sooka.common.utils.CacheUtils;
import com.sooka.common.utils.poi.ExcelUtil;
import com.sooka.system.gas.zenner_gas_purchase_center_infor.domain.TGuijiZennerGasPurchaseCenterInfor;
import com.sooka.system.gas.zenner_gas_purchase_center_infor.mapper.TGuijiZennerGasPurchaseCenterMapper;
import com.sooka.system.gas.zenner_gas_purchase_center_infor.service.ITGuijiZennerGasPurchaseCenterInforService;
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.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 真兰收费系统-中心计费购气信息Controller
 *
 * @author lei
 * @date 2022-08-22
 */
@Controller
@RequestMapping("/system/gas/zenner_gas_purchase_center_infor")
public class TGuijiZennerGasPurchaseCenterInforController extends BaseController
{
    private String prefix = "system/gas/zenner_gas_purchase_center_infor";

    @Autowired
    private ITGuijiZennerGasPurchaseCenterInforService service;

    @Resource
    private TGuijiZennerGasPurchaseCenterMapper mapper;

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

    /**
     * 查询真兰收费系统-中心计费购气信息列表
     */
    @RequiresPermissions("system:zenner_gas_purchase_center_infor:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TGuijiZennerGasPurchaseCenterInfor param)
    {
//        PageDomain pageDomain = TableSupport.buildPageRequest();
//        Integer pageNum = pageDomain.getPageNum();
//        Integer pageSize = pageDomain.getPageSize();
//        String limit = "limit " + ((pageNum - 1) * pageSize) + ", " + pageSize;
//        Map params = new HashMap();
//        params.put("limit", limit);
//        param.setParams(params);
//        List<TGuijiZennerGasPurchaseCenterInfor> list = service.selectList(param);
//        String paramStr = param.getVC_JFH_SKPERSON() + "," + param.getD_JFH_SKDATE();
//        return getDataTable(list, service.getTotal("t_guiji_gas_zenner_gas_purchase_center_infor", paramStr));

        PageDomain pageDomain = TableSupport.buildPageRequest();
        Integer pageNum = pageDomain.getPageNum();
        Integer pageSize = pageDomain.getPageSize();
        String limit = "limit " + ((pageNum - 1) * pageSize) + ", " + pageSize;
        Map params = new HashMap();
        params.put("limit", limit);
        param.setParams(params);
        List<TGuijiZennerGasPurchaseCenterInfor> idList = mapper.selectIds(param);
        String ids = "";
        for (TGuijiZennerGasPurchaseCenterInfor info : idList) {
            ids += "'" + info.getId() + "',";
        }
        ids = ids.length() == 0 ? ids : ids.substring(0, ids.length() - 1);
        Map map = new HashMap();
        map.put("ids", ids);
        String paramStr = param.getVC_JFH_SKPERSON() + "," + param.getD_JFH_SKDATE();
        Long total = service.getTotal("t_guiji_gas_zenner_gas_purchase_center_infor", paramStr);
        System.out.println("ids=" + ids);
        List<TGuijiZennerGasPurchaseCenterInfor> list = mapper.selectListbyIds(map);
        System.out.println(list.size() + "=size");
        System.out.println("total=" + total);
        return getDataTable(list, total);
    }

    /**
     * 导出真兰收费系统-中心计费购气信息列表
     */
    @RequiresPermissions("system:zenner_gas_purchase_center_infor:export")
    @Log(title = "真兰收费系统-中心计费购气信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TGuijiZennerGasPurchaseCenterInfor param)
    {
        List<TGuijiZennerGasPurchaseCenterInfor> list = service.selectList(param);
        ExcelUtil<TGuijiZennerGasPurchaseCenterInfor> util = new ExcelUtil<TGuijiZennerGasPurchaseCenterInfor>(TGuijiZennerGasPurchaseCenterInfor.class);
        return util.exportExcel(list, "真兰收费系统-中心计费购气信息");
    }

    /**
     * 新增真兰收费系统-中心计费购气信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存真兰收费系统-中心计费购气信息
     */
    @RequiresPermissions("system:zenner_gas_purchase_center_infor:add")
    @Log(title = "真兰收费系统-中心计费购气信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TGuijiZennerGasPurchaseCenterInfor param)
    {
        return toAjax(service.insert(param));
    }

    /**
     * 修改真兰收费系统-中心计费购气信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        TGuijiZennerGasPurchaseCenterInfor param = service.selectById(id);
        mmap.put("param", param);
        return prefix + "/edit";
    }

    /**
     * 修改保存真兰收费系统-中心计费购气信息
     */
    @RequiresPermissions("system:zenner_gas_purchase_center_infor:edit")
    @Log(title = "真兰收费系统-中心计费购气信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TGuijiZennerGasPurchaseCenterInfor param)
    {
        return toAjax(service.update(param));
    }

    /**
     * 删除真兰收费系统-中心计费购气信息
     */
    @RequiresPermissions("system:zenner_gas_purchase_center_infor:remove")
    @Log(title = "真兰收费系统-中心计费购气信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(service.deleteByIds(ids));
    }

    /**
     * 真兰收费系统-中心计费购气信息详情
     */
    @GetMapping("/detail/{id}")
    public String detail(@PathVariable("id") String id, ModelMap mmap)
    {
        TGuijiZennerGasPurchaseCenterInfor param = service.selectById(id);
        mmap.put("detail", param);
        return prefix + "/detail";
    }
}
