oppadmin преди 4 години
родител
ревизия
a59ccad77b

+ 0 - 4
smart-city-platform/src/main/java/com/bz/smart_city/dao/DeviceMapper.java

@@ -22,9 +22,5 @@ public interface DeviceMapper {
 
     //同步水表信息
     int updateSync(@Param("devices") MeterSyncDto devices);
-
-    //更新水表档案号
-    int updateMeterCode(@Param("customerId") Integer customerId,@Param("oldMeterCode") String oldMeterCode,@Param("newMeterCode") String newMeterCode);
-
 }
 

+ 2 - 1
smart-city-platform/src/main/java/com/bz/smart_city/dao/pay/PayBaseAccountMapper.java

@@ -4,6 +4,7 @@ import com.bz.smart_city.dto.pay.*;
 import com.bz.smart_city.entity.ProgramItem;
 import com.bz.smart_city.entity.pay.PayBaseAccount;
 import com.bz.smart_city.entity.pay.PayMeter;
+import com.bz.smart_city.entity.pay.archives.PayBaseCustomerandmeterrela;
 import org.apache.ibatis.annotations.Delete;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
@@ -63,5 +64,5 @@ public interface PayBaseAccountMapper {
 
     int updateDeviceAddr(@Param("accountId")BigInteger accountId,@Param("siteId") Integer siteId, @Param("customerId") Integer customerId,@Param("address") String address);
 
-
+    List<PayBaseAccount> getCustIdAndSiteId();
 }

+ 26 - 29
smart-city-platform/src/main/java/com/bz/smart_city/service/impl/pay/DeviceSyncServiceImpl.java

@@ -11,6 +11,7 @@ import com.bz.smart_city.commom.util.UserUtil;
 import com.bz.smart_city.dao.CustomerMapper;
 import com.bz.smart_city.dao.DeviceMapper;
 import com.bz.smart_city.dao.pay.AmountWaterUsedAmountMapper;
+import com.bz.smart_city.dao.pay.PayBaseAccountMapper;
 import com.bz.smart_city.dto.LoginUser;
 import com.bz.smart_city.dto.MeterSyncDto;
 import com.bz.smart_city.dto.MeterSyncInputDto;
@@ -18,6 +19,7 @@ import com.bz.smart_city.dto.pay.PayBaseConfigDto;
 import com.bz.smart_city.entity.Customer;
 import com.bz.smart_city.entity.Device;
 import com.bz.smart_city.entity.SyncValveResult;
+import com.bz.smart_city.entity.pay.PayBaseAccount;
 import com.bz.smart_city.entity.pay.archives.PayBaseCustomerandmeterrela;
 import com.bz.smart_city.quartz.entity.QuartzEntity;
 import com.bz.smart_city.quartz.job.DeviceSyncJob;
@@ -48,6 +50,8 @@ public class DeviceSyncServiceImpl implements DeviceSyncService, InitializingBea
     private JobAndTriggerService jobAndTriggerService;
     @Autowired
     private PayBaseConfigService payBaseConfigService;
+    @Resource
+    PayBaseAccountMapper payBaseAccountMapper;
     @Value("${Sync.Data.Url}")
     String SyncUrl;
 
