添加根据地图一键领权限功能

This commit is contained in:
joylink_zhangsai 2020-12-10 15:38:41 +08:00
parent c802b2115f
commit 2d3a2f25ee
8 changed files with 82 additions and 15 deletions

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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<PermissionVO> 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<GoodsVO> getByPermissionIds(List<Long> permissionIds) {
SaleGoodsExample example = new SaleGoodsExample();
example.createCriteria().andPermissionIdIn(permissionIds);
List<SaleGoods> 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);
}

View File

@ -48,7 +48,7 @@ public interface IGoodsService {
/**
* 通过关联权限ids查询权限包商品
*/
GoodsVO findGoodsByPermissionIds(Long[] relPermissionIds);
GoodsVO findGoodsByRelPermissionIds(Long[] relPermissionIds);
PageVO<GoodsVO> queryPagedGoodsByPermission(PermissionQueryVO queryVO);
@ -65,4 +65,5 @@ public interface IGoodsService {
boolean isExist(Long goodsId);
List<GoodsVO> getByPermissionIds(List<Long> permissionIds);
}

View File

@ -54,4 +54,6 @@ public interface IPermissionService {
* 根据mapId查询教学权限
*/
Permission findTeachPermissionEntity(Long mapId);
List<PermissionVO> getByMapId(Long mapId);
}

View File

@ -87,4 +87,12 @@ public interface IUserPermissionService {
* 查询有效的用户教学权限
*/
List<UserPermission> findEntity(List<Long> userIds, Boolean valid);
/**
* 给该用户领取该地图的权限
* @param mapId
* @param count
* @param user
*/
void getPermissions4Map(Long mapId, Integer count, UserVO user);
}

View File

@ -459,7 +459,7 @@ public class PermissionService implements IPermissionService {
example.createCriteria()
.andRelPermissionsEqualTo(ids);
List<Permission> permissionList = permissionDAO.selectByExample(example);
List<PermissionVO> voList = permissionList.stream().map(permission -> new PermissionVO(permission)).collect(Collectors.toList());
List<PermissionVO> 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<Permission> permissionList = permissionDAO.selectByExample(example);
List<PermissionVO> 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<PermissionVO> getByMapId(Long mapId) {
List<PermissionVO> permissions = findByMapId(mapId);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertCollectionNotEmpty(permissions, String.format("地图[%s]下没有权限", mapId));
return permissions;
}
/**
* 根据mapId获取该地图下的综合演练权限
*/

View File

@ -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<UserPermissionVO> queryPagedPermission(PermissionQueryVO queryVO) {
List<Long> 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<OrganizationVO> organizations = iOrganizationService.queryOrganization();
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertCollectionNotEmpty(organizations, "没有组织数据");
List<PermissionVO> permissions = iPermissionService.getByMapId(mapId);
List<GoodsVO> goods = iGoodsService.getByPermissionIds(permissions.stream().map(PermissionVO::getId).collect(Collectors.toList()));
List<OrderDetailCreateVO> 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<UserPermissionVO> findByUserId(Long userId) {
UserPermissionExample example = new UserPermissionExample();
example.createCriteria().andUserIdEqualTo(userId);