package org.jeecg.modules.stm.act.collection.controller;

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.apache.shiro.authz.annotation.RequiresPermissions;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.stm.act.collection.service.IStCaMainCollectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import org.jeecg.modules.stm.act.collection.entity.StCaMainCollection;

import jakarta.servlet.http.HttpServletRequest;

import java.util.Arrays;

 /**
 * @Description: 活动集合
 * @Author: yzh
 * @Date:   2023-03-06
 * @Version: V1.0
 */

@RestController
@RequestMapping("/act.collection/stCaMainCollection")
@Slf4j
public class StCaMainCollectionController extends JeecgController<StCaMainCollection, IStCaMainCollectionService> {
	@Autowired
	private IStCaMainCollectionService stCaMainCollectionService;
	
	/**
	 * 分页列表查询
	 *
	 * @param stCaMainCollection
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	//@AutoLog(value = "活动集合-分页列表查询")

	@GetMapping(value = "/list")
	public Result<IPage<StCaMainCollection>> queryPageList(StCaMainCollection stCaMainCollection,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
		QueryWrapper<StCaMainCollection> queryWrapper = QueryGenerator.initQueryWrapper(stCaMainCollection, req.getParameterMap());
		Page<StCaMainCollection> page = new Page<StCaMainCollection>(pageNo, pageSize);
		IPage<StCaMainCollection> pageList = stCaMainCollectionService.page(page, queryWrapper);
		return Result.OK(pageList);
	}
	
	/**
	 *   添加
	 *
	 * @param stCaMainCollection
	 * @return
	 */
	@AutoLog(value = "活动集合-添加")

	@RequiresPermissions("act.collection:st_ca_main_collection:add")
	@PostMapping(value = "/add")
	public Result<String> add(@RequestBody StCaMainCollection stCaMainCollection) {
		stCaMainCollectionService.save(stCaMainCollection);
		return Result.OK("添加成功！");
	}
	
	/**
	 *  编辑
	 *
	 * @param stCaMainCollection
	 * @return
	 */
	@AutoLog(value = "活动集合-编辑")
	@RequiresPermissions("act.collection:st_ca_main_collection:edit")
	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
	public Result<String> edit(@RequestBody StCaMainCollection stCaMainCollection) {
		stCaMainCollectionService.updateById(stCaMainCollection);
		return Result.OK("编辑成功!");
	}
	
	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "活动集合-通过id删除")

	@RequiresPermissions("act.collection:st_ca_main_collection:delete")
	@DeleteMapping(value = "/delete")
	public Result<String> delete(@RequestParam(name="id",required=true) String id) {
		stCaMainCollectionService.removeById(id);
		return Result.OK("删除成功!");
	}


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


}
