package com.sooka.system.controller;

import java.util.List;

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.TableDataInfo;
import com.sooka.common.enums.BusinessType;
import com.sooka.common.utils.poi.ExcelUtil;
import com.sooka.system.domain.TUSfz;
import com.util.HttpUtil;
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.sooka.system.domain.TUPeoplemarryinfosingle;
import com.sooka.system.service.ITUPeoplemarryinfosingleService;

import javax.servlet.http.HttpServletRequest;


/**
 * 国家民政部-婚姻信息（单方）-数据查询接口Controller
 *
 * @author lei
 * @date 2021-07-14
 */
@Controller
@RequestMapping("/system/peoplemarryinfosingle")
public class TUPeoplemarryinfosingleController extends BaseController
{
    private String prefix = "system/peoplemarryinfosingle";

    @Autowired
    private ITUPeoplemarryinfosingleService tUPeoplemarryinfosingleService;

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

    /**
     * 查询国家民政部-婚姻信息（单方）-数据查询接口列表
     */
    @RequiresPermissions("system:peoplemarryinfosingle:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TUPeoplemarryinfosingle tUPeoplemarryinfosingle, HttpServletRequest request)
    {
        String osAndBrowser[] = HttpUtil.getOsAndBrowserInfo(request).split("---");
        String os = osAndBrowser[0];
        String browser = osAndBrowser[1];
        String ipaddress = HttpUtil.getIPAddress(request);
        tUPeoplemarryinfosingle.setBrowser(browser);
        tUPeoplemarryinfosingle.setOs(os);
        tUPeoplemarryinfosingle.setIpaddress(ipaddress);
        List<TUPeoplemarryinfosingle> list = tUPeoplemarryinfosingleService.selectTUPeoplemarryinfosingleList(tUPeoplemarryinfosingle);

        if(list == null){
            return getDataTable("秘钥错误或过期,请联系管理员");
        }
        return getDataTable(list);
    }

    /**
     * 导出国家民政部-婚姻信息（单方）-数据查询接口列表
     */
    @RequiresPermissions("system:peoplemarryinfosingle:export")
    @Log(title = "国家民政部-婚姻信息（单方）-数据查询接口", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TUPeoplemarryinfosingle tUPeoplemarryinfosingle)
    {
        List<TUPeoplemarryinfosingle> list = tUPeoplemarryinfosingleService.selectTUPeoplemarryinfosingleList(tUPeoplemarryinfosingle);
        ExcelUtil<TUPeoplemarryinfosingle> util = new ExcelUtil<TUPeoplemarryinfosingle>(TUPeoplemarryinfosingle.class);
        return util.exportExcel(list, "peoplemarryinfosingle");
    }

    /**
     * 新增国家民政部-婚姻信息（单方）-数据查询接口
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存国家民政部-婚姻信息（单方）-数据查询接口
     */
    @RequiresPermissions("system:peoplemarryinfosingle:add")
    @Log(title = "国家民政部-婚姻信息（单方）-数据查询接口", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TUPeoplemarryinfosingle tUPeoplemarryinfosingle)
    {
        return toAjax(tUPeoplemarryinfosingleService.insertTUPeoplemarryinfosingle(tUPeoplemarryinfosingle));
    }

    /**
     * 修改国家民政部-婚姻信息（单方）-数据查询接口
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        TUPeoplemarryinfosingle tUPeoplemarryinfosingle = tUPeoplemarryinfosingleService.selectTUPeoplemarryinfosingleById(id);
        mmap.put("tUPeoplemarryinfosingle", tUPeoplemarryinfosingle);
        return prefix + "/edit";
    }

    /**
     * 修改保存国家民政部-婚姻信息（单方）-数据查询接口
     */
    @RequiresPermissions("system:peoplemarryinfosingle:edit")
    @Log(title = "国家民政部-婚姻信息（单方）-数据查询接口", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TUPeoplemarryinfosingle tUPeoplemarryinfosingle)
    {
        return toAjax(tUPeoplemarryinfosingleService.updateTUPeoplemarryinfosingle(tUPeoplemarryinfosingle));
    }

    /**
     * 删除国家民政部-婚姻信息（单方）-数据查询接口
     */
    @RequiresPermissions("system:peoplemarryinfosingle:remove")
    @Log(title = "国家民政部-婚姻信息（单方）-数据查询接口", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tUPeoplemarryinfosingleService.deleteTUPeoplemarryinfosingleByIds(ids));
    }
}
