package com.kingdee.eas.custom.shuiyou.six.osf; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; import com.kingdee.bos.BOSException; import com.kingdee.bos.Context; import com.kingdee.bos.bsf.service.app.IHRMsfService; import com.kingdee.bos.dao.IObjectPK; import com.kingdee.bos.util.BOSUuid; import com.kingdee.eas.common.EASBizException; import com.kingdee.eas.custom.shuiyou.task.MessageResult; import com.kingdee.eas.custom.shuiyou.uitls.ISYUtilsFacade; import com.kingdee.eas.custom.shuiyou.uitls.SYUtilsFacadeFactory; import com.kingdee.eas.custom.shuiyou.uitls.URLConfigEnum; import com.kingdee.eas.util.app.DbUtil; import com.kingdee.jdbc.rowset.IRowSet; import com.kingdee.shr.base.syssetting.app.filter.HRFilterUtils; import com.kingdee.shr.base.syssetting.exception.ShrWebBizException; import com.kingdee.shr.compensation.app.tax.TaxUnitCollection; import com.kingdee.shr.compensation.app.tax.TaxUnitFactory; import com.kingdee.shr.compensation.app.tax.TaxUnitInfo; import com.kingdee.shr.compensation.app.taxCal.TaxUnitDeductionCollection; import com.kingdee.shr.compensation.app.taxCal.TaxUnitDeductionFactory; import com.kingdee.shr.compensation.app.taxCal.TaxUnitDeductionInfo; import com.kingdee.shr.compensation.util.CmpStrUtil; import com.kingdee.shr.compensation.util.lock.CmpDistributedLockUtils; import java.sql.Timestamp; import java.util.*; /** * 获取人员名单 * description: QueryPreDeductService
* date: 2024/9/25 16:24
* author: lhbj
* version: 1.0
*/ public class QueryPreDeductService implements IHRMsfService { @Override public Object process(Context context, Map map) throws EASBizException, BOSException { String this_taskid= (String) map.get("this_taskId"); String paramData= (String) map.get("paramData"); ISYUtilsFacade facade = SYUtilsFacadeFactory.getLocalInstance(context); Map config =facade.getConfig(); MessageResult msg=null; try { String result = facade.post(config.get("ip") + URLConfigEnum.QUERYPREDEDUCT_VALUE, paramData); JSONObject paramJSON = JSONUtil.parseObj(paramData); String id = paramJSON.getStr("TAXUNITID"); int year = paramJSON.getInt("skssnd"); String oql = "select id,name,number,taxNumber,areaCode,regNumber,declPassword,realPassword,isAutoDeduct where id = '" + id + "'"; TaxUnitCollection taxUnitCollection = TaxUnitFactory.getLocalInstance(context).getTaxUnitCollection(oql); if (null != taxUnitCollection && taxUnitCollection.size() > 0) { TaxUnitInfo taxUnitInfo = taxUnitCollection.get(0); String taxUnitDeductionId = this.saveTaxUnitDeduction(context, taxUnitInfo, year); Object[] param = new Object[]{null, taxUnitDeductionId, BOSUuid.create("46E337F4").toString()}; if (null != result) { //成功写入人员是否6w msg = this._saveStaffCollection(context, taxUnitInfo, result); } else { msg = MessageResult.ERROR("接口调用异常"); } } }catch (Exception e){ e.printStackTrace(); } return msg; } protected String getTaxUnitDeduction(Context ctx, TaxUnitInfo taxUnit, int year) throws BOSException { String oql = "select id where taxUnit.id = '" + taxUnit.getId().toString() + "' and year = " + year; TaxUnitDeductionCollection collection = TaxUnitDeductionFactory.getLocalInstance(ctx).getTaxUnitDeductionCollection(oql); if (null != collection && !collection.isEmpty()) { return collection.get(0).getId().toString(); } else { throw new BOSException("没有找到纳税单位归集信息"); } } protected synchronized MessageResult _saveStaffCollection(Context ctx, TaxUnitInfo taxUnit, String result) throws BOSException, ShrWebBizException { MessageResult msg=null; JSONObject object = JSONUtil.parseObj(result); JSONObject head = object.getJSONObject("head"); Map headMap = (Map)object.get("head"); Map bodyMap = (Map)object.get("body"); if ("00000000".equals(head.getStr("code"))) { System.out.println("_saveStaffCollection:start"+result); List> kczglbList = (bodyMap.containsKey("kczglb") ? (List>) bodyMap.get("kczglb") : null); if (null != kczglbList && !kczglbList.isEmpty()) { String prefix = "person_collect_"; String resource = taxUnit.getId().toString(); boolean flag = CmpDistributedLockUtils.tryLock(ctx, prefix, resource); if (flag) { try { int year = taxUnit.getInt("year"); String taxUnitDeductionId = this.getTaxUnitDeduction(ctx, taxUnit, year); Map personMap = new HashMap(); String userId = HRFilterUtils.getCurrentUserId(ctx); Iterator itgjrylb = kczglbList.iterator(); while(itgjrylb.hasNext()) { Map stringObjectMap = (Map)itgjrylb.next(); personMap.put(stringObjectMap.get("zzhm").toString(), "是".equals(stringObjectMap.get("kcbs")) ? 1 : 0); } String cardNumbers = CmpStrUtil.converMapToString(personMap); 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 + ")"; IRowSet rowSet = DbUtil.executeQuery(ctx, sql); Timestamp createTime = new Timestamp(System.currentTimeMillis()); List paramList = new ArrayList(); HashMap personSet = new HashMap(); while(rowSet.next()) { Object[] param = new Object[10]; String taxPersonRecordEntryId = rowSet.getString(1); param[0] = taxPersonRecordEntryId; Integer isDirect = (Integer)personMap.get(rowSet.getString(2)); param[1] = isDirect; param[2] = taxUnitDeductionId; param[3] = userId; param[4] = createTime; param[5] = userId; param[6] = createTime; param[7] = BOSUuid.create("F831C6DA").toString(); param[8] = ""; param[9] = 10; personSet.put(taxPersonRecordEntryId, isDirect); paramList.add(param); } System.out.println("_saveStaffCollection:"+JSONUtil.toJsonStr(paramList)); String batchSql = "INSERT INTO T_HR_STAXDIRECTDEDUCTION( FTaxPersonRecordEntryId, FISDECDUT, FTAXUNITDEDUCTIONID, FCREATORID, FCREATETIME, FLASTUPDATEUSERID, FLASTUPDATETIME, FID, FTaskId, fSate) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; DbUtil.executeBatch(ctx, batchSql, paramList); sql = "UPDATE t_hr_sTaxPersonRecordEntry SET fIsDirect = ? WHERE fid = ?"; paramList = new ArrayList(); Iterator itPersonSet = personSet.entrySet().iterator(); while(itPersonSet.hasNext()) { Map.Entry entry = (Map.Entry)itPersonSet.next(); Object[] param = new Object[]{entry.getValue(), entry.getKey()}; paramList.add(param); } DbUtil.executeBatch(ctx, sql, paramList); System.out.println("_saveStaffCollection:"+JSONUtil.toJsonStr(paramList)); } catch (Exception var33) { var33.printStackTrace(); } finally { CmpDistributedLockUtils.unlock(ctx, prefix, resource); msg=MessageResult.SUCCESS(result); } } }else { msg=MessageResult.FAILED("未获取到人员6万信息!"); } }else{ msg=MessageResult.ERROR(result); } return msg; } protected String saveTaxUnitDeduction(Context ctx, TaxUnitInfo taxUnit, int year) throws BOSException { IObjectPK pk = null; try { String taxUnitId = taxUnit.getId().toString(); String deleteSQL = "delete from t_hr_sTaxDirectDeduction where fTaxUnitDeductionId in (select fid from T_HR_STaxUnitDeduction where fTaxUnitId = '" + taxUnitId + "' and fYear = " + year + ")"; System.out.println(deleteSQL); DbUtil.execute(ctx, deleteSQL); deleteSQL = "delete from T_HR_STaxUnitDeduction where fTaxUnitId = '" + taxUnitId + "' and fYear = " + year; System.out.println(deleteSQL); DbUtil.execute(ctx, deleteSQL); TaxUnitDeductionInfo info = new TaxUnitDeductionInfo(); info.setTaxUnit(taxUnit); info.setYear(year); info.setIsCollection(true); pk = TaxUnitDeductionFactory.getLocalInstance(ctx).save(info); } catch (EASBizException var8) { var8.printStackTrace(); } return pk.toString(); } }