|
@@ -2,17 +2,21 @@ package fi.gl.task;
|
|
|
|
|
|
import kd.bos.context.RequestContext;
|
|
|
import kd.bos.dataentity.entity.DynamicObject;
|
|
|
-import kd.bos.dataentity.entity.DynamicObjectCollection;
|
|
|
import kd.bos.entity.AppInfo;
|
|
|
import kd.bos.entity.AppMetadataCache;
|
|
|
import kd.bos.entity.param.AppParam;
|
|
|
import kd.bos.exception.KDException;
|
|
|
import kd.bos.orm.query.QCP;
|
|
|
import kd.bos.orm.query.QFilter;
|
|
|
+import kd.bos.schedule.api.TaskInfo;
|
|
|
import kd.bos.schedule.executor.AbstractTask;
|
|
|
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
|
|
+import kd.bos.servicehelper.operation.SaveServiceHelper;
|
|
|
import kd.bos.servicehelper.parameter.SystemParamServiceHelper;
|
|
|
+import kd.bos.servicehelper.schedule.ScheduleServiceHelper;
|
|
|
+import kd.bos.servicehelper.user.UserServiceHelper;
|
|
|
|
|
|
+import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.Date;
|
|
|
import java.util.Map;
|
|
@@ -25,12 +29,26 @@ import java.util.Map;
|
|
|
public class AutoDailTask extends AbstractTask {
|
|
|
@Override
|
|
|
public void execute(RequestContext requestContext, Map<String, Object> map) throws KDException {
|
|
|
- SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
- System.out.println("打印日志测试:" + df.format(new Date()));
|
|
|
+ TaskInfo taskInfo = ScheduleServiceHelper.queryTask(this.taskId);
|
|
|
+ String scheduleId = taskInfo.getScheduleId();
|
|
|
+ DynamicObject schedule = BusinessDataServiceHelper.loadSingleFromCache(scheduleId,"sch_schedule");
|
|
|
+ DynamicObject schprincipal = schedule.getDynamicObject("schprincipal");
|
|
|
+ Long userId = schprincipal.getLong("id");
|
|
|
+
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ String now = sdf.format(new Date());
|
|
|
+ Date nowDate = null;
|
|
|
+ try {
|
|
|
+ nowDate = sdf.parse(now);
|
|
|
+ } catch (ParseException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
QFilter qFilter_enable = new QFilter("enable", QCP.equals,"1");
|
|
|
QFilter qFilter_status = new QFilter("status", QCP.equals, "C");
|
|
|
+ QFilter qFilter_fisaccounting = new QFilter("fisaccounting", QCP.equals, "1");
|
|
|
+ QFilter qFilter_number = new QFilter("number", QCP.equals, "A002");
|
|
|
DynamicObject[] orgCol = BusinessDataServiceHelper.load("bos_org","id",
|
|
|
- new QFilter[]{qFilter_enable,qFilter_status});
|
|
|
+ new QFilter[]{qFilter_enable,qFilter_status,qFilter_fisaccounting,qFilter_number});
|
|
|
for(DynamicObject orgObj : orgCol){
|
|
|
|
|
|
AppInfo cgfwAppInfo = AppMetadataCache.getAppInfo("gl");
|
|
@@ -41,9 +59,73 @@ public class AutoDailTask extends AbstractTask {
|
|
|
apm.setOrgId(orgObj.getLong("id"));
|
|
|
Map<String,Object> paramWhole = SystemParamServiceHelper.loadAppParameterFromCache(apm);
|
|
|
Object nckd_isautodaily = paramWhole.get("nckd_isautodaily");
|
|
|
- if("true".equals(nckd_isautodaily)){
|
|
|
+ if("true".equals(nckd_isautodaily.toString())){
|
|
|
+ dailyData(orgObj,nowDate,userId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void dailyData(DynamicObject org, Date dailydate, Long userId) {
|
|
|
+
|
|
|
+ DynamicObject dailybillLogObj = BusinessDataServiceHelper.newDynamicObject("nckd_gl_autodaillog");
|
|
|
+
|
|
|
+ String messageInfo = "";
|
|
|
+ QFilter qFilter_org = new QFilter("org", QCP.equals,org.getPkValue());
|
|
|
+ QFilter qFilter_bizdate = new QFilter("bizdate",QCP.equals,dailydate);
|
|
|
+ DynamicObject[] voucherCol = BusinessDataServiceHelper.load("gl_voucher","id,ispost,billno,bizdate,org,billstatus",
|
|
|
+ new QFilter[]{qFilter_org,qFilter_bizdate});
|
|
|
+ for(DynamicObject voucherObj : voucherCol){
|
|
|
+ boolean ispost = voucherObj.getBoolean("ispost");
|
|
|
+ if(ispost!=true){
|
|
|
+ messageInfo = "所选日期存在未过账凭证";
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ if("".equals(messageInfo)){
|
|
|
+ QFilter qFilter_nckd_org = new QFilter("nckd_org", QCP.equals,org.getPkValue());
|
|
|
+ QFilter qFilter_nckd_dailydate = new QFilter("nckd_dailydate",QCP.equals,dailydate);
|
|
|
+ DynamicObject[] dailybillCol = BusinessDataServiceHelper.load("nckd_gl_dailybill","id",
|
|
|
+ new QFilter[]{qFilter_nckd_org,qFilter_nckd_dailydate});
|
|
|
+ if(dailybillCol!=null && dailybillCol.length>0){
|
|
|
+ messageInfo = "所选日期已日结";
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ if("".equals(messageInfo)){
|
|
|
+
|
|
|
+ messageInfo = writeDailybill(org,dailydate,userId);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ dailybillLogObj.set("nckd_orgfield",org.getPkValue());
|
|
|
+ dailybillLogObj.set("nckd_dailydate",dailydate);
|
|
|
+ dailybillLogObj.set("enable","1");
|
|
|
+ dailybillLogObj.set("status","C");
|
|
|
+ if("".equals(messageInfo)){
|
|
|
+ dailybillLogObj.set("nckd_dailstatus","0");
|
|
|
+ }else{
|
|
|
+ dailybillLogObj.set("nckd_dailstatus","1");
|
|
|
+ dailybillLogObj.set("nckd_errorinfo",messageInfo);
|
|
|
+ }
|
|
|
+ DynamicObject[] logDatalist = new DynamicObject[]{dailybillLogObj};
|
|
|
+ SaveServiceHelper.save(logDatalist);
|
|
|
+ }
|
|
|
+
|
|
|
+ private String writeDailybill(DynamicObject orgObjReal, Date dailydate, Long userId) {
|
|
|
+ String messageInfo = "";
|
|
|
+ try {
|
|
|
+ DynamicObject dailybillObj = BusinessDataServiceHelper.newDynamicObject("nckd_gl_dailybill");
|
|
|
+ dailybillObj.set("nckd_org", orgObjReal);
|
|
|
+ dailybillObj.set("nckd_dailydate", dailydate);
|
|
|
+ dailybillObj.set("status", "A");
|
|
|
+ dailybillObj.set("enable", "1");
|
|
|
+ dailybillObj.set("creator", userId);
|
|
|
+ DynamicObject[] datalist = new DynamicObject[]{dailybillObj};
|
|
|
+ SaveServiceHelper.save(datalist);
|
|
|
+ }catch(Exception e){
|
|
|
+ messageInfo = e.getMessage();
|
|
|
+ }
|
|
|
+ return messageInfo;
|
|
|
}
|
|
|
}
|