package com.pnkx.service.impl;

import com.github.pagehelper.PageInfo;
import com.pnkx.common.constant.HttpStatus;
import com.pnkx.common.core.page.TableDataInfo;
import com.pnkx.common.utils.DateUtils;
import com.pnkx.common.utils.SecurityUtils;
import com.pnkx.common.utils.ServletUtils;
import com.pnkx.domain.po.PxBookkeepingRecord;
import com.pnkx.framework.web.service.TokenService;
import com.pnkx.mapper.PxBookkeepingRecordMapper;
import com.pnkx.service.IPxBookkeepingRecordService;
import org.springframework.stereotype.Service;

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

/**
 * @author PHY
 * @classname PxBookkeepingRecordServiceImpl
 * @data 2021/11/18 0018 14:36
 * @description 描述
 */
@Service
public class PxBookkeepingRecordServiceImpl implements IPxBookkeepingRecordService {
    @Resource
    private PxBookkeepingRecordMapper pxBookkeepingRecordMapper;

    /**
     * 查询账本记录
     *
     * @param id 账本记录ID
     * @return 账本记录
     */
    @Override
    public PxBookkeepingRecord selectPxBookkeepingRecordById(Long id) {
        return pxBookkeepingRecordMapper.selectPxBookkeepingRecordById(id);
    }

    /**
     * 新增账本记录
     *
     * @param pxBookkeepingRecord 账本记录
     * @return 结果
     */
    @Override
    public int insertPxBookkeepingRecord(PxBookkeepingRecord pxBookkeepingRecord) {
        pxBookkeepingRecord.setCreateTime(DateUtils.getNowDate());
        pxBookkeepingRecord.setCreateBy(SecurityUtils.getUserId().toString());
        return pxBookkeepingRecordMapper.insertPxBookkeepingRecord(pxBookkeepingRecord);
    }

    /**
     * 查询账本记录列表
     *
     * @param pxBookkeepingRecord 账本记录
     * @return 账本记录
     */
    @Override
    public TableDataInfo selectPxBookkeepingRecordList(PxBookkeepingRecord pxBookkeepingRecord) {
        List<PxBookkeepingRecord> list = pxBookkeepingRecordMapper.selectPxBookkeepingRecordList(pxBookkeepingRecord);
        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(HttpStatus.SUCCESS);
        rspData.setMsg(pxBookkeepingRecordMapper.getInflowMoney(pxBookkeepingRecord) + "," + pxBookkeepingRecordMapper.getFlowOutMoney(pxBookkeepingRecord));
        rspData.setRows(list);
        rspData.setTotal(new PageInfo(list).getTotal());
        return rspData;
    }

    /**
     * 修改账本记录
     *
     * @param pxBookkeepingRecord 账本记录
     * @return 结果
     */
    @Override
    public int updatePxBookkeepingRecord(PxBookkeepingRecord pxBookkeepingRecord) {
        pxBookkeepingRecord.setUpdateTime(DateUtils.getNowDate());
        pxBookkeepingRecord.setUpdateBy(SecurityUtils.getUserId().toString());
        return pxBookkeepingRecordMapper.updatePxBookkeepingRecord(pxBookkeepingRecord);
    }

    /**
     * 批量删除账本记录
     *
     * @param ids 需要删除的账本记录ID
     * @return 结果
     */
    @Override
    public int deletePxBookkeepingRecordByIds(Long[] ids) {
        return pxBookkeepingRecordMapper.deletePxBookkeepingRecordByIds(ids);
    }

    /**
     * 删除账本记录信息
     *
     * @param id 账本记录ID
     * @return 结果
     */
    @Override
    public int deletePxBookkeepingRecordById(Long id) {
        return pxBookkeepingRecordMapper.deletePxBookkeepingRecordById(id);
    }
}
