|
@@ -0,0 +1,147 @@
|
|
|
+package com.bz.smart_city.service.impl.pay;
|
|
|
+
|
|
|
+import com.bz.smart_city.commom.model.AjaxMessage;
|
|
|
+import com.bz.smart_city.commom.util.HttpRequest;
|
|
|
+import com.bz.smart_city.commom.util.JacksonUtil;
|
|
|
+import com.bz.smart_city.commom.util.UserUtil;
|
|
|
+import com.bz.smart_city.dao.DeviceMapper;
|
|
|
+import com.bz.smart_city.dao.pay.AmountWaterUsedAmountMapper;
|
|
|
+import com.bz.smart_city.dto.LoginUser;
|
|
|
+import com.bz.smart_city.dto.MeterSyncDto;
|
|
|
+import com.bz.smart_city.dto.MeterSyncInputDto;
|
|
|
+import com.bz.smart_city.dto.pay.PayBaseConfigDto;
|
|
|
+import com.bz.smart_city.entity.Device;
|
|
|
+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;
|
|
|
+import com.bz.smart_city.quartz.service.JobAndTriggerService;
|
|
|
+import com.bz.smart_city.service.pay.DeviceSyncService;
|
|
|
+import com.bz.smart_city.service.pay.PayBaseConfigService;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.InitializingBean;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by ZJY on 2020-09-28 10:22
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Component
|
|
|
+public class DeviceSyncServiceImpl implements DeviceSyncService, InitializingBean {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private JobAndTriggerService jobAndTriggerService;
|
|
|
+ @Autowired
|
|
|
+ private PayBaseConfigService payBaseConfigService;
|
|
|
+ @Value("${Sync.Data.Url}")
|
|
|
+ String SyncUrl;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private AmountWaterUsedAmountMapper amountWaterUsedAmountMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private DeviceMapper deviceMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void afterPropertiesSet() {
|
|
|
+ init();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void init(){
|
|
|
+ //1.构建定时任务,若任务不存在则创建
|
|
|
+ QuartzEntity entity = new QuartzEntity();
|
|
|
+ entity.setJobGroup("设备同步任务");
|
|
|
+ entity.setJobName("DeviceSyncJob");
|
|
|
+ entity.setDescription("同步水表安装信息");
|
|
|
+
|
|
|
+ boolean exists = jobAndTriggerService.isExists(entity);
|
|
|
+
|
|
|
+ if(exists){
|
|
|
+ exists = false;
|
|
|
+ jobAndTriggerService.deleteJob(entity);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!exists){
|
|
|
+
|
|
|
+ //每隔X分钟一次
|
|
|
+ String cron = "0 */1 * * * ?";
|
|
|
+ log.info("水表安装信息同步"+cron);
|
|
|
+ entity.setCronExpression(cron);
|
|
|
+ entity.setJobClassName(DeviceSyncJob.class.getName());
|
|
|
+ jobAndTriggerService.save(entity);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void start(){
|
|
|
+ List<PayBaseCustomerandmeterrela> payBaseCustomerandmeterrelas = amountWaterUsedAmountMapper.getCustIdAndSiteId();
|
|
|
+ for (PayBaseCustomerandmeterrela payBaseCustomerandmeterrela: payBaseCustomerandmeterrelas){
|
|
|
+ this.upMeters(payBaseCustomerandmeterrela.getSiteId().intValue(),payBaseCustomerandmeterrela.getCustomerId().intValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void upMeters(Integer siteId, Integer customerId){
|
|
|
+
|
|
|
+ log.info(String.format("水表安装信息同步siteId:%s,customerId:%s",siteId,customerId));
|
|
|
+ //取客户编号
|
|
|
+ String customerNo="";
|
|
|
+ List<PayBaseConfigDto> payBaseConfigDtos = payBaseConfigService.getPrintInfo("CUSTOMER_NO",siteId,customerId);
|
|
|
+ for (PayBaseConfigDto item : payBaseConfigDtos){
|
|
|
+ if(item.getName().trim()=="CUSTOMER_NO"){
|
|
|
+ customerNo = item.getValue();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(customerNo == "")
|
|
|
+ return;
|
|
|
+
|
|
|
+ //查询未同步的数据
|
|
|
+ String url = SyncUrl+"/api/syncData/meterSync";
|
|
|
+ List<Device> deviceList = deviceMapper.getNoSyncList();
|
|
|
+ if(deviceList != null && deviceList.size() >0){
|
|
|
+
|
|
|
+ List<List<Device>> lists = Lists.partition(deviceList,500);
|
|
|
+ for(List<Device> subDeviceList : lists){
|
|
|
+ MeterSyncInputDto meterSyncInputDto = new MeterSyncInputDto();
|
|
|
+ meterSyncInputDto.setCustomerNo(customerNo);
|
|
|
+ List<String> fileNos = new ArrayList<>();
|
|
|
+ for (Device device:subDeviceList){
|
|
|
+ fileNos.add(device.getMetercode());
|
|
|
+ }
|
|
|
+ meterSyncInputDto.setFileNo(fileNos);
|
|
|
+
|
|
|
+ //调用接口同步
|
|
|
+ String json = JacksonUtil.obj2String(meterSyncInputDto);
|
|
|
+ try {
|
|
|
+ String result = HttpRequest.doPost(url,json);
|
|
|
+ AjaxMessage<List<MeterSyncDto>> ajaxMessage = JacksonUtil.string2Obj(result,AjaxMessage.class);
|
|
|
+
|
|
|
+ if(ajaxMessage != null){
|
|
|
+ //更新水表信息
|
|
|
+ if(ajaxMessage.getStatus() == 0){
|
|
|
+
|
|
|
+ for(MeterSyncDto meterSyncDto:ajaxMessage.getData()){
|
|
|
+ meterSyncDto.setCurrStatus(1);
|
|
|
+ deviceMapper.updateSync(meterSyncDto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error(e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|