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

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

import com.jeeplus.common.utils.IdGen;
import com.jeeplus.modules.sys.entity.Office;
import com.jeeplus.modules.sys.utils.UserUtils;
import com.jeeplus.modules.workexample.dao.WorkExampleInfoDao;
import com.jeeplus.modules.workexample.entity.WorkExampleInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jeeplus.common.persistence.Page;
import com.jeeplus.common.service.CrudService;
import com.jeeplus.modules.workexample.entity.WorkExampleIndices;
import com.jeeplus.modules.workexample.dao.WorkExampleIndicesDao;

/**
 * 指标项目字典Service
 * @author 杨帆
 * @version 2018-08-27
 */
@Service
@Transactional(readOnly = true)
public class WorkExampleIndicesService extends CrudService<WorkExampleIndicesDao, WorkExampleIndices> {
	@Autowired
	private WorkExampleInfoDao workExampleInfoDao;

	public WorkExampleIndices get(String id) {
		return super.get(id);
	}
	public WorkExampleInfo getWorkExampleInfo(String id) {
		return workExampleInfoDao.get(id);
	}
	public Integer getOrderNum(String id) {
		return dao.getOrderNum(id);
	}
	public Integer exampleIndicesCount(String id,String workExampleId) {
		return dao.exampleIndicesCount(id,workExampleId);
	}
	@Transactional(readOnly = false)
	public void saveExampleIndices(String id,String workExampleId) {
		dao.saveExampleIndices(id,workExampleId);
	}

	public List<WorkExampleIndices> findList(WorkExampleIndices workExampleIndices) {
		Office company = UserUtils.getSelectCompany();
		workExampleIndices.setCompanyId(company.getId());
		return super.findList(workExampleIndices);
	}

	@Transactional(readOnly = false)
	public List<WorkExampleIndices> findLists(WorkExampleIndices workExampleIndices) {
		List<WorkExampleIndices> list = new ArrayList<>();
		Office company = UserUtils.getSelectCompany();
		workExampleIndices.setCompanyId(company.getId());
		list = super.findList(workExampleIndices);
		if (list==null || list.size()==0){
			saveCompanyInfo(company);
		}
		return list;
	}
	public List<WorkExampleIndices> findByParentId(String id) {
		return dao.findByParentId(id);
	}
	public Page<WorkExampleIndices> findPageByParentId(Page<WorkExampleIndices> page, WorkExampleIndices workExampleIndices) {
		workExampleIndices.setPage(page);
		page.setList(dao.findByParentIds(workExampleIndices));
		return page;
	}
	public List<WorkExampleIndices> findListInfo(WorkExampleIndices workExampleIndices) {
		return dao.findListInfo(workExampleIndices);
	}
	public List<WorkExampleInfo> treeDataInfo(WorkExampleInfo workExampleInfo) {
		return workExampleInfoDao.findList(workExampleInfo);
	}

	public Page<WorkExampleIndices> findPage(Page<WorkExampleIndices> page, WorkExampleIndices workExampleIndices) {
		return super.findPage(page, workExampleIndices);
	}
	
