/*
 *      Copyright (c) 2018-2028, Chill Zhuang 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 dreamlu.net 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: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.bank.home.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.apache.poi.ss.formula.functions.T;
import org.springblade.bank.cardswallow.entity.CardSwallow;
import org.springblade.bank.cardswallow.service.ICardSwallowService;
import org.springblade.bank.checklist.entity.Checklist;
import org.springblade.bank.checklist.service.IChecklistService;
import org.springblade.bank.goodsuse.entity.GoodsUse;
import org.springblade.bank.goodsuse.service.IGoodsUseService;
import org.springblade.bank.keypwd.entity.KeyPwd;
import org.springblade.bank.keypwd.service.IKeyPwdService;
import org.springblade.bank.message.entity.Message;
import org.springblade.bank.message.service.IMessageService;
import org.springblade.bank.postchange.entity.PostChange;
import org.springblade.bank.postchange.service.IPostChangeService;
import org.springblade.bank.returns.entity.Returns;
import org.springblade.bank.returns.service.IReturnsService;
import org.springblade.bank.sealhandover.entity.SealHandover;
import org.springblade.bank.sealhandover.service.ISealHandoverService;
import org.springblade.bank.tellertrunk.entity.TellerTrunk;
import org.springblade.bank.tellertrunk.service.ITellerTrunkService;
import org.springblade.bank.warehouse.entity.CheckWarehouse;
import org.springblade.bank.warehouse.service.ICheckWarehouseService;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.mp.base.BaseEntity;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.secure.BladeUser;
import org.springblade.core.tenant.annotation.NonDS;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.constant.BladeConstant;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.StringPool;
import org.springblade.modules.system.entity.Dept;
import org.springblade.modules.system.entity.User;
import org.springblade.modules.system.vo.DeptVO;
import org.springblade.modules.system.vo.UserVO;
import org.springblade.modules.system.wrapper.UserWrapper;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 控制器
 *
 * @author Chill
 */
@NonDS
@RestController
@AllArgsConstructor
@RequestMapping("bank/home")
@Api(value = "首頁", tags = "")
public class HomeController extends BladeController {

	private final IKeyPwdService keyPwdService;
	private final ISealHandoverService sealHandoverService;
	private final IPostChangeService postChangeService;
	private final ICheckWarehouseService checkWarehouseService;
	private final IChecklistService checklistService;
	private final ITellerTrunkService tellerTrunkService;
	private final IGoodsUseService goodsUseService;
	private final ICardSwallowService cardSwallowService;
	private final IReturnsService returnsService;
	private final IMessageService messageService;

	/**
	 * 获取我的發起
	 */
	@GetMapping("/myInitiated")
	@ApiOperationSupport(order = 8)
	@ApiOperation(value = "获取我的發起", notes = "")
	public R myInitiated() {

//		List<KeyPwd> keyPwdList = keyPwdService.getMyInitialted();
//		List<SealHandover> sealList = sealHandoverService.getMyInitialted();
		List<PostChange> postChangeList = postChangeService.getMyInitialted();
//		List<CheckWarehouse> checkWarehouses = checkWarehouseService.getMyInitialted();
//		List<Checklist> checklistList = checklistService.getMyInitialted();
//		List<TellerTrunk> tellerTrunkList = tellerTrunkService.getMyInitialted();
		List<GoodsUse> goodsUseList = goodsUseService.getMyInitialted();
		List<CardSwallow> cardSwallowList = cardSwallowService.getMyInitialted();
		List<Returns> returnsList = returnsService.getMyInitialted();
		List<Message> messageList = messageService.getMyInitialted();

//		List<? extends BaseEntity> collect = Stream.of(postChangeList,goodsUseList,cardSwallowList,returnsList,messageList).flatMap(x -> x.stream()).collect(Collectors.toList());

		return R.data(postChangeList.size() + goodsUseList.size() + cardSwallowList.size() + returnsList.size() + messageList.size());
	}
	/**
	 * 获取待確認
	 */
	@GetMapping("/toBeConfirmed")
	@ApiOperationSupport(order = 8)
	@ApiOperation(value = "获取当前用户的部门信息", notes = "")
	public R toBeConfirmed() {

		List<PostChange> postChangeList = postChangeService.list(new QueryWrapper<>(new PostChange()).lambda().eq(PostChange::getProcess, 2));
		List<GoodsUse> goodsUseList = goodsUseService.list(new QueryWrapper<>(new GoodsUse()).lambda().eq(GoodsUse::getProcess, 2));
		List<Returns> returnsList = returnsService.list(new QueryWrapper<>(new Returns()).lambda().eq(Returns::getProcess, 3));
		return R.data(postChangeList.size() + goodsUseList.size() + returnsList.size());
	}

	/**
	 * 获取我的確認
	 */
	@GetMapping("/myConfirmation")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "树形结构", notes = "树形结构")
	public R myConfirmation() {
		List<PostChange> postChangeList = postChangeService.list(new QueryWrapper<>(new PostChange()).lambda().eq(PostChange::getProcess, 3));
		List<GoodsUse> goodsUseList = goodsUseService.list(new QueryWrapper<>(new GoodsUse()).lambda().eq(GoodsUse::getProcess, 3));
		List<Returns> returnsList = returnsService.list(new QueryWrapper<>(new Returns()).lambda().eq(Returns::getProcess, 4));
		return R.data(postChangeList.size() + goodsUseList.size() + returnsList.size());
	}

	/**
	 * 待發佈
	 */
	@GetMapping("/toBoReleased")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "列表", notes = "传入account和realName")
	public R toBoReleased(@ApiIgnore User user, Query query, Long deptId, BladeUser bladeUser) {
		List<CardSwallow> cardSwallowList = cardSwallowService.list(new QueryWrapper<>(new CardSwallow()).lambda().eq(CardSwallow::getProcess, 2));
		List<Returns> returnsList = returnsService.list(new QueryWrapper<>(new Returns()).lambda().eq(Returns::getProcess, 2));
		return R.data(cardSwallowList.size() + returnsList.size());
	}

}
