package com.jtj.web.service.impl;
import com.jtj.web.common.BasePointDto;
import com.jtj.web.common.ResultCode;
import com.jtj.web.common.ResultDto;
import com.jtj.web.common.exception.AssetException;
import com.jtj.web.dao.AssetDao;
import com.jtj.web.dao.PointDao;
import com.jtj.web.dao.UserDao;
import com.jtj.web.dto.AssetDto;
import com.jtj.web.dto.UserDto;
import com.jtj.web.entity.KeyValue;
import com.jtj.web.entity.Point;
import com.jtj.web.entity.User;
import com.jtj.web.service.PointService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import java.util.stream.Collectors;
/**
* Created by me
* 2017/3/15.
*/
@Service
public class PointServiceImpl implements PointService {
@Autowired
private PointDao pointDao;
@Autowired
private AssetDao assetDao;
@Autowired
private UserDao userDao;
//if you has redis, you can put it into redis
private static Map<Long,Point> allPointMap = new HashMap<>();
private static List<Point> allPointList = new ArrayList<>();
@Override
public Point getRootResource() {
Point point = new Point();
point.setName("root");
return point;
}
@Override
public PointDao getRepository() {
return pointDao;
}
@Override
public List<Point> getTreeResource() {
return pointDao.getAllPoint();
}
@Override
public List<Point> getTreeListResource() {
return allPointList;
}
@Override
public Map<Long, Point> getTreeMapResource() {
return allPointMap;
}
@Override
public ResultDto<Object> add(Point t) {
if (t.getPid() == null) {
t.setPid(0L);
}
ResultDto<Object> result = new ResultDto<>();
pointDao.add(t);
result.setResultCode(ResultCode.SUCCESS_POST);
refreshTreeData();
result.setMessage("请刷新当前页面!");
return result;
}
@Override
public ResultDto<Object> update(Point t) {
if (t.getPid() == null) {
t.setPid(0L);
}
ResultDto<Object> result = new ResultDto<>();
pointDao.update(t);
result.setResultCode(ResultCode.SUCCESS_PUT);
refreshTreeData();
return result;
}
@Override
@Transactional(rollbackFor = AssetException.class)
public ResultDto<Object> deleteById(Long id) throws AssetException {
Point point = getTreeMap().get(id);
if (point.getNodes().size() != 0){
throw new AssetException(new ResultDto<>(ResultCode.NOT_DELETE_USED));
}
if (point.getPid() == 0 || Objects.equals(point.getPid(), id)) {
//根节点,如果存在用户不能删除
UserDto userDto = new UserDto();
userDto.setPointId(point.getId());
if (userDao.getNum(userDto) != 0)
throw new AssetException(new ResultDto<>(ResultCode.NOT_DELETE_ROOT));
//根节点,如果存在资产不能删除
AssetDto assetDto = new AssetDto();
assetDto.setPointId(point.getId());
if (assetDao.getNum(assetDto) != 0)
throw new AssetException(new ResultDto<>(ResultCode.NOT_DELETE_ROOT));
}else {
userDao.updateToNewPoint(id,point.getPid());
assetDao.updateToNewPoint(id,point.getPid());
}
ResultDto<Object> result = new ResultDto<>();
int count = pointDao.delete(new Long[]{id});
result.setResultCode(ResultCode.SUCCESS_DELETE);
refreshTreeData();
return result;
}
@Override
public ResultDto<List<KeyValue>> getMapByPid(Long pid) throws AssetException {
ResultDto<List<KeyValue>> result = new ResultDto<>(ResultCode.SUCCESS);
//pid不存在返回全部
if (pid == null) {
result.setObject(getTreeList().stream().map(item->new KeyValue(item.getId()+"",item.getName()))
.collect(Collectors.toList()));
return result;
}
//pid存在返回子节点
Point point = getTreeMap().get(pid);
if (point == null){
throw new AssetException(new ResultDto<>(ResultCode.NOT_FOUND));
}
result.setObject(point.getNodes().stream()
.map(item-> new KeyValue(item.getId()+"",item.getName()))
.collect(Collectors.toList()));
return result;
}
@Override
public List<Point> getQueryPoint() {
List<Point> point = getQueryRootPoint();
List<Point> points = new ArrayList<>();
points.addAll(point);
Subject subject = SecurityUtils.getSubject();
if (!subject.isPermitted("system-point-subordinate:query")) {
return points;
}
List<List<Point>> lists = new ArrayList<>();
lists.add(points);
int i = 1;
while (points.size() != 0){
List<Point> pre = lists.get(i-1);
points = new ArrayList<>();
for (Point p1:pre){
if (p1 != null) {
points.addAll(p1.getNodes());
}
}
if (points.size() == 0) break;
lists.add(points);
i++;
}
return lists.stream().flatMap(Collection::stream).distinct().collect(Collectors.toList());
}
@Override
public List<Point> getQueryRootPoint() {
Subject subject = SecurityUtils.getSubject();
User user = (User) subject.getPrincipal();
if (subject.isPermitted("system-point-subordinate:query:globe")) {
return getTreeRoot();
}
List<Point> points = new ArrayList<>();
points.add(getTreeMap().get(user.getPointId()));
return points;
}
@Override
public Point getAuthenticationPoint(BasePointDto dto) {
Subject subject = SecurityUtils.getSubject();
User user = (User) subject.getPrincipal();
long pointId = dto.getPointId() == null?0L:dto.getPointId();
if (subject.isPermitted("point-subordinate-query:point-globe-query")) {
return getTreeMap().get(pointId);
}
if (subject.isPermitted("point-subordinate-query")){
boolean flag = checkAuthenticationPoint(pointId,user.getPoint());
return flag?getTreeMap().get(pointId):user.getPoint();
}
return user.getPoint();
}
private boolean checkAuthenticationPoint(long pointId, Point point) {
if (point == null) return false;
if (point.getId() == pointId) return true;
if (point.getNodes() == null) return false;
for (Point node : point.getNodes()){
if (checkAuthenticationPoint(pointId,node)) return true;
}
return false;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
基于SpringBoot+Mybatis企业固定资产管理系统源码+文档说明+数据库.zip本资源中的源码都是经过本地编译过可运行的,评审分达到95分以上。资源项目的难度比较适中,内容都是经过助教老师审定过的能够满足学习、使用需求,如果有需要的话可以放心下载使用。 基于SpringBoot+Mybatis企业固定资产管理系统源码+文档说明+数据库.zip本资源中的源码都是经过本地编译过可运行的,评审分达到95分以上。资源项目的难度比较适中,内容都是经过助教老师审定过的能够满足学习、使用需求,如果有需要的话可以放心下载使用。 基于SpringBoot+Mybatis企业固定资产管理系统源码+文档说明+数据库.zip本资源中的源码都是经过本地编译过可运行的,评审分达到95分以上。资源项目的难度比较适中,内容都是经过助教老师审定过的能够满足学习、使用需求,如果有需要的话可以放心下载使用。 基于SpringBoot+Mybatis企业固定资产管理系统源码+文档说明+数据库.zip本资源中的源码都是经过本地编译过可运行的,评审分达到95分以上。资源项目的难度比较适中,内容都是经过助教老师审定
资源推荐
资源详情
资源评论
收起资源包目录
基于SpringBoot+Mybatis企业固定资产管理系统源码+文档说明+数据库.zip (348个子文件)
.classpath 1KB
ele-green.css 349KB
style.css 172KB
bootstrap.css 143KB
ele.css 121KB
bootstrap.min.css 118KB
animate.css 65KB
datepicker3.css 33KB
jquery-ui.css 32KB
style.css 29KB
font-awesome.css 28KB
jquery-ui.min.css 25KB
style.min.css 25KB
font-awesome.min.css 23KB
font.css 19KB
sweetalert.css 18KB
select2.min.css 15KB
chosen.css 13KB
bootstrap-chosen.css 11KB
awesome-bootstrap-checkbox.css 7KB
toastr.min.css 7KB
index.css 2KB
bootstrap-duallistbox.min.css 2KB
custom.css 1KB
fontawesome-webfont.eot 59KB
glyphicons-halflings-regular.eot 20KB
animated-overlay.gif 2KB
throbber.gif 2KB
about.html 17KB
init.html 17KB
index.html 11KB
show.html 10KB
login.html 3KB
PointServiceImpl.java 7KB
StockTakeServiceImpl.java 5KB
RandomStringUtils.java 5KB
BorrowServiceImpl.java 5KB
ShiroRealm.java 4KB
AssetTypeServiceImpl.java 4KB
ShiroConfig.java 4KB
TreeService.java 3KB
PointAspect.java 3KB
RoleServiceImpl.java 3KB
MyPermissionAnnotationHandler.java 3KB
AssetTypeController.java 3KB
AssetController.java 3KB
PublicController.java 2KB
SerialCodeUtils.java 2KB
AssetOperationRecordServiceImpl.java 2KB
SystemServiceImpl.java 2KB
RoleController.java 2KB
User.java 2KB
AssetServiceImpl.java 2KB
StockTakeItemDto.java 2KB
Asset.java 2KB
Constant.java 2KB
StockTakeItem.java 2KB
CurdService.java 2KB
StockTake.java 2KB
ResultExceptionHandler.java 2KB
Borrow.java 2KB
ResultDto.java 2KB
PermissionController.java 2KB
StockTakeDto.java 2KB
UserServiceImpl.java 1KB
BorrowDto.java 1KB
JacksonUtils.java 1KB
ResultCode.java 1KB
Swagger2.java 1KB
UserController.java 1KB
AssetDto.java 1KB
ReportController.java 1KB
StockTakeDao.java 1KB
ReportServiceImpl.java 1KB
AssetApplicationWebMvcTests.java 1KB
MyAopAllianceAnnotationsAuthorizingMethodInterceptor.java 1KB
AssetOperationRecord.java 1KB
WebConfig.java 1KB
BeanUtils.java 1KB
MD5String.java 1KB
StockTakeService.java 1020B
PointService.java 884B
AssetOperationRecordDto.java 873B
PermissionServiceImpl.java 854B
BorrowService.java 842B
UserDao.java 799B
Dictionary.java 797B
Role.java 795B
PointDto.java 792B
AssetTypeService.java 788B
UsernamePasswordTokenDto.java 788B
MyFormAuthenticationFilter.java 746B
RoleDao.java 739B
BaseEntity.java 712B
Point.java 683B
AssetOperationRecordService.java 673B
TreeEntity.java 647B
UserDto.java 631B
RoleService.java 625B
AssetTypeDto.java 624B
共 348 条
- 1
- 2
- 3
- 4
资源评论
盈梓的博客
- 粉丝: 7131
- 资源: 1835
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功