Commit dcfed3a0 authored by litengwei's avatar litengwei

任务 9900

parent ed504d97
...@@ -110,4 +110,5 @@ public interface EquipmentSpecificIndexMapper extends BaseMapper<EquipmentSpecif ...@@ -110,4 +110,5 @@ public interface EquipmentSpecificIndexMapper extends BaseMapper<EquipmentSpecif
List<EquipmentSpecificIndex> getEquipmentSpeIndexByIotCodeTrend(String iotCode, Integer isTrend, String fieldKey); List<EquipmentSpecificIndex> getEquipmentSpeIndexByIotCodeTrend(String iotCode, Integer isTrend, String fieldKey);
List<Map<String, Object>> getEquipSpecificScrap();
} }
...@@ -6,6 +6,8 @@ import java.util.*; ...@@ -6,6 +6,8 @@ import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.yeejoin.amos.feign.systemctl.Systemctl;
import com.yeejoin.amos.feign.systemctl.model.MessageModel;
import com.yeejoin.equipmanage.common.entity.vo.*; import com.yeejoin.equipmanage.common.entity.vo.*;
import com.yeejoin.equipmanage.common.vo.*; import com.yeejoin.equipmanage.common.vo.*;
import com.yeejoin.equipmanage.mapper.*; import com.yeejoin.equipmanage.mapper.*;
...@@ -17,6 +19,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -17,6 +19,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
...@@ -162,6 +165,9 @@ public class EquipmentSpecificSerivceImpl extends ServiceImpl<EquipmentSpecificM ...@@ -162,6 +165,9 @@ public class EquipmentSpecificSerivceImpl extends ServiceImpl<EquipmentSpecificM
@Value("${equipment.type}") @Value("${equipment.type}")
String equipmentCategoryLeftTypeCode; String equipmentCategoryLeftTypeCode;
@Value("${equipment.scrap.day}")
String equipmentScrapDay;
@Autowired @Autowired
private ISyncDataService syncDataService; private ISyncDataService syncDataService;
...@@ -1803,4 +1809,73 @@ public class EquipmentSpecificSerivceImpl extends ServiceImpl<EquipmentSpecificM ...@@ -1803,4 +1809,73 @@ public class EquipmentSpecificSerivceImpl extends ServiceImpl<EquipmentSpecificM
return infoVoList; return infoVoList;
} }
/**
* 在设备报废前30日 每日9点执行 系统推送提醒。设备报废后停止消息推送提醒。。
*
* @throws Exception
*/
@Scheduled(cron = "${equipment.scrap.cron}")
@Transactional(rollbackFor = Exception.class)
public void equipmentScrap() throws Exception {
List<Map<String, Object>> equipSpecificScrap = equipmentSpecificIndexMapper.getEquipSpecificScrap();
equipSpecificScrap.forEach(e->{
try {
int year = e.get("weExpiry") != null ? Integer.parseInt(e.get("weExpiry").toString()) : Integer.parseInt(e.get("wesExpiry").toString());
Date productDate = DateUtils.dateParse(e.get("product").toString(),DateUtils.DATE_TIME_PATTERN);
Calendar calendar = Calendar.getInstance();
calendar.setTime(productDate);
calendar.add(Calendar.YEAR, year);
Date now = new Date();
String scrapTime = new SimpleDateFormat(DateUtils.DATE_TIME_PATTERN).format(calendar.getTime())
int i = 0;
while (now.after(calendar.getTime())) {
calendar.add(Calendar.DAY_OF_MONTH,1);
i++;
}
if(i < 30 && i > -1) {
syncSystemctlMsg(e, scrapTime,i);
}
} catch (ParseException parseException) {
parseException.printStackTrace();
}
});
}
void syncSystemctlMsg(Map<String, Object> map,String scrapTime, int i) {
try {
MessageModel model = new MessageModel();
model.setTitle("报废到期提醒");
String equipName = map.get("name").toString();
String location = map.get("sName").toString() + map.get("position").toString() ;
String body = String.format("%s-%s于%s报废,请提前更换处理", equipName, location, scrapTime);
String join = String.format("设备还剩%s天报废,请提前更换", i);
model.setBody(body);
model.setMsgType("scrapWarning");
model.setSendTime(new Date());
model.setIsSendApp(false);
model.setTerminal("WEB");
model.setIsSendWeb(true);
model.setRelationId(map.get("id").toString());
model.setCategory(1);
List<String> receive = new ArrayList<>();
receive.add("system");
Map<String, String> ext = new HashMap<>();
ext.put("content", join);
ext.put("type", "报废到期");
ext.put("name", map.get("name").toString());
ext.put("time", new SimpleDateFormat(DateUtils.DATE_TIME_PATTERN).format(new Date()));
model.setExtras(ext);
model.setRecivers(receive);
Systemctl.messageClient.create(model);
} catch (Exception e) {
e.printStackTrace();
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment