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 com.hzs.system.sys.IApprovalServiceApi;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * 保证金缴纳 服务实现类
 *
 * @author hzs
 * @since 2024-03-21
 */
@Service
public class ThMarginServiceImpl extends ServiceImpl<ThMarginMapper, ThMargin> implements IThMarginService {

    /**
     * @description: 保证金缴纳列表
     * @author: zhang jing
     * @date: 2024/3/22 14:47
     * @param: [thMarginVO]
     * @return: java.util.List<com.hzs.ground.margin.vo.ThMarginVO>
     **/
    @Override
    public List<ThMarginVO> queryThMarginList(ThMarginVO thMarginVO) {
        return baseMapper.queryThMarginList(thMarginVO);
    }

    /**
     * @description: 添加保证金缴纳
     * @author: zhang jing
     * @date: 2024/3/22 14:46
     * @param: [thMarginVO]
     * @return: boolean
     **/
    @Override
    public boolean saveThMargin(ThMarginVO thMarginVO) {
        ThMargin tm = BeanUtil.copyProperties(thMarginVO, ThMargin.class);
        baseMapper.insert(tm);
        return true;
    }

    /**
     * @description: 修改保证金缴纳
     * @author: zhang jing
     * @date: 2024/3/22 14:45
     * @param: [thMarginVO]
     * @return: boolean
     **/
    @Override
    public boolean updateThMargin(ThMarginVO thMarginVO) {
        ThMargin tm = BeanUtil.copyProperties(thMarginVO, ThMargin.class);
        baseMapper.updateById(tm);
        return true;
    }

    /**
     * @description: 删除保证金缴纳
     * @author: zhang jing
     * @date: 2024/3/22 14:45
     * @param: [pkId]
     * @return: boolean
     **/
    @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;
    }
}
