1 changed files with 0 additions and 207 deletions
@ -1,207 +0,0 @@
|
||||
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; |
||||
} |
||||
} |
Loading…
Reference in new issue