package org.springblade.modules.rhzf.wtfy.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.wtfy.excel.RhzfWtfyExcel;
import org.springblade.modules.rhzf.wtfy.pojo.entity.RhzfWtfyEntity;
import org.springblade.modules.rhzf.wtfy.pojo.vo.RhzfWtfyVO;
import org.springblade.modules.rhzf.wtfy.service.IRhzfWtfyService;
import org.springblade.modules.rhzf.wtfy.wrapper.RhzfWtfyWrapper;
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("/rhzfWtfy")
@Api(value = "入户走访_问题反映", tags = "入户走访_问题反映接口")
public class RhzfWtfyController extends BladeController {

	private final IRhzfWtfyService rhzfWtfyService;

	/**
	 * 入户走访_问题反映 详情
	 */
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情", notes  = "传入rhzfWtfy")
	public R<RhzfWtfyVO> detail(RhzfWtfyEntity rhzfWtfy) {
		RhzfWtfyEntity detail = rhzfWtfyService.getOne(Condition.getQueryWrapper(rhzfWtfy));
		return R.data(RhzfWtfyWrapper.build().entityVO(detail));
	}

	/**
	 * 入户走访_问题反映 分页
	 */
	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页", notes  = "传入rhzfWtfy")
	public R<IPage<RhzfWtfyVO>> list(@RequestParam Map<String, Object> rhzfWtfy, Query query) {
		IPage<RhzfWtfyEntity> pages = rhzfWtfyService.page(Condition.getPage(query), Condition.getQueryWrapper(rhzfWtfy, RhzfWtfyEntity.class));
		return R.data(RhzfWtfyWrapper.build().pageVO(pages));
	}

	/**
	 * 入户走访_问题反映 自定义分页
	 */
	@GetMapping("/page")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "分页", notes  = "传入rhzfWtfy")
	public R<IPage<RhzfWtfyVO>> page(RhzfWtfyVO rhzfWtfy, Query query) {
		IPage<RhzfWtfyVO> pages = rhzfWtfyService.selectRhzfWtfyPage(Condition.getPage(query), rhzfWtfy);
		return R.data(pages);
	}

	/**
	 * 入户走访_问题反映 新增
	 */
	@PostMapping("/save")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "新增", notes  = "传入rhzfWtfy")
	public R save(@RequestBody RhzfWtfyEntity rhzfWtfy) {
		return R.status(rhzfWtfyService.save(rhzfWtfy));
	}

	/**
	 * 入户走访_问题反映 修改
	 */
	@PostMapping("/update")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "修改", notes  = "传入rhzfWtfy")
	public R update(@RequestBody RhzfWtfyEntity rhzfWtfy) {
		return R.status(rhzfWtfyService.updateById(rhzfWtfy));
	}

	/**
	 * 入户走访_问题反映 新增或修改
	 */
	@PostMapping("/submit")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "新增或修改", notes  = "传入rhzfWtfy")
	public R submit(@RequestBody RhzfWtfyEntity rhzfWtfy) {
		return R.status(rhzfWtfyService.saveOrUpdate(rhzfWtfy));
	}

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

	/**
	 * 导出数据
	 */
	@PreAuth(RoleConstant.HAS_ROLE_ADMIN)
	@GetMapping("/export-rhzfWtfy")
	@ApiOperationSupport(order = 8)
	@ApiOperation(value = "导出数据", notes  = "传入rhzfWtfy")
	public void exportRhzfWtfy(@RequestParam Map<String, Object> rhzfWtfy, BladeUser bladeUser, HttpServletResponse response) {
		QueryWrapper<RhzfWtfyEntity> queryWrapper = Condition.getQueryWrapper(rhzfWtfy, RhzfWtfyEntity.class);
		//if (!AuthUtil.isAdministrator()) {
		//	queryWrapper.lambda().eq(RhzfWtfyEntity::getTenantId, bladeUser.getTenantId());
		//}
		//queryWrapper.lambda().eq(RhzfWtfyEntity::getIsDeleted, BladeConstant.DB_NOT_DELETED);
		List<RhzfWtfyExcel> list = rhzfWtfyService.exportRhzfWtfy(queryWrapper);
		ExcelUtil.export(response, "入户走访_问题反映数据" + DateUtil.time(), "入户走访_问题反映数据表", list, RhzfWtfyExcel.class);
	}

}
