package com.java110.api.listener.meterWater;

import com.alibaba.fastjson.JSONObject;
import com.java110.api.bmo.meterWater.IMeterWaterBMO;
import com.java110.api.listener.AbstractServiceApiPlusListener;
import com.java110.core.annotation.Java110Listener;
import com.java110.core.context.DataFlowContext;
import com.java110.core.event.service.api.ServiceDataFlowEvent;
import com.java110.dto.meterWater.MeterWaterDto;
import com.java110.intf.fee.IMeterWaterInnerServiceSMO;
import com.java110.po.fee.PayFeePo;
import com.java110.utils.constant.BusinessTypeConstant;
import com.java110.utils.constant.ServiceCodeMeterWaterConstant;
import com.java110.utils.util.Assert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpMethod;

import java.util.List;


/**
 * 保存小区侦听
 * add by wuxw 2019-06-30
 */
@Java110Listener("deleteMeterWaterListener")
public class DeleteMeterWaterListener extends AbstractServiceApiPlusListener {

    @Autowired
    private IMeterWaterBMO meterWaterBMOImpl;

    @Autowired
    private IMeterWaterInnerServiceSMO meterWaterInnerServiceSMOImpl;

    @Override
    protected void validate(ServiceDataFlowEvent event, JSONObject reqJson) {
        //Assert.hasKeyAndValue(reqJson, "xxx", "xxx");

        Assert.hasKeyAndValue(reqJson, "waterId", "waterId不能为空");

    }

    @Override
    protected void doSoService(ServiceDataFlowEvent event, DataFlowContext context, JSONObject reqJson) {
        MeterWaterDto meterWaterDto = new MeterWaterDto();
        meterWaterDto.setWaterId(reqJson.getString("waterId"));
        meterWaterDto.setCommunityId(reqJson.getString("communityId"));
        List<MeterWaterDto> meterWaterDtos = meterWaterInnerServiceSMOImpl.queryMeterWaters(meterWaterDto);

        Assert.listOnlyOne(meterWaterDtos, "数据异常未找到费用信息");

        PayFeePo payFeePo = new PayFeePo();
        payFeePo.setFeeId(meterWaterDtos.get(0).getFeeId());
        payFeePo.setCommunityId(meterWaterDtos.get(0).getCommunityId());
        super.delete(context, payFeePo, BusinessTypeConstant.BUSINESS_TYPE_DELETE_FEE_INFO);
        meterWaterBMOImpl.deleteMeterWater(reqJson, context);
    }

    @Override
    public String getServiceCode() {
        return ServiceCodeMeterWaterConstant.DELETE_METERWATER;
    }

    @Override
    public HttpMethod getHttpMethod() {
        return HttpMethod.POST;
    }

}

@@ -389,32 +389,116 @@
 dto.
-meterWater.MeterWaterDto
+fee.FeeDto;%0Aimport com.java110.dto.meterWater.MeterWaterDto;%0Aimport com.java110.intf.fee.IFeeInnerServiceSMO
 ;%0Aim
@@ -1192,24 +1192,96 @@
 ceSMOImpl;%0A%0A
+    @Autowired%0A    private IFeeInnerServiceSMO feeInnerServiceSMOImpl;%0A%0A
     @Overrid
@@ -1971,24 +1971,344 @@
 %E6%9C%AA%E6%89%BE%E5%88%B0%E8%B4%B9%E7%94%A8%E4%BF%A1%E6%81%AF%22);%0A%0A
+        //%E5%88%A4%E6%96%AD%E8%B4%B9%E7%94%A8%E6%98%AF%E5%90%A6%E5%B7%B2%E7%BB%8F%E8%A2%AB%E5%88%A0%E9%99%A4%0A        FeeDto feeDto = new FeeDto();%0A        feeDto.setFeeId(meterWaterDtos.get(0).getFeeId());%0A        feeDto.setCommunityId(meterWaterDtos.get(0).getCommunityId());%0A        List%3CFeeDto%3E feeDtos = feeInnerServiceSMOImpl.queryFees(feeDto);%0A        if (feeDtos != null && feeDtos.size() %3E 0) %7B%0A    
         PayF
@@ -2339,32 +2339,36 @@
 eePo();%0A        
+ 
+   
 payFeePo.setFeeI
@@ -2396,32 +2396,36 @@
 0).getFeeId());%0A
+    
         payFeePo
@@ -2473,32 +2473,36 @@
 CommunityId());%0A
+    
         super.de
@@ -2578,16 +2578,26 @@
 _INFO);%0A
+        %7D%0A
         

优化 先删除费用 再删除抄表记录时的bug