package sgc.portal.cw.cw0301.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import sgc.portal.base.util.EasyHashMap;
import sgc.portal.base.websquare.GridRowStatus;
import sgc.portal.com.com.persistence.ComAuthUserMngMapper;
import sgc.portal.cw.cw0301.persistence.CW03010001UMapper;
import sgc.portal.cw.cw0301.dto.CW03010001USearch;
import sgc.portal.cw.cw0301.model.CW03010001U;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class CW03010001UService {
    
	private final CW03010001UMapper mapper;

    public CW03010001UService(CW03010001UMapper mapper) {
        this.mapper = mapper;
    }
    
	//고충등록 내용 조회
    public List<EasyHashMap<String, Object>> selectProblemRegistryList(CW03010001USearch search) {
        return mapper.selectProblemRegistryList(search);
    }
    
    //고충등록 수정
    @Transactional
    public void saveProblemRegistryList(CW03010001U cW03010001U) {
    	
    	cW03010001U.setUserSabun(cW03010001U.getUserId());
    	
    	int count = mapper.selectCount(cW03010001U);
    	
    	if(count == 0) {
    		cW03010001U.setStatusCd("10");
    		int seq = mapper.selectProbId();
    		cW03010001U.setProbId(Integer.toString(seq));
    		mapper.insertProblemRegistry(cW03010001U);
    		
    		cW03010001U.setCmpnCd(cW03010001U.getCmpnCd());
    		cW03010001U.setProbId(Integer.toString(seq));
    		mapper.insertProblemRegistry2(cW03010001U);
    	}else {
    		mapper.updateProblemRegistry(cW03010001U);	
    	}
    	
    }
    
    //고충등록 취소
    public void updateProblemRegistryCanCel(CW03010001U cW03010001U) {
    	
    	cW03010001U.setUserSabun(cW03010001U.getUserId());
    	mapper.updateProblemRegistryCanCel(cW03010001U);
    }
}