package com.siwei.rsmonitoring.controller;

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

import com.siwei.common.core.utils.DateUtils;
import com.siwei.common.core.utils.StringUtils;
import com.siwei.common.core.utils.uuid.IdUtils;
import com.siwei.rsmonitoring.domain.TDkAuditflowRecordFj;
import com.siwei.rsmonitoring.service.ITDkAuditflowRecordFjService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
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.TDkAuditflowRecord;
import com.siwei.rsmonitoring.service.ITDkAuditflowRecordService;
import com.siwei.common.core.web.controller.BaseController;
import com.siwei.common.core.web.domain.AjaxResult;
import com.siwei.common.core.utils.poi.ExcelUtil;
import com.siwei.common.core.web.page.TableDataInfo;

/**
 * 地块核查流程Controller
 *
 * @author siwei
 * @date 2025-01-21
 */
@RestController
@RequestMapping("/auditflow/record")
public class TDkAuditflowRecordController extends BaseController {
    @Autowired
    private ITDkAuditflowRecordService tDkAuditflowRecordService;
    @Autowired
    private ITDkAuditflowRecordFjService tDkAuditflowRecordFjService;

    /**
     * 查询地块核查流程列表
     */
//    @RequiresPermissions("rsmonitoring:auditflow:record:list")
//    @GetMapping("/list")
//    public TableDataInfo list(TDkAuditflowRecord tDkAuditflowRecord) {
//        startPage();
//        List<TDkAuditflowRecord> list = tDkAuditflowRecordService.selectTDkAuditflowRecordList(tDkAuditflowRecord);
//        return getDataTable(list);
//    }
    @GetMapping("/list/business")
    public AjaxResult listBusiness(TDkAuditflowRecord tDkAuditflowRecord) {
        if (tDkAuditflowRecord == null || StringUtils.isEmpty(tDkAuditflowRecord.getDkjdxxId())) {
            return error("参数缺失");
        }
        tDkAuditflowRecord.setAuditflowState("0");
        return success(tDkAuditflowRecordService.selectTDkAuditflowRecordListBusiness(tDkAuditflowRecord));
    }

    /**
     * 查询当前地块可执行功能
     *
     * @param dkjdxxId
     * @return
     */
    @GetMapping("/list/step")
    public AjaxResult listStep(String dkjdxxId) {
        if (StringUtils.isEmpty(dkjdxxId)) {
            return error("参数缺失");
        }
        return success(tDkAuditflowRecordService.selectTDkAuditflowRecordListStep(dkjdxxId));
    }


    /**
     * 导出地块核查流程列表
     */
//    @RequiresPermissions("rsmonitoring:auditflow:record:export")
//    @Log(title = "地块核查流程", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, TDkAuditflowRecord tDkAuditflowRecord) {
//        List<TDkAuditflowRecord> list = tDkAuditflowRecordService.selectTDkAuditflowRecordList(tDkAuditflowRecord);
//        ExcelUtil<TDkAuditflowRecord> util = new ExcelUtil<TDkAuditflowRecord>(TDkAuditflowRecord.class);
//        util.exportExcel(response, list, "地块核查流程数据");
//    }
//
//    /**
//     * 获取地块核查流程详细信息
//     */
//    @RequiresPermissions("rsmonitoring:auditflow:record:query")
//    @GetMapping(value = "/{id}")
//    public AjaxResult getInfo(@PathVariable("id") String id) {
//        return success(tDkAuditflowRecordService.selectTDkAuditflowRecordById(id));
//    }
//
////    /**
////     * 新增地块核查流程
////     */
////    @RequiresPermissions("rsmonitoring:auditflow:record:add")
////    @Log(title = "地块核查流程", businessType = BusinessType.INSERT)
////    @PostMapping
////    public AjaxResult add(@RequestBody TDkAuditflowRecord tDkAuditflowRecord)
////    {
////        return toAjax(tDkAuditflowRecordService.insertTDkAuditflowRecord(tDkAuditflowRecord));
////    }
//
//    /**
//     * 修改地块核查流程
//     */
//    @RequiresPermissions("rsmonitoring:auditflow:record:edit")
//    @Log(title = "地块核查流程", businessType = BusinessType.UPDATE)
//    @PutMapping
//    public AjaxResult edit(@RequestBody TDkAuditflowRecord tDkAuditflowRecord) {
//        return toAjax(tDkAuditflowRecordService.updateTDkAuditflowRecord(tDkAuditflowRecord));
//    }
//
//    /**
//     * 删除地块核查流程
//     */
//    @RequiresPermissions("rsmonitoring:auditflow:record:remove")
//    @Log(title = "地块核查流程", businessType = BusinessType.DELETE)
//    @DeleteMapping("/{ids}")
//    public AjaxResult remove(@PathVariable String[] ids) {
//        return toAjax(tDkAuditflowRecordService.deleteTDkAuditflowRecordByIds(ids));
//    }


//    /**
//     * 新增地块核查流程
//     */
//    //    @RequiresPermissions("rsmonitoring:auditflow:record:refresh")
//    @Log(title = "更新地块核查流程", businessType = BusinessType.UPDATE)
//    @PostMapping("refresh")
//    public AjaxResult refresh(@RequestBody TDkAuditflowRecord tDkAuditflowRecord) {
//        //更新地块核查流程
//        Map<String, String> refreshData = tDkAuditflowRecordService.refreshTDkAuditflowRecord(tDkAuditflowRecord);
//        if (refreshData == null || refreshData.isEmpty()) {
//            return error("更新地块核查流程出错，请联系相关人员");
//        }
//        //更新地块核查流程与附件关联表
//        String current = refreshData.get("current");
//        List<String> fjList = tDkAuditflowRecord.getAuditflowFj();
//        if (fjList != null && !fjList.isEmpty()) {
//            TDkAuditflowRecordFj tDkAuditflowRecordFj = new TDkAuditflowRecordFj();
//            tDkAuditflowRecordFj.setRecordId(current);
//            tDkAuditflowRecordFj.setCreateTime(DateUtils.getNowDate());
//            tDkAuditflowRecordFj.setCreateBy(tDkAuditflowRecord.getCreateBy());
//            tDkAuditflowRecordFj.setState("0");
//            for (String fj : fjList) {
//                tDkAuditflowRecordFj.setFjId(fj);
//                tDkAuditflowRecordFj.setId(IdUtils.fastSimpleUUID());
//                tDkAuditflowRecordFjService.insertTDkAuditflowRecordFj(tDkAuditflowRecordFj);
//            }
//        }
//        return success(refreshData);
//    }

}
