package cn.com.countrygarden.bi.main.service.sharppathevaluation.impl;

import cn.com.countrygarden.bi.main.model.PageData;
import cn.com.countrygarden.bi.main.model.dup.DupOrgan;
import cn.com.countrygarden.bi.main.model.personnel.Personnel;
import cn.com.countrygarden.bi.main.model.personnel.PersonnelTag;
import cn.com.countrygarden.bi.main.model.sharppathevaluation.PersonnelSharppathevaluation;
import cn.com.countrygarden.bi.main.service.personnel.PersonnelCommenService;
import cn.com.countrygarden.bi.main.service.sharppathevaluation.PersonnelSharppathevaluationService;
import cn.com.countrygarden.bi.main.util.ExcelCommon;

import com.alibaba.fastjson.JSONArray;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import static org.hamcrest.CoreMatchers.nullValue;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.servlet.http.HttpServletResponse;
import javax.transaction.Transactional;
import org.apache.commons.collections.CollectionUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import cn.com.countrygarden.bi.main.core.Result;
import cn.com.countrygarden.bi.main.dao.performance.bdpsndocMapper;
import cn.com.countrygarden.bi.main.dao.performance.hipsnjobMapper;
import cn.com.countrygarden.bi.main.dao.personnel.PersonnelAdvisorMapper;
import cn.com.countrygarden.bi.main.dao.personnel.PersonnelMapper;
import cn.com.countrygarden.bi.main.dao.personnel.PersonnelTagMapper;
import cn.com.countrygarden.bi.main.dao.sharppathevaluation.PersonnelSharppathevaluationMapper;
import cn.com.countrygarden.bi.main.dto.PersonInfoVO;
import cn.com.countrygarden.bi.main.dto.PersonnelWrittenexaminationVO;
import cn.com.countrygarden.bi.main.dto.personnel.QueryCriteriaDTO;
import cn.com.countrygarden.bi.main.dto.sharppathevaluation.PersonnelSharppathevaluationDTO;
import cn.com.countrygarden.bi.main.exception.ServiceException;
import cn.com.countrygarden.bi.main.model.AccessToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import tk.mybatis.mapper.entity.Condition;
import cn.com.countrygarden.bi.main.core.Response;

/**
 * 锐途测评-业务逻辑层实现
 *
 * @author 汤婷
 * @email www.justintoforest@gamail.com
 * @url
 * @date 2018-09-25
 */
@Service
@Transactional
public class PersonnelSharppathevaluationServiceImpl implements PersonnelSharppathevaluationService {
	@Autowired
	private PersonnelSharppathevaluationMapper personnelSharppathevaluationMapper;
	@Autowired
	private bdpsndocMapper bdpsndocMapper;

	@Autowired
	private PersonnelMapper personnelMapper;

	@Autowired
	private PersonnelTagMapper personnelTagMapper;

	@Autowired
	private ExcelCommon excelCommon;
	
	 @Autowired
	    private PersonnelAdvisorMapper personnelAdvisorMapper;

	@Autowired
	private hipsnjobMapper hiPsnjobMapper;
	@Autowired
	private PersonnelCommenService personnelCommenService;

	public Result queryById(PersonnelSharppathevaluation personnelSharppathevaluation) {

		return Response.response(personnelSharppathevaluationMapper.PersonnelSharppathevaluationAll(
				personnelSharppathevaluation.getPersonnelId(), personnelSharppathevaluation.getPersonneltagId()));
	}

	public Result editOrAdd(PersonnelSharppathevaluation personnelSharppathevaluation, AccessToken accessToken) {
		personnelSharppathevaluation.setFlag(0);
		if (personnelSharppathevaluation.getId() == null) {
			personnelSharppathevaluation.setCreatedBy(accessToken.getUserCode());
			personnelSharppathevaluation.setCreatedDate(new Date());
			return Response.response(personnelSharppathevaluationMapper.insertSelective(personnelSharppathevaluation));
		} else {
			personnelSharppathevaluation.setUpdatedBy(accessToken.getUserCode());
			personnelSharppathevaluation.setUpdatedDate(new Date());

			return Response.response(
					personnelSharppathevaluationMapper.updateByPrimaryKeySelective(personnelSharppathevaluation));
		}

	}

	@Override
	public Result del(Integer id) {
		PersonnelSharppathevaluation personnelSharppathevaluation = personnelSharppathevaluationMapper
				.selectByPrimaryKey(id);
		personnelSharppathevaluation.setFlag(1);
		int count = personnelSharppathevaluationMapper.updateByPrimaryKeySelective(personnelSharppathevaluation);
		return Response.response(count);
	}

	@Override
	public Result exportExcel(String fileName, MultipartFile uploadfile, Integer radio, AccessToken accessToken) {
    	//List<String> liuserquyu=personnelCommenService.findErpRegionByUserCode(accessToken.getUserCode());

		Workbook xwb = null;
		BufferedInputStream bf = null;
		Sheet sheet = null;
		List<PersonnelSharppathevaluation> sharppathevaluationAddList = null;
		List<PersonnelSharppathevaluation> sharppathevaluationUpdateList = null;

		List<String> personnelNumberExistList = null;
		List<Personnel> PersonnelCodeNoExistList = null;
		List<PersonnelTag> tagList = new ArrayList<PersonnelTag>();
		try {
			bf = new BufferedInputStream(uploadfile.getInputStream());

			if (fileName.endsWith("xls")) { // Excel&nbsp;2003
				xwb = new HSSFWorkbook(bf);
			} else if (fileName.endsWith("xlsx")) { // Excel 2007/2010
				xwb = new XSSFWorkbook(bf);
			}
			sheet = xwb.getSheetAt(0);// 获取第几个页面0开始
			// 存放添加数据
			sharppathevaluationAddList = new LinkedList<PersonnelSharppathevaluation>();
			// 存放更新数据
			sharppathevaluationUpdateList = new LinkedList<PersonnelSharppathevaluation>();

			Personnel personnel = null;
			PersonnelTag personnelTag = null;
			PersonnelTag personnelTagIsRepeat = null;
			PersonnelSharppathevaluation personnelSharppathevaluation = null;
			Condition condition = null;
			int number = 0;
			for (int i = 3; i <= sheet.getLastRowNum(); i++) {
				System.out.println(sheet.getLastRowNum());
				Row row = sheet.getRow(i);
				if (row == null) {

					continue;
				}
				if (!excelCommon.isRowNotEmpty(row)) {
					System.out.println("空");
					continue;
				}
				// 怎么判断是否为结束的字段.(是否为合并单元格;

				if (row.getCell(0) == null) {
					return Response.response("第" + (i + 1) + "行，序列号为空,导入失败。");
				} else if (row.getCell(1) == null) {
					return Response.response("第" + (i + 1) + "行，人员编号为空,导入失败。");
				} else if (row.getCell(2) == null) {
					return Response.response("第" + (i + 1) + "行，人员姓名为空,导入失败。");
				} else if (row.getCell(3) == null) {
					return Response.response("第" + (i + 1) + "行，人员标签为空,添加失败。");
				} else if (row.getCell(4) == null) {
					return Response.response("第" + (i + 1) + "行，评估时间为空,添加失败。");
				} else {
					number++;
					XSSFCell cell1 = null;
					cell1 = (XSSFCell) row.getCell(1);// 0.
					cell1.setCellType(CellType.STRING);
					String userId = cell1.getStringCellValue();				
					cell1 = (XSSFCell) row.getCell(2);// 0.
					cell1.setCellType(CellType.STRING);
					String name = cell1.getStringCellValue();
					personnel = new Personnel();
					personnel = bdpsndocMapper.findByPersonInfoByCodeOrName(userId, name);
					cell1 = (XSSFCell) row.getCell(3);// 0.
					cell1.setCellType(CellType.STRING);
					String identity = cell1.getStringCellValue();
					if (personnel == null) {
						return Response.response("第" + (i + 1) + "行用户编号为:"+userId+"+姓名在员工信息数据或工作记录数据不存在,导入失败。");

					} else {
						condition = new Condition(Personnel.class);
						condition.createCriteria().andEqualTo("userId", personnel.getUserId()).andEqualTo("name",
								personnel.getName());

						List<Personnel> personnelOne = personnelMapper.selectByCondition(condition);

						condition = new Condition(PersonnelTag.class);
						condition.createCriteria().andEqualTo("userId", personnel.getUserId()).andEqualTo("identity",
								identity);
						List<PersonnelTag> personnelTagList = personnelTagMapper.selectByCondition(condition);

						if (personnelOne.size() < 1) {
							personnel.setCreatedBy(accessToken.getUserCode());
							personnel.setCreatedDate(new Date());
							personnelMapper.insertSelective(personnel);
						} else {
							personnel = personnelOne.get(0);
						}
						
//						  String userquyu=liuserquyu.get(0);
//	        			   String findboolean=personnelCommenService.findboolean(accessToken,personnel.getUserId(),null,userquyu);
//	                      
//	        			   if (findboolean.equals("role")||findboolean.equals("0")) {                	
//	                   		   throw new ServiceException("序号:"+(i-2)+"的用户编号:"+personnel.getUserId()+",导入权限不足，导入失败");                
//	          			
//	   				       }else if (findboolean.equals("gj_admin")) {
//	   				    	   userquyu=null; 
//						   }else if (findboolean.equals("gj_Area")) {
//							   userquyu=liuserquyu.get(0);
//						    }else if (personnelCommenService.findboolean(accessToken,null,identity,null).equals("identitys")) {
//							   userquyu=null; 
//							  
//						    }
						
						Map<String, Object> rolesMap = personnelCommenService.findRoleInfoMap(accessToken.getUserCode());    	
				    	//String userquyu=null;
				    	List<String> userquyu= new ArrayList<>();
				    	
				    	List<DupOrgan> result=null;
				    	for (Object obj : rolesMap.keySet()) {
				    		String key = (String) obj;
				    		if (key.equals("gj_admin")) {
				    			 userquyu=null;
				    			 List<PersonInfoVO> personInfoCodeOrId=personnelAdvisorMapper.selectByPersonInfoByCodeOrName(userId,null,null);
				    			 if (personInfoCodeOrId.size()==0) {
		                   				throw new ServiceException("用户编号" + userId + "有误或权限不足，无法添加");
									}
				    			 rolesMap.put("identitys", null);
				    			 break;
				    		}else if (key.equals("role")) {
				    			 return null;
							}else if (key.equals("gj_Area")) {
								rolesMap.put("identitys", null);
								
								 result = personnelCommenService.findDupCommByUserCode(accessToken.getUserCode(),null,true);
								for (int q = 0; q < result.size(); q++) {
									userquyu.add(result.get(q).getOrganName());
								}
								
							}
				    		List<PersonInfoVO> personInfoCodeOrId=personnelAdvisorMapper.selectByPersonInfoByCodeOrName(userId,null,userquyu);
				    		if (personInfoCodeOrId.size()==0) {
                   				throw new ServiceException("用户编号" + userId + "有误或权限不足，无法添加");
							}
							}
				   
						// 处理excel里的数据是否有重复
						personnelTagIsRepeat = new PersonnelTag();
						// 处理标签
						if (personnelTagList.size() < 1) {
							// 1.用户编号+标签没有查到时
							return Response.response("第" + (i + 1) + "行用户编号为:"+userId+"的人员标签不存在,导入失败。");

						} else {
							personnelTag = personnelTagList.get(0);
							personnelTagIsRepeat.setUserId(personnelTag.getUserId());
							personnelTagIsRepeat.setIdentity(personnelTag.getIdentity());
						}
						tagList.add(personnelTagIsRepeat);
						// 处理excel页面重复用户编号，用户标签，用户姓名 的数据
						Set<PersonnelTag> set = new HashSet<PersonnelTag>(tagList);
						if (set.size() != tagList.size()) {
							return Response.response("第" + (i + 1) + "行用户编号为:"+userId+"的编号+姓名+标签在excel中重复数据,导入失败。");
						}

						personnelSharppathevaluation = new PersonnelSharppathevaluation();
						personnelSharppathevaluation.setPersonnelId(personnel.getId());
						personnelSharppathevaluation.setPersonneltagId(personnelTag.getId());
						personnelSharppathevaluation.setFlag(0);
						List<PersonnelSharppathevaluation> list = personnelSharppathevaluationMapper
								.select(personnelSharppathevaluation);
						// 数据已经存在的情况下处理
						if (list.size() > 0) {
							// raido==0跳过，不添加，1：覆盖原数据
							if (radio == 1) {
								personnelSharppathevaluation.setId(list.get(0).getId());
								personnelSharppathevaluation.setUpdatedBy(accessToken.getUserCode());
								personnelSharppathevaluation.setUpdatedDate(new Date());
								if (ExcelAddPersonnelSharppathevaluation(personnelSharppathevaluation, row) != null) {
									sharppathevaluationUpdateList.add(
											ExcelAddPersonnelSharppathevaluation(personnelSharppathevaluation, row));
								}
							}
							// 数据不存在的情况下正常添加
						} else {
							personnelSharppathevaluation.setCreatedBy(accessToken.getUserCode());
							personnelSharppathevaluation.setCreatedDate(new Date());
							if (ExcelAddPersonnelSharppathevaluation(personnelSharppathevaluation, row) != null) {
								sharppathevaluationAddList
										.add(ExcelAddPersonnelSharppathevaluation(personnelSharppathevaluation, row));
							}
						}

					}
				}

			}

			if (CollectionUtils.isNotEmpty(sharppathevaluationAddList)) {
				// 处理新增数据
				int Count = personnelSharppathevaluationMapper.insertList(sharppathevaluationAddList);

				if (sharppathevaluationAddList.size() != Count) {
					try {
						throw new ServiceException("导入失败！");
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			}

			if (CollectionUtils.isNotEmpty(sharppathevaluationUpdateList)) {
				for (PersonnelSharppathevaluation per : sharppathevaluationUpdateList) {
					if (personnelSharppathevaluationMapper.updateByPrimaryKeySelective(per) < 1) {
						throw new ServiceException("导入失败！");
					}
				}
			}
			if (number == 0) {
				return Response.response("没有数据导入");
			}
		} catch (IOException e1) {
			e1.printStackTrace();
			throw new ServiceException("导入失败！请稍后重试！");
		}

		return Response.response("导入成功");

	}

	public PersonnelSharppathevaluation ExcelAddPersonnelSharppathevaluation(
			PersonnelSharppathevaluation personnelSharppathevaluation, Row row) {

		int j = 4;

		try {
			XSSFCell cell = null;

			// 时间
			cell = (XSSFCell) row.getCell(j++);// 0.

			SimpleDateFormat dateformat = new SimpleDateFormat("yyyy/MM/dd");

			try {
				personnelSharppathevaluation.setAdditionTime(dateformat.parse(excelCommon.getDate(cell, "yyyy/MM/dd")));
			} catch (ParseException e) {

				throw new ServiceException("第" + (row.getRowNum() + 1) + "行时间格式不符合规范，导入失败");
			}
			// 3.综合评价-综合指数
			cell = (XSSFCell) row.getCell(j++);// 0.
			cell.setCellType(CellType.STRING);
			personnelSharppathevaluation
					.setCompositeindex(cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
									: Double.parseDouble(cell.getStringCellValue()));

			// 4.综合评价-推理能力

			cell = (XSSFCell) row.getCell(j++);// 0.
			cell.setCellType(CellType.STRING);
			personnelSharppathevaluation.setInferentialcapability(
					cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
									: Double.parseDouble(cell.getStringCellValue()));
			// 5.综合评价-管理个性
			cell = (XSSFCell) row.getCell(j++);// 0.
			cell.setCellType(CellType.STRING);
			personnelSharppathevaluation.setManagementpersonality(
					cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			// 6.综合评价-管理技能
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			System.out.println("j" + j);
			personnelSharppathevaluation.setManagerialskills(
					cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			// 7.综合评价-星级推荐
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.

			personnelSharppathevaluation.setStarrecommendation(
					cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: cell.getStringCellValue());
			// 8.综合评价-综合评价
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.

			personnelSharppathevaluation.setOverallmerit(cell.getStringCellValue());
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation.setCominformunderstanding(
					cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));

			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation.setCriticalevaluation(
					cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			System.out.println(j);
			personnelSharppathevaluation.setStrategicreasoning(
					cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation.setConceptualreasoning(
					cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation.setGeneraldescription(cell.getStringCellValue());
			// TODO 时长需要做特殊处理
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation
					.setCsAnswerTime(cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation
					.setWishsuccess(cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation
					.setPowermotive(cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation.setAffiliationmotive(
					cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation
					.setVigour(cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation
					.setInnovation(cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation
					.setInsight(cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation
					.setMakedecision(cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation
					.setReason(cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation
					.setOptimistic(cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation.setCompressionresistance(
					cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation.setEmotionalstability(
					cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation
					.setAdaptability(cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);
			// 管理个性-社交自信
			personnelSharppathevaluation.setSocialconfidence(
					cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);
			// 管理个性-影响的
			personnelSharppathevaluation
					.setInfluencing(cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);
			// 管理个性-同理心
			personnelSharppathevaluation
					.setEmpathy(cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);
			// 管理个性-支持性
			personnelSharppathevaluation
					.setSupport(cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);
			// 管理个性-责任感.
			personnelSharppathevaluation
					.setResponsibility(cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);
			// 管理个性-审慎的
			personnelSharppathevaluation
					.setCareful(cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);
			// 管理个性-条理性
			personnelSharppathevaluation
					.setLogic(cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);
			// 管理个性-意志力
			personnelSharppathevaluation
					.setPsychokinesis(cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			System.out.println("j++:" + j);
			// 管理个性-总分
			personnelSharppathevaluation
					.setManTotalpoints(cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			// 管理个性-总体描述
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation.setManGeneraldescription(cell.getStringCellValue());
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation
					.setManAnswerTime(cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation.setPlanningmanagement(
					cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation.setOrganizationalmanant(
					cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation.setLeadershipmanagement(
					cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation.setControlmanagement(
					cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation.setStrategicunderstanding(
					cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation
					.setGoalsetting(cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation.setPlanningarrangements(
					cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation
					.setTimemanagement(cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation
					.setTasking(cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation
					.setAuthorization(cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation
					.setTeammanagement(cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation.setJudgementdecision(
					cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation
					.setIncentivedrive(cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation.setTrainsubordinates(
					cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation
					.setCommunication(cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation.setRelationshipmanagement(
					cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation.setMonitoringfeedback(
					cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation.setStrainregulation(
					cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation.setPerformancemanaent(
					cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation.setMskGeneraldescriptionc(cell.getStringCellValue());
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation
					.setMskAnswerTime(cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation.setTechnicalfunction(
					cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation
					.setManagementype(cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation.setCreativeentreprenship(
					cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation
					.setSafetytability(cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation
					.setChallengetype(cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation
					.setServicetype(cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation
					.setLivingform(cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation
					.setLndependentType(cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation.setOccupationalanchor(cell.getStringCellValue());
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation
					.setOccAnswerTime(cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation.setRelationaldimension(
					cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation
					.setTaskdimension(cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation.setManagementstyletype(cell.getStringCellValue());
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation
					.setMstAnswerTime(cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation
					.setLovecommitment(cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation
					.setIdealcommitment(cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation
					.setNormcommitment(cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation.setOpportunitycommitment(
					cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation
					.setOrgTotalpoints(cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			cell = (XSSFCell) row.getCell(j++);
			cell.setCellType(CellType.STRING);// 0.
			personnelSharppathevaluation
					.setOrgAnswerTime(cell.getStringCellValue().equals("") || cell.getStringCellValue() == null ? null
							: Double.parseDouble(cell.getStringCellValue()));
			personnelSharppathevaluation.setFlag(0);
		} catch (NumberFormatException e) {

			throw new ServiceException("第" + (row.getRowNum() + 1) + "行，第" + j + "列人只能是数字,导入失败。");

		}
		return personnelSharppathevaluation;

	}

	public Result importExcel(QueryCriteriaDTO queryCriteriaDTO, AccessToken accessToken, HttpServletResponse response)
			throws IOException {
		if (queryCriteriaDTO.getPersonnelIds() != null) {
			String[] personnelId = queryCriteriaDTO.getPersonnelIds().split(",");
			queryCriteriaDTO.setPersonnelId(personnelId);
		}
		// excel模板路径
		String path = "";
		try {
			path = this.getClass().getClassLoader().getResource("/").toURI().getPath() + "/excel/锐途测评导出模板.xlsx";
		} catch (URISyntaxException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		File fi = new File(path);
		InputStream in = new FileInputStream(fi);
		// 读取excel模板
		XSSFWorkbook wb = new XSSFWorkbook(in);
		// 读取excel模板

		XSSFSheet sheet1 = wb.getSheetAt(0);
		importPersonnelSharppathevaluationData(queryCriteriaDTO, sheet1, accessToken);

		excelCommon.downloadExcel(wb, "锐途测评明细", response);
		return null;
	}

	public void importPersonnelSharppathevaluationData(QueryCriteriaDTO queryCriteriaDTO, XSSFSheet sheet,
			AccessToken accessToken) {
		Map<String, Object> rolesMap = personnelCommenService.findRoleInfoMap(accessToken.getUserCode());    	
        List<String> userquyu= new ArrayList<>();
		
    	List<DupOrgan> result=null;
    	
    	for (Object obj : rolesMap.keySet()) {
    		String key = (String) obj;
    		if (key.equals("gj_admin")) {
    			 userquyu=null;
    			 rolesMap.put("identitys", null);
    			 break;
    		}else if (key.equals("role")) {
    			 userquyu=null;
    			 rolesMap.put("identitys", null);
    			 break;
			}else if (key.equals("gj_Area")) {
				//List<String> liuserquyu=personnelCommenService.findErpRegionByUserCode(accessToken.getUserCode());
				//userquyu=liuserquyu.get(0);
				 rolesMap.put("identitys", null);
				 result = personnelCommenService.findDupCommByUserCode(accessToken.getUserCode(),null,true);
					for (int i = 0; i < result.size(); i++) {
						userquyu.add(result.get(i).getOrganName());
					}
			}
    		
    	}
		
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
		List<PersonnelSharppathevaluationDTO> list = new ArrayList<PersonnelSharppathevaluationDTO>();

		List<PersonnelSharppathevaluationDTO> allList = personnelSharppathevaluationMapper
				.importPersonnelSharppathevaluationData2(queryCriteriaDTO, rolesMap);
		List<PersonnelSharppathevaluationDTO> newList = null;
		if (queryCriteriaDTO.getIs_all() != null && queryCriteriaDTO.getIs_all() == 0) {
			newList = this.selectSharppathevaluationNewest(rolesMap);
		}
		if (newList != null && newList.size() > 0) {
			for (PersonnelSharppathevaluationDTO dto : allList) {
				for (PersonnelSharppathevaluationDTO newDTO : newList) {
					if (dto.getPersonnelId().equals(newDTO.getPersonnelId())
							&& sdf.format(dto.getAdditionTime()).equals(sdf.format(newDTO.getAdditionTime()))) {
						list.add(dto);
					}
				}
			}
		} else {
			list.addAll(allList);
		}

		int count = 2;
		int copyRow = 3;
		int flag = 0;
		for (PersonnelSharppathevaluationDTO dto : list) {
			excelCommon.copyRows(sheet, 3, 3, copyRow);

			copyRow++;
			count++;

			DateFormat dFormat = new SimpleDateFormat("yyyy/MM/dd"); // HH表示24小时制；
			XSSFCell cell = null;
			int num = 0;
			cell = sheet.getRow(count).getCell(num++);// 序号
			cell.setCellValue(count - 2);
			cell = sheet.getRow(count).getCell(num++);// 区域
			cell.setCellValue(dto.getRegionName());
			cell = sheet.getRow(count).getCell(num++);// 人员编号
			cell.setCellValue(dto.getUserId());
			cell = sheet.getRow(count).getCell(num++);// 人员姓名
			cell.setCellValue(dto.getPersonnelName());
			cell = sheet.getRow(count).getCell(num++);// 标签
			cell.setCellValue(dto.getPersonnelTagIdentity());
			cell = sheet.getRow(count).getCell(num++);// 时间
			cell.setCellValue(dFormat.format(dto.getAdditionTime()));

			if (dto.getCompositeindex() != null) {
				cell = sheet.getRow(count).getCell(num++);// 综合评价-综合指数
				cell.setCellValue(dto.getCompositeindex());
			} else {
				num++;// 综合评价-综合指数
			}

			if (dto.getInferentialcapability() != null) {
				cell = sheet.getRow(count).getCell(num++);// 综合评价-推理能力
				cell.setCellValue(dto.getInferentialcapability());
			} else {
				num++;
			}
			if (dto.getManagementpersonality() != null) {
				cell = sheet.getRow(count).getCell(num++);// 综合评价-管理个性
				cell.setCellValue(dto.getManagementpersonality());
			} else {
				num++;
			}

			if (dto.getManagerialskills() != null) {
				cell = sheet.getRow(count).getCell(num++);// 综合评价-管理技能
				cell.setCellValue(dto.getManagerialskills());
			} else {
				num++;
			}
			if (dto.getStarrecommendation() != null) {
				cell = sheet.getRow(count).getCell(num++);// 综合评价-星级推荐
				cell.setCellValue(dto.getStarrecommendation());
			} else {
				num++;
			}

			if (dto.getOverallmerit() != null) {
				cell = sheet.getRow(count).getCell(num++);// 综合评价-综合评价
				cell.setCellValue(dto.getOverallmerit());
			} else {
				num++;
			}
			if (dto.getCominformunderstanding() != null) {
				cell = sheet.getRow((count)).getCell(num++);// 商业综合-复杂信息理解
				cell.setCellValue(dto.getCominformunderstanding());
			} else {
				num++;
			}
			if (dto.getCriticalevaluation() != null) {
				cell = sheet.getRow((count)).getCell(num++);// 商业综合-批判性评估
				cell.setCellValue(dto.getCriticalevaluation());
			} else {
				num++;
			}
			if (dto.getStrategicreasoning() != null) {
				cell = sheet.getRow((count)).getCell(num++);// 商业综合-策略性推理
				cell.setCellValue(dto.getStrategicreasoning());
			} else {
				num++;
			}
			if (dto.getConceptualreasoning() != null) {
				cell = sheet.getRow((count)).getCell(num++);// 商业综合-概念性推理
				cell.setCellValue(dto.getConceptualreasoning());
			} else {
				num++;
			}

			if (dto.getGeneraldescription() != null) {
				cell = sheet.getRow(count).getCell(num++);// 商业综合-总体描述
				cell.setCellValue(dto.getGeneraldescription());
			} else {
				num++;
			}
			if (dto.getCsAnswerTime() != null) {
				cell = sheet.getRow(count).getCell(num++);// 商业综合-作答时间
				cell.setCellValue(dto.getCsAnswerTime());
			} else {
				num++;
			}

			if (dto.getWishsuccess() != null) {
				cell = sheet.getRow(count).getCell(num++);// 管理个性-成功愿望
				cell.setCellValue(dto.getWishsuccess());
			} else {
				num++;
			}
			if (dto.getPowermotive() != null) {
				cell = sheet.getRow(count).getCell(num++);// 管理个性-权力动机
				cell.setCellValue(dto.getPowermotive());
			} else {
				num++;
			}
			if (dto.getAffiliationmotive() != null) {
				cell = sheet.getRow(count).getCell(num++);// 管理个性-亲和动机
				cell.setCellValue(dto.getAffiliationmotive());
			} else {
				num++;
			}
			if (dto.getVigour() != null) {
				cell = sheet.getRow(count).getCell(num++);// 管理个性-活力
				cell.setCellValue(dto.getVigour());
			} else {
				num++;
			}
			if (dto.getInnovation() != null) {
				cell = sheet.getRow(count).getCell(num++);// 管理个性-创新意识
				cell.setCellValue(dto.getInnovation());
			} else {
				num++;
			}
			if (dto.getInsight() != null) {
				cell = sheet.getRow(count).getCell(num++);// 管理个性-洞察力
				cell.setCellValue(dto.getInsight());
			} else {
				num++;
			}
			if (dto.getMakedecision() != null) {
				cell = sheet.getRow(count).getCell(num++);// 管理个性-决断的
				cell.setCellValue(dto.getMakedecision());
			} else {
				num++;
			}
			if (dto.getReason() != null) {
				cell = sheet.getRow(count).getCell(num++);// 管理个性-理性的
				cell.setCellValue(dto.getReason());
			} else {
				num++;
			}
			if (dto.getOptimistic() != null) {
				cell = sheet.getRow(count).getCell(num++);// 管理个性-乐观的
				cell.setCellValue(dto.getOptimistic());
			} else {
				num++;
			}
			if (dto.getCompressionresistance() != null) {
				cell = sheet.getRow(count).getCell(num++);// 管理个性-抗压性
				cell.setCellValue(dto.getCompressionresistance());
			} else {
				num++;
			}
			if (dto.getEmotionalstability() != null) {
				cell = sheet.getRow(count).getCell(num++);// 管理个性-情绪稳定性
				cell.setCellValue(dto.getEmotionalstability());
			} else {
				num++;
			}
			if (dto.getAdaptability() != null) {
				cell = sheet.getRow(count).getCell(num++);// 管理个性-适应性
				cell.setCellValue(dto.getAdaptability());
			} else {
				num++;
			}
			if (dto.getSocialconfidence() != null) {
				cell = sheet.getRow(count).getCell(num++);// 管理个性-社交自信
				cell.setCellValue(dto.getSocialconfidence());
			} else {
				num++;
			}
			if (dto.getInfluencing() != null) {
				cell = sheet.getRow(count).getCell(num++);// 管理个性-影响的
				cell.setCellValue(dto.getInfluencing());
			} else {
				num++;
			}
			if (dto.getEmpathy() != null) {
				cell = sheet.getRow(count).getCell(num++);// 管理个性-同理心
				cell.setCellValue(dto.getEmpathy());
			} else {
				num++;
			}
			if (dto.getSupport() != null) {
				cell = sheet.getRow(count).getCell(num++);// 管理个性-支持性
				cell.setCellValue(dto.getSupport());
			} else {
				num++;
			}
			if (dto.getResponsibility() != null) {
				cell = sheet.getRow(count).getCell(num++);// 管理个性-责任感
				cell.setCellValue(dto.getResponsibility());
			} else {
				num++;
			}
			if (dto.getCareful() != null) {
				cell = sheet.getRow(count).getCell(num++);// 管理个性-审慎的
				cell.setCellValue(dto.getCareful());
			} else {
				num++;
			}
			if (dto.getLogic() != null) {
				cell = sheet.getRow(count).getCell(num++);// 管理个性-条理性
				cell.setCellValue(dto.getLogic());
			} else {
				num++;
			}

			if (dto.getPsychokinesis() != null) {
				cell = sheet.getRow(count).getCell(num++);// 管理个性-意志力
				cell.setCellValue(dto.getPsychokinesis());
			} else {
				num++;
			}
			if (dto.getManTotalpoints() != null) {
				cell = sheet.getRow(count).getCell(num++);// 管理个性-总分
				cell.setCellValue(dto.getManTotalpoints());
			} else {
				num++;
			}
			if (dto.getManGeneraldescription() != null) {
				cell = sheet.getRow(count).getCell(num++);// 管理个性-总体描述
				cell.setCellValue(dto.getManGeneraldescription());
			} else {
				num++;
			}
			if (dto.getManAnswerTime() != null) {
				cell = sheet.getRow(count).getCell(num++);// 管理个性-作答时间（分钟）
				cell.setCellValue(dto.getManAnswerTime());
			} else {
				num++;
			}
			if (dto.getPlanningmanagement() != null) {
				cell = sheet.getRow(count).getCell(num++);// 管理技能-计划管理技能
				cell.setCellValue(dto.getPlanningmanagement());
			} else {
				num++;
			}
			if (dto.getOrganizationalmanant() != null) {
				cell = sheet.getRow(count).getCell(num++);// 管理技能-组织管理技能
				cell.setCellValue(dto.getOrganizationalmanant());
			} else {
				num++;
			}
			if (dto.getLeadershipmanagement() != null) {
				cell = sheet.getRow(count).getCell(num++);// 管理技能-领导管理技能
				cell.setCellValue(dto.getLeadershipmanagement());
			} else {
				num++;
			}
			if (dto.getControlmanagement() != null) {
				cell = sheet.getRow(count).getCell(num++);// 管理技能-控制管理技能
				cell.setCellValue(dto.getControlmanagement());
			} else {
				num++;
			}
			if (dto.getStrategicunderstanding() != null) {
				cell = sheet.getRow(count).getCell(num++);// 管理技能-战略理解与执行
				cell.setCellValue(dto.getStrategicunderstanding());
			} else {
				num++;
			}
			if (dto.getGoalsetting() != null) {
				cell = sheet.getRow(count).getCell(num++);// 管理技能-目标设置
				cell.setCellValue(dto.getGoalsetting());
			} else {
				num++;
			}
			if (dto.getPlanningarrangements() != null) {
				cell = sheet.getRow(count).getCell(num++);// 管理技能-规划安排
				cell.setCellValue(dto.getPlanningarrangements());
			} else {
				num++;
			}
			if (dto.getTimemanagement() != null) {
				cell = sheet.getRow(count).getCell(num++);// 管理技能-时间管理
				cell.setCellValue(dto.getTimemanagement());
			} else {
				num++;
			}
			if (dto.getTasking() != null) {
				cell = sheet.getRow(count).getCell(num++);// 管理技能-任务分配
				cell.setCellValue(dto.getTasking());
			} else {
				num++;
			}

			if (dto.getAuthorization() != null) {
				cell = sheet.getRow(count).getCell(num++);// 管理技能-授权管理
				cell.setCellValue(dto.getAuthorization());
			} else {
				num++;
			}
			if (dto.getTeammanagement() != null) {
				cell = sheet.getRow(count).getCell(num++);// 管理技能-团队管理
				cell.setCellValue(dto.getTeammanagement());
			} else {
				num++;
			}
			if (dto.getJudgementdecision() != null) {
				cell = sheet.getRow(count).getCell(num++);// 管理技能-决策判断
				cell.setCellValue(dto.getJudgementdecision());
			} else {
				num++;
			}
			if (dto.getIncentivedrive() != null) {
				cell = sheet.getRow(count).getCell(num++);// 管理技能-激励推动
				cell.setCellValue(dto.getIncentivedrive());
			} else {
				num++;
			}
			if (dto.getTrainsubordinates() != null) {
				cell = sheet.getRow(count).getCell(num++);// 管理技能-培养下属
				cell.setCellValue(dto.getTrainsubordinates());
			} else {
				num++;
			}
			if (dto.getCommunication() != null) {
				cell = sheet.getRow(count).getCell(num++);// 管理技能-沟通协调
				cell.setCellValue(dto.getCommunication());
			} else {
				num++;
			}
			if (dto.getRelationshipmanagement() != null) {
				cell = sheet.getRow(count).getCell(num++);// 管理技能-关系管理
				cell.setCellValue(dto.getRelationshipmanagement());
			} else {
				num++;
			}
			if (dto.getMonitoringfeedback() != null) {
				cell = sheet.getRow(count).getCell(num++);// 管理技能-监查反馈
				cell.setCellValue(dto.getMonitoringfeedback());
			} else {
				num++;
			}
			if (dto.getStrainregulation() != null) {
				cell = sheet.getRow(count).getCell(num++);// 管理技能-应变调控
				cell.setCellValue(dto.getStrainregulation());
			} else {
				num++;
			}
			if (dto.getPerformancemanaent() != null) {
				cell = sheet.getRow(count).getCell(num++);// 管理技能-绩效管理
				cell.setCellValue(dto.getPerformancemanaent());
			} else {
				num++;
			}
			if (dto.getMskGeneraldescriptionc() != null) {
				cell = sheet.getRow(count).getCell(num++);// 管理技能-总体特点描述
				cell.setCellValue(dto.getMskGeneraldescriptionc());
			} else {
				num++;
			}
			if (dto.getMskAnswerTime() != null) {
				cell = sheet.getRow(count).getCell(num++);// 管理技能-作答时间（分钟）
				cell.setCellValue(dto.getMskAnswerTime());
			} else {
				num++;
			}
			if (dto.getTechnicalfunction() != null) {
				cell = sheet.getRow(count).getCell(num++);// 职业锚-技术职能型
				cell.setCellValue(dto.getTechnicalfunction());
			} else {
				num++;
			}
			if (dto.getManagementype() != null) {
				cell = sheet.getRow(count).getCell(num++);// 职业锚-管理型
				cell.setCellValue(dto.getManagementype());
			} else {
				num++;
			}
			if (dto.getCreativeentreprenship() != null) {
				cell = sheet.getRow(count).getCell(num++);// 职业锚-创造创业型
				cell.setCellValue(dto.getCreativeentreprenship());
			} else {
				num++;
			}
			if (dto.getSafetytability() != null) {

				cell = sheet.getRow(count).getCell(num++);// 职业锚-安全稳定型
				cell.setCellValue(dto.getSafetytability());
			} else {
				num++;
			}
			if (dto.getChallengetype() != null) {

				cell = sheet.getRow(count).getCell(num++);// 职业锚-挑战型
				cell.setCellValue(dto.getChallengetype());
			} else {
				num++;
			}
			if (dto.getServicetype() != null) {
				cell = sheet.getRow(count).getCell(num++);// 职业锚-服务型
				cell.setCellValue(dto.getServicetype());
			} else {
				num++;
			}
			if (dto.getLivingform() != null) {
				cell = sheet.getRow(count).getCell(num++);// 职业锚-生活型
				cell.setCellValue(dto.getLivingform());
			} else {
				num++;
			}
			if (dto.getLndependentType() != null) {
				cell = sheet.getRow(count).getCell(num++);// 职业锚-自主独立型
				cell.setCellValue(dto.getLndependentType());
			} else {
				num++;
			}
			if (dto.getOccupationalanchor() != null) {
				cell = sheet.getRow(count).getCell(num++);// 职业锚-职业锚类型
				cell.setCellValue(dto.getOccupationalanchor());
			} else {
				num++;
			}
			if (dto.getOccAnswerTime() != null) {
				cell = sheet.getRow(count).getCell(num++);// 职业锚-作答时间（ 分钟）
				cell.setCellValue(dto.getOccAnswerTime());
			} else {
				num++;
			}
			if (dto.getRelationaldimension() != null) {
				cell = sheet.getRow(count).getCell(num++);// 管理风格-关系维度
				cell.setCellValue(dto.getRelationaldimension());
			} else {
				num++;
			}
			if (dto.getTaskdimension() != null) {
				cell = sheet.getRow(count).getCell(num++);// 管理风格-任务维度
				cell.setCellValue(dto.getTaskdimension());
			} else {
				num++;
			}
			if (dto.getManagementstyletype() != null) {
				cell = sheet.getRow(count).getCell(num++);// 管理风格-管理风格类型
				cell.setCellValue(dto.getManagementstyletype());
			} else {
				num++;
			}
			if (dto.getMstAnswerTime() != null) {
				cell = sheet.getRow(count).getCell(num++);// 管理风格-作答时间（分钟）
				cell.setCellValue(dto.getMstAnswerTime());
			} else {
				num++;
			}
			if (dto.getLovecommitment() != null) {
				cell = sheet.getRow(count).getCell(num++);// 组织忠诚度-情承诺
				cell.setCellValue(dto.getLovecommitment());
			} else {
				num++;
			}

			if (dto.getIdealcommitment() != null) {
				cell = sheet.getRow(count).getCell(num++);// 组织忠诚度-理想承诺
				cell.setCellValue(dto.getIdealcommitment());
			} else {
				num++;
			}
			if (dto.getNormcommitment() != null) {
				cell = sheet.getRow(count).getCell(num++);// 组织忠诚度-规范承诺
				cell.setCellValue(dto.getNormcommitment());
			} else {
				num++;
			}
			if (dto.getOpportunitycommitment() != null) {
				cell = sheet.getRow(count).getCell(num++);// 组织忠诚度-机会承诺
				cell.setCellValue(dto.getOpportunitycommitment());
			} else {
				num++;
			}
			if (dto.getOrgTotalpoints() != null) {
				cell = sheet.getRow(count).getCell(num++);// 组织忠诚度-总分
				cell.setCellValue(dto.getOrgTotalpoints());
			} else {
				num++;
			}
			if (dto.getOrgAnswerTime() != null) {
				cell = sheet.getRow(count).getCell(num++);// 组织忠诚度-作答时间（分钟）
				cell.setCellValue(dto.getOrgAnswerTime());
			} else {
				num++;
			}

		}

	}

	public Result queryPageList(PersonInfoVO personInfoVO, int page, int size, AccessToken accessToken) {
		Map<String, Object> rolesMap = personnelCommenService.findRoleInfoMap(accessToken.getUserCode());    	
        List<String> userquyu= new ArrayList<>();
		
    	List<DupOrgan> result=null;
    	
    	for (Object obj : rolesMap.keySet()) {
    		String key = (String) obj;
    		if (key.equals("gj_admin")) {
    			 userquyu=null;
    			 rolesMap.put("identitys", null);
    			 break;
    		}else if (key.equals("role")) {
    			return null;
			}else if (key.equals("gj_Area")) {
				//List<String> liuserquyu=personnelCommenService.findErpRegionByUserCode(accessToken.getUserCode());
				//userquyu=liuserquyu.get(0);
				 rolesMap.put("identitys", null);
				 result = personnelCommenService.findDupCommByUserCode(accessToken.getUserCode(),null,true);
					for (int i = 0; i < result.size(); i++) {
						userquyu.add(result.get(i).getOrganName());
					}
					
			}
    		
    	}   	
    	rolesMap.put("userquyu", userquyu);
		Page<PersonnelSharppathevaluationDTO> pageList = PageHelper.startPage(page, size);
	
		List<PersonnelSharppathevaluationDTO> list = personnelSharppathevaluationMapper
				.selectSharppathevaluationInfoMapRole(personInfoVO, rolesMap);
		if(list.size()<1) {
			return Response.response();
		}
		PageData data = new PageData(pageList);
		data.setData(pageList.getResult());
		return Response.response(data);

	}

	public List<PersonnelSharppathevaluationDTO> selectSharppathevaluationNewest(Map<String,Object> rolesMap) {

		List<PersonnelSharppathevaluationDTO> list = personnelSharppathevaluationMapper
				.selectSharppathevaluationNewest(null,rolesMap);
		return list;
	}

	@Override
	public Result delpiliang(String id) {

		List<String> shid = JSONArray.parseArray(id, String.class);
		
		personnelSharppathevaluationMapper.delpiliang(shid);
		return Response.response("删除成功");
	}

}