package sgc.portal.ll.ll0102.service;

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.ll.ll0102.model.LL01020001U;
import sgc.portal.ll.ll0102.dto.LL01020001USearch;
import sgc.portal.ll.ll0102.persistence.LL01020001UMapper;

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

@Service
public class LL01020001UService {
    private final LL01020001UMapper mapper;

    public LL01020001UService(LL01020001UMapper mapper) {
        this.mapper = mapper;
    }

    public List<EasyHashMap<String, Object>> getList(LL01020001USearch search) {
        return mapper.getList(search);
    }
    
    @Transactional
    public Map<String, String> save(List<LL01020001U> LL01020001U) {
    	
    	Map<String,String> result = new HashMap<>();
    	
    	for (LL01020001U lL01020001U : LL01020001U) {
            switch (lL01020001U.getRowStatus()) {
                case GridRowStatus.CREATED:
                    insert(lL01020001U);
                    break;
                case GridRowStatus.UPDATED:
                    update(lL01020001U);
                    break;
                case GridRowStatus.DELETED:
                    delete(lL01020001U);
                    break;
                default:
                    break;
            }
        }
    	return result;
    }

    private void insert(LL01020001U lL01020001U) {
        mapper.insert(lL01020001U);
    }

    private void update(LL01020001U lL01020001U) {
        mapper.update(lL01020001U);
    }

    private void delete(LL01020001U lL01020001U) {
        mapper.delete(lL01020001U);
    }
}
