Commit 3ae5eda1 by liuyang

2024-07-26 定时添加设备计划

parent f7c3c1a1
...@@ -3,9 +3,11 @@ package com.baosight.hggp.hg.sb.service; ...@@ -3,9 +3,11 @@ package com.baosight.hggp.hg.sb.service;
import com.baosight.hggp.aspect.annotation.OperationLogAnnotation; import com.baosight.hggp.aspect.annotation.OperationLogAnnotation;
import com.baosight.hggp.common.DdynamicEnum; import com.baosight.hggp.common.DdynamicEnum;
import com.baosight.hggp.core.constant.CommonConstant; import com.baosight.hggp.core.constant.CommonConstant;
import com.baosight.hggp.core.dao.DaoBase;
import com.baosight.hggp.core.dao.DaoUtils; import com.baosight.hggp.core.dao.DaoUtils;
import com.baosight.hggp.core.security.UserSessionUtils; import com.baosight.hggp.core.security.UserSessionUtils;
import com.baosight.hggp.hg.constant.HGConstant; import com.baosight.hggp.hg.constant.HGConstant;
import com.baosight.hggp.hg.kc.domain.HGKC006A;
import com.baosight.hggp.hg.sb.domain.HGSB001; import com.baosight.hggp.hg.sb.domain.HGSB001;
import com.baosight.hggp.hg.sb.domain.HGSB002A; import com.baosight.hggp.hg.sb.domain.HGSB002A;
import com.baosight.hggp.hg.sb.tools.HGSBTools; import com.baosight.hggp.hg.sb.tools.HGSBTools;
...@@ -28,6 +30,7 @@ import java.util.Arrays; ...@@ -28,6 +30,7 @@ import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
/** /**
* @author LiuYang * @author LiuYang
...@@ -165,4 +168,61 @@ public class ServiceHGSB002 extends ServiceEPBase { ...@@ -165,4 +168,61 @@ public class ServiceHGSB002 extends ServiceEPBase {
} }
return inInfo; return inInfo;
} }
@OperationLogAnnotation(operModul = "设备计划",operType = "保存",operDesc = "定时添加设备计划")
public EiInfo autoAdd(EiInfo inInfo) {
try {
String systemDate = DateUtils.formatShort(DateUtils.date());
inInfo.setCell(EiConstant.queryBlock, ACConstants.ROW_CODE_0,HGSB001.FIELD_MAINTAIN_DATE,systemDate);
List<HGSB001> hgsb001s= DaoBase.getInstance().query(HGSB001.QUERY,new HashMap<String,String>(){{
put(HGSB001.FIELD_MAINTAIN_DATE,systemDate);
}});
//List<HGSB001> resultBlock = inInfo.getBlock(EiConstant.resultBlock).getRows();
Map<String,List<HGSB001>> hgsb001Map = hgsb001s.stream().collect(Collectors.groupingBy(HGSB001::getCompanyCode,Collectors.toList()));
for (Map.Entry<String, List<HGSB001>> entry : hgsb001Map.entrySet()) {
String companyCode = entry.getKey();
List<HGSB001> hgsb001List = entry.getValue();
HGSB002 hgsb002 = new HGSB002();
hgsb002.setDeleteFlag(CommonConstant.YesNo.NO_0);
hgsb002.setCompanyCode(companyCode);
hgsb002.setCompanyName(hgsb001List.get(0).getCompanyName());
hgsb002.setPlanDate(systemDate);
hgsb002.setPlanType(2);
hgsb002.setPlanStartDate(systemDate.substring(0,6)+"01");
hgsb002.setPlanEndDate(systemDate.substring(0,6)+DateUtil.getDaysOfMonth(systemDate));
hgsb002.setPlanUserId("system");
hgsb002.setPlanUserName("system");
hgsb002.setPlanStatus(0);
hgsb002.setTaskStatus(0);
this.add(hgsb002);
this.addHgsb002a(hgsb001List,hgsb002);
}
}catch (Exception e){
LogUtils.setDetailMsg(inInfo,e,"自动添加设备计划失败");
}
return inInfo;
}
public void addHgsb002a(List<HGSB001> hgsb001List, HGSB002 hgsb002) {
for (HGSB001 hgsb001: hgsb001List) {
//HGSB001 hgsb001 = new HGSB001();
//hgsb001.fromMap(map);
HGSB002A hgsb002a = new HGSB002A();
hgsb002a.setDeleteFlag(CommonConstant.YesNo.NO_0);
hgsb002a.setParentId(hgsb002.getId());
hgsb002a.setGroupCode(hgsb001.getGroupCode());
hgsb002a.setGroupName(hgsb001.getGroupName());
hgsb002a.setDeviceType(hgsb001.getDeviceType());
hgsb002a.setDeviceCode(hgsb001.getDeviceCode());
hgsb002a.setDeviceName(hgsb001.getDeviceName());
hgsb002a.setDeviceModel(hgsb001.getDeviceModel());
DaoUtils.insert(HGSB002A.INSERT,hgsb002a);
String planCode = DateUtil.getDateOfDays(hgsb002.getPlanDate(),hgsb001.getPeriodDays(),DateUtil.DATE8_PATTERN);
hgsb001.setMaintainDate(planCode);
DaoUtils.update(HGSB001.UPDATE,hgsb001);
}
}
} }
...@@ -114,6 +114,13 @@ public class DateUtil { ...@@ -114,6 +114,13 @@ public class DateUtil {
return DateUtil.toDateStr(calendar.getTime(),DATE8_PATTERN);//输出上个月的日期 return DateUtil.toDateStr(calendar.getTime(),DATE8_PATTERN);//输出上个月的日期
} }
public static String getDateOfDays(String date,int day,String pattern){
Calendar calendar = Calendar.getInstance();//日历对象
calendar.setTime(Objects.requireNonNull(DateUtil.toDate(date, pattern)));//设置当前日期
calendar.add(Calendar.DAY_OF_YEAR, day);//加上天数
return DateUtil.toDateStr(calendar.getTime(),DATE8_PATTERN);//输出上个月的日期
}
private static SimpleDateFormat getDateParser(String pattern) { private static SimpleDateFormat getDateParser(String pattern) {
return new SimpleDateFormat(pattern); return new SimpleDateFormat(pattern);
} }
......
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