PsndocTrainServiceImpl.java 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. package nc.impl.hi.psndoc;
  2. import java.lang.reflect.Array;
  3. import java.util.ArrayList;
  4. import java.util.Date;
  5. import java.util.List;
  6. import nc.bs.dao.BaseDAO;
  7. import nc.bs.dao.DAOException;
  8. import nc.bs.logging.Logger;
  9. import nc.hr.utils.InSQLCreator;
  10. import nc.hr.utils.ResHelper;
  11. import nc.hr.utils.SQLHelper;
  12. import nc.itf.hi.IPsndocTrainService;
  13. import nc.jdbc.framework.processor.BeanListProcessor;
  14. import nc.vo.hi.psndoc.TrainVO;
  15. import nc.vo.hi.wadoc.PsndocWadocVO;
  16. import nc.vo.pub.BusinessException;
  17. import nc.vo.uif2.LoginContext;
  18. import nccloud.commons.lang.ArrayUtils;
  19. public class PsndocTrainServiceImpl implements IPsndocTrainService {
  20. private final int PSNNAME = 1;
  21. private final int PSNCODE = 0;
  22. private BaseDAO baseDAO;
  23. public BaseDAO getBaseDAO() {
  24. if(baseDAO == null) {
  25. baseDAO = new BaseDAO();
  26. }
  27. return baseDAO;
  28. }
  29. @Override
  30. public TrainVO[] importData2DB(TrainVO[] trainVOs, LoginContext context)
  31. throws BusinessException {
  32. return extendInertVoinfo(trainVOs, context);
  33. }
  34. /**
  35. * 对导入的数据集进行分析处理<BR>
  36. * 1)判断导入数据的各项目是否合法<BR>
  37. * 合法:导入数据库<BR>
  38. * 非法:判断原因存储,回显给用户<BR>
  39. * 2)返回 导入后信息<BR>
  40. *
  41. * @author xuhw on 2010-4-21
  42. * @param psndocWadocVOs
  43. * @return
  44. * @throws BusinessException
  45. */
  46. private TrainVO[] extendInertVoinfo(TrainVO[] trainVOs, LoginContext context)
  47. throws BusinessException{
  48. // 数据合法的记录集合
  49. List<TrainVO> successImportList = new ArrayList<TrainVO>();
  50. // 不合法的记录集合
  51. List<TrainVO> failtureImportList = new ArrayList<TrainVO>();
  52. TrainVO aftProVO = null;
  53. if (ArrayUtils.isEmpty(trainVOs)) {
  54. return trainVOs;
  55. }
  56. int inttt = 0;
  57. for (TrainVO trainVO : trainVOs) {
  58. aftProVO = this.expandInertVOInfo(trainVO,context);
  59. if(aftProVO == null){
  60. //added by zengcheng 2012-07-12,没有查到人,则需要放入不合法的记录,一般都是因为非谈判薪酬,然后金额不符合级档的规定
  61. failtureImportList.add(aftProVO);
  62. continue;
  63. }
  64. if (aftProVO == null) {
  65. failtureImportList.add(trainVO);
  66. continue;
  67. }
  68. successImportList.add(aftProVO);
  69. }
  70. if(successImportList.size() > 0) {
  71. getBaseDAO().insertVOArray(successImportList.toArray(new TrainVO[0]));
  72. }
  73. return queryWaFailedReason(failtureImportList, context);
  74. }
  75. private TrainVO expandInertVOInfo(TrainVO trainVO, LoginContext context) throws BusinessException{
  76. StringBuffer sbSql = new StringBuffer();
  77. sbSql.append(" select ");
  78. sbSql.append(" "+ SQLHelper.getMultiLangNameColumn("bd_psndoc.name")+ " as psnName, ");
  79. sbSql.append(" bd_psndoc.code as psnCode, ");
  80. sbSql.append(" hi_psnorg.pk_psnorg,");
  81. sbSql.append(" hi_psnjob.pk_psnjob ");
  82. sbSql.append(" from ");
  83. sbSql.append(" bd_psndoc ");
  84. sbSql.append(" inner join hi_psnorg on bd_psndoc.pk_psndoc = hi_psnorg.pk_psndoc ");
  85. sbSql.append(" inner join hi_psnjob on hi_psnjob.pk_psndoc = bd_psndoc.pk_psndoc and hi_psnorg.pk_psnorg = hi_psnjob.pk_psnorg");
  86. sbSql.append(" where ");
  87. sbSql.append(" bd_psndoc.code = '").append(trainVO.getPsnCode()).append("' and ");
  88. sbSql.append(" hi_psnorg.indocflag = 'Y' and ");
  89. sbSql.append(" hi_psnorg.lastflag = 'Y' ");
  90. TrainVO[] trainVOs = this.executeQueryVOs(sbSql.toString());
  91. if(trainVOs != null && trainVOs.length > 0) {
  92. trainVO.setPk_psnjob(trainVOs[0].getPk_psnjob());
  93. trainVO.setPk_psnorg(trainVOs[0].getPk_psnorg());
  94. return trainVO;
  95. }
  96. return null;
  97. }
  98. /**
  99. * 查询理由<BR>
  100. * <BR>
  101. *
  102. * @author xuhw on 2010-4-22
  103. * @param failtureImportList
  104. * @param content
  105. * @return
  106. * @throws BusinessException
  107. */
  108. private TrainVO[] queryWaFailedReason(List<TrainVO> failtureImportList, LoginContext context)
  109. throws BusinessException{
  110. try {
  111. // 员工信息中无此员工编码的人员
  112. List<TrainVO> vNotInBdpsndocByCode = checkFailedInResult(failtureImportList, this
  113. .queryInBdpsndocByCode(failtureImportList, context));
  114. failtureImportList = new ArrayList<TrainVO>();
  115. failtureImportList.addAll(vNotInBdpsndocByCode);
  116. } catch (Exception ex) {
  117. throw new BusinessException(ex.getMessage(), ex);
  118. }
  119. return failtureImportList.toArray(new TrainVO[0]);
  120. }
  121. /**
  122. * 从结果中剔除已经能够判断错误原因的人员的人员
  123. *
  124. * @param results
  125. * 待确认错误原因的人员
  126. * @param inQueryResult
  127. * 已经存在的人员
  128. * @return 剔除了已经存在人员的结果
  129. */
  130. private List<TrainVO> checkFailedInResult(List<TrainVO> failtureImportList,
  131. TrainVO[] inQueryResult){
  132. List<TrainVO> psnReasonPersons = new ArrayList<TrainVO>();
  133. List<TrainVO> otherReasonPsn = new ArrayList<TrainVO>();
  134. int length = 0;
  135. if (!ArrayUtils.isEmpty(inQueryResult)) {
  136. length = inQueryResult.length;
  137. }
  138. for (int i = 0; i < failtureImportList.size(); i++) {
  139. Logger.debug(new Date() + " : checkFailedInResult ----> + " + i);
  140. TrainVO trainVO = failtureImportList.get(i);
  141. trainVO.setReason("员工信息中编码为[{"+trainVO.getPsnCode()+"}]的员工不存在!\n");
  142. trainVO.setError_flag(PSNCODE);
  143. psnReasonPersons.add(trainVO);
  144. for (int j = 0; j < length; j++) {
  145. String psncode = inQueryResult[j].getPsnCode();
  146. String psnName = inQueryResult[j].getPsnName();
  147. if (psncode.equals(trainVO.getPsnCode())) {
  148. if (!psnName.equals(trainVO.getPsnName())) {
  149. trainVO.setReason("员工信息中无姓名为[{"+trainVO.getPsnName()+"}]的员工不存在!\n");
  150. trainVO.setError_flag(PSNNAME);
  151. } else {
  152. psnReasonPersons.remove(trainVO);
  153. trainVO.setReason(null);
  154. otherReasonPsn.add(trainVO);
  155. }
  156. }
  157. }
  158. }
  159. failtureImportList.clear();//removeAll(failtureImportList);
  160. failtureImportList.addAll(otherReasonPsn);
  161. return psnReasonPersons;
  162. }
  163. /**
  164. * 查询人员编码确定的人是否在人员档案中
  165. *
  166. * @author xuhw on 2010-4-21
  167. * @param results
  168. * @param context
  169. * @return
  170. * @throws BusinessException
  171. * @throws Exception
  172. */
  173. public TrainVO[] queryInBdpsndocByCode(List<TrainVO> failtureImportList, LoginContext context) throws BusinessException
  174. {
  175. if (failtureImportList == null || failtureImportList.size() == 0)
  176. {
  177. return new TrainVO[0];
  178. }
  179. String in = new InSQLCreator().getInSQL(failtureImportList.toArray(new TrainVO[0]), TrainVO.PSNCODE);
  180. // List<CircularlyAccessibleValueObject[]> list = FormatVO.seperateValueObject(failtureImportList.toArray(new PsndocWadocVO[0]));
  181. // String in = "";
  182. // for (CircularlyAccessibleValueObject[] circularlyAccessibleValueObjects : list)
  183. // {
  184. // if(!StringUtils.isEmpty(in)){
  185. // in += ",";
  186. // }
  187. // in += FormatVO.formatArrayToString(circularlyAccessibleValueObjects, PsndocWadocVO.PSNCODE, "'");
  188. // }
  189. StringBuffer sbSql = new StringBuffer();
  190. sbSql.append(" select ");
  191. sbSql.append(" "+ SQLHelper.getMultiLangNameColumn("bd_psndoc.name")+ " as psnname, ");
  192. sbSql.append(" bd_psndoc.code as psncode ");
  193. sbSql.append(" from ");
  194. sbSql.append(" bd_psndoc ");
  195. sbSql.append(" inner join hi_psnorg on bd_psndoc.pk_psndoc = hi_psnorg.pk_psndoc ");
  196. sbSql.append(" where ");
  197. sbSql.append(" bd_psndoc.code in (").append(in).append(") and ");
  198. //sbSql.append(" bd_psndoc.pk_org = '").append(context.getPk_org()).append("' and ");
  199. //sbSql.append(" bd_psndoc.pk_group = '").append(context.getPk_group()).append("' and "); //跨集团兼职人员定调资数据无法导入
  200. sbSql.append(" hi_psnorg.indocflag = 'Y' and ");
  201. // sbSql.append(" hi_psnorg.endflag = 'N' and ");
  202. sbSql.append(" hi_psnorg.lastflag = 'Y' ");
  203. return this.executeQueryVOs(sbSql.toString());
  204. }
  205. public TrainVO[] executeQueryVOs(String sql) throws DAOException {
  206. List<TrainVO> list = (List)getBaseDAO().executeQuery(sql, new BeanListProcessor(TrainVO.class));
  207. if (list == null || list.size() == 0) {
  208. return (TrainVO[])(Object[])Array.newInstance(TrainVO.class, 0);
  209. }
  210. return (TrainVO[])list.toArray((Object[])Array.newInstance(TrainVO.class, list.size()));
  211. }
  212. }