From 2d3a2f25ee1d3f62cc1986f7d4128f422ba8fb70 Mon Sep 17 00:00:00 2001 From: joylink_zhangsai <1021828630@qq.com> Date: Thu, 10 Dec 2020 15:38:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=A0=B9=E6=8D=AE=E5=9C=B0?= =?UTF-8?q?=E5=9B=BE=E4=B8=80=E9=94=AE=E9=A2=86=E6=9D=83=E9=99=90=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../permission/GoodsController.java | 2 +- .../user/UserPermissionController.java | 6 +++ .../joylink/rtss/services/GoodsService.java | 24 ++++++++--- .../joylink/rtss/services/IGoodsService.java | 3 +- .../rtss/services/IPermissionService.java | 2 + .../rtss/services/IUserPermissionService.java | 8 ++++ .../rtss/services/PermissionService.java | 12 ++++-- .../rtss/services/UserPermissionService.java | 40 +++++++++++++++++-- 8 files changed, 82 insertions(+), 15 deletions(-) diff --git a/src/main/java/club/joylink/rtss/controller/permission/GoodsController.java b/src/main/java/club/joylink/rtss/controller/permission/GoodsController.java index c845ab827..2453dd2c8 100644 --- a/src/main/java/club/joylink/rtss/controller/permission/GoodsController.java +++ b/src/main/java/club/joylink/rtss/controller/permission/GoodsController.java @@ -106,6 +106,6 @@ public class GoodsController { @ApiOperation(value = "根据权限ids查询权限包商品") @GetMapping(path = "/permissionIds") public GoodsVO findGoodsByPermissionIds(Long[] ids) { - return iGoodsService.findGoodsByPermissionIds(ids); + return iGoodsService.findGoodsByRelPermissionIds(ids); } } diff --git a/src/main/java/club/joylink/rtss/controller/user/UserPermissionController.java b/src/main/java/club/joylink/rtss/controller/user/UserPermissionController.java index 87f70c1f6..f5a4fb7c7 100644 --- a/src/main/java/club/joylink/rtss/controller/user/UserPermissionController.java +++ b/src/main/java/club/joylink/rtss/controller/user/UserPermissionController.java @@ -76,4 +76,10 @@ public class UserPermissionController { return iUserPermissionService.queryPersonalUserPermission(user); } + @ApiOperation("根据地图一键领取权限") + @PostMapping("/{mapId}/getPermissions") + public void getPermissions4Map(@PathVariable Long mapId, Integer count ,@RequestAttribute @ApiIgnore UserVO user) { + iUserPermissionService.getPermissions4Map(mapId, count, user); + } + } diff --git a/src/main/java/club/joylink/rtss/services/GoodsService.java b/src/main/java/club/joylink/rtss/services/GoodsService.java index eca1b719c..56faa3f6e 100644 --- a/src/main/java/club/joylink/rtss/services/GoodsService.java +++ b/src/main/java/club/joylink/rtss/services/GoodsService.java @@ -1,8 +1,5 @@ package club.joylink.rtss.services; -import club.joylink.rtss.exception.BusinessExceptionAssertEnum; -import com.github.pagehelper.Page; -import com.github.pagehelper.PageHelper; import club.joylink.rtss.constants.BusinessConsts; import club.joylink.rtss.constants.SaleGoodsTypeEnum; import club.joylink.rtss.constants.StatusEnum; @@ -13,6 +10,7 @@ import club.joylink.rtss.entity.Permission; import club.joylink.rtss.entity.PermissionExample; import club.joylink.rtss.entity.SaleGoods; import club.joylink.rtss.entity.SaleGoodsExample; +import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.vo.UserVO; import club.joylink.rtss.vo.client.GoodsTryVO; import club.joylink.rtss.vo.client.PageVO; @@ -22,14 +20,19 @@ import club.joylink.rtss.vo.client.goods.GoodsVO; import club.joylink.rtss.vo.client.permission.PermissionQueryVO; import club.joylink.rtss.vo.client.permission.PermissionSelectVO; import club.joylink.rtss.vo.client.permission.PermissionVO; +import com.github.pagehelper.Page; +import com.github.pagehelper.PageHelper; import lombok.extern.slf4j.Slf4j; -import org.springframework.util.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; +import org.springframework.util.StringUtils; import java.time.LocalDateTime; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; import java.util.stream.Collectors; @Service @@ -151,7 +154,7 @@ public class GoodsService implements IGoodsService { * 如果有权限包但没有对应的商品,返回一个只有permissionId和permissionName的goodsVO */ @Override - public GoodsVO findGoodsByPermissionIds(Long[] relPermissionIds) { + public GoodsVO findGoodsByRelPermissionIds(Long[] relPermissionIds) { List voList = iPermissionService.findPermissionByRelPermissionIds(Arrays.asList(relPermissionIds)); if (voList.isEmpty()) { return null; @@ -238,6 +241,15 @@ public class GoodsService implements IGoodsService { return goods != null; } + @Override + public List getByPermissionIds(List permissionIds) { + SaleGoodsExample example = new SaleGoodsExample(); + example.createCriteria().andPermissionIdIn(permissionIds); + List saleGoods = saleGoodsDAO.selectByExample(example); + BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertCollectionNotEmpty(saleGoods); + return saleGoods.stream().map(GoodsVO::new).collect(Collectors.toList()); + } + public SaleGoods findEntity(Long id) { return saleGoodsDAO.selectByPrimaryKey(id); } diff --git a/src/main/java/club/joylink/rtss/services/IGoodsService.java b/src/main/java/club/joylink/rtss/services/IGoodsService.java index 392325b91..c71dac3bb 100644 --- a/src/main/java/club/joylink/rtss/services/IGoodsService.java +++ b/src/main/java/club/joylink/rtss/services/IGoodsService.java @@ -48,7 +48,7 @@ public interface IGoodsService { /** * 通过关联权限ids查询权限包商品 */ - GoodsVO findGoodsByPermissionIds(Long[] relPermissionIds); + GoodsVO findGoodsByRelPermissionIds(Long[] relPermissionIds); PageVO queryPagedGoodsByPermission(PermissionQueryVO queryVO); @@ -65,4 +65,5 @@ public interface IGoodsService { boolean isExist(Long goodsId); + List getByPermissionIds(List permissionIds); } diff --git a/src/main/java/club/joylink/rtss/services/IPermissionService.java b/src/main/java/club/joylink/rtss/services/IPermissionService.java index 5a8f54b92..ad0aeb4ce 100644 --- a/src/main/java/club/joylink/rtss/services/IPermissionService.java +++ b/src/main/java/club/joylink/rtss/services/IPermissionService.java @@ -54,4 +54,6 @@ public interface IPermissionService { * 根据mapId查询教学权限 */ Permission findTeachPermissionEntity(Long mapId); + + List getByMapId(Long mapId); } diff --git a/src/main/java/club/joylink/rtss/services/IUserPermissionService.java b/src/main/java/club/joylink/rtss/services/IUserPermissionService.java index 5c3e45f34..6dd6baeea 100644 --- a/src/main/java/club/joylink/rtss/services/IUserPermissionService.java +++ b/src/main/java/club/joylink/rtss/services/IUserPermissionService.java @@ -87,4 +87,12 @@ public interface IUserPermissionService { * 查询有效的用户教学权限 */ List findEntity(List userIds, Boolean valid); + + /** + * 给该用户领取该地图的权限 + * @param mapId + * @param count + * @param user + */ + void getPermissions4Map(Long mapId, Integer count, UserVO user); } diff --git a/src/main/java/club/joylink/rtss/services/PermissionService.java b/src/main/java/club/joylink/rtss/services/PermissionService.java index 81a05a330..4e2df8b89 100644 --- a/src/main/java/club/joylink/rtss/services/PermissionService.java +++ b/src/main/java/club/joylink/rtss/services/PermissionService.java @@ -459,7 +459,7 @@ public class PermissionService implements IPermissionService { example.createCriteria() .andRelPermissionsEqualTo(ids); List permissionList = permissionDAO.selectByExample(example); - List voList = permissionList.stream().map(permission -> new PermissionVO(permission)).collect(Collectors.toList()); + List voList = permissionList.stream().map(PermissionVO::new).collect(Collectors.toList()); return voList; } @@ -468,8 +468,7 @@ public class PermissionService implements IPermissionService { PermissionExample example = new PermissionExample(); example.createCriteria().andMapIdEqualTo(mapId); List permissionList = permissionDAO.selectByExample(example); - List voList = permissionList.stream().map(permission -> new PermissionVO(permission)).collect(Collectors.toList()); - return voList; + return permissionList.stream().map(PermissionVO::new).collect(Collectors.toList()); } /** @@ -535,6 +534,13 @@ public class PermissionService implements IPermissionService { } } + @Override + public List getByMapId(Long mapId) { + List permissions = findByMapId(mapId); + BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertCollectionNotEmpty(permissions, String.format("地图[%s]下没有权限", mapId)); + return permissions; + } + /** * 根据mapId获取该地图下的综合演练权限 */ diff --git a/src/main/java/club/joylink/rtss/services/UserPermissionService.java b/src/main/java/club/joylink/rtss/services/UserPermissionService.java index 0c8459058..df68bdea4 100644 --- a/src/main/java/club/joylink/rtss/services/UserPermissionService.java +++ b/src/main/java/club/joylink/rtss/services/UserPermissionService.java @@ -1,9 +1,6 @@ package club.joylink.rtss.services; -import club.joylink.rtss.constants.MapPrdTypeEnum; -import club.joylink.rtss.constants.PermissionTypeEnum; -import club.joylink.rtss.constants.StatusEnum; -import club.joylink.rtss.constants.UserPermissionStatusEnum; +import club.joylink.rtss.constants.*; import club.joylink.rtss.dao.PermissionDAO; import club.joylink.rtss.dao.SysUserDAO; import club.joylink.rtss.dao.UserPermissionDAO; @@ -13,7 +10,11 @@ import club.joylink.rtss.entity.UserPermission; import club.joylink.rtss.entity.UserPermissionExample; import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.vo.UserVO; +import club.joylink.rtss.vo.client.OrganizationVO; import club.joylink.rtss.vo.client.PageVO; +import club.joylink.rtss.vo.client.goods.GoodsVO; +import club.joylink.rtss.vo.client.order.OrderCreateVO; +import club.joylink.rtss.vo.client.order.OrderDetailCreateVO; import club.joylink.rtss.vo.client.permission.DistributeSelectVO; import club.joylink.rtss.vo.client.permission.PermissionQueryVO; import club.joylink.rtss.vo.client.permission.PermissionVO; @@ -27,6 +28,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; +import java.time.LocalDateTime; import java.util.*; import java.util.stream.Collectors; @@ -59,6 +61,9 @@ public class UserPermissionService implements IUserPermissionService { @Autowired private IOrderService iOrderService; + @Autowired + private IOrganizationService iOrganizationService; + @Override public PageVO queryPagedPermission(PermissionQueryVO queryVO) { List relDistributeIds = new ArrayList<>(); @@ -512,6 +517,33 @@ public class UserPermissionService implements IUserPermissionService { return userPermissionDAO.selectByExample(example); } + @Override + public void getPermissions4Map(Long mapId, Integer count, UserVO user) { + if (count == null || count == 0) { + return; + } + List organizations = iOrganizationService.queryOrganization(); + BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertCollectionNotEmpty(organizations, "没有组织数据"); + + List permissions = iPermissionService.getByMapId(mapId); + List goods = iGoodsService.getByPermissionIds(permissions.stream().map(PermissionVO::getId).collect(Collectors.toList())); + List orderDetails = goods.stream().map(goodsVO -> new OrderDetailCreateVO(goodsVO.getId(), count)).collect(Collectors.toList()); + + OrderCreateVO orderCreate = new OrderCreateVO(); + orderCreate.setOrganizationId(48L); + orderCreate.setOrderType(SaleOrderTypeEnum.Internal_Distribution.getCode()); + orderCreate.setForever(true); + orderCreate.setStartTime(LocalDateTime.now()); + orderCreate.setPayStatus(SaleOrderPayStatusEnum.No_Need.getCode()); + orderCreate.setDetailCreateVOList(orderDetails); + //创建权限分发并领取权限 + String orderCode = iOrderService.createOrder(orderCreate, user); + iPermissionDistributeService.distributeFromOrder(orderCode, user); + DistributeVO distribute = iPermissionDistributeService.getByOrderCode(orderCode); + Long distributeId = distribute.getId(); + iPermissionDistributeService.getUserPermission(distributeId, user); + } + private List findByUserId(Long userId) { UserPermissionExample example = new UserPermissionExample(); example.createCriteria().andUserIdEqualTo(userId);