交班相关代码
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
package com.czg.service.account.mapper;
|
||||
|
||||
import com.czg.account.entity.HandoverRecord;
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 交班记录表
|
||||
*
|
||||
* @author Tankaikai tankaikai@aliyun.com
|
||||
* @since 1.0 2025-02-27
|
||||
*/
|
||||
@Mapper
|
||||
public interface HandoverRecordMapper extends BaseMapper<HandoverRecord> {
|
||||
|
||||
}
|
||||
@@ -6,20 +6,23 @@ import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import com.czg.account.dto.SysLoginDTO;
|
||||
import com.czg.account.entity.*;
|
||||
import com.czg.account.enums.HandoverAccountTypeEnum;
|
||||
import com.czg.account.service.*;
|
||||
import com.czg.account.vo.LoginVO;
|
||||
import com.czg.config.RedisCst;
|
||||
import com.czg.enums.PlatformTypeEnum;
|
||||
import com.czg.enums.StatusEnum;
|
||||
import com.czg.exception.ApiNotPrintException;
|
||||
import com.czg.sa.MyStpLogic;
|
||||
import com.czg.sa.StpKit;
|
||||
import com.czg.service.RedisService;
|
||||
import com.czg.service.account.mapper.SysMenuMapper;
|
||||
import com.czg.utils.ServletUtil;
|
||||
import com.wf.captcha.SpecCaptcha;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -44,6 +47,8 @@ public class AuthorizationServiceImpl implements AuthorizationService {
|
||||
private SysRoleService sysRoleService;
|
||||
@Resource
|
||||
private SysMenuMapper sysMenuMapper;
|
||||
@Resource
|
||||
private HandoverRecordService handoverRecordService;
|
||||
|
||||
|
||||
@Override
|
||||
@@ -83,8 +88,8 @@ public class AuthorizationServiceImpl implements AuthorizationService {
|
||||
}
|
||||
|
||||
user = sysUserService.queryChain().eq(SysUser::getAccount, sysUser.getId() + "@" + loginDTO.staffUserName()).one();
|
||||
}else {
|
||||
user = sysUserService.queryChain().eq(SysUser::getAccount,loginDTO.username()).one();
|
||||
} else {
|
||||
user = sysUserService.queryChain().eq(SysUser::getAccount, loginDTO.username()).one();
|
||||
}
|
||||
|
||||
if (user == null) {
|
||||
@@ -97,11 +102,12 @@ public class AuthorizationServiceImpl implements AuthorizationService {
|
||||
}
|
||||
|
||||
ShopInfo shopInfo;
|
||||
ShopStaff shopStaff = null;
|
||||
boolean isStaff = false;
|
||||
List<String> shopStaffPromissionList = null;
|
||||
// 商户员工登录
|
||||
if (loginDTO.loginType() == 1) {
|
||||
ShopStaff shopStaff = shopStaffService.queryChain().eq(ShopStaff::getStatus, 1)
|
||||
shopStaff = shopStaffService.queryChain().eq(ShopStaff::getStatus, 1)
|
||||
.eq(ShopStaff::getIsManage, 1)
|
||||
.eq(ShopStaff::getId, user.getId()).one();
|
||||
if (shopStaff == null) {
|
||||
@@ -112,7 +118,7 @@ public class AuthorizationServiceImpl implements AuthorizationService {
|
||||
|
||||
// 查询员工权限
|
||||
shopStaffPromissionList = shopStaffPermissionService.getPermissionByStaffId(shopInfo.getId(), shopStaff.getId(), user.getId()).stream().map(ShopPermission::getCode).toList();
|
||||
}else {
|
||||
} else {
|
||||
shopInfo = shopInfoService.getById(user.getId());
|
||||
}
|
||||
|
||||
@@ -126,7 +132,7 @@ public class AuthorizationServiceImpl implements AuthorizationService {
|
||||
}
|
||||
}
|
||||
|
||||
StpKit.USER.login(user.getId(), user.getAccount(), shopInfo.getId(), isStaff ? MyStpLogic.LoginType.STAFF :MyStpLogic.LoginType.MANAGER, user.getIsAdmin());
|
||||
StpKit.USER.login(user.getId(), user.getAccount(), shopInfo.getId(), isStaff ? MyStpLogic.LoginType.STAFF : MyStpLogic.LoginType.MANAGER, user.getIsAdmin());
|
||||
// 查询角色
|
||||
List<SysRole> roleList = sysRoleService.getByUserId(user.getId());
|
||||
List<String> roleNames = roleList.stream().map(SysRole::getName).collect(Collectors.toList());
|
||||
@@ -138,6 +144,30 @@ public class AuthorizationServiceImpl implements AuthorizationService {
|
||||
promissionList.addAll(shopStaffPromissionList);
|
||||
}
|
||||
StpKit.USER.addPermissionList(promissionList);
|
||||
String platformType = ServletUtil.getHeaderIgnoreCase(ServletUtil.getRequest(), "platformType");
|
||||
if (PlatformTypeEnum.PC_CLIENT.getValue().equals(platformType)) {
|
||||
// 初始化交班记录
|
||||
HandoverRecord entity = getHandoverRecord(isStaff, shopInfo, shopStaff);
|
||||
handoverRecordService.initHandoverRecord(entity);
|
||||
}
|
||||
return new LoginVO(StpKit.USER.getTokenInfo(), promissionList, loginDTO.loginType(), shopInfo);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static HandoverRecord getHandoverRecord(boolean isStaff, ShopInfo shopInfo, ShopStaff shopStaff) {
|
||||
HandoverRecord entity = new HandoverRecord();
|
||||
if (isStaff) {
|
||||
entity.setAccountType(HandoverAccountTypeEnum.STAFF.getValue());
|
||||
entity.setStaffId(shopStaff.getId());
|
||||
entity.setStaffName(shopStaff.getName());
|
||||
} else {
|
||||
entity.setAccountType(HandoverAccountTypeEnum.MERCHANT.getValue());
|
||||
|
||||
entity.setStaffId(shopInfo.getId());
|
||||
entity.setStaffName(shopInfo.getShopName());
|
||||
}
|
||||
entity.setShopId(shopInfo.getId());
|
||||
entity.setShopName(shopInfo.getShopName());
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
package com.czg.service.account.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||
import com.czg.account.dto.HandoverRecordDTO;
|
||||
import com.czg.account.entity.HandoverRecord;
|
||||
import com.czg.account.service.HandoverRecordService;
|
||||
import com.czg.account.vo.HandoverProductListVo;
|
||||
import com.czg.account.vo.HandoverTotalVo;
|
||||
import com.czg.order.service.OrderInfoService;
|
||||
import com.czg.sa.StpKit;
|
||||
import com.czg.service.account.mapper.HandoverRecordMapper;
|
||||
import com.czg.utils.PageUtil;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 交班记录表
|
||||
*
|
||||
* @author Tankaikai tankaikai@aliyun.com
|
||||
* @since 1.0 2025-02-27
|
||||
*/
|
||||
@Service
|
||||
public class HandoverRecordServiceImpl extends ServiceImpl<HandoverRecordMapper, HandoverRecord> implements HandoverRecordService {
|
||||
|
||||
@DubboReference
|
||||
private OrderInfoService orderInfoService;
|
||||
|
||||
private QueryWrapper buildQueryWrapper(HandoverRecordDTO param) {
|
||||
QueryWrapper queryWrapper = PageUtil.buildSortQueryWrapper();
|
||||
/*if (StrUtil.isNotEmpty(param.getName())) {
|
||||
queryWrapper.like(HandoverRecord::getName, param.getName());
|
||||
}*/
|
||||
Long shopId = StpKit.USER.getShopId(0L);
|
||||
queryWrapper.eq(HandoverRecord::getShopId, shopId);
|
||||
queryWrapper.orderBy(HandoverRecord::getId, false);
|
||||
return queryWrapper;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public HandoverTotalVo totalHandoverData() {
|
||||
orderInfoService.historyOrder(0L, "11");
|
||||
Long shopId = StpKit.USER.getShopId(0L);
|
||||
LocalDateTime handoverTime = LocalDateTime.now();
|
||||
HandoverRecord record = super.getOne(query().eq(HandoverRecord::getShopId, shopId).isNull(HandoverRecord::getHandoverTime));
|
||||
HandoverTotalVo data = new HandoverTotalVo();
|
||||
data.setId(record.getId());
|
||||
data.setShopId(record.getShopId());
|
||||
data.setShopName(record.getShopName());
|
||||
data.setAccountType(record.getAccountType());
|
||||
data.setStaffId(record.getStaffId());
|
||||
data.setStaffName(record.getStaffName());
|
||||
data.setLoginTime(record.getLoginTime());
|
||||
data.setHandoverTime(handoverTime);
|
||||
String loginTimeStr = LocalDateTimeUtil.formatNormal(record.getLoginTime());
|
||||
String handoverTimeStr = LocalDateTimeUtil.formatNormal(handoverTime);
|
||||
data.setCashAmount(sumCashAmount(shopId, loginTimeStr, handoverTimeStr));
|
||||
data.setRefundAmount(sumRefundAmount(shopId, loginTimeStr, handoverTimeStr));
|
||||
data.setHandAmount(sumHandAmount(shopId, loginTimeStr, handoverTimeStr));
|
||||
data.setOrderCount(countOrderNum(shopId, loginTimeStr, handoverTimeStr));
|
||||
data.setDetailList(getDetailList(shopId, loginTimeStr, handoverTimeStr));
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initHandoverRecord(HandoverRecord entity) {
|
||||
Long shopId = StpKit.USER.getShopId(0L);
|
||||
List<HandoverRecord> list = super.list(query().eq(HandoverRecord::getShopId, shopId).isNull(HandoverRecord::getHandoverTime));
|
||||
if (CollUtil.isNotEmpty(list)) {
|
||||
return;
|
||||
}
|
||||
entity.setShopId(shopId);
|
||||
entity.setLoginTime(LocalDateTime.now());
|
||||
super.save(entity);
|
||||
}
|
||||
|
||||
private BigDecimal sumCashAmount(Long shopId, String loginTime, String handoverTime) {
|
||||
return orderInfoService.getHandoverCashAmount(shopId, loginTime, handoverTime);
|
||||
}
|
||||
|
||||
private BigDecimal sumRefundAmount(Long shopId, String loginTime, String handoverTime) {
|
||||
return orderInfoService.getHandoverRefundAmount(shopId, loginTime, handoverTime);
|
||||
}
|
||||
|
||||
private BigDecimal sumHandAmount(Long shopId, String loginTime, String handoverTime) {
|
||||
return orderInfoService.getHandoverTotalAmount(shopId, loginTime, handoverTime);
|
||||
}
|
||||
|
||||
private int countOrderNum(Long shopId, String loginTime, String handoverTime) {
|
||||
return orderInfoService.getHandoverOrderNum(shopId, loginTime, handoverTime);
|
||||
}
|
||||
|
||||
private List<HandoverProductListVo> getDetailList(Long shopId, String loginTime, String handoverTime) {
|
||||
return orderInfoService.getHandoverDetailList(shopId, loginTime, handoverTime);
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,7 @@ public class PictureClassifyServiceImpl extends ServiceImpl<PictureClassifyMappe
|
||||
if (StrUtil.isNotEmpty(param.getName())) {
|
||||
queryWrapper.like(PictureClassify::getName, param.getName());
|
||||
}
|
||||
Long shopId = StpKit.USER.getLoginIdAsLong();
|
||||
Long shopId = StpKit.USER.getShopId(0L);
|
||||
queryWrapper.and(q -> {
|
||||
q.eq(PictureClassify::getShopId, shopId).or(q1 -> {
|
||||
q1.eq(PictureClassify::getShopId, 0).eq(PictureClassify::getIsSystem, YesNoEnum.YES.value());
|
||||
@@ -52,7 +52,7 @@ public class PictureClassifyServiceImpl extends ServiceImpl<PictureClassifyMappe
|
||||
|
||||
@Override
|
||||
public void addPictureClassify(PictureClassifyDTO dto) {
|
||||
Long shopId = StpKit.USER.getLoginIdAsLong();
|
||||
Long shopId = StpKit.USER.getShopId(0L);
|
||||
boolean exists = super.exists(query().eq(PictureClassify::getName, dto.getName())
|
||||
.and(q -> {
|
||||
q.eq(PictureClassify::getShopId, shopId).or(q1 -> {
|
||||
@@ -72,7 +72,7 @@ public class PictureClassifyServiceImpl extends ServiceImpl<PictureClassifyMappe
|
||||
@Override
|
||||
public void updatePictureClassify(PictureClassifyDTO dto) {
|
||||
checkPictureClassify(dto.getId());
|
||||
Long shopId = StpKit.USER.getLoginIdAsLong();
|
||||
Long shopId = StpKit.USER.getShopId(0L);
|
||||
dto.setShopId(shopId);
|
||||
boolean exists = super.exists(query().eq(PictureClassify::getName, dto.getName())
|
||||
.ne(PictureClassify::getId, dto.getId())
|
||||
@@ -93,7 +93,7 @@ public class PictureClassifyServiceImpl extends ServiceImpl<PictureClassifyMappe
|
||||
@Override
|
||||
public void deletePictureClassify(Long id) {
|
||||
checkPictureClassify(id);
|
||||
Long shopId = StpKit.USER.getLoginIdAsLong();
|
||||
Long shopId = StpKit.USER.getShopId(0L);
|
||||
UpdateChain.of(PictureClassify.class)
|
||||
.set(PictureClassify::getIsDel, DeleteEnum.DELETED.value())
|
||||
.eq(PictureClassify::getShopId, shopId)
|
||||
|
||||
@@ -33,7 +33,7 @@ public class PictureGalleryServiceImpl extends ServiceImpl<PictureGalleryMapper,
|
||||
if (ObjUtil.isNotNull(param.getPictureClassifyId())) {
|
||||
queryWrapper.eq(PictureGallery::getPictureClassifyId, param.getPictureClassifyId());
|
||||
}
|
||||
Long shopId = StpKit.USER.getLoginIdAsLong();
|
||||
Long shopId = StpKit.USER.getShopId(0L);
|
||||
queryWrapper.eq(PictureGallery::getShopId, shopId);
|
||||
queryWrapper.eq(PictureGallery::getIsDel, DeleteEnum.NORMAL.value());
|
||||
queryWrapper.orderBy(PictureGallery::getId, false);
|
||||
@@ -48,7 +48,7 @@ public class PictureGalleryServiceImpl extends ServiceImpl<PictureGalleryMapper,
|
||||
|
||||
@Override
|
||||
public void addPictureGallery(PictureGalleryParam param) {
|
||||
Long shopId = StpKit.USER.getLoginIdAsLong();
|
||||
Long shopId = StpKit.USER.getShopId(0L);
|
||||
for (String url : param.getUrls()) {
|
||||
PictureGallery entity = new PictureGallery();
|
||||
entity.setShopId(shopId);
|
||||
@@ -61,7 +61,7 @@ public class PictureGalleryServiceImpl extends ServiceImpl<PictureGalleryMapper,
|
||||
|
||||
@Override
|
||||
public void deletePictureGallery(Long id) {
|
||||
Long shopId = StpKit.USER.getLoginIdAsLong();
|
||||
Long shopId = StpKit.USER.getShopId(0L);
|
||||
UpdateChain.of(PictureGallery.class)
|
||||
.set(PictureGallery::getIsDel, DeleteEnum.DELETED.value())
|
||||
.eq(PictureGallery::getShopId, shopId)
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="com.czg.service.account.mapper.HandoverRecordMapper">
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user