package com.css.txw.gxzx.controller;

import com.css.ggzc.framework.cache.vo.DmbDTO;
import com.css.ggzc.framework.common.pojo.CommonResult;
import com.css.ggzc.framework.common.pojo.PageResult;
import com.css.ggzc.framework.common.util.gy.GyUtils;
import com.css.txw.gxzx.pojo.lsjy.BatchDeleteZcxxReqVO;
import com.css.txw.gxzx.pojo.lsjy.GxzxLsjyZcxxDto;
import com.css.txw.gxzx.pojo.lsjy.ZcsxjReqVO;
import com.css.txw.gxzx.pojo.lsjy.ZcxxcxRequestVO;
import com.css.txw.gxzx.pojo.vo.GxspReqVO;
import com.css.txw.gxzx.pojo.vo.ShqkxxVO;
import com.css.txw.gxzx.service.lsjy.GxzxLsjyZcxxService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotBlank;
import java.util.List;

@Slf4j
@RestController
@Tag(name = "绿色交易")
@RequestMapping("lsjy")
public class LsjyController {

    @Resource
    private GxzxLsjyZcxxService gxzxLsjyZcxxService;

    @Operation(summary = "获取资产类型列表")
    @GetMapping("/queryZclxList")
    public CommonResult queryZclxList() {
        List<DmbDTO> list = gxzxLsjyZcxxService.queryZclxList();
        return CommonResult.success(list);
    }

    @Operation(summary = "获取资产信息列表（分页）")
    @PostMapping("/queryZcxxList")
    public CommonResult queryZcxxList(@Validated @RequestBody ZcxxcxRequestVO requestVO) {
        PageResult<GxzxLsjyZcxxDto> pageData = gxzxLsjyZcxxService.queryZcxxList(requestVO);
        return CommonResult.success(pageData);
    }

    @Operation(summary = "获取资产信息详情")
    @GetMapping("/queryZcxxxq")
    public CommonResult queryZcxxxq(@RequestParam @NotBlank String zcid) {
        if (GyUtils.isNull(zcid)) {
            return CommonResult.error("资产id不能为空");
        }
        GxzxLsjyZcxxDto zcxxxq = gxzxLsjyZcxxService.queryZcxxxq(zcid);
        return CommonResult.success(zcxxxq);
    }

    @Operation(summary = "保存/修改资产信息")
    @PostMapping("/saveOrUpdate")
    public CommonResult saveOrUpdate(@RequestBody GxzxLsjyZcxxDto dto) {
        String squuid = gxzxLsjyZcxxService.saveOrUpdate(dto);
        return CommonResult.success(squuid);
    }

    @Operation(summary = "删除资产信息")
    @PostMapping("/delete/{zcid}")
    public CommonResult delete(@PathVariable("zcid") @NotBlank String zcid) {
        boolean result = gxzxLsjyZcxxService.removeById(zcid);
        return CommonResult.success(result);
    }

    @Operation(summary = "批量删除资产信息")
    @PostMapping("/batchDelete")
    public CommonResult batchDelete(@RequestBody BatchDeleteZcxxReqVO reqVO) {
        boolean result = gxzxLsjyZcxxService.batchDelete(reqVO);
        return CommonResult.success(result);
    }

    @Operation(summary = "获取待审批资产信息（分页）")
    @PostMapping("/queryDspZcxxList")
    public CommonResult queryDspZcxxList(@Validated @RequestBody ZcxxcxRequestVO requestVO) {
        PageResult<ShqkxxVO> pageData = gxzxLsjyZcxxService.queryDspZcxxList(requestVO);
        return CommonResult.success(pageData);
    }

    @Operation(summary = "审批资产")
    @PostMapping("/zcSp")
    public CommonResult<String> zcSp(@RequestBody GxspReqVO reqVO){
        return CommonResult.success(gxzxLsjyZcxxService.zcSp(reqVO));
    }

    @Operation(summary = "资产上下架")
    @PostMapping("/zcsxj")
    public CommonResult<String> zcsxj(@RequestBody ZcsxjReqVO reqVO){
        return CommonResult.success(gxzxLsjyZcxxService.zcsxj(reqVO));
    }
}
