Bladeren bron

优化代码

java110 4 jaren geleden
bovenliggende
commit
3c4a0a1edc

+ 138 - 140
java110-db/src/main/resources/mapper/community/CommunityV1ServiceDaoImplMapper.xml

@@ -5,165 +5,163 @@
 <mapper namespace="communityV1ServiceDaoImpl">
 
 
-
-
-
     <!-- 保存小区管理信息 add by wuxw 2018-07-03 -->
     <insert id="saveCommunityInfo" parameterType="Map">
         insert into s_community(
-fee_price,address,city_code,map_y,pay_fee_month,map_x,nearby_landmarks,name,tel,state,community_id,community_area
-) values (
-#{feePrice},#{address},#{cityCode},#{mapY},#{payFeeMonth},#{mapX},#{nearbyLandmarks},#{name},#{tel},#{state},#{communityId},#{communityArea}
-)
+        fee_price,address,city_code,map_y,pay_fee_month,map_x,nearby_landmarks,name,tel,state,community_id,community_area
+        ) values (
+        #{feePrice},#{address},#{cityCode},#{mapY},#{payFeeMonth},#{mapX},#{nearbyLandmarks},#{name},#{tel},#{state},#{communityId},#{communityArea}
+        )
     </insert>
 
 
-
     <!-- 查询小区管理信息 add by wuxw 2018-07-03 -->
     <select id="getCommunityInfo" parameterType="Map" resultType="Map">
-        select  t.fee_price,t.fee_price feePrice,t.address,t.city_code,t.city_code cityCode,t.status_cd,t.status_cd statusCd,t.map_y,t.map_y mapY,t.pay_fee_month,t.pay_fee_month payFeeMonth,t.map_x,t.map_x mapX,t.nearby_landmarks,t.nearby_landmarks nearbyLandmarks,t.name,t.tel,t.state,t.community_id,t.community_id communityId,t.community_area,t.community_area communityArea 
-from s_community t 
-where 1 =1 
-<if test="feePrice !=null and feePrice != ''">
-   and t.fee_price= #{feePrice}
-</if> 
-<if test="address !=null and address != ''">
-   and t.address= #{address}
-</if> 
-<if test="cityCode !=null and cityCode != ''">
-   and t.city_code= #{cityCode}
-</if> 
-<if test="statusCd !=null and statusCd != ''">
-   and t.status_cd= #{statusCd}
-</if> 
-<if test="mapY !=null and mapY != ''">
-   and t.map_y= #{mapY}
-</if> 
-<if test="payFeeMonth !=null and payFeeMonth != ''">
-   and t.pay_fee_month= #{payFeeMonth}
-</if> 
-<if test="mapX !=null and mapX != ''">
-   and t.map_x= #{mapX}
-</if> 
-<if test="nearbyLandmarks !=null and nearbyLandmarks != ''">
-   and t.nearby_landmarks= #{nearbyLandmarks}
-</if> 
-<if test="name !=null and name != ''">
-   and t.name= #{name}
-</if> 
-<if test="tel !=null and tel != ''">
-   and t.tel= #{tel}
-</if> 
-<if test="state !=null and state != ''">
-   and t.state= #{state}
-</if> 
-<if test="communityId !=null and communityId != ''">
-   and t.community_id= #{communityId}
-</if> 
-<if test="communityArea !=null and communityArea != ''">
-   and t.community_area= #{communityArea}
-</if> 
-order by t.create_time desc
-<if test="page != -1 and page != null ">
-   limit #{page}, #{row}
-</if> 
+        select t.fee_price,t.fee_price feePrice,t.address,t.city_code,t.city_code cityCode,t.status_cd,t.status_cd
+        statusCd,t.map_y,t.map_y mapY,t.pay_fee_month,t.pay_fee_month payFeeMonth,t.map_x,t.map_x
+        mapX,t.nearby_landmarks,t.nearby_landmarks nearbyLandmarks,t.name,t.tel,t.state,t.community_id,t.community_id
+        communityId,t.community_area,t.community_area communityArea
+        from s_community t
+        where 1 =1
+        <if test="feePrice !=null and feePrice != ''">
+            and t.fee_price= #{feePrice}
+        </if>
+        <if test="address !=null and address != ''">
+            and t.address= #{address}
+        </if>
+        <if test="cityCode !=null and cityCode != ''">
+            and t.city_code= #{cityCode}
+        </if>
+        <if test="statusCd !=null and statusCd != ''">
+            and t.status_cd= #{statusCd}
+        </if>
+        <if test="mapY !=null and mapY != ''">
+            and t.map_y= #{mapY}
+        </if>
+        <if test="payFeeMonth !=null and payFeeMonth != ''">
+            and t.pay_fee_month= #{payFeeMonth}
+        </if>
+        <if test="mapX !=null and mapX != ''">
+            and t.map_x= #{mapX}
+        </if>
+        <if test="nearbyLandmarks !=null and nearbyLandmarks != ''">
+            and t.nearby_landmarks= #{nearbyLandmarks}
+        </if>
+        <if test="name !=null and name != ''">
+            and t.name= #{name}
+        </if>
+        <if test="tel !=null and tel != ''">
+            and t.tel= #{tel}
+        </if>
+        <if test="state !=null and state != ''">
+            and t.state= #{state}
+        </if>
+        <if test="communityId !=null and communityId != ''">
+            and t.community_id= #{communityId}
+        </if>
+        <if test="communityArea !=null and communityArea != ''">
+            and t.community_area= #{communityArea}
+        </if>
+        order by t.create_time desc
+        <if test="page != -1 and page != null ">
+            limit #{page}, #{row}
+        </if>
 
     </select>
 
 
