package com.siwei.rsmonitoring.controller;

import com.siwei.common.core.utils.StringUtils;
import com.siwei.common.core.utils.file.UnPackageUtils;
import com.siwei.common.core.utils.poi.ExcelUtil;
import com.siwei.common.core.web.controller.BaseController;
import com.siwei.common.core.web.domain.AjaxResult;
import com.siwei.common.core.web.page.TableDataInfo;
import com.siwei.common.log.annotation.Log;
import com.siwei.common.log.enums.BusinessType;
import com.siwei.common.security.annotation.RequiresPermissions;
import com.siwei.rsmonitoring.domain.TDkFieldwork;
import com.siwei.rsmonitoring.domain.TDkGeomDb;
import com.siwei.rsmonitoring.domain.TDkGeomDbDetails;
import com.siwei.rsmonitoring.domain.TDkjbxx;
import com.siwei.rsmonitoring.service.ITDkGeomDbDetailsService;
import com.siwei.rsmonitoring.service.ITDkGeomDbService;
import com.siwei.rsmonitoring.service.ITDkjbxxService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * 上传数据基本信息Controller
 *
 * @author siwei
 * @date 2025-01-20
 */
@RestController
@RequestMapping("/dkgeomdb")
public class TDkGeomDbController extends BaseController {
    @Autowired
    private ITDkGeomDbService itDkGeomDbService;
    @Autowired
    private ITDkGeomDbDetailsService tDkGeomDbDetailsService;

    /**
     * 新增地块空间信息
     */
    //@RequiresPermissions("rsmonitoring:dkgeomdb:add")
    @Log(title = "新增地块空间信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TDkGeomDb tDkGeomDb) {
        if (null == tDkGeomDb || StringUtils.isEmpty(tDkGeomDb.getShppath())) {
            return AjaxResult.error("参数缺失");
        }
        return toAjax(itDkGeomDbService.insertTDkGeomDb(tDkGeomDb));
    }

    /**
     * 下发地块空间信息
     */
    //@RequiresPermissions("rsmonitoring:dkgeomdb:issue")
    @Log(title = "下发地块空间信息", businessType = BusinessType.INSERT)
    @PostMapping("/issue")
    public AjaxResult issue(@RequestBody TDkGeomDb tDkGeomDb) {
        if (tDkGeomDb == null || StringUtils.isEmpty(tDkGeomDb.getId())) {
            return AjaxResult.error("参数缺失");
        }
        return toAjax(itDkGeomDbService.issueTDkGeomDb(tDkGeomDb.getId()));
    }


    /**
     * 查询上传列表
     */
//    @RequiresPermissions("rsmonitoring:dkgeomdb:list")
    @GetMapping("/list")
    public TableDataInfo list(TDkGeomDb tDkGeomDb) {
        startPage();
        List<TDkGeomDb> list = itDkGeomDbService.selectTDkGeomDbList(tDkGeomDb);
        for (TDkGeomDb db : list) {
            db.setGeom(null);
        }
        return getDataTable(list);
    }

    /**
     * 查询地块空间详情列表
     */
//    @RequiresPermissions("rsmonitoring:dkgeomdb:list:details")
    @GetMapping("/details/list")
    public TableDataInfo list(TDkGeomDbDetails tDkGeomDbDetails) {
        startPage();
        List<TDkGeomDbDetails> list = tDkGeomDbDetailsService.selectTDkGeomDbDetailsList(tDkGeomDbDetails);
        return getDataTable(list);
    }

    //    @RequiresPermissions("rsmonitoring:dkgeomdb:query:details")
    @GetMapping("/details/{id}")
    public AjaxResult info(@PathVariable("id") String id) {
        return success(tDkGeomDbDetailsService.selectTDkGeomDbDetailsById(id));
    }

    //    @RequiresPermissions("rsmonitoring:fieldwork:remove")
//    @Log(title = "上传数据基本信息删除", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(itDkGeomDbService.deleteTDkGeomDbByIds(ids));
    }

}
