IitDeuctionClaimAsyncServiceImpl

来自ling
跳转至: 导航搜索
package com.deloitte.tms.iit.service;

import com.deloitte.tms.base.enums.BaseDeductionTypeEnums;
import com.deloitte.tms.base.orm.hibernate.base.BaseOrg;
import com.deloitte.tms.base.orm.hibernate.user.BasePersonalInfo;
import com.deloitte.tms.base.service.admin.IBaseOrgService;
import com.deloitte.tms.base.service.user.IBasePersonalInfoService;
import com.deloitte.tms.core.result.ServiceResponse;
import com.deloitte.tms.core.service.biz.AbstractBizServiceImpl;
import com.deloitte.tms.core.util.generic.AssertHelper;
import com.deloitte.tms.iit.orm.hibernate.IitDeductionClaimH;
import com.deloitte.tms.iit.service.base.IitDeductionClaimAsyncService;
import com.deloitte.tms.iit.service.base.IitDeductionClaimService;
import com.deloitte.tms.iit.service.vo.response.DeductionClaimDetailHVo;
import com.deloitte.tms.iit.service.vo.response.DeductionClaimDetailLVo;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Map;
import java.util.concurrent.Future;

@Service("iitDeductionClaimAsyncService")
public class IitDeuctionClaimAsyncServiceImpl extends AbstractBizServiceImpl implements IitDeductionClaimAsyncService {

    @Resource
    IitDeductionClaimService iitDeductionClaimService;

    @Async
    public Future<DeductionClaimDetailHVo> convertIitDeductionClaimHToDeductionClaimDetailHVoAsync(IitDeductionClaimH claimH) throws Exception {
        long start = System.currentTimeMillis();
        DeductionClaimDetailHVo vo = iitDeductionClaimService.convertIitDeductionClaimHToDeductionClaimDetailHVo(claimH, "lvo");
        logger.info("convertIitDeductionClaimHToDeductionClaimDetailHVoAsync消耗时间:"+String.format("任务执行成功,耗时{%s}毫秒", System.currentTimeMillis() - start));

        // 消息汇总
        return new AsyncResult<>(vo);
    }

    @Async
    public Future<DeductionClaimDetailHVo> processPersionInfo(IitDeductionClaimH iitDeductionClaimH, DeductionClaimDetailHVo result) throws Exception {
        long start = System.currentTimeMillis();
        String personId = iitDeductionClaimH.getBasePersonalInfoUuid();
        if (AssertHelper.notEmpty(personId)) {
            ServiceResponse<BasePersonalInfo> personalInfoRes = getService(IBasePersonalInfoService.class)
                    .getBasePersonalInfoByUuid(personId);
            if (personalInfoRes.isSuccess()) {
                BasePersonalInfo personalInfo = personalInfoRes.getResult();
                String orgId = personalInfo.getOrgId();
                if (AssertHelper.notEmpty(orgId)) {
                    BaseOrg org = getService(IBaseOrgService.class).getOrgById(orgId);
                    if (org != null) {
                        result.setOrgCode(org.getOrgCode());
                        result.setOrgName(org.getOrgName());
                    }
                }
                result.setName(personalInfo.getName());
                result.setIdCardType(personalInfo.getIdCardType());
                result.setIdCardNumber(personalInfo.getIdCardNumber());
                result.setTaxpayerIdentityNumber(personalInfo.getTaxpayerIdentityNumber());
                result.setStaffCode(personalInfo.getStaffCode());
            }
        }
        logger.info("processPersionInfo消耗时间:"+String.format("任务执行成功,耗时{%s}毫秒", System.currentTimeMillis() - start));
        return new AsyncResult<>(result);
    }

