Explorar o código

优化巡检点为 cmd 模式

java110 %!s(int64=3) %!d(string=hai) anos
pai
achega
f2f0a63888

+ 0 - 52
service-api/src/main/java/com/java110/api/listener/inspectionPoint/DeleteInspectionPointListener.java

@@ -1,52 +0,0 @@
-package com.java110.api.listener.inspectionPoint;
-
-import com.alibaba.fastjson.JSONObject;
-import com.java110.api.bmo.inspection.IInspectionBMO;
-import com.java110.api.listener.AbstractServiceApiPlusListener;
-import com.java110.utils.util.Assert;
-import com.java110.core.context.DataFlowContext;
-import com.java110.core.event.service.api.ServiceDataFlowEvent;
-
-import com.java110.core.annotation.Java110Listener;
-import com.java110.utils.constant.ServiceCodeInspectionPointConstant;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.HttpMethod;
-
-/**
- * 删除巡检点侦听
- * add by zc 2020-02-10
- */
-@Java110Listener("deleteInspectionPointListener")
-public class DeleteInspectionPointListener extends AbstractServiceApiPlusListener {
-    @Autowired
-    private IInspectionBMO inspectionBMOImpl;
-
-    @Override
-    protected void validate(ServiceDataFlowEvent event, JSONObject reqJson) {
-        //Assert.hasKeyAndValue(reqJson, "xxx", "xxx");
-
-        Assert.hasKeyAndValue(reqJson, "inspectionId", "巡检点ID不能为空");
-
-    }
-
-    @Override
-    protected void doSoService(ServiceDataFlowEvent event, DataFlowContext context, JSONObject reqJson) {
-
-        inspectionBMOImpl.deleteInspectionPoint(reqJson, context);
-    }
-
-    @Override
-    public String getServiceCode() {
-        return ServiceCodeInspectionPointConstant.DELETE_INSPECTIONPOINT;
-    }
-
-    @Override
-    public HttpMethod getHttpMethod() {
-        return HttpMethod.POST;
-    }
-
-    @Override
-    public int getOrder() {
-        return DEFAULT_ORDER;
-    }
-}

+ 0 - 52
service-api/src/main/java/com/java110/api/listener/inspectionPoint/SaveInspectionPointListener.java

@@ -1,52 +0,0 @@
-package com.java110.api.listener.inspectionPoint;
-
-import com.alibaba.fastjson.JSONObject;
-import com.java110.api.bmo.inspection.IInspectionBMO;
-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.utils.constant.ServiceCodeInspectionPointConstant;
-import com.java110.utils.util.Assert;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.HttpMethod;
-
-/**
- * 保存巡检点
- * add by zc 2020-02-09
- */
-@Java110Listener("saveInspectionPointListener")
-public class SaveInspectionPointListener extends AbstractServiceApiPlusListener {
-    @Autowired
-    private IInspectionBMO inspectionBMOImpl;
-
-    @Override
-    protected void validate(ServiceDataFlowEvent event, JSONObject reqJson) {
-        Assert.hasKeyAndValue(reqJson, "inspectionName", "必填,请填写巡检点名称");
-        Assert.hasKeyAndValue(reqJson, "pointObjId", "必填,请填写位置信息");
-        Assert.hasKeyAndValue(reqJson, "pointObjType", "必填,请填写巡检类型");
-        Assert.hasKeyAndValue(reqJson, "pointObjName", "必填,请填写位置信息");
-    }
-
-    @Override
-    protected void doSoService(ServiceDataFlowEvent event, DataFlowContext context, JSONObject reqJson) {
-
-        inspectionBMOImpl.addInspectionPoint(reqJson, context);
-    }
-
-    @Override
-    public String getServiceCode() {
-        return ServiceCodeInspectionPointConstant.ADD_INSPECTIONPOINT;
-    }
-
-    @Override
-    public HttpMethod getHttpMethod() {
-        return HttpMethod.POST;
-    }
-
-    @Override
-    public int getOrder() {
-        return DEFAULT_ORDER;
-    }
-
-}

+ 0 - 53
service-api/src/main/java/com/java110/api/listener/inspectionPoint/UpdateInspectionPointListener.java

