package org.springblade.modules.rhzf.aqxcff.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 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.secure.annotation.PreAuth;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.constant.RoleConstant;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.rhzf.aqxcff.excel.RhzfAqxcffExcel;
import org.springblade.modules.rhzf.aqxcff.pojo.entity.RhzfAqxcffEntity;
import org.springblade.modules.rhzf.aqxcff.pojo.vo.RhzfAqxcffVO;
import org.springblade.modules.rhzf.aqxcff.service.IRhzfAqxcffService;
import org.springblade.modules.rhzf.aqxcff.wrapper.RhzfAqxcffWrapper;
import org.springframework.web.bind.annotation.*;

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

/**
 * 入户走访_安全宣传防范 控制器
 *
 * @author wth
 * @since 2024-11-14
 */
@RestController
@AllArgsConstructor
@RequestMapping("/rhzfAqxcff")
@Api(value = "入户走访_安全宣传防范", tags = "入户走访_安全宣传防范接口")
public class RhzfAqxcffController extends BladeController {

	private final IRhzfAqxcffService rhzfAqxcffService;

	/**
	 * 入户走访_安全宣传防范 详情
	 */
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情", notes = "传入rhzfAqxcff")
	public R<RhzfAqxcffVO> detail(RhzfAqxcffEntity rhzfAqxcff) {
		RhzfAqxcffEntity detail = rhzfAqxcffService.getOne(Condition.getQueryWrapper(rhzfAqxcff));
		return R.data(RhzfAqxcffWrapper.build().entityVO(detail));
	}

	/**
	 * 入户走访_安全宣传防范 分页
	 */
	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页", notes = "传入rhzfAqxcff")
	public R<IPage<RhzfAqxcffVO>> list(@RequestParam Map<String, Object> rhzfAqxcff, Query query) {
		IPage<RhzfAqxcffEntity> pages = rhzfAqxcffService.page(Condition.getPage(query), Condition.getQueryWrapper(rhzfAqxcff, RhzfAqxcffEntity.class));
		return R.data(RhzfAqxcffWrapper.build().pageVO(pages));
	}

	/**
	 * 入户走访_安全宣传防范 自定义分页
	 */
	@GetMapping("/page")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "分页", notes = "传入rhzfAqxcff")
	public R<IPage<RhzfAqxcffVO>> page(RhzfAqxcffVO rhzfAqxcff, Query query) {
		IPage<RhzfAqxcffVO> pages = rhzfAqxcffService.selectRhzfAqxcffPage(Condition.getPage(query), rhzfAqxcff);
		return R.data(pages);
	}

	/**
	 * 入户走访_安全宣传防范 新增
	 */
	@PostMapping("/save")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "新增", notes = "传入rhzfAqxcff")
	public R save(@Valid @RequestBody RhzfAqxcffEntity rhzfAqxcff) {
		return R.status(rhzfAqxcffService.save(rhzfAqxcff));
	}

	/**
	 * 入户走访_安全宣传防范 修改
	 */
	@PostMapping("/update")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "修改", notes = "传入rhzfAqxcff")
	public R update(@Valid @RequestBody RhzfAqxcffEntity rhzfAqxcff) {
		return R.status(rhzfAqxcffService.updateById(rhzfAqxcff));
	}

	/**
	 * 入户走访_安全宣传防范 新增或修改
	 */
	@PostMapping("/submit")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "新增或修改", notes = "传入rhzfAqxcff")
	public R submit(@Valid @RequestBody RhzfAqxcffEntity rhzfAqxcff) {
		return R.status(rhzfAqxcffService.saveOrUpdate(rhzfAqxcff));
	}

	/**
	 * 入户走访_安全宣传防范 删除
	 */
	@PostMapping("/remove")
	@ApiOperationSupport(order = 7)
	@ApiOperation(value = "逻辑删除", notes = "传入ids")
	public R remove(@RequestParam String ids) {
		return R.status(rhzfAqxcffService.deleteLogic(Func.toLongList(ids)));
	}

	/**
	 * 导出数据
	 */
	@PreAuth(RoleConstant.HAS_ROLE_ADMIN)
	@GetMapping("/export-rhzfAqxcff")
	@ApiOperationSupport(order = 8)
	@ApiOperation(value = "导出数据", notes = "传入rhzfAqxcff")
	public void exportRhzfAqxcff(@RequestParam Map<String, Object> rhzfAqxcff, BladeUser bladeUser, HttpServletResponse response) {
		QueryWrapper<RhzfAqxcffEntity> queryWrapper = Condition.getQueryWrapper(rhzfAqxcff, RhzfAqxcffEntity.class);
		//if (!AuthUtil.isAdministrator()) {
		//	queryWrapper.lambda().eq(RhzfAqxcffEntity::getTenantId, bladeUser.getTenantId());
		//}
		//queryWrapper.lambda().eq(RhzfAqxcffEntity::getIsDeleted, BladeConstant.DB_NOT_DELETED);
		List<RhzfAqxcffExcel> list = rhzfAqxcffService.exportRhzfAqxcff(queryWrapper);
		ExcelUtil.export(response, "入户走访_安全宣传防范数据" + DateUtil.time(), "入户走访_安全宣传防范数据表", list, RhzfAqxcffExcel.class);
	}

}