-
-
     <!-- 修改小区管理信息 add by wuxw 2018-07-03 -->
     <update id="updateCommunityInfo" parameterType="Map">
-        update  s_community t set t.status_cd = #{statusCd}
-<if test="newBId != null and newBId != ''">
-,t.b_id = #{newBId}
-</if> 
-<if test="feePrice !=null and feePrice != ''">
-, t.fee_price= #{feePrice}
-</if> 
-<if test="address !=null and address != ''">
-, t.address= #{address}
-</if> 
-<if test="cityCode !=null and cityCode != ''">
-, t.city_code= #{cityCode}
-</if> 
-<if test="mapY !=null and mapY != ''">
-, t.map_y= #{mapY}
-</if> 
-<if test="payFeeMonth !=null and payFeeMonth != ''">
-, t.pay_fee_month= #{payFeeMonth}
-</if> 
-<if test="mapX !=null and mapX != ''">
-, t.map_x= #{mapX}
-</if> 
-<if test="nearbyLandmarks !=null and nearbyLandmarks != ''">
-, t.nearby_landmarks= #{nearbyLandmarks}
-</if> 
-<if test="name !=null and name != ''">
-, t.name= #{name}
-</if> 
-<if test="tel !=null and tel != ''">
-, t.tel= #{tel}
-</if> 
-<if test="state !=null and state != ''">
-, t.state= #{state}
-</if> 
-<if test="communityArea !=null and communityArea != ''">
-, t.community_area= #{communityArea}
-</if> 
- where 1=1 <if test="communityId !=null and communityId != ''">
-and t.community_id= #{communityId}
-</if> 
+        update s_community t set t.status_cd = #{statusCd}
+        <if test="newBId != null and newBId != ''">
+            ,t.b_id = #{newBId}
+        </if>
+        <if test="feePrice !=null and feePrice != ''">
+            , t.fee_price= #{feePrice}
+        </if>
+        <if test="address !=null and address != ''">
+            , t.address= #{address}
+        </if>
+        <if test="cityCode !=null and cityCode != ''">
+            , t.city_code= #{cityCode}
+        </if>
+        <if test="mapY !=null and mapY != ''">
+            , t.map_y= #{mapY}
+        </if>
+        <if test="payFeeMonth !=null and payFeeMonth != ''">
+            , t.pay_fee_month= #{payFeeMonth}
+        </if>
+        <if test="mapX !=null and mapX != ''">
+            , t.map_x= #{mapX}
+        </if>
+        <if test="nearbyLandmarks !=null and nearbyLandmarks != ''">
+            , t.nearby_landmarks= #{nearbyLandmarks}
+        </if>
+        <if test="name !=null and name != ''">
+            , t.name= #{name}
+        </if>
+        <if test="tel !=null and tel != ''">
+            , t.tel= #{tel}
+        </if>
+        <if test="state !=null and state != ''">
+            , t.state= #{state}
+        </if>
+        <if test="communityArea !=null and communityArea != ''">
+            , t.community_area= #{communityArea}
+        </if>
+        where 1=1
+        <if test="communityId !=null and communityId != ''">
+            and t.community_id= #{communityId}
+        </if>
 
     </update>
 
     <!-- 查询小区管理数量 add by wuxw 2018-07-03 -->
