java110 4 роки тому
батько
коміт
9db9c4a1eb

+ 95 - 0
service-job/src/main/java/com/java110/job/adapt/report/ReportOwnerPayFeeAdapt.java

@@ -0,0 +1,95 @@
+package com.java110.job.adapt.report;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson.serializer.SerializerFeature;
+import com.java110.dto.fee.FeeDetailDto;
+import com.java110.dto.fee.FeeDto;
+import com.java110.entity.order.Business;
+import com.java110.intf.fee.IFeeDetailInnerServiceSMO;
+import com.java110.intf.fee.IFeeInnerServiceSMO;
+import com.java110.job.adapt.DatabusAdaptImpl;
+import com.java110.job.adapt.report.asyn.ISaveReportOwnerPayFee;
+import com.java110.po.fee.PayFeeDetailPo;
+import com.java110.utils.util.Assert;
+import com.java110.utils.util.BeanConvertUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 生成 业主缴费表 报表
+ * 武汉物业公司需求 生成业主每月缴费明细表
+ *
+ * @author 吴学文
+ * @date 2020-12-11  18:54
+ */
+@Component(value = "reportOwnerPayFeeAdapt")
+public class ReportOwnerPayFeeAdapt extends DatabusAdaptImpl {
+
+    private static Logger logger = LoggerFactory.getLogger(ReportOwnerPayFeeAdapt.class);
+
+
+    @Autowired
+    private IFeeInnerServiceSMO feeInnerServiceSMOImpl;
+
+    @Autowired
+    private IFeeDetailInnerServiceSMO feeDetailInnerServiceSMOImpl;
+
+
+    @Autowired
+    private ISaveReportOwnerPayFee saveReportOwnerPayFeeImpl;
+
+
+    public final static String ALI_SMS_DOMAIN = "ALI_SMS";
+
+    @Override
+    public void execute(Business business, List<Business> businesses) {
+        JSONObject data = business.getData();
+        JSONArray businessPayFeeDetails = null;
+        if (data == null) {
+            FeeDetailDto feeDetailDto = new FeeDetailDto();
+            feeDetailDto.setbId(business.getbId());
+            List<FeeDetailDto> feeDetailDtos = feeDetailInnerServiceSMOImpl.queryFeeDetails(feeDetailDto);
+            Assert.listOnlyOne(feeDetailDtos, "未查询到缴费记录");
+            businessPayFeeDetails = JSONArray.parseArray(JSONArray.toJSONString(feeDetailDtos, SerializerFeature.WriteDateUseDateFormat));
+        } else if (data.containsKey(PayFeeDetailPo.class.getSimpleName())) {
+            Object bObj = data.get(PayFeeDetailPo.class.getSimpleName());
+            if (bObj instanceof JSONObject) {
+                businessPayFeeDetails = new JSONArray();
+                businessPayFeeDetails.add(bObj);
+            } else if (bObj instanceof Map) {
+                businessPayFeeDetails = new JSONArray();
+                businessPayFeeDetails.add(JSONObject.parseObject(JSONObject.toJSONString(bObj)));
+            } else if (bObj instanceof List) {
+                businessPayFeeDetails = JSONArray.parseArray(JSONObject.toJSONString(bObj));
+            } else {
+                businessPayFeeDetails = (JSONArray) bObj;
+            }
+        } else {
+            return;
+        }
+        for (int bPayFeeDetailIndex = 0; bPayFeeDetailIndex < businessPayFeeDetails.size(); bPayFeeDetailIndex++) {
+            JSONObject businessPayFeeDetail = businessPayFeeDetails.getJSONObject(bPayFeeDetailIndex);
+            doSendPayFeeDetail(business, businessPayFeeDetail);
+        }
+    }
+
+    private void doSendPayFeeDetail(Business business, JSONObject businessPayFeeDetail) {
+        //查询缴费明细
+        PayFeeDetailPo payFeeDetailPo = BeanConvertUtil.covertBean(businessPayFeeDetail, PayFeeDetailPo.class);
+
+        FeeDto feeDto = new FeeDto();
+        feeDto.setFeeId(payFeeDetailPo.getFeeId());
+        feeDto.setCommunityId(payFeeDetailPo.getCommunityId());
+        List<FeeDto> feeDtos = feeInnerServiceSMOImpl.queryFees(feeDto);
+        Assert.listOnlyOne(feeDtos, "未查询到费用信息");
+        saveReportOwnerPayFeeImpl.saveData(payFeeDetailPo, feeDtos.get(0));
+    }
+
+
+}

+ 23 - 0
service-job/src/main/java/com/java110/job/adapt/report/asyn/ISaveReportOwnerPayFee.java

@@ -0,0 +1,23 @@
+package com.java110.job.adapt.report.asyn;/*
+ * 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.
+ */
+
+import com.java110.dto.fee.FeeDto;
+import com.java110.po.fee.PayFeeDetailPo;
+
+public interface ISaveReportOwnerPayFee {
+
+    void saveData(PayFeeDetailPo payFeeDetailPo, FeeDto feeDto);
+}

+ 145 - 0
service-job/src/main/java/com/java110/job/adapt/report/asyn/impl/SaveReportOwnerPayFeeImpl.java

@@ -0,0 +1,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;
+    }
+}