/**
 * Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.modules.sg.materialmodule.activiti.service;

import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.service.CrudService;
import com.jeeplus.modules.sg.managementcenter.activiti.entity.EngineeringAmount;
import com.jeeplus.modules.sg.managementcenter.activiti.entity.UploadImages;
import com.jeeplus.modules.sg.managementcenter.constructionProject.entity.ConstructionProject;
import com.jeeplus.modules.sg.materialmodule.activiti.entity.MaterialModule;
import com.jeeplus.modules.sg.materialmodule.activiti.entity.NonPower;
import com.jeeplus.modules.sg.materialmodule.activiti.mapper.MaterialModuleMapper;
import com.jeeplus.modules.sg.materialmodule.activiti.mapper.NonPowerMapper;
import com.jeeplus.modules.test.one.dialog.entity.Leave1;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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

/**
 * 请假表单Service
 *
 * @author lgf
 * @version 2018-06-12
 */
@Service
@Transactional(readOnly = true)
public class NonPowerService extends CrudService<NonPowerMapper, NonPower> {
    @Autowired
    private NonPowerMapper nonPowerMapper;

    @Override
    public NonPower get(String id) {
        return super.get(id);
    }

    @Transactional(readOnly = false)
    public void insert(NonPower nonPower) {
        nonPower.preInsert();
        nonPowerMapper.insert(nonPower);
    }

    /**
     * 通过项目需求名称查询所有的施工交底土建信息
     * */
    public List<EngineeringAmount> findCivilWorks(String reserveProjectName) {
        return nonPowerMapper.findCivilWorks(reserveProjectName);
    }

    /**
     * 修改土建开工报告信息
     */
    @Transactional(readOnly = false)
    public void updateStart(NonPower nonPower) {
        nonPowerMapper.updateStart(nonPower);
    }

    /**
     * 修改土建竣工报告信息
     */
    @Transactional(readOnly = false)
    public void updateEnd(NonPower nonPower) {
        nonPowerMapper.updateEnd(nonPower);
    }



    @Override
    public NonPower get(NonPower entity) {
        return super.get(entity);
    }

    /**
     * 根据储备名称查询是否包含土建工程量
     * */
    public boolean findIsEngineering(String reserveProjectName){
        boolean flag = true;
        List<EngineeringAmount> civilWorks = nonPowerMapper.findCivilWorks(reserveProjectName);
        if (null == civilWorks || civilWorks.size() <= 0) {
            flag = false;
        }
        return flag;
    }

    public NonPower getById(String id) {
        return nonPowerMapper.getById(id);
    }

    public Page<NonPower> findListPage(Page<NonPower> page, NonPower nonPower) {
        dataRuleFilter(nonPower);
        nonPower.setPage(page);
        page.setList(nonPowerMapper.findListPage(nonPower));
        return page;
    }

    /**
     * 土建流程上传文件
     */
    @Transactional(readOnly = false)
    public void saveUpload(UploadImages uploadImages) {
        uploadImages.preInsert();
        nonPowerMapper.saveUpload(uploadImages);
    }
}