package org.jeecg.modules.stm.project.record.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.record.service.IStProjectRecordService;
import org.jeecg.modules.stm.project.record.entity.StProjectRecord;
import org.jeecg.modules.stm.project.record.vo.StProjectRecordVo;

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;

 /**
 * @Description: 项目归档
 * @Author: jeecg-boot
 * @Date:   2023-08-17
 * @Version: V1.0
 */
  
@RestController
@RequestMapping("/project.record/stProjectRecord")
@Slf4j
public class StProjectRecordController extends JeecgController<StProjectRecord, IStProjectRecordService> {
	@Autowired
	private IStProjectRecordService stProjectRecordService;
	
	/**
	 * 分页列表查询
	 *
	 * @param stProjectRecord
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	//@AutoLog(value = "项目归档-分页列表查询")
	  
	@GetMapping(value = "/list")
	public Result<IPage<StProjectRecordVo>> queryPageList(StProjectRecordVo stProjectRecordVo,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
		QueryWrapper<StProjectRecordVo> queryWrapper = QueryGenerator.initQueryWrapper(stProjectRecordVo, req.getParameterMap());
		Page<StProjectRecordVo> page = new Page<StProjectRecordVo>(pageNo, pageSize);
		IPage<StProjectRecordVo> pageList = stProjectRecordService.queryStProjectRecordVoByPage(page, stProjectRecordVo);
		return Result.OK(pageList);
	}
	
	/**
	 *   添加
	 *
	 * @param stProjectRecord
	 * @return
	 */
	@AutoLog(value = "项目归档-添加")
	  
	@RequiresPermissions("project.record:st_project_record:add")
	@PostMapping(value = "/add")
	public Result<String> add(@RequestBody StProjectRecord stProjectRecord) {
		stProjectRecordService.save(stProjectRecord);
		return Result.OK("添加成功！");
	}
	
	/**
	 *  编辑
	 *
	 * @param stProjectRecord
	 * @return
	 */
	@AutoLog(value = "项目归档-编辑")
	  
	@RequiresPermissions("project.record:st_project_record:edit")
	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
	public Result<String> edit(@RequestBody StProjectRecord stProjectRecord) {
		if(stProjectRecord.getId()==null){
			stProjectRecordService.save(stProjectRecord);			
		}else{
			stProjectRecordService.updateById(stProjectRecord);			
		}
		return Result.OK("编辑成功!");
	}
	
	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "项目归档-通过id删除")
	  
	@RequiresPermissions("project.record:st_project_record:delete")
	@DeleteMapping(value = "/delete")
	public Result<String> delete(@RequestParam(name="id",required=true) String id) {
		stProjectRecordService.removeById(id);
		return Result.OK("删除成功!");
	}
	
	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "项目归档-批量删除")
	  
	@RequiresPermissions("project.record:st_project_record:deleteBatch")
	@DeleteMapping(value = "/deleteBatch")
	public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.stProjectRecordService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}
	
	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	//@AutoLog(value = "项目归档-通过id查询")
	  
	@GetMapping(value = "/queryById")
	public Result<StProjectRecord> queryById(@RequestParam(name="id",required=true) String id) {
		StProjectRecord stProjectRecord = stProjectRecordService.getById(id);
		if(stProjectRecord==null) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(stProjectRecord);
	}

    /**
    * 导出excel
    *
    * @param request
    * @param stProjectRecord
    */
    @RequiresPermissions("project.record:st_project_record:exportXls")
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, StProjectRecord stProjectRecord) {
        return super.exportXls(request, stProjectRecord, StProjectRecord.class, "项目归档");
    }

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

}
