package com.pnkx.service.impl;

import com.pnkx.common.utils.DateUtils;
import com.pnkx.common.utils.SecurityUtils;
import com.pnkx.common.utils.ServletUtils;
import com.pnkx.framework.web.service.TokenService;
import com.pnkx.mapper.PxMenstruationRecordMapper;
import com.pnkx.service.IPxMenstruationRecordService;
import com.pnkx.domain.po.PxMenstruationRecord;
import org.springframework.stereotype.Service;

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

/**
 * 姨妈记录Service业务层处理
 *
 * @author pnkx
 * @date 2021-12-03
 */
@Service
public class PxMenstruationRecordServiceImpl implements IPxMenstruationRecordService {
    @Resource
    private PxMenstruationRecordMapper pxMenstruationRecordMapper;

    /**
     * 查询姨妈记录
     *
     * @param id 姨妈记录ID
     * @return 姨妈记录
     */
    @Override
    public PxMenstruationRecord selectPxMenstruationRecordById(Long id) {
        return pxMenstruationRecordMapper.selectPxMenstruationRecordById(id);
    }

    /**
     * 查询姨妈记录列表
     *
     * @param pxMenstruationRecord 姨妈记录
     * @return 姨妈记录
     */
    @Override
    public List<PxMenstruationRecord> selectPxMenstruationRecordList(PxMenstruationRecord pxMenstruationRecord) {
        pxMenstruationRecord.setUserId(SecurityUtils.getUserId());
        return pxMenstruationRecordMapper.selectPxMenstruationRecordList(pxMenstruationRecord);
    }

    /**
     * 查询姨妈记录列表
     *
     * @param pxMenstruationRecord 姨妈记录
     * @return 姨妈记录
     */
    @Override
    public List<PxMenstruationRecord> getPxMenstruationRecordList(PxMenstruationRecord pxMenstruationRecord) {
        pxMenstruationRecord.setUserId(SecurityUtils.getUserId());
        return pxMenstruationRecordMapper.getPxMenstruationRecordList(pxMenstruationRecord);
    }

    /**
     * 新增姨妈记录
     *
     * @param pxMenstruationRecord 姨妈记录
     * @return 结果
     */
    @Override
    public int insertPxMenstruationRecord(PxMenstruationRecord pxMenstruationRecord) {
        pxMenstruationRecord.setCreateTime(DateUtils.getNowDate());
        pxMenstruationRecord.setCreateBy(SecurityUtils.getUserId().toString());
        return pxMenstruationRecordMapper.insertPxMenstruationRecord(pxMenstruationRecord);
    }

    /**
     * 修改姨妈记录
     *
     * @param pxMenstruationRecord 姨妈记录
     * @return 结果
     */
    @Override
    public int updatePxMenstruationRecord(PxMenstruationRecord pxMenstruationRecord) {
        pxMenstruationRecord.setUpdateTime(DateUtils.getNowDate());
        pxMenstruationRecord.setUpdateBy(SecurityUtils.getUserId().toString());
        return pxMenstruationRecordMapper.updatePxMenstruationRecord(pxMenstruationRecord);
    }

    /**
     * 批量删除姨妈记录
     *
     * @param ids 需要删除的姨妈记录ID
     * @return 结果
     */
    @Override
    public int deletePxMenstruationRecordByIds(Long[] ids) {
        return pxMenstruationRecordMapper.deletePxMenstruationRecordByIds(ids);
    }

    /**
     * 删除姨妈记录信息
     *
     * @param id 姨妈记录ID
     * @return 结果
     */
    @Override
    public int deletePxMenstruationRecordById(Long id) {
        return pxMenstruationRecordMapper.deletePxMenstruationRecordById(id);
    }

    /**
     * APP首页获取姨妈提醒列表
     * @param pxMenstruationRecord
     * @return
     */
    @Override
    public List<PxMenstruationRecord> selectMenstruationRecordList(PxMenstruationRecord pxMenstruationRecord) {
        return pxMenstruationRecordMapper.selectMenstruationRecordList(pxMenstruationRecord);
    }

    /**
     * 获取最后一次姨妈开始的记录
     * @return
     */
    @Override
    public PxMenstruationRecord getLastStartDate() {
        return pxMenstruationRecordMapper.getLastStartDate();
    }
}