@@ -1,53 +0,0 @@
-package com.java110.api.listener.inspectionPoint;
-
-import com.alibaba.fastjson.JSONObject;
-import com.java110.api.bmo.inspection.IInspectionBMO;
-import com.java110.api.listener.AbstractServiceApiPlusListener;
-import com.java110.utils.util.Assert;
-import com.java110.core.annotation.Java110Listener;
-import com.java110.core.context.DataFlowContext;
-import com.java110.core.event.service.api.ServiceDataFlowEvent;
-import com.java110.utils.constant.ServiceCodeInspectionPointConstant;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.HttpMethod;
-
-/**
- * 修改巡检点侦听
- * add by ZC 2020-02-08
- */
-@Java110Listener("updateInspectionPointListener")
-public class UpdateInspectionPointListener extends AbstractServiceApiPlusListener {
-
-    @Autowired
-    private IInspectionBMO inspectionBMOImpl;
-
-    @Override
-    protected void validate(ServiceDataFlowEvent event, JSONObject reqJson) {
-        Assert.hasKeyAndValue(reqJson, "inspectionId", "巡检点ID不能为空");
-        Assert.hasKeyAndValue(reqJson, "inspectionName", "必填,请填写巡检点名称");
-        Assert.hasKeyAndValue(reqJson, "pointObjId", "必填,请填写位置信息");
-        Assert.hasKeyAndValue(reqJson, "pointObjType", "必填,请填写巡检类型");
-        Assert.hasKeyAndValue(reqJson, "pointObjName", "必填,请填写位置信息");
-    }
-
-    @Override
-    protected void doSoService(ServiceDataFlowEvent event, DataFlowContext context, JSONObject reqJson) {
-        inspectionBMOImpl.updateInspectionPoint(reqJson, context);
-    }
-
-    @Override
-    public String getServiceCode() {
-        return ServiceCodeInspectionPointConstant.UPDATE_INSPECTIONPOINT;
-    }
-
-    @Override
-    public HttpMethod getHttpMethod() {
-        return HttpMethod.POST;
-    }
-
-    @Override
-    public int getOrder() {
-        return DEFAULT_ORDER;
-    }
-
-}

+ 47 - 0
service-community/src/main/java/com/java110/community/cmd/inspectionPoint/DeleteInspectionPointCmd.java

@@ -0,0 +1,47 @@
+package com.java110.community.cmd.inspectionPoint;
+
+import com.alibaba.fastjson.JSONObject;
+import com.java110.core.annotation.Java110Cmd;
+import com.java110.core.context.ICmdDataFlowContext;
+import com.java110.core.event.cmd.Cmd;
+import com.java110.core.event.cmd.CmdEvent;
+import com.java110.dto.inspectionPlan.InspectionRoutePointRelDto;
+import com.java110.intf.community.IInspectionPointV1InnerServiceSMO;
+import com.java110.intf.community.IInspectionRoutePointRelInnerServiceSMO;
+import com.java110.po.inspection.InspectionPointPo;
+import com.java110.utils.exception.CmdException;
+import com.java110.utils.util.Assert;
+import com.java110.utils.util.BeanConvertUtil;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.util.List;
+
+@Java110Cmd(serviceCode = "inspectionPoint.deleteInspectionPoint")
+public class DeleteInspectionPointCmd extends Cmd {
+
+    @Autowired
+    private IInspectionRoutePointRelInnerServiceSMO inspectionRoutePointRelInnerServiceSMOImpl;
+
+    @Autowired
+    private IInspectionPointV1InnerServiceSMO inspectionPointV1InnerServiceSMOImpl;
+
+    @Override
+    public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException {
+        Assert.hasKeyAndValue(reqJson, "inspectionId", "巡检点ID不能为空");
+    }
+
+    @Override
+    public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException {
+        InspectionPointPo inspectionPointPo = BeanConvertUtil.covertBean(reqJson, InspectionPointPo.class);
+        InspectionRoutePointRelDto inspectionRoutePointRelDto = new InspectionRoutePointRelDto();
+        inspectionRoutePointRelDto.setInspectionId(inspectionPointPo.getInspectionId());
+        //查询巡检点巡检路线关系表
+        List<InspectionRoutePointRelDto> inspectionRoutePointRelDtos = inspectionRoutePointRelInnerServiceSMOImpl.queryInspectionRoutePointRels(inspectionRoutePointRelDto);
+        Assert.listIsNull(inspectionRoutePointRelDtos, "该巡检点正在使用,不能删除!");
+
+        int flag = inspectionPointV1InnerServiceSMOImpl.deleteInspectionPoint(inspectionPointPo);
+        if (flag < 1) {
+            throw new CmdException("删除巡检点失败");
+        }
+    }
+}

+ 12 - 41
service-api/src/main/java/com/java110/api/listener/inspectionPoint/ListInspectionPointsListener.java

