package com.siwei.rsmonitoring.controller;

import com.siwei.common.core.exception.ServiceException;
import com.siwei.common.core.utils.StringUtils;
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.utils.SecurityUtils;
import com.siwei.rsmonitoring.domain.TDkFieldwork;
import com.siwei.rsmonitoring.domain.vo.DataCountVo;
import com.siwei.rsmonitoring.service.ITDkFieldworkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 地块外业分配Controller
 *
 * @author siwei
 * @date 2025-01-21
 */
@RestController
@RequestMapping("/fieldwork")
public class TFieldworkController extends BaseController {
    @Autowired
    private ITDkFieldworkService tDkFieldworkService;

    /**
     * 核查图斑数据汇总
     */
    @GetMapping("/hc/count")
    public AjaxResult hcCount() {
        Long userid = SecurityUtils.getUserId();
        if (null == userid) {
            return error("未登录");
        }
        String queryUserId = userid.toString();
        return success(tDkFieldworkService.hcCount(queryUserId));
    }

    /**
     * 查询地块外业分配列表
     */
//    @RequiresPermissions("rsmonitoring:fieldwork:list")
    @GetMapping("/list")
    public TableDataInfo list(TDkFieldwork tDkFieldwork) {
        Long userid = SecurityUtils.getUserId();
        if (null == userid) {
            throw new ServiceException("未登录");
        }
        startPage();
        tDkFieldwork.setFieldworkId(userid.toString());
        List<TDkFieldwork> list = tDkFieldworkService.selectTDkFieldworkList(tDkFieldwork);
        return getDataTable(list);
    }

    //    @RequiresPermissions("rsmonitoring:fieldwork:list")
    @PostMapping("/confirm")
    public AjaxResult confirm(@RequestBody TDkFieldwork tDkFieldwork) {
        Long userid = SecurityUtils.getUserId();
        if (null == userid) {
            throw new ServiceException("未登录");
        }
        return toAjax(tDkFieldworkService.confirmTDkFieldwork(tDkFieldwork));
    }

}
