package com.engine.htsc.trip.service.impl;

import com.engine.htsc.trip.util.LogUtil;
import com.weaverboot.frame.ioc.anno.classAnno.WeaIocReplaceComponent;
import com.weaverboot.frame.ioc.anno.methodAnno.WeaReplaceBefore;
import com.weaverboot.frame.ioc.handler.replace.weaReplaceParam.impl.WeaBeforeReplaceParam;
import weaver.conn.RecordSet;
import weaver.general.Util;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Map;

@WeaIocReplaceComponent("generatePrintLogInterceptor")
public class GeneratePrintLogInterceptor {

	private final LogUtil logUtil = new LogUtil();

	@WeaReplaceBefore(value = "/htoa/api/workflow/reqform/generatePrintLog", order = 1, description = "拦截调用打印接口前")
	public void before(WeaBeforeReplaceParam weaBeforeReplaceParam) {
		logUtil.writeLog("===GeneratePrintLogInterceptor, 拦截调用打印接口前===");
		Map<String, Object> paramMap = weaBeforeReplaceParam.getParamMap();
		String requestid = (String) paramMap.getOrDefault("requestid", "");
		logUtil.writeLog("[requestid]: (" + requestid + ")");
		RecordSet rs = new RecordSet();
		rs.executeQuery("select ismultiprint from workflow_requestbase where requestid=" + requestid);
		String ismultiprint = ""; //打印标识
		if (rs.next()) {
			ismultiprint = Util.null2String(rs.getString("ismultiprint"));
		}
		DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
		if (!"1".equals(ismultiprint)) {
			String now = df.format(LocalDateTime.now());
			rs.executeUpdate("update uf_zfmx set dyzt=0,dysj='" + now + "' where reqid=" + requestid);
			logUtil.writeLog("已更新");
		} else {
			String now = df.format(LocalDateTime.now());
			rs.executeUpdate("update uf_zfmx set dysj='" + now + "' where reqid=" + requestid);
			logUtil.writeLog("打印时间已更新");
		}

	}
}
