123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230 |
- package com.kingdee.eas.custom.compensation.service;
- import cn.com.servyou.dto.ApiResponse;
- import cn.com.servyou.dto.tax.CalculateTaxResultRequest;
- import cn.com.servyou.dto.tax.ComplexIncome;
- import cn.com.servyou.dto.tax.ComplexIncomeResultRequest;
- import cn.com.servyou.dto.tax.ComplexTaxCalculateResult;
- import cn.com.servyou.rmi.client.ClientProxyFactory;
- import cn.com.servyou.service.TaxRequest;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.fasterxml.jackson.core.JsonProcessingException;
- import com.fasterxml.jackson.databind.ObjectMapper;
- 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.dao.ormapping.ObjectUuidPK;
- import com.kingdee.bos.metadata.entity.EntityViewInfo;
- import com.kingdee.bos.metadata.entity.FilterInfo;
- import com.kingdee.bos.metadata.entity.FilterItemInfo;
- import com.kingdee.bos.metadata.query.util.CompareType;
- import com.kingdee.eas.basedata.person.IPerson;
- import com.kingdee.eas.basedata.person.PersonCollection;
- import com.kingdee.eas.basedata.person.PersonFactory;
- import com.kingdee.eas.basedata.person.PersonInfo;
- import com.kingdee.eas.common.EASBizException;
- import com.kingdee.eas.custom.individualback.*;
- import com.kingdee.eas.custom.shuiyou.interfacelog.LogInfoFactory;
- import com.kingdee.eas.custom.shuiyou.interfacelog.LogInfoInfo;
- import com.kingdee.eas.custom.shuiyou.task.MessageResult;
- import com.kingdee.eas.custom.shuiyou.utils.ClientProxyFactoryUtils;
- import com.kingdee.eas.util.app.DbUtil;
- import com.kingdee.jdbc.rowset.IRowSet;
- import com.kingdee.shr.compensation.CalSchemeFactory;
- import com.kingdee.util.StringUtils;
- import org.apache.log4j.Logger;
- import java.io.IOException;
- import java.math.BigDecimal;
- import java.sql.SQLException;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- /**
- * @author qingwu
- * @date 2024/9/9
- * @apiNote
- */
- public class SynIndividualIncomeTaxService implements IHRMsfService {
- Logger logger = Logger.getLogger("com.kingdee.eas.custom.compensation.service.SynIndividualIncomeTaxService");
- @Override
- public Object process(Context context, Map map) throws EASBizException, BOSException {
- //接口日志实体
- LogInfoInfo logInfo = new LogInfoInfo();
- //入口
- logInfo.setEntrance(this.getClass().getName());
- logInfo.setBizDate(new Date());
- Map resMap = new HashMap();
- logger.error("SynIndividualIncomeTaxService----------OSF----Start");
- JSONObject paramData = JSONObject.parseObject((String) map.get("paramData"));
- logger.error("paramData--------" + paramData);
- String requestId = paramData.getString("requestId");
- JSONObject param = paramData.getJSONObject("param");
- logger.error("requestId--------" + requestId);
- logger.error("param--------" + param);
- try {
- ObjectMapper mapper = new ObjectMapper();
- //客户端代理工厂
- ClientProxyFactory clientProxyFactory = ClientProxyFactoryUtils.getClientProxyFactory();
- //算税请求接口
- TaxRequest taxRequest = clientProxyFactory.getTaxRequest();
- ApiResponse<CalculateTaxResultRequest> aSynIndividualIncomeTaxFeedback = taxRequest.getReverseASynIndividualIncomeTaxFeedback(requestId);
- logger.error("aSynIndividualIncomeTaxFeedback--------" + mapper.writeValueAsString(aSynIndividualIncomeTaxFeedback));
- String status = aSynIndividualIncomeTaxFeedback.getHead().getStatus();
- logInfo.setInterfaceAddress("/gateway/iit/reverseCalculateTax/getASynIndividualIncomeTaxFeedback");//接口地址
- logInfo.setInterfaceName("getASynIndividualIncomeTaxFeedback");//接口名
- logInfo.setInParameter(mapper.writeValueAsString(aSynIndividualIncomeTaxFeedback));//入参
- CalculateTaxResultRequest body = null;
- if ("N".equals(status)) {
- //请求失败响应
- String msg = aSynIndividualIncomeTaxFeedback.getHead().getMsg();
- logInfo.setStatus("处理中");
- //throw new BOSException(msg);
- return MessageResult.FAILED(msg);
- } else {
- //调用成功
- //请求id
- body = aSynIndividualIncomeTaxFeedback.getBody();
- logger.error("SynIndividualIncomeTaxService----------body---" + mapper.writeValueAsString(body));
- logInfo.setOutParameter(mapper.writeValueAsString(body));//回参
- //if (body.getEmployeeDeclareFeedbackList() != null) {
- logInfo.setStatus("成功");
- disposeTaxPaymentBackCalculate(context, body, param);
- //} else {
- // logInfo.setStatus("人员报错");
- //}
- }
- LogInfoFactory.getLocalInstance(context).addnew(logInfo);
- return MessageResult.SUCCESS(mapper.writeValueAsString(body));
- } catch (IOException e) {
- e.printStackTrace();
- logInfo.setErrorInfo(e.getMessage());//错误信息
- logInfo.setStatus("失败");
- LogInfoFactory.getLocalInstance(context).save(logInfo);
- logger.error("SynIndividualIncomeTaxService----------error---" + e.getMessage());
- //throw new BOSException(e);
- return MessageResult.ERROR(e.getMessage());
- }
- }
- /**
- * 处理个税反算数据
- *
- * @param resBody 查询反算反馈结果接口返回结果
- * @param param 员工ID
- * @return
- */
- public void disposeTaxPaymentBackCalculate(Context ctx, CalculateTaxResultRequest
- resBody, com.alibaba.fastjson.JSONObject param) throws BOSException, EASBizException, JsonProcessingException {
- logger.error("addTaxPaymentBackCalculate============Start===============");
- ObjectMapper mapper = new ObjectMapper();
- ITaxPaymentBackCalculate iTaxPaymentBackCalculate = TaxPaymentBackCalculateFactory.getLocalInstance(ctx);
- String taxItemPlanNumber = param.getString("taxItemPlanNumber");//个税项目方案
- logger.error("taxItemPlanNumber============" + taxItemPlanNumber);
- ComplexTaxCalculateResult complexTaxCalculateResult = null;
- //zhsd 综合所得
- ComplexIncomeResultRequest complexIncomeResultRequest = resBody.getComplexIncomeResultRequest();
- logger.error("complexIncomeResultRequest============" + mapper.writeValueAsString(complexIncomeResultRequest));
- //全年一次性奖金
- //if ("2024083001".equals(taxItemPlanNumber)) {
- if ("GS003".equals(taxItemPlanNumber)) {
- //qnycxjjsslb 全年一次性奖金
- complexTaxCalculateResult = complexIncomeResultRequest.getAnnualOneTimeBonusIncome();
- }
- //一般劳务报酬所得列表
- if ("GS002".equals(taxItemPlanNumber)) {
- //lwbclb 一般劳务报酬所得列表
- complexTaxCalculateResult = complexIncomeResultRequest.getLaborRemunerationIncome();
- }
- //正常工资薪金对象
- if ("GS001".equals(taxItemPlanNumber)) {
- //zcgzxj 正常工资薪金对象
- complexTaxCalculateResult = complexIncomeResultRequest.getNormalSalarySpecIncome();
- }
- IPerson iPerson = PersonFactory.getLocalInstance(ctx);
- List<ComplexIncome> successComplexIncomes = complexTaxCalculateResult.getSuccessComplexIncomes();
- for (ComplexIncome complexIncome : successComplexIncomes) {
- //证件类型
- String licenseType = complexIncome.getLicenseType();
- PersonInfo personInfo = null;
- if ("居民身份证".equals(licenseType)) {
- //证件号码
- String licenseNumber = complexIncome.getLicenseNumber();
- PersonCollection personCollection = iPerson.getPersonCollection("where idCardNO = '" + licenseNumber + "'");
- if (personCollection.size() > 0) {
- personInfo = personCollection.get(0);
- }
- }
- if ("中国护照".equals(licenseType)) {
- //证件号码
- String licenseNumber = complexIncome.getLicenseNumber();
- PersonCollection personCollection = iPerson.getPersonCollection("where passportNO = '" + licenseNumber + "'");
- if (personCollection.size() > 0) {
- personInfo = personCollection.get(0);
- }
- }
- param.put("personId", personInfo.getId());
- saveTaxPaymentBackCalculateCollection(ctx, param, complexIncome);
- }
- logger.error("addTaxPaymentBackCalculate============end===============");
- }
- public String getParamContent(String requestId) {
- return "select CFParamContent as paramContent from CT_TK_TaskRequestParam where CFTaskID in (select FID from CT_TK_Task where CFRequestId = '" + requestId + "')";
- }
- public TaxPaymentBackCalculateCollection saveTaxPaymentBackCalculateCollection(Context ctx, JSONObject
- param, ComplexIncome complexIncome) throws BOSException, EASBizException {
- TaxPaymentBackCalculateInfo taxPaymentBackCalculateInfo = new TaxPaymentBackCalculateInfo();
- String personId = param.getString("personId");//员工ID
- String periodYear = param.getString("periodYear");//统计年
- String periodMonth = param.getString("periodMonth");//统计月
- String cmpschemeid = param.getString("cmpschemeid");//计算规则ID
- String taxItemPlanName = param.getString("taxItemPlanName");//个税项目方案
- String taxItemPlanNumber = param.getString("taxItemPlanNumber");//个税项目方案
- FilterInfo filterInfo = new FilterInfo();
- filterInfo.getFilterItems().add(new FilterItemInfo("person", personId, CompareType.EQUALS));
- filterInfo.getFilterItems().add(new FilterItemInfo("periodMonth", periodMonth, CompareType.EQUALS));
- filterInfo.getFilterItems().add(new FilterItemInfo("periodYear", periodYear, CompareType.EQUALS));
- filterInfo.getFilterItems().add(new FilterItemInfo("cmpscheme", cmpschemeid, CompareType.EQUALS));
- EntityViewInfo entityViewInfo = EntityViewInfo.getInstance(filterInfo, null, null);
- ////查询税款反算表是否存在该数据
- ITaxPaymentBackCalculate iTaxPaymentBackCalculate = TaxPaymentBackCalculateFactory.getLocalInstance(ctx);
- TaxPaymentBackCalculateCollection taxPaymentBackCalculateCollection = iTaxPaymentBackCalculate.getTaxPaymentBackCalculateCollection(entityViewInfo);
- if (taxPaymentBackCalculateCollection.size() > 0) {
- taxPaymentBackCalculateInfo = taxPaymentBackCalculateCollection.get(0);
- taxPaymentBackCalculateInfo.setId(taxPaymentBackCalculateCollection.get(0).getId());
- }
- //员工
- taxPaymentBackCalculateInfo.setPerson(PersonFactory.getLocalInstance(ctx).getPersonInfo(new ObjectUuidPK(personId)));
- //统计年
- taxPaymentBackCalculateInfo.setPeriodYear(periodYear);
- //统计月
- taxPaymentBackCalculateInfo.setPeriodMonth(periodMonth);
- //计算规则
- taxPaymentBackCalculateInfo.setCmpscheme(CalSchemeFactory.getLocalInstance(ctx).getCalSchemeInfo(new ObjectUuidPK(cmpschemeid)));
- //个税项目方案
- taxPaymentBackCalculateInfo.setTaxItemPlan(taxItemPlanName);
- //sre 收入额
- BigDecimal income = complexIncome.getIncome();
- taxPaymentBackCalculateInfo.setSalarySum(income);
- //ybtse refundTax 应补退税额
- BigDecimal refundTax = complexIncome.getRefundTax();
- taxPaymentBackCalculateInfo.setIndividual(refundTax);
- IObjectPK save = iTaxPaymentBackCalculate.save(taxPaymentBackCalculateInfo);
- logger.error("saveTaxPaymentBackCalculateCollection----------save---" + save);
- return taxPaymentBackCalculateCollection;
- }
- }
|