1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291 |
- package com.kingdee.eas.custom.compensation.handler;
- import cn.com.servyou.dto.ApiResponse;
- import cn.com.servyou.dto.AsyncResult;
- import cn.com.servyou.dto.declare.CompanyDeclareRequest;
- import cn.com.servyou.dto.declare.DeclareCancelRequest;
- import cn.com.servyou.dto.declare.DeclareCorrectRequest;
- import cn.com.servyou.dto.tax.*;
- import cn.com.servyou.rmi.client.ClientProxyFactory;
- import cn.com.servyou.service.DeclarationRequest;
- import com.alibaba.fastjson.JSONObject;
- import com.fasterxml.jackson.core.JsonProcessingException;
- import com.fasterxml.jackson.databind.ObjectMapper;
- import com.google.gson.Gson;
- import com.google.gson.reflect.TypeToken;
- import com.kingdee.bos.BOSException;
- import com.kingdee.bos.Context;
- import com.kingdee.bos.dao.ormapping.impl.ImplUtils;
- import com.kingdee.bos.metadata.entity.*;
- import com.kingdee.bos.metadata.query.util.CompareType;
- import com.kingdee.bos.util.EASResource;
- import com.kingdee.eas.basedata.hraux.NationalityInfo;
- 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.shuiyou.task.TaskCatalogEnum;
- import com.kingdee.eas.custom.shuiyou.uitls.ISYUtilsFacade;
- import com.kingdee.eas.custom.shuiyou.uitls.SYUtilsFacadeFactory;
- import com.kingdee.eas.custom.shuiyou.utils.ClientProxyFactoryUtils;
- import com.kingdee.eas.util.app.DbUtil;
- import com.kingdee.jdbc.rowset.IRowSet;
- import com.kingdee.jdbc.rowset.IRowSetMetaData;
- import com.kingdee.shr.base.syssetting.context.SHRContext;
- import com.kingdee.shr.base.syssetting.exception.SHRWebException;
- import com.kingdee.shr.base.syssetting.exception.ShrWebBizException;
- import com.kingdee.shr.base.syssetting.web.dynamic.util.DynamicUtil;
- import com.kingdee.shr.base.syssetting.web.dynamic.util.MD5;
- import com.kingdee.shr.base.syssetting.web.json.JSONUtils;
- import com.kingdee.shr.base.syssetting.web.util.UserUtil;
- import com.kingdee.shr.compensation.TaxDeclareStatusEnum;
- import com.kingdee.shr.compensation.TbTypeEnum;
- import com.kingdee.shr.compensation.app.incomeTax.ITaxPersonRecordEntry;
- import com.kingdee.shr.compensation.app.incomeTax.TaxPersonRecordEntryCollection;
- import com.kingdee.shr.compensation.app.incomeTax.TaxPersonRecordEntryFactory;
- import com.kingdee.shr.compensation.app.incomeTax.TaxPersonRecordEntryInfo;
- import com.kingdee.shr.compensation.app.tax.*;
- import com.kingdee.shr.compensation.app.tax.base.TaxIncomeItemInfo;
- import com.kingdee.shr.compensation.app.taxCal.*;
- import com.kingdee.shr.compensation.helper.CmpConstants;
- import com.kingdee.shr.compensation.taxCal.util.TaxCalcFileUtils;
- import com.kingdee.shr.compensation.util.*;
- import com.kingdee.shr.compensation.web.handler.tax.IncomeTaxDeclareListHandler;
- import com.kingdee.shr.compensation.web.handler.tax.dto.TaxDeclarExcelRowDTO;
- import com.kingdee.shr.compensation.web.handler.tax.dto.TaxDeclareDTO;
- import com.kingdee.util.StringUtils;
- import org.apache.log4j.Logger;
- import org.apache.poi.hssf.usermodel.*;
- import org.springframework.ui.ModelMap;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.lang.reflect.Type;
- import java.math.BigDecimal;
- import java.net.URLEncoder;
- import java.sql.SQLException;
- import java.text.SimpleDateFormat;
- import java.util.*;
- /**
- * @author qingwu
- * @date 2024/9/18
- * @apiNote 个税申报扩展
- */
- public class IncomeTaxDeclareListHandlerEx extends IncomeTaxDeclareListHandler {
- private static final Logger LOG = Logger.getLogger(IncomeTaxDeclareListHandlerEx.class);
- private Context ctx = SHRContext.getInstance().getContext();
- private ObjectMapper mapper = new ObjectMapper();
- /**
- * 个税申报
- *
- * @param request
- * @param response
- * @param modelMap
- */
- @Override
- public void taxDeclareAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws BOSException, SHRWebException {
- LOG.error("taxDeclareAction-----------start-----------");
- Context ctx = SHRContext.getInstance().getContext();
- try {
- boolean isHaveTaxService = CmpTaxUtil.isHaveTaxService(ctx);
- if (!isHaveTaxService) {
- throw new ShrWebBizException(EASResource.getString("com.kingdee.shr.compensation.resource.CommonResource", "label136", ctx.getLocale()));
- } else {
- String selectedId = request.getParameter("selectedId");
- Map<String, Object> resultMap = new HashMap();
- Map<String, Object> declareData = this.getDeclareData(ctx, selectedId);
- Map<String, Object> paramMap = new HashMap();
- paramMap.put("declaData", declareData.get("WATI_TO_DECLARE"));
- LOG.error("paramMap-----------" + paramMap);
- try {
- //纳税单位
- List<String> advanceDeclareInfo = (List) declareData.get("advanceDeclareInfo");
- LOG.error("advanceDeclareInfo------------" + advanceDeclareInfo);
- if (!advanceDeclareInfo.isEmpty()) {
- throw new ShrWebBizException(this.combineError(advanceDeclareInfo));
- }
- //个税审批 审批状态=审批通过的数据
- List<IncomeTaxDeclarInfo> waitToDeclareList = (List) paramMap.get("declaData");
- if (waitToDeclareList.size() <= 0) {
- resultMap.put("success", false);
- resultMap.put("excel", "");
- resultMap.put("hasErrData", true);
- resultMap.put("hasCheckDataErr", true);
- resultMap.put("info", "不可重复声申报!!");
- JSONUtils.SUCCESS(resultMap);
- return;
- }
- //检查纳税申报数据
- Map<String, Object> checkResultMap = this.checkTaxDeclareData(ctx, request, waitToDeclareList);
- Boolean hasErr = (Boolean) checkResultMap.get("hasErrData");
- if (hasErr != null && hasErr) {
- resultMap.put("success", false);
- resultMap.put("excel", checkResultMap.get("excel"));
- resultMap.put("hasErrData", true);
- resultMap.put("hasCheckDataErr", true);
- resultMap.put("info", "");
- JSONUtils.SUCCESS(resultMap);
- return;
- }
- String errMsg = this.checkTaxCalStatus(ctx, waitToDeclareList);
- if (null != errMsg) {
- resultMap.put("success", false);
- resultMap.put("dataError", true);
- resultMap.put("errMsg", errMsg);
- JSONUtils.SUCCESS(resultMap);
- return;
- }
- checkResultMap = this.checkIncomeTaxIssue(ctx, waitToDeclareList);
- if (checkResultMap != null) {
- checkResultMap.put("success", false);
- JSONUtils.SUCCESS(checkResultMap);
- return;
- }
- //errMsg = this.checkReductionItems(ctx, waitToDeclareList);
- //if (null != errMsg) {
- // resultMap.put("success", false);
- // resultMap.put("reductionError", true);
- // resultMap.put("errMsg", errMsg);
- // JSONUtils.SUCCESS(resultMap);
- // return;
- //}
- //Map<String, Object> taxDeclareResult = IncomeTaxDeclareFacadeFactory.getLocalInstance(ctx).taxDeclare(paramMap);
- //调佣税友纳税申报
- Map<String, Object> taxDeclareResult = callShuiYouTaxDeclare(paramMap);
- Boolean isSuccess = (Boolean) taxDeclareResult.get("success");
- resultMap.put("success", isSuccess);
- resultMap.put("excel", "");
- resultMap.put("hasErrData", !isSuccess);
- resultMap.put("hasCheckDataErr", false);
- resultMap.put("info", declareData.get("info"));
- } catch (Exception var17) {
- var17.printStackTrace();
- LOG.error(var17.getMessage(), var17);
- resultMap.put("success", false);
- resultMap.put("excel", "");
- resultMap.put("hasErrData", true);
- resultMap.put("hasCheckDataErr", false);
- resultMap.put("info", declareData.get("info"));
- resultMap.put("errorMsg", var17.getMessage());
- }
- LOG.error("taxDeclareAction-----------end-----------");
- JSONUtils.SUCCESS(resultMap);
- }
- } catch (JsonProcessingException e) {
- e.printStackTrace();
- throw new RuntimeException(e);
- }
- }
- /**
- * 调佣税友纳税申报
- *
- * @param paramMap
- * @return
- */
- public Map<String, Object> callShuiYouTaxDeclare(Map paramMap) {
- LOG.error("callShuiYouTaxDeclare--------------------paramMap" + paramMap);
- Map<String, Object> resultMap = new HashMap();
- resultMap.put("success", true);
- resultMap.put("msg", "");
- List<IncomeTaxDeclarInfo> waitToDeclareList = (List) paramMap.get("declaData");
- Map<String, Object> requestParamMap = new HashMap();
- List<Object[]> paramList = new ArrayList();
- try {
- if (waitToDeclareList != null && waitToDeclareList.size() > 0) {
- for (int i = 0; i < waitToDeclareList.size(); i++) {
- IncomeTaxDeclarInfo taxDeclarInfo = waitToDeclareList.get(i);
- JSONObject param = new JSONObject();
- param.put("taxDeclarId", taxDeclarInfo.getId());
- param.put("taxDeclarBatchNo", taxDeclarInfo.getBatchNo());
- //纳税单位
- TaxUnitInfo taxUnitInfo = taxDeclarInfo.getTaxUnit();
- //客户端代理工厂
- ClientProxyFactory clientProxyFactory = ClientProxyFactoryUtils.getClientProxyFactory();
- //算税请求接口
- DeclarationRequest declarationRequest = clientProxyFactory.getDeclarationRequest();
- //获取请求参数
- CompanyDeclareRequest declareRequestParameter = getDeclareRequestParameter(taxUnitInfo, taxDeclarInfo);
- LOG.error("declareRequestParameter-----------------" + mapper.writeValueAsString(declareRequestParameter));
- ApiResponse<AsyncResult> apiResponse = declarationRequest.send(declareRequestParameter);
- LOG.error("asyncResultApiResponse-----getCode-------" + apiResponse.getHead().getCode());
- LOG.error("asyncResultApiResponse-----getMsg--------" + apiResponse.getHead().getMsg());
- resultMap.put("msg", mapper.writeValueAsString(declareRequestParameter));
- if (apiResponse.getHead().getCode().equals("00000000")) {
- AsyncResult body = apiResponse.getBody();
- String requestId = body.getRequestId();
- LOG.error("requestId-----" + requestId);
- LOG.error("apiResponse-----" + mapper.writeValueAsString(apiResponse));
- //查询反算反馈结果
- ISYUtilsFacade isyUtilsFacade = SYUtilsFacadeFactory.getLocalInstance(ctx);
- //backTask(url,requestId,回调osf服务,自定义参数,任务类型)
- //isyUtilsFacade.backTask(isyUtilsFacade.getConfig().get("ip") + "/gateway/iit/reverseCalculateTax/getASynIndividualIncomeTaxFeedback", requestId, "synIndividualIncomeTaxService", jsonObject.toString(), TaskCatalogEnum.CAL_GET);
- JSONObject json = new JSONObject();
- json.put("requestId", requestId);
- json.put("param", param.toString());
- isyUtilsFacade.addTask("synIncomeTaxDeclareService", json.toJSONString(), TaskCatalogEnum.TAX, "");
- }
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- resultMap.put("success", false);
- resultMap.put("msg", e.getMessage());
- return resultMap;
- }
- return resultMap;
- }
- /**
- * 获取请求参数
- * 注意:
- * 1.解除劳动合同一次性补偿金、全年一次性奖金所得,不能单独申报,需要同正常工资薪金一起申报。
- * 2.解除劳动合同一次性补偿金、稿酬所得,由于税务规则需要,解除劳动合同一次性补偿金、稿酬所得必须填写免税附表。
- *
- * @param taxUnitInfo
- * @param taxDeclarInfo
- * @return
- */
- private CompanyDeclareRequest getDeclareRequestParameter(TaxUnitInfo taxUnitInfo,
- IncomeTaxDeclarInfo taxDeclarInfo
- ) throws BOSException, JsonProcessingException, EASBizException, SQLException {
- LOG.error("getDeclareRequestParameter-----------taxDeclarInfo-----" + taxDeclarInfo);
- CompanyDeclareRequest declareRequestPara = new CompanyDeclareRequest();
- Map<String, Object> requestParamMap = new HashMap();
- //随机id
- String bizNo = UUID.randomUUID().toString();
- LOG.error("bizNo:" + bizNo);
- //外部业务订单号*
- declareRequestPara.setBizNo(bizNo);
- //企业名称*
- declareRequestPara.setName(taxUnitInfo.getName());
- //税号*
- declareRequestPara.setTaxNo(taxUnitInfo.getTaxNumber());
- //行政区划代码*
- declareRequestPara.setArea(taxUnitInfo.getAreaCode());
- //登记序号
- declareRequestPara.setRegistrationNumber(taxUnitInfo.getRegNumber());
- String declPassword = taxUnitInfo.getDeclPassword();
- if (StringUtils.isEmpty(declPassword)) {
- throw new BOSException("申报密码不能为空!");
- }
- declareRequestPara.setDeclarePassword(Base64Utils.decode(declPassword));
- //所得月份
- String yearMonth = taxDeclarInfo.getYearMonth();
- String replaceYearMonth = yearMonth.replace("-", "");
- LOG.error("replaceYearMonth----------------" + replaceYearMonth);
- //税款所属期YYYYMM*
- declareRequestPara.setMonth(replaceYearMonth);
- //总金额
- //BigDecimal totalMoney = taxDeclarInfo.getTotalMoney();
- //应退税额
- //BigDecimal taxRebate = taxDeclarInfo.getTaxRebate();
- //总人数
- //long totalPerson = taxDeclarInfo.getTotalPerson();
- //申报表分类 1=预扣预缴申报表 2=分类所得申报表 3=非居民所得申报表
- //String tbTble = taxDeclarInfo.getTbType().getValue();
- //纳税单位ID
- //String taxUnitId = taxUnitInfo.getId().toString();
- //Map<String, Object> tbTypeMap = new HashMap();
- //if (totalMoney.compareTo(BigDecimal.ZERO) == 0) {
- // tbTypeMap.put("zje", 0.0);
- //} else {
- // tbTypeMap.put("zje", totalMoney);
- //}
- //
- //if (taxRebate.compareTo(BigDecimal.ZERO) == 0) {
- // tbTypeMap.put("ynse", 0.0);
- //} else {
- // tbTypeMap.put("ynse", taxRebate);
- //}
- //tbTypeMap.put("zrs", totalPerson);
- //Map<String, Object> dataMap = new HashMap();
- //if ("1".equals(tbTble)) {
- // dataMap.put("ykyj", tbTypeMap);
- //} else if ("2".equals(tbTble)) {
- // dataMap.put("flsd", tbTypeMap);
- //} else if ("3".equals(tbTble)) {
- // dataMap.put("fjm", tbTypeMap);
- //}
- //密码类型*
- declareRequestPara.setPasswordType("0");
- //离职日期处理策略 1、不传或传1,代表离职日期自动清空,即人员状态由“非正常”变更为“正常”时,离职日期字段自动清空,默认逻辑。
- //2、传2离职日期不自动清空,即人员状态由“非正常”变更为“正常”时,离职日期不自动清空,客户如需清空需对离职日期字段传入空字符串。
- //declareRequestPara.setResignDateStrategy();
- //批次号
- String batchNo = taxDeclarInfo.getBatchNo();
- LOG.error("taxCalConfigDetailCollection--------taxDeclarInfo---------" + taxDeclarInfo);
- //个税应用+税款计算最终拆分明细表
- ITaxCalConfigDetail taxCalConfigDetail = TaxCalConfigDetailFactory.getLocalInstance(ctx);
- TaxCalConfigDetailCollection taxCalConfigDetailCollection = taxCalConfigDetail.getTaxCalConfigDetailCollection("select *,incomeItem.*, person.* where batchNo = '" + batchNo + "' and state = '20'");
- LOG.error("taxCalConfigDetailCollection-----------------" + taxCalConfigDetailCollection.size());
- //员工信息ID
- Set personIds = new HashSet();
- //综合所得对象
- ComplexIncomeRequest complexIncomeRequest = new ComplexIncomeRequest();
- //正常工资薪金对象
- NormalSalarySpecIncome normalSalarySpecIncome = new NormalSalarySpecIncome();
- //正常工资薪金列表
- List<ComplexIncome> normalSalarySpec = new ArrayList();
- //全年一次性奖金收入
- List<ComplexIncome> annualOneTimeBonusIncome = new ArrayList();
- //全年一次性奖金收入
- List<ComplexIncome> laborRemunerationIncome = new ArrayList();
- if (taxCalConfigDetailCollection.size() > 0) {
- for (int i = 0; i < taxCalConfigDetailCollection.size(); i++) {
- TaxCalConfigDetailInfo taxCalConfigDetailInfo = taxCalConfigDetailCollection.get(i);
- //员工信息
- PersonInfo personInfo = taxCalConfigDetailInfo.getPerson();
- personIds.add(personInfo.getId().toString());
- //所得项目
- TaxIncomeItemInfo incomeItem = taxCalConfigDetailInfo.getIncomeItem();
- //本期收入
- Integer sre = null;
- String getSreSql = "select t1 from T_HR_STaxCalConfigDetail where fid ='" + taxCalConfigDetailInfo.getId().toString() + "'";
- IRowSet iRowSet = DbUtil.executeQuery(ctx, getSreSql);
- while (iRowSet.next()) {
- sre = iRowSet.getInt("t1");
- }
- LOG.error("incomeItem-----------------" + incomeItem);
- //所属项目名称
- String incomeItemName = incomeItem.getName();
- //所属项目编码
- String incomeItemNumber = incomeItem.getNumber();
- //正常工资薪金
- if ("zcgzxjlb".equals(incomeItemNumber)) {
- //getComplexIncome(员工信息对象 ,所属项目,本期收入)
- normalSalarySpec.add(getComplexIncome(personInfo, incomeItemName, sre));
- //正常工资薪金列表 保存数据
- normalSalarySpecIncome.setNormalSalarySpec(normalSalarySpec);
- LOG.error("normalSalarySpecIncome-----------------" + mapper.writeValueAsString(normalSalarySpecIncome));
- complexIncomeRequest.setNormalSalarySpecIncome(normalSalarySpecIncome);
- }
- //全年一次性奖金收入
- if ("qnycxjjlb".equals(incomeItemNumber)) {
- annualOneTimeBonusIncome.add(getComplexIncome(personInfo, incomeItemName, sre));
- LOG.error("annualOneTimeBonusIncome-----------------" + mapper.writeValueAsString(annualOneTimeBonusIncome));
- LOG.error("annualOneTimeBonusIncome-----------------" + annualOneTimeBonusIncome);
- LOG.error("annualOneTimeBonusIncome.size()-----------------" + annualOneTimeBonusIncome.size());
- //全年一次性奖金收入 保存数据
- complexIncomeRequest.setAnnualOneTimeBonusIncome(annualOneTimeBonusIncome);
- }
- //一般劳务报酬所得
- if ("lwbclb".equals(incomeItemNumber)) {
- laborRemunerationIncome.add(getComplexIncome(personInfo, incomeItemName, sre));
- LOG.error("laborRemunerationIncome-----------------" + mapper.writeValueAsString(laborRemunerationIncome));
- //一般劳务报酬所得 保存数据
- complexIncomeRequest.setLaborRemunerationIncome(laborRemunerationIncome);
- }
- }
- }
- //综合所得
- declareRequestPara.setComplexIncomeRequest(complexIncomeRequest);
- //企业员工列表
- List<DetailCompanyEmployee> companyEmployeeList = getCompanyEmployeeList(personIds);
- declareRequestPara.setCompanyEmployeeList(companyEmployeeList);
- LOG.error("companyEmployeeList-----------------" + mapper.writeValueAsString(companyEmployeeList));
- return declareRequestPara;
- }
- /***
- * 员工
- * @return
- */
- private ComplexIncome getComplexIncome(PersonInfo personInfo, String incomeItemName, Integer sre) {
- ComplexIncome complexIncome = new ComplexIncome();
- //姓名
- complexIncome.setName(personInfo.getName());
- //居民身份证
- if (personInfo.getIdCardNO() != null) {
- //证照号码
- complexIncome.setLicenseNumber(personInfo.getIdCardNO());
- //证照类型
- complexIncome.setLicenseType("居民身份证");
- }
- //中国护照不
- if (personInfo.getPassportNO() != null) {
- //证照类型
- complexIncome.setLicenseType("中国护照");
- //证照号码
- complexIncome.setLicenseNumber(personInfo.getPassportNO());
- }
- //收入额
- complexIncome.setIncome(new BigDecimal(sre));
- complexIncome.setIncomeItemName(incomeItemName);
- return complexIncome;
- }
- /**
- * 企业员工列表*
- *
- * @return
- */
- private List<DetailCompanyEmployee> getCompanyEmployeeList(Set personIds) throws BOSException, EASBizException {
- List<DetailCompanyEmployee> companyEmployeeList = new ArrayList<DetailCompanyEmployee>();
- SelectorItemCollection sic = new SelectorItemCollection();
- sic.add("*");
- FilterInfo filterInfo = new FilterInfo();
- filterInfo.getFilterItems().add(new FilterItemInfo("id", personIds, CompareType.INCLUDE));
- EntityViewInfo entityViewInfo = EntityViewInfo.getInstance(filterInfo, sic, null); //获取人员数据
- PersonCollection personCollection = PersonFactory.getLocalInstance(ctx).getPersonCollection(entityViewInfo);
- if (personCollection.size() > 0) {
- for (int i = 0; i < personCollection.size(); i++) {
- PersonInfo personInfo = personCollection.get(i);
- companyEmployeeList.add(getDetailCompanyEmployee(personInfo));
- }
- }
- return companyEmployeeList;
- }
- /**
- * 人员
- *
- * @return
- */
- public DetailCompanyEmployee getDetailCompanyEmployee(PersonInfo personInfo) throws BOSException, EASBizException {
- //人员对象
- DetailCompanyEmployee detailCompanyEmployee = new DetailCompanyEmployee();
- ////姓名
- //detailCompanyEmployee.setName("何云");
- ////证件类型
- //detailCompanyEmployee.setLicenseType("居民身份证");
- ////证照号码
- //detailCompanyEmployee.setLicenseNumber("429004198601085125");
- //姓名
- detailCompanyEmployee.setName(personInfo.getName());
- //complexIncome.setName("何云");
- //居民身份证
- if (personInfo.getIdCardNO() != null) {
- //证照号码
- detailCompanyEmployee.setLicenseNumber(personInfo.getIdCardNO());
- //证照类型
- detailCompanyEmployee.setLicenseType("居民身份证");
- //人员地区
- detailCompanyEmployee.setArea("境内");
- }
- //中国护照
- if (personInfo.getPassportNO() != null) {
- //证照类型
- detailCompanyEmployee.setLicenseType("中国护照");
- //证照号码
- detailCompanyEmployee.setLicenseNumber(personInfo.getPassportNO());
- //人员地区
- detailCompanyEmployee.setArea("境外");
- }
- //电话号码
- detailCompanyEmployee.setPhone(personInfo.getCell());
- //人员状态
- detailCompanyEmployee.setState(personInfo.getEmployeeType().getName());
- //人员报税信息->任职受雇从业信息
- ITaxPersonRecordEntry iTaxPersonRecordEntry = TaxPersonRecordEntryFactory.getLocalInstance(ctx);
- TaxPersonRecordEntryCollection taxPersonRecordEntryCollection = iTaxPersonRecordEntry.getTaxPersonRecordEntryCollection("where person.id = '" + personInfo.getId() + "'");
- TaxPersonRecordEntryInfo taxPersonRecordEntryInfo = taxPersonRecordEntryCollection.get(0);
- //任职受雇类型 可选择雇员、保险营销员、证券经纪人、其他、实习学生(全日制学历教育)
- //detailCompanyEmployee.setIsEmployee("其他");
- detailCompanyEmployee.setIsEmployee(taxPersonRecordEntryInfo.getEmployedType().getAlias());
- //受雇日期 YYYY-MM-DD,不能大于当前时间,任职受雇类型选择雇员、保险营销员、证券经纪人时必录
- SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd");
- detailCompanyEmployee.setEmployedDate(inputFormat.format(taxPersonRecordEntryInfo.getEmployedDate()));
- //性别
- detailCompanyEmployee.setGender(personInfo.getGender().getAlias());
- //出生日期
- detailCompanyEmployee.setBirthday(inputFormat.format(personInfo.getBirthday()));
- //国籍 nationality
- NationalityInfo nationality = personInfo.getNationality();
- detailCompanyEmployee.setNationality(nationality.getName());
- return detailCompanyEmployee;
- }
- private String getCheckSqlByType(Map<String, Object> incomeIdMap, String taxUnitId, String yearMonth, TbTypeEnum typeEnum) {
- StringBuilder sqlBuf = new StringBuilder();
- sqlBuf.append(" SELECT distinct tx.FTAXUNITID,t1.Fname_l2 as TAXNAME,p1.FNUMBER,p1.Fname_l2 as PERSONNAME, ti.fIncomeCode ");
- sqlBuf.append(" FROM T_HR_STaxCalConfigDetail tx ");
- sqlBuf.append(" left join T_HR_TAXUNIT as t1 on t1.fid = tx.FTaxUnitID ");
- sqlBuf.append(" left join T_BD_PERSON as p1 on p1.fid = tx.FPersonId ");
- sqlBuf.append(" left join t_hr_sTaxIncomeItem as ti on tx.fIncomeItemId = ti.fid ");
- String dateFilter = CmpSQLUtil.generateSqlDateFilter("tx.FPeriodBegin", "tx.FPeriodEnd", yearMonth);
- sqlBuf.append(" where ").append(dateFilter);
- sqlBuf.append(" and tx.FTAXUNITID='").append(taxUnitId).append("'");
- sqlBuf.append(" and tx.FSTATE=10");
- sqlBuf.append(" and tx.FIsLast=1");
- sqlBuf.append(" and tx.FIncomeItemId in ").append(incomeIdMap.get(typeEnum.getValue()));
- return sqlBuf.toString();
- }
- //private Map<String, Object> checkTaxDeclareData(Context ctx, List<IncomeTaxDeclarInfo> waitToDeclareList) throws BOSException {
- // Map<String, Object> checkDataResultMap = new HashMap();
- // return null;
- //}
- private Map<String, Object> checkTaxDeclareData(Context ctx, HttpServletRequest request, List<IncomeTaxDeclarInfo> waitToDeclareList) throws BOSException, SQLException, ShrWebBizException {
- Map<String, Object> checkDataResultMap = new HashMap();
- boolean hasErrData = false;
- if (waitToDeclareList != null && waitToDeclareList.size() > 0) {
- List<String> preCheckSql = new ArrayList();
- List<String> specCheckForPre = new ArrayList();
- List<String> notPersonCheckSql = new ArrayList();
- List<String> classifyCheckSql = new ArrayList();
- Map<String, Object> incomeIdMap = new HashMap();
- incomeIdMap.put("1", CmpTaxUtil.genIncomeItemId(ctx, "1"));
- incomeIdMap.put("2", CmpTaxUtil.genIncomeItemId(ctx, "2"));
- incomeIdMap.put("3", CmpTaxUtil.genIncomeItemId(ctx, "3"));
- Iterator i$ = waitToDeclareList.iterator();
- String yearMonth;
- while (i$.hasNext()) {
- IncomeTaxDeclarInfo declareInfo = (IncomeTaxDeclarInfo) i$.next();
- TbTypeEnum tbType = declareInfo.getTbType();
- String taxUnitId = declareInfo.getTaxUnit().getId().toString();
- yearMonth = declareInfo.getYearMonth();
- if (tbType != null) {
- if ("1".equals(tbType.getValue())) {
- preCheckSql.add(this.getCheckSqlByType(incomeIdMap, taxUnitId, yearMonth, TbTypeEnum.SB0701));
- specCheckForPre.add(this.getPreCheckSql(declareInfo));
- } else if ("3".equals(tbType.getValue())) {
- notPersonCheckSql.add(this.getCheckSqlByType(incomeIdMap, taxUnitId, yearMonth, TbTypeEnum.SB0703));
- } else {
- classifyCheckSql.add(this.getCheckSqlByType(incomeIdMap, taxUnitId, yearMonth, TbTypeEnum.SB0702));
- }
- }
- }
- Map<String, String> reasonOperaMap = new HashMap();
- reasonOperaMap.put("noCalDataReson", EASResource.getString("com.kingdee.shr.compensation.resource.CommonResource", "label140", ctx.getLocale()));
- reasonOperaMap.put("noCalDataOper", EASResource.getString("com.kingdee.shr.compensation.resource.CommonResource", "label141", ctx.getLocale()));
- reasonOperaMap.put("preDataReason", EASResource.getString("com.kingdee.shr.compensation.resource.CommonResource", "label142", ctx.getLocale()));
- reasonOperaMap.put("preDataOpera", EASResource.getString("com.kingdee.shr.compensation.resource.CommonResource", "label143", ctx.getLocale()));
- List<TaxDeclarExcelRowDTO> taxDeclareExcelRowDTOS = new ArrayList();
- taxDeclareExcelRowDTOS.addAll(this.getExceptData(ctx, preCheckSql, specCheckForPre, reasonOperaMap, TbTypeEnum.SB0701));
- taxDeclareExcelRowDTOS.addAll(this.getExceptData(ctx, classifyCheckSql, specCheckForPre, reasonOperaMap, TbTypeEnum.SB0702));
- taxDeclareExcelRowDTOS.addAll(this.getExceptData(ctx, notPersonCheckSql, specCheckForPre, reasonOperaMap, TbTypeEnum.SB0703));
- String filePath = "";
- if (taxDeclareExcelRowDTOS.size() > 0) {
- hasErrData = true;
- HSSFWorkbook workbook = new HSSFWorkbook();
- yearMonth = EASResource.getString("com.kingdee.shr.compensation.resource.CommonResource", "label144", ctx.getLocale());
- this.fillTitle(ctx, workbook, yearMonth.split(","));
- this.fillWorkdBookData(workbook, taxDeclareExcelRowDTOS);
- SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
- File dir = new File(UserUtil.getUserTempDirAbsolutePath(request.getSession()));
- if (!dir.exists()) {
- dir.mkdirs();
- }
- String fileName = EASResource.getString("com.kingdee.shr.compensation.resource.CommonResource", "label145", ctx.getLocale()) + "_" + format.format(new Date()) + ".xls";
- String realFileName = MD5.md5Hash(fileName);
- File file = new File(dir, realFileName);
- FileOutputStream out = null;
- try {
- out = new FileOutputStream(file);
- workbook.write(out);
- out.flush();
- } catch (FileNotFoundException var33) {
- LOG.error(var33.getMessage(), var33);
- } catch (IOException var34) {
- LOG.error(var34.getMessage(), var34);
- } finally {
- if (out != null) {
- try {
- out.close();
- } catch (IOException var32) {
- LOG.error(var32.getMessage(), var32);
- }
- }
- }
- Map<String, String> params = new HashMap();
- params.put("method", "tmp");
- params.put("file", realFileName);
- params.put("filename", fileName);
- filePath = DynamicUtil.assembleUrl("/downloadfile.do", params);
- }
- checkDataResultMap.put("excel", filePath);
- }
- checkDataResultMap.put("hasErrData", hasErrData);
- return checkDataResultMap;
- }
- private void fillTitle(Context ctx, HSSFWorkbook workbook, String[] titleArr) {
- HSSFSheet sheet = workbook.createSheet();
- HSSFRow createRow = sheet.createRow(0);
- HSSFCell infoCell = createRow.createCell(0);
- infoCell.setCellValue(EASResource.getString("com.kingdee.shr.compensation.resource.CommonResource", "label146", ctx.getLocale()));
- sheet.setColumnWidth(0, 12800);
- createRow = sheet.createRow(1);
- HSSFFont font = workbook.createFont();
- font.setColor((short) 8);
- font.setFontHeightInPoints((short) 12);
- font.setBoldweight((short) 700);
- HSSFCellStyle style = workbook.createCellStyle();
- style.setFont(font);
- style.setAlignment((short) 2);
- style.setVerticalAlignment((short) 1);
- if (titleArr != null && titleArr.length > 0) {
- for (int i = 0; i < titleArr.length; ++i) {
- HSSFCell cell = createRow.createCell(i);
- cell.setCellStyle(style);
- cell.setCellValue(titleArr[i]);
- if (i > 3) {
- sheet.setColumnWidth(i, 15360);
- } else {
- sheet.setColumnWidth(i, 7680);
- }
- }
- }
- }
- private void fillWorkdBookData(HSSFWorkbook workbook, List<TaxDeclarExcelRowDTO> dataList) {
- HSSFSheet sheet = workbook.getSheetAt(0);
- if (dataList != null && dataList.size() > 0) {
- for (int i = 0; i < dataList.size(); ++i) {
- HSSFRow row = sheet.createRow(i + 2);
- TaxDeclarExcelRowDTO excelRowDTO = (TaxDeclarExcelRowDTO) dataList.get(i);
- HSSFCell cell = row.createCell(0);
- cell.setCellValue(excelRowDTO.getPersonNum());
- cell = row.createCell(1);
- cell.setCellValue(excelRowDTO.getPersonName());
- cell = row.createCell(2);
- cell.setCellValue(excelRowDTO.getTaxName());
- cell = row.createCell(3);
- cell.setCellValue(excelRowDTO.getDeclarType());
- cell = row.createCell(4);
- cell.setCellValue(excelRowDTO.getReason());
- cell = row.createCell(5);
- cell.setCellValue(excelRowDTO.getOperation());
- }
- }
- }
- private String getSqlDateFilterLqDate(String dateStr) {
- String[] beginDateArr = dateStr.split("-");
- Calendar calendar = Calendar.getInstance();
- calendar.set(Integer.parseInt(beginDateArr[0]), Integer.parseInt(beginDateArr[1]) - 1, 1, 0, 0, 0);
- Date beginDate = calendar.getTime();
- return CmpDateUtil.toKSqlDate(beginDate);
- }
- private List<TaxDeclarExcelRowDTO> getExceptData(Context ctx, List<String> preCheckSql, List<String> specCheckForPre, Map<String, String> noCalDataOper, TbTypeEnum typeEnum) throws BOSException, SQLException, ShrWebBizException {
- List<TaxDeclarExcelRowDTO> taxDeclarExcelRowDTOS = new ArrayList();
- Iterator i$;
- String s;
- IRowSet rowSet;
- TaxDeclarExcelRowDTO taxDeclareExcelRow;
- if (preCheckSql != null && preCheckSql.size() > 0) {
- i$ = preCheckSql.iterator();
- while (i$.hasNext()) {
- s = (String) i$.next();
- rowSet = DbUtil.executeQuery(ctx, s);
- while (rowSet.next()) {
- taxDeclareExcelRow = new TaxDeclarExcelRowDTO();
- taxDeclareExcelRow.setPersonNum(rowSet.getString("FNUMBER"));
- taxDeclareExcelRow.setPersonName(rowSet.getString("PERSONNAME"));
- String taxUnitName = rowSet.getString("TAXNAME");
- taxDeclareExcelRow.setTaxName(taxUnitName);
- taxDeclareExcelRow.setDeclarType(typeEnum.getAlias());
- taxDeclareExcelRow.setReason((String) noCalDataOper.get("noCalDataReson"));
- taxDeclareExcelRow.setOperation((String) noCalDataOper.get("noCalDataOper"));
- String incomeCode = (String) noCalDataOper.get("fIncomeCode");
- taxDeclarExcelRowDTOS.add(taxDeclareExcelRow);
- }
- }
- }
- if ("1".equals(typeEnum.getValue()) && specCheckForPre != null && specCheckForPre.size() > 0) {
- i$ = specCheckForPre.iterator();
- while (i$.hasNext()) {
- s = (String) i$.next();
- rowSet = DbUtil.executeQuery(ctx, s);
- while (rowSet.next()) {
- taxDeclareExcelRow = new TaxDeclarExcelRowDTO();
- taxDeclareExcelRow.setPersonNum(rowSet.getString("FNUMBER"));
- taxDeclareExcelRow.setPersonName(rowSet.getString("PERSONNAME"));
- taxDeclareExcelRow.setTaxName(rowSet.getString("TAXNAME"));
- taxDeclareExcelRow.setDeclarType(typeEnum.getAlias());
- taxDeclareExcelRow.setReason((String) noCalDataOper.get("preDataReason"));
- taxDeclareExcelRow.setOperation((String) noCalDataOper.get("preDataOpera"));
- taxDeclarExcelRowDTOS.add(taxDeclareExcelRow);
- }
- }
- }
- return taxDeclarExcelRowDTOS;
- }
- private String getPreCheckSql(IncomeTaxDeclarInfo incomeTaxDeclarInfo) {
- StringBuilder sqlBuf = new StringBuilder();
- String yearMonth = incomeTaxDeclarInfo.getYearMonth();
- String taxUnitId = incomeTaxDeclarInfo.getTaxUnit().getId().toString();
- String sql = "select FPersonID from T_HR_STaxCalConfigDetail where FTaxUnitId='" + taxUnitId + "' and FPeriodBegin = " + CmpDateUtil.toKSqlDate(incomeTaxDeclarInfo.getYearMonthDate());
- sqlBuf.append(" SELECT distinct ent.FTAXUNITID, t.Fname_l2 as TAXNAME, p.FNUMBER, p.Fname_l2 as PERSONNAME ");
- sqlBuf.append(" FROM T_HR_STaxPersonRecordEntry ent ");
- sqlBuf.append(" left join T_HR_TAXUNIT as t on t.fid = ent.FTaxUnitID ");
- sqlBuf.append(" left join T_BD_PERSON as p on p.fid = ent.FPersonId ");
- sqlBuf.append(" where ent.FSubmitStatus='2' and ent.FPersonStatus='1' ");
- sqlBuf.append(" and ent.FTaxUnitID='").append(taxUnitId).append("'");
- sqlBuf.append(" and ent.FENDDATE <=").append(this.getSqlDateFilterLqDate(yearMonth));
- sqlBuf.append(" and ent.FPersonID not in ( ").append(sql).append(" )");
- return sqlBuf.toString();
- }
- private Map<String, Object> checkIncomeTaxIssue(Context ctx, List<IncomeTaxDeclarInfo> waitToDeclareList) throws BOSException {
- StringBuilder taxUnitIds = new StringBuilder();
- IncomeTaxDeclarInfo declareInfo;
- for (Iterator i$ = waitToDeclareList.iterator(); i$.hasNext(); taxUnitIds.append(declareInfo.getTaxUnit().getId().toString())) {
- declareInfo = (IncomeTaxDeclarInfo) i$.next();
- if (taxUnitIds.length() > 0) {
- taxUnitIds.append(",");
- }
- }
- String oql = "select person.person.name where taxUnit.id in " + CmpStrUtil.buildInSql(taxUnitIds.toString()) + " and result = " + 1 + " and status = " + 2 + " and inviteStatus = " + 0;
- IncomeTaxIssueCollection collection = IncomeTaxIssueFactory.getLocalInstance(ctx).getIncomeTaxIssueCollection(oql);
- if (collection != null && !collection.isEmpty()) {
- StringBuilder errMsg = new StringBuilder();
- for (int i = 0; i < collection.size() && i != 5; ++i) {
- if (errMsg.length() > 0) {
- errMsg.append(",");
- }
- errMsg.append("[").append(collection.get(i).getPerson().getPerson().getName()).append("]");
- }
- Map<String, Object> map = new HashMap();
- map.put("errMsg", "以下员工存在申诉属实争议,且未进行邀请确认,需要进行发送邀请确认后才可进行个税申报或者进行非正常人员报送(更新人员报税信息中的人员状态为非正常,并进行人员报送成功),员工姓名:" + errMsg.toString() + ",选择[是]则跳转到[申诉争议-申诉属实人员]列表,选择[否]则跳转到[人员报税信息]列表。");
- map.put("issueError", true);
- return map;
- } else {
- return null;
- }
- }
- private String checkTaxCalStatus(Context ctx, List<IncomeTaxDeclarInfo> waitToDeclareList) throws SHRWebException {
- String sql = "select t.fState, u.fName_l2 taxUnitName, d.fIncomeItemId from t_hr_sTaxCalConfigDetail d left join t_hr_sTaxCalInitDetail t on d.fCmpCalTableId = t.fCmpCalTableId and d.fIncomeItemId = t.fIncomeItemId left join t_hr_taxUnit u on d.fTaxUnitId = u.fid where d.fTaxUnitId = ? and d.fPeriodBegin = ?";
- try {
- Iterator i$ = waitToDeclareList.iterator();
- boolean isTaxCalFinished;
- String taxUnitName;
- do {
- if (!i$.hasNext()) {
- return null;
- }
- IncomeTaxDeclarInfo declareInfo = (IncomeTaxDeclarInfo) i$.next();
- String taxUnitId = declareInfo.getTaxUnit().getId().toString();
- Date periodDate = declareInfo.getYearMonthDate();
- Object[] param = new Object[]{taxUnitId, CmpDateUtil.toSqlDate(periodDate)};
- IRowSet rs = DbUtil.executeQuery(ctx, sql, param);
- boolean havingSalaryIncome = false;
- isTaxCalFinished = true;
- taxUnitName = "";
- while (rs.next()) {
- int state = rs.getInt("fState");
- taxUnitName = rs.getString("taxUnitName");
- String incomeItemId = rs.getString("fIncomeItemId");
- if (state != 40) {
- isTaxCalFinished = false;
- }
- if ("8r0AAABCg2PDiOoP".equals(incomeItemId)) {
- havingSalaryIncome = true;
- }
- }
- TbTypeEnum typeEnum = declareInfo.getTbType();
- if (!havingSalaryIncome && typeEnum == TbTypeEnum.SB0701) {
- return "纳税单位[" + taxUnitName + "]当期预扣预缴申报表未包含所得项目为正常工资薪金所得的员工,不允许申报,请确认";
- }
- } while (isTaxCalFinished);
- return "纳税单位【" + taxUnitName + "】存在接口算税未完成的数据,请确认";
- } catch (Exception var15) {
- LOG.error("checkTaxCalStatus error: ", var15);
- throw new SHRWebException(var15.getMessage());
- }
- }
- /**
- * 异常提醒
- *
- * @param advanceDeclareInfo
- * @return
- */
- private String combineError(List<String> advanceDeclareInfo) {
- StringBuilder error = new StringBuilder();
- error.append("以下纳税单位尚未到申报时间,请不要提前申报:");
- Iterator i$ = advanceDeclareInfo.iterator();
- while (i$.hasNext()) {
- String taxUnitInfo = (String) i$.next();
- if (advanceDeclareInfo.indexOf(taxUnitInfo) == 5) {
- error.append("...");
- break;
- }
- if (advanceDeclareInfo.indexOf(taxUnitInfo) > 0) {
- error.append(",");
- }
- String[] arr = taxUnitInfo.split("_");
- error.append(arr[0]).append("【").append(arr[1]).append("】");
- }
- return error.toString();
- }
- /**
- * 获取个税申报审批通过数据
- *
- * @param ctx
- * @param selectedId
- * @return
- * @throws BOSException
- */
- private Map<String, Object> getDeclareData(Context ctx, String selectedId) throws BOSException, JsonProcessingException {
- Map<String, Object> resultMap = new HashMap();
- List<TaxDeclareDTO> declaredList = new ArrayList();
- List<IncomeTaxDeclarInfo> waitToDeclareList = new ArrayList();
- String sqlInString = CmpUtils.spiltToSqlString(selectedId);
- if (StringUtils.isEmpty(sqlInString)) {
- sqlInString = "''";
- }
- String currentYearMonth = CmpDateUtil.getDateStr(new Date(), "yyyy-MM");
- String oqlBuffer = "select id,yearMonth,totalPerson,totalMoney,taxRebate,declareStatus,versionCode,yearMonthDate,tbType,taxUnit.id,taxUnit.name,taxUnit.taxNumber,taxUnit.regNumber,taxUnit.areaCode,taxUnit.declPassword, batchNo where id in ( " + sqlInString + " )";
- LOG.error("getDeclareData----------oqlBuffer------" + oqlBuffer);
- IncomeTaxDeclarCollection declareCollection = IncomeTaxDeclarFactory.getLocalInstance(ctx).getIncomeTaxDeclarCollection(oqlBuffer);
- LOG.error("getDeclareData----------declareCollection------" + declareCollection.size());
- String ms1 = EASResource.getString("com.kingdee.shr.compensation.resource.CommonResource", "label137", ctx.getLocale());
- String ms2 = EASResource.getString("com.kingdee.shr.compensation.resource.CommonResource", "label138", ctx.getLocale());
- String ms3 = EASResource.getString("com.kingdee.shr.compensation.resource.CommonResource", "label139", ctx.getLocale());
- List<String> taxUnitInfo = new ArrayList();
- if (declareCollection != null && declareCollection.size() > 0) {
- for (int i = 0; i < declareCollection.size(); ++i) {
- IncomeTaxDeclarInfo declareInfo = declareCollection.get(i);
- String declareStatus = declareInfo.getDeclareStatus().getValue();
- LOG.error("getDeclareData----------declareStatus------" + declareStatus);
- String taxUnitName = declareInfo.getTaxUnit().getName();
- String tbTypeAlia = declareInfo.getTbType().getAlias();
- if (currentYearMonth.compareTo(declareInfo.getYearMonth()) <= 0) {
- taxUnitInfo.add(declareInfo.getTaxUnit().getName() + "_" + declareInfo.getYearMonth());
- }
- if (!"1".equals(declareStatus) && !"2".equals(declareStatus)) {
- waitToDeclareList.add(declareInfo);
- LOG.error("getDeclareData----------waitToDeclareList------" + waitToDeclareList);
- } else {
- TaxDeclareDTO dto = new TaxDeclareDTO(taxUnitName, tbTypeAlia);
- declaredList.add(dto);
- }
- }
- if (declaredList.size() == declareCollection.size()) {
- resultMap.put("info", ms1);
- } else if (declaredList.size() == 0) {
- resultMap.put("info", ms2);
- } else {
- resultMap.put("info", ms3);
- }
- }
- LOG.error("getDeclareData----------resultMap------" + resultMap);
- resultMap.put("DECLARED", declaredList);
- resultMap.put("advanceDeclareInfo", taxUnitInfo);
- resultMap.put("WATI_TO_DECLARE", waitToDeclareList);
- return resultMap;
- }
-
-
-
-
-
- private void updateOrCancel(HttpServletRequest request, HttpServletResponse response, TaskCatalogEnum catalog)
- throws SHRWebException {
- Context ctx = SHRContext.getInstance().getContext();
- String selectedId = request.getParameter("selectedId");
- String oql = "select id, tbType, yearMonth, yearMonthDate, taxUnit.id, taxUnit.name, taxUnit.areaCode, taxUnit.taxNumber, taxUnit.regNumber, taxUnit.declPassword, taxUnit.realPassword, acceptId where id = '"
- + selectedId + "'";
-
- try {
- IncomeTaxDeclarCollection collection = IncomeTaxDeclarFactory.getLocalInstance(ctx)
- .getIncomeTaxDeclarCollection(oql);
- if (null != collection && collection.size() != 0) {
- IncomeTaxDeclarInfo incomeTaxDeclare = collection.get(0);
- if (TaskCatalogEnum.TaxDeclareUpdate == catalog) {
- //更新
- updateDeclare(ctx,incomeTaxDeclare);
- } else {
- //更新以外的
- if (TaskCatalogEnum.CancelTaxDeclare != catalog) {
- //撤销更正
- System.out.print("撤销更正找到方法");
- cancelUpdate( ctx ,incomeTaxDeclare);
- return;
- }
- //撤销申报
- System.out.print("作废申报找到方法");
- cancelDeclare(ctx,incomeTaxDeclare);
- System.out.print("作废申报完成");
- }
-
- String templateId = "4i4AAAAS76+Vh943";
- String columnSQL = "select t.fieldsn, f.FPROPNAME,f.fname_l2,f.fcustomfield from T_BS_SHRFileTemplateFields f left join t_HR_sTaxItem t on f.FPROPNAME = t.FNUMBER where f.fcmpimporttempid = '"
- + templateId + "' order by f.fsortsn ";
- IRowSet columnSet = DbUtil.executeQuery(ctx, columnSQL);
- StringBuilder tmpSQL = new StringBuilder();
- tmpSQL.append("select ");
- String dynamicFieldPrefix = "t";
- String local = SHRContext.getInstance().getContext().getLocale().getDisplayLanguage();
- int columnSize = columnSet.size();
-
- while (columnSet.next()) {
- int index = columnSet.getInt(1);
- String propName = columnSet.getString(2);
- int isCustom = columnSet.getInt(4);
- if (isCustom == 1 && index > 0) {
- tmpSQL.append(dynamicFieldPrefix).append(index).append(",");
- } else if (propName.endsWith("_")) {
- tmpSQL.append(propName).append(local).append(",");
- } else {
- tmpSQL.append(propName).append(",");
- }
- }
-
- String sql = tmpSQL.substring(0, tmpSQL.length() - 1);
- Date date = incomeTaxDeclare.getYearMonthDate();
- String taxUnitId = incomeTaxDeclare.getTaxUnit().getId().toString();
- TbTypeEnum tbType = incomeTaxDeclare.getTbType();
- String personType = CmpConstants.getPayerTypeByTbType(tbType.getValue());
- String dataSQL = sql
- + " from t_hr_sTaxCalConfigDetail t left join T_BD_Person person on t.fPersonId = person.fid left join T_HR_STaxPersonRecord taxPersonRec on t.fPersonId = taxPersonRec.fPersonId left join T_HR_TaxUnit taxUnit on t.fTaxUnitId = taxUnit.fid left join T_HR_STaxIncomeItem item on t.fIncomeItemId = item.fid left join T_HR_STaxPersonRecordEntry pEntry on taxPersonRec.fid = pEntry.fBillId where t.fPeriodBegin = "
- + CmpDateUtil.toKSqlDate(date) + " and t.fTaxUnitId = '" + taxUnitId
- + "' and pEntry.fTaxUnitId = '" + taxUnitId + "' and pEntry.fPayerType = '" + personType
- + "'";
- IRowSet dataSet = DbUtil.executeQuery(ctx, dataSQL);
- List<List<Object>> dataList = new ArrayList();
- IRowSetMetaData metaData = dataSet.getRowSetMetaData();
-
- for (int rowIndex = 1; dataSet.next(); ++rowIndex) {
- List<Object> row = new ArrayList();
- row.add(rowIndex);
-
- for (int i = 1; i <= columnSize; ++i) {
- int dataType = metaData.getColumnType(i);
- row.add(ImplUtils.getDataFromDr(dataType, dataSet, i));
- }
-
- dataList.add(row);
- }
-
- String template = request.getSession().getServletContext().getRealPath("/")
- + "addon/compensation/web/resource/incomeTaxSbbExportTemplate.xlsx";
- String taxUnitName = incomeTaxDeclare.getTaxUnit().getName();
- String tbTypeName = incomeTaxDeclare.getTbType().getAlias();
- String period = TaxCalcFileUtils.getCnPeriod1(incomeTaxDeclare.getYearMonthDate());
- String timestamp = TaxCalcFileUtils.getTimestamp(new Date());
- String userTempDirAbsolutePath = UserUtil.getUserTempDirAbsolutePath(request.getSession());
- userTempDirAbsolutePath = userTempDirAbsolutePath + "/exportExcel";
- File dir = new File(userTempDirAbsolutePath);
- if (!dir.exists()) {
- dir.mkdirs();
- }
-
- String fileName = "个税申报表_" + taxUnitName + "_" + tbTypeName + "_" + period + "_" + timestamp
- + ".xlsx";
- String path = dir.getAbsolutePath() + File.separator + fileName;
- Map<String, String> params = new HashMap();
- params.put("startAndEnd", TaxCalcFileUtils.getCnPeriod2(incomeTaxDeclare.getYearMonthDate()));
- params.put("taxUnitName", taxUnitName);
- params.put("taxUnitNumber", incomeTaxDeclare.getTaxUnit().getTaxNumber());
- CmpExcelUtil.writeData2Template(dataList, template, 8, path, params);
- String headerStr = "attachment;filename=" + URLEncoder.encode(fileName, "utf-8");
- response.setHeader("Content-disposition", headerStr);
- response.getOutputStream().write(TaxCalcFileUtils.file2ByteArray(new File(path)));
- response.getOutputStream().flush();
- return;
- } else {
- throw new SHRWebException("没有找到申报记录");
- }
- } catch (Exception var37) {
- LOG.error("updateDeclareAction error: ", var37);
- throw new SHRWebException(var37.getMessage());
- }
- }
-
-
-
- protected Map cancelUpdate(Context ctx, IncomeTaxDeclarInfo taxDeclare) throws BOSException {
- try {
- String sql = "select t.fAccept_id as acceptId from t_hr_sIncomeTaxDeclar d left join t_hr_sTaskIncomeTaxRelation r on d.fid = r.fBizId left join t_hr_sTaxCalTask t on r.fTaskId = t.fid where d.fid = '"
- + taxDeclare.getId().toString() + "' and t.fCatalog = " + 120;
- IRowSet rowSet = DbUtil.executeQuery(ctx, sql);
- if (rowSet.size() == 0) {
- throw new BOSException("找不到更正申报任务受理id");
- } else {
- while (rowSet.next()) {
- taxDeclare.setAcceptId(rowSet.getString("acceptId"));
- }
-
- return updateOrCancel(ctx, taxDeclare, TaskCatalogEnum.CancelTaxUpdate);
- }
- } catch (SQLException var5) {
- LOG.error("_cancelUpdate error: ", var5);
- throw new BOSException(var5.getMessage());
- }
- }
-
-
-
- private Map updateOrCancel(Context ctx, IncomeTaxDeclarInfo taxDeclare, TaskCatalogEnum catalog)
- throws BOSException {
- JSONObject param = new JSONObject();
- String billId = StringUtils.cnulls(taxDeclare.getId());
- param.put("taxDeclarId", billId);
- param.put("taxDeclarBatchNo", StringUtils.cnulls(taxDeclare.getBatchNo()) );
- Map<String, Object> paramMap = new HashMap();
- DeclareCancelRequest requestObj = new DeclareCancelRequest();
- TaxUnitInfo taxUnit = taxDeclare.getTaxUnit();
- /// bizNo 外部业务编号 String(64) 是 外部业务编号,唯一,幂等需要,最长64位,建议使用UUID
- String bizNo = UUID.randomUUID().toString();
- paramMap.put("bizNo" , bizNo);
- requestObj.setBizNo(bizNo);
- //qymc 企业名称 String(64) 是 代报企业全称
- System.out.print("企业名称为:"+taxUnit.getName());
- paramMap.put("qymc" , taxUnit.getName() );
- requestObj.setName(taxUnit.getName());
- //djxhid 登记序号 String(64) 条件必填 存在多个登记序号时,需要指定传入一个.例:10117440105249764755
- paramMap.put("djxhid" , taxUnit.getRegNumber());
- requestObj.setRegistrationNumber(taxUnit.getRegNumber());
- //nsrsbh 税号 String(64) 是 扣缴单位纳税人识别号
- paramMap.put("nsrsbh" , taxUnit.getTaxNumber());
- requestObj.setTaxNo(taxUnit.getTaxNumber());
- //areaid 地区编号 String(64) 是 6位行政区划代码,精确到市级,例如:440100,参考省市区编码
- paramMap.put("areaid" , taxUnit.getAreaCode());
- requestObj.setArea(taxUnit.getAreaCode());
- //bmbh 部门编号 String(64) 条件必填 分部门代报时必传
- //bmmc 部门名称 String(64) 否
- //skssq 所属期 String(64) 是 格式YYYYMM。为空时, 根据任职受雇日期判断:
- String period = taxDeclare.getYearMonth();
- period = period.contains("-") ? period.replace("-", "") : period;
- period = period.substring(0, 6);
- requestObj.setMonth(period);
- paramMap.put("skssq" , period);
- //sblx 申报类型 String(64) 必填 1:综合所得;2:分类所得;3:非居民所得;4:限售股所得
- paramMap.put("sblx" , "1");
- requestObj.setDeclarationType("1");
- //sfqksd 是否清空所得数据 String(64) 否 0:不清空 1 清空, 默认为0, 作废申报的同时清空数据
- requestObj.setCancelImportDataOption("0");
- //jmsmmm 加密实名密码 String(64) 否 默认不传则设置为0,0表示不加密;1表示加密
- paramMap.put("jmsbmm" , "0");
- requestObj.setEncryptedRealNamePassword("0");
- if (!StringUtils.isEmpty(taxUnit.getRealPassword())) {
- //mmlx 密码类型 String(64) 否 默认不传则设置为0, 0表示申报密码;2表示实名账号实名密码
- paramMap.put("mmlx" , "2");
- requestObj.setPasswordType("2");
- //smzh 实名账号 String(64) 条件必填 当mmlx=2时,必填。
- paramMap.put("smzh", false);
- requestObj.setRealNameAccount("");
- //smmm 实名密码 String(64) 条件必填 当mmlx=2时,必填
- paramMap.put("smmm", Base64Utils.decode(taxUnit.getRealPassword()));
- requestObj.setRealNamePassword(Base64Utils.decode(taxUnit.getRealPassword()));
- }
- if (!StringUtils.isEmpty(taxUnit.getDeclPassword())) {
- //sbmm 申报密码 String(64) 条件必填 当mmlx=0时,必填
- paramMap.put("sbmm", Base64Utils.decode(taxUnit.getDeclPassword()));
- requestObj.setDeclarePassword(Base64Utils.decode(taxUnit.getDeclPassword()));
- //mmlx 密码类型 String(64) 否 默认不传则设置为0, 0表示申报密码;2表示实名账号实名密码
- paramMap.put("mmlx" , "0");
- requestObj.setPasswordType("0");
- }
-
-
- //客户端代理工厂
- try {
- ClientProxyFactory clientProxyFactory = ClientProxyFactoryUtils.getClientProxyFactory();
- //算税请求接口
- DeclarationRequest declarationRequest = clientProxyFactory.getDeclarationRequest();
- //获取请求参数
- if( catalog.equals(TaskCatalogEnum.CancelTaxDeclare) ) {
- // Gson gson = new Gson();
- // Type personType = new TypeToken<DeclareCancelRequest>(){}.getType();
- // DeclareCancelRequest newObj = gson.fromJson(gson.toJson(requestObj), personType);
- LOG.error("撤销申报执行参数:"+mapper.writeValueAsString(requestObj));
- //CancelTaxDeclare 作废申报 140
- ApiResponse<AsyncResult> apiResponse = declarationRequest.cancel (requestObj);
- LOG.error("撤销申报执行结果"+apiResponse.getHead().getMsg());
- if (apiResponse.getHead().getCode().equals("00000000")) {
- AsyncResult body = apiResponse.getBody();
- String requestId = body.getRequestId();
- LOG.error("requestId-----" + requestId);
- ISYUtilsFacade isyUtilsFacade = SYUtilsFacadeFactory.getLocalInstance(ctx);
- //backTask(url,requestId,回调osf服务,自定义参数,任务类型)
- JSONObject json = new JSONObject();
- json.put("requestId", requestId);
- json.put("reportType", "1");
- //
- // JSONObject paramJson = new JSONObject();
- // paramJson.put("taxDeclarId", taxDeclare.getId().toString());
- // paramJson.put("taxDeclarBatchNo", taxDeclare.getBatchNo());
- json.put("param", param );
- LOG.error("撤销申报执行调用后台开始"+param);
- isyUtilsFacade.addTask("CancelDeclareService", json.toJSONString(), TaskCatalogEnum.CancelTaxDeclare, "");
- LOG.error("撤销申报执行调用后台完成");
- }
- }else if(catalog.equals(TaskCatalogEnum.TaxDeclareUpdate)) {
- //更正申报 120
- // Gson gson = new Gson();
- // Type personType = new TypeToken<DeclareCorrectRequest>(){}.getType();
- // DeclareCorrectRequest newObj = gson.fromJson(gson.toJson(paramMap), personType);
- ObjectMapper mapper = new ObjectMapper();
- DeclareCorrectRequest newObj = mapper.convertValue(paramMap, DeclareCorrectRequest.class);
- LOG.error("更正申报执行参数:"+mapper.writeValueAsString(newObj));
- ApiResponse<AsyncResult> apiResponse = declarationRequest.correct (newObj);
- LOG.error("更正申报执行结果"+apiResponse.getHead().getMsg());
- if (apiResponse.getHead().getCode().equals("00000000")) {
- //同步接口;
- //个税申报批次号
- String taxDeclarBatchNo = taxDeclare.getBatchNo();
- IIncomeTaxDeclar iIncomeTaxDeclar = IncomeTaxDeclarFactory.getLocalInstance(ctx);
- IncomeTaxDeclarInfo incomeTaxDeclarInfo = iIncomeTaxDeclar.getIncomeTaxDeclarInfo(new ObjectUuidPK(billId));
- SelectorItemCollection updateSic = new SelectorItemCollection();
- updateSic.add("declareStatus");
- if (null != incomeTaxDeclarInfo) {
- incomeTaxDeclarInfo.setDeclareStatus(TaxDeclareStatusEnum.DECLARE_NO);
- iIncomeTaxDeclar.updatePartial(incomeTaxDeclarInfo, updateSic);
- }
- }
- }else if(catalog.equals(TaskCatalogEnum.CancelTaxUpdate )) {
- System.out.print("撤销更正执行");
- //撤销更正申报
- // Gson gson = new Gson();
- // Type personType = new TypeToken<DeclareCorrectRequest>(){}.getType();
- // DeclareCorrectRequest newObj = gson.fromJson(gson.toJson(paramMap), personType);
- ObjectMapper mapper = new ObjectMapper();
- DeclareCorrectRequest convertValue = mapper.convertValue(paramMap, DeclareCorrectRequest.class);
- LOG.error("撤销更正执行参数:"+mapper.writeValueAsString(convertValue));
- ApiResponse<AsyncResult> apiResponse = declarationRequest.cancelCorrect (convertValue);
- LOG.error("撤销更正执行结果"+apiResponse.getHead().getMsg());
- if (apiResponse.getHead().getCode().equals("00000000")) {
- //同步接口;
- //个税申报批次号
- String taxDeclarBatchNo = taxDeclare.getBatchNo();
- IIncomeTaxDeclar iIncomeTaxDeclar = IncomeTaxDeclarFactory.getLocalInstance(ctx);
- // IncomeTaxDeclarCollection incomeTaxDeclarCollection = iIncomeTaxDeclar.getIncomeTaxDeclarCollection("where batchNo = '" + taxDeclarBatchNo + "'");
- IncomeTaxDeclarInfo incomeTaxDeclarInfo = iIncomeTaxDeclar.getIncomeTaxDeclarInfo(new ObjectUuidPK(billId));
- SelectorItemCollection updateSic = new SelectorItemCollection();
- updateSic.add("declareStatus");
- if (null != incomeTaxDeclarInfo) {
- // IncomeTaxDeclarInfo incomeTaxDeclarInfo = incomeTaxDeclarCollection.get(0);
- incomeTaxDeclarInfo.setDeclareStatus(TaxDeclareStatusEnum.DECLARE_SUCCESS);
- iIncomeTaxDeclar.updatePartial(incomeTaxDeclarInfo, updateSic);
- }
- }
- }
- } catch (IOException e) {
- e.printStackTrace();
- } catch (EASBizException e) {
- e.printStackTrace();
- }
- return paramMap;
- }
-
-
-
-
-
-
-
- /**
- * 撤销申请
- * @param ctx
- * @param taxDeclare
- * @return
- * @throws BOSException
- */
- protected Map cancelDeclare(Context ctx, IncomeTaxDeclarInfo taxDeclare) throws BOSException {
- return this.updateOrCancel(ctx, taxDeclare, TaskCatalogEnum.CancelTaxDeclare);
- }
-
-
-
-
- /**
- * 更正
- * @param ctx
- * @param taxDeclare
- * @return
- * @throws BOSException
- */
- protected Map updateDeclare(Context ctx, IncomeTaxDeclarInfo taxDeclare) throws BOSException {
- return updateOrCancel(ctx, taxDeclare, TaskCatalogEnum.TaxDeclareUpdate);
- }
-
-
- /**
- * 撤销申报
- *
- */
- public void cancelDeclareAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap)
- throws SHRWebException {
- this.updateOrCancel(request, response, TaskCatalogEnum.CancelTaxDeclare);
- request.setAttribute(CmpConstants.CMP_LOG_OPERATE, "cancelDeclare");
- }
-
- /**
- * 更正申请
- */
- public void updateDeclareAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap)
- throws SHRWebException {
- this.updateOrCancel(request, response, TaskCatalogEnum.TaxDeclareUpdate);
- request.setAttribute(CmpConstants.CMP_LOG_OPERATE, "updateDeclare");
- }
-
- /**
- * 撤销更正
- *
- */
- public void cancelUpdateAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap)
- throws SHRWebException {
- this.updateOrCancel(request, response, TaskCatalogEnum.CancelTaxUpdate);
- request.setAttribute(CmpConstants.CMP_LOG_OPERATE, "cancelUpdate");
- }
-
-
-
- }
|