package com.nantian.cloud.jly.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nantian.cloud.jly.entity.CheckBasisFile;
import com.nantian.cloud.jly.entity.CheckPlan;
import com.nantian.cloud.jly.mapper.CheckBasisFileMapper;
import com.nantian.cloud.jly.mapper.CheckPlanMapper;
import com.nantian.cloud.jly.service.CheckBasisFileService;
import com.nantian.cloud.jly.service.CheckPlanService;
import com.nantian.sc.cloud.common.data.datascope.DataScope;
import com.nantian.sc.cloud.common.security.service.ScUser;
import com.nantian.sc.cloud.common.security.util.SecurityUtils;
import org.springframework.stereotype.Service;

import java.math.BigInteger;
import java.util.Date;

/**
 *
 * @date 2018-09-27
 */
@Service("CheckBasisFileService")
public class CheckBasisFileServiceImpl extends ServiceImpl<CheckBasisFileMapper, CheckBasisFile> implements CheckBasisFileService {
    @Override
    public boolean upload(String uuid, CheckBasisFile checkBasisFile) {
        CheckBasisFile checkBasisFileNew = new CheckBasisFile();
//        checkBasisFileNew.setCheckPlanId(checkPlanId);
//        checkBasisFileNew.setBasisFile(uuid);

        int i = 0;
        CheckBasisFile oldData = baseMapper.selectOne(Wrappers.query(checkBasisFile));
        ScUser u = SecurityUtils.getUser();
        if (oldData != null) { //修改
            if (u.getId() != null) {
                oldData.setUserid(u.getId());
            }
            oldData.setUpdateTime(new Date());
            oldData.setBasisFile(uuid);
            i = baseMapper.updateById(oldData);
            System.err.println("oldDate：" + oldData);
        } else { //新增
            if (u.getId() != null) {
                checkBasisFile.setUserid(u.getId());
            }
            checkBasisFile.setUpdateTime(new Date());
            checkBasisFile.setDelFlag("1");
            checkBasisFile.setDeptId(u.getDeptId());
            checkBasisFile.setBasisFile(uuid);
            i = baseMapper.insert(checkBasisFile);
            System.err.println("checkBasisFile：" + checkBasisFile);
        }
        return i == 0 ? false : true;
    }

    @Override
    public boolean upload1(String uuid, CheckBasisFile checkBasisFile) {
        CheckBasisFile checkBasisFileNew = new CheckBasisFile();

        int i = 0;
        CheckBasisFile oldData = baseMapper.selectOne(Wrappers.query(checkBasisFile));
        ScUser u = SecurityUtils.getUser();
        if (oldData != null) { //修改
            if (u.getId() != null) {
                oldData.setUserid(u.getId());
            }
            oldData.setUpdateTime(new Date());
            oldData.setTableFile(uuid);
            i = baseMapper.updateById(oldData);
            System.err.println("oldDate：" + oldData);
        } else { //新增
            if (u.getId() != null) {
                checkBasisFile.setUserid(u.getId());
            }
            checkBasisFile.setUpdateTime(new Date());
            checkBasisFile.setDelFlag("1");
            checkBasisFile.setDeptId(u.getDeptId());
            checkBasisFile.setTableFile(uuid);
            i = baseMapper.insert(checkBasisFile);
            System.err.println("checkBasisFile：" + checkBasisFile);
        }
        return i == 0 ? false : true;
    }

    @Override
    public IPage<CheckBasisFile> selectAll(Page page, CheckBasisFile checkBasisFile) {
        return baseMapper.selectAll(page,checkBasisFile,new DataScope());
    }
//
//    @Override
//    public IPage<CheckPlan> getByPage(Page page, CheckPlan checkPlan) {
//        return baseMapper.getByPage(page,checkPlan,new DataScope());
//    }
//
//    @Override
//    public IPage<CheckPlan> getPageByEpc(Page page, String epc) {
//        return baseMapper.getPageByEpc(page,epc);
//    }
}

