package com.smart.canteen.service.impl;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.smart.canteen.dto.CommonList;
import com.smart.canteen.dto.card.CardForm;
import com.smart.canteen.dto.card.CardSearch;
import com.smart.canteen.dto.card.DeductionForm;
import com.smart.canteen.dto.card.PatchCardForm;
import com.smart.canteen.dto.recharge.RechargeForm;
import com.smart.canteen.entity.Employee;
import com.smart.canteen.entity.IcCard;
import com.smart.canteen.entity.Machine;
import com.smart.canteen.entity.RechargeLog;
import com.smart.canteen.enums.*;
import com.smart.canteen.mapper.IcCardMapper;
import com.smart.canteen.service.*;
import com.smart.canteen.utils.EntityLogUtil;
import com.smart.canteen.vo.CardUserVo;
import com.smart.canteen.vo.CardVo;
import com.smart.canteen.vo.ResponseMsg;
import live.lumia.dto.Account;
import live.lumia.error.BaseException;
import live.lumia.utils.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import java.util.*;
/**
* <p>
* iC卡 服务实现类
* </p>
*
* @author lc
* @since 2020-03-03
*/
@Slf4j
@Transactional(rollbackFor = Exception.class, timeout = 2000)
@Service
public class IcCardServiceImpl extends ServiceImpl<IcCardMapper, IcCard> implements IIcCardService {
@Autowired
private IEmployeeRoleService iEmployeeRoleService;
@Autowired
private IRechargeLogService iRechargeLogService;
@Override
public Long addCard(CardForm form, Employee employee, Account create) {
ValidatorUtil.validator(form, CardForm.Insert.class);
IcCard card = getByCode(form.getNo());
if (card != null) {
throw new BaseException(CanteenExceptionEnum.CARD_NO_REPEAT);
}
card = ModelMapperUtils.strict(form, IcCard.class);
card.setStatus(CardStatusEnum.ENABLE);
card.setAccountStatus(CardAccountEnum.NORMAL);
card.setEmployeeId(employee.getId());
card.setEmployeeNo(employee.getNo());
card.setEmployeeName(employee.getName());
card.setCurrentBalance(ObjectUtil.getDouble(form.getOpenCardAmount()));
EntityLogUtil.addNormalUser(card, create);
boolean save = save(card);
if (!save) {
throw new BaseException(CanteenExceptionEnum.CREATE_FAIL);
}
if (ObjectUtil.getDouble(card.getOpenCardAmount()) > 0) {
RechargeForm form1 = new RechargeForm();
ArrayList<Long> objects = new ArrayList<>();
objects.add(card.getId());
form1.setCardIds(objects);
form1.setMoney(ObjectUtil.getDouble(card.getOpenCardAmount()));
form1.setRechargeType(RechargeTypeEnum.NORMAL.getValue());
form1.setDescription("开户金额");
recharge(form1, create);
}
return card.getId();
}
@Override
public CardUserVo getCardUser(Long cardId) {
if (ObjectUtil.getLong(cardId) < 1) {
return null;
}
CardUserVo vo = getBaseMapper().getByCardId(cardId);
vo.setRoleName(new HashSet<>(iEmployeeRoleService.getEmpRoleName(vo.getEmpId())));
return vo;
}
@Override
public IcCard getByCode(String no) {
return getOne(Wrappers.<IcCard>lambdaQuery().eq(IcCard::getNo, no), false);
}
@Override
public IcCard getById(Long id) {
return super.getById(id);
}
@Override
public void update(CardForm form, Employee employee, Account create) {
ValidatorUtil.validator(form, CardForm.Update.class);
IcCard card = getById(form.getId());
if (card == null) {
throw new BaseException(CanteenExceptionEnum.CARD_NO_EXIST);
}
BeanUtils.copyProperties(form, card, "id", "no");
card.setEmployeeName(employee.getName());
card.setEmployeeNo(employee.getNo());
boolean b = updateById(card);
if (!b) {
throw new BaseException(CanteenExceptionEnum.UPDATE_FAIL);
}
}
@Override
public CommonList<CardVo> listCard(CardSearch search) {
Page<CardVo> page = new Page<>(search.getPage(), search.getSize());
getBaseMapper().selectPageVo(page, search, false);
return new CommonList<>(page.hasNext(), page.getTotal(), page.getCurrent(), page.getRecords());
}
@Override
public CommonList<CardVo> listCardForRecharge(CardSearch search) {
Page<CardVo> page = new Page<>(search.getPage(), search.getSize());
getBaseMapper().selectPageVo(page, search, true);
return new CommonList<>(page.hasNext(), page.getTotal(), page.getCurrent(), page.getRecords());
}
@Override
public void recharge(RechargeForm form, Account account) {
ValidatorUtil.validator(form);
List<Long> cardIds = form.getCardIds();
Collection<IcCard> cards = listByIds(cardIds);
boolean b1 = cards.stream().anyMatch(x -> x.getStatus() != CardStatusEnum.ENABLE);
if (b1) {
throw new BaseException(CanteenExceptionEnum.CARD_TYPE_ERROR1);
}
List<RechargeLog> logs = new ArrayList<>();
cards.forEach(x -> {
RechargeLog rechargeLog = new RechargeLog();
double lastBalance = MathUtil.add(ObjectUtil.getDouble(x.getCurrentBalance()), ObjectUtil.getDouble(form.getMoney()));
x.setCurrentBalance(lastBalance);
rechargeLog.setMoney(form.getMoney());
rechargeLog.setCardId(x.getId());
rechargeLog.setCardNo(x.getNo());
rechargeLog.setType(RechargeTypeEnum.getByCode(form.getRechargeType()));
rechargeLog.setBalance(lastBalance);
rechargeLog.setEmployeeName(x.getEmployeeName());
rechargeLog.setEmployeeNo(x.getEmployeeNo());
rechargeLog.setDescription(form.getDescription());
EntityLogUtil.addNormalUser(rechargeLog, account);
logs.add(rechargeLog);
});
boolean b = updateBatchById(cards);
cardIds.clear();
cards.clear();
if (b) {
iRechargeLogService.addRechargeLogs(logs);
} else {
throw new BaseException(CanteenExceptionEnum.RECHARGE_FAIL);
}
}
@Autowired
private IOrderService iOrderService;
@Value("${card.timeout}")
private Long timeout;
@Override
public ResponseMsg deductions(String cardNo, Integer money, String machineNo) {
Long start = System.currentTimeMillis();
Machine machine = iMachineService.getByCode(machineNo);
if (machine == null) {
return new ResponseMsg(CmdCodeEnum.CON, Voices.WARN, cardNo, "机器未注册");
}
IcCard card = getOne(Wrappers.<IcCard>lambdaQuery()
.select(IcCard::getCurrentBalance, IcCard::getStatus, IcCard::getId, IcCard::getNo, IcCard::getEmployeeName, IcCard::getEmployeeNo)
.eq(IcCard::getNo, cardNo),
false);
if (card == null) {
return new ResponseMsg(CmdCodeEnum.CON, Voices.INVALID, cardNo, "无效卡!");
}
if (card.getStatus() != CardStatusEnum.ENABLE) {
return new ResponseMsg(CmdCodeEnum.CON, Voices.LOSS, cardNo, "挂失卡!");
}
if (card.getValidityTime() != null && card.getValidityTime().before(new Date())) {
return new ResponseMsg(CmdCodeEnum.CON, Voices.INVALID, cardNo, "无效卡!");
}
double currentBalance = ObjectUtil.getDouble(card.getCurrentBalance());
Double l
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
【资源说明】 基于java开发的高校智慧食堂系统源码+sql数据库(毕业设计).zip 基于java开发的高校智慧食堂系统源码+sql数据库(毕业设计).zip 基于java开发的高校智慧食堂系统源码+sql数据库(毕业设计).zip 该项目是个人毕设项目源码,评审分达到95分,都经过严格调试,确保可以运行!放心下载使用。 该项目资源主要针对计算机、自动化等相关专业的学生或从业者下载使用,也可作为期末课程设计、课程大作业、毕业设计等。 具有较高的学习借鉴价值!基础能力强的可以在此基础上修改调整,以实现类似其他功能。
资源推荐
资源详情
资源评论
收起资源包目录
基于java开发的高校智慧食堂系统源码+sql数据库(毕业设计).zip (173个子文件)
Dockerfile 357B
IcCardServiceImpl.java 16KB
EmployeeServiceImpl.java 11KB
CrcUtil.java 8KB
OrderServiceImpl.java 8KB
OriginationServiceImpl.java 8KB
WebSocket.java 5KB
ResponseMsg.java 5KB
EmployeeController.java 4KB
IcCardController.java 4KB
MachineServiceImpl.java 4KB
OriginationController.java 4KB
RoleServiceImpl.java 4KB
RechargeLogServiceImpl.java 4KB
Packet.java 4KB
RolePermissionServiceImpl.java 3KB
ServerHandler.java 3KB
EmployeeForm.java 3KB
RoleController.java 3KB
Order.java 3KB
OrderController.java 3KB
OperationLogServiceImpl.java 3KB
IIcCardService.java 3KB
EmployeeRoleServiceImpl.java 3KB
MachineController.java 3KB
IcCard.java 2KB
BaseEntity.java 2KB
IEmployeeService.java 2KB
LoginLogServiceImpl.java 2KB
MysqlGenerator.java 2KB
LogController.java 2KB
RolePermissionController.java 2KB
CanteenExceptionEnum.java 2KB
RechargeLogController.java 2KB
IOrderService.java 2KB
DefaultAesDecryptImpl.java 2KB
Employee.java 2KB
IOriginationService.java 2KB
EmployeeVO.java 2KB
TenantServiceImpl.java 2KB
SendMsgUtil.java 2KB
RechargeLog.java 2KB
OperationLog.java 2KB
DateUtil.java 2KB
EmployeeSearch.java 2KB
PermissionServiceImpl.java 2KB
Origination.java 2KB
LoginLog.java 2KB
Permission.java 2KB
CardVo.java 2KB
IMachineService.java 1KB
OrderMapper.java 1KB
CardSearch.java 1KB
MachineDTO.java 1KB
LogAspect.java 1KB
CardForm.java 1KB
RechargeLogSearch.java 1KB
OrderSearch.java 1KB
Swagger2Configuration.java 1KB
Voices.java 1KB
OrderVo.java 1KB
CardUserVo.java 1KB
NettyServer.java 1KB
IRoleService.java 1KB
OriginationForm.java 1KB
RechargeLogVO.java 1KB
OperationSearch.java 1KB
Tenant.java 1KB
Role.java 1KB
ByteArrayUtils.java 1KB
Machine.java 1KB
IEmployeeRoleService.java 1KB
Subscribe.java 1KB
LoginSearch.java 1KB
EmployeeRole.java 1KB
OriginationSearch.java 1KB
EntityLogUtil.java 1013B
IcCardMapper.java 995B
IRechargeLogService.java 991B
LoginLogVO.java 979B
EmployeeMapper.java 978B
ConEventEnum.java 978B
RechargeForm.java 971B
RolePermission.java 966B
RoleSearch.java 920B
MachineSearch.java 917B
IRolePermissionService.java 894B
IOperationLogService.java 870B
CmdCodeEnum.java 832B
MachineVO.java 828B
RoleForm.java 817B
RechargeTypeEnum.java 792B
ILoginLogService.java 784B
CardAccountEnum.java 779B
ChangePasswordForm.java 751B
DeductionForm.java 693B
EmployeeRoleMapper.java 635B
CardStatusEnum.java 620B
OriginationMapper.java 619B
OrderChannelEnum.java 615B
共 173 条
- 1
- 2
资源评论
onnx
- 粉丝: 1w+
- 资源: 5626
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- SBT 226-2007 食品机械通用技术条件 焊接、铆接件技术要求.pdf
- SBT 10148.6-1993 粮油加工机械通用技术条件 焊接件.pdf
- SHJ 509-1988 石油化工工程焊接工艺评定.pdf
- SH 3525-1992 石油化工低温钢焊接规程(附条文说明).pdf
- SDCV0041-2002 钢结构焊接节点.pdf
- SHJ 520-1991 石油化工工程铬钼耐热钢管道焊接技术规程(现编号SH3520-91).pdf
- SHS 01012-2004 常压立式圆筒形钢制焊接储罐维护检修规程.pdf
- 基于RFID的物联网STM32单片机图书档案管理系统源码(高分毕业设计)
- 在Debian上安装Docker Engine.pdf
- 岚精灵课程预约系统(教师端+学院端)
- 齿环研磨机sw16可编辑全套技术开发资料100%好用.zip
- 大卡车头模型step全套技术开发资料100%好用.zip
- c语言文件读写操作代码.txt
- ysaggxgzvhgvzshvhgvahg
- c语言文件读写操作代码.txt
- c语言文件读写操作代码.txt
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功