    @Async
    public Future<DeductionClaimDetailHVo> processMonthAmount(DeductionClaimDetailHVo result) throws Exception {
        long start = System.currentTimeMillis();
        BigDecimal schoolEdu = iitDeductionClaimService.calClaimLAmtByStatuAndDeduType(result.getIitdeduClaimHUuid(), null,
                BaseDeductionTypeEnums.schoolEdu.toString());
        BigDecimal careerEdu = iitDeductionClaimService.calClaimLAmtByStatuAndDeduType(result.getIitdeduClaimHUuid(), null,
                BaseDeductionTypeEnums.careerEdu.toString());
        BigDecimal childEdu = iitDeductionClaimService.calClaimLAmtByStatuAndDeduType(result.getIitdeduClaimHUuid(), null,
                BaseDeductionTypeEnums.childEdu.toString());
        BigDecimal elder = iitDeductionClaimService.calClaimLAmtByStatuAndDeduType(result.getIitdeduClaimHUuid(), null,
                BaseDeductionTypeEnums.elder.toString());
        BigDecimal loanInterest = iitDeductionClaimService.calClaimLAmtByStatuAndDeduType(result.getIitdeduClaimHUuid(), null,
                BaseDeductionTypeEnums.loanInterest.toString());
        BigDecimal rental = iitDeductionClaimService.calClaimLAmtByStatuAndDeduType(result.getIitdeduClaimHUuid(), null,
                BaseDeductionTypeEnums.rental.toString());
        result.setSchoolEduAmout(schoolEdu);
        result.setCareerEduAmout(careerEdu);
        result.setChildEduAmout(childEdu);
        result.setElderAmout(elder);
        result.setLoanInterestAmout(loanInterest);
        result.setRentalAmout(rental);
        result.setTotalAmout(schoolEdu.add(careerEdu).add(childEdu).add(elder).add(loanInterest).add(rental));
        logger.info("processMonthAmount消耗时间:"+String.format("任务执行成功,耗时{%s}毫秒", System.currentTimeMillis() - start));
        return new AsyncResult<>(result);
    }

    @Async
    public Future<DeductionClaimDetailHVo> processYearSum(DeductionClaimDetailHVo result) throws Exception {
        long start = System.currentTimeMillis();
        Map<String, BigDecimal> yearSumMap = iitDeductionClaimService.getDeductionTypeYearSumAmount(result.getPeriodYear());
        result.setSchoolEduTotal(yearSumMap.get(BaseDeductionTypeEnums.schoolEdu.toString()));
        result.setCareerEduTotal(yearSumMap.get(BaseDeductionTypeEnums.careerEdu.toString()));
        result.setChildEduTotal(yearSumMap.get(BaseDeductionTypeEnums.childEdu.toString()));
        result.setElderTotal(yearSumMap.get(BaseDeductionTypeEnums.elder.toString()));
        result.setLoanInterestTotal(yearSumMap.get(BaseDeductionTypeEnums.loanInterest.toString()));
        result.setRentalTotal(yearSumMap.get(BaseDeductionTypeEnums.rental.toString()));

        for (DeductionClaimDetailLVo lvo : result.getIitDeductionClaimLVos()) {
            BaseDeductionTypeEnums enums = BaseDeductionTypeEnums.valueOf(lvo.getIitDeductionType());
            switch (enums) {
                case rental:// 房屋租金
                    lvo.setCurrentYearTotal(yearSumMap.get(BaseDeductionTypeEnums.rental.toString()));
                    break;
                case elder:// 赡养老人
                    lvo.setCurrentYearTotal(yearSumMap.get(BaseDeductionTypeEnums.elder.toString()));
                    break;
                case childEdu:// 子女教育
                    lvo.setCurrentYearTotal(yearSumMap.get(BaseDeductionTypeEnums.childEdu.toString()));
                    break;
                case careerEdu:// 职业继续教育
                    lvo.setCurrentYearTotal(yearSumMap.get(BaseDeductionTypeEnums.careerEdu.toString()));
                    break;
                case schoolEdu:// 学历继续教育
                    lvo.setCurrentYearTotal(yearSumMap.get(BaseDeductionTypeEnums.schoolEdu.toString()));
                    break;
                case loanInterest:// 贷款利息
                    lvo.setCurrentYearTotal(yearSumMap.get(BaseDeductionTypeEnums.loanInterest.toString()));
                    break;
                default:
            }
        }
        logger.info("processYearSum消耗时间:"+String.format("任务执行成功,耗时{%s}毫秒", System.currentTimeMillis() - start));
        return new AsyncResult<>(result);
    }
}