package com.emr.service.tScanAssort;

import com.emr.dao.CommomMapper;
import com.emr.dao.tScanAssort.T_Scan_AssortMapper;
import com.emr.entity.recordLock.Emr_Lock;
import com.emr.entity.tScanAssort.T_Scan_Assort;
import com.emr.vo.FontVo.ScanAssortVo;
import com.emr.vo.commomSearch.CommomVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @ProjectName:
 * @Description:
 * @Param 传输参数
 * @Return
 * @Author: 曾文和
 * @CreateDate: 2019/6/6 15:19
 * @UpdateUser: 曾文和
 * @UpdateDate: 2019/6/6 15:19
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
@Service
@Transactional
public class T_Scan_AssortServiceImpl implements T_Scan_AssortService{
    @Autowired
    private T_Scan_AssortMapper scanAssortMapper;
    @Autowired
    private CommomMapper commomMapper;
    @Override
    public void updateByPrimaryKeySelective(T_Scan_Assort newAssort, T_Scan_Assort oldAssort) {
        scanAssortMapper.updateByPrimaryKeySelective(newAssort,oldAssort);
    }

    @Override
    public int SimpleUpdate(String patientId, String assortId, List<String> list) {
        return scanAssortMapper.SimpleUpdate(patientId, assortId, list);
    }

    @Override
    public int SimpleUpdateByPatientIdAndScanPages(String patientId, String newAssortId, String scanPages) {
        return scanAssortMapper.SimpleUpdateByPatientIdAndScanPages(patientId, newAssortId, scanPages);
    }

    @Override
    public int SimpleDelByPatientIdAndScanPages(String patientId, String scanPages) {
        return scanAssortMapper.SimpleDelByPatientIdAndScanPages(patientId,scanPages);
    }

    @Override
    public void SimpleInsert(List<T_Scan_Assort> list) {
        if(!CollectionUtils.isEmpty(list)) {
            //根据字段多少批量新增
            ///查询表列数
            int colCount = commomMapper.selectColByTableName("t_scan_assort");
            int simpleInsertCount = 2100 / colCount;
            List<T_Scan_Assort> scanAssorts = new ArrayList<>();
            for (int i = 0; i < list.size(); i++) {
                //处理批量添加sql太长问题，设定个数为180
                if (i != 0 && list.size() % simpleInsertCount == 0) {
                    scanAssorts.clear();
                }
                scanAssorts.add(list.get(i));
                //是180的倍数或最后一个
                if (list.size() % simpleInsertCount == 0 || i == list.size() - 1) {
                    scanAssortMapper.SimpleInsert(scanAssorts);
                }
            }
        }
    }

    @Override
    public List<ScanAssortVo> selectPicPaths(String patientId, String scanPages, String flag) {
        return scanAssortMapper.selectPicPaths(patientId, scanPages, flag);
    }

    @Override
    public void recoverPic(String patientId, String scanPages) {
        scanAssortMapper.recoverPic(patientId, scanPages);
    }
}