@@ -90,9 +94,9 @@ public class DeviceSyncServiceImpl implements DeviceSyncService, InitializingBea
 
     @Override
     public void start(){
-        List<PayBaseCustomerandmeterrela> payBaseCustomerandmeterrelas = amountWaterUsedAmountMapper.getCustIdAndSiteId();
-        for (PayBaseCustomerandmeterrela payBaseCustomerandmeterrela: payBaseCustomerandmeterrelas){
-            this.upMeters(payBaseCustomerandmeterrela.getSiteId().intValue(),payBaseCustomerandmeterrela.getCustomerId().intValue());
+        List<PayBaseAccount> payBaseAccounts = payBaseAccountMapper.getCustIdAndSiteId();
+        for (PayBaseAccount payBaseAccount: payBaseAccounts){
+            this.upMeters(payBaseAccount.getSiteId().intValue(),payBaseAccount.getCustomerId().intValue());
         }
     }
 
@@ -138,38 +142,31 @@ public class DeviceSyncServiceImpl implements DeviceSyncService, InitializingBea
                             if(meterSyncDtoList != null){
                                 for(MeterSyncDto meterSyncDto:meterSyncDtoList){
                                     //水表档案号变更
-                                    if(!meterSyncDto.getMeterCode().equals(meterSyncDto.getFileNo())){
-                                        //修改计费系统水表档案号
-                                        if(deviceMapper.updateMeterCode(null,meterSyncDto.getMeterCode(),meterSyncDto.getFileNo()) > 0){
-                                            try {
-                                                meterSyncDto.setMeterCode(meterSyncDto.getFileNo());
-                                                //更改营业系统水表档案号
-                                                String updateMeterNoUrl = SyncUrl + "/api/platform/updateMeterNo";
-                                                String params = String.format("?customerNo=%s&meterNo=%s&meterCode=%s",customerNo,meterSyncDto.getFileNo(),meterSyncDto.getMeterCode());
-                                                updateMeterNoUrl += params;
-                                                String postResult = HttpRequest.doPost(updateMeterNoUrl ,"");
-                                                SyncValveResult syncValveResult = JacksonUtil.string2Obj(postResult, SyncValveResult.class);
-                                                Integer getResult = Integer.parseInt(syncValveResult.getStatus());
-                                            }
-                                            catch (Exception e){
-                                                e.printStackTrace();
+                                    if(StringUtils.isNotBlank(meterSyncDto.getFileNo()) && !meterSyncDto.getMeterCode().equals(meterSyncDto.getFileNo())){
+                                        try {
+                                            //更改营业系统水表档案号
+                                            String updateMeterNoUrl = SyncUrl + "/api/platform/updateMeterNo";
+                                            String params = String.format("?customerNo=%s&meterNo=%s&meterCode=%s",customerNo,meterSyncDto.getFileNo(),meterSyncDto.getMeterCode());
+                                            updateMeterNoUrl += params;
+                                            String postResult = HttpRequest.doPost(updateMeterNoUrl ,"");
+                                            SyncValveResult syncValveResult = JacksonUtil.string2Obj(postResult, SyncValveResult.class);
+                                            Integer getResult = Integer.parseInt(syncValveResult.getStatus());
+                                            if(getResult == null || getResult != 0){
+                                                continue; //失败
                                             }
                                         }
-                                        else
-                                            continue;
+                                        catch (Exception e){
+                                            e.printStackTrace();
+                                        }
                                     }
 
-
-                                    String strList = JacksonUtil.obj2String(meterSyncDto);
-                                    MeterSyncDto resultMeterSyncDto = JacksonUtil.string2Obj(strList,MeterSyncDto.class);
-                                    resultMeterSyncDto.setCurrStatus(1);
-
-                                    if(StringUtils.isBlank(resultMeterSyncDto.getInitialData()))
-                                        resultMeterSyncDto.setInitialData("0");
-                                    deviceMapper.updateSync(resultMeterSyncDto);
+                                    meterSyncDto.setCurrStatus(1);
+                                    if(StringUtils.isBlank(meterSyncDto.getInitialData()))
+                                        meterSyncDto.setInitialData("0");
+                                    deviceMapper.updateSync(meterSyncDto);
                                 }
                             }
-                            
+
                         }
                     }
 

+ 3 - 9
smart-city-platform/src/main/resources/mapper/DeviceMapper.xml

@@ -91,16 +91,10 @@
             <if test="devices.dateUpdate != null and devices.dateUpdate != ''">date_update = #{devices.dateUpdate,jdbcType=VARCHAR},</if>
             <if test="devices.status != null">status = #{devices.status,jdbcType=INTEGER},</if>
             <if test="devices.currStatus != null">curr_status = #{devices.currStatus,jdbcType=INTEGER},</if>
-            <if test="devices.initialData != null">new_meter_start = #{devices.initialData,jdbcType=DECIMAL}</if>
+            <if test="devices.initialData != null">new_meter_start = #{devices.initialData,jdbcType=DECIMAL},</if>
+            <if test="devices.fileNo != null and devices.fileNo != ''"> metercode = #{devices.fileNo}</if>
         </set>
-        where metercode = #{devices.fileNo,jdbcType=VARCHAR}
-    </update>
-
-    <update id="updateMeterCode">
-        update sc_device
-        set metercode=#{newMeterCode}
-        where metercode = #{oldMeterCode}
-        <if test="customerId != null and customerId != ''"> and customer_id=#{customerId}</if>
+        where metercode = #{devices.meterCode}
     </update>
 
     <select id="getNoSyncList" resultType="com.bz.smart_city.entity.Device">

+ 10 - 0
smart-city-platform/src/main/resources/mapper/pay/PayBaseAccountMapper.xml

@@ -646,4 +646,14 @@
         where  account_id = #{accountId}
         <if test="customerId != null"> and customer_id = #{customerId}</if>
     </update>
+
+    <select id="getCustIdAndSiteId" resultType="com.bz.smart_city.entity.pay.PayBaseAccount">
+        select
+        c.customer_id customerId,
+        c.site_id siteId
+        from pay_base_account c
+        where
+        c.customer_id is not null  and c.site_id is not null
+        group by c.customer_id, c.site_id
+    </select>
 </mapper>