|
@@ -2,14 +2,17 @@ package com.ruoyi.equity.service.impl;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
-import java.util.Collections;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Objects;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+import java.util.stream.Stream;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.ruoyi.common.core.domain.model.LoginUser;
|
|
|
import com.ruoyi.common.exception.user.OnlyOneMainCompanyAllowedException;
|
|
|
+import com.ruoyi.common.exception.user.urNotshareholderException;
|
|
|
import com.ruoyi.common.utils.DateUtils;
|
|
|
+import com.ruoyi.common.utils.SecurityUtils;
|
|
|
import com.ruoyi.equity.domain.vo.ShareholderDownPicVO;
|
|
|
import com.ruoyi.equity.domain.vo.ShareholderInfoVO;
|
|
|
import com.ruoyi.equity.domain.vo.ShareholderPicVO;
|
|
@@ -17,7 +20,11 @@ import com.ruoyi.equity.domain.vo.ShareholderUpPicVO;
|
|
|
import com.ruoyi.equity.utils.ForestNodeManager2;
|
|
|
import com.ruoyi.equity.utils.ForestNodeMerger;
|
|
|
import com.ruoyi.equity.utils.ForestNodeMerger2;
|
|
|
+import com.ruoyi.framework.web.service.SysLoginService;
|
|
|
+import com.ruoyi.system.domain.SysLogininfor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.security.core.Authentication;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.ruoyi.equity.mapper.ShareholderInfoMapper;
|
|
|
import com.ruoyi.equity.domain.ShareholderInfo;
|
|
@@ -26,127 +33,155 @@ import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
/**
|
|
|
* 股东信息Service业务层处理
|
|
|
- *
|
|
|
+ *
|
|
|
* @author ruoyi
|
|
|
* @date 2025-03-03
|
|
|
*/
|
|
|
@Service
|
|
|
-public class ShareholderInfoServiceImpl extends ServiceImpl<ShareholderInfoMapper, ShareholderInfo> implements IShareholderInfoService
|
|
|
-{
|
|
|
+@Slf4j
|
|
|
+public class ShareholderInfoServiceImpl extends ServiceImpl<ShareholderInfoMapper, ShareholderInfo> implements IShareholderInfoService {
|
|
|
+ public static final long USER_ROLE_ID = 102 ;
|
|
|
@Autowired
|
|
|
private ShareholderInfoMapper shareholderInfoMapper;
|
|
|
|
|
|
/**
|
|
|
* 查询股东信息
|
|
|
- *
|
|
|
+ *
|
|
|
* @param shareholderId 股东信息主键
|
|
|
* @return 股东信息
|
|
|
*/
|
|
|
@Override
|
|
|
- public ShareholderInfo selectShareholderInfoByShareholderId(Long shareholderId)
|
|
|
- {
|
|
|
+ public ShareholderInfo selectShareholderInfoByShareholderId(Long shareholderId) {
|
|
|
return shareholderInfoMapper.selectShareholderInfoByShareholderId(shareholderId);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询股东信息列表
|
|
|
- *
|
|
|
+ *
|
|
|
* @param shareholderInfo 股东信息
|
|
|
* @return 股东信息
|
|
|
*/
|
|
|
@Override
|
|
|
- public List<ShareholderInfoVO> selectShareholderInfoList(ShareholderInfo shareholderInfo)
|
|
|
- {
|
|
|
+ public List<ShareholderInfoVO> selectShareholderInfoList(ShareholderInfo shareholderInfo) {
|
|
|
|
|
|
return shareholderInfoMapper.selectShareholderInfoList(shareholderInfo);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 新增股东信息
|
|
|
- *
|
|
|
+ *
|
|
|
* @param shareholderInfo 股东信息
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int insertShareholderInfo(ShareholderInfo shareholderInfo)
|
|
|
- {
|
|
|
+ public int insertShareholderInfo(ShareholderInfo shareholderInfo) {
|
|
|
shareholderInfo.setCreateTime(DateUtils.getNowDate());
|
|
|
return shareholderInfoMapper.insertShareholderInfo(shareholderInfo);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 修改股东信息
|
|
|
- *
|
|
|
+ *
|
|
|
* @param shareholderInfo 股东信息
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int updateShareholderInfo(ShareholderInfo shareholderInfo)
|
|
|
- {
|
|
|
+ public int updateShareholderInfo(ShareholderInfo shareholderInfo) {
|
|
|
shareholderInfo.setUpdateTime(DateUtils.getNowDate());
|
|
|
return shareholderInfoMapper.updateShareholderInfo(shareholderInfo);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 批量删除股东信息
|
|
|
- *
|
|
|
+ *
|
|
|
* @param shareholderIds 需要删除的股东信息主键
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int deleteShareholderInfoByShareholderIds(Long[] shareholderIds)
|
|
|
- {
|
|
|
+ public int deleteShareholderInfoByShareholderIds(Long[] shareholderIds) {
|
|
|
return shareholderInfoMapper.deleteShareholderInfoByShareholderIds(shareholderIds);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 删除股东信息信息
|
|
|
- *
|
|
|
+ *
|
|
|
* @param shareholderId 股东信息主键
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int deleteShareholderInfoByShareholderId(Long shareholderId)
|
|
|
- {
|
|
|
+ public int deleteShareholderInfoByShareholderId(Long shareholderId) {
|
|
|
return shareholderInfoMapper.deleteShareholderInfoByShareholderId(shareholderId);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public ShareholderPicVO getShareholderPic() {
|
|
|
+ ShareholderInfo info;
|
|
|
try {
|
|
|
//获取主体公司,如果未获取到,则直接提示
|
|
|
- ShareholderInfo info = shareholderInfoMapper.getSubjectCompany();
|
|
|
- if (Objects.isNull(info)){
|
|
|
- return null;
|
|
|
+ info = shareholderInfoMapper.getSubjectCompany();
|
|
|
+ } catch (Exception e) {
|
|
|
+ //如果是多主体公司,抛出自定义异常
|
|
|
+ throw new OnlyOneMainCompanyAllowedException();
|
|
|
+ }
|
|
|
+ if (Objects.isNull(info)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ //封装返回值
|
|
|
+ ShareholderPicVO vo = ShareholderPicVO.builder()
|
|
|
+ .id(info.getShareholderId())
|
|
|
+ .name(info.getShareholderName())
|
|
|
+ .companyValuation(info.getCompanyValuation())
|
|
|
+ .shareholdingRatio(info.getShareholdingRatio())
|
|
|
+ .build();
|
|
|
+
|
|
|
+ // ----- 根据股东信息来显示内容
|
|
|
+ //获取登录用户所绑定的股东信息;如果不是股东就抛异常
|
|
|
+ Long userId = SecurityUtils.getUserId();
|
|
|
+ try {
|
|
|
+ ShareholderInfo shareholderInfo = shareholderInfoMapper.selectShareholderInfoByUserId(userId);
|
|
|
+ Long shareholderId = shareholderInfo.getShareholderId();
|
|
|
+ String[] str = shareholderInfo.getAncestors().split(",");
|
|
|
+ List<Long> ancestors = Arrays.stream(str) .map(Long::parseLong).collect(Collectors.toList());
|
|
|
+ //获取股东的role_id
|
|
|
+ Long shareholderRoleId = shareholderInfoMapper.selectShareholderRoleIdByUserId(userId);
|
|
|
+
|
|
|
+ log.info("当前登录用户所绑定的股东:{}", shareholderInfo.getShareholderName());
|
|
|
+
|
|
|
+
|
|
|
+ List<ShareholderUpPicVO> ups;
|
|
|
+ //如果是管理员 查什么写好的,如果不是查我们自己的
|
|
|
+ if (shareholderRoleId == USER_ROLE_ID){
|
|
|
+ List<ShareholderUpPicVO> oneselfNodes = shareholderInfoMapper.getOneSelfNode(shareholderId,ancestors);
|
|
|
+ ups = ForestNodeMerger2.merge(oneselfNodes);
|
|
|
+ }else{
|
|
|
+ //获取主体上层的所有节点
|
|
|
+ List<ShareholderUpPicVO> upNodes = shareholderInfoMapper.getAllUpNode();
|
|
|
+ ups = ForestNodeMerger2.merge(upNodes);
|
|
|
}
|
|
|
- //封装返回值
|
|
|
- ShareholderPicVO vo =ShareholderPicVO.builder()
|
|
|
- .id(info.getShareholderId())
|
|
|
- .name(info.getShareholderName())
|
|
|
- .companyValuation(info.getCompanyValuation())
|
|
|
- .shareholdingRatio(info.getShareholdingRatio())
|
|
|
- .build();
|
|
|
- //获取主体上层的所有节点
|
|
|
- List<ShareholderUpPicVO> upNodes = shareholderInfoMapper.getAllUpNode();
|
|
|
- List<ShareholderUpPicVO> ups = ForestNodeMerger2.merge(upNodes);
|
|
|
- if (!ups.isEmpty()){
|
|
|
+
|
|
|
+
|
|
|
+ if (!ups.isEmpty()) {
|
|
|
List<ShareholderUpPicVO> parents = ups.get(0).getParents();
|
|
|
//如果公司存在估值,则递归生成股份估值信息
|
|
|
- if (Objects.nonNull(info.getCompanyValuation())){
|
|
|
- setShareholdingRatio(parents,info.getCompanyValuation());
|
|
|
+ if (Objects.nonNull(info.getCompanyValuation())) {
|
|
|
+ setShareholdingRatio(parents, info.getCompanyValuation());
|
|
|
}
|
|
|
vo.setParents(parents);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
//获取主体下层的所有节点
|
|
|
List<ShareholderDownPicVO> downNodes = shareholderInfoMapper.getAllDownNode();
|
|
|
List<ShareholderDownPicVO> downs = ForestNodeMerger.merge(downNodes);
|
|
|
- if (!downs.isEmpty()){
|
|
|
+ if (!downs.isEmpty()) {
|
|
|
vo.setChildren(downs.get(0).getChildren());
|
|
|
}
|
|
|
return vo;
|
|
|
} catch (Exception e) {
|
|
|
- throw new OnlyOneMainCompanyAllowedException();
|
|
|
+ throw new urNotshareholderException();
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -160,11 +195,11 @@ public class ShareholderInfoServiceImpl extends ServiceImpl<ShareholderInfoMappe
|
|
|
}
|
|
|
|
|
|
//递归赋值股份信息
|
|
|
- private void setShareholdingRatio(List<ShareholderUpPicVO> list, BigDecimal equityValuation){
|
|
|
+ private void setShareholdingRatio(List<ShareholderUpPicVO> list, BigDecimal equityValuation) {
|
|
|
for (ShareholderUpPicVO vo : list) {
|
|
|
vo.setValuation(equityValuation.divide(new BigDecimal(100)).multiply(vo.getShareholdingRatio()).setScale(2, RoundingMode.UP));
|
|
|
- if (!CollectionUtils.isEmpty(vo.getParents())){
|
|
|
- setShareholdingRatio(vo.getParents(),vo.getValuation());
|
|
|
+ if (!CollectionUtils.isEmpty(vo.getParents())) {
|
|
|
+ setShareholdingRatio(vo.getParents(), vo.getValuation());
|
|
|
}
|
|
|
}
|
|
|
}
|