import com.supwisdom.dlpay.framework.util.ApplicationUtil
import com.supwisdom.dlpay.framework.util.TradeDict
import com.supwisdom.dlpay.util.ConstantUtil
+import net.javacrumbs.shedlock.core.SchedulerLock
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.ApplicationContext
import org.springframework.scheduling.annotation.Scheduled
class MySchedulerTask {
@Autowired
private lateinit var shopaccService: ShopaccService
- @Autowired
- private lateinit var systemUtilService: SystemUtilService
fun doShopBlanceUpdate(dtl: TShopdtl) {
shopaccService.recalcShopBalance(dtl.refno, true)
}
@Scheduled(cron = "\${shopbalance.updater.cron:-}")
+ @SchedulerLock(name = "dealShopUnupdatedDtl")
fun dealShopUnupdatedDtl() {
- var tasklock = TTaskLock()
- try {
- //集群控制
- try {
- tasklock = systemUtilService.doLockTask("SHOPBLANCEUPDATETASK", 10, "更新账户余额任务")
- if (tasklock == null) {
- return
- }
- } catch (e: Exception) {
- return
- }
-
- shopaccService.findUnupdatedShopDtl(100).forEach {
- doShopBlanceUpdate(it)
- }
- } catch (ex: Exception) {
- ex.printStackTrace()
- } finally {
- if (tasklock?.taskcode.isNotEmpty()) {
- tasklock.taskstatus = 0
- tasklock.tasktime = systemUtilService.sysdatetime.hostdatetime
- systemUtilService.updateTaskLock(tasklock)
- }
+ shopaccService.findUnupdatedShopDtl(100).forEach {
+ doShopBlanceUpdate(it)
}
-
-
}
}
private lateinit var applicationContext: ApplicationContext
@Scheduled(cron = "\${query.third.transdtl.result.cron:-}")
+ @SchedulerLock(name = "DtlQueryResultSchedulerTask")
fun queryThirdTransdtlResult() {
- var tasklock = TTaskLock()
- try {
- //集群控制
+ //仅查询当天数据,查询次数在规定次数之下
+ dtlQueryResultService.getNeedQueryRecords(systemUtilService.accdate, ConstantUtil.QUERY_MAX_COUNT).forEach {
try {
- tasklock = systemUtilService.doLockTask("QUERYTHIRDTRANSDTLRESULTTASK", 10, "查询第三方流水状态任务")
- if (tasklock == null) {
- return
- }
- } catch (e: Exception) {
- return
- }
-
- //仅查询当天数据,查询次数在规定次数之下
- dtlQueryResultService.getNeedQueryRecords(systemUtilService.accdate, ConstantUtil.QUERY_MAX_COUNT).forEach {
- try {
- doQuery(it)
- } catch (exp: Exception) {
- it.qcnt = it.qcnt + 1
- dtlQueryResultService.saveOrUpdateDtlQuery(it) //次数加一
- }
- }
- } catch (ex: Exception) {
- ex.printStackTrace()
- } finally {
- if (tasklock?.taskcode.isNotEmpty()) {
- tasklock.taskstatus = 0
- tasklock.tasktime = systemUtilService.sysdatetime.hostdatetime
- systemUtilService.updateTaskLock(tasklock)
+ doQuery(it)
+ } catch (exp: Exception) {
+ it.qcnt = it.qcnt + 1
+ dtlQueryResultService.saveOrUpdateDtlQuery(it) //次数加一
}
}
}
+++ /dev/null
-package com.supwisdom.agent.api.bean;
-
-/**
- * 第一行:总笔数|总金额|代扣总笔数|代扣总金额|退款总笔数|退款总金额|
- */
-public class CheckFileHeader {
- private int totalCount;
- private int totalAmount;
- private int payCount;
- private int payAmount;
- private int refundCount;
- private int refundAmount;
-
- public int getTotalCount() {
- return totalCount;
- }
-
- public void setTotalCount(int totalCount) {
- this.totalCount = totalCount;
- }
-
- public int getTotalAmount() {
- return totalAmount;
- }
-
- public void setTotalAmount(int totalAmount) {
- this.totalAmount = totalAmount;
- }
-
- public int getPayCount() {
- return payCount;
- }
-
- public void setPayCount(int payCount) {
- this.payCount = payCount;
- }
-
- public int getPayAmount() {
- return payAmount;
- }
-
- public void setPayAmount(int payAmount) {
- this.payAmount = payAmount;
- }
-
- public int getRefundCount() {
- return refundCount;
- }
-
- public void setRefundCount(int refundCount) {
- this.refundCount = refundCount;
- }
-
- public int getRefundAmount() {
- return refundAmount;
- }
-
- public void setRefundAmount(int refundAmount) {
- this.refundAmount = refundAmount;
- }
-
- public boolean isZero() {
- return (totalAmount == 0 && totalCount == 0
- && payAmount == 0 && payCount == 0 && refundAmount == 0 && refundCount == 0);
- }
-
- @Override
- public String toString() {
- return totalCount +
- ", " + totalAmount +
- ", " + payCount +
- ", " + payAmount +
- ", " + refundCount +
- ", " + refundAmount;
- }
-}
import com.supwisdom.agent.Util.DlpayUtil;
import com.supwisdom.agent.Util.ErrorCode;
import com.supwisdom.agent.Util.StringUtil;
-import com.supwisdom.agent.api.bean.CheckFileHeader;
import com.supwisdom.agent.api.bean.CheckFileLine;
import com.supwisdom.agent.api.bean.DlpayReq;
import com.supwisdom.agent.api.bean.DlpayResp;
import com.supwisdom.agent.api.service.YnrccApiService;
import com.supwisdom.agent.api.service.YnrccParamCheckService;
+import com.supwisdom.dlpay.api.agent.Constant;
import org.apache.commons.beanutils.BeanUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* 第一行:总笔数|总金额|代扣总笔数|代扣总金额|退款总笔数|退款总金额|
* 第二行及以后:交易日期|交易时间|报文业务类型|业务系统流水号|银行流水号|付款银行卡号|收款商户银行卡号|核心记账日期|交易金额|交易摘要|
*/
- private static final String[] chkFileColumnList = new String[]{"transdate", "transtime", "flag", "refno", "agentrefno",
- "payerid", "payeeid", "agentdate", "amount", "summary"};
- private static final String[] chkFileHeaderColumnList = new String[]{"totalCount", "totalAmount", "payCount",
- "payAmount", "refundCount", "refundAmount"};
+ private static final String[] chkFileColumnList = new String[]{"transdate", "transtime", Constant.COL_FLAG,
+ Constant.COL_REFNO, Constant.COL_AGENT_REFNO, Constant.COL_PAYERID, Constant.COL_PAYEEID,
+ Constant.COL_AGENT_DATE, Constant.COL_AMOUNT, Constant.COL_SUMMARY};
+
private static final String chkFileDelimiter = "|";
private static final String FLAG_WITHHOLD = "BC5512";
private static final String FLAG_REFUND = "BC5513";
}
private <T> void populate(String[] fields, String[] column, T bean) {
- if (fields.length != column.length) {
+ if (fields.length < column.length) {
throw new IllegalArgumentException("错误的列定义");
}
try {
try {
T bean = beanClass.newInstance();
populate(fields, column, bean);
+ return bean;
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
throw new IllegalArgumentException("错误的列定义");
}
- private void writeLine(OutputStream output, String delimiter, Object... columns) throws IOException {
+ private void writeLine(OutputStream output, Object... columns) throws IOException {
for (Object item : columns) {
output.write(item.toString().getBytes(StandardCharsets.UTF_8));
- output.write(delimiter.getBytes());
+ output.write(Constant.CHKFILE_DELIMITER.getBytes(StandardCharsets.UTF_8));
}
output.write("\n".getBytes());
}
throw new IllegalArgumentException("数据文件内容为空");
}
- CheckFileHeader fileHeader = populate(chkFileHeaderColumnList,
+ CheckFileHeader fileHeader = populate(CheckFileHeader.chkFileHeaderColumnList,
header.split(chkFileDelimiter), CheckFileHeader.class);
CheckFileLine record = new CheckFileLine();
- writeLine(output, ",", "refno", "agentrefno", "agentdate", "flag", "payerid",
- "payeeid", "amount", "summary");
+ writeLine(output, Constant.COL_REFNO, Constant.COL_AGENT_REFNO,
+ Constant.COL_AGENT_DATE, Constant.COL_FLAG, Constant.COL_PAYERID,
+ Constant.COL_PAYEEID, Constant.COL_STATUS,
+ Constant.COL_AMOUNT, Constant.COL_SUMMARY);
while (true) {
String line = reader.readLine();
if (line == null) {
String flag;
if (FLAG_WITHHOLD.equals(record.getFlag())) {
amount = -record.getAmount();
- flag = "pay";
+ flag = Constant.FLAG_PAY;
fileHeader.setPayCount(fileHeader.getPayCount() - 1);
fileHeader.setPayAmount(fileHeader.getPayAmount() - record.getAmount());
} else if (FLAG_REFUND.equals(record.getFlag())) {
amount = +record.getAmount();
- flag = "refund";
+ flag = Constant.FLAG_REFUND;
fileHeader.setRefundCount(fileHeader.getRefundCount() - 1);
fileHeader.setRefundAmount(fileHeader.getRefundAmount() - record.getAmount());
} else {
}
fileHeader.setTotalCount(fileHeader.getTotalCount() - 1);
fileHeader.setTotalAmount(fileHeader.getTotalAmount() - record.getAmount());
- writeLine(output, ",", record.getRefno(),
- record.getAgentrefno(), record.getAgentdate(),
- flag, record.getPayerid(), record.getPayeeid(),
+ writeLine(output, record.getRefno(), record.getAgentrefno(), record.getAgentdate(),
+ flag, record.getPayerid(), record.getPayeeid(), Constant.STATUS_SUCCESS,
amount, record.getSummary());
}
if (!fileHeader.isZero()) {
response.sendError(HttpStatus.SERVICE_UNAVAILABLE.value(), e.getMessage());
}
}
+
+
+ /**
+ * 第一行:总笔数|总金额|代扣总笔数|代扣总金额|退款总笔数|退款总金额|
+ */
+ private static class CheckFileHeader {
+ static final String[] chkFileHeaderColumnList = new String[]{"totalCount", "totalAmount", "payCount",
+ "payAmount", "refundCount", "refundAmount"};
+
+ private int totalCount;
+ private int totalAmount;
+ private int payCount;
+ private int payAmount;
+ private int refundCount;
+ private int refundAmount;
+
+ int getTotalCount() {
+ return totalCount;
+ }
+
+ void setTotalCount(int totalCount) {
+ this.totalCount = totalCount;
+ }
+
+ int getTotalAmount() {
+ return totalAmount;
+ }
+
+ void setTotalAmount(int totalAmount) {
+ this.totalAmount = totalAmount;
+ }
+
+ int getPayCount() {
+ return payCount;
+ }
+
+ void setPayCount(int payCount) {
+ this.payCount = payCount;
+ }
+
+ int getPayAmount() {
+ return payAmount;
+ }
+
+ void setPayAmount(int payAmount) {
+ this.payAmount = payAmount;
+ }
+
+ int getRefundCount() {
+ return refundCount;
+ }
+
+ void setRefundCount(int refundCount) {
+ this.refundCount = refundCount;
+ }
+
+ int getRefundAmount() {
+ return refundAmount;
+ }
+
+ void setRefundAmount(int refundAmount) {
+ this.refundAmount = refundAmount;
+ }
+
+ boolean isZero() {
+ return (totalAmount == 0 && totalCount == 0
+ && payAmount == 0 && payCount == 0 && refundAmount == 0 && refundCount == 0);
+ }
+ }
}