package com.bonus.canteen.core.customer.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bonus.common.houqin.constant.LeConstants;
import com.bonus.canteen.core.customer.mapper.CustAddrMapper;
import com.bonus.canteen.core.customer.model.CustAddr;
import com.bonus.canteen.core.customer.service.CustAddrService;
import com.bonus.common.houqin.utils.id.Id;
import org.springframework.stereotype.Service;

import java.lang.invoke.SerializedLambda;

@Service
public class CustAddrServiceImpl extends ServiceImpl<CustAddrMapper, CustAddr> implements CustAddrService {
   public void insertCustAddr(CustAddr custAddr) {
      custAddr.setAddrId(Id.next());
      this.save(custAddr);
   }

   public void updateDefaultAddrForApp(CustAddr custAddr) {
      CustAddr updateAddr = new CustAddr();
      String openid = custAddr.getOpenid();
      Integer sourceType = custAddr.getSourceType();
      Long addrId = custAddr.getAddrId();
      updateAddr.setIfDefault(LeConstants.COMMON_NO);
      //this.update(updateAddr, (Wrapper)((LambdaQueryWrapper)(new QueryWrapper()).lambda().eq(CustAddr::getOpenid, openid)).eq(CustAddr::getSourceType, sourceType));
      this.update(updateAddr, new LambdaQueryWrapper<CustAddr>().eq(CustAddr::getOpenid, openid).eq(CustAddr::getSourceType, sourceType));
      updateAddr.setIfDefault(LeConstants.COMMON_YES);
     // this.update(updateAddr, (Wrapper)(new QueryWrapper()).lambda().eq(CustAddr::getAddrId, addrId));
      this.update(updateAddr, new LambdaQueryWrapper<CustAddr>().eq(CustAddr::getAddrId, addrId));
   }

   public void deleteCustAddrForApp(CustAddr custAddr) {
      custAddr.setIfDel(LeConstants.COMMON_YES);
      this.updateById(custAddr);
   }

   // $FF: synthetic method

}
