|
@@ -1,30 +1,23 @@
|
|
|
package com.huaxu.service.impl;
|
|
|
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
-import com.huaxu.client.OperationManagerClient;
|
|
|
-import com.huaxu.client.UserCenterClient;
|
|
|
-import com.huaxu.dao.AlarmDetailMapper;
|
|
|
import com.huaxu.dao.RevenueMapper;
|
|
|
import com.huaxu.dto.*;
|
|
|
-import com.huaxu.entity.AlarmDetailsEntity;
|
|
|
-import com.huaxu.entity.Message;
|
|
|
+import com.huaxu.entity.MonthRevenueEntity;
|
|
|
import com.huaxu.model.LoginUser;
|
|
|
-import com.huaxu.service.AlarmDetailsService;
|
|
|
+import com.huaxu.quartz.entity.QuartzEntity;
|
|
|
+import com.huaxu.quartz.job.SyncMeterCountJob;
|
|
|
+import com.huaxu.quartz.service.JobAndTriggerService;
|
|
|
import com.huaxu.service.RevenueService;
|
|
|
-import com.huaxu.util.DatesUtil;
|
|
|
-import com.huaxu.util.MessageSendUtil;
|
|
|
import com.huaxu.util.UserUtil;
|
|
|
-import javafx.beans.binding.DoubleExpression;
|
|
|
import lombok.extern.log4j.Log4j2;
|
|
|
-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.stereotype.Service;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.*;
|
|
|
-import java.util.function.Function;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @description
|
|
@@ -33,10 +26,37 @@ import java.util.stream.Collectors;
|
|
|
*/
|
|
|
@Service
|
|
|
@Log4j2
|
|
|
-public class RevenueServiceImpl implements RevenueService {
|
|
|
+public class RevenueServiceImpl implements RevenueService, InitializingBean {
|
|
|
|
|
|
@Resource
|
|
|
private RevenueMapper revenueMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private JobAndTriggerService jobAndTriggerService;
|
|
|
+ @Autowired
|
|
|
+ private RestTemplate restTemplate;
|
|
|
+ @Value("${http_pool.meterRequesturl}")
|
|
|
+ private String meterRequestUrl;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void afterPropertiesSet() throws Exception {
|
|
|
+ saveQrtzTask("0 0 1 * * ? ","同步水表数量","smsWaterSyncMeterCountJob", SyncMeterCountJob.class.getName());
|
|
|
+ }
|
|
|
+ public void saveQrtzTask(String cron, String jobGroup ,String jobName,String JobClassName) {
|
|
|
+ // 1,查询需要批量推送的配置项目并构建定时任务
|
|
|
+ // 2,若对应定时任务不存在则创建
|
|
|
+ QuartzEntity entity = new QuartzEntity();
|
|
|
+ entity.setJobGroup(jobGroup);
|
|
|
+ entity.setJobName(jobName);
|
|
|
+ entity.setDescription(jobName);
|
|
|
+ //jobAndTriggerService.deleteJob(entity);
|
|
|
+ boolean exists = jobAndTriggerService.isExists(entity);
|
|
|
+ if(!exists){
|
|
|
+ entity.setCronExpression(cron);
|
|
|
+ entity.setJobClassName(JobClassName);
|
|
|
+ jobAndTriggerService.save(entity);
|
|
|
+ }
|
|
|
+ }
|
|
|
/**
|
|
|
* 查询本月售水信息
|
|
|
* @return
|
|
@@ -184,5 +204,57 @@ public class RevenueServiceImpl implements RevenueService {
|
|
|
return revenueMapper.selectRevenueByDate(monthRevenueDto);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 查询是否当月有营收数据
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Integer isExistThisMonthRevenue(String tenantId) {
|
|
|
+ return revenueMapper.isExistThisMonthRevenue(tenantId);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 插入营收数据
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Integer insert(MonthRevenueEntity monthRevenueEntity) {
|
|
|
+ return revenueMapper.insert(monthRevenueEntity);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 修改营收数据
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Integer update(MonthRevenueEntity monthRevenueEntity) {
|
|
|
+ return revenueMapper.update(monthRevenueEntity);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询该租户一级公司id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Integer selectCompanyIdByTenant(String tenantId) {
|
|
|
+ return revenueMapper.selectCompanyIdByTenant(tenantId);
|
|
|
+ }
|
|
|
|
|
|
+ @Override
|
|
|
+ public void syncMeterCount() {
|
|
|
+ MeterCountDto meterCountDto = restTemplate.getForObject(meterRequestUrl, MeterCountDto.class);
|
|
|
+ if(meterCountDto.getStatus()==0){
|
|
|
+ for (MonthRevenueEntity monthRevenueEntity : meterCountDto.getData()) {
|
|
|
+ //查询当月是否有数据 有就更新 没有就插入
|
|
|
+ Integer count =revenueMapper.isExistThisMonthRevenue(monthRevenueEntity.getTenantId());
|
|
|
+ if(count==0){
|
|
|
+ Calendar thisMonthFirstDateCal = Calendar.getInstance();
|
|
|
+ thisMonthFirstDateCal.set(Calendar.DAY_OF_MONTH, 1);
|
|
|
+ monthRevenueEntity.setCollectDate(thisMonthFirstDateCal.getTime());
|
|
|
+ monthRevenueEntity.setCompanyOrgId(revenueMapper.selectCompanyIdByTenant(monthRevenueEntity.getTenantId()));
|
|
|
+ revenueMapper.insert(monthRevenueEntity);
|
|
|
+ }else{
|
|
|
+ revenueMapper.update(monthRevenueEntity);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|