package com.hzs.ground.margin.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzs.common.core.enums.*;
import com.hzs.common.domain.ground.margin.ThMargin;
import com.hzs.common.security.utils.SecurityUtils;
import com.hzs.ground.margin.mapper.ThMarginMapper;
import com.hzs.ground.margin.service.IThMarginService;
import com.hzs.ground.margin.vo.ThMarginVO;
import com.hzs.ground.product.service.IThApprovalLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * 保证金缴纳 服务实现类
 */
@Service
public class ThMarginServiceImpl extends ServiceImpl<ThMarginMapper, ThMargin> implements IThMarginService {

    @Autowired
    IThApprovalLogService iThApprovalLogService;

    @Override
    public List<ThMarginVO> queryThMarginList(ThMarginVO thMarginVO) {
        return baseMapper.queryThMarginList(thMarginVO);
    }

    @Override
    public boolean saveThMargin(ThMarginVO thMarginVO) {
        ThMargin tm = BeanUtil.copyProperties(thMarginVO, ThMargin.class);
        baseMapper.insert(tm);
        return true;
    }

    @Override
    public boolean updateThMargin(ThMarginVO thMarginVO) {
        ThMargin tm = BeanUtil.copyProperties(thMarginVO, ThMargin.class);
        baseMapper.updateById(tm);
        return true;
    }

    @Override
    public boolean delThMargin(Long pkId) {
        UpdateWrapper<ThMargin> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("PK_ID", pkId);
        updateWrapper.set("PK_MODIFIED", SecurityUtils.getUserId());
        updateWrapper.set("MODIFIED_TIME", new Date());
        updateWrapper.set("DEL_FLAG", EDelFlag.DELETE.getValue());
        baseMapper.update(null, updateWrapper);
        return true;
    }

}
