| @@ -0,0 +1,18 @@ | |||||
| package com.iformall.domain.vo; | |||||
| import com.iformall.enums.EnumRentContractStatus; | |||||
| import lombok.Data; | |||||
| import java.util.List; | |||||
| /** | |||||
| * 合同签约信息 | |||||
| * 商铺 -> 合同 : 1 -> 1 | |||||
| * 商铺 -> 合同 : n -> 1 | |||||
| */ | |||||
| @Data(staticConstructor = "of") | |||||
| public class RentEventInfo { | |||||
| private final Long rentId ; | |||||
| private final List<Long> targetIds ; | |||||
| private final EnumRentContractStatus type ; | |||||
| } | |||||
| @@ -70,6 +70,8 @@ public interface WxRentContractService { | |||||
| ResultData updateRentContractStatus(Long id); | ResultData updateRentContractStatus(Long id); | ||||
| List<Long> getShopIds(WxRentContract record) ; | |||||
| void updateApplyStatus(WxRentContract wxRentContract); | void updateApplyStatus(WxRentContract wxRentContract); | ||||
| List<WxBillRent> buildRent(WxMerchant wxMerchant, Long userId,WxRentContract rentContract,Integer isPreview,boolean saveDb); | List<WxBillRent> buildRent(WxMerchant wxMerchant, Long userId,WxRentContract rentContract,Integer isPreview,boolean saveDb); | ||||
| @@ -18,6 +18,7 @@ import com.iformall.mapper.*; | |||||
| import com.iformall.mq.MqBaseProducer; | import com.iformall.mq.MqBaseProducer; | ||||
| import com.iformall.service.*; | import com.iformall.service.*; | ||||
| import com.iformall.utils.Constant; | import com.iformall.utils.Constant; | ||||
| import com.iformall.utils.EventUtil; | |||||
| import com.iformall.utils.JsonUtil; | import com.iformall.utils.JsonUtil; | ||||
| import org.apache.commons.collections.CollectionUtils; | import org.apache.commons.collections.CollectionUtils; | ||||
| import org.apache.commons.collections.map.HashedMap; | import org.apache.commons.collections.map.HashedMap; | ||||
| @@ -21,6 +21,7 @@ import com.iformall.service.*; | |||||
| import com.iformall.utils.BeanMapping; | import com.iformall.utils.BeanMapping; | ||||
| import com.iformall.utils.DataUtil; | import com.iformall.utils.DataUtil; | ||||
| import com.iformall.utils.DateUtils; | import com.iformall.utils.DateUtils; | ||||
| import com.iformall.utils.EventUtil; | |||||
| import me.chanjar.weixin.common.util.DataUtils; | import me.chanjar.weixin.common.util.DataUtils; | ||||
| import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| @@ -390,6 +391,8 @@ public class WxMerchantServiceImpl implements WxMerchantService { | |||||
| wxRentContract.setStatus(EnumRentContractStatus.SIGNED_RENT_UNPAID.getCode()); | wxRentContract.setStatus(EnumRentContractStatus.SIGNED_RENT_UNPAID.getCode()); | ||||
| } | } | ||||
| wxRentContractMapper.updateById(wxRentContract); | wxRentContractMapper.updateById(wxRentContract); | ||||
| EventUtil.publistRentEvent(wxRentContractService,wxRentContract); | |||||
| //预览账单改为正式,并写入商户id(租赁合同需要绑定商户才变成已签约) | //预览账单改为正式,并写入商户id(租赁合同需要绑定商户才变成已签约) | ||||
| WxBillRent billRent = new WxBillRent(); | WxBillRent billRent = new WxBillRent(); | ||||
| billRent.setRentContractId(wxMerchant.getRentContractId()); | billRent.setRentContractId(wxMerchant.getRentContractId()); | ||||
| @@ -12,15 +12,15 @@ import com.iformall.common.ResultData; | |||||
| import com.iformall.domain.po.*; | import com.iformall.domain.po.*; | ||||
| import com.iformall.domain.vo.BillTimeVo; | import com.iformall.domain.vo.BillTimeVo; | ||||
| import com.iformall.domain.vo.RatioVo; | import com.iformall.domain.vo.RatioVo; | ||||
| import com.iformall.domain.vo.RentEventInfo; | |||||
| import com.iformall.enums.*; | import com.iformall.enums.*; | ||||
| import com.iformall.exception.MallinkException; | import com.iformall.exception.MallinkException; | ||||
| import com.iformall.mapper.*; | import com.iformall.mapper.*; | ||||
| import com.iformall.service.*; | import com.iformall.service.*; | ||||
| import com.iformall.utils.DateUtils; | |||||
| import com.iformall.utils.DownFileUtil; | |||||
| import com.iformall.utils.PriceUtil; | |||||
| import com.iformall.utils.WordUtil; | |||||
| import com.iformall.service.invest.event.InvestEvent; | |||||
| import com.iformall.utils.*; | |||||
| import org.apache.commons.collections.map.HashedMap; | import org.apache.commons.collections.map.HashedMap; | ||||
| import org.apache.commons.compress.utils.Lists; | |||||
| import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
| import org.apache.shiro.SecurityUtils; | import org.apache.shiro.SecurityUtils; | ||||
| import org.flowable.engine.RuntimeService; | import org.flowable.engine.RuntimeService; | ||||
| @@ -428,6 +428,7 @@ public class WxRentContractServiceImpl implements WxRentContractService { | |||||
| record.setCreatetime(date); | record.setCreatetime(date); | ||||
| record.setUpdatetime(date); | record.setUpdatetime(date); | ||||
| List<Long> shopList = Lists.newArrayList(); | |||||
| if (record.getRentShopType().equals(EnumRentShopType.SHOP.getCode())) { | if (record.getRentShopType().equals(EnumRentShopType.SHOP.getCode())) { | ||||
| String rentInfo = record.getRentInfo(); | String rentInfo = record.getRentInfo(); | ||||
| JSONArray rentInfoArray = JSONArray.parseArray(rentInfo); | JSONArray rentInfoArray = JSONArray.parseArray(rentInfo); | ||||
| @@ -466,6 +467,7 @@ public class WxRentContractServiceImpl implements WxRentContractService { | |||||
| return new ResultData(ErrorCode.SHOP_IS_RENT.getCode(), "店铺 " + wxShop.getShopNumber() + " 已出租"); | return new ResultData(ErrorCode.SHOP_IS_RENT.getCode(), "店铺 " + wxShop.getShopNumber() + " 已出租"); | ||||
| } | } | ||||
| } | } | ||||
| shopList.add(shopId); | |||||
| } | } | ||||
| } else { | } else { | ||||
| WxRentContract wxRentContract = new WxRentContract(); | WxRentContract wxRentContract = new WxRentContract(); | ||||
| @@ -478,6 +480,7 @@ public class WxRentContractServiceImpl implements WxRentContractService { | |||||
| if (count > 0) { | if (count > 0) { | ||||
| return new ResultData(ErrorCode.RENT_CONTRACT_WITH_SHOP_IS_FOUND); | return new ResultData(ErrorCode.RENT_CONTRACT_WITH_SHOP_IS_FOUND); | ||||
| } | } | ||||
| shopList.add(record.getShopId()); | |||||
| } | } | ||||
| try { | try { | ||||
| @@ -527,9 +530,35 @@ public class WxRentContractServiceImpl implements WxRentContractService { | |||||
| List<WxBillRent> resultList = buildRent(new WxMerchant(), null, record, EnumIsPreview.YES.getCode(),true); | List<WxBillRent> resultList = buildRent(new WxMerchant(), null, record, EnumIsPreview.YES.getCode(),true); | ||||
| record.setPreviewBillRentList(resultList); | record.setPreviewBillRentList(resultList); | ||||
| } | } | ||||
| EventUtil.publistRentEvent(this, record); | |||||
| return new ResultData(Result.SUCCESS, "保存租赁合同信息成功", record); | return new ResultData(Result.SUCCESS, "保存租赁合同信息成功", record); | ||||
| } | } | ||||
| @Override | |||||
| public List<Long> getShopIds(WxRentContract record) { | |||||
| List<Long> shopList = Lists.newArrayList(); | |||||
| if (record.getRentShopType().equals(EnumRentShopType.SHOP.getCode())) { | |||||
| String rentInfo = record.getRentInfo(); | |||||
| JSONArray rentInfoArray = JSONArray.parseArray(rentInfo); | |||||
| int size = rentInfoArray.size(); | |||||
| //查询rent_info 包括 shopId | |||||
| for (int i = 0; i < size; i++) { | |||||
| JSONObject rentInfoObject = rentInfoArray.getJSONObject(i); | |||||
| WxRentContract wxRentContract = new WxRentContract(); | |||||
| wxRentContract.setTenantId(record.getTenantId()); | |||||
| Long shopId = rentInfoObject.getLong("shopId"); | |||||
| shopList.add(shopId); | |||||
| } | |||||
| } else { | |||||
| WxRentContract wxRentContract = new WxRentContract(); | |||||
| wxRentContract.setTenantId(record.getTenantId()); | |||||
| wxRentContract.setShopId(record.getShopId()); | |||||
| shopList.add(record.getShopId()); | |||||
| } | |||||
| return shopList; | |||||
| } | |||||
| @Transactional(rollbackFor = {Exception.class}) | @Transactional(rollbackFor = {Exception.class}) | ||||
| @Override | @Override | ||||
| public ResultData update(WxRentContract record, Long userId,String userName,int from,Date oldRentStartDate) { | public ResultData update(WxRentContract record, Long userId,String userName,int from,Date oldRentStartDate) { | ||||
| @@ -1685,6 +1714,7 @@ public class WxRentContractServiceImpl implements WxRentContractService { | |||||
| wxRentContract.setStatus(EnumRentContractStatus.SIGNED_RENT_UNPAID.getCode()); | wxRentContract.setStatus(EnumRentContractStatus.SIGNED_RENT_UNPAID.getCode()); | ||||
| } | } | ||||
| wxRentContractMapper.updateById(wxRentContract); | wxRentContractMapper.updateById(wxRentContract); | ||||
| EventUtil.publistRentEvent(this, wxRentContract); | |||||
| //建立账单 | //建立账单 | ||||
| if (record != null && | if (record != null && | ||||
| record.getMerchantId() != null && | record.getMerchantId() != null && | ||||
| @@ -0,0 +1,14 @@ | |||||
| package com.iformall.service.invest.event; | |||||
| import org.springframework.context.ApplicationEvent; | |||||
| public class InvestEvent extends ApplicationEvent { | |||||
| /** | |||||
| * Create a new ApplicationEvent. | |||||
| * | |||||
| * @param source the object on which the event initially occurred (never {@code null}) | |||||
| */ | |||||
| public InvestEvent(Object source) { | |||||
| super(source); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,56 @@ | |||||
| package com.iformall.service.invest.event; | |||||
| import com.alibaba.fastjson.JSON; | |||||
| import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |||||
| import com.iformall.domain.po.InvestTaskEntity; | |||||
| import com.iformall.domain.vo.RentEventInfo; | |||||
| import com.iformall.enums.EnumInvestType; | |||||
| import com.iformall.enums.EnumRentContractStatus; | |||||
| import com.iformall.enums.EnumTaskStatus; | |||||
| import com.iformall.service.invest.InvestTaskService; | |||||
| import lombok.extern.slf4j.Slf4j; | |||||
| import org.apache.commons.collections.CollectionUtils; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.context.ApplicationListener; | |||||
| import org.springframework.stereotype.Component; | |||||
| import java.util.List; | |||||
| import java.util.Objects; | |||||
| @Slf4j | |||||
| @Component | |||||
| public class InvestListener implements ApplicationListener<InvestEvent> { | |||||
| @Autowired | |||||
| private InvestTaskService taskService; | |||||
| @Override | |||||
| public void onApplicationEvent(InvestEvent event) { | |||||
| RentEventInfo rentEventInfo = (RentEventInfo) event.getSource(); | |||||
| log.debug("receive InvestEvent , info : {}", JSON.toJSONString(rentEventInfo)); | |||||
| LambdaQueryWrapper<InvestTaskEntity> query = new LambdaQueryWrapper<>(); | |||||
| query.in(InvestTaskEntity::getTargetId, rentEventInfo.getTargetIds()); | |||||
| query.eq(InvestTaskEntity::getTargetType, EnumInvestType.SHOP); | |||||
| List<InvestTaskEntity> tasks = taskService.list(query); | |||||
| if (CollectionUtils.isEmpty(tasks)) { | |||||
| log.warn("receive InvestEvent , tasks is empty : {}", tasks); | |||||
| return; | |||||
| } | |||||
| EnumTaskStatus status = EnumTaskStatus.CREATED; | |||||
| EnumRentContractStatus rentContractStatus = rentEventInfo.getType(); | |||||
| if (Objects.equals(EnumRentContractStatus.INTENTION, rentContractStatus)) { | |||||
| status = EnumTaskStatus.INTENTION; | |||||
| } else if (Objects.equals(EnumRentContractStatus.SIGNED_RENT_UNPAID, rentContractStatus)) { | |||||
| status = EnumTaskStatus.FINISH; | |||||
| } else if (Objects.equals(EnumRentContractStatus.RENT_PAID, rentContractStatus)) { | |||||
| status = EnumTaskStatus.FINISH; | |||||
| } | |||||
| for (InvestTaskEntity task : tasks) { | |||||
| task.setStatus(status); | |||||
| } | |||||
| taskService.updateBatchById(tasks); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,24 @@ | |||||
| package com.iformall.utils; | |||||
| import com.iformall.domain.po.WxRentContract; | |||||
| import com.iformall.domain.vo.RentEventInfo; | |||||
| import com.iformall.enums.EnumRentContractStatus; | |||||
| import com.iformall.service.WxRentContractService; | |||||
| import com.iformall.service.invest.event.InvestEvent; | |||||
| import lombok.extern.slf4j.Slf4j; | |||||
| @Slf4j | |||||
| public class EventUtil { | |||||
| public static void publistRentEvent(WxRentContractService rentContractService, WxRentContract rentContract) { | |||||
| try { | |||||
| RentEventInfo rentEventInfo = RentEventInfo | |||||
| .of(rentContract.getId(), rentContractService.getShopIds(rentContract), EnumRentContractStatus.getEnum(rentContract.getStatus())); | |||||
| InvestEvent event = new InvestEvent(rentEventInfo); | |||||
| SpringContextUtils.pulish(event); | |||||
| } catch (Exception e) { | |||||
| log.error("publistRentEvent error", e); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -3,6 +3,7 @@ package com.iformall.utils; | |||||
| import org.springframework.beans.BeansException; | import org.springframework.beans.BeansException; | ||||
| import org.springframework.context.ApplicationContext; | import org.springframework.context.ApplicationContext; | ||||
| import org.springframework.context.ApplicationContextAware; | import org.springframework.context.ApplicationContextAware; | ||||
| import org.springframework.context.ApplicationEvent; | |||||
| import org.springframework.stereotype.Component; | import org.springframework.stereotype.Component; | ||||
| /** | /** | ||||
| @@ -46,4 +47,8 @@ public class SpringContextUtils implements ApplicationContextAware { | |||||
| return applicationContext.getBean(clazz); | return applicationContext.getBean(clazz); | ||||
| } | } | ||||
| public static void pulish(ApplicationEvent event) { | |||||
| applicationContext.publishEvent(event); | |||||
| } | |||||
| } | } | ||||