package org.jeecg.modules.stm.bcs.streTest.controller;

import java.util.Arrays;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.stm.bcs.streTest.entity.BcsStreTest;
import org.jeecg.modules.stm.bcs.streTest.entity.BcsStreTestexe;
import org.jeecg.modules.stm.bcs.streTest.service.IBcsStreTestService;
import org.jeecg.modules.stm.bcs.streTest.service.IBcsStreTestexeService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.jeecg.common.system.base.controller.JeecgController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
 
 
import org.jeecg.common.aspect.annotation.AutoLog;

/**
 * @Description: 压力测试执行
 * @Author: jeecg-boot
 * @Date:   2025-10-07
 * @Version: V1.0
 */

@RestController
@RequestMapping("/bcs.streTest/bcsStreTestexe")
@Slf4j
public class BcsStreTestexeController extends JeecgController<BcsStreTestexe, IBcsStreTestexeService> {
	@Autowired
	private IBcsStreTestexeService bcsStreTestexeService;
	 @Autowired
	 private IBcsStreTestService bcsStreTestService;
	
	/**
	 * 分页列表查询
	 *
	 * @param bcsStreTestexe
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	//@AutoLog(value = "压力测试执行-分页列表查询")

	@GetMapping(value = "/list")
	public Result<IPage<BcsStreTestexe>> queryPageList(BcsStreTestexe bcsStreTestexe,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
		QueryWrapper<BcsStreTestexe> queryWrapper = QueryGenerator.initQueryWrapper(bcsStreTestexe, req.getParameterMap());
		Page<BcsStreTestexe> page = new Page<BcsStreTestexe>(pageNo, pageSize);
		IPage<BcsStreTestexe> pageList = bcsStreTestexeService.page(page, queryWrapper);
		return Result.OK(pageList);
	}
	
	/**
	 *   添加
	 *
	 * @param bcsStreTestexe
	 * @return
	 */
	@AutoLog(value = "压力测试执行-添加")

	//@RequiresPermissions("bcs.streTest:bcs_stre_testexe:add")
	@PostMapping(value = "/add")
	public Result<String> add(@RequestBody BcsStreTestexe bcsStreTestexe) {

		BcsStreTest bcsStreTest =new BcsStreTest();
		bcsStreTest.setExeSta("1");
		bcsStreTest.setId(bcsStreTestexe.getTestId());;
		bcsStreTestService.updateById(bcsStreTest);

		bcsStreTestexeService.save(bcsStreTestexe);
		return Result.OK("添加成功！");
	}
	
	/**
	 *  编辑
	 *
	 * @param bcsStreTestexe
	 * @return
	 */
	@AutoLog(value = "压力测试执行-编辑")

	//@RequiresPermissions("bcs.streTest:bcs_stre_testexe:edit")
	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
	public Result<String> edit(@RequestBody BcsStreTestexe bcsStreTestexe) {
		bcsStreTestexeService.updateById(bcsStreTestexe);
		return Result.OK("编辑成功!");
	}
	
	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "压力测试执行-通过id删除")

	//@RequiresPermissions("bcs.streTest:bcs_stre_testexe:delete")
	@DeleteMapping(value = "/delete")
	public Result<String> delete(@RequestParam(name="id",required=true) String id) {
		bcsStreTestexeService.removeById(id);
		return Result.OK("删除成功!");
	}
	
	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "压力测试执行-批量删除")

	//@RequiresPermissions("bcs.streTest:bcs_stre_testexe:deleteBatch")
	@DeleteMapping(value = "/deleteBatch")
	public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.bcsStreTestexeService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}
	
	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	//@AutoLog(value = "压力测试执行-通过id查询")

	@GetMapping(value = "/queryById")
	public Result<BcsStreTestexe> queryById(@RequestParam(name="id",required=true) String id) {
		BcsStreTestexe bcsStreTestexe = bcsStreTestexeService.getById(id);
		if(bcsStreTestexe==null) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(bcsStreTestexe);
	}


	 /**
	  * 通过testId查询
	  *
	  * @param testId
	  * @return
	  */
	 //@AutoLog(value = "压力测试执行-通过id查询")

	 @GetMapping(value = "/queryByTestId")
	 public Result<BcsStreTestexe> queryByTestId(@RequestParam(name="testId",required=true) String testId) {
		 BcsStreTestexe bcsStreTestexe = bcsStreTestexeService.queryTestexeByTestid(Integer.parseInt(testId));
		 if(bcsStreTestexe==null) {
			 return Result.error("未找到对应数据");
		 }
		 return Result.OK(bcsStreTestexe);
	 }

    /**
    * 导出excel
    *
    * @param request
    * @param bcsStreTestexe
    */
    //@RequiresPermissions("bcs.streTest:bcs_stre_testexe:exportXls")
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, BcsStreTestexe bcsStreTestexe) {
        return super.exportXls(request, bcsStreTestexe, BcsStreTestexe.class, "压力测试执行");
    }

    /**
      * 通过excel导入数据
    *
    * @param request
    * @param response
    * @return
    */
    //@RequiresPermissions("bcs.streTest:bcs_stre_testexe:importExcel")
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, BcsStreTestexe.class);
    }

}
