package com.yeejoin.amos.api.openapi.face.service;

import com.yeejoin.amos.api.openapi.face.model.*;
import com.yeejoin.amos.boot.module.cylinder.flc.api.dto.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.typroject.tyboot.core.foundation.utils.Bean;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yeejoin.amos.boot.module.cylinder.flc.api.dto.CylinderInfoDto;
import com.yeejoin.amos.boot.module.cylinder.flc.api.entity.CylinderFilling;
import com.yeejoin.amos.boot.module.cylinder.flc.api.entity.CylinderFillingCheck;
import com.yeejoin.amos.boot.module.cylinder.flc.api.entity.CylinderFillingExamine;
import com.yeejoin.amos.boot.module.cylinder.flc.api.entity.CylinderFillingRecord;
import com.yeejoin.amos.boot.module.cylinder.flc.api.entity.CylinderInfo;
import com.yeejoin.amos.boot.module.cylinder.flc.api.entity.CylinderInspection;
import com.yeejoin.amos.boot.module.cylinder.flc.api.entity.CylinderTags;
import com.yeejoin.amos.boot.module.cylinder.flc.api.entity.CylinderUnit;
import com.yeejoin.amos.boot.module.cylinder.flc.api.entity.CylinderUnitVideo;
import com.yeejoin.amos.boot.module.cylinder.flc.api.mapper.CylCylinderFillingCheckMapper;
import com.yeejoin.amos.boot.module.cylinder.flc.api.mapper.CylinderFillingCheckMapper;
import com.yeejoin.amos.boot.module.cylinder.flc.api.mapper.CylinderFillingExamineMapper;
import com.yeejoin.amos.boot.module.cylinder.flc.api.mapper.CylinderFillingMapper;
import com.yeejoin.amos.boot.module.cylinder.flc.api.mapper.CylinderInfoMapper;
import com.yeejoin.amos.boot.module.cylinder.flc.api.mapper.CylinderInspectionMapper;
import com.yeejoin.amos.boot.module.cylinder.flc.api.mapper.CylinderTagsMapper;
import com.yeejoin.amos.boot.module.cylinder.flc.api.mapper.CylinderUnitMapper;

import java.util.List;

@Component
@DS("tzs")
public class SyncCylinderDataService
{
  /**
   * 气瓶企业信息
   */
  @Autowired
  private CylinderUnitMapper cylinderUnitMapper;
  /**
   * 气瓶基本信息
   */
  @Autowired
  private CylinderInfoMapper cylinderInfoMapper;
  /**
   * 气瓶充装信息--充装前检查
   */
  @Autowired
  private CylinderFillingMapper  cylinderFillingMapper;
  /**
   * 液化气体气瓶充装信息-充装后复查
   */
  @Autowired
  private CylinderFillingCheckMapper  cylinderFillingCheckMapper;
  @Autowired
  private CylCylinderFillingCheckMapper cylCylinderFillingCheckMapper;
  /**
   * 液化气体气瓶充装信息审核
   */
  @Autowired
  private CylinderFillingExamineMapper cylinderFillingExamineMapper;
  /**
   * 气瓶标签信息
   */
  @Autowired
  private CylinderTagsMapper  cylinderTagsMapper;
  /**
   * 气瓶检验信息
   */
  @Autowired
  private CylinderInspectionMapper  cylinderInspectionMapper;

  @DS("tzs")
  public void syncCylinderUnit(List<TmCylinderUnitModel> cylinderUnitDto) {
//    List<CylinderUnit> cylinderUnits = Bean.toModels(cylinderUnitDto,CylinderUnit.class);
//    LambdaQueryWrapper<CylinderUnit> wrapper = new LambdaQueryWrapper<>();
//    List<CylinderUnit> cylinderUnitList = this.getBaseMapper().selectList(wrapper);
    List<CylinderUnit> cylinderUnitList = Bean.toModels(cylinderUnitDto,CylinderUnit.class);
    cylinderUnitMapper.saveOrUpdateBatch(cylinderUnitList);
  }
  @DS("tzs")
  public void syncCylinderInfo(final List<TmCylinderInfoModel> cylinderInfoDto) {
    List<CylinderInfo> cylinderUnitList = Bean.toModels(cylinderInfoDto,CylinderInfo.class);
    cylinderInfoMapper.saveOrUpdateBatch(cylinderUnitList);
  }
  @DS("tzs")
  public void syncCylinderFillingExamine(List<TmCylinderFillingExamineModel> cylinderFillingExamineDto) {
    List<CylinderFillingExamine> cylinderFillingExamineList = Bean.toModels(cylinderFillingExamineDto,
        CylinderFillingExamine.class);
    cylinderFillingExamineMapper.saveOrUpdateBatch(cylinderFillingExamineList);
  }
  @DS("tzs")
  public void syncCylinderFillingRecord(List<TmCylinderFillingRecordModel> cylinderFillingRecordDtos) {
    List<CylinderFillingRecord> cylinderFillingRecordList = Bean.toModels(cylinderFillingRecordDtos, CylinderFillingRecord.class);
    cylCylinderFillingCheckMapper.batchInsertOrUpdate(cylinderFillingRecordList);
  }
  @DS("tzs")
  public void syncCylinderInspection(List<TmCylinderInspectionModel> cylinderInspectionDto) {
    List<CylinderInspection> cylinderInspectionList = Bean.toModels(cylinderInspectionDto, CylinderInspection.class);
    cylinderInspectionMapper.saveOrUpdateBatch(cylinderInspectionList);
  }
  @DS("tzs")
  public void syncCylinderTag(List<TmCylinderTagsModel> cylinderTagsDtos) {
    List<CylinderTags> cylinderTagsList = Bean.toModels(cylinderTagsDtos, CylinderTags.class);
    cylinderTagsMapper.saveOrUpdateBatch(cylinderTagsList);
  }
  @DS("tzs")
  public void syncCylinderFillingBefore(List<TmCylinderFillingModel> cylinderFillingDtos) {
    List<CylinderFilling> cylinderFillingList = Bean.toModels(cylinderFillingDtos, CylinderFilling.class);
    cylCylinderFillingCheckMapper.saveAndBatchInsert(cylinderFillingList);
  }
  @DS("tzs")
  public void syncCylinderFillingAfter(List<TmCylinderFillingCheckModel> cylinderFillingCheckDtos) {
    List<CylinderFillingCheck> cylinderFillingChecList = Bean.toModels(cylinderFillingCheckDtos, CylinderFillingCheck.class);
    cylinderFillingCheckMapper.saveOrUpdateByCondition(cylinderFillingChecList);
  }
}
