package org.jeecg.modules.stm.project.create.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.project.create.service.IStProjectCreService;
import org.jeecg.modules.stm.project.create.entity.StProjectCre;

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;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.jeecg.modules.stm.project.create.vo.ProjectConfigVo;
import org.jeecg.modules.stm.project.create.vo.ProjectImportVo;
import org.jeecg.modules.stm.project.create.vo.TwoProjectConfigVo;

/**
 * @Description: 项目立项
 * @Author: jeecg-boot
 * @Date:   2023-08-13
 * @Version: V1.0
 */

@RestController
@RequestMapping("/project.create/stProjectCre")
@Slf4j
public class StProjectCreController extends JeecgController<StProjectCre, IStProjectCreService> {
	@Autowired
	private IStProjectCreService stProjectCreService;
	
	/**
	 * 分页列表查询
	 *
	 * @param stProjectCre
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	//@AutoLog(value = "项目立项-分页列表查询")

	@GetMapping(value = "/list")
	public Result<IPage<StProjectCre>> queryPageList(StProjectCre stProjectCre,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
		QueryWrapper<StProjectCre> queryWrapper = QueryGenerator.initQueryWrapper(stProjectCre, req.getParameterMap());
		Page<StProjectCre> page = new Page<StProjectCre>(pageNo, pageSize);
		IPage<StProjectCre> pageList = stProjectCreService.defPage(page, queryWrapper);
		return Result.OK(pageList);
	}


	 @GetMapping(value = "/listPrepar")
	 public Result<IPage<StProjectCre>> queryPreparPageList(StProjectCre stProjectCre,
													  @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
													  @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
													  HttpServletRequest req) {
		 QueryWrapper<StProjectCre> queryWrapper = QueryGenerator.initQueryWrapper(stProjectCre, req.getParameterMap());
		 Page<StProjectCre> page = new Page<StProjectCre>(pageNo, pageSize);
		 IPage<StProjectCre> pageList = stProjectCreService.pagePrepar(page, queryWrapper);
		 return Result.OK(pageList);
	 }
	
	/**
	 *   添加
	 *
	 * @param stProjectCre
	 * @return
	 */
	@AutoLog(value = "项目立项-添加")

	@RequiresPermissions("project.create:st_project_cre:add")
	@PostMapping(value = "/add")
	public Result<String> add(@RequestBody StProjectCre stProjectCre) {
		stProjectCreService.save(stProjectCre);
		return Result.OK("添加成功！");
	}
	
	/**
	 *  编辑
	 *
	 * @param stProjectCre
	 * @return
	 */
	@AutoLog(value = "项目立项-编辑")

	@RequiresPermissions("project.create:st_project_cre:edit")
	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
	public Result<String> edit(@RequestBody StProjectCre stProjectCre) {
		stProjectCreService.updateById(stProjectCre);
		return Result.OK("编辑成功!");
	}

	 @AutoLog(value = "项目立项-审核")

