diff --git a/mallinkAdmin/src/main/resources/application-dev.yml b/mallinkAdmin/src/main/resources/application-dev.yml index 0ae1a7e6a..8074ce74f 100644 --- a/mallinkAdmin/src/main/resources/application-dev.yml +++ b/mallinkAdmin/src/main/resources/application-dev.yml @@ -70,6 +70,7 @@ spring: username: ENC(2f9Nqt3c4cbVGYnhpjp9Mg==) password: ENC(2av0JfMfz141IHkG6ibI8aKzmD33bc64wcN/O43ucbo=) publisher-confirms: true + publisher-returns: true virtual-host: / flyway: enabled: true diff --git a/mallinkAdmin/src/main/resources/application-prod.yml b/mallinkAdmin/src/main/resources/application-prod.yml index 9b23d6034..2cbb45cc9 100644 --- a/mallinkAdmin/src/main/resources/application-prod.yml +++ b/mallinkAdmin/src/main/resources/application-prod.yml @@ -58,6 +58,7 @@ spring: username: ENC(lRmLd6EzgeY1RT5ktcHv9g==) password: ENC(gBI8mCjr3OC0v57jcnSb660Ux7mW03K2oePgvohhg7w=) publisher-confirms: true + publisher-returns: true virtual-host: / flyway: enabled: true diff --git a/mallinkAdmin/src/main/resources/application-test.yml b/mallinkAdmin/src/main/resources/application-test.yml index 291fdc71b..d815e5e1d 100644 --- a/mallinkAdmin/src/main/resources/application-test.yml +++ b/mallinkAdmin/src/main/resources/application-test.yml @@ -58,6 +58,7 @@ spring: username: ENC(aSRr6mnSryEqzHHz1hJf1g==) password: ENC(GnjF/mdqKdvmDYC0tIIso7+20/jBALPw39tiWCYJ4iw=) publisher-confirms: true + publisher-returns: true virtual-host: / flyway: enabled: true diff --git a/mallinkService/src/main/java/com/iformall/mq/impl/RabbitMqMessageProducer.java b/mallinkService/src/main/java/com/iformall/mq/impl/RabbitMqMessageProducer.java index 036ed2b58..cea901409 100644 --- a/mallinkService/src/main/java/com/iformall/mq/impl/RabbitMqMessageProducer.java +++ b/mallinkService/src/main/java/com/iformall/mq/impl/RabbitMqMessageProducer.java @@ -8,11 +8,16 @@ import com.iformall.service.WxMsgRecordService; import com.iformall.utils.JsonUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.slf4j.Marker; import org.springframework.amqp.core.AmqpTemplate; +import org.springframework.amqp.core.Message; +import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.amqp.rabbit.support.CorrelationData; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Profile; import org.springframework.stereotype.Service; + +import javax.annotation.PostConstruct; import java.util.UUID; /** @@ -22,42 +27,52 @@ import java.util.UUID; */ @Service @Profile(MQConfig.Impl.RABBIT_MQ) -public class RabbitMqMessageProducer implements MqBaseProducer { +public class RabbitMqMessageProducer implements MqBaseProducer , RabbitTemplate.ConfirmCallback, RabbitTemplate.ReturnCallback { private final Logger log = LoggerFactory.getLogger(this.getClass()); @Autowired - private AmqpTemplate rabbitTemplate; + private RabbitTemplate rabbitTemplate; @Autowired private WxMsgRecordMapper wxMsgRecordMapper; @Autowired private WxMsgRecordService wxMsgRecordService; -// -// @Override -// public void confirm(CorrelationData correlationData, boolean b, String s) { -// log.info("------correlationData"+correlationData.toString()); -// System.out.println(); -// if(b){ -// System.out.println(); -// }else{ -// -// } -// } + + @PostConstruct + public void init() { + rabbitTemplate.setConfirmCallback(this); + rabbitTemplate.setReturnCallback(this); + } + + @Override + public void confirm(CorrelationData correlationData, boolean ack, String cause) { + log.info("confirm:: correlationData {},ack {}, cause {}", correlationData,ack,cause); + System.out.println(); + if(ack){ + System.out.println(); + }else{ + + } + } + + + @Override + public void returnedMessage(Message message, int replyCode, String replyText, String exchange, String routingKey) { + log.info("returnedMessage::message {} 消息发送失败,应答码:{}, 应答描述:{} ,exchange: {} ,routingKey :{}", new String(message.getBody()), replyCode, replyText, exchange, routingKey); + } @Override public void sendMessage(BaseMsg data, String topic, String tags, String keys) { + String tag = UUID.randomUUID().toString(); try { - data.setUuid(UUID.randomUUID().toString()); + data.setUuid(tag); wxMsgRecordService.save(data); - //CorrelationData correlationData = new CorrelationData("16746324"); - rabbitTemplate.convertAndSend(topic, JsonUtil.obj2Json(data)); - + CorrelationData correlationData = new CorrelationData(tag); + rabbitTemplate.convertAndSend(topic, (Object) JsonUtil.obj2Json(data),correlationData); // data.setMsgStatus(EnumMsgRecordStatus.SEND_SUCC.getCode()); // wxMsgRecordMapper.update(data); log.info(data.getUuid()+"发送mq成功。"); - } catch (Exception e) { - log.error("RabbitMqMessageProducer: Send Message Error ", e); + log.error(tag + " RabbitMqMessageProducer: Send Message Error", e); } } - } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxBusinessServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxBusinessServiceImpl.java index 0fce5b60d..b8bb0475a 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxBusinessServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxBusinessServiceImpl.java @@ -4,15 +4,14 @@ import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.iformall.common.ResultData; import com.iformall.domain.po.*; -import com.iformall.enums.EnumBusinessFilter; -import com.iformall.enums.EnumIsPreview; -import com.iformall.enums.EnumRentContractStatus; +import com.iformall.enums.*; import com.iformall.mapper.WxBusinessMapper; import com.iformall.mapper.WxPropertyContractMapper; import com.iformall.mapper.WxRentContractMapper; import com.iformall.service.WxBusinessService; import com.iformall.service.WxPropertyContractService; import com.iformall.service.WxRentContractService; +import com.iformall.utils.DateUtils; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; @@ -21,6 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.math.BigDecimal; +import java.math.RoundingMode; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -28,12 +28,12 @@ import java.util.Map; @Service public class WxBusinessServiceImpl implements WxBusinessService { private final Logger logger = LoggerFactory.getLogger(this.getClass()); - - @Autowired + + @Autowired WxBusinessMapper wxBusinessMapper; - @Autowired + @Autowired private WxRentContractMapper wxRentContractMapper; - @Autowired + @Autowired private WxRentContractService wxRentContractService; @Autowired private WxPropertyContractMapper wxPropertyContractMapper; @@ -69,14 +69,12 @@ public class WxBusinessServiceImpl implements WxBusinessService { } @Override - public List> businessDataList(WxBusiness wxBusiness,Long userid) { + public List> businessDataList(WxBusiness wxBusiness, Long userid) { + //1 得到天数+1 + int day = DateUtils.daysBetween(wxBusiness.getStartdate(), wxBusiness.getEnddate()) + 1; List> resultList = wxBusinessMapper.businessDataList(wxBusiness); resultList.stream().forEach(e->{ - WxBusiness business = new WxBusiness(); - business.setId((Integer) e.get("id")); - BigDecimal businessSumMoney = new BigDecimal(0); - WxRentContract query = new WxRentContract(); query.setBusinessId((Integer) e.get("id")); List rentContractList = wxRentContractMapper.select(query); @@ -90,16 +88,13 @@ public class WxBusinessServiceImpl implements WxBusinessService { System.out.println("rent rentInfo is null:{}"+dbRent.getId()); continue; } - logger.info("业态分析>>>>>>>>>>>>>>>>>>租金合同ID:" + dbRent.getId()); - List previewBill = new ArrayList<>(); - WxBillRent preview = new WxBillRent(); - preview.setStarttime(dbRent.getRentalStartDate()); - preview.setEndtime(dbRent.getRentalEndDate()); - previewBill.add(preview); - - dbRent.setPreviewBillRentList(previewBill); - List billRentList = wxRentContractService.buildRent(new WxMerchant(),userid,dbRent, EnumIsPreview.YES.getCode(), false); - businessSumMoney = businessSumMoney.add(new BigDecimal(billRentList.get(0).getReceivePay())); + Long price = dbRent.getPrice(); + Integer priceUnit = dbRent.getPriceUnit(); + Integer type = dbRent.getType(); + Integer period = dbRent.getReceivePeriod(); + Integer busDiscountTime = dbRent.getBusDiscountTime(); + BigDecimal priceDecimal = getPriceDecimal(day, price, priceUnit, type, period, busDiscountTime); + businessSumMoney = businessSumMoney.add(priceDecimal); } WxPropertyContract pquery = new WxPropertyContract(); @@ -116,15 +111,10 @@ public class WxBusinessServiceImpl implements WxBusinessService { continue; } logger.info("业态分析>>>>>>>>>>>>>>>>>>物业合同ID:" + dbRent.getId()); - List previewBill = new ArrayList<>(); - WxBillProperty preview = new WxBillProperty(); - preview.setStarttime(dbRent.getRentalStartDate()); - preview.setEndtime(dbRent.getRentalEndDate()); - previewBill.add(preview); - - dbRent.setPreviewBillRentList(previewBill); - List billRentList = wxPropertyContractService.buildProperty(new WxMerchant(),userid,dbRent, EnumIsPreview.YES.getCode(), false); - businessSumMoney = businessSumMoney.add(new BigDecimal(billRentList.get(0).getReceivePay())); + Long price = dbRent.getPrice(); + Integer priceUnit = dbRent.getPriceUnit(); + BigDecimal priceDecimal = getPriceDecimal(day, price, priceUnit, EnumRentContractType.RENT_BY_AREA.getCode(), null, null); + businessSumMoney = businessSumMoney.add(priceDecimal); } logger.info("业态分析>>>>>>>>>>>>>>>>>>商铺面积:" + e.get("area").toString()); if (e.get("area") == null || "0".equals(e.get("area").toString()) || @@ -141,6 +131,32 @@ public class WxBusinessServiceImpl implements WxBusinessService { return resultList; } + + /** + * 1按面积 1日(price*day) 2月(price/31*day) 3年(price/365*day) + * 2联营 1年(price/365*day) 2月(price/31*day) 3周期 (price/period/31*day) + * 3取其高 与按面积 相同 + */ + public BigDecimal getPriceDecimal(int day, Long price, Integer priceUnit, Integer type, Integer period, Integer busDiscountTime) { + if (EnumRentContractType.RENT_BY_JOINT.getCode().equals(type)) { + if (EnumBusRatioTime.YEAR.getCode().equals(busDiscountTime)) { + return new BigDecimal(price).divide(new BigDecimal(365), 0, RoundingMode.HALF_UP).multiply(new BigDecimal(day)); + } + if (EnumBusRatioTime.MONTH.getCode().equals(busDiscountTime)) { + return new BigDecimal(price).divide(new BigDecimal(31), 0, RoundingMode.HALF_UP).multiply(new BigDecimal(day)); + } + return new BigDecimal(price).divide(new BigDecimal(31).multiply(new BigDecimal(period)), 0, RoundingMode.HALF_UP).multiply(new BigDecimal(day)); + } else { + if (EnumPriceUnit.D.getCode().equals(priceUnit)) { + return new BigDecimal(price).multiply(new BigDecimal(day)); + } + if (EnumPriceUnit.M.getCode().equals(priceUnit)) { + return new BigDecimal(price).divide(new BigDecimal(31), 0, RoundingMode.HALF_UP).multiply(new BigDecimal(day)); + } + return new BigDecimal(price).divide(new BigDecimal(365), 0, RoundingMode.HALF_UP).multiply(new BigDecimal(day)); + } + } + @Override public ResultData devoteList(WxBusiness wxBusiness, Integer pageNum, Integer pageSize) { wxBusiness.setLimitStart(0); @@ -173,5 +189,6 @@ public class WxBusinessServiceImpl implements WxBusinessService { PageHelper.clearPage(); return new ResultData(pageInfo); } - } + + diff --git a/mallinkService/src/main/resources/mapper/WxBusinessMapper.xml b/mallinkService/src/main/resources/mapper/WxBusinessMapper.xml index b2137e784..6319b59d7 100644 --- a/mallinkService/src/main/resources/mapper/WxBusinessMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxBusinessMapper.xml @@ -100,12 +100,8 @@ left join wx_shop ws on(mtd.shop_id = ws.id) where m.business_id = b.id and m.tenant_id=#{tenantId} and m.status = 1 and m.is_del = 0 ) /100,2) sale, - - (select if(sum(ws.operation_area) is null,0,sum(ws.operation_area)) - from wx_merchant m - left join wx_merchant_shop mtd on mtd.merchant_id = m.id - left join wx_shop ws on(mtd.shop_id = ws.id) - where m.business_id = b.id and m.tenant_id=#{tenantId} and m.status = 1 and m.is_del = 0 )area, + + (select ifnull(sum(rent_area),0) from wx_rent_contract where tenant_id=#{tenantId} and business_id=b.id and status in (2,3,4)) area, round( (select if(sum(mtd.trade_amt) is null,0,sum(mtd.trade_amt))