|
@@ -5,7 +5,9 @@ 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.PayMessagetemplateMapper;
|
|
|
import com.bz.smart_city.dao.pay.archives.PayBaseCustomerandmeterrelaMapper;
|
|
|
+import com.bz.smart_city.dto.pay.PayMessageTemplateDto;
|
|
|
import com.bz.smart_city.entity.Customer;
|
|
|
import com.bz.smart_city.entity.SyncValveResult;
|
|
|
import com.bz.smart_city.entity.SyncValveSend;
|
|
@@ -15,9 +17,11 @@ 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.PayControlRecordService;
|
|
|
import com.bz.smart_city.service.pay.PayControlRuleService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.ibatis.annotations.Param;
|
|
|
import org.springframework.beans.factory.InitializingBean;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
@@ -31,7 +35,11 @@ import org.springframework.util.MultiValueMap;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.math.BigInteger;
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
@@ -50,6 +58,10 @@ public class ControlDayServiceImpl implements ControlDayService, InitializingBea
|
|
|
private JobAndTriggerService jobAndTriggerService;
|
|
|
@Resource
|
|
|
CustomerMapper customerMapper;
|
|
|
+ @Autowired
|
|
|
+ PayControlRecordService payControlRecordService;
|
|
|
+ @Resource
|
|
|
+ private PayMessagetemplateMapper payMessagetemplateMapper;
|
|
|
|
|
|
@Autowired
|
|
|
PayControlRuleService payControlRuleService;
|
|
@@ -59,84 +71,151 @@ public class ControlDayServiceImpl implements ControlDayService, InitializingBea
|
|
|
|
|
|
@Override
|
|
|
public void afterPropertiesSet(){
|
|
|
- saveQrtzTask();
|
|
|
+ List<PayBaseCustomerandmeterrela> payBaseCustomerandmeterrelas = amountWaterUsedAmountMapper.getCustIdAndSiteId();
|
|
|
+ for (PayBaseCustomerandmeterrela payBaseCustomerandmeterrela: payBaseCustomerandmeterrelas){
|
|
|
+ saveQrtzTask(payBaseCustomerandmeterrela.getSiteId(),payBaseCustomerandmeterrela.getCustomerId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public void saveQrtzTask(BigInteger siteId,BigInteger customerId){
|
|
|
+ try {
|
|
|
+ // 1,查询需要批量推送的配置项目并构建定时任务
|
|
|
+ // 2,若对应定时任务不存在则创建
|
|
|
+ String cron = getCron(siteId,customerId);
|
|
|
+ if (StringUtils.isNotBlank(cron)){
|
|
|
+ QuartzEntity entity = new QuartzEntity();
|
|
|
+ entity.setJobGroup("根据阀控规则定时处理开关阀");
|
|
|
+ entity.setJobName("ControlByDayJob" +customerId);
|
|
|
+ entity.setDescription("ControlByDayJob" +customerId);
|
|
|
+ boolean exists = jobAndTriggerService.isExists(entity);
|
|
|
+
|
|
|
+ if(exists)
|
|
|
+ jobAndTriggerService.deleteJob(entity);
|
|
|
+
|
|
|
+ if(1==1) {
|
|
|
+ log.info(String.format("定时阀控处理:%s,客户ID%s",cron,customerId));
|
|
|
+ entity.setCronExpression(cron);
|
|
|
+ entity.setJobClassName(ControlByDayJob.class.getName());
|
|
|
+
|
|
|
+ HashMap<String, Object> jobData = new HashMap<String, Object>();
|
|
|
+ jobData.put("siteId", siteId.intValue());
|
|
|
+ jobData.put("customerId", customerId.intValue());
|
|
|
+ entity.setJobData(jobData);
|
|
|
+ jobAndTriggerService.save(entity);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex){
|
|
|
+ log.error(ex.getMessage());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- 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 0 1 * * ?";
|
|
|
- log.info("每天处理开关阀:" + cron);
|
|
|
- entity.setCronExpression(cron);
|
|
|
- entity.setJobClassName(ControlByDayJob.class.getName());
|
|
|
- jobAndTriggerService.save(entity);
|
|
|
+ public String getCron(BigInteger siteId,BigInteger customerId){
|
|
|
+ //查询催缴设置
|
|
|
+ //(1)手动催缴:实时执行;
|
|
|
+ //(2)自动催缴:半小时后执行。
|
|
|
+ //3. 若设定欠费关阀规则,但未进行催缴设置则不执行“欠费关阀”指令。
|
|
|
+ PayMessageTemplateDto payMessageTemplateDto = payMessagetemplateMapper.get(siteId,customerId,null,null);
|
|
|
+
|
|
|
+ if(payMessageTemplateDto != null){
|
|
|
+ String sendTime = payMessageTemplateDto.getSendTime();
|
|
|
+ if(StringUtils.isNotBlank(sendTime)){
|
|
|
+ if(sendTime.length() == 5)
|
|
|
+ sendTime += ":00";
|
|
|
+ //催缴方式 0手动 1自动
|
|
|
+ if(payMessageTemplateDto.getOperationType() == 0){
|
|
|
+ String[] sp = sendTime.split(":");
|
|
|
+ if(sp != null && sp.length == 3){
|
|
|
+ String cron = String.format("%s %s %s * * ?",Integer.parseInt(sp[2]),Integer.parseInt(sp[1]),Integer.parseInt(sp[0]));
|
|
|
+ return cron;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (payMessageTemplateDto.getOperationType() == 1){
|
|
|
+ DateTimeFormatter dfYmd = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+ String currTime = LocalDateTime.now().format(dfYmd) + " " + sendTime;;
|
|
|
+ DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+ LocalDateTime localDateTime = LocalDateTime.parse(currTime,df);
|
|
|
+ localDateTime.plusMinutes(30);
|
|
|
+ String cron = String.format("%s %s %s * * ?",localDateTime.getSecond(),localDateTime.getMinute(),localDateTime.getHour());
|
|
|
+ return cron;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
+ return "";
|
|
|
}
|
|
|
|
|
|
- @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);
|
|
|
+ public void start(int flag,BigInteger siteId,BigInteger customerId){
|
|
|
+ PayBaseCustomerandmeterrela customer = new PayBaseCustomerandmeterrela();
|
|
|
+ customer.setCustomerId(customerId);
|
|
|
+ customer.setSiteId(siteId);
|
|
|
+ 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(),",");
|
|
|
+ //循环用户关联的所有阀控规则
|
|
|
+ Integer ControlResult = null;
|
|
|
+ if(deviceType != null ){
|
|
|
+ for (int i=0;i<deviceType.length;i++){
|
|
|
+ //result执行动作,0关阀 1开阀
|
|
|
+ List<Integer> filterId = new ArrayList<>();
|
|
|
+ filterId.add(2);
|
|
|
+ filterId.add(4);
|
|
|
+ filterId.add(5);
|
|
|
+ Integer result = payControlRuleService.GetConditionReusl(new Integer(deviceType[i]),one.getAccountId().toString(),flag,filterId);
|
|
|
+ if(result != null){
|
|
|
+ try {
|
|
|
+ //后面规则执行动作与前面一样不操作
|
|
|
+ if(ControlResult == result.intValue())
|
|
|
+ continue;
|
|
|
+ ControlResult = result;
|
|
|
+
|
|
|
+ //最近一次阀控动作如果与当前一致则不操作
|
|
|
+ PayControlRecord payControlRecordTemp = new PayControlRecord();
|
|
|
+ payControlRecordTemp.setAccountId(one.getAccountId());
|
|
|
+ PayControlRecord payControlRecordLast = payControlRecordService.getRecord(payControlRecordTemp);
|
|
|
+ if(payControlRecordLast != null){
|
|
|
+ if(payControlRecordLast.getType().intValue() == result){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //执行动作与阀门当前状态一致不操作
|
|
|
+
|
|
|
+
|
|
|
|
|
|
//调用阀门接口
|
|
|
- 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();
|
|
|
+ String url=SyncUrl + "/api/platform/sendCommond";
|
|
|
+ String params = String.format("?customerNo=%s&meterNo=%s&type=%s",customerNo.getCustomerNo(),one.getMetercode(),result.toString());
|
|
|
+ url += params;
|
|
|
+ String postResult = HttpRequest.doPost(url ,"");
|
|
|
+ SyncValveResult syncValveResult = JacksonUtil.string2Obj(postResult, SyncValveResult.class);
|
|
|
+ Integer getResult = Integer.parseInt(syncValveResult.getStatus());
|
|
|
+ if(getResult != null && getResult == 0){
|
|
|
+ //插入数据库
|
|
|
+ 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.setSiteId(customer.getSiteId());
|
|
|
+ payControlRecord.setCreateDate(LocalDateTime.now());
|
|
|
+ payControlRecordMapper.add(payControlRecord);
|
|
|
}
|
|
|
}
|
|
|
+ catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|