/*
 *    Copyright (c) 2018-2025, lengleng All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the yifu4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: lengleng (wangiegie@gmail.com)
 */

package com.yifu.cloud.plus.v1.yifu.insurances.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import com.yifu.cloud.plus.v1.yifu.common.core.vo.BaseSearchListVO;
import com.yifu.cloud.plus.v1.yifu.common.core.vo.BaseSearchVO;
import com.yifu.cloud.plus.v1.yifu.common.log.annotation.SysLog;
import com.yifu.cloud.plus.v1.yifu.common.security.annotation.Inner;
import com.yifu.cloud.plus.v1.yifu.insurances.entity.TInsurancePreRenewDetail;
import com.yifu.cloud.plus.v1.yifu.insurances.service.insurance.TInsurancePreRenewDetailService;
import com.yifu.cloud.plus.v1.yifu.insurances.vo.BatchIgnoreVo;
import com.yifu.cloud.plus.v1.yifu.insurances.vo.InsuranceAutoParam;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 商险续签待办
 *
 * @author hgw
 * @date 2025-11-11 16:33:49
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/tinsuranceprerenewdetail")
@Tag(name = "商险续签待办管理")
public class TInsurancePreRenewDetailController {

	private final TInsurancePreRenewDetailService tInsurancePreRenewDetailService;


	/**
	 * 简单分页查询
	 *
	 * @param page                     分页对象
	 * @param tInsurancePreRenewDetail 商险续签待办
	 * @return
	 */
	@Operation(description = "简单分页查询")
	@GetMapping("/page")
	public R<IPage<TInsurancePreRenewDetail>> getTInsurancePreRenewDetailPage(Page<TInsurancePreRenewDetail> page, TInsurancePreRenewDetail tInsurancePreRenewDetail) {
		return new R<>(tInsurancePreRenewDetailService.getTInsurancePreRenewDetailPage(page, tInsurancePreRenewDetail));
	}

	/**
	 * 通过insurancesId查询商险续签待办
	 *
	 * @return R
	 */
	@Operation(summary = "通过insurancesId查询", description = "通过insurancesId查询")
	@GetMapping("/getByInsurancesId")
	public R<TInsurancePreRenewDetail> getByInsurancesId(@RequestParam String insurancesId) {
		TInsurancePreRenewDetail tInsurancePreRenewDetail = tInsurancePreRenewDetailService
				.getOne(Wrappers.<TInsurancePreRenewDetail>lambdaQuery()
						.eq(TInsurancePreRenewDetail::getInsurancesId, insurancesId)
						.last(CommonConstants.LAST_ONE_SQL));
		return R.ok(tInsurancePreRenewDetail);
	}

	/**
	 * 修改商险续签待办
	 *
	 * @param tInsurancePreRenewDetail 商险续签待办
	 * @return R
	 */
	@Operation(summary = "单个确认-商险续签待办", description = "单个确认-商险续签待办")
	@SysLog("单个确认-商险续签待办")
	@PostMapping("/doSure")
	public R<String> doSure(@RequestBody TInsurancePreRenewDetail tInsurancePreRenewDetail) {
		return tInsurancePreRenewDetailService.doSure(tInsurancePreRenewDetail);
	}

	/**
	 * @Description: 批量确认
	 * @Author: hgw
	 * @Date: 2025/11/17 10:53
	 * @return: com.yifu.cloud.plus.v1.yifu.common.core.util.R<java.lang.Boolean>
	 **/
	@Operation(summary = "批量确认-商险续签待办", description = "批量确认-商险续签待办")
	@SysLog("批量确认-商险续签待办（与单个确认分开，是因为单个确认还有编辑功能，批量仅改状态")
	@PostMapping("/doSureBatch")
	public R<String> doSureBatch(@RequestBody BatchIgnoreVo vo) {
		if (null == vo || vo.getIds() == null || vo.getIds().isEmpty()){
			return R.failed(CommonConstants.PARAM_IS_NOT_ERROR);
		}
		return tInsurancePreRenewDetailService.doSureBatch(vo);
	}