@@ -1,10 +1,12 @@
-package com.java110.api.listener.inspectionPoint;
+package com.java110.community.cmd.inspectionPoint;
 
 import com.alibaba.fastjson.JSONObject;
 import com.aliyuncs.utils.StringUtils;
-import com.java110.api.listener.AbstractServiceApiListener;
-import com.java110.core.annotation.Java110Listener;
+import com.java110.core.annotation.Java110Cmd;
 import com.java110.core.context.DataFlowContext;
+import com.java110.core.context.ICmdDataFlowContext;
+import com.java110.core.event.cmd.Cmd;
+import com.java110.core.event.cmd.CmdEvent;
 import com.java110.core.event.service.api.ServiceDataFlowEvent;
 import com.java110.dto.RoomDto;
 import com.java110.dto.community.CommunityDto;
@@ -15,25 +17,20 @@ import com.java110.intf.community.IInspectionInnerServiceSMO;
 import com.java110.intf.community.IRoomInnerServiceSMO;
 import com.java110.intf.community.IUnitInnerServiceSMO;
 import com.java110.utils.cache.MappingCache;
-import com.java110.utils.constant.ServiceCodeInspectionPointConstant;
+import com.java110.utils.exception.CmdException;
 import com.java110.utils.util.Assert;
 import com.java110.utils.util.BeanConvertUtil;
 import com.java110.vo.api.inspectionPoint.ApiInspectionPointDataVo;
 import com.java110.vo.api.inspectionPoint.ApiInspectionPointVo;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.HttpMethod;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
 
 import java.util.ArrayList;
 import java.util.List;
 