-     <select id="queryCommunitysCount" parameterType="Map" resultType="Map">
-        select  count(1) count 
-from s_community t 
-where 1 =1 
-<if test="feePrice !=null and feePrice != ''">
-   and t.fee_price= #{feePrice}
-</if> 
-<if test="address !=null and address != ''">
-   and t.address= #{address}
-</if> 
-<if test="cityCode !=null and cityCode != ''">
-   and t.city_code= #{cityCode}
-</if> 
-<if test="statusCd !=null and statusCd != ''">
-   and t.status_cd= #{statusCd}
-</if> 
-<if test="mapY !=null and mapY != ''">
-   and t.map_y= #{mapY}
-</if> 
-<if test="payFeeMonth !=null and payFeeMonth != ''">
-   and t.pay_fee_month= #{payFeeMonth}
-</if> 
-<if test="mapX !=null and mapX != ''">
-   and t.map_x= #{mapX}
-</if> 
-<if test="nearbyLandmarks !=null and nearbyLandmarks != ''">
-   and t.nearby_landmarks= #{nearbyLandmarks}
-</if> 
-<if test="name !=null and name != ''">
-   and t.name= #{name}
-</if> 
-<if test="tel !=null and tel != ''">
-   and t.tel= #{tel}
-</if> 
-<if test="state !=null and state != ''">
-   and t.state= #{state}
-</if> 
-<if test="communityId !=null and communityId != ''">
-   and t.community_id= #{communityId}
-</if> 
-<if test="communityArea !=null and communityArea != ''">
-   and t.community_area= #{communityArea}
-</if> 
+    <select id="queryCommunitysCount" parameterType="Map" resultType="Map">
+        select count(1) count
+        from s_community t
+        where 1 =1
+        <if test="feePrice !=null and feePrice != ''">
+            and t.fee_price= #{feePrice}
+        </if>
+        <if test="address !=null and address != ''">
+            and t.address= #{address}
+        </if>
+        <if test="cityCode !=null and cityCode != ''">
+            and t.city_code= #{cityCode}
+        </if>
+        <if test="statusCd !=null and statusCd != ''">
+            and t.status_cd= #{statusCd}
+        </if>
+        <if test="mapY !=null and mapY != ''">
+            and t.map_y= #{mapY}
+        </if>
+        <if test="payFeeMonth !=null and payFeeMonth != ''">
+            and t.pay_fee_month= #{payFeeMonth}
+        </if>
+        <if test="mapX !=null and mapX != ''">
+            and t.map_x= #{mapX}
+        </if>
+        <if test="nearbyLandmarks !=null and nearbyLandmarks != ''">
+            and t.nearby_landmarks= #{nearbyLandmarks}
+        </if>
+        <if test="name !=null and name != ''">
+            and t.name= #{name}
+        </if>
+        <if test="tel !=null and tel != ''">
+            and t.tel= #{tel}
+        </if>
+        <if test="state !=null and state != ''">
+            and t.state= #{state}
+        </if>
+        <if test="communityId !=null and communityId != ''">
+            and t.community_id= #{communityId}
+        </if>
+        <if test="communityArea !=null and communityArea != ''">
+            and t.community_area= #{communityArea}
+        </if>
 
 
-     </select>
+    </select>
 
 </mapper>

+ 2 - 6
java110-service/src/main/java/com/java110/service/smo/impl/CmdServiceSMOImpl.java

@@ -19,10 +19,10 @@ import com.java110.utils.exception.SMOException;
 import com.java110.utils.kafka.KafkaFactory;
 import com.java110.utils.log.LoggerEngine;
 import com.java110.utils.util.DateUtil;
+import com.java110.vo.ResultVo;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Service;
 