	 @RequiresPermissions("project.create:st_project_cre:edit")
	 @RequestMapping(value = "/approve", method = {RequestMethod.PUT,RequestMethod.POST})
	 public Result<String> approve(@RequestBody StProjectCre stProjectCre) {
		 stProjectCreService.approve(stProjectCre);
		 return Result.OK("审核成功!");
	 }
	
	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "项目立项-通过id删除")

	@RequiresPermissions("project.create:st_project_cre:delete")
	@DeleteMapping(value = "/delete")
	public Result<String> delete(@RequestParam(name="id",required=true) String id) {
		stProjectCreService.removeById(id);
		return Result.OK("删除成功!");
	}
	
	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "项目立项-批量删除")

	@RequiresPermissions("project.create:st_project_cre:deleteBatch")
	@DeleteMapping(value = "/deleteBatch")
	public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.stProjectCreService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}
	
	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	//@AutoLog(value = "项目立项-通过id查询")

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

    /**
    * 导出excel
    *
    * @param request
    * @param stProjectCre
    */
    @RequiresPermissions("project.create:st_project_cre:exportXls")
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, StProjectCre stProjectCre) {
        return super.exportXls(request, stProjectCre, StProjectCre.class, "项目立项");
    }

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


	 @AutoLog(value = "项目准备第一步")

	 @RequiresPermissions("project.create:st_project_cre:add")
	 @PostMapping(value = "/addOneStep")
	 public Result<String> addOneStep(@RequestBody ProjectConfigVo projectConfigVo) {
		 stProjectCreService.saveOneStep(projectConfigVo);
		 return Result.OK("添加成功！");
	 }

	@AutoLog(value = "项目准备第二步")

	@RequiresPermissions("project.create:st_project_cre:add")
	@PostMapping(value = "/addTwoStep")
	public Result<String> addTwoStep(@RequestBody TwoProjectConfigVo twoProjectConfigVo) {
		stProjectCreService.saveTwoStep(twoProjectConfigVo);
		return Result.OK("添加成功！");
	}

	@AutoLog(value = "项目准备第三步")

	@RequiresPermissions("project.create:st_project_cre:add")
	@PostMapping(value = "/add3Step")
	public Result<String> add3Step(@RequestBody TwoProjectConfigVo twoProjectConfigVo) {
		stProjectCreService.add3Step(twoProjectConfigVo);
		return Result.OK("添加成功！");
	}

	@AutoLog(value = "项目准备第三步")

	@RequiresPermissions("project.create:st_project_cre:add")
	@PostMapping(value = "/add4Step")
	public Result<String> add4Step(@RequestBody TwoProjectConfigVo twoProjectConfigVo) {
		stProjectCreService.add4Step(twoProjectConfigVo);
		return Result.OK("添加成功！");
	}

	@AutoLog(value = "项目准备第5步")

	@RequiresPermissions("project.create:st_project_cre:add")
	@PostMapping(value = "/add5Step")
	public Result<String> add5Step(@RequestBody TwoProjectConfigVo twoProjectConfigVo) {
		stProjectCreService.add5Step(twoProjectConfigVo);
		return Result.OK("添加成功！");
	}

	@AutoLog(value = "项目准备第5步")

	@RequiresPermissions("project.create:st_project_cre:add")
	@PostMapping(value = "/add6Step")
	public Result<String> add6Step(@RequestBody TwoProjectConfigVo twoProjectConfigVo) {
		stProjectCreService.add6Step(twoProjectConfigVo);
		return Result.OK("添加成功！");
	}

	@AutoLog(value = "项目准备第5步")

	@RequiresPermissions("project.create:st_project_cre:add")
	@PostMapping(value = "/add7Step")
	public Result<String> add7Step(@RequestBody TwoProjectConfigVo twoProjectConfigVo) {
		stProjectCreService.add7Step(twoProjectConfigVo);
		return Result.OK("添加成功！");
	}

	@AutoLog(value = "项目准备第5步")

	@RequiresPermissions("project.create:st_project_cre:add")
	@PostMapping(value = "/submitPrepate")
	public Result<String> submitPrepate(@RequestBody TwoProjectConfigVo twoProjectConfigVo){
		stProjectCreService.submitPrepate(twoProjectConfigVo);
		return Result.OK("添加成功！");
	}

	@AutoLog(value = "项目准备第5步")

	@RequiresPermissions("project.create:st_project_cre:add")
	@PostMapping(value = "/save2Submit")
	public Result<String> save2Submit(@RequestBody TwoProjectConfigVo twoProjectConfigVo){
		stProjectCreService.save2Submit(twoProjectConfigVo);
		return Result.OK("添加成功！");
	}


	@AutoLog(value = "项目导入操作")

	@RequiresPermissions("project.create:st_project_cre:add")
	@PostMapping(value = "/projectImport")
	public Result<String> projectImport(@RequestBody ProjectImportVo projectImportVo){
		stProjectCreService.projectImport(projectImportVo);
		return Result.OK("导入成功！");
	}
}
