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

import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.util.BooleanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bonus.canteen.core.customer.mapper.CustJobMapper;
import com.bonus.canteen.core.customer.model.CustJob;
import com.bonus.canteen.core.customer.service.CustInfoService;
import com.bonus.canteen.core.customer.service.CustJobService;
import com.bonus.common.houqin.i18n.I18n;
import com.bonus.common.houqin.utils.id.Id;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.lang.invoke.SerializedLambda;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class CustJobServiceImpl extends ServiceImpl<CustJobMapper, CustJob> implements CustJobService {
//   @Autowired
//   CustInfoService custInfoService;
//
//   public void addCustJob(CustJob custJob) {
//      List<CustJob> custJobList = ((CustJobMapper)this.baseMapper).selectCustJob(custJob);
//      Iterator var3 = custJobList.iterator();
//
//      CustJob result;
//      do {
//         if (!var3.hasNext()) {
//            custJob.setJobId(Id.next());
//            ((CustJobMapper)this.baseMapper).insert(custJob);
//            return;
//         }
//
//         result = (CustJob)var3.next();
//         if (result.getJobName().equals(custJob.getJobName())) {
//            throw new LeException(RetCodeEnum.CORE_IMPORT_EMPTY, I18n.getMessage("customer.job.name.exists", new Object[0]));
//         }
//      } while(!result.getJobCode().equals(custJob.getJobCode()));
//
//      throw new LeException(RetCodeEnum.CORE_IMPORT_EMPTY, I18n.getMessage("customer.job.num.exists", new Object[0]));
//   }
//
//   public void deleteCustJobById(Collection<Long> ids) {
//      List<String> jobCodes = (List)((CustJobMapper)this.baseMapper).selectList((Wrapper)Wrappers.lambdaQuery(CustJob.class).select(new SFunction[]{CustJob::getJobCode}).in(CustJob::getId, ids)).stream().map(CustJob::getJobCode).collect(Collectors.toList());
//      if (BooleanUtil.isTrue(this.custInfoService.exitsCustomerBindJobs(jobCodes))) {
//         throw new LeException(I18n.getMessage("customer.job.exists.bind.cannotDelete", new Object[0]));
//      } else {
//         ((CustJobMapper)this.baseMapper).deleteBatchIds(ids);
//      }
//   }
//
//   public Page<CustJobVO> pageCustJobList(Page mpPage, CustJobDTO custJobDTO) {
//      return ((CustJobMapper)this.baseMapper).pageCustJobList(mpPage, custJobDTO);
//   }
//
//   public synchronized void syncCustJob(String jobCode, String jobName, CustJobTypeEnum jobTypeEnum) {
//      if (CharSequenceUtil.hasBlank(new CharSequence[]{jobCode, jobName})) {
//         throw new LeException(I18n.getMessage("customer.job.numAndnameAndType.nonNull", new Object[0]));
//      } else {
//         CustJob custJob = (CustJob)((CustJobMapper)this.baseMapper).selectOne((Wrapper)((LambdaQueryWrapper)Wrappers.lambdaQuery(CustJob.class).eq(CustJob::getJobType, jobTypeEnum.getKey())).eq(CustJob::getJobCode, jobCode));
//         if (ObjectUtil.isNull(custJob)) {
//            ((CustJobMapper)this.baseMapper).selectList((Wrapper)((LambdaQueryWrapper)((LambdaQueryWrapper)((LambdaQueryWrapper)Wrappers.lambdaQuery(CustJob.class).eq(CustJob::getJobType, jobTypeEnum.getKey())).eq(CustJob::getJobCode, jobCode)).or()).eq(CustJob::getJobName, jobName)).forEach((item) -> {
//               if (jobCode.equals(item.getJobCode())) {
//                  throw new LeException(I18n.getMessage("customer.job.num.exists", new Object[0]));
//               } else if (jobName.equals(item.getJobName())) {
//                  throw new LeException(I18n.getMessage("customer.job.name.exists", new Object[0]));
//               }
//            });
//            custJob = new CustJob();
//            custJob.setJobId(Id.next());
//            custJob.setJobCode(jobCode);
//            custJob.setJobName(jobName);
//            custJob.setJobType(jobTypeEnum.getKey());
//            custJob.setDescription("third同步");
//            ((CustJobMapper)this.baseMapper).insert(custJob);
//         } else {
//            custJob.setJobName(jobName);
//            custJob.setDescription("third同步");
//            ((CustJobMapper)this.baseMapper).updateById(custJob);
//         }
//
//      }
//   }
}
