package vip.xiaonuo.money.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import vip.xiaonuo.money.entity.MoneyPeople;
import vip.xiaonuo.money.mapper.MoneyPeopleMapper;
import vip.xiaonuo.money.param.MoneyPeopleAddParam;
import vip.xiaonuo.money.service.IMoneyPeopleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 财务预警通知 服务实现类
 * </p>
 *
 * @author author
 * @since 2024-11-22
 */
@Service
public class MoneyPeopleServiceImpl extends ServiceImpl<MoneyPeopleMapper, MoneyPeople> implements IMoneyPeopleService {

    @Autowired
    private MoneyPeopleMapper peopleMapper;

    @Override
    public void add(MoneyPeopleAddParam addParam) {
        String orgId = addParam.getOrgId();
        QueryWrapper<MoneyPeople> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("org_id", orgId).eq("type", addParam.getType());
        MoneyPeople people = peopleMapper.selectOne(queryWrapper);
        if (ObjectUtil.isNotEmpty(people)) {
            people.setOrdinary(addParam.getOrdinary());
            people.setImportant(addParam.getImportant());
            people.setRemind(addParam.getRemind());
            peopleMapper.updateById(people);
        } else {
            MoneyPeople moneyPeople = BeanUtil.toBean(addParam, MoneyPeople.class);
            peopleMapper.insert(moneyPeople);
        }
    }
}
