package com.kiisoo.ic.customer.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.kiisoo.ic.customer.entity.OpCustomer;
import com.kiisoo.ic.customer.entity.OpCustomerEnterpriseWechat;
import com.kiisoo.ic.customer.entity.OpSellerCustomerRelation;
import com.kiisoo.ic.customer.entity.OpVip;
import com.kiisoo.ic.customer.mapper.OpCustomerDOMapper;
import com.kiisoo.ic.customer.mapper.OpCustomerEnterpriseWechatDOMapper;
import com.kiisoo.ic.customer.mapper.OpSellerCustomerRelationDOMapper;
import com.kiisoo.ic.customer.mapper.OpVipDOMapper;
import com.kiisoo.ic.store.entity.PoiStoreStaff;
import com.kiisoo.ic.store.mapper.PoiStoreStaffDOMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * @ClassName: CustomerEnterpriseService
 * @Description: 店铺企业微信信息
 * @Auther: yinliujing
 * @Date: 2020/4/8
 * @Version: v1
 */
@Service
public class CustomerEnterpriseService {

    @Autowired
    private  OpCustomerEnterpriseWechatDOMapper opCustomerDOMapper;

    /**
     * 新增店铺企业微信信息
     * @param  oCusEnterprise
     */
    @Transactional(rollbackFor = Exception.class)
    public void addCustomerEnterprise(OpCustomerEnterpriseWechat oCusEnterprise){
        QueryWrapper<OpCustomerEnterpriseWechat> customerWrapper = new QueryWrapper<>();
        customerWrapper.eq("unionid",oCusEnterprise.getUnionid()).last("limit 1");
        OpCustomerEnterpriseWechat opCustomerEnterpriseWechat = opCustomerDOMapper.selectOne(customerWrapper);
        if(null == opCustomerEnterpriseWechat){
            //不存在
            opCustomerDOMapper.insert(oCusEnterprise);
        }
    }

    /**
     * 更新店铺企业微信信息
     * @param  oCusEnterprise
     */
    @Transactional(rollbackFor = Exception.class)
    public void editCustomerEnterprise(OpCustomerEnterpriseWechat oCusEnterprise){
        QueryWrapper<OpCustomerEnterpriseWechat> wrapper1 = new QueryWrapper<>();
        wrapper1.eq("unionid",oCusEnterprise.getUnionid());
        opCustomerDOMapper.update(oCusEnterprise,wrapper1);
    }



}
