package com.css.simulation.resource.server.adapter.controller.system_manage.scene_package_manage;

import api.common.pojo.common.ResponseBodyVO;
import api.common.pojo.param.scene.SystemScenePackageParam;
import api.common.pojo.param.scene.SystemUserSceneParam;
import api.common.pojo.po.scene.ScoringRulesPO;
import api.common.pojo.po.scene.SystemScenePackageNewPO;
import api.common.pojo.po.scene.SystemScenePackagePO;
import api.common.pojo.vo.scene.SystemScenePackageVO;
import api.common.pojo.vo.scene.SystemUserSceneVO;
import api.common.util.ObjectUtil;
import com.css.simulation.resource.server.infra.util.PageUtil;
import com.css.simulation.resource.server.app.service.SystemScenePackageService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

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

//场景包
@RestController
@RequestMapping("/SystemScenePackage")
public class ScenePackageController {

    @Resource
    SystemScenePackageService systemScenePackageService;

    //查询列表
    @PostMapping("/querySystemScenePackageList")
    @ResponseBody
    public ResponseBodyVO<List<SystemScenePackageVO>> querySystemScenePackageList(@RequestBody SystemScenePackageParam parms) {
        PageUtil.setPageInfo(parms);
        List<SystemScenePackageVO> list = systemScenePackageService.querySystemScenePackageList(parms);

        return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS, new PageInfo(list));
    }

    //查询场景包详情
    @PostMapping("/querySystemScenePackageById")
    @ResponseBody
    public ResponseBodyVO<SystemScenePackageNewPO> querySystemScenePackageById(@RequestBody SystemScenePackageParam parms) {
        if (ObjectUtil.isNull(parms.getId())) {
            return new ResponseBodyVO(ResponseBodyVO.Response.CLIENT_FAILURE, "参数id不能为空，请检查");
        }
        SystemScenePackageNewPO po = systemScenePackageService.querySystemScenePackageById(parms);
        return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS, po);

    }

    //新增场景包
    @PostMapping("/saveSystemScenePackage")
    @ResponseBody
    public ResponseBodyVO<String> saveSystemScenePackage(@RequestBody SystemScenePackageNewPO parms) {
        if (ObjectUtil.isNotNull(parms.getId())) {
            systemScenePackageService.updateSystemScenePackage(parms);
        } else {
            // return systemScenePackageService.saveSystemScenePackage(parms);
            return systemScenePackageService.saveSystemScenePackageNew(parms);
        }
        return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS);
    }


    //删除
    @PostMapping("/deleteSystemScenePackage")
    @ResponseBody
    public ResponseBodyVO<String> deleteScoringRules(@RequestBody SystemScenePackagePO params) {
        systemScenePackageService.deleteSystemScenePackage(params);
        return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS);
    }

    //编辑场景包
    @PostMapping("/updateSystemScenePackage")
    @ResponseBody
    public ResponseBodyVO<List<ScoringRulesPO>> updateSystemScenePackage(@RequestBody SystemScenePackageNewPO params) {
        systemScenePackageService.updateSystemScenePackage(params);
        return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS);
    }

    //场景包配置账号查询 （未启用）
    @PostMapping("/queryUserByPackageId")
    @ResponseBody
    public ResponseBodyVO<SystemUserSceneVO> queryUserByPackageId(@RequestBody SystemScenePackageNewPO params) {
        SystemUserSceneVO vo = systemScenePackageService.queryUserByPackageId(params);
        return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS, vo);
    }

    //场景包配置账号添加
    @PostMapping("/saveUserByPackageId")
    @ResponseBody
    public ResponseBodyVO<String> saveUserByPackageId(@RequestBody SystemUserSceneParam params) {
        systemScenePackageService.saveUserByPackageId(params);
        return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS);
    }

    //场景包配置账号删除
    @PostMapping("/deleteUserByPackageId")
    @ResponseBody
    public ResponseBodyVO<String> deleteUserByPackageId(@RequestBody SystemUserSceneParam params) {
        systemScenePackageService.deleteUserByPackageId(params);
        return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS);
    }

    //人员表查询测试包详情
    @PostMapping("/queryPackageByUserId")
    @ResponseBody
    public ResponseBodyVO<List<Map>> queryPackageByUserId(@RequestBody SystemScenePackageParam parms) {
        // PageUtil.setPageInfo(parms);
        Map map = systemScenePackageService.queryPackageByUserId(parms);
        return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS, map);
    }

    //人员添加场景包
    @PostMapping("/savePackageByUserId")
    @ResponseBody
    public ResponseBodyVO<String> savePackageByUserId(@RequestBody SystemUserSceneParam params) {
        systemScenePackageService.savePackageByUserId(params);
        return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS);
    }


    //人员场景包列表
    @PostMapping("/queryPackageByUserIdList")
    @ResponseBody
    public ResponseBodyVO<PageInfo<SystemScenePackageVO>> queryPackageByUserIdList(@RequestBody SystemScenePackageParam param) {
        PageUtil.setPageInfo(param);
        List<SystemScenePackageVO> list = systemScenePackageService.queryPackageByUserIdList(param);

        return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS, new PageInfo<>(list));
    }

    // 查询勾选场景数量
    @PostMapping("/querySystemScenePackageListByTJ")
    @ResponseBody
    public ResponseBodyVO<List<Map<String, String>>> querySystemScenePackageListByTJ(@RequestBody SystemScenePackageParam parms) {
        if (ObjectUtil.isNull(parms.getPackageNames())) {
            return new ResponseBodyVO<>(ResponseBodyVO.Response.CLIENT_FAILURE, "参数packageNames不能为空，请检查");
        }

        return systemScenePackageService.querySystemScenePackageListByTJ(parms);
    }
}
