package org.springblade.modules.log.logCsInfo.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.excel.util.ExcelUtil;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.secure.BladeUser;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.constant.BladeConstant;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.log.logCsInfo.entity.LogCsInfoEntity;
import org.springblade.modules.log.logCsInfo.excel.LogCsInfoExcel;
import org.springblade.modules.log.logCsInfo.service.ILogCsInfoService;
import org.springblade.modules.log.logCsInfo.vo.LogCsInfoVO;
import org.springblade.modules.log.logCsInfo.wrapper.LogCsInfoWrapper;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * 日志_九小场所信息变动表 控制器
 *
 * @author BladeX
 * @since 2024-04-17
 */
@RestController
@AllArgsConstructor
@RequestMapping("blade-logCsInfo/logCsInfo")
@Api(value = "日志_九小场所信息变动表", tags = "日志_九小场所信息变动表接口")
public class LogCsInfoController extends BladeController {

	private final ILogCsInfoService logCsInfoService;

	/**
	 * 日志_九小场所信息变动表 详情
	 */
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情", notes = "传入logCsInfo")
	public R<LogCsInfoVO> detail(LogCsInfoEntity logCsInfo) {
		LogCsInfoEntity detail = logCsInfoService.getOne(Condition.getQueryWrapper(logCsInfo));
		return R.data(LogCsInfoWrapper.build().entityVO(detail));
	}

	/**
	 * 日志_九小场所信息变动表 分页
	 */
	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页", notes = "传入logCsInfo")
	public R<IPage<LogCsInfoVO>> list(@ApiIgnore @RequestParam Map<String, Object> logCsInfo, Query query) {
		IPage<LogCsInfoEntity> pages = logCsInfoService.page(Condition.getPage(query), Condition.getQueryWrapper(logCsInfo, LogCsInfoEntity.class));
		return R.data(LogCsInfoWrapper.build().pageVO(pages));
	}

	/**
	 * 日志_九小场所信息变动表 自定义分页
	 */
	@GetMapping("/page")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "分页", notes = "传入logCsInfo")
	public R<IPage<LogCsInfoVO>> page(LogCsInfoVO logCsInfo, Query query) {
		IPage<LogCsInfoVO> pages = logCsInfoService.selectLogCsInfoPage(Condition.getPage(query), logCsInfo);
		return R.data(pages);
	}

	/**
	 * 日志_九小场所信息变动表 新增
	 */
	@PostMapping("/save")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "新增", notes = "传入logCsInfo")
	public R save(@Valid @RequestBody LogCsInfoEntity logCsInfo) {
		return R.status(logCsInfoService.save(logCsInfo));
	}

	/**
	 * 日志_九小场所信息变动表 修改
	 */
	@PostMapping("/update")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "修改", notes = "传入logCsInfo")
	public R update(@Valid @RequestBody LogCsInfoEntity logCsInfo) {
		return R.status(logCsInfoService.updateById(logCsInfo));
	}

	/**
	 * 日志_九小场所信息变动表 新增或修改
	 */
	@PostMapping("/submit")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "新增或修改", notes = "传入logCsInfo")
	public R submit(@Valid @RequestBody LogCsInfoEntity logCsInfo) {
		return R.status(logCsInfoService.saveOrUpdate(logCsInfo));
	}

	/**
	 * 日志_九小场所信息变动表 删除
	 */
	@PostMapping("/remove")
	@ApiOperationSupport(order = 7)
	@ApiOperation(value = "逻辑删除", notes = "传入ids")
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		return R.status(logCsInfoService.deleteLogic(Func.toLongList(ids)));
	}

	/**
	 * 导出数据
	 */
	@GetMapping("/export-logCsInfo")
	@ApiOperationSupport(order = 9)
	@ApiOperation(value = "导出数据", notes = "传入logCsInfo")
	public void exportLogCsInfo(@ApiIgnore @RequestParam Map<String, Object> logCsInfo, BladeUser bladeUser, HttpServletResponse response) {
		QueryWrapper<LogCsInfoEntity> queryWrapper = Condition.getQueryWrapper(logCsInfo, LogCsInfoEntity.class);
		queryWrapper.lambda().eq(LogCsInfoEntity::getIsDeleted, BladeConstant.DB_NOT_DELETED);
		List<LogCsInfoExcel> list = logCsInfoService.exportLogCsInfo(queryWrapper);
		ExcelUtil.export(response, "日志_九小场所信息变动表数据" + DateUtil.time(), "日志_九小场所信息变动表数据表", list, LogCsInfoExcel.class);
	}

}
