package com.hotent.uc.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.hotent.base.annotation.ApiGroup;
import com.hotent.base.constants.ApiGroupConsts;
import com.hotent.base.controller.BaseController;
import com.hotent.base.controller.BaseController2;
import com.hotent.base.feign.BpmModelFeignService;
import com.hotent.base.model.CommonResult;
import com.hotent.base.query.PageList;
import com.hotent.base.query.QueryFilter;
import com.hotent.base.util.BeanUtils;
import com.hotent.base.util.StringUtil;
import com.hotent.uc.manager.MatrixProcRelationManager;
import com.hotent.uc.model.MatrixProcRelation;
import com.hotent.uc.model.MatrixProcRelationWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Iterator;
import java.util.List;

/**
 * <pre>
 * 描述：矩阵流程关系表 控制器类
 * 构建组：x7
 * 作者:zjq
 * 邮箱:zjq@jee-soft.cn
 * 日期:2021-01-16 17:10:08
 * 版权：广州宏天软件股份有限公司
 * </pre>
 */
@RestController
@RequestMapping(value = "/uc/matrixProcRelation/v2/")
@Api(tags = "matrixProcRelationController2")
@ApiGroup(group= {ApiGroupConsts.GROUP_UC})
public class MatrixProcRelationController2 extends BaseController2<MatrixProcRelationManager, MatrixProcRelation> {
    @Resource
    MatrixProcRelationManager matrixProcRelationManager;
    @Resource
    BpmModelFeignService bpmModelFeignService;

    /**
     * 矩阵流程关系表列表(分页条件查询)数据
     *
     * @param queryFilter
     * @return
     * @throws Exception PageJson
     * @throws
     */
    @PostMapping("listJson")
    @ApiOperation(value = "矩阵流程关系表数据列表", httpMethod = "POST", notes = "获取矩阵流程关系表列表")
    public CommonResult<PageList<MatrixProcRelation>> list(@ApiParam(name = "queryFilter", value = "查询对象") @RequestBody QueryFilter queryFilter) throws Exception {
        PageList<MatrixProcRelation> list = matrixProcRelationManager.getList(queryFilter);
        return CommonResult.<PageList<MatrixProcRelation>>ok().value(list);
    }


    /**
     * 新增矩阵流程关系表
     *
     * @param matrixProcRelation
     * @return
     * @throws Exception
     * @throws
     */
    @PostMapping(value = "save")
    @ApiOperation(value = "新增,更新矩阵流程关系表数据", httpMethod = "POST", notes = "新增,更新矩阵流程关系表数据")
    public CommonResult<String> save(@ApiParam(name = "matrixProcRelation", value = "矩阵流程关系表业务对象", required = true) @RequestBody MatrixProcRelation matrixProcRelation) throws Exception {
        String msg = "添加矩阵流程关系表成功";
        if (StringUtil.isEmpty(matrixProcRelation.getId())) {
            matrixProcRelationManager.create(matrixProcRelation);
        } else {
            matrixProcRelationManager.update(matrixProcRelation);
            msg = "更新矩阵流程关系表成功";
        }
        return CommonResult.<String>ok().message(msg);
    }



    @PostMapping(value = "batchHandle")
    @ApiOperation(value = "批量增删矩阵流程关系表数据", httpMethod = "POST", notes = "批量增删矩阵流程关系表数据")
    public CommonResult<String> batchHandle(@ApiParam(name = "relationObjNode", value = "矩阵流程关系新旧数据", required = true) @RequestBody MatrixProcRelationWrapper relationObjNode) throws Exception {
        List<MatrixProcRelation> oldMatrixProcRelations = relationObjNode.getOldMatrixProcRelations();
        List<MatrixProcRelation> newMatrixProcRelations = relationObjNode.getNewMatrixProcRelations();
        matrixProcRelationManager.batchHandle(oldMatrixProcRelations, newMatrixProcRelations);
        String msg = "批量增删矩阵流程关系成功";
        return CommonResult.<String>ok().message(msg);
    }

    @PostMapping(value = "removeByProcDefKey")
    @ApiOperation(value = "通过流程定义Key删除矩阵流程关系表记录", httpMethod = "POST", notes = "通过流程定义Key删除矩阵流程关系表记录")
    public CommonResult<String> removeByProcDefKey(@ApiParam(name = "procDefKey", value = "流程定义Key", required = true) @RequestParam String procDefKey) throws Exception {
        QueryWrapper<MatrixProcRelation> wrapper = new QueryWrapper<>();
        wrapper.eq("proc_def_key_", procDefKey);
        matrixProcRelationManager.remove(wrapper);
        String msg = "批量删除成功";
        return CommonResult.<String>ok().message(msg);
    }
}