	/**
	 * 修改商险续签待办
	 *
	 * @param tInsurancePreRenewDetail 商险续签待办
	 * @return R
	 */
	@Operation(summary = "编辑商险续签待办", description = "编辑商险续签待办")
	@SysLog("编辑商险续签待办")
	@PutMapping
	public R<String> updateById(@RequestBody TInsurancePreRenewDetail tInsurancePreRenewDetail) {
		return tInsurancePreRenewDetailService.doEdit(tInsurancePreRenewDetail);
	}

	/**
	 * @Description: 商险待续保单个/批量派单
	 * @Author: hgw
	 * @Date: 2025/11/17 14:17
	 * @return: com.yifu.cloud.plus.v1.yifu.common.core.util.R
	 **/
	@Operation(description = "商险待续保单个/批量派单")
	@PostMapping("/batchDoInsurancePreRenew")
	public R<List<InsuranceAutoParam>> batchDoInsurancePreRenew(@RequestBody List<String> idList, @RequestParam(required = false) String isExit) {
		return tInsurancePreRenewDetailService.batchDoInsurancePreRenew(idList, isExit, false);
	}

	/**
	 * @Description: 每天下午三点、三点二十推送续保待派单数
	 * @Author: hgw
	 * @Date: 2025/11/17 16:18
	 * @return: void
	 **/
	@SysLog("每天下午三点、三点二十推送续保待派单数据")
	@Inner
	@PostMapping("/inner/autoDoInsurancePreRenew")
	public void autoDoInsurancePreRenew() {
		tInsurancePreRenewDetailService.autoDoInsurancePreRenew();
	}

	/**
	 * @Description: 每日9点统一推送确认信息
	 * @Author: hgw
	 * @Date: 2025/11/17 16:18
	 * @return: void
	 **/
	@SysLog("每日9点统一推送确认信息（确认日到派单日之间的数据且今天是工作日）")
	@Inner
	@PostMapping("/inner/autoDoWxSureMessage")
	public void autoDoWxSureMessage() {
		tInsurancePreRenewDetailService.autoDoWxSureMessage();
	}

	@Operation(summary = "测试今天是否为工作日", description = "测试今天是否为工作日")
	@PostMapping("/isWorkDayTest")
	public boolean isWorkDayTest() {
		return tInsurancePreRenewDetailService.isWorkDayTest();
	}

	/**
	 * @param paramVo
	 * @Description: 离职待办确认后，更新为商险续签待办为已离职
	 * @Author: hgw
	 * @Date: 2025-11-21 14:21:25
	 * @return: com.yifu.cloud.plus.v1.yifu.common.core.vo.BaseSearchVO
	 **/
	@Operation(summary = "离职待办确认后，更新为商险续签待办为已离职", description = "离职待办确认后，更新为商险续签待办为已离职")
	@Inner
	@PostMapping("/inner/updateInsurancePreRenewToIsLeave")
	public String updateInsurancePreRenewToIsLeave(@RequestBody BaseSearchVO paramVo) {
		tInsurancePreRenewDetailService.updateInsurancePreRenewToIsLeave(paramVo);
		return CommonConstants.UPDATE_SUCCESS;
	}

	/**
	 * @param paramVoList
	 * @Description: 离职待办确认后，更新为商险续签待办为已离职_多条数据
	 * @Author: hgw
	 * @Date: 2025-11-21 14:21:25
	 * @return: com.yifu.cloud.plus.v1.yifu.common.core.vo.BaseSearchVO
	 **/
	@Operation(summary = "离职待办确认后，更新为商险续签待办为已离职", description = "离职待办确认后，更新为商险续签待办为已离职")
	@Inner
	@PostMapping("/inner/updateInsurancePreRenewToIsLeaveList")
	public String updateInsurancePreRenewToIsLeaveList(@RequestBody BaseSearchListVO paramVoList) {
		tInsurancePreRenewDetailService.updateInsurancePreRenewToIsLeaveList(paramVoList);
		return CommonConstants.UPDATE_SUCCESS;
	}

}
