model.service.ServiceEmployee.java Source code

Java tutorial

Introduction

Here is the source code for model.service.ServiceEmployee.java

Source

package model.service;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

import model.dao.DaoEmployee;
import model.dataBase.Temployee;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class ServiceEmployee {

    @Autowired
    private DaoEmployee daoEmployee;

    @Transactional
    public Boolean save(Temployee employee) {
        if (employee.getIdEmployee() == 0)
            return daoEmployee.save(employee);
        else
            return daoEmployee.update(employee);
    }

    @Transactional(readOnly = true)
    public Temployee findById(int id) {
        return daoEmployee.findById(id);
    }

    @Transactional(readOnly = true)
    public Temployee findByDocNum(String docNum) {
        List<Temployee> list = daoEmployee.listByField("docNum", docNum);
        if (list.isEmpty())
            return null;
        else
            return list.get(0);
    }

    @Transactional(readOnly = true)
    public List<Temployee> listActive() {
        return daoEmployee.listActive();
    }

    @Transactional(readOnly = true)
    public List<Temployee> listByDocNum(String docNum) {
        return daoEmployee.listByField("docNum", docNum);
    }

    @Transactional(readOnly = true)
    public List<Temployee> listByName(String name) {
        return daoEmployee.listByField("name", name);
    }

    @Transactional(readOnly = true)
    public List<Temployee> listByLastName(String lastName) {
        return daoEmployee.listByField("lastName", lastName);
    }

    @Transactional(readOnly = true)
    public List<String> listDocNum() {
        return daoEmployee.listStringByField("docNum");
    }

    @Transactional(readOnly = true)
    public List<String> listName() {
        return daoEmployee.listStringByField("name");
    }

    @Transactional(readOnly = true)
    public List<String> listLastName() {
        return daoEmployee.listStringByField("lastName");
    }

    @Transactional(readOnly = true)
    public List<Temployee> listExpirationLicenses() {
        Calendar date = Calendar.getInstance();
        /* Sumamos 30 dias al dia actual */
        date.add(Calendar.DAY_OF_MONTH, 30);
        Date dateFuture = date.getTime();
        List<Temployee> list = daoEmployee.listUpcomingDatesActive("dateLicense", dateFuture);
        return list;
    }

    @Transactional(readOnly = true)
    public List<Temployee> listExpirationCertificate() {
        Calendar date = Calendar.getInstance();
        /* Sumamos 30 dias al dia actual */
        date.add(Calendar.DAY_OF_MONTH, 30);
        Date dateFuture = date.getTime();
        List<Temployee> list = daoEmployee.listUpcomingDatesActive("dateCertificate", dateFuture);
        return list;
    }
}