/**
 * Copyright 2019 DH
 * All right reserved.
 * 项目名称: 大恒泰山系统
 * 创建日期:2022/8/22
 */
package org.springblade.modules.baseinfo.org.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.*;
import lombok.AllArgsConstructor;
import org.springblade.constant.BusinessConstant;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.launch.constant.AppConstant;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.secure.BladeUser;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.etl.entity.EtlAdCdEntity;
import org.springblade.etl.service.IEtlAdCdService;
import org.springblade.modules.baseinfo.org.entity.OrgInfoEntity;
import org.springblade.modules.baseinfo.org.service.IBaseInfoOrgService;
import org.springblade.modules.baseinfo.org.vo.OrgInfoVO;
import org.springblade.modules.baseinfo.org.wrapper.OrgInfoWrapper;
import org.springblade.modules.baseinfo.region.dto.RegionInfoDTO;
import org.springblade.modules.baseinfo.region.entity.RegionInfoEntity;
import org.springblade.modules.baseinfo.region.entity.RegionTreeNodeEntity;
import org.springblade.modules.baseinfo.region.service.IBaseInfoRegionService;
import org.springblade.modules.baseinfo.region.vo.RegionInfoVO;
import org.springblade.modules.baseinfo.region.wrapper.RegionInfoNodeWrapper;
import org.springblade.modules.baseinfo.region.wrapper.RegionInfoWrapper;
import org.springblade.modules.system.entity.Dept;
import org.springblade.modules.system.service.IDeptService;
import org.springblade.modules.system.service.IRegionService;
import org.springblade.modules.system.vo.DeptVO;
import org.springblade.modules.system.wrapper.DeptWrapper;
import org.springframework.web.bind.annotation.*;

import java.util.LinkedList;
import java.util.List;


/***
 * Date:2022/8/22
 * Title:行政区划管理
 * Description：对本文件的详细描述，原则上不能少于30字
 * @author dylan
 * @version 1.0
 * Remark：认为有必要的其他信息
 */
@RestController
@RequestMapping("galaxy-business/baseinfo/org")
@AllArgsConstructor
@Api(value = "运维单位管理", tags = "运维单位管理")
public class BaseInfoOrgController extends BladeController {
	private final IBaseInfoOrgService orgService;
	private final IDeptService deptService;


	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "不分页")
	public R<List<OrgInfoVO>> list() {
		BladeUser user = AuthUtil.getUser();
		if (BusinessConstant.ROLE_ORG_ADMIN.equals(user.getRoleName()) || BusinessConstant.ROLE_ORG_SERVICE_PERSON.equals(user.getRoleName())) {

			Dept dept = deptService.getById(Func.toLong(user.getDeptId()));
			List<Dept> list = new LinkedList<>();
			list.add(dept);
			return R.data(OrgInfoWrapper.build().listVO(list));
		} else {

			LambdaQueryWrapper<Dept> queryWrapper = Wrappers.<Dept>query().lambda();
			queryWrapper.eq(Dept::getIsDeleted, 0);
			queryWrapper.eq(Dept::getParentId, BusinessConstant.ORG_ADMIN_ID);
			List<Dept> list = deptService.list(queryWrapper);
			return R.data(OrgInfoWrapper.build().listVO(list));
		}


	}




}
