4 changed files with 509 additions and 0 deletions
@ -0,0 +1,207 @@
|
||||
package demo.weihuijia.controller; |
||||
|
||||
|
||||
import demo.weihuijia.model.AccountTab; |
||||
import demo.weihuijia.model.RecordTable; |
||||
import demo.weihuijia.model.WithdrawMoneyDTO; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.jdbc.core.JdbcTemplate; |
||||
import org.springframework.util.CollectionUtils; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import java.time.LocalDateTime; |
||||
import java.time.format.DateTimeFormatter; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @author Administrator |
||||
*/ |
||||
@RestController |
||||
@RequestMapping("/weihuijia") |
||||
public class AccountController { |
||||
|
||||
@Autowired |
||||
private JdbcTemplate jdbcTemplate; |
||||
|
||||
/** |
||||
* 生成银行卡号接口 |
||||
* |
||||
* @param organiNm 公司 |
||||
* @return |
||||
*/ |
||||
@GetMapping("/generateBankNumber") |
||||
public String generateBankNumber(String organiNm) { |
||||
// 根据机构名称 查询机构号
|
||||
String agencyNumber = getOrganizationNoByOrganizationName(organiNm); |
||||
|
||||
int number = 1; |
||||
// 向编号表查询 编号名noName是否已经存在
|
||||
String sql_qry = String.format("select * from ordinal"); |
||||
List<Map<String, Object>> list = jdbcTemplate.queryForList(sql_qry); |
||||
if (!CollectionUtils.isEmpty(list)) { |
||||
number = list.size() + 1; |
||||
} |
||||
String formattedString = String.format("%04d", number); |
||||
String count = "625772024" + agencyNumber + formattedString; |
||||
|
||||
// 将count 存入数据库中
|
||||
|
||||
// 将数据添加到数据库
|
||||
String sql = String.format( |
||||
"INSERT INTO newbank.ordinal (ordinalNo) " + |
||||
"VALUES ('%s');", |
||||
count |
||||
); |
||||
jdbcTemplate.update(sql); |
||||
|
||||
return count; |
||||
} |
||||
|
||||
/** |
||||
* 开户接口 |
||||
* |
||||
* @return |
||||
*/ |
||||
@PostMapping("/openAccount") |
||||
public Boolean openAccount(@RequestBody AccountTab account) { |
||||
// 开户
|
||||
final String INSERT_SQL = "INSERT INTO account_tab (" + |
||||
"cardNo, customNo, IDtype, IDNo, organiNm, accountDa, accstaff, balance, acctype, depositTy, status, password) " + |
||||
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; |
||||
|
||||
jdbcTemplate.update(INSERT_SQL, |
||||
account.getCardNo(), |
||||
account.getCustomNo(), |
||||
account.getIdType(), |
||||
account.getIdNo(), |
||||
account.getOrganiNm(), |
||||
account.getAccountDa(), |
||||
account.getAccstaff(), |
||||
account.getBalance(), |
||||
account.getAcctype(), |
||||
account.getDepositTy(), |
||||
account.getStatus(), |
||||
account.getPassword() |
||||
); |
||||
|
||||
// 生成流水
|
||||
|
||||
// 根据机构名称 查询机构号
|
||||
String agencyNumber = getOrganizationNoByOrganizationName(account.getOrganiNm()); |
||||
RecordTable recordTable = new RecordTable(); |
||||
recordTable.setCardNo(account.getCardNo()); |
||||
recordTable.setMoney(account.getBalance()); |
||||
recordTable.setServiceTy("1"); |
||||
recordTable.setBalance(account.getBalance()); |
||||
recordTable.setRecordNo(getRecordNo(account.getAccstaff(), agencyNumber)); |
||||
saveRecordTable(recordTable); |
||||
|
||||
return true; |
||||
} |
||||
|
||||
/** |
||||
* 查询卡信息 |
||||
* |
||||
* @param cardNo 卡号 |
||||
* @return |
||||
*/ |
||||
@GetMapping("/getAccount") |
||||
public List<Map<String, Object>> getAccount(String cardNo) { |
||||
String sql = "select * from account_tab s where cardNo ='" + cardNo + "'"; |
||||
return jdbcTemplate.queryForList(sql); |
||||
} |
||||
|
||||
/** |
||||
* 验证账户密码 |
||||
* |
||||
* @param cardNo 卡号 |
||||
* @param password 密码 |
||||
* @return |
||||
*/ |
||||
@GetMapping("/verifyAccountPassword") |
||||
public Boolean verifyAccountPassword(String cardNo, String password) { |
||||
String sql = "select * from account_tab s where cardNo ='" + cardNo + "'" + "and password='" + password + "'"; |
||||
return !CollectionUtils.isEmpty(jdbcTemplate.queryForList(sql)); |
||||
} |
||||
|
||||
/** |
||||
* 存取钱接口 |
||||
* |
||||
* @return |
||||
*/ |
||||
@PostMapping("/withdrawMoney") |
||||
public Boolean withdrawMoney(@RequestBody WithdrawMoneyDTO withdrawMoneyDTO) { |
||||
String sql = "select * from account_tab s where cardNo ='" + withdrawMoneyDTO.getCardNo() + "'"; |
||||
if (CollectionUtils.isEmpty(jdbcTemplate.queryForList(sql))) { |
||||
return false; |
||||
} |
||||
List<Map<String, Object>> maps = jdbcTemplate.queryForList(sql); |
||||
double balance = Double.parseDouble(maps.get(0).get("balance").toString()); |
||||
// 存钱
|
||||
if (withdrawMoneyDTO.getServiceTy().equals("1")) { |
||||
balance = balance + withdrawMoneyDTO.getMoney(); |
||||
} |
||||
// 取钱
|
||||
else { |
||||
balance = balance - withdrawMoneyDTO.getMoney(); |
||||
} |
||||
// 更新账户信息
|
||||
String sql1 = "UPDATE account_tab SET balance = ? WHERE cardNo = ?"; |
||||
jdbcTemplate.update(sql1, balance, withdrawMoneyDTO.getCardNo()); |
||||
|
||||
// 产生流水记录
|
||||
RecordTable recordTable = new RecordTable(); |
||||
recordTable.setCardNo(withdrawMoneyDTO.getCardNo()); |
||||
recordTable.setMoney(withdrawMoneyDTO.getMoney()); |
||||
recordTable.setServiceTy(withdrawMoneyDTO.getServiceTy()); |
||||
recordTable.setBalance(balance); |
||||
recordTable.setRecordNo(getRecordNo(withdrawMoneyDTO.getStaffNo(), withdrawMoneyDTO.getOrganiNm())); |
||||
saveRecordTable(recordTable); |
||||
return true; |
||||
} |
||||
|
||||
/** |
||||
* 存入流水记录 |
||||
*/ |
||||
private void saveRecordTable(RecordTable recordTable) { |
||||
// 获取当前时间
|
||||
String formattedTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); |
||||
String sql = "INSERT INTO recordtable (date, cardNo, money, serviceTy, balance, recordNo) VALUES (?, ?, ?, ?, ?, ?)"; |
||||
// 执行插入操作
|
||||
jdbcTemplate.update(sql, formattedTime, recordTable.getCardNo(), recordTable.getMoney(), recordTable.getServiceTy(), recordTable.getBalance(), recordTable.getRecordNo()); |
||||
} |
||||
|
||||
/** |
||||
* 获取流水号 年月日+机构号+员工号+序号 20位 |
||||
* |
||||
* @param staffNo 开户员工 |
||||
* @param organiNm 开户机构 |
||||
* @return |
||||
*/ |
||||
private String getRecordNo(String staffNo, String organiNm) { |
||||
int number = 1; |
||||
String sql_qry = String.format("select * from recordtable"); |
||||
List<Map<String, Object>> list = jdbcTemplate.queryForList(sql_qry); |
||||
if (!CollectionUtils.isEmpty(list)) { |
||||
number = list.size() + 1; |
||||
} |
||||
// 序号
|
||||
String formattedString = String.format("%06d", number); |
||||
String formattedTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")); |
||||
return formattedTime + organiNm + staffNo + formattedString; |
||||
} |
||||
|
||||
/** |
||||
* 通过机构名称 查询机构号 |
||||
*/ |
||||
private String getOrganizationNoByOrganizationName(String organiNm) { |
||||
// 根据机构名称 查询机构号
|
||||
String sql1 = "select * from bank_organi where organiNm ='" + organiNm + "'"; |
||||
List<Map<String, Object>> list1 = jdbcTemplate.queryForList(sql1); |
||||
if (!CollectionUtils.isEmpty(list1)) { |
||||
return list1.get(0).get("organiNo").toString(); |
||||
} |
||||
return null; |
||||
} |
||||
} |
@ -0,0 +1,161 @@
|
||||
package demo.weihuijia.model; |
||||
|
||||
/** |
||||
* @author Administrator |
||||
* 账户表 |
||||
*/ |
||||
public class AccountTab { |
||||
|
||||
/** |
||||
* 账号(卡号) |
||||
*/ |
||||
private String cardNo; |
||||
|
||||
/** |
||||
* 客户号 |
||||
*/ |
||||
private String customNo; |
||||
|
||||
/** |
||||
* 证件类型 |
||||
*/ |
||||
private String idType; |
||||
/** |
||||
* 证件号码 |
||||
*/ |
||||
private String idNo; |
||||
/** |
||||
* 开户机构 |
||||
*/ |
||||
private String organiNm; |
||||
/** |
||||
* 开户日期 |
||||
*/ |
||||
private String accountDa; |
||||
|
||||
/** |
||||
* 开户员工(员工号) |
||||
*/ |
||||
private String accstaff; |
||||
|
||||
/** |
||||
* 余额 |
||||
*/ |
||||
private Double balance; |
||||
|
||||
/** |
||||
* 类型(1个人、2企业) |
||||
*/ |
||||
private String acctype; |
||||
|
||||
/** |
||||
* 存款类型 1存 2取 |
||||
*/ |
||||
private String depositTy; |
||||
|
||||
/** |
||||
* 账户状态 1 正常 2 销户 |
||||
*/ |
||||
private String status; |
||||
|
||||
/** |
||||
* 密码 |
||||
*/ |
||||
private String password; |
||||
|
||||
public String getCardNo() { |
||||
return cardNo; |
||||
} |
||||
|
||||
public void setCardNo(String cardNo) { |
||||
this.cardNo = cardNo; |
||||
} |
||||
|
||||
public String getCustomNo() { |
||||
return customNo; |
||||
} |
||||
|
||||
public void setCustomNo(String customNo) { |
||||
this.customNo = customNo; |
||||
} |
||||
|
||||
public String getIdType() { |
||||
return idType; |
||||
} |
||||
|
||||
public void setIdType(String idType) { |
||||
this.idType = idType; |
||||
} |
||||
|
||||
public String getIdNo() { |
||||
return idNo; |
||||
} |
||||
|
||||
public void setIdNo(String idNo) { |
||||
this.idNo = idNo; |
||||
} |
||||
|
||||
public String getOrganiNm() { |
||||
return organiNm; |
||||
} |
||||
|
||||
public void setOrganiNm(String organiNm) { |
||||
this.organiNm = organiNm; |
||||
} |
||||
|
||||
public String getAccountDa() { |
||||
return accountDa; |
||||
} |
||||
|
||||
public void setAccountDa(String accountDa) { |
||||
this.accountDa = accountDa; |
||||
} |
||||
|
||||
public String getAccstaff() { |
||||
return accstaff; |
||||
} |
||||
|
||||
public void setAccstaff(String accstaff) { |
||||
this.accstaff = accstaff; |
||||
} |
||||
|
||||
public Double getBalance() { |
||||
return balance; |
||||
} |
||||
|
||||
public void setBalance(Double balance) { |
||||
this.balance = balance; |
||||
} |
||||
|
||||
public String getAcctype() { |
||||
return acctype; |
||||
} |
||||
|
||||
public void setAcctype(String acctype) { |
||||
this.acctype = acctype; |
||||
} |
||||
|
||||
public String getDepositTy() { |
||||
return depositTy; |
||||
} |
||||
|
||||
public void setDepositTy(String depositTy) { |
||||
this.depositTy = depositTy; |
||||
} |
||||
|
||||
public String getStatus() { |
||||
return status; |
||||
} |
||||
|
||||
public void setStatus(String status) { |
||||
this.status = status; |
||||
} |
||||
|
||||
public String getPassword() { |
||||
return password; |
||||
} |
||||
|
||||
public void setPassword(String password) { |
||||
this.password = password; |
||||
} |
||||
} |
@ -0,0 +1,72 @@
|
||||
package demo.weihuijia.model; |
||||
|
||||
/** |
||||
* @author Administrator |
||||
*/ |
||||
public class RecordTable { |
||||
|
||||
/** |
||||
* 卡号 |
||||
*/ |
||||
private String cardNo; |
||||
|
||||
/** |
||||
* 金钱 |
||||
*/ |
||||
private Double money; |
||||
|
||||
/** |
||||
* 存取钱 1存钱 2取钱 |
||||
*/ |
||||
private String serviceTy; |
||||
|
||||
/** |
||||
* 金额 |
||||
*/ |
||||
private Double balance; |
||||
|
||||
/** |
||||
* 流水号 |
||||
*/ |
||||
private String recordNo; |
||||
|
||||
public String getCardNo() { |
||||
return cardNo; |
||||
} |
||||
|
||||
public void setCardNo(String cardNo) { |
||||
this.cardNo = cardNo; |
||||
} |
||||
|
||||
public String getServiceTy() { |
||||
return serviceTy; |
||||
} |
||||
|
||||
public void setServiceTy(String serviceTy) { |
||||
this.serviceTy = serviceTy; |
||||
} |
||||
|
||||
public Double getMoney() { |
||||
return money; |
||||
} |
||||
|
||||
public void setMoney(Double money) { |
||||
this.money = money; |
||||
} |
||||
|
||||
public Double getBalance() { |
||||
return balance; |
||||
} |
||||
|
||||
public void setBalance(Double balance) { |
||||
this.balance = balance; |
||||
} |
||||
|
||||
public String getRecordNo() { |
||||
return recordNo; |
||||
} |
||||
|
||||
public void setRecordNo(String recordNo) { |
||||
this.recordNo = recordNo; |
||||
} |
||||
} |
@ -0,0 +1,69 @@
|
||||
package demo.weihuijia.model; |
||||
|
||||
|
||||
/** |
||||
* @author Administrator |
||||
*/ |
||||
public class WithdrawMoneyDTO { |
||||
|
||||
/** |
||||
* 账号 |
||||
*/ |
||||
private String cardNo; |
||||
/** |
||||
* 金额 |
||||
*/ |
||||
private Double money; |
||||
/** |
||||
* 存取 1存 2取 |
||||
*/ |
||||
private String serviceTy; |
||||
/** |
||||
* 员工编号 |
||||
*/ |
||||
private String staffNo; |
||||
/** |
||||
* 机构号 |
||||
*/ |
||||
private String organiNm; |
||||
|
||||
public String getCardNo() { |
||||
return cardNo; |
||||
} |
||||
|
||||
public void setCardNo(String cardNo) { |
||||
this.cardNo = cardNo; |
||||
} |
||||
|
||||
public Double getMoney() { |
||||
return money; |
||||
} |
||||
|
||||
public void setMoney(Double money) { |
||||
this.money = money; |
||||
} |
||||
|
||||
public String getServiceTy() { |
||||
return serviceTy; |
||||
} |
||||
|
||||
public void setServiceTy(String serviceTy) { |
||||
this.serviceTy = serviceTy; |
||||
} |
||||
|
||||
public String getStaffNo() { |
||||
return staffNo; |
||||
} |
||||
|
||||
public void setStaffNo(String staffNo) { |
||||
this.staffNo = staffNo; |
||||
} |
||||
|
||||
public String getOrganiNm() { |
||||
return organiNm; |
||||
} |
||||
|
||||
public void setOrganiNm(String organiNm) { |
||||
this.organiNm = organiNm; |
||||
} |
||||
} |
Loading…
Reference in new issue