QueryPreDeductService.java 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. package com.kingdee.eas.custom.shuiyou.six.osf;
  2. import cn.hutool.json.JSONObject;
  3. import cn.hutool.json.JSONUtil;
  4. import com.kingdee.bos.BOSException;
  5. import com.kingdee.bos.Context;
  6. import com.kingdee.bos.bsf.service.app.IHRMsfService;
  7. import com.kingdee.bos.dao.IObjectPK;
  8. import com.kingdee.bos.util.BOSUuid;
  9. import com.kingdee.eas.common.EASBizException;
  10. import com.kingdee.eas.custom.shuiyou.task.MessageResult;
  11. import com.kingdee.eas.custom.shuiyou.uitls.ISYUtilsFacade;
  12. import com.kingdee.eas.custom.shuiyou.uitls.SYUtilsFacadeFactory;
  13. import com.kingdee.eas.custom.shuiyou.uitls.URLConfigEnum;
  14. import com.kingdee.eas.util.app.DbUtil;
  15. import com.kingdee.jdbc.rowset.IRowSet;
  16. import com.kingdee.shr.base.syssetting.app.filter.HRFilterUtils;
  17. import com.kingdee.shr.base.syssetting.exception.ShrWebBizException;
  18. import com.kingdee.shr.compensation.app.tax.TaxUnitCollection;
  19. import com.kingdee.shr.compensation.app.tax.TaxUnitFactory;
  20. import com.kingdee.shr.compensation.app.tax.TaxUnitInfo;
  21. import com.kingdee.shr.compensation.app.taxCal.TaxUnitDeductionCollection;
  22. import com.kingdee.shr.compensation.app.taxCal.TaxUnitDeductionFactory;
  23. import com.kingdee.shr.compensation.app.taxCal.TaxUnitDeductionInfo;
  24. import com.kingdee.shr.compensation.util.CmpStrUtil;
  25. import com.kingdee.shr.compensation.util.lock.CmpDistributedLockUtils;
  26. import java.sql.Timestamp;
  27. import java.util.*;
  28. /**
  29. * 获取人员名单
  30. * description: QueryPreDeductService <br>
  31. * date: 2024/9/25 16:24 <br>
  32. * author: lhbj <br>
  33. * version: 1.0 <br>
  34. */
  35. public class QueryPreDeductService implements IHRMsfService {
  36. @Override
  37. public Object process(Context context, Map map) throws EASBizException, BOSException {
  38. String this_taskid= (String) map.get("this_taskId");
  39. String paramData= (String) map.get("paramData");
  40. ISYUtilsFacade facade = SYUtilsFacadeFactory.getLocalInstance(context);
  41. Map<String,String> config =facade.getConfig();
  42. MessageResult msg=null;
  43. try {
  44. String result = facade.post(config.get("ip") + URLConfigEnum.QUERYPREDEDUCT_VALUE, paramData);
  45. JSONObject paramJSON = JSONUtil.parseObj(paramData);
  46. String id = paramJSON.getStr("TAXUNITID");
  47. int year = paramJSON.getInt("skssnd");
  48. String oql = "select id,name,number,taxNumber,areaCode,regNumber,declPassword,realPassword,isAutoDeduct where id = '" + id + "'";
  49. TaxUnitCollection taxUnitCollection = TaxUnitFactory.getLocalInstance(context).getTaxUnitCollection(oql);
  50. if (null != taxUnitCollection && taxUnitCollection.size() > 0) {
  51. TaxUnitInfo taxUnitInfo = taxUnitCollection.get(0);
  52. String taxUnitDeductionId = this.saveTaxUnitDeduction(context, taxUnitInfo, year);
  53. Object[] param = new Object[]{null, taxUnitDeductionId, BOSUuid.create("46E337F4").toString()};
  54. if (null != result) {
  55. //成功写入人员是否6w
  56. msg = this._saveStaffCollection(context, taxUnitInfo, result);
  57. } else {
  58. msg = MessageResult.ERROR("接口调用异常");
  59. }
  60. }
  61. }catch (Exception e){
  62. e.printStackTrace();
  63. }
  64. return msg;
  65. }
  66. protected String getTaxUnitDeduction(Context ctx, TaxUnitInfo taxUnit, int year) throws BOSException {
  67. String oql = "select id where taxUnit.id = '" + taxUnit.getId().toString() + "' and year = " + year;
  68. TaxUnitDeductionCollection collection = TaxUnitDeductionFactory.getLocalInstance(ctx).getTaxUnitDeductionCollection(oql);
  69. if (null != collection && !collection.isEmpty()) {
  70. return collection.get(0).getId().toString();
  71. } else {
  72. throw new BOSException("没有找到纳税单位归集信息");
  73. }
  74. }
  75. protected synchronized MessageResult _saveStaffCollection(Context ctx, TaxUnitInfo taxUnit, String result) throws BOSException, ShrWebBizException {
  76. MessageResult msg=null;
  77. JSONObject object = JSONUtil.parseObj(result);
  78. JSONObject head = object.getJSONObject("head");
  79. Map<String, Object> headMap = (Map)object.get("head");
  80. Map<String, Object> bodyMap = (Map)object.get("body");
  81. if ("00000000".equals(head.getStr("code"))) {
  82. System.out.println("_saveStaffCollection:start"+result);
  83. List<Map<String, Object>> kczglbList = (bodyMap.containsKey("kczglb") ? (List<Map<String, Object>>) bodyMap.get("kczglb") : null);
  84. if (null != kczglbList && !kczglbList.isEmpty()) {
  85. String prefix = "person_collect_";
  86. String resource = taxUnit.getId().toString();
  87. boolean flag = CmpDistributedLockUtils.tryLock(ctx, prefix, resource);
  88. if (flag) {
  89. try {
  90. int year = taxUnit.getInt("year");
  91. String taxUnitDeductionId = this.getTaxUnitDeduction(ctx, taxUnit, year);
  92. Map<String, Integer> personMap = new HashMap();
  93. String userId = HRFilterUtils.getCurrentUserId(ctx);
  94. Iterator itgjrylb = kczglbList.iterator();
  95. while(itgjrylb.hasNext()) {
  96. Map<String, Object> stringObjectMap = (Map)itgjrylb.next();
  97. personMap.put(stringObjectMap.get("zzhm").toString(), "是".equals(stringObjectMap.get("kcbs")) ? 1 : 0);
  98. }
  99. String cardNumbers = CmpStrUtil.converMapToString(personMap);
  100. String sql = "SELECT e.fid, r.fCardNumber FROM t_hr_sTaxPersonRecordEntry e, t_hr_sTaxPersonRecord r WHERE e.fTaxUnitID = '" + resource + "' " + " and e.fBillId = r.fid " + " and r.fCardNumber IN (" + cardNumbers + ")";
  101. IRowSet rowSet = DbUtil.executeQuery(ctx, sql);
  102. Timestamp createTime = new Timestamp(System.currentTimeMillis());
  103. List<Object[]> paramList = new ArrayList();
  104. HashMap personSet = new HashMap();
  105. while(rowSet.next()) {
  106. Object[] param = new Object[10];
  107. String taxPersonRecordEntryId = rowSet.getString(1);
  108. param[0] = taxPersonRecordEntryId;
  109. Integer isDirect = (Integer)personMap.get(rowSet.getString(2));
  110. param[1] = isDirect;
  111. param[2] = taxUnitDeductionId;
  112. param[3] = userId;
  113. param[4] = createTime;
  114. param[5] = userId;
  115. param[6] = createTime;
  116. param[7] = BOSUuid.create("F831C6DA").toString();
  117. param[8] = "";
  118. param[9] = 10;
  119. personSet.put(taxPersonRecordEntryId, isDirect);
  120. paramList.add(param);
  121. }
  122. System.out.println("_saveStaffCollection:"+JSONUtil.toJsonStr(paramList));
  123. String batchSql = "INSERT INTO T_HR_STAXDIRECTDEDUCTION( FTaxPersonRecordEntryId, FISDECDUT, FTAXUNITDEDUCTIONID, FCREATORID, FCREATETIME, FLASTUPDATEUSERID, FLASTUPDATETIME, FID, FTaskId, fSate) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
  124. DbUtil.executeBatch(ctx, batchSql, paramList);
  125. sql = "UPDATE t_hr_sTaxPersonRecordEntry SET fIsDirect = ? WHERE fid = ?";
  126. paramList = new ArrayList();
  127. Iterator itPersonSet = personSet.entrySet().iterator();
  128. while(itPersonSet.hasNext()) {
  129. Map.Entry<String, Integer> entry = (Map.Entry)itPersonSet.next();
  130. Object[] param = new Object[]{entry.getValue(), entry.getKey()};
  131. paramList.add(param);
  132. }
  133. DbUtil.executeBatch(ctx, sql, paramList);
  134. System.out.println("_saveStaffCollection:"+JSONUtil.toJsonStr(paramList));
  135. } catch (Exception var33) {
  136. var33.printStackTrace();
  137. } finally {
  138. CmpDistributedLockUtils.unlock(ctx, prefix, resource);
  139. msg=MessageResult.SUCCESS(result);
  140. }
  141. }
  142. }else {
  143. msg=MessageResult.FAILED("未获取到人员6万信息!");
  144. }
  145. }else{
  146. msg=MessageResult.ERROR(result);
  147. }
  148. return msg;
  149. }
  150. protected String saveTaxUnitDeduction(Context ctx, TaxUnitInfo taxUnit, int year) throws BOSException {
  151. IObjectPK pk = null;
  152. try {
  153. String taxUnitId = taxUnit.getId().toString();
  154. String deleteSQL = "delete from t_hr_sTaxDirectDeduction where fTaxUnitDeductionId in (select fid from T_HR_STaxUnitDeduction where fTaxUnitId = '" + taxUnitId + "' and fYear = " + year + ")";
  155. System.out.println(deleteSQL);
  156. DbUtil.execute(ctx, deleteSQL);
  157. deleteSQL = "delete from T_HR_STaxUnitDeduction where fTaxUnitId = '" + taxUnitId + "' and fYear = " + year;
  158. System.out.println(deleteSQL);
  159. DbUtil.execute(ctx, deleteSQL);
  160. TaxUnitDeductionInfo info = new TaxUnitDeductionInfo();
  161. info.setTaxUnit(taxUnit);
  162. info.setYear(year);
  163. info.setIsCollection(true);
  164. pk = TaxUnitDeductionFactory.getLocalInstance(ctx).save(info);
  165. } catch (EASBizException var8) {
  166. var8.printStackTrace();
  167. }
  168. return pk.toString();
  169. }
  170. }