	@Transactional(readOnly = false)
	public void save(WorkExampleIndices workExampleIndices) {
		super.save(workExampleIndices);
	}
	@Transactional(readOnly = false)
	public void saveCompanyInfo(Office company) {
		WorkExampleIndices workExampleIndices = new WorkExampleIndices();
		workExampleIndices.setCompanyId(company.getId());
		workExampleIndices.preInsert();
		workExampleIndices.setIsDisable("0");
		workExampleIndices.setName("单项工程造价指标");
		workExampleIndices.setOrderNum("1");
		workExampleIndices.setParentIds("0,");
		workExampleIndices.setParent(new WorkExampleIndices("0"));
		workExampleIndices.setType("1");
		dao.insert(workExampleIndices);
		String ids = IdGen.uuid();
		String parentIds = "0,"+ids+",";
		workExampleIndices.setName("单位工程造价指标");
		workExampleIndices.setOrderNum("2");
		workExampleIndices.setType("2");
		workExampleIndices.setId(ids);
		dao.insert(workExampleIndices);
		String id1 = IdGen.uuid();
		String id2 = IdGen.uuid();
		String id3 = IdGen.uuid();
		String id4 = IdGen.uuid();
		String id5 = IdGen.uuid();
		String id6 = IdGen.uuid();
		String id7 = IdGen.uuid();
		String id8 = IdGen.uuid();
		String id9 = IdGen.uuid();
		String id10 = IdGen.uuid();
		workExampleIndices.setName("房屋建筑工程指标");
		workExampleIndices.setOrderNum("201");
		workExampleIndices.setParentIds(parentIds);
		workExampleIndices.setParent(new WorkExampleIndices(ids));
		workExampleIndices.setType("3");
		workExampleIndices.setId(id1);
		dao.insert(workExampleIndices);
		workExampleIndices.setName("房屋装饰工程指标");
		workExampleIndices.setOrderNum("202");
		workExampleIndices.setParentIds(parentIds);
		workExampleIndices.setParent(new WorkExampleIndices(ids));
		workExampleIndices.setType("3");
		workExampleIndices.setId(id2);
		dao.insert(workExampleIndices);
		workExampleIndices.setName("电气工程指标");
		workExampleIndices.setOrderNum("203");
		workExampleIndices.setParentIds(parentIds);
		workExampleIndices.setParent(new WorkExampleIndices(ids));
		workExampleIndices.setType("3");
		workExampleIndices.setId(id3);
		dao.insert(workExampleIndices);
		workExampleIndices.setName("建筑智能化安装工程指标");
		workExampleIndices.setOrderNum("204");
		workExampleIndices.setParentIds(parentIds);
		workExampleIndices.setParent(new WorkExampleIndices(ids));
		workExampleIndices.setType("3");
		workExampleIndices.setId(id4);
		dao.insert(workExampleIndices);
		workExampleIndices.setName("通风空调工程指标");
		workExampleIndices.setOrderNum("205");
		workExampleIndices.setParentIds(parentIds);
		workExampleIndices.setParent(new WorkExampleIndices(ids));
		workExampleIndices.setType("3");
		workExampleIndices.setId(id5);
		dao.insert(workExampleIndices);
		workExampleIndices.setName("消防工程指标");
		workExampleIndices.setOrderNum("206");
		workExampleIndices.setParentIds(parentIds);
		workExampleIndices.setParent(new WorkExampleIndices(ids));
		workExampleIndices.setType("3");
		workExampleIndices.setId(id6);
		dao.insert(workExampleIndices);
		workExampleIndices.setName("给排水工程指标");
		workExampleIndices.setOrderNum("207");
		workExampleIndices.setParentIds(parentIds);
		workExampleIndices.setParent(new WorkExampleIndices(ids));
		workExampleIndices.setType("3");
		workExampleIndices.setId(id7);
		dao.insert(workExampleIndices);
		workExampleIndices.setName("采暖工程指标");
		workExampleIndices.setOrderNum("208");
		workExampleIndices.setParentIds(parentIds);
		workExampleIndices.setParent(new WorkExampleIndices(ids));
		workExampleIndices.setType("3");
		workExampleIndices.setId(id8);
		dao.insert(workExampleIndices);
		workExampleIndices.setName("燃气工程指标");
		workExampleIndices.setOrderNum("209");
		workExampleIndices.setParentIds(parentIds);
		workExampleIndices.setParent(new WorkExampleIndices(ids));
		workExampleIndices.setType("3");
		workExampleIndices.setId(id9);
		dao.insert(workExampleIndices);
		workExampleIndices.setName("医疗气体工程指标");
		workExampleIndices.setOrderNum("210");
		workExampleIndices.setParentIds(parentIds);
		workExampleIndices.setParent(new WorkExampleIndices(ids));
		workExampleIndices.setType("3");
		workExampleIndices.setId(id10);
		dao.insert(workExampleIndices);

		workExampleIndices.setName("房屋建筑工程经济指标");
		workExampleIndices.setOrderNum("20101");
		workExampleIndices.setParentIds(parentIds+id1+",");
		workExampleIndices.setParent(new WorkExampleIndices(id1));
		workExampleIndices.preInsert();
		workExampleIndices.setType("4");
		dao.insert(workExampleIndices);
		workExampleIndices.setName("房屋建筑工程主要工程量指标");
		workExampleIndices.setOrderNum("20102");
		workExampleIndices.setParentIds(parentIds+id1+",");
		workExampleIndices.setParent(new WorkExampleIndices(id1));
		workExampleIndices.setType("5");
		workExampleIndices.preInsert();
		dao.insert(workExampleIndices);
		workExampleIndices.setName("房屋建筑工程主要工料价格及消耗量指标");
		workExampleIndices.setOrderNum("20103");
		workExampleIndices.setParentIds(parentIds+id1+",");
		workExampleIndices.setParent(new WorkExampleIndices(id1));
		workExampleIndices.setType("6");
		workExampleIndices.preInsert();
		dao.insert(workExampleIndices);

		workExampleIndices.setName("房屋装饰工程经济指标");
		workExampleIndices.setOrderNum("20201");
		workExampleIndices.setParentIds(parentIds+id2+",");
		workExampleIndices.setParent(new WorkExampleIndices(id2));
		workExampleIndices.preInsert();
		workExampleIndices.setType("4");
		dao.insert(workExampleIndices);
		workExampleIndices.setName("房屋装饰工程主要工程量指标");
		workExampleIndices.setOrderNum("20202");
		workExampleIndices.setParentIds(parentIds+id2+",");
		workExampleIndices.setParent(new WorkExampleIndices(id2));
		workExampleIndices.setType("5");
		workExampleIndices.preInsert();
		dao.insert(workExampleIndices);
		workExampleIndices.setName("房屋装饰工程主要工料价格及消耗量指标");
		workExampleIndices.setOrderNum("20203");
		workExampleIndices.setParentIds(parentIds+id2+",");
		workExampleIndices.setParent(new WorkExampleIndices(id2));
		workExampleIndices.setType("6");
		workExampleIndices.preInsert();

		dao.insert(workExampleIndices);
		workExampleIndices.setName("电气工程经济指标");
		workExampleIndices.setOrderNum("20301");
		workExampleIndices.setParentIds(parentIds+id3+",");
		workExampleIndices.setParent(new WorkExampleIndices(id3));
		workExampleIndices.preInsert();
		workExampleIndices.setType("4");
		dao.insert(workExampleIndices);
		workExampleIndices.setName("电气工程主要工程量指标");
		workExampleIndices.setOrderNum("20302");
		workExampleIndices.setParentIds(parentIds+id3+",");
		workExampleIndices.setParent(new WorkExampleIndices(id3));
		workExampleIndices.setType("5");
		workExampleIndices.preInsert();
		dao.insert(workExampleIndices);
		workExampleIndices.setName("电气工程主要工料价格及消耗量指标");
		workExampleIndices.setOrderNum("20303");
		workExampleIndices.setParentIds(parentIds+id3+",");
		workExampleIndices.setParent(new WorkExampleIndices(id3));
		workExampleIndices.setType("6");
		workExampleIndices.preInsert();
		dao.insert(workExampleIndices);

		workExampleIndices.setName("建筑智能化安装工程经济指标");
		workExampleIndices.setOrderNum("20401");
		workExampleIndices.setParentIds(parentIds+id4+",");
		workExampleIndices.setParent(new WorkExampleIndices(id4));
		workExampleIndices.preInsert();
		workExampleIndices.setType("4");
		dao.insert(workExampleIndices);
		workExampleIndices.setName("建筑智能化安装工程主要工程量指标");
		workExampleIndices.setOrderNum("20402");
		workExampleIndices.setParentIds(parentIds+id4+",");
		workExampleIndices.setParent(new WorkExampleIndices(id4));
		workExampleIndices.setType("5");
		workExampleIndices.preInsert();
		dao.insert(workExampleIndices);
		workExampleIndices.setName("建筑智能化安装工程主要工料价格及消耗量指标");
		workExampleIndices.setOrderNum("20403");
		workExampleIndices.setParentIds(parentIds+id4+",");
		workExampleIndices.setParent(new WorkExampleIndices(id4));
		workExampleIndices.setType("6");
		workExampleIndices.preInsert();
		dao.insert(workExampleIndices);

		workExampleIndices.setName("通风空调工程经济指标");
		workExampleIndices.setOrderNum("20501");
		workExampleIndices.setParentIds(parentIds+id5+",");
		workExampleIndices.setParent(new WorkExampleIndices(id5));
		workExampleIndices.preInsert();
		workExampleIndices.setType("4");
		dao.insert(workExampleIndices);
		workExampleIndices.setName("通风空调工程主要工程量指标");
		workExampleIndices.setOrderNum("20502");
		workExampleIndices.setParentIds(parentIds+id5+",");
		workExampleIndices.setParent(new WorkExampleIndices(id5));
		workExampleIndices.setType("5");
		workExampleIndices.preInsert();
		dao.insert(workExampleIndices);
		workExampleIndices.setName("通风空调工程主要工料价格及消耗量指标");
		workExampleIndices.setOrderNum("20503");
		workExampleIndices.setParentIds(parentIds+id5+",");
		workExampleIndices.setParent(new WorkExampleIndices(id5));
		workExampleIndices.setType("6");
		workExampleIndices.preInsert();
		dao.insert(workExampleIndices);

		workExampleIndices.setName("消防工程经济指标");
		workExampleIndices.setOrderNum("20601");
		workExampleIndices.setParentIds(parentIds+id6+",");
		workExampleIndices.setParent(new WorkExampleIndices(id6));
		workExampleIndices.preInsert();
		workExampleIndices.setType("4");
		dao.insert(workExampleIndices);
		workExampleIndices.setName("消防工程主要工程量指标");
		workExampleIndices.setOrderNum("20602");
		workExampleIndices.setParentIds(parentIds+id6+",");
		workExampleIndices.setParent(new WorkExampleIndices(id6));
		workExampleIndices.setType("5");
		workExampleIndices.preInsert();
		dao.insert(workExampleIndices);
		workExampleIndices.setName("消防工程主要工料价格及消耗量指标");
		workExampleIndices.setOrderNum("20603");
		workExampleIndices.setParentIds(parentIds+id6+",");
		workExampleIndices.setParent(new WorkExampleIndices(id6));
		workExampleIndices.setType("6");
		workExampleIndices.preInsert();
		dao.insert(workExampleIndices);

		workExampleIndices.setName("给排水工程经济指标");
		workExampleIndices.setOrderNum("20701");
		workExampleIndices.setParentIds(parentIds+id7+",");
		workExampleIndices.setParent(new WorkExampleIndices(id7));
		workExampleIndices.preInsert();
		workExampleIndices.setType("4");
		dao.insert(workExampleIndices);
		workExampleIndices.setName("给排水工程主要工程量指标");
		workExampleIndices.setOrderNum("20702");
		workExampleIndices.setParentIds(parentIds+id7+",");
		workExampleIndices.setParent(new WorkExampleIndices(id7));
		workExampleIndices.setType("5");
		workExampleIndices.preInsert();
		dao.insert(workExampleIndices);
		workExampleIndices.setName("给排水工程主要工料价格及消耗量指标");
		workExampleIndices.setOrderNum("20703");
		workExampleIndices.setParentIds(parentIds+id7+",");
		workExampleIndices.setParent(new WorkExampleIndices(id7));
		workExampleIndices.setType("6");
		workExampleIndices.preInsert();
		dao.insert(workExampleIndices);

		workExampleIndices.setName("采暖工程经济指标");
		workExampleIndices.setOrderNum("20801");
		workExampleIndices.setParentIds(parentIds+id8+",");
		workExampleIndices.setParent(new WorkExampleIndices(id8));
		workExampleIndices.preInsert();
		workExampleIndices.setType("4");
		dao.insert(workExampleIndices);
		workExampleIndices.setName("采暖工程主要工程量指标");
		workExampleIndices.setOrderNum("20802");
		workExampleIndices.setParentIds(parentIds+id8+",");
		workExampleIndices.setParent(new WorkExampleIndices(id8));
		workExampleIndices.setType("5");
		workExampleIndices.preInsert();
		dao.insert(workExampleIndices);
		workExampleIndices.setName("采暖工程主要工料价格及消耗量指标");
		workExampleIndices.setOrderNum("20803");
		workExampleIndices.setParentIds(parentIds+id8+",");
		workExampleIndices.setParent(new WorkExampleIndices(id8));
		workExampleIndices.setType("6");
		workExampleIndices.preInsert();
		dao.insert(workExampleIndices);

		workExampleIndices.setName("燃气工程经济指标");
		workExampleIndices.setOrderNum("20901");
		workExampleIndices.setParentIds(parentIds+id9+",");
		workExampleIndices.setParent(new WorkExampleIndices(id9));
		workExampleIndices.preInsert();
		workExampleIndices.setType("4");
		dao.insert(workExampleIndices);
		workExampleIndices.setName("燃气工程主要工程量指标");
		workExampleIndices.setOrderNum("20902");
		workExampleIndices.setParentIds(parentIds+id9+",");
		workExampleIndices.setParent(new WorkExampleIndices(id9));
		workExampleIndices.setType("5");
		workExampleIndices.preInsert();
		dao.insert(workExampleIndices);
		workExampleIndices.setName("燃气工程主要工料价格及消耗量指标");
		workExampleIndices.setOrderNum("20903");
		workExampleIndices.setParentIds(parentIds+id9+",");
		workExampleIndices.setParent(new WorkExampleIndices(id9));
		workExampleIndices.setType("6");
		workExampleIndices.preInsert();
		dao.insert(workExampleIndices);

		workExampleIndices.setName("医疗气体工程经济指标");
		workExampleIndices.setOrderNum("21001");
		workExampleIndices.setParentIds(parentIds+id10+",");
		workExampleIndices.setParent(new WorkExampleIndices(id10));
		workExampleIndices.preInsert();
		workExampleIndices.setType("4");
		dao.insert(workExampleIndices);
		workExampleIndices.setName("医疗气体工程主要工程量指标");
		workExampleIndices.setOrderNum("21002");
		workExampleIndices.setParentIds(parentIds+id10+",");
		workExampleIndices.setParent(new WorkExampleIndices(id10));
		workExampleIndices.setType("5");
		workExampleIndices.preInsert();
		dao.insert(workExampleIndices);
		workExampleIndices.setName("医疗气体工程主要工料价格及消耗量指标");
		workExampleIndices.setOrderNum("21003");
		workExampleIndices.setParentIds(parentIds+id10+",");
		workExampleIndices.setParent(new WorkExampleIndices(id10));
		workExampleIndices.setType("6");
		workExampleIndices.preInsert();
		dao.insert(workExampleIndices);

	}

	@Transactional(readOnly = false)
	public void delete(WorkExampleIndices workExampleIndices) {
		super.delete(workExampleIndices);
	}
	@Transactional(readOnly = false)
	public void updateStatus(WorkExampleIndices workExampleIndices) {
		dao.updateStatus(workExampleIndices);
	}

	public List<WorkExampleIndices> findByName(WorkExampleIndices workExampleIndices) {
		return dao.findByName(workExampleIndices);
	}
	public List<WorkExampleIndices> find(WorkExampleIndices workExampleIndices) {
		return dao.find(workExampleIndices);
	}
	public List<WorkExampleIndices> findExampleIndices(String parentId) {
		return dao.findExampleIndices(parentId);
	}

	@Transactional(readOnly = false)
	public void deleteExampleIndices(String workExampleId,String exampleIndicesId) {
		dao.deleteExampleIndices(workExampleId,exampleIndicesId);
	}
}