package com.boman.web.core.controller;

import com.boman.common.core.utils.poi.ExcelUtil;
import com.boman.common.core.web.controller.BaseController;
import com.boman.common.log.annotation.Log;
import com.boman.common.log.enums.BusinessType;
import com.boman.common.security.annotation.PreAuthorize;
import com.boman.domain.Czrk;
import com.boman.domain.CzrkJzdz;
import com.boman.domain.TableDataInfo;
import com.boman.domain.dto.AjaxResult;
import com.boman.web.core.service.czrk.ICzrkJzdzService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 常住人口对应的居住地址Controller
 *
 * @author ruoyi
 * @date 2022-01-14
 */
@RestController
@RequestMapping("/core/jzdz")
public class CzrkJzdzController extends BaseController {
    @Autowired
    private ICzrkJzdzService czrkJzdzService;

    /**
     * 人员信息中查询常住人口
     * 2022/3/23重新修复的PC人员信息查看常住人口接口
     */
//    @PreAuthorize("@ss.hasPermi('system:jzdz:list')")
    @GetMapping("/list")
    public TableDataInfo list(Czrk czrk) {
        List<Czrk> list = czrkJzdzService.listByCzrkJzdz(czrk);
        return getDataTable(list);
    }

    /**
     * 导出常住人口对应的居住地址列表
     */
//    @PreAuthorize("@ss.hasPermi('system:jzdz:export')")
    @Log(title = "常住人口对应的居住地址", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CzrkJzdz czrkJzdz) throws IOException {
        List<CzrkJzdz> list = czrkJzdzService.selectCzrkJzdzList(czrkJzdz);
        ExcelUtil<CzrkJzdz> util = new ExcelUtil<>(CzrkJzdz.class);
        util.exportExcel(response, list, "常住人口对应的居住地址数据");
    }


    /**
     * 人员数据导出（只导出填写到潜山市的数据）
     *
     */
    @Log(title = "人员信息", businessType = BusinessType.EXPORT)
    @PreAuthorize(hasPermi = "system:czrk:exportQianShan")
    @PostMapping("/exportQianShanCz")
    public void exportQianShanCz(HttpServletResponse response) throws IOException
    {
        List<Czrk> czrkList = czrkJzdzService.exportQianShanCz();
        ExcelUtil<Czrk> util = new ExcelUtil<>(Czrk.class);
        util.exportExcel(response, czrkList, "人员数据");
    }


    /**
     * 获取常住人口对应的居住地址详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:jzdz:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(czrkJzdzService.selectCzrkJzdzById(id));
    }

    /**
     * 新增常住人口对应的居住地址
     */
//    @PreAuthorize("@ss.hasPermi('system:jzdz:add')")
    @Log(title = "常住人口对应的居住地址", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CzrkJzdz czrkJzdz) {
        return toAjax(czrkJzdzService.insertCzrkJzdz(czrkJzdz));
    }

    /**
     * 修改常住人口对应的居住地址
     */
//    @PreAuthorize("@ss.hasPermi('system:jzdz:edit')")
    @Log(title = "常住人口对应的居住地址", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CzrkJzdz czrkJzdz) {
        return toAjax(czrkJzdzService.updateCzrkJzdz(czrkJzdz));
    }

    /**
     * 删除常住人口对应的居住地址
     */
//    @PreAuthorize("@ss.hasPermi('system:jzdz:remove')")
    @Log(title = "常住人口对应的居住地址", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(czrkJzdzService.deleteCzrkJzdzByIds(ids));
    }
}
