package org.springblade.modules.rhzf.gzyj.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.gzyj.excel.RhzfGzyjExcel;
import org.springblade.modules.rhzf.gzyj.pojo.entity.RhzfGzyjEntity;
import org.springblade.modules.rhzf.gzyj.pojo.vo.RhzfGzyjVO;
import org.springblade.modules.rhzf.gzyj.service.IRhzfGzyjService;
import org.springblade.modules.rhzf.gzyj.wrapper.RhzfGzyjWrapper;
import org.springframework.web.bind.annotation.*;

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

/**
 * 入户走访_意见征集 控制器
 *
 * @author wth
 * @since 2024-11-14
 */
@RestController
@AllArgsConstructor
@RequestMapping("/rhzfGzyj")
@Api(value = "入户走访_意见征集", tags = "入户走访_意见征集接口")
public class RhzfGzyjController extends BladeController {

	private final IRhzfGzyjService rhzfGzyjService;

	/**
	 * 入户走访_意见征集 详情
	 */
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情", notes = "传入rhzfGzyj")
	public R<RhzfGzyjVO> detail(RhzfGzyjEntity rhzfGzyj) {
		RhzfGzyjEntity detail = rhzfGzyjService.getOne(Condition.getQueryWrapper(rhzfGzyj));
		return R.data(RhzfGzyjWrapper.build().entityVO(detail));
	}

	/**
	 * 入户走访_意见征集 分页
	 */
	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页", notes = "传入rhzfGzyj")
	public R<IPage<RhzfGzyjVO>> list(@RequestParam Map<String, Object> rhzfGzyj, Query query) {
		IPage<RhzfGzyjEntity> pages = rhzfGzyjService.page(Condition.getPage(query), Condition.getQueryWrapper(rhzfGzyj, RhzfGzyjEntity.class));
		return R.data(RhzfGzyjWrapper.build().pageVO(pages));
	}

	/**
	 * 入户走访_意见征集 自定义分页
	 */
	@GetMapping("/page")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "分页", notes = "传入rhzfGzyj")
	public R<IPage<RhzfGzyjVO>> page(RhzfGzyjVO rhzfGzyj, Query query) {
		IPage<RhzfGzyjVO> pages = rhzfGzyjService.selectRhzfGzyjPage(Condition.getPage(query), rhzfGzyj);
		return R.data(pages);
	}

	/**
	 * 入户走访_意见征集 新增
	 */
	@PostMapping("/save")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "新增", notes = "传入rhzfGzyj")
	public R save(@RequestBody RhzfGzyjEntity rhzfGzyj) {
		return R.status(rhzfGzyjService.save(rhzfGzyj));
	}

	/**
	 * 入户走访_意见征集 修改
	 */
	@PostMapping("/update")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "修改", notes = "传入rhzfGzyj")
	public R update(@RequestBody RhzfGzyjEntity rhzfGzyj) {
		return R.status(rhzfGzyjService.updateById(rhzfGzyj));
	}

	/**
	 * 入户走访_意见征集 新增或修改
	 */
	@PostMapping("/submit")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "新增或修改", notes = "传入rhzfGzyj")
	public R submit(@RequestBody RhzfGzyjEntity rhzfGzyj) {
		return R.status(rhzfGzyjService.saveOrUpdate(rhzfGzyj));
	}

	/**
	 * 入户走访_意见征集 删除
	 */
	@PostMapping("/remove")
	@ApiOperationSupport(order = 7)
	@ApiOperation(value = "逻辑删除", notes = "传入ids")
	public R remove(@RequestParam String ids) {
		return R.status(rhzfGzyjService.deleteLogic(Func.toLongList(ids)));
	}

	/**
	 * 导出数据
	 */
	@PreAuth(RoleConstant.HAS_ROLE_ADMIN)
	@GetMapping("/export-rhzfGzyj")
	@ApiOperationSupport(order = 8)
	@ApiOperation(value = "导出数据", notes = "传入rhzfGzyj")
	public void exportRhzfGzyj(@RequestParam Map<String, Object> rhzfGzyj, BladeUser bladeUser, HttpServletResponse response) {
		QueryWrapper<RhzfGzyjEntity> queryWrapper = Condition.getQueryWrapper(rhzfGzyj, RhzfGzyjEntity.class);
		//if (!AuthUtil.isAdministrator()) {
		//	queryWrapper.lambda().eq(RhzfGzyjEntity::getTenantId, bladeUser.getTenantId());
		//}
		//queryWrapper.lambda().eq(RhzfGzyjEntity::getIsDeleted, BladeConstant.DB_NOT_DELETED);
		List<RhzfGzyjExcel> list = rhzfGzyjService.exportRhzfGzyj(queryWrapper);
		ExcelUtil.export(response, "入户走访_意见征集数据" + DateUtil.time(), "入户走访_意见征集数据表", list, RhzfGzyjExcel.class);
	}

}
