package com.szwl.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.netflix.discovery.util.StringUtil;
import com.szwl.constant.ResponseCodesEnum;
import com.szwl.model.bo.R;
import com.szwl.model.bo.ResponseModel;
import com.szwl.model.entity.*;
import com.szwl.service.*;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
/**
*
* 用户收款信息表变动申请表 前端控制器
*
*
* @author wuhs
* @since 2022-04-29
*/
@RestController
@RequestMapping("/tJoinpayMchCheck")
public class TJoinpayMchCheckController {
@Autowired
TJoinpayMchService tJoinpayMchService;
@Autowired
TShandeMchCheckService tShandeMchCheckService;
@Autowired
TJoinpayMchCheckService tJoinpayMchCheckService;
@Autowired
TShandeMchService tShandeMchService;
@Autowired
THuifuMchCheckService tHuifuMchCheckService;
@Autowired
TAdminService adminService;
@ApiOperation(value = "平台查找审核信息列表")
@GetMapping("/pageMch")
public ResponseModel> pageMch(String adminId, String username, String type, long current, long size) {
if (StringUtils.isEmpty(type) || StringUtils.isEmpty(adminId)) {
return R.fail(ResponseCodesEnum.A0100);
}
TAdmin admin = adminService.getById(adminId);
if (type.equals("0")) {
//汇聚的审核信息
LambdaQueryWrapper query = Wrappers.lambdaQuery();
if (admin.getType() > 1) {
query.eq(TJoinpayMchCheck::getAdminId, admin.getId());
}
if (StringUtils.isNotEmpty(username)) {
LambdaQueryWrapper query1 = Wrappers.lambdaQuery();
query1.eq(TAdmin::getUsername, username);
List list1 = adminService.list(query1);
if (list1.size() > 0) {
query.eq(TJoinpayMchCheck::getAdminId, list1.get(0).getId());
}
}
if (admin.getId() == 2738) {
LambdaQueryWrapper adminQuery = Wrappers.lambdaQuery();
adminQuery.isNull(TAdmin::getCompanyType).or()
.eq(TAdmin::getCompanyType, "0");
List adminIds = adminService.list(adminQuery).stream()
.map(TAdmin::getId).collect(Collectors.toList());
query.in(TJoinpayMchCheck::getAdminId, adminIds);
}
// 七云平台管理员
if (admin.getId() == 2739) {
LambdaQueryWrapper adminQuery = Wrappers.lambdaQuery();
adminQuery.eq(TAdmin::getCompanyType, "1");
List adminIds = adminService.list(adminQuery).stream()
.map(TAdmin::getId).collect(Collectors.toList());
query.in(TJoinpayMchCheck::getAdminId, adminIds);
}
query.orderByDesc(TJoinpayMchCheck::getCreateDate);
query.eq(TJoinpayMchCheck::getType, "0");
Page page = new Page<>(current, size, true);
IPage iPage = tJoinpayMchCheckService.page(page, query);
return R.ok(iPage);
}
if (type.equals("1")) {
//杉德的审核信息
LambdaQueryWrapper query = Wrappers.lambdaQuery();
if (admin.getType() > 1) {
query.eq(THuifuMchCheck::getAdminId, admin.getId());
}
if (StringUtils.isNotEmpty(username)) {
LambdaQueryWrapper query1 = Wrappers.lambdaQuery();
query1.eq(TAdmin::getUsername, username);
List list1 = adminService.list(query1);
if (list1.size() > 0) {
query.eq(THuifuMchCheck::getAdminId, list1.get(0).getId());
}
}
if (admin.getId() == 2738) {
LambdaQueryWrapper adminQuery = Wrappers.lambdaQuery();
adminQuery.isNull(TAdmin::getCompanyType).or()
.eq(TAdmin::getCompanyType, "0");
List adminIds = adminService.list(adminQuery).stream()
.map(TAdmin::getId).collect(Collectors.toList());
query.in(THuifuMchCheck::getAdminId, adminIds);
}
// 七云平台管理员
if (admin.getId() == 2739) {
LambdaQueryWrapper adminQuery = Wrappers.lambdaQuery();
adminQuery.eq(TAdmin::getCompanyType, "1");
List adminIds = adminService.list(adminQuery).stream()
.map(TAdmin::getId).collect(Collectors.toList());
query.in(THuifuMchCheck::getAdminId, adminIds);
}
query.orderByDesc(THuifuMchCheck::getCreateDate);
// query.eq(THuifuMchCheck::getStatus,"1").or().eq(THuifuMchCheck::getStatus,"4");
Page page = new Page<>(current, size, true);
IPage iPage = tHuifuMchCheckService.page(page, query);
return R.ok(iPage);
}
return R.ok();
}
@ApiOperation(value = "商家查找汇聚收款账户在审核信息")
@PostMapping("/getOne")
public ResponseModel> findById(Long id, String username) {
TAdmin admin = adminService.getById(id);
if (!admin.getUsername().equals(username)) {
return R.fail("username不符合!");
}
LambdaQueryWrapper query = Wrappers.lambdaQuery();
query.eq(TJoinpayMchCheck::getAdminId, id);
query.eq(TJoinpayMchCheck::getType, "0");
List list = tJoinpayMchCheckService.list(query);
if (list.size() > 0) {
return R.ok(list.get(list.size() - 1));
} else {
return R.fail("没有审核信息");
}
}
@GetMapping("/selectOne")
public ResponseModel> selectOne(Long id, String type) {
if (StringUtils.isNotEmpty(type)) {
if (type.equals("0")) {
//汇聚
TJoinpayMchCheck joinpayMchCheck = tJoinpayMchCheckService.getById(id);
return R.ok(joinpayMchCheck);
}
if (type.equals("1")) {
//汇付
THuifuMchCheck huifuMchCheck = tHuifuMchCheckService.getById(id);
return R.ok(huifuMchCheck);
}
}
return R.ok();
}
@ApiOperation(value = "撤销申请")
@GetMapping("/update")
public ResponseModel> update(Long id) {
LambdaQueryWrapper query = Wrappers.lambdaQuery();
query.eq(TJoinpayMchCheck::getId, id);
List list = tJoinpayMchCheckService.list(query);
if (list.size() > 0) {
TJoinpayMchCheck tJoinpayMchCheck = list.get(0);
tJoinpayMchCheck.setType("2");
tJoinpayMchCheck.setModifyDate(new Date());
tJoinpayMchCheckService.updateById(tJoinpayMchCheck);
return R.ok();
} else {
return R.fail("撤销失败");
}
}
@ApiOperation(value = "平台查找汇聚收款账户在审核信息")
@PostMapping("/getList")
public ResponseModel> getList(String username, String type) {
LambdaQueryWrapper query = Wrappers.lambdaQuery();
if (StringUtils.isNotEmpty(username)) {
LambdaQueryWrapper query1 = Wrappers.lambdaQuery();
query1.eq(TAdmin::getUsername, username);
List list1 = adminService.list(query1);
if (list1.size() > 0) {
query.eq(TJoinpayMchCheck::getAdminId, list1.get(0).getId());
}
}
if (StringUtils.isNotEmpty(type)) {
query.eq(TJoinpayMchCheck::getType, type);
}
List list = tJoinpayMchCheckService.list(query);
if (list.size() > 0) {
return R.ok(list);
} else {
return R.fail("没有审核信息");
}
}
@ApiOperation(value = "平台审核是否通过")
@GetMapping("/shenhe")
public ResponseModel> shenhe(Long id, String type, String status) {
if (type.equals("0")) {
//汇聚
if (status.equals("1")) {
//通过
TJoinpayMchCheck joinpayMchCheck = tJoinpayMchCheckService.getById(id);
joinpayMchCheck.setType("1");
LambdaQueryWrapper query1 = Wrappers.lambdaQuery();
query1.eq(TJoinpayMch::getAdminId, joinpayMchCheck.getAdminId());
List list1 = tJoinpayMchService.list(query1);
if (list1.size() > 0) {
TJoinpayMch mch = list1.get(0);
mch.setModifyDate(new Date());
mch.setAltMerchantType(joinpayMchCheck.getAltMerchantType());
mch.setBusiContactMobileNo(joinpayMchCheck.getBusiContactMobileNo());
mch.setBusiContactName(joinpayMchCheck.getBusiContactName());
mch.setPhoneNo(joinpayMchCheck.getPhoneNo());
mch.setLegalPerson(joinpayMchCheck.getLegalPerson());
mch.setIdCardNo(joinpayMchCheck.getIdCardNo());
mch.setLicenseNo(joinpayMchCheck.getLicenseNo());
mch.setAltMerchantType(joinpayMchCheck.getAltMerchantType());
mch.setBankAccountName(joinpayMchCheck.getBankAccountName());
mch.setBankAccountNo(joinpayMchCheck.getBankAccountNo());
mch.setBankChannelNo(joinpayMchCheck.getBankChannelNo());
mch.setSettMode(joinpayMchCheck.getSettMode());
mch.setRiskDay(joinpayMchCheck.getRiskDay());
mch.setStep("0");
//修改的数据发送到汇聚
String result = tJoinpayMchService.updateMch(mch);
if (result.equals("ok")) {
tJoinpayMchService.updateById(mch);
joinpayMchCheck.setModifyDate(new Date());
tJoinpayMchCheckService.updateById(joinpayMchCheck);
} else {
return R.fail(result);
}
}
} else {
//拒绝
TJoinpayMchCheck tJoinpayMchCheck = tJoinpayMchCheckService.getById(id);
tJoinpayMchCheck.setModifyDate(new Date());
tJoinpayMchCheck.setType("3");
tJoinpayMchCheckService.updateById(tJoinpayMchCheck);
}
}
if (type.equals("1")) {
//杉德
if (status.equals("1")) {
//通过
TShandeMchCheck shandeMchCheck = tShandeMchCheckService.getById(id);
LambdaQueryWrapper query = Wrappers.lambdaQuery();
query.eq(TShandeMch::getAdminId, shandeMchCheck.getAdminId());
List list = tShandeMchService.list(query);
if (list.size() > 0) {
TShandeMch mch = list.get(0);
mch.setModifyDate(new Date());
mch.setBankName(shandeMchCheck.getBankName());
mch.setType(shandeMchCheck.getType());
mch.setBankNo(shandeMchCheck.getBankNo());
//企业
if (shandeMchCheck.getType().equals("0")) {
mch.setBankChannelNo(shandeMchCheck.getBankChannelNo());
mch.setBankChannelName(shandeMchCheck.getBankChannelName());
}
//个人
if (shandeMchCheck.getType().equals("1")) {
mch.setBankChannelNo(null);
mch.setBankChannelName(null);
}
tShandeMchService.updateById(mch);
shandeMchCheck.setCheckType("1");
shandeMchCheck.setModifyDate(new Date());
tShandeMchCheckService.updateById(shandeMchCheck);
}
} else {
//拒绝
TShandeMchCheck tShandeMchCheck = tShandeMchCheckService.getById(id);
tShandeMchCheck.setModifyDate(new Date());
tShandeMchCheck.setCheckType("3");
tShandeMchCheckService.updateById(tShandeMchCheck);
}
}
return R.ok();
}
}