
package org.jeecg.modules.alUser.service;


import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.jeecg.config.shiro.ShiroRealm;
import org.jeecg.modules.address.entity.TbAddress;
import org.jeecg.modules.address.service.ITbAddressService;
import org.jeecg.modules.hanHaiMember.entity.HanHaiMember;
import org.jeecg.modules.hanHaiMember.service.IHanHaiMemberService;
import org.jeecg.modules.postBean.AddressReq;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@Service
public class AddressServiceImpl implements AddressService {


    @Autowired
    private ITbAddressService tbAddressService;
    @Autowired
    private IHanHaiMemberService iHanHaiMemberService;
    @Autowired
    private ShiroRealm shiroRealm;


    @Transactional(rollbackFor = Exception.class)
    @Override
    public void editAddresss(AddressReq tbAddress, String token) {
        HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiAccount(token);
        TbAddress tbAddress1 = new TbAddress();
        BeanUtils.copyProperties(tbAddress, tbAddress1);
        if (tbAddress.getDefaultFlag() == 1) {
            UpdateWrapper<TbAddress> objectUpdateWrapper = new UpdateWrapper<>();
            objectUpdateWrapper.set("default_flag", 0).eq("user_id", hanHaiMember.getId());
            tbAddressService.update(objectUpdateWrapper);
        }
        tbAddressService.updateById(tbAddress1);
    }









}
