java110
2021-06-11 9db9c4a1eb7f20bff200239faa670805cf1c91c2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
 * Copyright 2017-2020 吴学文 and java110 team.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.java110.job.adapt.report.asyn.impl;
 
import com.java110.core.factory.GenerateCodeFactory;
import com.java110.core.smo.IComputeFeeSMO;
import com.java110.dto.fee.FeeAttrDto;
import com.java110.dto.fee.FeeDto;
import com.java110.intf.report.IReportOwnerPayFeeInnerServiceSMO;
import com.java110.job.adapt.report.ReportOwnerPayFeeAdapt;
import com.java110.job.adapt.report.asyn.ISaveReportOwnerPayFee;
import com.java110.po.fee.PayFeeDetailPo;
import com.java110.po.reportOwnerPayFee.ReportOwnerPayFeePo;
import com.java110.utils.util.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
 
import java.math.BigDecimal;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
 
/**
 * @desc add by 吴学文 16:28
 */
@Service
public class SaveReportOwnerPayFeeImpl implements ISaveReportOwnerPayFee {
    private static Logger logger = LoggerFactory.getLogger(SaveReportOwnerPayFeeImpl.class);
 
 
    @Autowired
    private IComputeFeeSMO computeFeeSMOImpl;
 
    @Autowired
    private IReportOwnerPayFeeInnerServiceSMO reportOwnerPayFeeInnerServiceSMOImpl;
 
    @Override
    @Async
    public void saveData(PayFeeDetailPo payFeeDetailPo, FeeDto feeDto) {
        List<String> dateSub = null;
        try {
            dateSub = analyseDate(DateUtil.getDateFromString(payFeeDetailPo.getStartTime(), DateUtil.DATE_FORMATE_STRING_A),
                    DateUtil.getDateFromString(payFeeDetailPo.getEndTime(), DateUtil.DATE_FORMATE_STRING_A));
        } catch (ParseException e) {
            logger.error("出错了", e);
            return;
        }
 
        if (dateSub.size() < 1) {
            return;
        }
 
        BigDecimal amount = new BigDecimal(payFeeDetailPo.getReceivedAmount());
        amount = amount.divide(new BigDecimal(dateSub.size()), BigDecimal.ROUND_HALF_UP);
 
        for (String dateStr : dateSub) {
            try {
                dealOwnerPayFee(dateStr, payFeeDetailPo, feeDto, amount.doubleValue());
            } catch (Exception e) {
                logger.error("出错了", e);
                return;
            }
        }
    }
 
 
    private void dealOwnerPayFee(String dateStr, PayFeeDetailPo payFeeDetailPo, FeeDto feeDto, double amount) throws Exception {
        ReportOwnerPayFeePo reportOwnerPayFeePo = new ReportOwnerPayFeePo();
        reportOwnerPayFeePo.setCommunityId(payFeeDetailPo.getCommunityId());
        reportOwnerPayFeePo.setAmount(amount + "");
        reportOwnerPayFeePo.setConfigId(feeDto.getConfigId());
        reportOwnerPayFeePo.setConfigName(feeDto.getFeeName());
        reportOwnerPayFeePo.setFeeName(feeDto.getFeeName());
        reportOwnerPayFeePo.setDetailId(payFeeDetailPo.getDetailId());
        reportOwnerPayFeePo.setFeeId(feeDto.getFeeId());
        //获取缴费用户楼栋单元房间号
        String payerObjName = computeFeeSMOImpl.getFeeObjName(feeDto);
        reportOwnerPayFeePo.setObjId(feeDto.getPayerObjId());
        reportOwnerPayFeePo.setObjName(payerObjName);
        reportOwnerPayFeePo.setObjType(feeDto.getPayerObjType());
        reportOwnerPayFeePo.setOwnerId(FeeAttrDto.getFeeAttrValue(feeDto, FeeAttrDto.SPEC_CD_OWNER_ID));
        reportOwnerPayFeePo.setOwnerName(FeeAttrDto.getFeeAttrValue(feeDto, FeeAttrDto.SPEC_CD_OWNER_NAME));
        reportOwnerPayFeePo.setPfDate(dateStr);
        reportOwnerPayFeePo.setPfMonth(getMonth(dateStr) + "");
        reportOwnerPayFeePo.setPfId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_pfId));
        reportOwnerPayFeePo.setPfYear(getYear(dateStr) + "");
        reportOwnerPayFeeInnerServiceSMOImpl.saveReportOwnerPayFee(reportOwnerPayFeePo);
    }
 
    public static int getMonth(String dateStr) throws Exception {
        Date date = DateUtil.getDateFromString(dateStr, DateUtil.DATE_FORMATE_STRING_B);
        Calendar c1 = Calendar.getInstance();
        c1.setTime(date);
        return c1.get(Calendar.MONTH) + 1;
    }
 
    public static int getYear(String dateStr) throws Exception {
        Date date = DateUtil.getDateFromString(dateStr, DateUtil.DATE_FORMATE_STRING_B);
        Calendar c1 = Calendar.getInstance();
        c1.setTime(date);
        return c1.get(Calendar.YEAR);
    }
 
    public static List<String> analyseDate(Date begintime, Date endtime) {
        List<String> results = new ArrayList<String>();
        Calendar c1 = Calendar.getInstance();
        Calendar c2 = Calendar.getInstance();
        c1.setTime(begintime);//2014-02-24
        c2.setTime(endtime);//2015-04-30
        String[] str = null;
        String sd = "";
        while (c1.compareTo(c2) < 0) {
//            System.out.println(c1.getTime());
            str = new String[2];
            sd = c1.get(Calendar.YEAR) + "-" + (c1.get(Calendar.MONTH) + 1) + "-01";
 
 
            if (c1.get(Calendar.MONTH) == 2) {
                c1.add(Calendar.DAY_OF_YEAR, 1);
            }
            c1.add(Calendar.MONTH, 1);
//            System.out.println("str[1]:"+str[1]);
            results.add(sd);
        }
        return results;
    }
}