/**
|
# __----~~~~~~~~~~~------___
|
# . . ~~//====...... __--~ ~~
|
# -. \_|// |||\\ ~~~~~~::::... /~
|
# ___-==_ _-~o~ \/ ||| \\ _/~~-
|
# __---~~~.==~||\=_ -_--~/_-~|- |\\ \\ _/~
|
# _-~~ .=~ | \\-_ '-~7 /- / || \ /
|
# .~ .~ | \\ -_ / /- / || \ /
|
# / ____ / | \\ ~-_/ /|- _/ .|| \ /
|
# |~~ ~~|--~~~~--_ \ ~==-/ | \~--===~~ .\
|
# ' ~-| /| |-~\~~ __--~~
|
# |-~~-_/ | | ~\_ _-~ /\
|
# / \ \__ \/~ \__
|
# _--~ _/ | .-~~____--~-/ ~~==.
|
# ((->/~ '.|||' -_| ~~-/ , . _||
|
# -_ ~\ ~~---l__i__i__i--~~_/
|
# _-~-__ ~) \--______________--~~
|
# //.-~~~-~_--~- |-------~~~~~~~~
|
# //.-~~~--\
|
# 神兽保佑
|
# 永无BUG!
|
*/
|
package com.lunhan.water.service;
|
|
import com.lunhan.water.common.*;
|
import com.lunhan.water.common.enums.*;
|
import com.lunhan.water.common.model.Tuple;
|
import com.lunhan.water.common.security.MD5Util;
|
import com.lunhan.water.common.util.*;
|
import com.lunhan.water.entity.enums.EPayNotifyState;
|
import com.lunhan.water.entity.enums.EPaymentChannel;
|
import org.apache.commons.lang3.BooleanUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import java.util.*;
|
import java.util.stream.Collectors;
|
import com.lunhan.water.repository.impl.ThirdNotifyMapperImpl;
|
import com.lunhan.water.repository.po.ThirdNotifyPO;
|
import com.lunhan.water.entity.request.thirdnotify.ReqCreateThirdNotify;
|
import com.lunhan.water.entity.request.thirdnotify.ReqModifyThirdNotify;
|
import com.lunhan.water.entity.search.SearchThirdNotify;
|
import com.lunhan.water.repository.vo.ThirdNotifyVO;
|
import com.lunhan.water.service.convert.ThirdNotifyConvert;
|
|
/**
|
* 第三方支付通知记录
|
* @author lin.liu
|
*/
|
@Service
|
public class ThirdNotifyService extends BaseService {
|
@Autowired
|
private ThirdNotifyMapperImpl mapper;
|
|
public ExecutedResult<Long> create(ReqCreateThirdNotify request) {
|
// 转换po
|
ThirdNotifyPO item = ThirdNotifyConvert.INSTANCE.toCreate(request);
|
// 设置状态
|
//item.setStatus(EState.NORMAL.getValue());
|
// 设置记录创建时间
|
item.setCreateTime(LocalDateTimeUtil.nowTimeStamp());
|
// 是否删除(逻辑删除)初始值
|
item.setIsDelete(EYesOrNo.NO.getValue());
|
|
int rowCount = mapper.insert(item);
|
if (rowCount != 1) {
|
return ExecutedResult.failed("创建[第三方支付通知记录]失败。");
|
}
|
return ExecutedResult.success(item.getId());
|
}
|
|
public ExecutedResult<String> modify(ReqModifyThirdNotify request) {
|
// 验证记录是否存在
|
ExecutedResult<ThirdNotifyPO> checkExists = this.check4Id(request.getId());
|
if (checkExists.isFailed()) {
|
return ExecutedResult.failed(checkExists.getMsg());
|
}
|
// 转换po
|
ThirdNotifyPO item = ThirdNotifyConvert.INSTANCE.toModify(request);
|
|
int rowCount = mapper.updateById(item);
|
if (rowCount != 1) {
|
return ExecutedResult.failed("编辑[第三方支付通知记录]失败。");
|
}
|
return ExecutedResult.success();
|
}
|
|
public ExecutedResult<ThirdNotifyVO> get(Long id) {
|
ThirdNotifyVO result = new ThirdNotifyVO();
|
|
ThirdNotifyPO find = mapper.get(id);
|
if (null != find) {
|
// 转换vo
|
result = ThirdNotifyConvert.INSTANCE.toVo(find);
|
}
|
return ExecutedResult.success(result);
|
}
|
|
// public ExecutedResult<String> stop(Long id) {
|
// // 验证记录是否存在
|
// ExecutedResult<ThirdNotifyPO> checkExists = this.check4Id(id);
|
// if (checkExists.isFailed()) {
|
// return ExecutedResult.failed(checkExists.getMsg());
|
// }
|
// ThirdNotifyPO item = new ThirdNotifyPO();
|
// item.setId(id);
|
// item.setStatus(EState.DISABLED.getValue());
|
//
|
// int rowCount = mapper.updateById(item);
|
// if (rowCount != 1) {
|
// return ExecutedResult.failed("停用[第三方支付通知记录]失败。");
|
// }
|
// return ExecutedResult.success();
|
// }
|
//
|
// public ExecutedResult<String> enable(Long id) {
|
// // 验证记录是否存在
|
// ExecutedResult<ThirdNotifyPO> checkExists = this.check4Id(id);
|
// if (checkExists.isFailed()) {
|
// return ExecutedResult.failed(checkExists.getMsg());
|
// }
|
// ThirdNotifyPO item = new ThirdNotifyPO();
|
// item.setId(id);
|
// item.setStatus(EState.NORMAL.getValue());
|
//
|
// int rowCount = mapper.updateById(item);
|
// if (rowCount != 1) {
|
// return ExecutedResult.failed("启用[第三方支付通知记录]失败。");
|
// }
|
// return ExecutedResult.success();
|
// }
|
//
|
// public ExecutedResult<String> setSort(ReqSetSort request) {
|
// // 验证记录是否存在
|
// ExecutedResult<ThirdNotifyPO> checkExists = this.check4Id(request.getId());
|
// if (checkExists.isFailed()) {
|
// return ExecutedResult.failed(checkExists.getMsg());
|
// }
|
// ThirdNotifyPO item = new ThirdNotifyPO();
|
// item.setId(request.getId());
|
// item.setSort(request.getSort());
|
//
|
// int rowCount = mapper.updateById(item);
|
// if (rowCount != 1) {
|
// return ExecutedResult.failed("设置[第三方支付通知记录]排序值失败。");
|
// }
|
// return ExecutedResult.success();
|
// }
|
//
|
// public ExecutedResult<String> listSetSort(ReqListSetSort request) {
|
// // id列表
|
// List<Long> listId = request.getList().stream().map(ReqSetSort::getId).collect(Collectors.toList());
|
// // 验证记录是否存在
|
// ExecutedResult<List<ThirdNotifyPO>> checkExists = this.check4Id(listId);
|
// if (checkExists.isFailed()) {
|
// return ExecutedResult.failed(checkExists.getMsg());
|
// }
|
//
|
// List<ThirdNotifyPO> listUpdate = request.getList().stream()
|
// .map(c -> {
|
// ThirdNotifyPO item = new ThirdNotifyPO();
|
// item.setId(c.getId());
|
// item.setSort(c.getSort());
|
// return item;
|
// })
|
// .collect(Collectors.toList());
|
// Boolean result = mapper.modifyList(listUpdate);
|
// if (result) {
|
// return ExecutedResult.success();
|
// }
|
// return ExecutedResult.failed("[第三方支付通知记录]设置排序值失败");
|
// }
|
//
|
// public ExecutedResult<String> remove(Long id) {
|
// Boolean result = mapper.deleteLogic(id);
|
// if (BooleanUtils.isFalse(result)) {
|
// return ExecutedResult.failed("删除[第三方支付通知记录]失败。");
|
// }
|
// return ExecutedResult.success();
|
// }
|
//
|
// public ExecutedResult<String> removeList(List<Long> ids) {
|
// Boolean result = mapper.deleteLogic(ids);
|
// if (BooleanUtils.isFalse(result)) {
|
// return ExecutedResult.failed("删除[第三方支付通知记录]失败。");
|
// }
|
// return ExecutedResult.success();
|
// }
|
public ExecutedResult<Long> saveWinXinPayNotify(EPaymentChannel channel, String business, String body, Integer businessType) {
|
String md5 = MD5Util.encrypt(body);
|
Long now = LocalDateTimeUtil.nowTimeStamp();
|
|
ThirdNotifyPO find = mapper.get4Md5(md5);
|
if (Objects.nonNull(find) && md5.equals(find.getMd5())) {
|
return ExecutedResult.failed("重复通知!", ConstantFactory.MCODE_TOKENERROR);
|
}
|
ThirdNotifyPO item = new ThirdNotifyPO();
|
item.setBusiness(business);
|
item.setBusinessType(businessType);
|
item.setBusinessCode("");
|
item.setPaymentChannel(channel.getValue());
|
item.setChannelName(channel.getDesc());
|
item.setMd5(md5);
|
item.setBody(body);
|
item.setComment("");
|
item.setStatus(EPayNotifyState.WAITING.getValue());
|
item.setCreateTime(now);
|
|
int saveNotify = mapper.insert(item);
|
if (saveNotify<1) {
|
return ExecutedResult.failed("保存报文失败!");
|
}
|
return ExecutedResult.success(item.getId());
|
}
|
public void updateBusinessCode(Long notifyId, String businessCode) {
|
try {
|
ThirdNotifyPO upd = new ThirdNotifyPO();
|
upd.setId(notifyId);
|
upd.setBusinessCode(businessCode);
|
|
mapper.updateById(upd);
|
} catch (Exception e) {
|
LoggerUtil.get(ELogger.SYS_ERROR).error("ThirdNotifyService_updateBusinessCode", e);
|
}
|
}
|
public ExecutedResult<List<ThirdNotifyVO>> getList(List<Long> listId) {
|
List<ThirdNotifyVO> result = new ArrayList<>();
|
|
List<ThirdNotifyPO> list = mapper.getList(listId);
|
if (ListUtil.isNotNullOrEmpty(list)) {
|
// 转换vo
|
result = ThirdNotifyConvert.INSTANCE.toVo(list);
|
}
|
return ExecutedResult.success(result);
|
}
|
|
public ExecutedResult<PagerResult<ThirdNotifyVO>> search(SearchThirdNotify search) {
|
// 处理创建时间范围-查询参数
|
Tuple<String, String> createTimeRange = ParameterUtil.getTimeRange(search.getCreateTimeRange());
|
if (StringUtil.isNotNullOrEmpty(createTimeRange.getItem1())) {
|
search.setCreateTimeStart(LocalDateTimeUtil.getTimeStamp(createTimeRange.getItem1()).getTime());
|
}
|
if (StringUtil.isNotNullOrEmpty(createTimeRange.getItem2())) {
|
search.setCreateTimeEnd(LocalDateTimeUtil.getTimeStamp(createTimeRange.getItem2()).getTime());
|
}
|
|
PagerResult<ThirdNotifyPO> pageList = mapper.search(search);
|
List<ThirdNotifyVO> listVo = new ArrayList<>();
|
List<ThirdNotifyPO> list = pageList.getList();
|
if (ListUtil.isNotNullOrEmpty(list)) {
|
pageList.setLastId(list.get(list.size() - 1).getId());
|
// 转换vo
|
listVo = ThirdNotifyConvert.INSTANCE.toVo(list);
|
}
|
PagerResult<ThirdNotifyVO> result = new PagerResult<>(pageList.getLimit(), pageList.getPage(), pageList.getTotal(), listVo);
|
result.setLastId(pageList.getLastId());
|
return ExecutedResult.success(result);
|
}
|
|
protected ExecutedResult<ThirdNotifyPO> check4Id(Long id) {
|
ThirdNotifyPO exists = mapper.get(id);
|
if (Objects.isNull(exists)) {
|
return ExecutedResult.failed("[第三方支付通知记录]不存在:" + id);
|
}
|
return ExecutedResult.success(exists);
|
}
|
protected ExecutedResult<List<ThirdNotifyPO>> check4Id(List<Long> listId) {
|
// 从数据库查找第三方支付通知记录
|
List<ThirdNotifyPO> list = mapper.getList(listId);
|
if (ListUtil.isNullOrEmpty(list)) {
|
return ExecutedResult.failed("[第三方支付通知记录]不存在." + listId);
|
}
|
// 数据库找到的id列表
|
List<Long> listIdFind = list.stream().map(ThirdNotifyPO::getId).collect(Collectors.toList());
|
// 数量不一致
|
if (listId.size() != listIdFind.size()) {
|
// 筛选数据库不存在的第三方支付通知记录
|
List<Long> listIdNotFound = listId.stream().filter(c -> !listIdFind.contains(c)).collect(Collectors.toList());
|
if (ListUtil.isNullOrEmpty(list)) {
|
return ExecutedResult.failed("[第三方支付通知记录]不存在." + listIdNotFound);
|
}
|
}
|
return ExecutedResult.success(list);
|
}}
|