|
@@ -0,0 +1,142 @@
|
|
|
+package com.bz.smart_city.quartz.service.impl;
|
|
|
+
|
|
|
+import com.bz.smart_city.commom.util.HttpRequest;
|
|
|
+import com.bz.smart_city.commom.util.JacksonUtil;
|
|
|
+import com.bz.smart_city.dao.CustomerMapper;
|
|
|
+import com.bz.smart_city.dao.pay.AmountWaterUsedAmountMapper;
|
|
|
+import com.bz.smart_city.dao.pay.PayControlRecordMapper;
|
|
|
+import com.bz.smart_city.dao.pay.archives.PayBaseCustomerandmeterrelaMapper;
|
|
|
+import com.bz.smart_city.entity.Customer;
|
|
|
+import com.bz.smart_city.entity.SyncValveResult;
|
|
|
+import com.bz.smart_city.entity.SyncValveSend;
|
|
|
+import com.bz.smart_city.entity.pay.PayControlRecord;
|
|
|
+import com.bz.smart_city.entity.pay.archives.PayBaseCustomerandmeterrela;
|
|
|
+import com.bz.smart_city.quartz.entity.QuartzEntity;
|
|
|
+import com.bz.smart_city.quartz.job.ControlByDayJob;
|
|
|
+import com.bz.smart_city.quartz.service.ControlDayService;
|
|
|
+import com.bz.smart_city.quartz.service.JobAndTriggerService;
|
|
|
+import com.bz.smart_city.service.pay.PayControlRuleService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.InitializingBean;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.http.HttpEntity;
|
|
|
+import org.springframework.http.HttpHeaders;
|
|
|
+import org.springframework.http.MediaType;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.util.LinkedMultiValueMap;
|
|
|
+import org.springframework.util.MultiValueMap;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by ZJY on 2021-01-18 19:10
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Component
|
|
|
+public class ControlDayServiceImpl implements ControlDayService, InitializingBean {
|
|
|
+ @Resource
|
|
|
+ private AmountWaterUsedAmountMapper amountWaterUsedAmountMapper;
|
|
|
+ @Resource
|
|
|
+ PayBaseCustomerandmeterrelaMapper payBaseCustomerandmeterrelaMapper;
|
|
|
+ @Resource
|
|
|
+ PayControlRecordMapper payControlRecordMapper;
|
|
|
+ @Resource
|
|
|
+ private JobAndTriggerService jobAndTriggerService;
|
|
|
+ @Resource
|
|
|
+ CustomerMapper customerMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ PayControlRuleService payControlRuleService;
|
|
|
+
|
|
|
+ @Value("${Sync.Data.Url}")
|
|
|
+ String SyncUrl;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void afterPropertiesSet(){
|
|
|
+ saveQrtzTask();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void saveQrtzTask(){
|
|
|
+ // 1,查询需要批量推送的配置项目并构建定时任务
|
|
|
+ // 2,若对应定时任务不存在则创建
|
|
|
+ QuartzEntity entity = new QuartzEntity();
|
|
|
+ entity.setJobGroup("根据阀控规则定时处理开关阀");
|
|
|
+ entity.setJobName("ControlByDayJob" );
|
|
|
+ entity.setDescription("ControlByDayJob" );
|
|
|
+
|
|
|
+ boolean exists = jobAndTriggerService.isExists(entity);
|
|
|
+ if(!exists) {
|
|
|
+ String cron = "0 */30 * * * ?";
|
|
|
+ log.info("每天处理开关阀:" + cron);
|
|
|
+ entity.setCronExpression(cron);
|
|
|
+ entity.setJobClassName(ControlByDayJob.class.getName());
|
|
|
+ jobAndTriggerService.save(entity);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void start(){
|
|
|
+ List<PayBaseCustomerandmeterrela> payBaseCustomerandmeterrelas = amountWaterUsedAmountMapper.getCustIdAndSiteId();
|
|
|
+ for (PayBaseCustomerandmeterrela payBaseCustomerandmeterrela: payBaseCustomerandmeterrelas){
|
|
|
+
|
|
|
+ PayBaseCustomerandmeterrela customer = new PayBaseCustomerandmeterrela();
|
|
|
+ customer.setCustomerId(payBaseCustomerandmeterrela.getCustomerId());
|
|
|
+ List<PayBaseCustomerandmeterrela> payBaseCustomerandmeterrelaList = payBaseCustomerandmeterrelaMapper.findList(customer);
|
|
|
+ if(payBaseCustomerandmeterrelaList.size() > 0){
|
|
|
+
|
|
|
+ Customer customerNo = customerMapper.findById(customer.getCustomerId().intValue());
|
|
|
+ for (PayBaseCustomerandmeterrela one: payBaseCustomerandmeterrelaList){
|
|
|
+ String[] deviceType = StringUtils.split(one.getValveRuleId(),",");
|
|
|
+ String[] deviceTypeName = StringUtils.split(one.getValveRuleName(),",");
|
|
|
+
|
|
|
+ if(deviceType != null ){
|
|
|
+ for (int i=0;i<deviceType.length;i++){
|
|
|
+ //result执行动作,0关阀 1开阀
|
|
|
+ Integer result = payControlRuleService.GetConditionReusl(new Integer(deviceType[i]),one.getAccountId().toString());
|
|
|
+ if(result != null){
|
|
|
+ //插入数据库
|
|
|
+ PayControlRecord payControlRecord = new PayControlRecord();
|
|
|
+ payControlRecord.setAccountId(one.getAccountId());
|
|
|
+ payControlRecord.setMeterId(one.getWatermeterId());
|
|
|
+ payControlRecord.setType(result);
|
|
|
+ payControlRecord.setControlRuleId(new Integer(deviceType[i]));
|
|
|
+ payControlRecord.setControlRuleIdName(deviceTypeName[i]);
|
|
|
+ payControlRecord.setDelFlag("0");
|
|
|
+ payControlRecord.setCustomerId(customer.getCustomerId());
|
|
|
+ payControlRecord.setCreateDate(LocalDateTime.now());
|
|
|
+ payControlRecordMapper.add(payControlRecord);
|
|
|
+
|
|
|
+ //调用阀门接口
|
|
|
+ try {
|
|
|
+ String url=SyncUrl + "/api/platform/sendCommond";
|
|
|
+
|
|
|
+ String params = String.format("?customerNo=%s&meterNo=%s&type=%s",customerNo.getCustomerNo(),payControlRecord.getMeterId().toString(),payControlRecord.getType().toString());
|
|
|
+ url += params;
|
|
|
+ SyncValveSend syncValveSend = new SyncValveSend();
|
|
|
+ syncValveSend.setMeterNo(payControlRecord.getMeterId().toString());
|
|
|
+ syncValveSend.setType(payControlRecord.getType().toString());
|
|
|
+ syncValveSend.setCustomerNo(customerNo.getCustomerNo());
|
|
|
+ String json = JacksonUtil.obj2String(syncValveSend);
|
|
|
+ String postResult = HttpRequest.doPost(url ,"");
|
|
|
+ SyncValveResult syncValveResult = JacksonUtil.string2Obj(postResult, SyncValveResult.class);
|
|
|
+ Integer getResult = Integer.parseInt(syncValveResult.getStatus());
|
|
|
+ }
|
|
|
+ catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|