@@ -67,9 +67,6 @@ public class CmdServiceSMOImpl extends LoggerEngine implements ICmdServiceSMO {
 
         ResponseEntity<String> responseEntity = null;
 
-        String resJson = "";
-
-
         //1.0 创建数据流 appId serviceCode
         cmdDataFlowContext = DataFlowFactory.newInstance(CmdDataFlow.class).builder(reqJson, headers);
 
@@ -82,8 +79,7 @@ public class CmdServiceSMOImpl extends LoggerEngine implements ICmdServiceSMO {
         Date endDate = DateUtil.getCurrentDate();
 
         if (responseEntity == null) {
-            //resJson = encrypt(responseJson.toJSONString(),headers);
-            responseEntity = new ResponseEntity<String>(resJson, HttpStatus.OK);
+            responseEntity = ResultVo.success();
         }
         return responseEntity;
     }

+ 2 - 0
service-community/src/main/java/com/java110/community/cmd/community/SaveCommunityCmd.java

@@ -31,6 +31,7 @@ import com.java110.po.workflow.WorkflowPo;
 import com.java110.utils.constant.BusinessTypeConstant;
 import com.java110.utils.exception.CmdException;
 import com.java110.utils.util.Assert;
+import com.java110.vo.ResultVo;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -122,6 +123,7 @@ public class SaveCommunityCmd extends AbstractServiceCmdListener {
         if (flag < 1) {
             throw new IllegalArgumentException("添加流程失败");
         }
+        cmdDataFlowContext.setResponseEntity(ResultVo.success());
     }
 
 

+ 36 - 7
service-community/src/main/java/com/java110/community/cmd/community/UpdateCommunityCmd.java

@@ -15,17 +15,18 @@
  */
 package com.java110.community.cmd.community;
 
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.java110.community.bmo.community.ICommunityBMO;
 import com.java110.core.annotation.Java110Cmd;
 import com.java110.core.annotation.Java110Transactional;
 import com.java110.core.context.ICmdDataFlowContext;
 import com.java110.core.event.cmd.AbstractServiceCmdListener;
 import com.java110.core.event.cmd.CmdEvent;
 import com.java110.intf.community.ICommunityV1InnerServiceSMO;
-import com.java110.po.community.CommunityPo;
 import com.java110.utils.exception.CmdException;
 import com.java110.utils.util.Assert;
-import com.java110.utils.util.BeanConvertUtil;
+import com.java110.utils.util.StringUtil;
 import com.java110.vo.ResultVo;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -51,9 +52,20 @@ public class UpdateCommunityCmd extends AbstractServiceCmdListener {
     @Autowired
     private ICommunityV1InnerServiceSMO communityV1InnerServiceSMOImpl;
 
+
+    @Autowired
+    private ICommunityBMO communityBMOImpl;
+
+
     @Override
     public void validate(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) {
-        Assert.hasKeyAndValue(reqJson, "communityId", "communityId不能为空");
+
+        Assert.hasKeyAndValue(reqJson, "communityId", "小区ID不能为空");
+        Assert.hasKeyAndValue(reqJson, "name", "必填,请填写小区名称");
+        Assert.hasKeyAndValue(reqJson, "address", "必填,请填写小区地址");
+        Assert.hasKeyAndValue(reqJson, "nearbyLandmarks", "必填,请填写小区附近地标");
+
+        Assert.judgeAttrValue(reqJson);
 
     }
 
@@ -61,11 +73,28 @@ public class UpdateCommunityCmd extends AbstractServiceCmdListener {
     @Java110Transactional
     public void doCmd(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {
 
-        CommunityPo communityPo = BeanConvertUtil.covertBean(reqJson, CommunityPo.class);
-        int flag = communityV1InnerServiceSMOImpl.updateCommunity(communityPo);
 
-        if (flag < 1) {
-            throw new CmdException("更新数据失败");
+        communityBMOImpl.updateCommunityOne(reqJson, cmdDataFlowContext);
+
+        if (!reqJson.containsKey("attrs")) {
+            return;
+        }
+
+        JSONArray attrs = reqJson.getJSONArray("attrs");
+        if (attrs.size() < 1) {
+            return;
+        }
+
+
+        JSONObject attr = null;
+        for (int attrIndex = 0; attrIndex < attrs.size(); attrIndex++) {
+            attr = attrs.getJSONObject(attrIndex);
+            attr.put("communityId", reqJson.getString("communityId"));
+            if (!attr.containsKey("attrId") || attr.getString("attrId").startsWith("-") || StringUtil.isEmpty(attr.getString("attrId"))) {
+                communityBMOImpl.addAttr(attr, cmdDataFlowContext);
+                continue;
+            }
+            communityBMOImpl.updateAttr(attr, cmdDataFlowContext);
         }
 
         cmdDataFlowContext.setResponseEntity(ResultVo.success());