package org.springblade.modules.log.rhzfFw.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.rhzfFw.entity.RhzfFwEntity;
import org.springblade.modules.log.rhzfFw.excel.RhzfFwExcel;
import org.springblade.modules.log.rhzfFw.service.IRhzfFwService;
import org.springblade.modules.log.rhzfFw.vo.RhzfFwVO;
import org.springblade.modules.log.rhzfFw.wrapper.RhzfFwWrapper;
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-03-15
 */
@RestController
@AllArgsConstructor
@RequestMapping("blade-rhzfFw/rhzfFw")
@Api(value = "入户走访_房屋_基本信息", tags = "入户走访_房屋_基本信息接口")
public class RhzfFwController extends BladeController {

	private final IRhzfFwService rhzfFwService;

	/**
	 * 入户走访_房屋_基本信息 详情
	 */
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情", notes = "传入rhzfFw")
	public R<RhzfFwVO> detail(RhzfFwEntity rhzfFw) {
		RhzfFwEntity detail = rhzfFwService.getOne(Condition.getQueryWrapper(rhzfFw));
		return R.data(RhzfFwWrapper.build().entityVO(detail));
	}
	/**
	 * 入户走访_房屋_基本信息 分页
	 */
	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页", notes = "传入rhzfFw")
	public R<IPage<RhzfFwVO>> list(@ApiIgnore @RequestParam Map<String, Object> rhzfFw, Query query) {
		IPage<RhzfFwEntity> pages = rhzfFwService.page(Condition.getPage(query), Condition.getQueryWrapper(rhzfFw, RhzfFwEntity.class));
		return R.data(RhzfFwWrapper.build().pageVO(pages));
	}

	/**
	 * 入户走访_房屋_基本信息 自定义分页
	 */
	@GetMapping("/page")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "分页", notes = "传入rhzfFw")
	public R<IPage<RhzfFwVO>> page(RhzfFwVO rhzfFw, Query query) {
		IPage<RhzfFwVO> pages = rhzfFwService.selectRhzfFwPage(Condition.getPage(query), rhzfFw);
		return R.data(pages);
	}

	/**
	 * 入户走访_房屋_基本信息 新增
	 */
	@PostMapping("/save")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "新增", notes = "传入rhzfFw")
	public R save(@Valid @RequestBody RhzfFwEntity rhzfFw) {
		return R.status(rhzfFwService.save(rhzfFw));
	}

	/**
	 * 入户走访_房屋_基本信息 修改
	 */
	@PostMapping("/update")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "修改", notes = "传入rhzfFw")
	public R update(@Valid @RequestBody RhzfFwEntity rhzfFw) {
		return R.status(rhzfFwService.updateById(rhzfFw));
	}

	/**
	 * 入户走访_房屋_基本信息 新增或修改
	 */
	@PostMapping("/submit")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "新增或修改", notes = "传入rhzfFw")
	public R submit(@Valid @RequestBody RhzfFwEntity rhzfFw) {
		return R.status(rhzfFwService.saveOrUpdate(rhzfFw));
	}

	/**
	 * 入户走访_房屋_基本信息 删除
	 */
	@PostMapping("/remove")
	@ApiOperationSupport(order = 7)
	@ApiOperation(value = "逻辑删除", notes = "传入ids")
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		return R.status(rhzfFwService.deleteLogic(Func.toLongList(ids)));
	}


	/**
	 * 导出数据
	 */
	@GetMapping("/export-rhzfFw")
	@ApiOperationSupport(order = 9)
	@ApiOperation(value = "导出数据", notes = "传入rhzfFw")
	public void exportRhzfFw(@ApiIgnore @RequestParam Map<String, Object> rhzfFw, BladeUser bladeUser, HttpServletResponse response) {
		QueryWrapper<RhzfFwEntity> queryWrapper = Condition.getQueryWrapper(rhzfFw, RhzfFwEntity.class);
		//if (!AuthUtil.isAdministrator()) {
		//	queryWrapper.lambda().eq(RhzfFw::getTenantId, bladeUser.getTenantId());
		//}
		queryWrapper.lambda().eq(RhzfFwEntity::getIsDeleted, BladeConstant.DB_NOT_DELETED);
		List<RhzfFwExcel> list = rhzfFwService.exportRhzfFw(queryWrapper);
		ExcelUtil.export(response, "入户走访_房屋_基本信息数据" + DateUtil.time(), "入户走访_房屋_基本信息数据表", list, RhzfFwExcel.class);
	}

}
