SpringBoot售卖物品操作核对数据库信息,并实现增删改查
程序员文章站
2022-01-20 23:15:07
...
问题描述:
这里是实现了对卡卷的发售,并且判断数据库表中是否存在该代理,该代理是否已经拥有该类卡卷。
如果有则对数据进行修改,如果没有该类卡,那么加入一条该代理的该类卡卷的新数据。
如果没有该代理,则加入新的代理信息和该类卡卷信息,形成一条新数据。
@PostMapping("sale")
@ResponseBody
public AjaxResult sale(Ticket ticket) {
// status=3, statusName=售出, holder=4, holderName=代理ID:4)
System.out.println("---->" + ticket.toString());
if (ticket.getStatus() == Ticket.SALE) {
System.out.println("持卡人id----》" + ticket.getHolder());
//查卡卷类型ID
Integer ticketTypeId = ticketService.selectByIdReturnTicket(ticket.getId());
//查卡卷信息
Ticket ticket1 = ticketService.selectByIdReturnOne(ticket.getId());
//查看此代理 是否在 代理持卡表中
List<AgentTicket> agentTickets = agentTicketService.selectByAgentIdReList(ticket.getHolder());
//list不空的话-
if (!agentTickets.isEmpty()) {
Iterator<AgentTicket> iterator = agentTickets.iterator();
//遍历器遍历
while (iterator.hasNext()) {
AgentTicket agentTicket = iterator.next();
if (ticketTypeId == agentTicket.getTicketType()) {
agentTicket.setTicketNum(agentTicket.getTicketNum() + 1);
boolean flag2 = agentTicketService.updateById(agentTicket);
return toAjax(flag2);
} else {
continue;
}
}
}
//list空
else {
AgentTicket agentTicket = new AgentTicket();
//获得 这个代理的信息
Agent agent = agentService.selectByPrimaryKey(ticket.getHolder());
agentTicket.setAgentName(agent.getAgentName());
long id = agent.getId();
Integer agentId = (int) id;
agentTicket.setAgentId(agentId);
agentTicket.setTicketType(ticketTypeId);
agentTicket.setTicketNum(1);
agentTicket.setTicketName(ticket1.getTicketName());
agentTicket.setIncome(0);
boolean flag2 = agentTicketService.save(agentTicket);
return toAjax(flag2);
}
}
else{
return toAjax(false);
}
return toAjax(false);
}
大概逻辑是这样,但是里边涉及的类太多,没办法都发出来,大家自行理解,改写即可。
一起进步加油!!!!!
上一篇: 通过scrapy实现简单爬虫
下一篇: nginx配置那些事