GetASynIndividualIncomeTaxFeedback.java 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068
  1. package com.kingdee.eas.custom.shuiyou.taxCal.service;
  2. import cn.com.servyou.dto.ApiResponse;
  3. import cn.com.servyou.dto.Head;
  4. import cn.com.servyou.dto.employee.EmployeeDeclareFeedback;
  5. import cn.com.servyou.dto.tax.*;
  6. import cn.com.servyou.rmi.client.ClientProxyFactory;
  7. import cn.com.servyou.service.TaxRequest;
  8. import com.fasterxml.jackson.core.JsonProcessingException;
  9. import com.fasterxml.jackson.databind.ObjectMapper;
  10. import com.kingdee.bos.BOSException;
  11. import com.kingdee.bos.Context;
  12. import com.kingdee.bos.bsf.service.app.IHRMsfService;
  13. import com.kingdee.bos.metadata.entity.*;
  14. import com.kingdee.bos.metadata.query.util.CompareType;
  15. import com.kingdee.eas.common.EASBizException;
  16. import com.kingdee.eas.custom.shuiyou.interfacelog.ILogInfo;
  17. import com.kingdee.eas.custom.shuiyou.interfacelog.LogInfoFactory;
  18. import com.kingdee.eas.custom.shuiyou.interfacelog.LogInfoInfo;
  19. import com.kingdee.eas.custom.shuiyou.task.MessageResult;
  20. import com.kingdee.eas.custom.shuiyou.utils.ClientProxyFactoryUtils;
  21. import com.kingdee.eas.hr.ats.AtsUtil;
  22. import com.kingdee.eas.hr.ats.util.AtsDateUtils;
  23. import com.kingdee.eas.util.app.DbUtil;
  24. import com.kingdee.jdbc.rowset.IRowSet;
  25. import com.kingdee.shr.compensation.CardTypeEnum;
  26. import com.kingdee.shr.compensation.app.incomeTax.*;
  27. import com.kingdee.shr.compensation.app.tax.base.*;
  28. import com.kingdee.shr.compensation.app.taxCal.*;
  29. import com.kingdee.util.StringUtils;
  30. import org.apache.log4j.Logger;
  31. import java.math.BigDecimal;
  32. import java.sql.SQLException;
  33. import java.text.ParseException;
  34. import java.text.SimpleDateFormat;
  35. import java.util.*;
  36. /**
  37. * @Description 获取异步算税反馈结果
  38. * @Date 2024/9/10 15:26
  39. * @Created by Heyuan
  40. */
  41. public class GetASynIndividualIncomeTaxFeedback implements IHRMsfService {
  42. private static Logger logger = Logger.getLogger(GetASynIndividualIncomeTaxFeedback.class);
  43. private String taxUnitId = null;//纳税单位id
  44. private String period = null;//税款所属期 yyyy-MM
  45. private String creator = null;//创建人id
  46. private String initIds = null;
  47. private String periodBegin = null;//税款所属期起 yyyy-MM-dd
  48. private String periodEnd = null;//税款所属期止 yyyy-MM-dd
  49. private ObjectMapper objectMapper = new ObjectMapper();
  50. //证件类型map
  51. //private static Map<String, String> cardTypeEnumMap = null;
  52. private Map<String, String> incomeItemMap = null;//所有启用的所得项目
  53. private Map<String, String> taxItemInitMap = null;//初算个税项目
  54. private Map<String, String> taxItemConfigMap = null;//明细个税项目
  55. private Map<String, String> taxPersonRecordMap = null;//报送人员信息 key:证件号码+证件类型,value:员工id
  56. @Override
  57. public MessageResult process(Context ctx, Map paramMap) throws EASBizException, BOSException {
  58. ILogInfo iLogInfo = LogInfoFactory.getLocalInstance(ctx);
  59. //接口日志实体
  60. LogInfoInfo logInfo = new LogInfoInfo();
  61. //入口
  62. logInfo.setEntrance(this.getClass().getName());
  63. logInfo.setBizDate(new Date());
  64. try {
  65. logger.info("调用 GetASynIndividualIncomeTaxFeedback, 参数 " + objectMapper.writeValueAsString(paramMap));
  66. MessageResult messageResult = null;
  67. String this_taskId = (String) paramMap.get("this_taskId");//任务id
  68. String paramData = (String) paramMap.get("paramData");
  69. Map<String, String> paramDataMap = objectMapper.readValue(paramData, Map.class);
  70. taxUnitId = paramDataMap.get("TAXUNITID");//纳税单位id
  71. period = paramDataMap.get("PERIOD");//周期yyyy-MM
  72. creator = paramDataMap.get("creator");//创建人id
  73. initIds = paramDataMap.get("initIds");//初算数据id
  74. String requestId = paramDataMap.get("requestId");
  75. StringBuilder errorMsg = new StringBuilder();
  76. if (StringUtils.isEmpty(taxUnitId)) {
  77. errorMsg.append("纳税单位id不能为空!\n");
  78. }
  79. if (StringUtils.isEmpty(period)) {
  80. errorMsg.append("周期yyyy-MM不能为空!\n");
  81. }
  82. if (StringUtils.isEmpty(requestId)) {
  83. errorMsg.append("requestId不能为空!\n");
  84. }
  85. if (errorMsg.length() > 0) {
  86. throw new BOSException(errorMsg.toString());
  87. }
  88. SimpleDateFormat shortsdf = new SimpleDateFormat("yyyy-MM");
  89. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  90. Date parse = shortsdf.parse(period);
  91. periodBegin = sdf.format(AtsDateUtils.getMonthFirstDay(parse));
  92. periodEnd = sdf.format(AtsDateUtils.getMonthLastDay(parse));
  93. //客户端代理工厂
  94. ClientProxyFactory clientProxyFactory = ClientProxyFactoryUtils.getClientProxyFactory();
  95. logInfo.setInterfaceAddress("/gateway/iit/calculateTax/getASynIndividualIncomeTaxFeedback");//接口地址
  96. logInfo.setInterfaceName("getASynIndividualIncomeTaxFeedback");//接口名
  97. logInfo.setInParameter("{\"requestId\":\"" + requestId + "\"}");//入参
  98. //算税请求接口
  99. TaxRequest taxRequest = clientProxyFactory.getTaxRequest();
  100. //调用异步算税接口
  101. ApiResponse<CalculateTaxResultRequest> apiResponse = taxRequest.getASynIndividualIncomeTaxFeedback(requestId);
  102. ObjectMapper mapper = new ObjectMapper();
  103. logInfo.setOutParameter(mapper.writeValueAsString(apiResponse));//回参
  104. Head head = apiResponse.getHead();
  105. String status = head.getStatus();
  106. String code = head.getCode();
  107. if ("100004".equals(code)) {
  108. //请求处理中
  109. messageResult = MessageResult.AGAIN(head.getMsg());
  110. logInfo.setErrorInfo(head.getMsg());//错误信息
  111. logInfo.setStatus("处理中");
  112. } else if ("000004".equals(code)) {
  113. //请求失败
  114. messageResult = MessageResult.FAILED(head.getMsg());
  115. logInfo.setErrorInfo(head.getMsg());//错误信息
  116. logInfo.setStatus("失败");
  117. } else if ("00000000".equals(code)) {
  118. logger.info("成功");
  119. //获取所有启用的所得项目
  120. incomeItemMap = getIncomeItemMap(ctx);
  121. logger.info("objectMapper.writeValueAsString(incomeItemMap) " + objectMapper.writeValueAsString(incomeItemMap));
  122. //获取个税项目
  123. getTaxItemMap(ctx);
  124. logger.info("objectMapper.writeValueAsString(taxItemInitMap) " + objectMapper.writeValueAsString(taxItemInitMap));
  125. logger.info("objectMapper.writeValueAsString(taxItemConfigMap) " + objectMapper.writeValueAsString(taxItemConfigMap));
  126. //获取报送人员信息
  127. getTaxPersonRecordMap(ctx);
  128. logger.info("objectMapper.writeValueAsString(taxPersonRecordMap) " + objectMapper.writeValueAsString(taxPersonRecordMap));
  129. //请求成功
  130. CalculateTaxResultRequest body = apiResponse.getBody();
  131. //企业名称
  132. // String qymc = body.getName();
  133. // //税号
  134. // String nsrsbh = body.getTaxNo();
  135. // //部门编号
  136. // String bmbh = body.getDeptNo();
  137. // //部门名称
  138. // String bmmc = body.getDeptName();
  139. // //行政区划代码
  140. // String areaid = body.getArea();
  141. // //税款所属期
  142. // String skssq = body.getMonth();
  143. // //外部业务订单号
  144. // String bizNo = body.getBizNo();
  145. //综合所得
  146. ComplexIncomeResultRequest complexIncomeResult = body.getComplexIncomeResultRequest();
  147. //人员申报失败列表
  148. List<EmployeeDeclareFeedback> employeeDeclareFeedbacks = complexIncomeResult.getEmployeeDeclareFeedbacks();
  149. String updateSqlTemp = "/*dialect*/update T_HR_STaxCalInitDetail set FERRORINFO = '%s',FSTATE = '50' " +
  150. "where fpersonId = '%s' and fid in (%s) and FSTATE =30";
  151. for (int i = 0; employeeDeclareFeedbacks != null && i < employeeDeclareFeedbacks.size(); i++) {
  152. EmployeeDeclareFeedback employeeDeclareFeedback = employeeDeclareFeedbacks.get(i);
  153. //失败原因
  154. String message = employeeDeclareFeedback.getMessage();
  155. if (!StringUtils.isEmpty(message)) {
  156. //姓名
  157. String name = employeeDeclareFeedback.getName();
  158. //证件类型名称
  159. String licenseType = employeeDeclareFeedback.getLicenseType();
  160. //证件号码
  161. String licenseNumber = employeeDeclareFeedback.getLicenseNumber();
  162. //员工id
  163. String personId = taxPersonRecordMap.get(licenseNumber + licenseType);
  164. if (StringUtils.isEmpty(personId)) {
  165. logger.error("未匹配到人员 证件号: " + licenseNumber + " 证件类型: " + licenseType);
  166. continue;
  167. }
  168. //报送状态 1 待报送 2 代报中 3 代报失败 4 代报成功
  169. //String submissionState = employeeDeclareFeedback.getSubmissionState();
  170. //人员验证状态 0 若是身份证,状态为验证中;其他证件为暂不验证 1 验证通过 2 验证不通过 4 待验证 9 同代码0处理
  171. //String authenticationState = employeeDeclareFeedback.getAuthenticationState();
  172. //专项报送状态 2 代报成功 3 代报失败
  173. //String deductionSubmissionState = employeeDeclareFeedback.getDeductionSubmissionState();
  174. //专项报送结果原因
  175. //String deductionMessage = employeeDeclareFeedback.getDeductionMessage();
  176. try {
  177. logger.error("报送失败人员 " + name);
  178. logger.error("报送失败原因 " + message);
  179. String updateSql = String.format(updateSqlTemp, message, personId, initIds);
  180. logger.error("报送失败更新sql " + updateSql);
  181. DbUtil.execute(ctx, updateSql);
  182. } catch (Exception e) {
  183. e.printStackTrace();
  184. }
  185. }
  186. }
  187. logger.error("正常工资薪金算税结果对象");
  188. //正常工资薪金算税结果对象
  189. ComplexTaxCalculateResult normalSalarySpecIncome = complexIncomeResult.getNormalSalarySpecIncome();
  190. handleComplexTaxCalculateResult(ctx, normalSalarySpecIncome);
  191. logger.error("全年一次性奖金收入算税结果对象");
  192. //全年一次性奖金收入算税结果对象
  193. ComplexTaxCalculateResult annualOneTimeBonusIncome = complexIncomeResult.getAnnualOneTimeBonusIncome();
  194. handleComplexTaxCalculateResult(ctx, annualOneTimeBonusIncome);
  195. logger.error("一般劳务报酬算税结果对象");
  196. //一般劳务报酬算税结果对象
  197. ComplexTaxCalculateResult laborRemunerationIncome = complexIncomeResult.getLaborRemunerationIncome();
  198. handleComplexTaxCalculateResult(ctx, laborRemunerationIncome);
  199. logger.error("解除劳动合同一次性补偿金算税结果对象");
  200. //解除劳动合同一次性补偿金算税结果对象
  201. ComplexTaxCalculateResult compensateIncome = complexIncomeResult.getCompensateIncome();
  202. handleComplexTaxCalculateResult(ctx, compensateIncome);
  203. messageResult = MessageResult.SUCCESS();
  204. }
  205. logger.error("保存日志对象");
  206. iLogInfo.addnew(logInfo);
  207. logger.error("返回结果");
  208. return messageResult;
  209. } catch (Exception e) {
  210. e.printStackTrace();
  211. logInfo.setErrorInfo(e.getMessage());//错误信息
  212. iLogInfo.addnew(logInfo);
  213. return MessageResult.ERROR(e.getMessage());
  214. }
  215. }
  216. /**
  217. * 处理所得项目算税结果
  218. *
  219. * @param ctx
  220. * @param normalSalarySpecIncome
  221. * @throws BOSException
  222. */
  223. private void handleComplexTaxCalculateResult(
  224. Context ctx,
  225. ComplexTaxCalculateResult normalSalarySpecIncome)
  226. throws BOSException, JsonProcessingException {
  227. logger.info("handleComplexTaxCalculateResult:" + objectMapper.writeValueAsString(normalSalarySpecIncome));
  228. if (normalSalarySpecIncome != null) {
  229. //算税总人数
  230. Integer totalPeople = normalSalarySpecIncome.getTotalPeople();
  231. //算税失败人数
  232. Integer failedPeople = normalSalarySpecIncome.getFailedPeople();
  233. //年金上限
  234. BigDecimal annuityLimit = normalSalarySpecIncome.getAnnuityLimit();
  235. //公积金上限
  236. BigDecimal houseProvidentFundLimit = normalSalarySpecIncome.getHouseProvidentFundLimit();
  237. //年平均工资
  238. BigDecimal averageAnnual = normalSalarySpecIncome.getAverageAnnual();
  239. //企业在电子税务局上月是否已申报(仅正常工资薪金有效) 0:上月未申报 1:上月已申报 2:上上月未申报
  240. String etaxDeclaredLastMonth = normalSalarySpecIncome.getEtaxDeclaredLastMonth();
  241. //综合算税成功列表
  242. List<ComplexIncome> successComplexIncomes = normalSalarySpecIncome.getSuccessComplexIncomes();
  243. handleSuccessComplexIncome(ctx, successComplexIncomes);
  244. //综合算税失败薪资列表
  245. List<ComplexIncome> failedComplexIncomes = normalSalarySpecIncome.getFailedComplexIncomes();
  246. //handleFailedComplexIncome(failedComplexIncomes);
  247. //失败算税原因列表
  248. List<CheckTaxCalResult> failedCheckTaxCalResult = normalSalarySpecIncome.getFailedCheckTaxCalResult();
  249. handleFailedCheckTaxCalResult(ctx, failedCheckTaxCalResult);
  250. }
  251. }
  252. /**
  253. * 处理综合算税成功列表
  254. */
  255. private void handleSuccessComplexIncome(Context ctx, List<ComplexIncome> successComplexIncomes) throws BOSException {
  256. if (successComplexIncomes != null) {
  257. //SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  258. StringBuilder updateSql = new StringBuilder();
  259. updateSql.append("/*dialect*/update T_HR_STaxCalInitDetail set FSTATE = '40',FERRORINFO = '成功', ");
  260. for (String key : taxItemInitMap.keySet()) {
  261. String tableField = taxItemInitMap.get(key);
  262. updateSql.append(tableField).append("=?, ");
  263. }
  264. updateSql.deleteCharAt(updateSql.lastIndexOf(","));
  265. updateSql.append(" where fpersonId = ? ");
  266. updateSql.append(" and FTAXUNITID=? and to_char(FPERIODBEGIN,'yyyy-mm-dd') >= ? and to_char(FPERIODEND,'yyyy-mm-dd') <= ? and FINCOMEITEMID=? and FSTATE =30");
  267. List<Object[]> sqlParams = new ArrayList<>();
  268. Set<String> personIds = new HashSet<>();
  269. Set<String> incomeitemIds = new HashSet<>();
  270. for (int i = 0; successComplexIncomes != null && i < successComplexIncomes.size(); i++) {
  271. ComplexIncome complexIncome = successComplexIncomes.get(i);
  272. Map incomeDataMap = new HashMap();
  273. List updateList = new ArrayList();
  274. //姓名
  275. String name = complexIncome.getName();
  276. //证件类型名称
  277. String licenseType = complexIncome.getLicenseType();
  278. //String cardTypeValue = cardTypeEnumMap.get(licenseType);
  279. //证件号码
  280. String licenseNumber = complexIncome.getLicenseNumber();
  281. //员工id
  282. String personId = taxPersonRecordMap.get(licenseNumber + licenseType);
  283. if (StringUtils.isEmpty(personId)) {
  284. logger.error("未匹配到人员 证件号: " + licenseNumber + " 证件类型: " + licenseType);
  285. continue;
  286. }
  287. //受雇日期
  288. //String employedDate = complexIncome.getEmployedDate();
  289. //离职日期
  290. //String resignDate = complexIncome.getResignDate();
  291. //是否明细申报
  292. //String isDetailedDeclaration = complexIncome.getIsDetailedDeclaration();
  293. //当期收入额
  294. BigDecimal income = complexIncome.getIncome();
  295. incomeDataMap.put("sre", income);
  296. //免税收入
  297. BigDecimal exemptIncome = complexIncome.getExemptIncome();
  298. incomeDataMap.put("mssd", exemptIncome);
  299. //基本养老保险
  300. BigDecimal endowmentInsurance = complexIncome.getEndowmentInsurance();
  301. incomeDataMap.put("jbylaobxf", endowmentInsurance);
  302. //基本医疗保险
  303. BigDecimal medicalInsurance = complexIncome.getMedicalInsurance();
  304. incomeDataMap.put("jbylbxf", medicalInsurance);
  305. //失业保险
  306. BigDecimal unemploymentInsurance = complexIncome.getUnemploymentInsurance();
  307. incomeDataMap.put("sybxf", unemploymentInsurance);
  308. //住房公积金
  309. BigDecimal houseProvidentFund = complexIncome.getHouseProvidentFund();
  310. incomeDataMap.put("zfgjj", houseProvidentFund);
  311. //原始住房公积金
  312. BigDecimal originalHouseProvidentFund = complexIncome.getOriginalHouseProvidentFund();
  313. //子女教育支出
  314. BigDecimal childEducationExpenditure = complexIncome.getChildEducationExpenditure();
  315. incomeDataMap.put("dyznjyzc", childEducationExpenditure);
  316. //赡养老人支出
  317. BigDecimal supportElderExpenditure = complexIncome.getSupportElderExpenditure();
  318. incomeDataMap.put("dysylrzc", supportElderExpenditure);
  319. //住房租金支出
  320. BigDecimal houseRentExpenditure = complexIncome.getHouseRentExpenditure();
  321. incomeDataMap.put("dyzfzjzc", houseRentExpenditure);
  322. //房屋贷款支出
  323. BigDecimal houseLoanExpenditure = complexIncome.getHouseLoanExpenditure();
  324. incomeDataMap.put("dyfwdkzc", houseLoanExpenditure);
  325. //继续教育支出
  326. BigDecimal continueEducationExpenditure = complexIncome.getContinueEducationExpenditure();
  327. incomeDataMap.put("dyjxjyzc", continueEducationExpenditure);
  328. //非学历继续教育支出
  329. BigDecimal unDegreeContinueEducationExpenditure = complexIncome.getUnDegreeContinueEducationExpenditure();
  330. incomeDataMap.put("dyfxljxjyzc", unDegreeContinueEducationExpenditure);
  331. //婴幼儿照护支出
  332. BigDecimal babyCareExpenditure = complexIncome.getBabyCareExpenditure();
  333. incomeDataMap.put("dyyyrzhzc", babyCareExpenditure);
  334. //企业年金/职业年金
  335. BigDecimal annuity = complexIncome.getAnnuity();
  336. incomeDataMap.put("nj", annuity);
  337. //商业健康保险
  338. BigDecimal commercialHealthInsurance = complexIncome.getCommercialHealthInsurance();
  339. incomeDataMap.put("syjkbx", commercialHealthInsurance);
  340. //税延养老保险
  341. BigDecimal extensionEndowmentInsurance = complexIncome.getExtensionEndowmentInsurance();
  342. incomeDataMap.put("syylbx", extensionEndowmentInsurance);
  343. //其他
  344. BigDecimal other = complexIncome.getOther();
  345. incomeDataMap.put("qt", other);
  346. //减免税额
  347. BigDecimal taxDeduction = complexIncome.getTaxDeduction();
  348. incomeDataMap.put("jmse", taxDeduction);
  349. //备注 根据政策要求,填写【其他】项,一定在备注中写明具体扣除项目名称
  350. String remark = complexIncome.getRemark();
  351. incomeDataMap.put("bz", remark);
  352. //减除费用
  353. BigDecimal deductionAmount = complexIncome.getDeductionAmount();
  354. incomeDataMap.put("qzd", deductionAmount);
  355. //其他扣除合计
  356. BigDecimal otherDeductionSum = complexIncome.getOtherDeductionSum();
  357. incomeDataMap.put("qtckhj", otherDeductionSum);
  358. //应纳税所得额
  359. BigDecimal taxableIncome = complexIncome.getTaxableIncome();
  360. incomeDataMap.put("ynssde", taxableIncome);
  361. //应纳税额
  362. BigDecimal payableAmount = complexIncome.getPayableAmount();
  363. //已缴税额
  364. BigDecimal paidAmount = complexIncome.getPaidAmount();
  365. //应扣缴税额
  366. BigDecimal withholdingAmount = complexIncome.getWithholdingAmount();
  367. //税率
  368. BigDecimal taxRate = complexIncome.getTaxRate();
  369. incomeDataMap.put("sl", taxRate);
  370. //速算扣除数
  371. BigDecimal quickDeduction = complexIncome.getQuickDeduction();
  372. incomeDataMap.put("sskcs", quickDeduction);
  373. //所得项目名称
  374. String incomeItemName = complexIncome.getIncomeItemName();
  375. if (!incomeItemMap.containsKey(incomeItemName)) {
  376. logger.error("未匹配到所得项目 名称为: " + incomeItemName);
  377. continue;
  378. }
  379. String incomeItemId = incomeItemMap.get(incomeItemName);
  380. incomeDataMap.put("sdxm", incomeItemId);
  381. //应补退税额 累计应扣缴税额-累计已缴税额
  382. BigDecimal refundTax = complexIncome.getRefundTax();
  383. incomeDataMap.put("bqybtse", refundTax);
  384. //累计收入额 本年累计收入=本期所有的工资薪金所得收入之和+往期工资薪金所得收入之和(见税款计算)
  385. BigDecimal accumulatedIncome = complexIncome.getAccumulatedIncome();
  386. incomeDataMap.put("bqljsre", accumulatedIncome);
  387. //累计免税收入额
  388. BigDecimal accumulatedExemptIncome = complexIncome.getAccumulatedExemptIncome();
  389. incomeDataMap.put("bqljmssr", accumulatedExemptIncome);
  390. //累计专项扣除额
  391. BigDecimal accumulatedSpecDeduction = complexIncome.getAccumulatedSpecDeduction();
  392. incomeDataMap.put("zxkchj", accumulatedSpecDeduction);
  393. //累计专项(附加)扣除额
  394. BigDecimal accumulatedSpecAttachDeduction = complexIncome.getAccumulatedSpecAttachDeduction();
  395. incomeDataMap.put("zxfjkchj", accumulatedSpecAttachDeduction);
  396. //累计其他扣除额
  397. BigDecimal accumulatedOtherDeduction = complexIncome.getAccumulatedOtherDeduction();
  398. incomeDataMap.put("qtckhj", accumulatedOtherDeduction);
  399. //累计减免税额
  400. BigDecimal accumulatedTaxDeduction = complexIncome.getAccumulatedTaxDeduction();
  401. incomeDataMap.put("ljjmse", accumulatedTaxDeduction);
  402. //累计减除费用额
  403. BigDecimal accumulatedDeductionAmount = complexIncome.getAccumulatedDeductionAmount();
  404. incomeDataMap.put("jcfy", accumulatedDeductionAmount);
  405. //todo 累计月减除费用
  406. BigDecimal accumulatedMonthDeduction = complexIncome.getAccumulatedMonthDeduction();
  407. //累计应纳税所得额
  408. BigDecimal accumulatedTaxableIncome = complexIncome.getAccumulatedTaxableIncome();
  409. incomeDataMap.put("ljynssde", accumulatedTaxableIncome);
  410. //累计应纳税额
  411. BigDecimal accumulatedPayableAmount = complexIncome.getAccumulatedPayableAmount();
  412. incomeDataMap.put("ljynse", accumulatedPayableAmount);
  413. //累计应扣缴税额 累计应纳税额 - 累计减免税额
  414. BigDecimal accumulatedWithholdingAmount = complexIncome.getAccumulatedWithholdingAmount();
  415. incomeDataMap.put("ljyingkjse", accumulatedWithholdingAmount);
  416. //累计子女教育支出
  417. BigDecimal accumulatedChildEducation = complexIncome.getAccumulatedChildEducation();
  418. incomeDataMap.put("znjyzc", accumulatedChildEducation);
  419. //累计继续教育支出
  420. BigDecimal accumulatedContinueEducation = complexIncome.getAccumulatedContinueEducation();
  421. incomeDataMap.put("jxjyzc", accumulatedContinueEducation);
  422. //累计学历继续教育支出
  423. BigDecimal accumulatedDegreeContinueEducationLimit = complexIncome.getAccumulatedDegreeContinueEducationLimit();
  424. incomeDataMap.put("ljxljxjyzc", accumulatedDegreeContinueEducationLimit);
  425. //累计非学历继续教育支出
  426. BigDecimal accumulatedUnDegreeContinueEducationLimit = complexIncome.getAccumulatedUnDegreeContinueEducationLimit();
  427. incomeDataMap.put("ljfxljxjyzc", accumulatedUnDegreeContinueEducationLimit);
  428. //累计住房租金支出
  429. BigDecimal accumulatedHouseRent = complexIncome.getAccumulatedHouseRent();
  430. incomeDataMap.put("zfzjzc", accumulatedHouseRent);
  431. //累计房屋贷款支出
  432. BigDecimal accumulatedHouseLoan = complexIncome.getAccumulatedHouseLoan();
  433. incomeDataMap.put("zfdklxzc", accumulatedHouseLoan);
  434. //累计赡养老人支出
  435. BigDecimal accumulatedSupportElder = complexIncome.getAccumulatedSupportElder();
  436. incomeDataMap.put("sylrzc", accumulatedSupportElder);
  437. //todo 累计3岁以下婴幼儿照护支出
  438. BigDecimal accumulatedBabyCare = complexIncome.getAccumulatedBabyCare();
  439. incomeDataMap.put("yyezhfzc", accumulatedBabyCare);
  440. //累计准予扣除的捐赠额
  441. BigDecimal accumulatedDeductibleDonation = complexIncome.getAccumulatedDeductibleDonation();
  442. incomeDataMap.put("ljzykcdjze", accumulatedDeductibleDonation);
  443. //累计个人养老金
  444. BigDecimal accumulatedPersonalPension = complexIncome.getAccumulatedPersonalPension();
  445. incomeDataMap.put("grylj", accumulatedPersonalPension);
  446. //todo 累计个人养老金校验码
  447. String accumulatedPersonalPensionCheckCode = complexIncome.getAccumulatedPersonalPensionCheckCode();
  448. //准予扣除的捐赠额
  449. BigDecimal deductibleDonation = complexIncome.getDeductibleDonation();
  450. incomeDataMap.put("zykcjze", deductibleDonation);
  451. //累计已缴税额
  452. BigDecimal accumulatedPaidAmount = complexIncome.getAccumulatedPaidAmount();
  453. //incomeDataMap.put("ykjse", accumulatedPaidAmount);
  454. //企业上月是否已申报
  455. String etaxDeclaredLastMonth = complexIncome.getEtaxDeclaredLastMonth();
  456. //员工在税局累计已扣缴的税额
  457. BigDecimal etaxAccumulatedPaidAmount = complexIncome.getEtaxAccumulatedPaidAmount();
  458. //incomeDataMap.put("ykjse", etaxAccumulatedPaidAmount);
  459. //本月已累计扣除税额
  460. BigDecimal monthAccumulatedWithholdingAmount = complexIncome.getMonthAccumulatedWithholdingAmount();
  461. incomeDataMap.put("ykjse", etaxAccumulatedPaidAmount);
  462. //本次应扣缴税额
  463. BigDecimal currentWithholdingAmount = complexIncome.getCurrentWithholdingAmount();
  464. incomeDataMap.put("ykjse", etaxAccumulatedPaidAmount);
  465. //允许扣除的税费
  466. BigDecimal taxDeductible = complexIncome.getTaxDeductible();
  467. incomeDataMap.put("yxkcsf", taxDeductible);
  468. //展业成本
  469. BigDecimal exhibitionCost = complexIncome.getExhibitionCost();
  470. incomeDataMap.put("zycb", exhibitionCost);
  471. //月减除费用
  472. BigDecimal monthDeduction = complexIncome.getMonthDeduction();
  473. incomeDataMap.put("qzd", monthDeduction);
  474. //分摊年度数
  475. Integer apportionYears = complexIncome.getApportionYears();
  476. //年减除费用 默认为60000
  477. BigDecimal yearDeduction = complexIncome.getYearDeduction();
  478. //封装更新参数
  479. for (String key : taxItemInitMap.keySet()) {
  480. updateList.add(incomeDataMap.get(key));
  481. }
  482. updateList.add(personId);
  483. updateList.add(taxUnitId);
  484. updateList.add(periodBegin);
  485. updateList.add(periodEnd);
  486. updateList.add(incomeItemId);
  487. sqlParams.add(updateList.toArray());
  488. if (!personIds.contains(personId)) {
  489. personIds.add(personId);
  490. }
  491. if (!incomeitemIds.contains(incomeItemId)) {
  492. incomeitemIds.add(incomeItemId);
  493. }
  494. }
  495. try {
  496. logger.info("updateSql: " + updateSql);
  497. logger.info("处理综合算税成功列表 sqlParams " + objectMapper.writeValueAsString(sqlParams));
  498. if (!sqlParams.isEmpty()) {
  499. DbUtil.executeBatch(ctx, updateSql.toString(), sqlParams);
  500. }
  501. } catch (Exception e) {
  502. e.printStackTrace();
  503. throw new BOSException("处理处理综合算税成功列表,更新初算数据报错:" + e.getMessage());
  504. }
  505. //生成个税应用+税款计算最终拆分明细表
  506. try {
  507. logger.info("处理综合算税成功列表 personIds " + objectMapper.writeValueAsString(personIds));
  508. logger.info("处理综合算税成功列表 incomeitemIds " + objectMapper.writeValueAsString(incomeitemIds));
  509. if (!personIds.isEmpty() && !incomeitemIds.isEmpty()) {
  510. generateOrUpdateTaxCalConfigDetail(ctx, personIds, incomeitemIds);
  511. }
  512. } catch (Exception e) {
  513. e.printStackTrace();
  514. throw new BOSException("处理处理综合算税成功列表,生成个税应用+税款计算最终拆分明细表报错:" + e.getMessage());
  515. }
  516. }
  517. }
  518. /**
  519. * 处理综合算税失败薪资列表
  520. *
  521. * @param failedComplexIncomes
  522. */
  523. private void handleFailedComplexIncome(List<ComplexIncome> failedComplexIncomes) {
  524. for (int i = 0; failedComplexIncomes != null && i < failedComplexIncomes.size(); i++) {
  525. ComplexIncome complexIncome = failedComplexIncomes.get(i);
  526. //姓名
  527. String name = complexIncome.getName();
  528. //证件类型名称
  529. String licenseType = complexIncome.getLicenseType();
  530. //证件号码
  531. String licenseNumber = complexIncome.getLicenseNumber();
  532. //受雇日期
  533. String employedDate = complexIncome.getEmployedDate();
  534. //离职日期
  535. String resignDate = complexIncome.getResignDate();
  536. //是否明细申报
  537. String isDetailedDeclaration = complexIncome.getIsDetailedDeclaration();
  538. //当期收入额
  539. BigDecimal income = complexIncome.getIncome();
  540. //免税收入
  541. BigDecimal exemptIncome = complexIncome.getExemptIncome();
  542. //基本养老保险
  543. BigDecimal endowmentInsurance = complexIncome.getEndowmentInsurance();
  544. //基本医疗保险
  545. BigDecimal medicalInsurance = complexIncome.getMedicalInsurance();
  546. //失业保险
  547. BigDecimal unemploymentInsurance = complexIncome.getUnemploymentInsurance();
  548. //住房公积金
  549. BigDecimal houseProvidentFund = complexIncome.getHouseProvidentFund();
  550. //原始住房公积金
  551. //BigDecimal originalHouseProvidentFund = complexIncome.getOriginalHouseProvidentFund();
  552. //子女教育支出
  553. BigDecimal childEducationExpenditure = complexIncome.getChildEducationExpenditure();
  554. //赡养老人支出
  555. BigDecimal supportElderExpenditure = complexIncome.getSupportElderExpenditure();
  556. //住房租金支出
  557. BigDecimal houseRentExpenditure = complexIncome.getHouseRentExpenditure();
  558. //房屋贷款支出
  559. BigDecimal houseLoanExpenditure = complexIncome.getHouseLoanExpenditure();
  560. //继续教育支出
  561. BigDecimal continueEducationExpenditure = complexIncome.getContinueEducationExpenditure();
  562. //非学历继续教育支出
  563. BigDecimal unDegreeContinueEducationExpenditure = complexIncome.getUnDegreeContinueEducationExpenditure();
  564. //婴幼儿照护支出
  565. BigDecimal babyCareExpenditure = complexIncome.getBabyCareExpenditure();
  566. //企业年金/职业年金
  567. BigDecimal annuity = complexIncome.getAnnuity();
  568. //商业健康保险
  569. BigDecimal commercialHealthInsurance = complexIncome.getCommercialHealthInsurance();
  570. //税延养老保险
  571. BigDecimal extensionEndowmentInsurance = complexIncome.getExtensionEndowmentInsurance();
  572. //其他
  573. BigDecimal other = complexIncome.getOther();
  574. //减免税额
  575. BigDecimal taxDeduction = complexIncome.getTaxDeduction();
  576. //备注
  577. String remark = complexIncome.getRemark();
  578. //减除费用
  579. BigDecimal deductionAmount = complexIncome.getDeductionAmount();
  580. //其他扣除合计
  581. BigDecimal otherDeductionSum = complexIncome.getOtherDeductionSum();
  582. //应纳税所得额
  583. BigDecimal taxableIncome = complexIncome.getTaxableIncome();
  584. //应纳税额
  585. BigDecimal payableAmount = complexIncome.getPayableAmount();
  586. //已缴税额
  587. BigDecimal paidAmount = complexIncome.getPaidAmount();
  588. //应扣缴税额
  589. BigDecimal withholdingAmount = complexIncome.getWithholdingAmount();
  590. //税率
  591. BigDecimal taxRate = complexIncome.getTaxRate();
  592. //速算扣除数
  593. BigDecimal quickDeduction = complexIncome.getQuickDeduction();
  594. //所得项目名称
  595. String incomeItemName = complexIncome.getIncomeItemName();
  596. //应补退税额
  597. BigDecimal refundTax = complexIncome.getRefundTax();
  598. //累计收入额
  599. BigDecimal accumulatedIncome = complexIncome.getAccumulatedIncome();
  600. //累计免税收入额
  601. BigDecimal accumulatedExemptIncome = complexIncome.getAccumulatedExemptIncome();
  602. //累计专项扣除额
  603. BigDecimal accumulatedSpecDeduction = complexIncome.getAccumulatedSpecDeduction();
  604. //累计专项(附加)扣除额
  605. BigDecimal accumulatedSpecAttachDeduction = complexIncome.getAccumulatedSpecAttachDeduction();
  606. //累计其他扣除额
  607. BigDecimal accumulatedOtherDeduction = complexIncome.getAccumulatedOtherDeduction();
  608. //累计减免税额
  609. BigDecimal accumulatedTaxDeduction = complexIncome.getAccumulatedTaxDeduction();
  610. //累计减除费用额
  611. BigDecimal accumulatedDeductionAmount = complexIncome.getAccumulatedDeductionAmount();
  612. //累计月减除费用
  613. BigDecimal accumulatedMonthDeduction = complexIncome.getAccumulatedMonthDeduction();
  614. //累计应纳税所得额
  615. BigDecimal accumulatedTaxableIncome = complexIncome.getAccumulatedTaxableIncome();
  616. //累计应纳税额
  617. BigDecimal accumulatedPayableAmount = complexIncome.getAccumulatedPayableAmount();
  618. //累计应扣缴税额
  619. BigDecimal accumulatedWithholdingAmount = complexIncome.getAccumulatedWithholdingAmount();
  620. //累计子女教育支出
  621. BigDecimal accumulatedChildEducation = complexIncome.getAccumulatedChildEducation();
  622. //累计继续教育支出
  623. BigDecimal accumulatedContinueEducation = complexIncome.getAccumulatedContinueEducation();
  624. //累计学历继续教育支出
  625. BigDecimal accumulatedDegreeContinueEducationLimit = complexIncome.getAccumulatedDegreeContinueEducationLimit();
  626. //累计非学历继续教育支出
  627. BigDecimal accumulatedUnDegreeContinueEducationLimit = complexIncome.getAccumulatedUnDegreeContinueEducationLimit();
  628. //累计住房租金支出
  629. BigDecimal accumulatedHouseRent = complexIncome.getAccumulatedHouseRent();
  630. //累计房屋贷款支出
  631. BigDecimal accumulatedHouseLoan = complexIncome.getAccumulatedHouseLoan();
  632. //累计赡养老人支出
  633. BigDecimal accumulatedSupportElder = complexIncome.getAccumulatedSupportElder();
  634. //累计3岁以下婴幼儿照护支出
  635. BigDecimal accumulatedBabyCare = complexIncome.getAccumulatedBabyCare();
  636. //累计准予扣除的捐赠额
  637. BigDecimal accumulatedDeductibleDonation = complexIncome.getAccumulatedDeductibleDonation();
  638. //累计个人养老金
  639. BigDecimal accumulatedPersonalPension = complexIncome.getAccumulatedPersonalPension();
  640. //累计个人养老金校验码
  641. String accumulatedPersonalPensionCheckCode = complexIncome.getAccumulatedPersonalPensionCheckCode();
  642. //准予扣除的捐赠额
  643. BigDecimal deductibleDonation = complexIncome.getDeductibleDonation();
  644. //累计已缴税额
  645. BigDecimal accumulatedPaidAmount = complexIncome.getAccumulatedPaidAmount();
  646. //企业上月是否已申报:
  647. String etaxDeclaredLastMonth = complexIncome.getEtaxDeclaredLastMonth();
  648. //员工在税局累计已扣缴的税额
  649. BigDecimal etaxAccumulatedPaidAmount = complexIncome.getEtaxAccumulatedPaidAmount();
  650. //本月已累计扣除税额
  651. BigDecimal monthAccumulatedWithholdingAmount = complexIncome.getMonthAccumulatedWithholdingAmount();
  652. //本次应扣缴税额
  653. BigDecimal currentWithholdingAmount = complexIncome.getCurrentWithholdingAmount();
  654. //允许扣除的税费
  655. BigDecimal taxDeductible = complexIncome.getTaxDeductible();
  656. //展业成本
  657. BigDecimal exhibitionCost = complexIncome.getExhibitionCost();
  658. //月减除费用
  659. BigDecimal monthDeduction = complexIncome.getMonthDeduction();
  660. //分摊年度数
  661. Integer apportionYears = complexIncome.getApportionYears();
  662. //年减除费用 默认为60000
  663. BigDecimal yearDeduction = complexIncome.getYearDeduction();
  664. }
  665. }
  666. /**
  667. * 处理失败算税原因列表
  668. *
  669. * @param failedCheckTaxCalResult
  670. */
  671. private void handleFailedCheckTaxCalResult(
  672. Context ctx,
  673. List<CheckTaxCalResult> failedCheckTaxCalResult)
  674. throws BOSException, JsonProcessingException {
  675. logger.info("handleFailedCheckTaxCalResult:" + objectMapper.writeValueAsString(failedCheckTaxCalResult));
  676. if (failedCheckTaxCalResult != null) {
  677. String updateSql = "/*dialect*/update T_HR_STaxCalInitDetail set FERRORINFO = ?,FSTATE = '50' " +
  678. "where fpersonId = ? " +
  679. "and FTAXUNITID=? and to_char(FPERIODBEGIN,'yyyy-mm-dd') >= ? and to_char(FPERIODEND,'yyyy-mm-dd') <= ? and FINCOMEITEMID=? and FSTATE =30";
  680. List<Object[]> udpateParameter = new ArrayList<>();
  681. for (int i = 0; failedCheckTaxCalResult != null && i < failedCheckTaxCalResult.size(); i++) {
  682. List list = new ArrayList();
  683. CheckTaxCalResult checkTaxCalResult = failedCheckTaxCalResult.get(i);
  684. //证件类型名称
  685. String licenseType = checkTaxCalResult.getLicenseType();
  686. //String cardTypeValue = cardTypeEnumMap.get(licenseType);
  687. //证件号码
  688. String licenseNumber = checkTaxCalResult.getLicenseNumber();
  689. //员工id
  690. String personId = taxPersonRecordMap.get(licenseNumber + licenseType);
  691. if (StringUtils.isEmpty(personId)) {
  692. logger.error("未匹配到人员 证件号: " + licenseNumber + " 证件类型: " + licenseType);
  693. continue;
  694. }
  695. //人员id
  696. Long employeeId = checkTaxCalResult.getEmployeeId();
  697. //人员名称
  698. String employeeName = checkTaxCalResult.getEmployeeName();
  699. //错误码
  700. String errorCode = checkTaxCalResult.getErrorCode();
  701. //错误信息
  702. String errorMessage = checkTaxCalResult.getErrorMessage();
  703. //所得税表的code
  704. String incomeItemCode = checkTaxCalResult.getIncomeItemCode();
  705. //所得税表的name
  706. String incomeItemName = checkTaxCalResult.getIncomeItemName();
  707. if (!incomeItemMap.containsKey(incomeItemName)) {
  708. logger.error("未匹配到所得项目 名称为: " + incomeItemName);
  709. continue;
  710. }
  711. String incomeItemId = incomeItemMap.get(incomeItemName);
  712. list.add(errorMessage);
  713. list.add(personId);
  714. list.add(taxUnitId);
  715. list.add(periodBegin);
  716. list.add(periodEnd);
  717. list.add(incomeItemId);
  718. udpateParameter.add(list.toArray());
  719. }
  720. try {
  721. logger.error("处理失败算税原因列表 updateSql " + updateSql);
  722. logger.error("处理失败算税原因列表 udpateParameter " + objectMapper.writeValueAsString(udpateParameter));
  723. if (!udpateParameter.isEmpty()) {
  724. DbUtil.executeBatch(ctx, updateSql, udpateParameter);
  725. }
  726. } catch (BOSException e) {
  727. e.printStackTrace();
  728. throw new BOSException("更新处理失败算税原因列表报错: " + e.getMessage());
  729. }
  730. }
  731. }
  732. /**
  733. * 生成个税应用+税款计算最终拆分明细表
  734. * 先新增再更新
  735. */
  736. private void generateOrUpdateTaxCalConfigDetail(Context ctx,
  737. Set<String> personIds,
  738. Set<String> incomeitemIds) throws BOSException, SQLException, ParseException, JsonProcessingException {
  739. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  740. Date periodBeginDate = sdf.parse(periodBegin);
  741. Date periodEndDate = sdf.parse(periodEnd);
  742. //先查出计算成功的初算数据(人员、纳税单位id、周期、所得项目、状态=成功)
  743. ITaxCalConfigDetail iTaxCalConfigDetail = TaxCalConfigDetailFactory.getLocalInstance(ctx);
  744. StringBuilder querySql = new StringBuilder();
  745. querySql.append("SELECT fid,fpersonId,fincomeitemid,FCALSCHEMEID,FCMPCALTABLEID,FTAXUNITID from T_HR_STaxCalInitDetail where").append("\n");
  746. querySql.append(" fpersonId in(").append(AtsUtil.convertSetToString(personIds)).append(")").append("\n");
  747. querySql.append(" and to_char(FPERIODBEGIN, 'yyyy-mm-dd') >= '").append(periodBegin).append("'").append("\n");
  748. querySql.append(" and to_char(FPERIODEND, 'yyyy-mm-dd') <= '").append(periodEnd).append("'").append("\n");
  749. querySql.append(" and FINCOMEITEMID in(").append(AtsUtil.convertSetToString(incomeitemIds)).append(")").append("\n");
  750. querySql.append(" and FTAXUNITID = '").append(taxUnitId).append("'").append("\n");
  751. querySql.append(" and FSTATE = '40'").append("\n");
  752. logger.info("generateOrUpdateTaxCalConfigDetail.sql: " + querySql);
  753. IRowSet iRowSet = DbUtil.executeQuery(ctx, querySql.toString());
  754. List<Map<String, String>> list = new ArrayList<>();
  755. while (iRowSet.next()) {
  756. Map<String, String> map = new HashMap<>();
  757. map.put("initId", iRowSet.getString("fid"));
  758. map.put("personId", iRowSet.getString("fpersonId"));
  759. map.put("incomeitemid", iRowSet.getString("FINCOMEITEMID"));
  760. map.put("calSchemeId", iRowSet.getString("FCALSCHEMEID"));
  761. map.put("cmpCalTableId", iRowSet.getString("FCMPCALTABLEID"));
  762. map.put("taxUnitId", iRowSet.getString("FTAXUNITID"));
  763. list.add(map);
  764. }
  765. //用初算数据生成明细表(需要判断明细表数据是否已经生成过)
  766. Set<String> initIds = new HashSet<>();
  767. Set<String> configIds = new HashSet<>();
  768. for (int i = 0; i < list.size(); i++) {
  769. try {
  770. String detailId = null;
  771. Map<String, String> map = list.get(i);
  772. String initId = map.get("initId");//初算id
  773. String personId = map.get("personId");
  774. String taxUnitId = map.get("taxUnitId");
  775. String incomeitemid = map.get("incomeitemid");
  776. String calSchemeId = map.get("calSchemeId");
  777. String cmpCalTableId = map.get("cmpCalTableId");
  778. FilterInfo filterInfo = new FilterInfo();
  779. FilterItemCollection filterItems = filterInfo.getFilterItems();
  780. filterItems.add(new FilterItemInfo("person", personId));
  781. filterItems.add(new FilterItemInfo("taxUnit", taxUnitId));
  782. filterItems.add(new FilterItemInfo("periodBegin", periodBeginDate, CompareType.GREATER_EQUALS));
  783. filterItems.add(new FilterItemInfo("periodEnd", periodEndDate, CompareType.LESS_EQUALS));
  784. filterItems.add(new FilterItemInfo("incomeItem", incomeitemid));
  785. filterItems.add(new FilterItemInfo("calScheme", calSchemeId));
  786. filterItems.add(new FilterItemInfo("cmpCalTable", cmpCalTableId));
  787. SelectorItemCollection sic = new SelectorItemCollection();
  788. sic.add("state");
  789. EntityViewInfo instance = EntityViewInfo.getInstance(filterInfo, sic, null);
  790. logger.info("instance: " + instance.toString());
  791. TaxCalConfigDetailCollection taxCalConfigDetailCol = iTaxCalConfigDetail.getTaxCalConfigDetailCollection(instance);
  792. if (taxCalConfigDetailCol.size() > 0) {
  793. TaxCalConfigDetailInfo taxCalConfigDetailInfo = taxCalConfigDetailCol.get(0);
  794. if (TaxResultStateEnum.UN_CONFIRM.equals(taxCalConfigDetailInfo.getState())) {
  795. //未确认,更新数据
  796. detailId = taxCalConfigDetailInfo.getId().toString();
  797. configIds.add(detailId);
  798. } else {
  799. //已确认,不能更新
  800. logger.error("更新明细表数据 已确认,不能更新");
  801. continue;
  802. }
  803. } else {
  804. //没有找到明细数据,创建数据
  805. //个税应用+税款计算最终拆分明细表
  806. TaxCalConfigDetailInfo taxCalConfigDetailInfo = new TaxCalConfigDetailInfo();
  807. //计算规则
  808. taxCalConfigDetailInfo.put("calScheme", map.get("calSchemeId"));
  809. //核算表id
  810. taxCalConfigDetailInfo.put("cmpCalTable", map.get("cmpCalTableId"));
  811. //状态
  812. taxCalConfigDetailInfo.setState(TaxResultStateEnum.UN_CONFIRM);
  813. //依赖id
  814. //taxCalConfigDetailInfo.setRelay();
  815. //是否最后一条
  816. taxCalConfigDetailInfo.setIsLast(true);
  817. //是否生成个税申报
  818. taxCalConfigDetailInfo.setIsGenerateTaxDeclare(false);
  819. //申报批次号
  820. //taxCalConfigDetailInfo.setBatchNo();
  821. //员工
  822. taxCalConfigDetailInfo.put("person", map.get("personId"));
  823. //纳税单位
  824. taxCalConfigDetailInfo.put("taxUnit", map.get("taxUnitId"));
  825. //税款所属期间起
  826. taxCalConfigDetailInfo.setPeriodBegin(periodBeginDate);
  827. //税款所属期间止
  828. taxCalConfigDetailInfo.setPeriodEnd(periodEndDate);
  829. //所得项目
  830. taxCalConfigDetailInfo.put("incomeItem", map.get("incomeitemid"));
  831. detailId = iTaxCalConfigDetail.addnew(taxCalConfigDetailInfo).toString();
  832. configIds.add(detailId);
  833. }
  834. initIds.add(initId);
  835. } catch (Exception e) {
  836. e.printStackTrace();
  837. }
  838. }
  839. logger.info("configIds: " + objectMapper.writeValueAsString(configIds));
  840. logger.info("initIds " + objectMapper.writeValueAsString(initIds));
  841. if (!configIds.isEmpty() && !initIds.isEmpty()) {
  842. //更新明细表数据
  843. StringBuilder updateSql = new StringBuilder();
  844. StringBuilder querySqlForUpdate = new StringBuilder();
  845. updateSql.append("update T_HR_STaxCalConfigDetail config set (").append("\n");
  846. for (String key : taxItemConfigMap.keySet()) {
  847. updateSql.append(taxItemConfigMap.get(key)).append(",").append("\n");
  848. querySqlForUpdate.append(taxItemConfigMap.get(key)).append(",").append("\n");
  849. }
  850. updateSql.deleteCharAt(updateSql.lastIndexOf(","));
  851. querySqlForUpdate.deleteCharAt(querySqlForUpdate.lastIndexOf(","));
  852. updateSql.append(") = (select ").append(querySqlForUpdate).append("\n");
  853. updateSql.append(" from T_HR_STaxCalInitDetail ").append("\n");
  854. updateSql.append(" where fid in (").append(AtsUtil.convertSetToString(initIds)).append(")").append("\n");
  855. updateSql.append(" and config.fpersonId = fpersonId").append("\n");
  856. updateSql.append(" and config.fCmpCalTableId = fCmpCalTableId").append("\n");
  857. updateSql.append(" and config.fIncomeItemId = fIncomeItemId").append("\n");
  858. updateSql.append(" and config.FPERIODBEGIN = FPERIODBEGIN").append("\n");
  859. updateSql.append(" and config.FPERIODEND = FPERIODEND)").append("\n");
  860. updateSql.append(" where config.fstate = '10'").append("\n");
  861. updateSql.append(" and config.fid in(").append(AtsUtil.convertSetToString(configIds)).append(")").append("\n");
  862. logger.info("更新明细表sql: " + updateSql);
  863. DbUtil.execute(ctx, updateSql.toString());
  864. }
  865. }
  866. /**
  867. * 获取证件map
  868. *
  869. * @return
  870. */
  871. // private static Map<String, String> getCardTypeEnumMap() {
  872. // Map<String, String> cardTypeEnumMap = new HashMap<>();
  873. // List<Map<String, String>> enumList = CardTypeEnum.getEnumList();
  874. // for (int i = 0; i < enumList.size(); i++) {
  875. // CardTypeEnum cardTypeEnum = (CardTypeEnum) enumList.get(i);
  876. // String value = cardTypeEnum.getValue();
  877. // String alias = cardTypeEnum.getAlias();
  878. // cardTypeEnumMap.put(alias, value);
  879. // }
  880. // return cardTypeEnumMap;
  881. // }
  882. /**
  883. * 获取所得项目
  884. *
  885. * @param ctx
  886. * @return
  887. * @throws BOSException
  888. */
  889. private Map<String, String> getIncomeItemMap(Context ctx) throws BOSException {
  890. Map<String, String> incomeItemMap = new HashMap<>();
  891. try {
  892. TaxIncomeItemCollection taxIncomeItemCollection = TaxIncomeItemFactory.getLocalInstance(ctx).getTaxIncomeItemCollection("where state = 1");
  893. for (int i = 0; i < taxIncomeItemCollection.size(); i++) {
  894. TaxIncomeItemInfo taxIncomeItemInfo = taxIncomeItemCollection.get(i);
  895. String taxIncomeItemId = taxIncomeItemInfo.getId().toString();
  896. String name = taxIncomeItemInfo.getName();
  897. incomeItemMap.put(name, taxIncomeItemId);
  898. }
  899. return incomeItemMap;
  900. } catch (BOSException e) {
  901. e.printStackTrace();
  902. throw new BOSException("获取所得项目数据报错: " + e.getMessage());
  903. }
  904. }
  905. /**
  906. * 获取报送人员信息
  907. *
  908. * @param ctx
  909. * @throws BOSException
  910. */
  911. private void getTaxPersonRecordMap(Context ctx) throws BOSException {
  912. if (taxPersonRecordMap == null) {
  913. taxPersonRecordMap = new HashMap<>();
  914. }
  915. String oql = "select bill.person.id,bill.cardType,bill.cardNumber";
  916. TaxPersonRecordEntryCollection taxPersonRecordEntryCollection =
  917. TaxPersonRecordEntryFactory.getLocalInstance(ctx).getTaxPersonRecordEntryCollection(oql);
  918. for (int i = 0; i < taxPersonRecordEntryCollection.size(); i++) {
  919. TaxPersonRecordInfo taxPersonRecordInfo = taxPersonRecordEntryCollection.get(i).getBill();
  920. if (taxPersonRecordInfo != null) {
  921. String personId = taxPersonRecordInfo.getPerson().getId().toString();
  922. CardTypeEnum cardType = taxPersonRecordInfo.getCardType();
  923. if (cardType == null) {
  924. logger.error("获取报送人员信息 人员id[" + personId + "] 的证件类型为空!");
  925. continue;
  926. }
  927. String cardTypeName = cardType.getAlias();
  928. String cardNumber = taxPersonRecordInfo.getCardNumber();
  929. taxPersonRecordMap.put(cardNumber + cardTypeName, personId);
  930. }
  931. }
  932. }
  933. /**
  934. * 获取个税项目
  935. *
  936. * @param ctx
  937. * @return
  938. * @throws BOSException
  939. */
  940. private void getTaxItemMap(Context ctx) throws BOSException {
  941. if (taxItemInitMap == null) {
  942. taxItemInitMap = new HashMap<>();
  943. }
  944. if (taxItemConfigMap == null) {
  945. taxItemConfigMap = new HashMap<>();
  946. }
  947. //获取所有个税项目
  948. Set initSet = new HashSet();
  949. initSet.add("jmse");//减免税额
  950. initSet.add("qzd");//减除费用
  951. initSet.add("ynssde");//应纳税所得额
  952. initSet.add("sl");//税率
  953. initSet.add("sskcs");//速算扣除数
  954. initSet.add("bqybtse");//应补退税额
  955. initSet.add("bqljsre");//累计收入额
  956. initSet.add("bqljmssr");///累计免税收入额
  957. initSet.add("zxkchj");//累计专项扣除额
  958. initSet.add("zxfjkchj");//累计专项(附加)扣除额
  959. initSet.add("qtckhj");//累计其他扣除额
  960. initSet.add("ljjmse");//累计减免税额
  961. initSet.add("jcfy");//累计减除费用额
  962. initSet.add("ljynssde");//累计应纳税所得额
  963. initSet.add("ljynse");//累计应纳税额
  964. initSet.add("ljyingkjse");//累计应扣缴税额
  965. initSet.add("znjyzc");//累计子女教育支出
  966. initSet.add("jxjyzc");//累计继续教育支出
  967. initSet.add("ljxljxjyzc");//累计学历继续教育支出
  968. initSet.add("ljfxljxjyzc");//累计非学历继续教育支出
  969. initSet.add("zfzjzc");//累计住房租金支出
  970. initSet.add("zfdklxzc");//累计房屋贷款支出
  971. initSet.add("sylrzc");//累计赡养老人支出
  972. initSet.add("ljzykcdjze");//累计准予扣除的捐赠额
  973. initSet.add("grylj"); //累计个人养老金
  974. initSet.add("zykcjze");//准予扣除的捐赠额
  975. initSet.add("ykjse");//本月已累计扣除税额
  976. initSet.add("yxkcsf");//允许扣除的税费
  977. initSet.add("zycb");//展业成本
  978. initSet.add("qzd");//月减除费用
  979. //最终拆分明细表个税项目
  980. Set configSet = new HashSet();
  981. configSet.add("sre");//本期收入
  982. configSet.add("mssd");// 本期免税收入
  983. configSet.add("jbylaobxf");// 基本养老保险费
  984. configSet.add("jbylbxf");// 基本医疗保险费
  985. configSet.add("sybxf");// 失业保险费
  986. configSet.add("zfgjj");// 住房公积金
  987. configSet.add("znjyzc");// 累计子女教育
  988. configSet.add("jxjyzc");// 累计继续教育
  989. configSet.add("zfdklxzc");// 累计住房贷款利息");
  990. configSet.add("zfzjzc");// 累计住房租金");
  991. configSet.add("nj");// 企业(职业)年金");
  992. configSet.add("syjkbx");// 商业健康保险");
  993. configSet.add("syylbx");// 税延养老保险");
  994. configSet.add("qt");// 其他");
  995. configSet.add("zykcjze");// 准予扣除的捐赠额");
  996. configSet.add("jmse");// 减免税额");
  997. configSet.add("yxkcsf");// 允许扣除的税费");
  998. configSet.add("ljsre");// 上期累计收入");
  999. configSet.add("bqljsre");// 本期累计收入");
  1000. configSet.add("ljmssd");// 上期累计免税收入");
  1001. configSet.add("bqljmssr");// 本期累计免税收入");
  1002. configSet.add("qzd");// 减除费用");
  1003. configSet.add("jcfy");// 累计减除费用");
  1004. configSet.add("fy");// 本期费用");
  1005. configSet.add("zxkchj");// 累计专项扣除");
  1006. configSet.add("zxfjkchj");// 累计专项附加扣除合计");
  1007. configSet.add("qtckhj");// 累计其他扣除");
  1008. configSet.add("ljzykcdjze");// 累计准予扣除的捐赠
  1009. configSet.add("ljynssde");// 累计应纳税所得额
  1010. configSet.add("sl");// 税率
  1011. configSet.add("sskcs");// 速算扣除数
  1012. configSet.add("ljynse");// 累计应纳税额
  1013. configSet.add("ljjmse");// 累计减免税额
  1014. configSet.add("ljyingkjse");// 累计应扣缴税额
  1015. configSet.add("ykjse");// 累计已预缴税额
  1016. configSet.add("ybtse");// 累计应补(退)税额
  1017. configSet.add("ycxbc");// 一次性补偿
  1018. configSet.add("zycb");// 展业成本
  1019. configSet.add("bz");// 备注
  1020. configSet.add("ccyz");// 财产原值
  1021. configSet.add("jsbl");// 减按计税比例
  1022. configSet.add("ynssde");// 应纳税所得额
  1023. configSet.add("bqybtse");// 本期应补(退)税额
  1024. configSet.add("sylrzc");// 累计赡养老人
  1025. configSet.add("yyezhfzc");// 累计婴幼儿照护费用
  1026. configSet.add("grylj");// 累计个人养老金
  1027. configSet.add("ljfxljxjyzc");// 累计非学历继续教育支出
  1028. configSet.add("ljxljxjyzc");// 累计学历继续教育支出
  1029. configSet.add("dyznjyzc");// 子女教育支出
  1030. configSet.add("dysylrzc");// 赡养老人支出
  1031. configSet.add("dyfwdkzc");// 住房贷款利息支出
  1032. configSet.add("dyzfzjzc");// 住房租金支出
  1033. configSet.add("dyjxjyzc");// 继续教育支出
  1034. configSet.add("dyfxljxjyzc");//非学历继续教育支出
  1035. configSet.add("dyyyrzhzc");// 婴幼儿照护支出
  1036. try {
  1037. TaxItemCollection itemColl = TaxItemFactory.getLocalInstance(ctx)
  1038. .getTaxItemCollection("where state = 1");
  1039. for (int i = 0; i < itemColl.size(); ++i) {
  1040. TaxItemInfo info = itemColl.get(i);
  1041. String number = info.getNumber();
  1042. if (initSet.contains(number)) {
  1043. taxItemInitMap.put(number, "T" + info.getFieldSn());
  1044. }
  1045. if (configSet.contains(number)) {
  1046. taxItemConfigMap.put(number, "T" + info.getFieldSn());
  1047. }
  1048. }
  1049. } catch (BOSException var5) {
  1050. var5.printStackTrace();
  1051. throw new BOSException("获取个税项目报错: " + var5.getMessage());
  1052. }
  1053. }
  1054. }