/*
 *    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.social.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yifu.cloud.plus.v1.yifu.common.core.util.Common;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
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.social.entity.TForecastLibrary;
import com.yifu.cloud.plus.v1.yifu.social.service.TForecastLibraryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;


/**
 * 预估费用
 *
 * @author hgw
 * @date 2022-07-18 16:21:40
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/tforecastlibrary")
@Tag(name = "预估费用管理")
public class TForecastLibraryController {

	private final TForecastLibraryService tForecastLibraryService;


	/**
	 * 简单分页查询
	 *
	 * @param page             分页对象
	 * @param tForecastLibrary 预估费用
	 * @return
	 */
	@Operation(description = "简单分页查询")
	@GetMapping("/page")
	public R<IPage<TForecastLibrary>> getTForecastLibraryPage(Page<TForecastLibrary> page, TForecastLibrary tForecastLibrary) {
		return new R<>(tForecastLibraryService.getTForecastLibraryPage(page, tForecastLibrary));
	}

	/**
	 * 通过id查询预估费用
	 *
	 * @param id id
	 * @return R
	 */
	@Operation(summary = "通过id查询", description = "通过id查询")
	@GetMapping("/{id}")
	public R<TForecastLibrary> getById(@PathVariable("id") String id) {
		return R.ok(tForecastLibraryService.getById(id));
	}

	/**
	 * 新增预估费用
	 *
	 * @param tForecastLibrary 预估费用
	 * @return R
	 */
	@Operation(summary = "新增预估费用", description = "新增预估费用：hasPermission('social_tforecastlibrary_add')")
	@SysLog("新增预估费用")
	@PostMapping
	@PreAuthorize("@pms.hasPermission('social_tforecastlibrary_add')")
	public R<Boolean> save(@RequestBody TForecastLibrary tForecastLibrary) {
		return R.ok(tForecastLibraryService.save(tForecastLibrary));
	}

	/**
	 * 修改预估费用
	 *
	 * @param tForecastLibrary 预估费用
	 * @return R
	 */
	@Operation(summary = "修改预估费用", description = "修改预估费用：hasPermission('social_tforecastlibrary_edit')")
	@SysLog("修改预估费用")
	@PutMapping
	@PreAuthorize("@pms.hasPermission('social_tforecastlibrary_edit')")
	public R<Boolean> updateById(@RequestBody TForecastLibrary tForecastLibrary) {
		return R.ok(tForecastLibraryService.updateById(tForecastLibrary));
	}

	/**
	 * 通过id删除预估费用
	 *
	 * @param id id
	 * @return R
	 */
	@Operation(summary = "通过id删除预估费用", description = "通过id删除预估费用：hasPermission('social_tforecastlibrary_del')")
	@SysLog("通过id删除预估费用")
	@DeleteMapping("/{id}")
	@PreAuthorize("@pms.hasPermission('social_tforecastlibrary_del')")
	public R<Boolean> removeById(@PathVariable String id) {
		return R.ok(tForecastLibraryService.removeById(id));
	}

	/**
	 * 预估费用 批量导出
	 *
	 * @author hgw
	 * @date 2022-07-18 16:21:40
	 **/
	@Operation(description = "导出预估费用 hasPermission('social_tforecastlibrary-export')")
	@PostMapping("/export")
	@PreAuthorize("@pms.hasPermission('social_tforecastlibrary-export')")
	public void export(HttpServletResponse response, @RequestBody TForecastLibrary searchVo) {
		tForecastLibraryService.listExport(response, searchVo);
	}

	/**
	 * @param payMonths 缴纳月
	 * @param empIdCard 身份证
	 * @param settleDomainIds 项目ids
	 * @Description: 按缴纳月重新生成
	 * @Author: hgw
	 * @Date: 2022/7/18 17:12
	 * @return: com.yifu.cloud.plus.v1.yifu.common.core.util.R<java.lang.Boolean>
	 **/
	@Operation(summary = "按缴纳月重新生成", description = "按缴纳月重新生成：hasPermission('social_tforecastlibrary_create')")
	@SysLog("按缴纳月重新生成")
	@PostMapping("/createForecastlibary")
	@PreAuthorize("@pms.hasPermission('social_tforecastlibrary_create')")
	public R<String> createForecastlibary(@RequestParam String payMonths
			, @RequestParam(value = "empIdCard", required = false) String empIdCard
			, @RequestParam(value = "settleDomainIds", required = false) String settleDomainIds) {
		if (Common.isEmpty(empIdCard) && Common.isEmpty(settleDomainIds)) {
			return R.failed("参数有误：身份证或项目ID不可为空！");
		}
		return tForecastLibraryService.createForecastlibary(payMonths, empIdCard, settleDomainIds);
	}

	/**
	 * @Description: 每日定时刷新社保公积金信息、预估数据，根据新增的户数据
	 * @Author: hgw
	 * @Date: 2022/7/27 19:34
	 * @return: void
	 **/
	@Operation(summary = "每日定时刷新社保公积金信息、预估数据，根据新增的户数据", description = "每日定时刷新社保公积金信息、预估数据，根据新增的户数据")
	@SysLog("每日定时刷新社保公积金信息、预估数据，根据新增的户数据")
	@Inner
	@PostMapping("/inner/updateForecastLibaryBySysBase")
	public void updateForecastLibaryBySysBase() {
		tForecastLibraryService.updateForecastLibaryBySysBase(null);
	}

	/**
	 * @Description: 每月定时生成下月预估库数据
	 * @Author: hgw
	 * @Date: 2022/7/27 19:34
	 * @return: void
	 **/
	@Operation(summary = "每月定时生成下月预估库数据", description = "每月定时生成下月预估库数据")
	@SysLog("每月定时生成下月预估库数据")
	@Inner
	@PostMapping("/inner/everyMonthCreateForecastLibary")
	public void everyMonthCreateForecastLibary() {
		tForecastLibraryService.everyMonthCreateForecastLibary();
	}


}
