From d582febb0419f7cb564b752317b183d0f78b5eb9 Mon Sep 17 00:00:00 2001 From: gongbiao Date: Thu, 23 May 2019 11:22:34 +0800 Subject: [PATCH] =?UTF-8?q?[=E6=97=A5=E5=B8=B8=E8=B4=B9=E7=94=A8=E8=B4=A6?= =?UTF-8?q?=E5=8D=95][=E4=BF=AE=E6=94=B9][=E5=AF=BC=E5=85=A5=E6=95=B0?= =?UTF-8?q?=E6=8D=AE]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/mem/BillDailyAsyncTask.java | 71 ++++++++++++++++--- .../service/impl/WxBillDailyServiceImpl.java | 71 ++----------------- 2 files changed, 69 insertions(+), 73 deletions(-) diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/mem/BillDailyAsyncTask.java b/mallinkAdmin/src/main/java/com/iformall/controller/mem/BillDailyAsyncTask.java index e06e11ad5..3464352dc 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/mem/BillDailyAsyncTask.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/mem/BillDailyAsyncTask.java @@ -6,7 +6,11 @@ import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult; import cn.afterturn.easypoi.handler.impl.ExcelDataHandlerDefaultImpl; import cn.afterturn.easypoi.handler.inter.IExcelDataHandler; import com.iformall.domain.po.MallUserInfo; +import com.iformall.domain.po.WxShop; import com.iformall.domain.vo.WxBillDailyVo; +import com.iformall.enums.EnumDelStatus; +import com.iformall.enums.EnumShopStatus; +import com.iformall.mapper.WxShopMapper; import com.iformall.service.WxBillDailyService; import org.apache.shiro.session.UnknownSessionException; import org.slf4j.Logger; @@ -17,6 +21,8 @@ import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import java.io.File; +import java.math.BigDecimal; +import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; @@ -30,6 +36,9 @@ public class BillDailyAsyncTask { @Autowired StringRedisTemplate stringRedisTemplate; + @Autowired + WxShopMapper wxShopMapper; + private class BillDailyExcelHandler extends ExcelDataHandlerDefaultImpl { @Override public Object importHandler(WxBillDailyVo obj, String name, Object value) { @@ -56,9 +65,9 @@ public class BillDailyAsyncTask { public void importExcelData(File file, MallUserInfo user, String importKey, String tenantId) { ImportParams params = new ImportParams(); // 需要验证 - params.setImportFields(new String[]{"商铺号", "费用类型", "实际应收金额", "实收金额", "截止收款日期", "逾期天数"}); + params.setImportFields(new String[]{"商铺号", "费用类型", "实际应收金额(元)", "实收金额(元)", "缴款截止日期", "逾期天数"}); IExcelDataHandler handler = new BillDailyAsyncTask.BillDailyExcelHandler(); - handler.setNeedHandlerFields(new String[]{"商铺号", "费用类型", "实际应收金额", "实收金额", "截止收款日期", "逾期天数"}); + handler.setNeedHandlerFields(new String[]{"商铺号", "费用类型", "实际应收金额(元)", "实收金额(元)", "缴款截止日期", "逾期天数"}); params.setNeedVerify(true); ExcelImportResult datalist = null; @@ -83,23 +92,67 @@ public class BillDailyAsyncTask { List successList = datalist.getList(); List failList = datalist.getFailList(); + List processList = new ArrayList<>(); + + int fail = 0; + for (WxBillDailyVo vo : successList) { + + //店铺 + WxShop shop = new WxShop(); + shop.setShopNumber(vo.getShopNumber()); + shop.setTenantId(tenantId); + shop.setStatus(EnumShopStatus.RENT.getCode()); + shop.setIsDel(EnumDelStatus.NOT_DEL.getCode()); + WxShop wxShop = wxShopMapper.selectOne(shop); + if (wxShop == null) { + logger.error("店铺不存在", vo.toString()); + fail++; + continue; + } - logger.info("验证通过的数量: " + successList.size()); + String receivePayStr = vo.getReceivePayStr(); + double receivePayD = new BigDecimal(receivePayStr).doubleValue(); + if (receivePayD <= 0) { + logger.error("实际应收金额小于等于0", vo.toString()); + fail++; + continue; + } + String payStr = vo.getPayStr(); + double payD = new BigDecimal(payStr).doubleValue(); + if (payD < 0) { + logger.error("实收金额小于0", vo.toString()); + fail++; + continue; + } + if (receivePayD < payD) { + logger.error("实际应收金额小于实收金额", vo.toString()); + fail++; + continue; + } + long receivePay = new BigDecimal(receivePayD).multiply(new BigDecimal(100)).longValue(); + vo.setReceivePay(receivePay); + long pay = new BigDecimal(payD).multiply(new BigDecimal(100)).longValue(); + vo.setPay(pay); + vo.setTenantId(tenantId); + vo.setShopId(wxShop.getId()); + vo.setRentShopType(wxShop.getType()); + processList.add(vo); + } + logger.info("验证通过的数量: " + processList.size()); logger.info("验证未通过的数量: " + failList.size()); - int total = successList.size() + failList.size(); - int all_success = successList.size(); - int all_fail = failList.size(); + int all_success = processList.size(); + int all_fail = failList.size() + fail; + int total = processList.size() + all_fail; //添加到redis里 set_redis_value(importKey, "" + total, "" + all_success, "0", "" + all_fail, total == all_fail); - if (successList.size() > 0) { + if (processList.size() > 0) { try { - successList.parallelStream().forEach(billDaily -> { + processList.parallelStream().forEach(billDaily -> { try { //插入数据 - billDaily.setTenantId(tenantId); wxBillDailyService.insertData(billDaily, importKey, user); } catch (UnknownSessionException ue) { logger.error("session :" + ue.getMessage()); diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxBillDailyServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxBillDailyServiceImpl.java index 03e7b703b..64e3c6a6f 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxBillDailyServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxBillDailyServiceImpl.java @@ -17,7 +17,6 @@ import com.iformall.service.ExcelService; import com.iformall.service.WxBillActionService; import com.iformall.service.WxBillDailyService; import com.iformall.utils.DateUtils; -import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -242,69 +241,13 @@ public class WxBillDailyServiceImpl implements WxBillDailyService { @Override public void insertData(WxBillDailyVo billDaily, String importKey, MallUserInfo user) { - String shopNumber = billDaily.getShopNumber(); - if (StringUtils.isBlank(shopNumber)) { - stringRedisTemplate.opsForHash().increment(importKey, "failCount", 1); - logger.error("商铺号为空", billDaily.toString()); - return; - } - //店铺 - WxShop shop = new WxShop(); - shop.setShopNumber(shopNumber); - shop.setTenantId(billDaily.getTenantId()); - shop.setStatus(EnumShopStatus.RENT.getCode()); - shop.setIsDel(EnumDelStatus.NOT_DEL.getCode()); - WxShop wxShop = wxShopMapper.selectOne(shop); - if (wxShop == null) { - stringRedisTemplate.opsForHash().increment(importKey, "failCount", 1); - logger.error("商铺未找到", billDaily.toString()); - return; - } - Integer type = billDaily.getType(); - if (type == null) { - stringRedisTemplate.opsForHash().increment(importKey, "failCount", 1); - logger.error("账单类型为空", billDaily.toString()); - return; - } - String receivePayStr = billDaily.getReceivePayStr(); - if (StringUtils.isBlank(receivePayStr)) { - stringRedisTemplate.opsForHash().increment(importKey, "failCount", 1); - logger.error("实际应收金额为空", billDaily.toString()); - return; - } - double receivePayD = new BigDecimal(receivePayStr).doubleValue(); - if (receivePayD <= 0) { - stringRedisTemplate.opsForHash().increment(importKey, "failCount", 1); - logger.error("实际应收金额小于等于0", billDaily.toString()); - return; - } - String payStr = billDaily.getPayStr(); - if (StringUtils.isBlank(payStr)) { - stringRedisTemplate.opsForHash().increment(importKey, "failCount", 1); - logger.error("实收金额为空", billDaily.toString()); - return; - } - double payD = new BigDecimal(payStr).doubleValue(); - if (payD < 0) { - stringRedisTemplate.opsForHash().increment(importKey, "failCount", 1); - logger.error("实收金额小于0", billDaily.toString()); - return; - } - - if (receivePayD < payD) { - stringRedisTemplate.opsForHash().increment(importKey, "failCount", 1); - logger.error("实际应收金额小于实收金额", billDaily.toString()); - return; - } + Integer type = billDaily.getType(); WxBillDaily wxBillDaily = new WxBillDaily(); - - long receivePay = new BigDecimal(receivePayD).multiply(new BigDecimal(100)).longValue(); + Long receivePay = billDaily.getReceivePay(); wxBillDaily.setReceivePay(receivePay); - - long pay = new BigDecimal(payD).multiply(new BigDecimal(100)).longValue(); + Long pay = billDaily.getPay(); wxBillDaily.setPay(pay); - wxBillDaily.setOwe(receivePay - pay); wxBillDaily.setType(type); Date receiveDate = billDaily.getReceiveDate(); @@ -320,20 +263,20 @@ public class WxBillDailyServiceImpl implements WxBillDailyService { } else { wxBillDaily.setStatus(EnumBillRentStatus.WAIT_PAY.getCode()); } - if (receivePayD == payD) { + if (receivePay.equals(pay)) { wxBillDaily.setStatus(EnumBillRentStatus.PAID.getCode()); } wxBillDaily.setUserId(user.getId()); - wxBillDaily.setShopId(wxShop.getId()); - wxBillDaily.setRentShopType(wxShop.getType()); + wxBillDaily.setShopId(billDaily.getShopId()); + wxBillDaily.setRentShopType(billDaily.getRentShopType()); wxBillDaily.setPayWay(EnumBillPayWay.OTHER.getCode()); wxBillDaily.setCreatetime(date); wxBillDaily.setUpdatetime(date); wxBillDaily.setIsDel(EnumDelStatus.NOT_DEL.getCode()); //商户 WxMerchantShop merchantShop = new WxMerchantShop(); - merchantShop.setShopId(wxShop.getId()); + merchantShop.setShopId(billDaily.getShopId()); merchantShop.setIsDel(EnumDelStatus.NOT_DEL.getCode()); WxMerchantShop wxMerchantShop = wxMerchantShopMapper.selectOne(merchantShop); wxBillDaily.setMerchantId(wxMerchantShop.getMerchantId());