package com.unis.crk.common.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.unis.crk.common.entity.Bizflowtrail;
import com.unis.crk.common.service.IBizflowtrailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.unis.crk.utils.ResultUtil;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * <p>
 * 数据流程节点轨迹记录表 前端控制器
 * </p>
 *
 * @author TangSong
 * @since 2021-09-28
 */
@Api(value = "数据流程节点轨迹记录表", tags = {"数据流程节点轨迹记录表"})
@RestController
@RequestMapping("bizflowtrail")
@CrossOrigin
public class BizflowtrailController {

    private final static Logger LOGGER = LoggerFactory.getLogger(BizflowtrailController.class);


    @Autowired
    private IBizflowtrailService bizflowtrailService;


    /**
     * 根据ID查询数据
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "查询", notes = "根据ID查询数据")
    @GetMapping("getOne/{id}")
    public ResultUtil getOne(@PathVariable("id") String id) {
        LOGGER.info("入参为:{}", id);
        ResultUtil<Bizflowtrail> data = new ResultUtil<>();
        if (StringUtils.isEmpty(id)) {
            data.failed("传入的主键为空");
            return data;
        }
        data.success(this.bizflowtrailService.getById(id));
        return data;
    }


    /**
     * 通过单位查询相应数据
     *
     * @param bizNo 单据号
     * @return
     */
    @ApiOperation(value = "查询", notes = "查询全部数据")
    @GetMapping("getAllByBizNo/{bizNo}")
    public ResultUtil getAll(@PathVariable("bizNo") String bizNo) {
        ResultUtil<List<Bizflowtrail>> data = new ResultUtil<>();
        QueryWrapper<Bizflowtrail> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("BillNo", bizNo);
        queryWrapper.orderByDesc("TrailOrder");//按节点排序
        data.success(this.bizflowtrailService.list(queryWrapper));
        return data;
    }


}

