package cn.com.victorysoft.business.condition.service;

import cn.com.victorysoft.business.condition.dao.ConditionUnitDao;
import cn.com.victorysoft.business.condition.entity.ConditionUnit;
import cn.com.victorysoft.business.sys.param.UnitDatePageParam;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public class ConditionUnitService {

    @Resource
    private ConditionUnitDao unitDailyDao;

    /**
     * 查询本单位及子单位
     */
    public List<ConditionUnit> selectUnitChildren(UnitDatePageParam param) {
        List<ConditionUnit> result = new ArrayList<>();
        ConditionUnit unit = unitDailyDao.selectUnit(param);
        if (unit == null) {
            unit = new ConditionUnit();
        }
        List<ConditionUnit> children = unitDailyDao.selectChildren(param);
        result.add(unit);
        result.addAll(children);
        return result;
    }

    public int deleteByDate(Date date) {
        return unitDailyDao.deleteByDate(date);
    }

}
