package com.xinelu.manage.service.nursestationpersonrevenue.Impl;

import com.xinelu.manage.domain.nursestationpersonrevenue.NurseStationPersonRevenue;
import com.xinelu.manage.mapper.nursestationpersonrevenue.NurseStationPersonRevenueMapper;
import com.xinelu.manage.service.nursestationpersonrevenue.INurseStationPersonRevenueService;
import com.xinelu.manage.vo.nursestationpersonrevenue.PersonRevenueCountVO;
import com.xinelu.manage.vo.nursestationpersonrevenue.RevenueTimeDTO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.temporal.TemporalAdjusters;
import java.util.List;
import java.util.Objects;


/**
 * 护理员订单佣金收益信息Service业务层处理
 *
 * @author xinyilu
 * @date 2023-03-29
 */
@Service
public class NurseStationPersonRevenueServiceImpl implements INurseStationPersonRevenueService {
    @Resource
    private NurseStationPersonRevenueMapper nurseStationPersonRevenueMapper;

    /**
     * 查询护理员订单佣金收益信息
     *
     * @param id 护理员订单佣金收益信息主键
     * @return 护理员订单佣金收益信息
     */
    @Override
    public NurseStationPersonRevenue selectNurseStationPersonRevenueById(Long id) {
        return nurseStationPersonRevenueMapper.selectNurseStationPersonRevenueById(id);
    }

    /**
     * 查询护理员订单佣金收益信息列表
     *
     * @param revenueTime 护理员订单佣金收益信息
     * @return 护理员订单佣金收益信息
     */
    @Override
    public List<PersonRevenueCountVO> selectNurseStationPersonRevenueList(RevenueTimeDTO revenueTime) {
        revenueTime.setStartTime(LocalDate.now().atTime(0, 0, 0));
        revenueTime.setNowTime(LocalDateTime.now());
        if (Objects.nonNull(revenueTime.getMonthTime())) {
            revenueTime.setMonthStartDateTime(revenueTime.getMonthTime().with(TemporalAdjusters.firstDayOfMonth()).atTime(0, 0, 0));
            revenueTime.setMonthEndDateTime(revenueTime.getMonthTime().with(TemporalAdjusters.lastDayOfMonth()).atTime(23, 59, 59));
            return nurseStationPersonRevenueMapper.selectCount(revenueTime);
        }
        if (Objects.nonNull(revenueTime.getMonthStartTime()) && Objects.nonNull(revenueTime.getMonthEndTime())) {
            revenueTime.setMonthStartDateTime(revenueTime.getMonthStartTime().atTime(0, 0, 0));
            revenueTime.setMonthEndDateTime(revenueTime.getMonthEndTime().atTime(23, 59, 59));
            return nurseStationPersonRevenueMapper.selectCount(revenueTime);
        }
        revenueTime.setMonthStartDateTime(LocalDate.now().with(TemporalAdjusters.firstDayOfMonth()).atTime(0, 0, 0));
        revenueTime.setMonthEndDateTime(LocalDate.now().with(TemporalAdjusters.lastDayOfMonth()).atTime(23, 59, 59));
        return nurseStationPersonRevenueMapper.selectCount(revenueTime);
    }

    /**
     * 新增护理员订单佣金收益信息
     *
     * @param nurseStationPersonRevenue 护理员订单佣金收益信息
     * @return 结果
     */
    @Override
    public int insertNurseStationPersonRevenue(NurseStationPersonRevenue nurseStationPersonRevenue) {
        nurseStationPersonRevenue.setCreateTime(LocalDateTime.now());
        return nurseStationPersonRevenueMapper.insertNurseStationPersonRevenue(nurseStationPersonRevenue);
    }

    /**
     * 修改护理员订单佣金收益信息
     *
     * @param nurseStationPersonRevenue 护理员订单佣金收益信息
     * @return 结果
     */
    @Override
    public int updateNurseStationPersonRevenue(NurseStationPersonRevenue nurseStationPersonRevenue) {
        nurseStationPersonRevenue.setUpdateTime(LocalDateTime.now());
        return nurseStationPersonRevenueMapper.updateNurseStationPersonRevenue(nurseStationPersonRevenue);
    }

    /**
     * 批量删除护理员订单佣金收益信息
     *
     * @param ids 需要删除的护理员订单佣金收益信息主键
     * @return 结果
     */
    @Override
    public int deleteNurseStationPersonRevenueByIds(Long[] ids) {
        return nurseStationPersonRevenueMapper.deleteNurseStationPersonRevenueByIds(ids);
    }

    /**
     * 删除护理员订单佣金收益信息信息
     *
     * @param id 护理员订单佣金收益信息主键
     * @return 结果
     */
    @Override
    public int deleteNurseStationPersonRevenueById(Long id) {
        return nurseStationPersonRevenueMapper.deleteNurseStationPersonRevenueById(id);
    }
}
