96c39c290554abe8d348cde9f5b863cd453486fd.svn-base 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818
  1. package cn.com.goldenwater.dcproj.service.impl.importex;
  2. import cn.com.goldenwater.dcproj.dao.ImpPersInfoDao;
  3. import cn.com.goldenwater.dcproj.dto.ExcelInspPersDto;
  4. import cn.com.goldenwater.dcproj.model.*;
  5. import cn.com.goldenwater.dcproj.param.*;
  6. import cn.com.goldenwater.dcproj.service.*;
  7. import cn.com.goldenwater.core.service.AbstractCrudService;
  8. import cn.com.goldenwater.id.util.UuidUtil;
  9. import com.github.pagehelper.PageHelper;
  10. import org.apache.commons.lang3.StringUtils;
  11. import org.apache.poi.xssf.usermodel.XSSFRow;
  12. import org.apache.poi.xssf.usermodel.XSSFSheet;
  13. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.stereotype.Service;
  16. import org.springframework.transaction.annotation.Transactional;
  17. import org.springframework.web.multipart.MultipartFile;
  18. import java.io.InputStream;
  19. import java.text.ParseException;
  20. import java.text.SimpleDateFormat;
  21. import java.util.Date;
  22. import java.util.HashMap;
  23. import java.util.List;
  24. import java.util.Map;
  25. /**
  26. * @author lune
  27. * @date 2019-7-23
  28. */
  29. @Service
  30. @Transactional
  31. public class ImpPersInfoServiceImpl extends AbstractCrudService<ImpPersInfo, ImpPersInfoParam> implements ImpPersInfoService {
  32. @Autowired
  33. private ImpPersInfoDao impPersInfoDao;
  34. @Autowired
  35. private AttAdXBaseService attAdXBaseService;
  36. @Autowired
  37. private BisInspAllService inspAllService;
  38. @Autowired
  39. private BisInspAllRlationPersService bisInspAllRlationPersService;
  40. @Autowired
  41. private BisInspAllRlationService bisInspAllRlationService;
  42. @Autowired
  43. private BisInspSelAreaService bisInspSelAreaService;
  44. public ImpPersInfoServiceImpl(ImpPersInfoDao impPersInfoDao) {
  45. super(impPersInfoDao);
  46. this.impPersInfoDao = impPersInfoDao;
  47. }
  48. @Override
  49. public String insertList(List<ExcelInspPersDto> list, String mnth) {
  50. ImpPersInfo impPersInfo = new ImpPersInfo();
  51. int i = 1;
  52. for (ExcelInspPersDto inspPers : list) {
  53. ImpPersInfo persInfo = new ImpPersInfo();
  54. persInfo.setId(UuidUtil.uuid());
  55. persInfo.setNum(String.valueOf(i));
  56. persInfo.setOrgId(inspPers.getOrgId());
  57. persInfo.setOrgNm(inspPers.getOrgName());
  58. String adCd = getAdCd(inspPers.getGroName(), "", "");
  59. persInfo.setAdCode(adCd);
  60. persInfo.setAdName(inspPers.getGroName());
  61. Map<String, String> map = this.addPers(inspPers);
  62. String leadId = map.get("one");
  63. persInfo.setLeadId(leadId);
  64. persInfo.setLeadName(inspPers.getHeadman());
  65. persInfo.setLeadUnitJob(inspPers.getHeadNm());
  66. persInfo.setCrewId(map.get("two"));
  67. persInfo.setCrewName(inspPers.getMembers());
  68. persInfo.setCrewUnitJob(inspPers.getMemNm());
  69. persInfo.setLisonId(map.get("three"));
  70. persInfo.setLisonName(inspPers.getConPers());
  71. persInfo.setLisonUnitJob(inspPers.getConNm());
  72. persInfo.setMnth(mnth);
  73. if (StringUtils.isNotBlank(leadId)) {
  74. //查询是否能关联上现有的督查组,根据月份、督查区域、组长进行匹配
  75. Map<String, Object> param = new HashMap<>();
  76. param.put("persId", leadId);
  77. param.put("persType", "1");
  78. param.put("adCd", adCd.substring(0, 2));
  79. param.put("id", "001");
  80. param.put("mnth", mnth);
  81. List<Map<String, Object>> groups = impPersInfoDao.getGroupId(param);
  82. if (groups != null && groups.size() > 0) {
  83. Map<String, Object> group = groups.get(0);
  84. persInfo.setOldGroupId(group.get("ID").toString());
  85. } else {
  86. param.put("persType", "");
  87. groups = impPersInfoDao.getGroupId(param);
  88. if (groups != null && groups.size() > 0) {
  89. Map<String, Object> group = groups.get(0);
  90. persInfo.setOldGroupId(group.get("ID").toString());
  91. //如果不是组长,那么把本行数据中的组长设置成该督查组组长
  92. BisInspAllRlation bisInspAllRlation = new BisInspAllRlation();
  93. bisInspAllRlation.setId(group.get("ID").toString());
  94. bisInspAllRlation.setPersid(leadId);
  95. bisInspAllRlation.setPertype("1");
  96. bisInspAllRlation.setImpData("2");
  97. bisInspAllRlationService.update(bisInspAllRlation);
  98. }
  99. }
  100. } else {
  101. persInfo.setOldGroupId(impPersInfo.getOldGroupId());
  102. }
  103. impPersInfo = persInfo;
  104. impPersInfoDao.insert(persInfo);
  105. i++;
  106. }
  107. return null;
  108. }
  109. @Override
  110. public String handlePersData(String mnth, String orgId) {
  111. ImpPersInfoParam impPersInfoParam = new ImpPersInfoParam();
  112. impPersInfoParam.setMnth(mnth);
  113. impPersInfoParam.setOrgId(orgId);
  114. List<ImpPersInfo> persInfos = impPersInfoDao.findList(impPersInfoParam);
  115. String groupId = "";
  116. String groupNm = "";
  117. for (ImpPersInfo info:persInfos) {
  118. Map<String, String> map = addGroup(info,groupId,groupNm);
  119. groupId = map.get("groupId");
  120. groupNm = map.get("groupNm");
  121. }
  122. return null;
  123. }
  124. public String getAdCd(String sheng, String shi, String xian) {
  125. String adCd = "";
  126. String adCd2 = "";
  127. if(sheng.contains("/")){
  128. String sheng2 = sheng.substring(sheng.indexOf("/")+1);
  129. adCd2 = getAdCd(sheng2,"","");
  130. sheng = sheng.substring(0,sheng.indexOf("/"));
  131. }
  132. AttAdXBaseParam attAdXBaseParam = new AttAdXBaseParam();
  133. AttAdXBase attAdXBase;
  134. if (StringUtils.isNotBlank(sheng)) {
  135. attAdXBaseParam.setAdName(sheng);
  136. attAdXBaseParam.setAdGrad("2");
  137. attAdXBase = attAdXBaseService.getBy(attAdXBaseParam);
  138. if (attAdXBase != null) {
  139. String shengCode = attAdXBase.getAdCode();
  140. attAdXBaseParam.setAdFcode(shengCode);
  141. adCd = shengCode;
  142. } else {
  143. attAdXBaseParam.setAdName("");
  144. attAdXBaseParam.setAdFullName(sheng);
  145. attAdXBase = attAdXBaseService.getBy(attAdXBaseParam);
  146. if (attAdXBase != null) {
  147. String shengCode = attAdXBase.getAdCode();
  148. attAdXBaseParam.setAdFcode(shengCode);
  149. adCd = shengCode;
  150. }
  151. }
  152. }
  153. if (StringUtils.isNotBlank(shi)) {
  154. attAdXBaseParam.setAdName(shi);
  155. attAdXBaseParam.setAdGrad("3");
  156. attAdXBase = attAdXBaseService.getBy(attAdXBaseParam);
  157. if (attAdXBase != null) {
  158. String shiCode = attAdXBase.getAdCode();
  159. attAdXBaseParam.setAdFcode(shiCode);
  160. adCd = shiCode;
  161. } else {
  162. attAdXBaseParam.setAdName("");
  163. attAdXBaseParam.setAdFullName(shi);
  164. attAdXBase = attAdXBaseService.getBy(attAdXBaseParam);
  165. if (attAdXBase != null) {
  166. String shiCode = attAdXBase.getAdCode();
  167. attAdXBaseParam.setAdFcode(shiCode);
  168. adCd = shiCode;
  169. }
  170. }
  171. }
  172. if (StringUtils.isNotBlank(xian)) {
  173. attAdXBaseParam.setAdName(xian);
  174. attAdXBaseParam.setAdGrad("4");
  175. attAdXBase = attAdXBaseService.getBy(attAdXBaseParam);
  176. if (attAdXBase != null) {
  177. adCd = attAdXBase.getAdCode();
  178. } else {
  179. attAdXBaseParam.setAdName("");
  180. attAdXBaseParam.setAdFullName(xian);
  181. attAdXBase = attAdXBaseService.getBy(attAdXBaseParam);
  182. if (attAdXBase != null) {
  183. adCd = attAdXBase.getAdCode();
  184. }
  185. }
  186. }
  187. if(StringUtils.isNotBlank(adCd2)){
  188. adCd = adCd + "/" + adCd2;
  189. }
  190. return adCd;
  191. }
  192. public Map<String, String> addPers(ExcelInspPersDto persDto) {
  193. Map<String, String> map = new HashMap<>();
  194. String sheng = persDto.getGroName();
  195. String shengCode = getAdCd(sheng, "", "");
  196. String orgId = persDto.getOrgId();
  197. String persName = persDto.getHeadman();
  198. String persId = "";
  199. String headerNm = persDto.getHeadNm();
  200. String memeber = persDto.getMembers();
  201. String memNm = persDto.getMemNm();
  202. String comPer = persDto.getConPers();
  203. String comNm = persDto.getConNm();
  204. if (StringUtils.isNotBlank(persName)) {
  205. persId = this.addOnePers(orgId, persName, headerNm);
  206. } else {
  207. persId = "";
  208. }
  209. map.put("one", persId);
  210. if (StringUtils.isNotBlank(memeber)) {
  211. persId = this.addOnePers(orgId, memeber, memNm);
  212. } else {
  213. persId = "";
  214. }
  215. map.put("two", persId);
  216. if (StringUtils.isNotBlank(comPer)) {
  217. persId = this.addOnePers(orgId, comPer, comNm);
  218. } else {
  219. persId = "";
  220. }
  221. map.put("three", persId);
  222. return map;
  223. }
  224. public String addOnePers(String orgId, String persName, String dpp) {
  225. String persId = "";
  226. if (StringUtils.isNotEmpty(persName)) {
  227. persName = persName.replaceAll(" ", "");
  228. }
  229. BisInspAllRlationPersParam persParam = new BisInspAllRlationPersParam();
  230. persParam.setOrgId(orgId);
  231. persParam.setPersName(persName);
  232. List<BisInspAllRlationPers> rlationPers = bisInspAllRlationPersService.findList(persParam);
  233. if (rlationPers != null && rlationPers.size() > 0) {
  234. BisInspAllRlationPers rlationPer = rlationPers.get(0);
  235. persId = rlationPer.getGuid();
  236. } else {
  237. persId = UuidUtil.uuid();
  238. BisInspAllRlationPers rlationPer = new BisInspAllRlationPers();
  239. rlationPer.setGuid(persId);
  240. rlationPer.setOrgId(orgId);
  241. rlationPer.setPersName(persName);
  242. rlationPer.setPwd("JinShui@433");
  243. if (dpp.contains("/")) {
  244. String[] strs = dpp.split("/");
  245. for (int i = 0; i < strs.length; i++) {
  246. if (i == 0) {
  247. rlationPer.setDpnm(strs[0]);
  248. } else if (i == 1) {
  249. rlationPer.setDppost(strs[1]);
  250. }
  251. }
  252. } else {
  253. rlationPer.setDppost(dpp);
  254. }
  255. persParam.setPersName("");
  256. int count = bisInspAllRlationPersService.selectCount(persParam);
  257. String phone = orgId + String.format("%08d", count + 1);//其中0表示补零而不是补空格,6表示至少6位
  258. rlationPer.setMobilenumb(phone);
  259. bisInspAllRlationPersService.insert(rlationPer);
  260. }
  261. return persId;
  262. }
  263. public Map<String, String> addGroup(ImpPersInfo info,String groupId, String groupNm) {
  264. Map<String, String> result = new HashMap<>();
  265. String oldGroupId = info.getOldGroupId();
  266. String leadId = info.getLeadId();
  267. String crewId = info.getCrewId();
  268. String lisonId = info.getLisonId();
  269. String mnth = info.getMnth();
  270. String orgId = info.getOrgId();
  271. String adCode = info.getAdCode();
  272. String adName = info.getAdName();
  273. //如果人员不能关联到该月批次下的组,则进行新增或者重新匹配
  274. if (StringUtils.isBlank(oldGroupId)) {
  275. //首先查询该月份是否有相应批次
  276. BisInspAllParam bisInspAllParam = new BisInspAllParam();
  277. BisInspAll bisInspAll;
  278. bisInspAllParam.setInspYear("2019");
  279. bisInspAllParam.setInspMnth(mnth);
  280. String pid = "001" + orgId;//6位
  281. bisInspAllParam.setId("");
  282. bisInspAllParam.setPid(pid);
  283. //查询该机构本月批次
  284. List<BisInspAll> bisInspAlls = inspAllService.findList(bisInspAllParam);
  285. if (bisInspAlls != null && bisInspAlls.size() > 0) {
  286. //查询该批次下是否有督查组能与本行数据中组长、行政区关联
  287. //首先判断本行数据中是否有组长
  288. if (StringUtils.isNotBlank(leadId)) {
  289. Map<String, Object> param = new HashMap<>();
  290. param.put("persId", leadId);
  291. param.put("adCd", adCode.substring(0, 2));
  292. param.put("id", pid);
  293. param.put("mnth", mnth);
  294. List<Map<String, Object>> groups = impPersInfoDao.getGroupId(param);
  295. if (groups!=null&&groups.size()>0){
  296. //对本行数据中的组长、组员、联系人进行判断,判断是否都在其督查组中,是否在督查组中担任的角色是准确的
  297. this.checkGroupPers(info,groups);
  298. //查询本行数据中行政区划是否在督查组
  299. BisInspSelAreaParam bisInspSelAreaParam = new BisInspSelAreaParam();
  300. bisInspSelAreaParam.setId(oldGroupId);
  301. bisInspSelAreaParam.setAdCode(adCode);
  302. BisInspSelArea selArea = bisInspSelAreaService.getBy(bisInspSelAreaParam);
  303. if(selArea==null){
  304. //本行数据中行政区划添加进督查组
  305. selArea = new BisInspSelArea();
  306. selArea.setAreaId(UuidUtil.uuid());
  307. selArea.setId(oldGroupId);
  308. selArea.setAdName(adName);
  309. selArea.setAdCode(adCode);
  310. selArea.setImpData("1");
  311. bisInspSelAreaService.insert(selArea);
  312. }
  313. }else{
  314. //如果没有查询到督查组,则在第一个批次下进行新增相应的督查组
  315. //获取批次
  316. bisInspAll = bisInspAlls.get(0);
  317. pid = bisInspAll.getId();
  318. //新增督查组,然后把本行数据中的组长、组员、联系人新增进该督查组
  319. info = this.addBatchGroup(info,pid);
  320. }
  321. } else {
  322. //如果本行数据中没有组长,那么可以直接使用上一行的督查组信息
  323. info.setOldGroupId(groupId);
  324. info.setGroupId(groupId);
  325. info.setGroupNm(groupNm);
  326. impPersInfoDao.update(info);
  327. Map<String, Object> param = new HashMap<>();
  328. param.put("persId", crewId);
  329. param.put("id", groupId);
  330. param.put("mnth", mnth);
  331. List<Map<String, Object>> groups = impPersInfoDao.getGroupId(param);
  332. this.checkGroupPers(info, groups);
  333. }
  334. } else {
  335. //如果没有有对应批次则新建批次和督查组
  336. info = this.addBatchGroup(info, pid);
  337. pid = info.getGroupId();
  338. info = this.addBatchGroup(info, pid);
  339. }
  340. } else {
  341. //如果已经关联到已有督查组,则对本行数据中的组长、组员、联系人进行判断,判断是否都在其督查组中,是否在督查组中担任的角色是准确的
  342. Map<String, Object> param = new HashMap<>();
  343. List<Map<String, Object>> groups;
  344. param.put("adCd",info.getAdCode().substring(0,2));
  345. param.put("id",oldGroupId);
  346. param.put("mnth",mnth);
  347. String persIds = "";
  348. if (StringUtils.isNotBlank(leadId)) {
  349. persIds += leadId + ",";
  350. }
  351. if (StringUtils.isNotBlank(lisonId)) {
  352. persIds += lisonId + ",";
  353. }
  354. if (StringUtils.isNotBlank(crewId)) {
  355. persIds += crewId;
  356. }
  357. param.put("persIds", persIds);
  358. groups = impPersInfoDao.getGroupId(param);
  359. if (groups != null && groups.size() > 0) {
  360. //对本行数据中的组长、组员、联系人进行判断,判断是否都在其督查组中,是否在督查组中担任的角色是准确的
  361. this.checkGroupPers(info, groups);
  362. } else {
  363. //如果本组中没有人员,则把本行数据中的组长、组员、联系人新增进该督查组
  364. this.addGroupPers(info, oldGroupId);
  365. }
  366. //查询本行数据中行政区划是否在督查组
  367. BisInspSelAreaParam bisInspSelAreaParam = new BisInspSelAreaParam();
  368. bisInspSelAreaParam.setId(oldGroupId);
  369. bisInspSelAreaParam.setAdCode(adCode);
  370. BisInspSelArea selArea = bisInspSelAreaService.getBy(bisInspSelAreaParam);
  371. if(selArea==null){
  372. //本行数据中行政区划添加进督查组
  373. selArea = new BisInspSelArea();
  374. selArea.setAreaId(UuidUtil.uuid());
  375. selArea.setId(oldGroupId);
  376. selArea.setAdName(adName);
  377. selArea.setAdCode(adCode);
  378. selArea.setImpData("1");
  379. bisInspSelAreaService.insert(selArea);
  380. }
  381. BisInspAll bisInspAll = inspAllService.get(oldGroupId);
  382. info.setGroupId(oldGroupId);
  383. info.setGroupNm(bisInspAll.getPnm());
  384. impPersInfoDao.update(info);
  385. }
  386. result.put("groupId",info.getGroupId());
  387. result.put("groupNm",info.getGroupNm());
  388. return result;
  389. }
  390. public void addGroupPers(ImpPersInfo info, String groupId) {
  391. String leadId = info.getLeadId();
  392. String crewId = info.getCrewId();
  393. String lisonId = info.getLisonId();
  394. //本行数据中组长、组员、联系人添加进督查组
  395. BisInspAllRlation bisInspAllRlation = new BisInspAllRlation();
  396. if (StringUtils.isNotBlank(leadId)) {
  397. bisInspAllRlation.setId(groupId);
  398. bisInspAllRlation.setPersid(leadId);
  399. bisInspAllRlation.setPertype("1");
  400. bisInspAllRlation.setImpData("1");
  401. System.out.println(bisInspAllRlation.toString());
  402. BisInspAllRlationParam param = new BisInspAllRlationParam();
  403. param.setPersid(bisInspAllRlation.getPersid());
  404. param.setId(bisInspAllRlation.getId());
  405. BisInspAllRlation rlation = bisInspAllRlationService.getBy(param);
  406. if(rlation!=null){
  407. bisInspAllRlationService.update(bisInspAllRlation);
  408. }else{
  409. bisInspAllRlationService.insert(bisInspAllRlation);
  410. }
  411. }
  412. if (StringUtils.isNotBlank(crewId)) {
  413. bisInspAllRlation.setId(groupId);
  414. bisInspAllRlation.setPersid(crewId);
  415. bisInspAllRlation.setPertype("2");
  416. bisInspAllRlation.setImpData("1");
  417. System.out.println(bisInspAllRlation.toString());
  418. BisInspAllRlationParam param = new BisInspAllRlationParam();
  419. param.setPersid(bisInspAllRlation.getPersid());
  420. param.setId(bisInspAllRlation.getId());
  421. BisInspAllRlation rlation = bisInspAllRlationService.getBy(param);
  422. if(rlation!=null){
  423. bisInspAllRlationService.update(bisInspAllRlation);
  424. }else{
  425. bisInspAllRlationService.insert(bisInspAllRlation);
  426. }
  427. }
  428. if (StringUtils.isNotBlank(lisonId)) {
  429. bisInspAllRlation.setId(groupId);
  430. bisInspAllRlation.setPersid(lisonId);
  431. bisInspAllRlation.setPertype("3");
  432. bisInspAllRlation.setImpData("1");
  433. System.out.println(bisInspAllRlation.toString());
  434. BisInspAllRlationParam param = new BisInspAllRlationParam();
  435. param.setPersid(bisInspAllRlation.getPersid());
  436. param.setId(bisInspAllRlation.getId());
  437. BisInspAllRlation rlation = bisInspAllRlationService.getBy(param);
  438. if(rlation!=null){
  439. bisInspAllRlationService.update(bisInspAllRlation);
  440. }else{
  441. bisInspAllRlationService.insert(bisInspAllRlation);
  442. }
  443. }
  444. }
  445. public void checkGroupPers(ImpPersInfo info, List<Map<String, Object>> groups) {
  446. String oldGroupId = info.getOldGroupId();
  447. String leadId = info.getLeadId();
  448. String crewId = info.getCrewId();
  449. String lisonId = info.getLisonId();
  450. boolean hasLead = false;
  451. boolean isLead = false;
  452. boolean hasLison = false;
  453. boolean isLison = false;
  454. boolean hasCrew = false;
  455. boolean isCrew = false;
  456. for (Map<String, Object> group : groups) {
  457. String persId = String.valueOf(group.get("PERSID"));
  458. String persType = String.valueOf(group.get("PERTYPE"));
  459. if (persId.equals(leadId)) {
  460. hasLead = true;
  461. if ("1".equals(persType)) {
  462. isLead = true;
  463. }
  464. }
  465. if (persId.equals(crewId)) {
  466. hasCrew = true;
  467. if ("2".equals(persType)) {
  468. isCrew = true;
  469. }
  470. }
  471. if (persId.equals(lisonId)) {
  472. hasLison = true;
  473. if ("3".equals(persType)) {
  474. isLison = true;
  475. }
  476. }
  477. }
  478. //如果本组中有人员与本行数据中的组长一致,则判断人员类型是否匹配
  479. if (hasLead) {
  480. //如果不是组长,那么把本行数据中的组长设置成该督查组组长
  481. if (!isLead) {
  482. BisInspAllRlation bisInspAllRlation = new BisInspAllRlation();
  483. bisInspAllRlation.setId(oldGroupId);
  484. bisInspAllRlation.setPersid(leadId);
  485. bisInspAllRlation.setPertype("1");
  486. bisInspAllRlation.setImpData("2");
  487. System.out.println(bisInspAllRlation.toString());
  488. bisInspAllRlationService.update(bisInspAllRlation);
  489. }
  490. }else{
  491. if(StringUtils.isNotBlank(leadId)){
  492. //如果本组中没有人员与本行数据中的组长一致,那么把本行数据中的组长设置成该督查组组长
  493. BisInspAllRlation bisInspAllRlation = new BisInspAllRlation();
  494. bisInspAllRlation.setId(oldGroupId);
  495. bisInspAllRlation.setPersid(leadId);
  496. bisInspAllRlation.setPertype("1");
  497. bisInspAllRlation.setImpData("1");
  498. System.out.println(bisInspAllRlation.toString());
  499. bisInspAllRlationService.insert(bisInspAllRlation);
  500. }
  501. }
  502. //如果本组中有人员与本行数据中的组员一致,则判断人员类型是否匹配
  503. if (hasCrew) {
  504. //如果不是组员,那么把本行数据中的组员设置成该督查组组员
  505. if (!isCrew) {
  506. BisInspAllRlation bisInspAllRlation = new BisInspAllRlation();
  507. bisInspAllRlation.setId(oldGroupId);
  508. bisInspAllRlation.setPersid(crewId);
  509. bisInspAllRlation.setPertype("2");
  510. bisInspAllRlation.setImpData("2");
  511. System.out.println(bisInspAllRlation.toString());
  512. bisInspAllRlationService.update(bisInspAllRlation);
  513. }
  514. }else{
  515. if(StringUtils.isNotBlank(crewId)){
  516. //如果本组中没有人员与本行数据中的组员一致,那么把本行数据中的组员设置成该督查组组员
  517. BisInspAllRlation bisInspAllRlation = new BisInspAllRlation();
  518. bisInspAllRlation.setId(oldGroupId);
  519. bisInspAllRlation.setPersid(crewId);
  520. bisInspAllRlation.setPertype("2");
  521. bisInspAllRlation.setImpData("1");
  522. System.out.println(bisInspAllRlation.toString());
  523. bisInspAllRlationService.insert(bisInspAllRlation);
  524. }
  525. }
  526. //如果本组中有人员与本行数据中的联系人一致,则判断人员类型是否匹配
  527. if (hasLison) {
  528. //如果不是联系人,那么把本行数据中的联系人设置成该督查组联系人
  529. if (!isLison) {
  530. BisInspAllRlation bisInspAllRlation = new BisInspAllRlation();
  531. bisInspAllRlation.setId(oldGroupId);
  532. bisInspAllRlation.setPersid(lisonId);
  533. bisInspAllRlation.setPertype("3");
  534. bisInspAllRlation.setImpData("2");
  535. System.out.println(bisInspAllRlation.toString());
  536. bisInspAllRlationService.update(bisInspAllRlation);
  537. }
  538. }else{
  539. if(StringUtils.isNotBlank(lisonId)){
  540. //如果本组中没有有人员与本行数据中的联系人一致,则把本行数据中的联系人设置成该督查组联系人
  541. BisInspAllRlation bisInspAllRlation = new BisInspAllRlation();
  542. bisInspAllRlation.setId(oldGroupId);
  543. bisInspAllRlation.setPersid(lisonId);
  544. bisInspAllRlation.setPertype("3");
  545. bisInspAllRlation.setImpData("1");
  546. System.out.println(bisInspAllRlation.toString());
  547. bisInspAllRlationService.insert(bisInspAllRlation);
  548. }
  549. }
  550. }
  551. public String getGroupNm(ImpPersInfo info) {
  552. String nm;
  553. int num = 0;
  554. String id = info.getId();
  555. String mnth = info.getMnth();
  556. String orgId = info.getOrgId();
  557. String adCode = info.getAdCode();
  558. String adName = info.getAdName();
  559. ImpPersInfoParam param = new ImpPersInfoParam();
  560. param.setMnth(mnth);
  561. param.setOrgId(orgId);
  562. param.setAdCode(adCode);
  563. param.setIsLead("1");
  564. List<ImpPersInfo> impPersInfos = impPersInfoDao.findList(param);
  565. for (int i = 0; i < impPersInfos.size(); i++) {
  566. ImpPersInfo impPersInfo = impPersInfos.get(i);
  567. if(id.equals(impPersInfo.getId())){
  568. num = i+1;
  569. break;
  570. }
  571. }
  572. if(impPersInfos.size()==1){
  573. nm = adName+"组";
  574. }else {
  575. nm = adName+num+"组";
  576. }
  577. return nm;
  578. }
  579. public ImpPersInfo addBatchGroup(ImpPersInfo info, String pid) {
  580. String mnth = info.getMnth();
  581. String adCode = info.getAdCode();
  582. String adName = info.getAdName();
  583. String groupId = "";
  584. String groupNm = "";
  585. try {
  586. BisInspAll bisInspAll = new BisInspAll();
  587. Date date = new SimpleDateFormat("yyyy/MM/dd").parse("2019/" + mnth + "/30");
  588. bisInspAll.setEntm(date);
  589. date = new SimpleDateFormat("yyyy/MM/dd").parse("2019/" + mnth + "/01");
  590. bisInspAll.setSttm(date);
  591. BisInspAllParam newInspAllParam=new BisInspAllParam();
  592. newInspAllParam.setPid(pid);
  593. String maxId=inspAllService.selectMax(newInspAllParam);
  594. if(StringUtils.isBlank(maxId)) {
  595. maxId = pid + "001";
  596. }else {
  597. maxId="00"+(Integer.parseInt(maxId)+1);
  598. }
  599. if(pid.length()==6){
  600. groupId = maxId;
  601. groupNm = "2019年" + mnth + "月督查工作";
  602. //创建批次
  603. bisInspAll.setId(maxId);
  604. bisInspAll.setPid(pid);
  605. bisInspAll.setInspYear("2019");
  606. bisInspAll.setInspMnth(mnth);
  607. bisInspAll.setPnm("2019年" + mnth + "月督查工作");
  608. bisInspAll.setInspTask("导入新增批次");
  609. bisInspAll.setImpData("1");
  610. inspAllService.insert(bisInspAll);
  611. } else if (pid.length() == 9) {
  612. //创建督查组
  613. bisInspAll.setId(maxId);
  614. bisInspAll.setPid(pid);
  615. bisInspAll.setInspYear("2019");
  616. bisInspAll.setInspMnth(mnth);
  617. String pnm = getGroupNm(info);
  618. bisInspAll.setPnm(pnm);
  619. bisInspAll.setInspTask(adCode);
  620. bisInspAll.setImpData("1");
  621. inspAllService.insert(bisInspAll);
  622. System.out.println("新增bis_insp_all p&c" +pnm);
  623. groupId = maxId;
  624. groupNm = pnm;
  625. //本行数据中组长、组员、联系人添加进督查组
  626. this.addGroupPers(info,maxId);
  627. //本行数据中行政区划添加进督查组
  628. BisInspSelArea selArea = new BisInspSelArea();
  629. selArea.setAreaId(UuidUtil.uuid());
  630. selArea.setId(maxId);
  631. selArea.setAdName(adName);
  632. selArea.setAdCode(adCode);
  633. selArea.setImpData("1");
  634. bisInspSelAreaService.insert(selArea);
  635. }
  636. //更新本行数据中督查组信息
  637. info.setOldGroupId(groupId);
  638. info.setGroupId(groupId);
  639. info.setGroupNm(groupNm);
  640. impPersInfoDao.update(info);
  641. } catch (Exception e) {
  642. e.printStackTrace();
  643. }
  644. return info;
  645. }
  646. private String getOrgId(String orgNm){
  647. String orgId = "041";
  648. if ("长江委".equals(orgNm)||"长委".equals(orgNm)) {
  649. orgId = "020";
  650. } else if ("黄委".equals(orgNm)) {
  651. orgId = "021";
  652. } else if ("淮委".equals(orgNm)) {
  653. orgId = "022";
  654. } else if ("海委".equals(orgNm)) {
  655. orgId = "023";
  656. } else if ("珠委".equals(orgNm)||"珠江委".equals(orgNm)) {
  657. orgId = "024";
  658. } else if ("松辽委".equals(orgNm)) {
  659. orgId = "025";
  660. } else if ("太湖局".equals(orgNm)) {
  661. orgId = "026";
  662. } else if ("部督查办".equals(orgNm)||"督查办".equals(orgNm)) {
  663. orgId = "027";
  664. } else {
  665. orgId = "";
  666. }
  667. return orgId;
  668. }
  669. private String getMnth(String cell){
  670. String mnth="";
  671. if("三月".equals(cell)){
  672. mnth = "03";
  673. }else if("四月".equals(cell)){
  674. mnth = "03";
  675. }else if("五月".equals(cell)){
  676. mnth = "03";
  677. }else if("六月".equals(cell)){
  678. mnth = "03";
  679. }else if("七月".equals(cell)){
  680. mnth = "03";
  681. }else if("八月".equals(cell)){
  682. mnth = "03";
  683. }else if("九月".equals(cell)){
  684. mnth = "03";
  685. }else if("十月".equals(cell)){
  686. mnth = "03";
  687. }
  688. return mnth;
  689. }
  690. @Override
  691. public String insertPersList(MultipartFile file) {
  692. try{
  693. InputStream is = file.getInputStream();
  694. // 构造 XSSFWorkbook 对象,strPath 传入文件路径
  695. XSSFWorkbook xwb = new XSSFWorkbook(is);
  696. XSSFSheet sheet = xwb.getSheetAt(0);
  697. ImpPersInfo impPersInfo = new ImpPersInfo();
  698. for (int i = sheet.getFirstRowNum() + 2; i < sheet.getPhysicalNumberOfRows(); i++) {
  699. XSSFRow row = sheet.getRow(i);
  700. int total = row.getPhysicalNumberOfCells();
  701. String cell = null;
  702. ImpPersInfo persInfo = new ImpPersInfo();
  703. for (int j = row.getFirstCellNum(); j < total; j++) {
  704. cell = String.valueOf(row.getCell(j));
  705. cell = cell.replaceAll(" ","");
  706. persInfo.setId(UuidUtil.uuid());
  707. if(j==0){
  708. if (StringUtils.isEmpty(cell)) {
  709. persInfo.setNum(impPersInfo.getNum());
  710. }else{
  711. persInfo.setNum(String.valueOf(cell));
  712. }
  713. }else if(j==1){
  714. if (StringUtils.isEmpty(cell)) {
  715. persInfo.setOrgId(impPersInfo.getOrgId());
  716. persInfo.setOrgNm(impPersInfo.getOrgNm());
  717. }else {
  718. String orgId = getOrgId(cell);
  719. persInfo.setOrgId(orgId);
  720. persInfo.setOrgNm(cell);
  721. }
  722. }else if(j==2){
  723. if (StringUtils.isEmpty(cell)) {
  724. persInfo.setAdCode(impPersInfo.getAdCode());
  725. persInfo.setAdName(impPersInfo.getAdName());
  726. }else {
  727. String adCd = getAdCd(cell, "", "");
  728. persInfo.setAdCode(adCd);
  729. persInfo.setAdName(cell);
  730. }
  731. }else if(j==3){
  732. if (StringUtils.isEmpty(cell)) {
  733. persInfo.setLeadId(impPersInfo.getLeadId());
  734. persInfo.setLeadName(impPersInfo.getLeadName());
  735. persInfo.setLeadUnitJob(impPersInfo.getLeadUnitJob());
  736. }else {
  737. persInfo.setLeadName(cell);
  738. }
  739. }else if(j==4){
  740. if (StringUtils.isEmpty(cell)) {
  741. persInfo.setLeadId(impPersInfo.getLeadId());
  742. persInfo.setLeadName(impPersInfo.getLeadName());
  743. persInfo.setLeadUnitJob(impPersInfo.getLeadUnitJob());
  744. }else {
  745. String persId = this.addOnePers(persInfo.getOrgId(), persInfo.getLeadName(), cell);
  746. persInfo.setLeadId(persId);
  747. persInfo.setLeadUnitJob(cell);
  748. }
  749. }else if(j==5){
  750. if (StringUtils.isEmpty(cell)) {
  751. persInfo.setCrewId(impPersInfo.getCrewId());
  752. persInfo.setCrewName(impPersInfo.getCrewName());
  753. persInfo.setCrewUnitJob(impPersInfo.getCrewUnitJob());
  754. }else {
  755. persInfo.setCrewName(cell);
  756. }
  757. }else if(j==6){
  758. if (StringUtils.isEmpty(cell)) {
  759. persInfo.setCrewId(impPersInfo.getCrewId());
  760. persInfo.setCrewName(impPersInfo.getCrewName());
  761. persInfo.setCrewUnitJob(impPersInfo.getCrewUnitJob());
  762. }else {
  763. String persId = this.addOnePers(persInfo.getOrgId(), persInfo.getCrewName(), cell);
  764. persInfo.setCrewId(persId);
  765. persInfo.setCrewUnitJob(cell);
  766. }
  767. }else if(j==7){
  768. if (StringUtils.isEmpty(cell)) {
  769. persInfo.setLisonId(impPersInfo.getLisonId());
  770. persInfo.setLisonName(impPersInfo.getLisonName());
  771. persInfo.setLisonUnitJob(impPersInfo.getLisonUnitJob());
  772. }else {
  773. persInfo.setLisonName(cell);
  774. }
  775. }else if(j==8){
  776. if (StringUtils.isEmpty(cell)) {
  777. persInfo.setLisonId(impPersInfo.getLisonId());
  778. persInfo.setLisonName(impPersInfo.getLisonName());
  779. persInfo.setLisonUnitJob(impPersInfo.getLisonUnitJob());
  780. }else {
  781. String persId = this.addOnePers(persInfo.getOrgId(), persInfo.getLisonName(), cell);
  782. persInfo.setLisonId(persId);
  783. persInfo.setLisonUnitJob(cell);
  784. }
  785. }else if(j==9){
  786. persInfo.setMnth(getMnth(cell));
  787. }
  788. }
  789. impPersInfoDao.insert(persInfo);
  790. impPersInfo = persInfo;
  791. }
  792. }catch (Exception e){
  793. e.printStackTrace();
  794. }
  795. return null;
  796. }
  797. }