package com.inkasso.factoring.system.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.inkasso.adapter.exception.enums.ExceptionEnum;
import com.inkasso.adapter.util.BeanUtilsProxy;
import com.inkasso.factoring.system.user.dao.WxAccountDAO;
import com.inkasso.factoring.system.user.entity.WxAccountDO;
import com.inkasso.factoring.system.user.model.request.AddWxAccountRequest;
import com.inkasso.factoring.system.user.model.request.EditWxAccountRequest;
import com.inkasso.factoring.system.user.service.WxAccountService;
import com.inkasso.adapter.exception.ServiceException;
import org.springframework.stereotype.Service;

/**
* @author 张超
* @date  2023-08-17
*/
@Service
public class WxAccountServiceImpl extends ServiceImpl<WxAccountDAO, WxAccountDO> implements WxAccountService {


    @Override
    public void addWxAccount(AddWxAccountRequest addWxAccountRequest) {
    WxAccountDO wxAccount = BeanUtilsProxy.copyPropertiesIgnoreNull(addWxAccountRequest, WxAccountDO.class);
    this.baseMapper.insert(wxAccount);
    }

    @Override
    public void editWxAccount(EditWxAccountRequest editWxAccountRequest) {

    WxAccountDO wxAccount = super.getById(editWxAccountRequest.getId());
    if (wxAccount == null) {
    throw new ServiceException(400, ExceptionEnum.SYSTEM_DATE_ERROR);
    }
    BeanUtilsProxy.copyPropertiesNotIgnoreNull(editWxAccountRequest,wxAccount);
    this.updateById(wxAccount);
    }


    @Override
    public WxAccountDO getByOpenId(String openId) {
        LambdaQueryWrapper<WxAccountDO> queryWrapper = new  LambdaQueryWrapper();
        queryWrapper.eq(WxAccountDO::getOpenId,openId);
        WxAccountDO wxAccountDO = this.baseMapper.selectOne(queryWrapper);

        return wxAccountDO;
    }

    @Override
    public void deleteWxAccount(Long id) {

    this.removeById(id);
    }
}

