| @@ -0,0 +1,31 @@ | |||||
| update mall_permission set name = '账单催缴' where name = '商户账单'; | |||||
| INSERT INTO `mall_permission` | |||||
| (`id`,`name`, `parent_id`,`available`,`permission`,`resource_type`, `module_color`, `module_color_num`, `url`, `icon`, `version_type`,`sort`) | |||||
| VALUES | |||||
| (414, '商户账单', 4, 'Y', null, 1, null, null, 'merchantBillList', 'icon-icon-test2', 0, 402); | |||||
| DROP TABLE IF EXISTS `mall_sale_type` ; | |||||
| CREATE TABLE `mall_sale_type` ( | |||||
| `id` bigint(64) NOT NULL, | |||||
| `name` varchar(32) DEFAULT NULL COMMENT '销售类型', | |||||
| `type` tinyint(2) DEFAULT NULL COMMENT '资源类型1:尊享全能版 2:尊享营销版 3.速享版', | |||||
| `period` tinyint(2) DEFAULT NULL COMMENT '有效期(单位月)', | |||||
| `menus` json DEFAULT NULL COMMENT '菜单列表', | |||||
| PRIMARY KEY (`id`), | |||||
| UNIQUE `id_UNIQUE` USING BTREE (`id`) comment '' | |||||
| ) ENGINE=`InnoDB` ROW_FORMAT=DYNAMIC COMMENT='系统销售表' CHECKSUM=0 DELAY_KEY_WRITE=0; | |||||
| INSERT INTO `mall_sale_type` | |||||
| (`id`,`name`, `type`, `period`, `menus`) | |||||
| VALUES | |||||
| (1, '尊享全能版', 1, 12, | |||||
| '[1,2,3,4,5,6,7,8,9,10,50,101,102,103,104,105,106,107,108,201,202,203,204,205,206,211,212,221,222,251,301,302,303,304,305,306,401,402,403,404,405,406,407,408,409,410,411,412,413,414,501,502,503,504,505,506,507,508,509,511,512,513,521,522,523,531,532,533,591,595,601,602,603,604,605,606,607,608,609,610,611,612,621,622,623,624,625,626,627,641,642,643,644,645,651,661,662,663,671,672,673,674,681,682,683,684,685,691,692,693,694,695,701,702,711,712,713,901,902,903,931,932,951,952,961,962,965,966,967]' | |||||
| ), | |||||
| (2, '尊享营销版', 2, 12, | |||||
| '[1,2,4,5,6,7,8,9,10,50,101,102,103,104,105,106,107,201,202,203,204,205,211,212,221,222,251,409,410,411,501,502,503,504,505,506,507,508,509,511,512,513,521,522,523,531,532,533,591,595,601,602,603,604,605,606,607,608,609,610,611,612,621,622,623,624,625,626,627,641,642,643,644,645,651,661,662,663,671,672,673,674,681,682,683,684,685,691,692,693,694,695,701,702,711,712,713,901,902,903,931,932,951,961]' | |||||
| ), | |||||
| (3, '速享版', 3, 1, | |||||
| '[2,4,5,6,7,10,50,201,202,205,211,212,221,222,251,409,410,411,501,502,503,504,505,506,507,508,511,512,513,521,522,523,531,532,533,591,592,601,602,603,604,605,606,607,608,609,610,611,612,621,622,623,624,625,626,641,642,643,644,645,651,661,662,663,671,672,673,674,681,682,683,684,685,691,692,693,694,695,701,702,711,712,713,901,902,903,931,932]' | |||||
| ) | |||||
| ; | |||||
| @@ -1,15 +1,16 @@ | |||||
| package com.iformall.schedule; | package com.iformall.schedule; | ||||
| import com.alibaba.fastjson.JSONObject; | import com.alibaba.fastjson.JSONObject; | ||||
| import com.iformall.domain.dto.KwMeterDataDto; | |||||
| import com.iformall.domain.po.*; | import com.iformall.domain.po.*; | ||||
| import com.iformall.enums.EnumBillDailyType; | |||||
| import com.iformall.enums.EnumBillPayWay; | |||||
| import com.iformall.enums.EnumDelStatus; | |||||
| import com.iformall.enums.EnumPowerBillBuildWay; | |||||
| import com.iformall.domain.vo.KwMeterDataVo; | |||||
| import com.iformall.enums.*; | |||||
| import com.iformall.mapper.KwMerchantMeterMapper; | |||||
| import com.iformall.mapper.WxMerchantPowerBillConfigMapper; | import com.iformall.mapper.WxMerchantPowerBillConfigMapper; | ||||
| import com.iformall.mapper.WxMerchantShopMapper; | import com.iformall.mapper.WxMerchantShopMapper; | ||||
| import com.iformall.mapper.WxPowerBillAutoConfigMapper; | import com.iformall.mapper.WxPowerBillAutoConfigMapper; | ||||
| import com.iformall.service.WxBillDailyService; | import com.iformall.service.WxBillDailyService; | ||||
| import com.iformall.service.kw.KwMeterDataService; | |||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| @@ -47,6 +48,12 @@ public class PowerBillAutoBuildSchedule { | |||||
| @Autowired | @Autowired | ||||
| private WxMerchantShopMapper wxMerchantShopMapper; | private WxMerchantShopMapper wxMerchantShopMapper; | ||||
| @Autowired | |||||
| KwMeterDataService kwMeterDataService; | |||||
| @Autowired | |||||
| KwMerchantMeterMapper kwMerchantMeterMapper; | |||||
| /** | /** | ||||
| * 每天5点执行 | * 每天5点执行 | ||||
| */ | */ | ||||
| @@ -75,25 +82,37 @@ public class PowerBillAutoBuildSchedule { | |||||
| private void buildPowerBill(WxMerchantPowerBillConfig wxMerchantPowerBillConfig, WxPowerBillAutoConfig wxPowerBillAutoConfig) { | private void buildPowerBill(WxMerchantPowerBillConfig wxMerchantPowerBillConfig, WxPowerBillAutoConfig wxPowerBillAutoConfig) { | ||||
| String unitPrice = wxPowerBillAutoConfig.getUnitPrice(); | |||||
| Date startdate = getLastMonthDate().get("startdate"); | |||||
| Date enddate = getLastMonthDate().get("enddate"); | |||||
| Map<String, Date> monthDate = getLastMonthDate(); | |||||
| Date startdate = monthDate.get("startdate"); | |||||
| Date enddate = monthDate.get("enddate"); | |||||
| Date lastdate = monthDate.get("lastdate"); | |||||
| MallUserInfo mallUserInfo = getMallUserInfo(); | MallUserInfo mallUserInfo = getMallUserInfo(); | ||||
| WxBillDaily wxBillDaily = getBillDaily(wxMerchantPowerBillConfig); | WxBillDaily wxBillDaily = getBillDaily(wxMerchantPowerBillConfig); | ||||
| JSONObject priceDetal = new JSONObject(); | JSONObject priceDetal = new JSONObject(); | ||||
| Date receiveDate = getReceiveDate(Integer.parseInt(wxPowerBillAutoConfig.getReceiveDay())); | Date receiveDate = getReceiveDate(Integer.parseInt(wxPowerBillAutoConfig.getReceiveDay())); | ||||
| long receivePay = 0L; | |||||
| Long merchantId = wxMerchantPowerBillConfig.getMerchantId(); | |||||
| if (wxMerchantPowerBillConfig.getBuildWay().equals(EnumPowerBillBuildWay.METER.getCode())) { | if (wxMerchantPowerBillConfig.getBuildWay().equals(EnumPowerBillBuildWay.METER.getCode())) { | ||||
| //根据日期拉取电量 单价 * 电量 = 电费 | //根据日期拉取电量 单价 * 电量 = 电费 | ||||
| int usedPower = getUsedPower(startdate, lastdate, merchantId); | |||||
| if (usedPower == 0) { | |||||
| logger.info("没有电量使用,不生成账单>>>>商户ID:" + merchantId); | |||||
| return; | |||||
| } | |||||
| String price = wxMerchantPowerBillConfig.getPrice(); | |||||
| priceDetal.put("unitPrice", price); | |||||
| priceDetal.put("power", usedPower); | |||||
| receivePay = new BigDecimal(price).multiply(new BigDecimal(100)) | |||||
| .multiply(new BigDecimal(usedPower)).longValue(); | |||||
| } else { | } else { | ||||
| String unitPrice = wxPowerBillAutoConfig.getUnitPrice(); | |||||
| String price = wxMerchantPowerBillConfig.getPrice(); | String price = wxMerchantPowerBillConfig.getPrice(); | ||||
| priceDetal.put("unitPrice", unitPrice); | priceDetal.put("unitPrice", unitPrice); | ||||
| priceDetal.put("power", 0); | priceDetal.put("power", 0); | ||||
| long receivePay = new BigDecimal(price).multiply(new BigDecimal(100)).longValue(); | |||||
| wxBillDaily.setReceivePay(receivePay); | |||||
| wxBillDaily.setNeedPay(receivePay); | |||||
| receivePay = new BigDecimal(price).multiply(new BigDecimal(100)).longValue(); | |||||
| } | } | ||||
| wxBillDaily.setReceivePay(receivePay); | |||||
| wxBillDaily.setNeedPay(receivePay); | |||||
| wxBillDaily.setReceiveDate(receiveDate); | wxBillDaily.setReceiveDate(receiveDate); | ||||
| wxBillDaily.setStarttime(startdate); | wxBillDaily.setStarttime(startdate); | ||||
| wxBillDaily.setEndtime(enddate); | wxBillDaily.setEndtime(enddate); | ||||
| @@ -102,6 +121,28 @@ public class PowerBillAutoBuildSchedule { | |||||
| } | } | ||||
| private int getUsedPower(Date startdate, Date lastdate, Long merchantId) { | |||||
| KwMerchantMeter kwMerchantMeter = new KwMerchantMeter(); | |||||
| kwMerchantMeter.setMerchantId(merchantId); | |||||
| kwMerchantMeter.setStatus(EnumMerchantMeterStatus.VALID.getCode()); | |||||
| List<KwMerchantMeter> merchantMeterList = kwMerchantMeterMapper.select(kwMerchantMeter); | |||||
| int usedPower = 0; | |||||
| if (!merchantMeterList.isEmpty()) { | |||||
| int size = merchantMeterList.size(); | |||||
| for (int i = 0; i < size; i++) { | |||||
| KwMerchantMeter merchantMeter = merchantMeterList.get(i); | |||||
| KwMeterDataDto kwMeterDataDto = new KwMeterDataDto(); | |||||
| kwMeterDataDto.setTenantId(merchantMeter.getTenantId()); | |||||
| kwMeterDataDto.setMeterId(merchantMeter.getMeterId()); | |||||
| kwMeterDataDto.setStartTime(startdate); | |||||
| kwMeterDataDto.setEndTime(lastdate); | |||||
| KwMeterDataVo power = kwMeterDataService.getPower(kwMeterDataDto); | |||||
| usedPower += power.getUsedPower(); | |||||
| } | |||||
| } | |||||
| return usedPower; | |||||
| } | |||||
| private WxBillDaily getBillDaily(WxMerchantPowerBillConfig wxMerchantPowerBillConfig) { | private WxBillDaily getBillDaily(WxMerchantPowerBillConfig wxMerchantPowerBillConfig) { | ||||
| WxBillDaily wxBillDaily = new WxBillDaily(); | WxBillDaily wxBillDaily = new WxBillDaily(); | ||||
| Long merchantId = wxMerchantPowerBillConfig.getMerchantId(); | Long merchantId = wxMerchantPowerBillConfig.getMerchantId(); | ||||
| @@ -125,13 +166,17 @@ public class PowerBillAutoBuildSchedule { | |||||
| now = now.with(TemporalAdjusters.lastDayOfMonth()); | now = now.with(TemporalAdjusters.lastDayOfMonth()); | ||||
| Instant end = now.atStartOfDay().atZone(zoneId).toInstant(); | Instant end = now.atStartOfDay().atZone(zoneId).toInstant(); | ||||
| Date last = Date.from(end); | Date last = Date.from(end); | ||||
| now = now.with(TemporalAdjusters.firstDayOfNextMonth()); | |||||
| Instant lastday = now.atStartOfDay().atZone(zoneId).toInstant(); | |||||
| Date next = Date.from(lastday); | |||||
| Map<String, Date> dateMap = new HashMap<>(2); | Map<String, Date> dateMap = new HashMap<>(2); | ||||
| dateMap.put("startdate", first); | dateMap.put("startdate", first); | ||||
| dateMap.put("enddate", last); | dateMap.put("enddate", last); | ||||
| dateMap.put("lastdate", next); | |||||
| return dateMap; | return dateMap; | ||||
| } | } | ||||
| private Date getReceiveDate(Integer day) { | |||||
| private Date getReceiveDate(int day) { | |||||
| ZoneId zoneId = ZoneOffset.systemDefault(); | ZoneId zoneId = ZoneOffset.systemDefault(); | ||||
| LocalDate of = LocalDate.of(LocalDate.now().getYear(), LocalDate.now().getMonth(), day); | LocalDate of = LocalDate.of(LocalDate.now().getYear(), LocalDate.now().getMonth(), day); | ||||
| Instant instant = of.atStartOfDay().atZone(zoneId).toInstant(); | Instant instant = of.atStartOfDay().atZone(zoneId).toInstant(); | ||||