package sgc.portal.com.com.service;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import sgc.portal.base.exception.UnsupportedGirdStatusException;
import sgc.portal.base.util.EasyHashMap;
import sgc.portal.base.websquare.GridRowStatus;
import sgc.portal.com.com.model.Dept;
import sgc.portal.com.com.persistence.ComDeptMngMapper;
import sgc.portal.security.annotation.Secured;
import sgc.portal.security.annotation.SecurityPolicy;

/**********************************************************
 * 시스템명  	: 시스템관리(COM)
 * 프로그램ID : ComDeptMngService
 * 프로그램명   : 부서관리 Service
 * @author  : SBK
 * @version :  2022-07-01
 * @since JDK1.8
 * @see
 * 1. 최초 작성
**********************************************************/
@Transactional
@Service
public class ComDeptMngService {
    /**
     * 변수명은 소문자로 시작하는 CamelCase를 사용합니다.
     * ComDeptMngMapper --> comDeptMngMapper
     *  2020.08.31 yongsang
     */
    @Autowired
    private ComDeptMngMapper comDeptMngMapper;

	/**
	 * Select com dept mng list.
	 * 사용자기본정보조회
	 *
	 * @param dept the dept
	 * @return the list
	 */
    public  List<EasyHashMap<String, Object>>  selectComDeptMng(Dept dept) {
        return comDeptMngMapper.selectComDeptMng(dept);
    }

	@Secured(policy = SecurityPolicy.NONE)
    public void saveComDeptMng(List<Dept> depts) {

	    if (CollectionUtils.isNotEmpty(depts)) {
	    	
	        for (Dept dept : depts) {
	           
	            switch (dept.getRowStatus()) {
                    case GridRowStatus.CREATED:
                        comDeptMngMapper.insertComDeptMng(dept);
                        break;
                    case GridRowStatus.UPDATED:
                        comDeptMngMapper.updateComDeptMng(dept);
                        break;
                    case GridRowStatus.DELETED:
                        comDeptMngMapper.deleteComDeptMng(dept);
                        break;
                    default:
                        throw new UnsupportedGirdStatusException();
                }
            }
        }
    }
}
