package org.springblade.system.controller;

import com.github.pagehelper.PageHelper;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springblade.common.annotation.RequiresPermissions;
import org.springblade.common.annotation.SysLog;
import org.springblade.common.core.controller.BaseController;
import org.springblade.common.core.domain.AjaxResult;
import org.springblade.common.core.page.TableDataInfo;
import org.springblade.common.enums.OperaType;
import org.springblade.common.utils.sql.SqlUtil;
import org.springblade.core.tenant.annotation.NonDS;
import org.springblade.system.domain.ProjectDto;
import org.springblade.system.domain.RectificationDto;
import org.springblade.system.service.RectFeedbackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author：liang.chao
 * @Date：2025/12/3 - 14:15
 * 整改反馈
 */
@RestController
@RequestMapping("/rectFeedback")
@Slf4j
@NonDS
public class RectFeedbackController extends BaseController {

	@Resource
	private RectFeedbackService service;
	@PostMapping("list")
	@SysLog(title = "整改反馈列表", module = "数据档案移交->整改反馈", businessType = OperaType.QUERY, details = "整改反馈列表", logType = 1)
	@RequiresPermissions("rectify:feedback:list")
	public TableDataInfo list(@RequestBody RectificationDto dto) {
		try {
			// 直接使用 dto 中的分页参数
			PageHelper.startPage(dto.getPageNum() != null ? dto.getPageNum() : 1,
					dto.getPageSize() != null ? dto.getPageSize() : 10,
					SqlUtil.escapeOrderBySql(dto.getOrderBy()))
				.setReasonable(dto.getReasonable() != null ? dto.getReasonable() : true);
			List<RectificationDto> list = service.list(dto);
			return getDataTable(list);
		} catch (Exception e) {
			log.error(e.toString(), e);
			return getDataTable(new ArrayList<>());
		}
	}
	@PostMapping("detail")
	@SysLog(title = "整改反馈列表", module = "数据档案移交->整改反馈", businessType = OperaType.QUERY, details = "整改反馈列表", logType = 1)
	@RequiresPermissions("rectify:feedback:query")
	public AjaxResult detail(@RequestBody RectificationDto dto) {
		try {
			RectificationDto detail = service.detail(dto);
			return AjaxResult.success(detail);
		} catch (Exception e) {
			log.error(e.toString(), e);
			return new AjaxResult(500, "请求出错了");
		}
	}
	@PostMapping("rectify")
	@SysLog(title = "整改提交", module = "数据档案移交->整改反馈", businessType = OperaType.INSERT, details = "整改提交", logType = 1)
	@RequiresPermissions("rectify:feedback:rectify")
	public AjaxResult rectify(@RequestBody @Validated RectificationDto dto) {
		return service.rectify(dto);
	}
	@PostMapping("rectifyPass")
	@SysLog(title = "整改通过", module = "数据档案移交->整改反馈", businessType = OperaType.INSERT, details = "整改通过", logType = 1)
	@RequiresPermissions("rectify:feedback:rectify")
	public AjaxResult rectifyPass(@RequestBody RectificationDto dto) {
		return service.rectifyPass(dto);
	}
	@PostMapping("rectifyRefuse")
	@SysLog(title = "整改驳回", module = "数据档案移交->整改反馈", businessType = OperaType.INSERT, details = "整改驳回", logType = 1)
	@RequiresPermissions("rectify:feedback:rectify")
	public AjaxResult rectifyRefuse(@RequestBody @Validated RectificationDto dto) {
		return service.rectifyRefuse(dto);
	}
}