-
-/**
- * 查询小区侦听类
- */
-@Java110Listener("listInspectionPointsListener")
-public class ListInspectionPointsListener extends AbstractServiceApiListener {
+@Java110Cmd(serviceCode = "inspectionPoint.listInspectionPoints")
+public class ListInspectionPointsCmd extends Cmd {
 
     @Autowired
     private IInspectionInnerServiceSMO inspectionPointInnerServiceSMOImpl;
@@ -48,39 +45,13 @@ public class ListInspectionPointsListener extends AbstractServiceApiListener {
     private IUnitInnerServiceSMO unitInnerServiceSMOImpl;
 
     @Override
-    public String getServiceCode() {
-        return ServiceCodeInspectionPointConstant.LIST_INSPECTIONPOINTS;
-    }
-
-    @Override
-    public HttpMethod getHttpMethod() {
-        return HttpMethod.GET;
-    }
-
-
-    @Override
-    public int getOrder() {
-        return DEFAULT_ORDER;
-    }
-
-
-    public IInspectionInnerServiceSMO getInspectionPointInnerServiceSMOImpl() {
-        return inspectionPointInnerServiceSMOImpl;
-    }
-
-    public void setInspectionPointInnerServiceSMOImpl(IInspectionInnerServiceSMO inspectionPointInnerServiceSMOImpl) {
-        this.inspectionPointInnerServiceSMOImpl = inspectionPointInnerServiceSMOImpl;
-    }
-
-    @Override
-    protected void validate(ServiceDataFlowEvent event, JSONObject reqJson) {
+    public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException {
         super.validatePageInfo(reqJson);
         Assert.hasKeyAndValue(reqJson, "communityId", "小区ID不能为空");
     }
 
     @Override
-    protected void doSoService(ServiceDataFlowEvent event, DataFlowContext context, JSONObject reqJson) {
-
+    public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException {
         if (reqJson.containsKey("relationship")) {
             queryRelationship(event, context, reqJson);
         } else {
@@ -96,7 +67,7 @@ public class ListInspectionPointsListener extends AbstractServiceApiListener {
      * @param context
      * @param reqJson
      */
-    private void queryRelationship(ServiceDataFlowEvent event, DataFlowContext context, JSONObject reqJson) {
+    private void queryRelationship(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) {
         InspectionDto inspectionPointDto = BeanConvertUtil.covertBean(reqJson, InspectionDto.class);
 
         int count = inspectionPointInnerServiceSMOImpl.queryInspectionsRelationShipCount(inspectionPointDto);
@@ -140,7 +111,7 @@ public class ListInspectionPointsListener extends AbstractServiceApiListener {
      * @param context
      * @param reqJson
      */
-    private void queryCommon(ServiceDataFlowEvent event, DataFlowContext context, JSONObject reqJson) {
+    private void queryCommon(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) {
         InspectionDto inspectionPointDto = BeanConvertUtil.covertBean(reqJson, InspectionDto.class);
 
         int count = inspectionPointInnerServiceSMOImpl.queryInspectionsCount(inspectionPointDto);

+ 39 - 0
service-community/src/main/java/com/java110/community/cmd/inspectionPoint/SaveInspectionPointCmd.java

@@ -0,0 +1,39 @@
+package com.java110.community.cmd.inspectionPoint;
+
+import com.alibaba.fastjson.JSONObject;
+import com.java110.core.annotation.Java110Cmd;
+import com.java110.core.context.ICmdDataFlowContext;
+import com.java110.core.event.cmd.Cmd;
+import com.java110.core.event.cmd.CmdEvent;
+import com.java110.core.factory.GenerateCodeFactory;
+import com.java110.intf.community.IInspectionPointV1InnerServiceSMO;
+import com.java110.po.inspection.InspectionPointPo;
+import com.java110.utils.exception.CmdException;
+import com.java110.utils.util.Assert;
+import com.java110.utils.util.BeanConvertUtil;
+import org.springframework.beans.factory.annotation.Autowired;
+
+@Java110Cmd(serviceCode = "inspectionPoint.saveInspectionPoint")
+public class SaveInspectionPointCmd extends Cmd {
+
+    @Autowired
+    private IInspectionPointV1InnerServiceSMO inspectionPointV1InnerServiceSMOImpl;
+
+    @Override
+    public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException {
+        Assert.hasKeyAndValue(reqJson, "inspectionName", "必填,请填写巡检点名称");
+        Assert.hasKeyAndValue(reqJson, "pointObjId", "必填,请填写位置信息");
+        Assert.hasKeyAndValue(reqJson, "pointObjType", "必填,请填写巡检类型");
+        Assert.hasKeyAndValue(reqJson, "pointObjName", "必填,请填写位置信息");
+    }
+
+    @Override
+    public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException {
+        reqJson.put("inspectionId", GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_inspectionId));
+        InspectionPointPo inspectionPointPo = BeanConvertUtil.covertBean(reqJson, InspectionPointPo.class);
+        int flag = inspectionPointV1InnerServiceSMOImpl.saveInspectionPoint(inspectionPointPo);
+        if(flag < 1){
+            throw new CmdException("保存巡检点失败");
+        }
+    }
+}

+ 38 - 0
service-community/src/main/java/com/java110/community/cmd/inspectionPoint/UpdateInspectionPointCmd.java

@@ -0,0 +1,38 @@
+package com.java110.community.cmd.inspectionPoint;
+
+import com.alibaba.fastjson.JSONObject;
+import com.java110.core.annotation.Java110Cmd;
+import com.java110.core.context.ICmdDataFlowContext;
+import com.java110.core.event.cmd.Cmd;
+import com.java110.core.event.cmd.CmdEvent;
+import com.java110.intf.community.IInspectionPointV1InnerServiceSMO;
+import com.java110.po.inspection.InspectionPointPo;
+import com.java110.utils.exception.CmdException;
+import com.java110.utils.util.Assert;
+import com.java110.utils.util.BeanConvertUtil;
+import org.springframework.beans.factory.annotation.Autowired;
+
+@Java110Cmd(serviceCode = "inspectionPoint.updateInspectionPoint")
+public class UpdateInspectionPointCmd extends Cmd {
+    @Autowired
+    private IInspectionPointV1InnerServiceSMO inspectionPointV1InnerServiceSMOImpl;
+
+    @Override
+    public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException {
+        Assert.hasKeyAndValue(reqJson, "inspectionId", "巡检点ID不能为空");
+        Assert.hasKeyAndValue(reqJson, "inspectionName", "必填,请填写巡检点名称");
+        Assert.hasKeyAndValue(reqJson, "pointObjId", "必填,请填写位置信息");
+        Assert.hasKeyAndValue(reqJson, "pointObjType", "必填,请填写巡检类型");
+        Assert.hasKeyAndValue(reqJson, "pointObjName", "必填,请填写位置信息");
+    }
+
+    @Override
+    public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException {
+
+        InspectionPointPo inspectionPointPo = BeanConvertUtil.covertBean(reqJson, InspectionPointPo.class);
+        int flag = inspectionPointV1InnerServiceSMOImpl.updateInspectionPoint(inspectionPointPo);
+        if (flag < 1) {
+            throw new CmdException("保存巡检点失败");
+        }
+    }
+}