PersonnelServiceImpl.java 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. package com.goafanti.personnel.service.impl;
  2. import java.io.IOException;
  3. import java.io.OutputStream;
  4. import java.text.SimpleDateFormat;
  5. import java.util.ArrayList;
  6. import java.util.Date;
  7. import java.util.HashMap;
  8. import java.util.List;
  9. import java.util.Map;
  10. import javax.servlet.http.HttpServletResponse;
  11. import org.apache.poi.xssf.usermodel.XSSFCell;
  12. import org.apache.poi.xssf.usermodel.XSSFRow;
  13. import org.apache.poi.xssf.usermodel.XSSFSheet;
  14. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  15. import org.springframework.beans.factory.annotation.Autowired;
  16. import org.springframework.stereotype.Service;
  17. import com.alibaba.fastjson.JSON;
  18. import com.alibaba.fastjson.JSONArray;
  19. import com.goafanti.common.bo.Error;
  20. import com.goafanti.common.constant.AFTConstants;
  21. import com.goafanti.common.dao.AdminMapper;
  22. import com.goafanti.common.dao.PersonnelChooseMapper;
  23. import com.goafanti.common.dao.PersonnelContactMapper;
  24. import com.goafanti.common.dao.PersonnelContractMapper;
  25. import com.goafanti.common.dao.PersonnelDossierMapper;
  26. import com.goafanti.common.dao.PersonnelEntryMapper;
  27. import com.goafanti.common.dao.PersonnelLevelMapper;
  28. import com.goafanti.common.dao.PersonnelMidMapper;
  29. import com.goafanti.common.dao.PersonnelPromotionMapper;
  30. import com.goafanti.common.dao.PersonnelQuitMapper;
  31. import com.goafanti.common.dao.PersonnelWelfareMapper;
  32. import com.goafanti.common.error.BusinessException;
  33. import com.goafanti.common.model.Admin;
  34. import com.goafanti.common.model.PersonnelContact;
  35. import com.goafanti.common.model.PersonnelDossier;
  36. import com.goafanti.common.model.PersonnelEntry;
  37. import com.goafanti.common.model.PersonnelMid;
  38. import com.goafanti.common.model.PersonnelWelfare;
  39. import com.goafanti.common.utils.ExportExcelUtil;
  40. import com.goafanti.core.mybatis.BaseMybatisDao;
  41. import com.goafanti.core.mybatis.page.Pagination;
  42. import com.goafanti.core.shiro.token.TokenManager;
  43. import com.goafanti.personnel.bo.InputPersonnelBo;
  44. import com.goafanti.personnel.bo.InputPersonnelChooseBo;
  45. import com.goafanti.personnel.bo.InputPersonnelContactBo;
  46. import com.goafanti.personnel.bo.InputPersonnelContractBo;
  47. import com.goafanti.personnel.bo.InputPersonnelEntryBo;
  48. import com.goafanti.personnel.bo.InputPersonnelListBo;
  49. import com.goafanti.personnel.bo.InputPersonnelLvlBo;
  50. import com.goafanti.personnel.bo.InputPersonnelPromotionBo;
  51. import com.goafanti.personnel.bo.InputPersonnelQuitBo;
  52. import com.goafanti.personnel.bo.IntpersonnelWelfareBo;
  53. import com.goafanti.personnel.bo.OutPersonnelBo;
  54. import com.goafanti.personnel.bo.OutPersonnelListBo;
  55. import com.goafanti.personnel.bo.OutPersonnelLvlBo;
  56. import com.goafanti.personnel.service.PersonnelService;
  57. @Service
  58. public class PersonnelServiceImpl extends BaseMybatisDao<PersonnelDossierMapper> implements PersonnelService {
  59. @Autowired
  60. private PersonnelDossierMapper personnelDossierMapper;
  61. @Autowired
  62. private PersonnelContactMapper personnelContactMapper;
  63. @Autowired
  64. private PersonnelEntryMapper personnelEntryMapper;
  65. @Autowired
  66. private PersonnelPromotionMapper personnelPromotionMapper;
  67. @Autowired
  68. private PersonnelContractMapper personnelContractMapper;
  69. @Autowired
  70. private PersonnelChooseMapper personnelChooseMapper;
  71. @Autowired
  72. private PersonnelQuitMapper personnelQuitMapper;
  73. @Autowired
  74. private PersonnelLevelMapper personnelLevelMapper;
  75. @Autowired
  76. private PersonnelWelfareMapper personnelWelfareMapper;
  77. @Autowired
  78. private PersonnelMidMapper personnelMidMapper;
  79. @Autowired
  80. private AdminMapper adminMapper;
  81. @Override
  82. public int addPersonnel(InputPersonnelBo i) {
  83. if (TokenManager.hasRole(AFTConstants.SALESMAN_ADMIN)) {
  84. Admin a=adminMapper.selectByPrimaryKey(TokenManager.getAdminId());
  85. if (a!=null) {
  86. i.setCompany(a.getDepartmentId());
  87. }
  88. }
  89. return personnelDossierMapper.insertSelective(i);
  90. }
  91. @Override
  92. public int updatePersonnel(InputPersonnelBo i) {
  93. return personnelDossierMapper.updateByPrimaryKeySelective(i);
  94. }
  95. @Override
  96. public int updateContact(InputPersonnelContactBo i) {
  97. PersonnelDossier p=new PersonnelDossier();
  98. p.setId(i.getId());
  99. p.setMobile(i.getMobile());
  100. p.setFixedTel(i.getFixedTel());
  101. personnelDossierMapper.updateByPrimaryKeySelective(p);
  102. JSONArray ja = (JSONArray) JSON.parse(i.getContactList());
  103. List<PersonnelContact> list = new ArrayList<PersonnelContact>();
  104. if (ja != null && !ja.isEmpty()) {
  105. PersonnelContact pc = null;
  106. for (int idx = 0; idx < ja.size(); idx++) {
  107. pc = ja.getJSONObject(idx).toJavaObject(PersonnelContact.class);
  108. list.add(pc);
  109. }
  110. }
  111. for (PersonnelContact pc : list) {
  112. if (pc.getId()!=null) {
  113. personnelContactMapper.updateByPrimaryKeySelective(pc);
  114. }else {
  115. personnelContactMapper.insertSelective(pc);
  116. }
  117. }
  118. PersonnelContact pc =list.get(0);
  119. PersonnelMid m=new PersonnelMid();
  120. m.setId(i.getId());
  121. m.setEmergencyContact(pc.getEmergencyContact());
  122. m.setEmergencyMobile(pc.getEmergencyMobile());
  123. PersonnelMid pm=personnelMidMapper.selectByPrimaryKey(i.getId());
  124. if (pm==null||pm.getId()==null) {
  125. personnelMidMapper.insertSelective(m);
  126. }else {
  127. personnelMidMapper.updateByPrimaryKeySelective(m);
  128. }
  129. return 1;
  130. }
  131. @Override
  132. public int updateEntry(InputPersonnelEntryBo i) {
  133. PersonnelEntry p=personnelEntryMapper.selectByPrimaryKey(i.getId());
  134. if (p==null||p.getId()==null) {
  135. personnelEntryMapper.insertSelective(i);
  136. }else {
  137. personnelEntryMapper.updateByPrimaryKeySelective(i);
  138. }
  139. return 1;
  140. }
  141. @Override
  142. public int updatePromotion(InputPersonnelPromotionBo i) {
  143. if (i.getId()==null) {
  144. personnelPromotionMapper.insertSelective(i);
  145. }else {
  146. personnelPromotionMapper.updateByPrimaryKeySelective(i);
  147. }
  148. PersonnelMid p=new PersonnelMid();
  149. p.setId(i.getPdId());
  150. p.setPromotionRemarks(i.getPromotionRemarks());
  151. p.setPromotionTime(i.getPromotionTime());
  152. PersonnelMid pm=personnelMidMapper.selectByPrimaryKey(i.getPdId());
  153. if (pm==null||pm.getId()==null) {
  154. personnelMidMapper.insertSelective(p);
  155. }else {
  156. personnelMidMapper.updateByPrimaryKeySelective(p);
  157. }
  158. return 1;
  159. }
  160. @Override
  161. public int checkDoorId(Integer doorId,Integer id) {
  162. int i=personnelDossierMapper.checkDoorId(doorId,id);
  163. return i;
  164. }
  165. @Override
  166. public int checkEmployeeId(Integer employeeId,Integer id) {
  167. int i=personnelDossierMapper.checkEmployeeId(employeeId,id);
  168. return i;
  169. }
  170. @Override
  171. public int updateContract(InputPersonnelContractBo i) {
  172. if (i.getId()==null) {
  173. personnelContractMapper.insertSelective(i);
  174. } else {
  175. personnelContractMapper.updateByPrimaryKeySelective(i);
  176. }
  177. PersonnelMid p=new PersonnelMid();
  178. p.setId(i.getPdId());
  179. p.setContractStartTime(i.getStartTime());
  180. p.setContractEndTime(i.getEndTime());
  181. PersonnelMid pm=personnelMidMapper.selectByPrimaryKey(i.getPdId());
  182. if (pm==null||pm.getId()==null) {
  183. personnelMidMapper.insertSelective(p);
  184. }else {
  185. personnelMidMapper.updateByPrimaryKeySelective(p);
  186. }
  187. return 1;
  188. }
  189. @Override
  190. public int updateChoose(InputPersonnelChooseBo i) {
  191. if (i.getId()==null) {
  192. personnelChooseMapper.insertSelective(i);
  193. } else {
  194. personnelChooseMapper.updateByPrimaryKeySelective(i);
  195. }
  196. return 1;
  197. }
  198. @Override
  199. public int updateQuit(InputPersonnelQuitBo i) {
  200. if (i.getId()==null) {
  201. personnelQuitMapper.insertSelective(i);
  202. } else {
  203. personnelQuitMapper.updateByPrimaryKeySelective(i);
  204. }
  205. PersonnelMid p=new PersonnelMid();
  206. p.setId(i.getPdId());
  207. p.setQuitTime(i.getEffectTime());
  208. PersonnelMid pm=personnelMidMapper.selectByPrimaryKey(i.getPdId());
  209. if (pm==null||pm.getId()==null) {
  210. personnelMidMapper.insertSelective(p);
  211. }else {
  212. personnelMidMapper.updateByPrimaryKeySelective(p);
  213. }
  214. return 1;
  215. }
  216. @SuppressWarnings("unchecked")
  217. @Override
  218. public Pagination<OutPersonnelListBo> selectList(InputPersonnelListBo i) {
  219. Map<String, Object> params = new HashMap<>();
  220. if (i.getPageNo()==null||i.getPageNo()<1)i.setPageNo(1);
  221. if (i.getPageSize()==null||i.getPageSize()<1) i.setPageSize(10);
  222. params.put("i", i);
  223. if (TokenManager.hasRole(AFTConstants.SALESMAN_ADMIN)) {
  224. params.put("aid", TokenManager.getAdminId());
  225. }
  226. Pagination<OutPersonnelListBo>p=(Pagination<OutPersonnelListBo>) findPage("selectPersonnelByList", "selectPersonnelByCount",
  227. params, i.getPageNo(), i.getPageSize());
  228. return p;
  229. }
  230. @Override
  231. public OutPersonnelBo selectBypdId(Integer id) {
  232. OutPersonnelBo op= personnelDossierMapper.selectBypdId(id);
  233. op.setContactList(personnelContactMapper.selectBypdId(id));
  234. PersonnelEntry pe=personnelEntryMapper.selectByPrimaryKey(id);
  235. op.setPersonnelEntry(pe);
  236. op.setPromotionList(personnelPromotionMapper.selectBypdId(id));
  237. op.setContractList(personnelContractMapper.selectBypdId(id));
  238. op.setChooseList(personnelChooseMapper.selectBypdId(id));
  239. op.setQuitList(personnelQuitMapper.selectBypdId(id));
  240. op.setWelfareList(personnelWelfareMapper.selectBypdId(id));
  241. return op;
  242. }
  243. @SuppressWarnings("unchecked")
  244. @Override
  245. public void exportPersonnelList(HttpServletResponse response, InputPersonnelListBo in) throws IOException {
  246. OutputStream out = response.getOutputStream();
  247. try {
  248. List<OutPersonnelListBo>list=(List<OutPersonnelListBo>) selectList(in).getList();
  249. String[] comment = {"员工编号","门禁编号","姓名","员工状态","所属系统","所属公司","职位名称","等级名称","星级","入职时间","转正时间","出生日期","性别"
  250. ,"婚否","子女","政治面貌","学历","毕业学校","所学专业","职称/证书","晋升明细","最近晋升时间","合同","联系电话","办公室电话",
  251. "身份证号码","身份证发证地","户籍所在地","现住址","紧急联系人","紧急联系人电话","离职时间","工作年限","年龄","出生月份","参保时间","停保时间",
  252. "入公积金时间","停公积金时间"};
  253. String fileName ="人事档案表" + new SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date()) + ".xls";
  254. //type 0 变更
  255. XSSFWorkbook wb =ExportExcelUtil.exportTemplateInfoS(comment,"人事档案表");
  256. //根据列表编写文档
  257. XSSFSheet sheet =wb.getSheetAt(0);
  258. for (OutPersonnelListBo ob : (List<OutPersonnelListBo>)list) {
  259. //新增一行
  260. XSSFRow r = sheet.createRow(sheet.getLastRowNum()+1);
  261. for (int i = 0; i < comment.length; i++) {
  262. //当前列的只
  263. String o = "";
  264. switch (comment[i]) {
  265. // "员工编号","门禁编号","姓名","员工状态","所属系统","所属公司","职位名称","等级名称","星级","入职时间","转正时间","出生日期","性别"
  266. case "员工编号": o = ob.getEmployeeId()==null?"":ob.getEmployeeId().toString(); break;
  267. case "门禁编号": o = ob.getDoorId().toString(); break;
  268. case "姓名": o = ob.getName(); break;
  269. case "员工状态": o = ob.getStatusName(); break;
  270. case "所属系统": o = ob.getSystemName(); break;
  271. case "所属公司": o = ob.getDepName(); break;
  272. case "职位名称": o = ob.getJobsName(); break;
  273. case "等级名称": o = ob.getStarName(); break;
  274. case "星级": o = ob.getLvlName(); break;
  275. case "入职时间": o = ob.getEntryTimes(); break;
  276. case "转正时间": o = ob.getPromotionTimes()==null?"":ob.getPromotionTimes(); break;
  277. case "出生日期": o = ob.getBirthdays(); break;
  278. case "性别": o = ob.getSex()==0?"男":"女"; break;
  279. case "婚否": o = ob.getMarriageName(); break;
  280. case "子女": o = ob.getSon().toString()+"/"+ob.getGirl().toString(); break;
  281. case "政治面貌": o = ob.getPoliticalOutlookName(); break;
  282. case "学历": o = ob.getEducationName(); break;
  283. case "毕业学校": o = ob.getSchool(); break;
  284. case "所学专业": o = ob.getMajor(); break;
  285. case "职称/证书": o = ob.getTitle(); break;
  286. case "晋升明细": o = ob.getPromotionRemarks(); break;
  287. case "最近晋升时间": o = ob.getPromotionTimes(); break;
  288. case "合同": if (ob.getContractStart()!=null&&ob.getContractEnd()!=null) {
  289. o = ob.getContractStart()+" ~ "+ob.getContractEnd();
  290. }
  291. break;
  292. case "联系电话": o = ob.getMobile(); break;
  293. case "办公室电话": o = ob.getFixedTel(); break;
  294. case "身份证号码": o = ob.getIdCard(); break;
  295. case "身份证发证地": o = ob.getCertificationAuthority(); break;
  296. case "户籍所在地": o = ob.getResidenceName(); break;
  297. case "现住址": o = ob.getNowName(); break;
  298. case "紧急联系人": o = ob.getEmergencyContact(); break;
  299. case "紧急联系人电话": o = ob.getEmergencyMobile(); break;
  300. case "离职时间": o = ob.getQuitTime(); break;
  301. case "工作年限": o = ob.getWorkingYear()==null?"":ob.getWorkingYear().toString(); break;
  302. case "年龄": o = ob.getAge()==null?"":ob.getAge().toString(); break;
  303. case "出生月份": o = ob.getMonth()==null?"":ob.getMonth().toString(); break;
  304. case "参保时间": o = ob.getInsuranceStartTimes(); break;
  305. case "停保时间": o = ob.getInsuranceEndTimes(); break;
  306. case "入公积金时间": o = ob.getFundStartTimes(); break;
  307. case "停公积金时间": o = ob.getFundEndTimes(); break;
  308. default: o = ""; break;
  309. }
  310. XSSFCell c = r.createCell(i);
  311. c.setCellValue(o);
  312. }
  313. }
  314. //返回名称及参数
  315. response.addHeader("Content-Disposition", "attachment;filename=" + new String(fileName.getBytes(),"iso-8859-1"));
  316. response.setContentType("application/octet-stream;charset=utf-8");
  317. // 返回数据流
  318. wb.write(out);
  319. out.flush();
  320. out.close();
  321. } catch (Exception e) {
  322. logger.error(e.getLocalizedMessage());
  323. throw new BusinessException(new Error("表格生成错误。"));
  324. }finally {
  325. out.flush();
  326. out.close();
  327. }
  328. }
  329. @Override
  330. public List<OutPersonnelLvlBo> selectLvlList() {
  331. return personnelLevelMapper.selectAll();
  332. }
  333. @Override
  334. public int updateLvl(InputPersonnelLvlBo i) {
  335. if (i.getId()==null) {
  336. personnelLevelMapper.insertSelective(i);
  337. }else {
  338. personnelLevelMapper.updateByPrimaryKeySelective(i);
  339. }
  340. return 1;
  341. }
  342. @Override
  343. public int updateWelfare(IntpersonnelWelfareBo i) {
  344. PersonnelWelfare p=personnelWelfareMapper.selectByPrimaryKey(i.getId());
  345. if (p==null||p.getId()==null) {
  346. if (i.getType()!=null) {
  347. personnelWelfareMapper.insertSelective(i);
  348. }
  349. }else {
  350. personnelWelfareMapper.updateByPrimaryKey(i);
  351. }
  352. PersonnelMid m=new PersonnelMid();
  353. m.setId(i.getPdId());
  354. m.setWelfareAnnexUrl(i.getAnnexUrl());
  355. m.setWelfareAnnexName(i.getAnnexName());
  356. m.setWelfareRemarks(i.getRemarks());
  357. PersonnelMid pm=personnelMidMapper.selectByPrimaryKey(i.getPdId());
  358. if (i.getType()!=null) {
  359. if (i.getType()==0) {
  360. m.setInsuranceStartTime(i.getStartTime());
  361. m.setInsuranceEndTime(i.getEndTime());
  362. }else if (i.getType()==1) {
  363. m.setFundStartTime(i.getStartTime());
  364. m.setFundEndTime(i.getEndTime());
  365. }else if (i.getType()==2) {
  366. m.setEmployerStartTime(i.getStartTime());
  367. m.setEmployerEndTime(i.getEndTime());
  368. }
  369. }
  370. if (pm==null||pm.getId()==null) {
  371. personnelMidMapper.insertSelective(m);
  372. }else {
  373. personnelMidMapper.updateByidTime(m,i.getType());
  374. }
  375. return 1;
  376. }
  377. }