package com.fs.store.service.impl;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import cn.hutool.json.JSONUtil;
import com.fs.common.utils.DateUtils;
import com.fs.store.param.FsUserBillParam;
import com.fs.store.param.FsUserBillQueryParam;
import com.fs.store.vo.FsUserBillVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.fs.store.mapper.FsUserBillMapper;
import com.fs.store.domain.FsUserBill;
import com.fs.store.service.IFsUserBillService;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * 用户账单Service业务层处理
 *
 * @author fs
 * @date 2022-04-03
 */
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class FsUserBillServiceImpl implements IFsUserBillService
{
    @Autowired
    private FsUserBillMapper fsUserBillMapper;

    Logger logger= LoggerFactory.getLogger(getClass());

    /**
     * 查询用户账单
     *
     * @param id 用户账单ID
     * @return 用户账单
     */
    @Override
    public FsUserBill selectFsUserBillById(Long id)
    {
        return fsUserBillMapper.selectFsUserBillById(id);
    }

    /**
     * 查询用户账单列表
     *
     * @param fsUserBill 用户账单
     * @return 用户账单
     */
    @Override
    public List<FsUserBill> selectFsUserBillList(FsUserBill fsUserBill)
    {
        return fsUserBillMapper.selectFsUserBillList(fsUserBill);
    }

    /**
     * 新增用户账单
     *
     * @param fsUserBill 用户账单
     * @return 结果
     */
    @Override
    public int insertFsUserBill(FsUserBill fsUserBill)
    {
        fsUserBill.setCreateTime(DateUtils.getNowDate());
        return fsUserBillMapper.insertFsUserBill(fsUserBill);
    }

    /**
     * 修改用户账单
     *
     * @param fsUserBill 用户账单
     * @return 结果
     */
    @Override
    public int updateFsUserBill(FsUserBill fsUserBill)
    {
        fsUserBill.setUpdateTime(DateUtils.getNowDate());
        return fsUserBillMapper.updateFsUserBill(fsUserBill);
    }

    /**
     * 批量删除用户账单
     *
     * @param ids 需要删除的用户账单ID
     * @return 结果
     */
    @Override
    public int deleteFsUserBillByIds(Long[] ids)
    {
        return fsUserBillMapper.deleteFsUserBillByIds(ids);
    }

    /**
     * 删除用户账单信息
     *
     * @param id 用户账单ID
     * @return 结果
     */
    @Override
    public int deleteFsUserBillById(Long id)
    {
        return fsUserBillMapper.deleteFsUserBillById(id);
    }

    @Override
    public void addBill(Long uid, String cate,Integer billType,String title, double number, double balance, String renark,String busId,Long tuiUserId) {
        FsUserBill bill=new FsUserBill();
        bill.setCategory(cate);
        bill.setBillType(billType);
        bill.setUserId(uid);
        bill.setTitle(title);
        bill.setNumber(number);
        bill.setBalance(balance);
        bill.setRemark(renark);
        bill.setBusinessId(busId);
        bill.setStatus(1);
        bill.setCreateTime(new Date());
        bill.setTuiUserId(tuiUserId);
        logger.info("加入addBill:"+JSONUtil.toJsonStr(bill));
        fsUserBillMapper.insertFsUserBill(bill);
    }

    @Override
    public List<FsUserBill> selectFsUserBillListQuery(FsUserBillQueryParam param) {
        return fsUserBillMapper.selectFsUserBillListQuery(param);
    }

    @Override
    public List<FsUserBillVO> selectFsUserBillListVO(FsUserBillParam fsUserBill) {
        return fsUserBillMapper.selectFsUserBillListVO(fsUserBill);
    }

    @Override
    public BigDecimal selectFsUserBillTotalByUserId(String userId, String cate) {
        return fsUserBillMapper.selectFsUserBillTotalByUserId(userId,cate);
    }


}
