|
@@ -4,14 +4,17 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.imed.costaccount.common.exception.CostException;
|
|
|
+import com.imed.costaccount.common.util.JsonUtil;
|
|
|
import com.imed.costaccount.common.util.PageUtils;
|
|
|
+import com.imed.costaccount.constants.NumberConstant;
|
|
|
import com.imed.costaccount.mapper.CostAccountShareMapper;
|
|
|
-import com.imed.costaccount.model.CostAccountShare;
|
|
|
-import com.imed.costaccount.model.Responsibility;
|
|
|
-import com.imed.costaccount.model.User;
|
|
|
+import com.imed.costaccount.model.*;
|
|
|
import com.imed.costaccount.model.dto.CostAccountShareEditDto;
|
|
|
import com.imed.costaccount.model.dto.CostAccountShareSaveDto;
|
|
|
+import com.imed.costaccount.model.dto.ShareParamEditDto;
|
|
|
import com.imed.costaccount.model.vo.CostAccountShareVO;
|
|
|
+import com.imed.costaccount.model.vo.CostShareParamVO;
|
|
|
+import com.imed.costaccount.model.vo.ShareParamProportionVO;
|
|
|
import com.imed.costaccount.service.CostAccountShareService;
|
|
|
import com.imed.costaccount.utils.BeanUtil;
|
|
|
import org.apache.shiro.SecurityUtils;
|
|
@@ -22,9 +25,11 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
+import java.util.concurrent.atomic.AtomicReference;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
@@ -34,6 +39,15 @@ public class CostAccountShareServiceImpl extends ServiceImpl<CostAccountShareMap
|
|
|
@Autowired
|
|
|
private ResponsibilityServiceImpl responsibilityService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private AccountingServiceImpl accountingService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CostShareLevelServiceImpl costShareLevelService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CostShareParamServiceImpl costShareParamService;
|
|
|
+
|
|
|
/**
|
|
|
* 分页查询责任中心成本对照相关数据
|
|
|
*
|
|
@@ -47,7 +61,7 @@ public class CostAccountShareServiceImpl extends ServiceImpl<CostAccountShareMap
|
|
|
Page<CostAccountShare> costAccountSharePage = new Page<>(page, pageSize);
|
|
|
Page<CostAccountShare> pages = this.page(costAccountSharePage, new QueryWrapper<CostAccountShare>().lambda()
|
|
|
.eq(!StringUtils.isEmpty(hospId), CostAccountShare::getHospId, hospId)
|
|
|
- .like(!StringUtils.isEmpty(name), CostAccountShare::getAccountingName, name)
|
|
|
+ .like(!StringUtils.isEmpty(name), CostAccountShare::getResponsibilityName, name)
|
|
|
.orderByAsc(CostAccountShare::getShareLevel));
|
|
|
List<CostAccountShare> costAccountShareList = pages.getRecords();
|
|
|
List<CostAccountShareVO> costAccountShareVOList = BeanUtil.convertList(costAccountShareList, CostAccountShareVO.class);
|
|
@@ -66,14 +80,31 @@ public class CostAccountShareServiceImpl extends ServiceImpl<CostAccountShareMap
|
|
|
public void addCostAccountShare(CostAccountShareSaveDto costAccountShareSaveDto) {
|
|
|
User user = (User) SecurityUtils.getSubject().getPrincipal();
|
|
|
Integer hospId = user.getHospId();
|
|
|
- // 检验输入的责任中心是否存在
|
|
|
+ // 检验输入的数据的合理性
|
|
|
+ checkAccountShare(costAccountShareSaveDto, hospId);
|
|
|
+ CostAccountShare costAccountShareRequest = BeanUtil.convertObj(costAccountShareSaveDto, CostAccountShare.class);
|
|
|
+ costAccountShareRequest.setHospId(hospId);
|
|
|
+ costAccountShareRequest.setCreateTime(System.currentTimeMillis());
|
|
|
+ baseMapper.insert(costAccountShareRequest);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 检验输入数据的合理性
|
|
|
+ * @param costAccountShareSaveDto
|
|
|
+ * @param hospId
|
|
|
+ */
|
|
|
+ private void checkAccountShare(CostAccountShareSaveDto costAccountShareSaveDto, Integer hospId) {
|
|
|
Integer responsibilityId = costAccountShareSaveDto.getResponsibilityId();
|
|
|
- Responsibility responsibility = responsibilityService.getOne(new QueryWrapper<Responsibility>().lambda().eq(Responsibility::getId, responsibilityId));
|
|
|
+ Responsibility responsibility = responsibilityService.getOne(new QueryWrapper<Responsibility>().lambda().eq(Responsibility::getHospId,hospId).eq(Responsibility::getId, responsibilityId));
|
|
|
if (Objects.isNull(responsibility)){
|
|
|
throw new CostException(500,"输入的责任不存在");
|
|
|
}
|
|
|
if (costAccountShareSaveDto.getAccountingId() > 0){
|
|
|
- throw new CostException(500,"输入的成本科目不存在");
|
|
|
+ // 如果输入成本科目的情况下
|
|
|
+ Accounting accounting = accountingService.getOne(new QueryWrapper<Accounting>().lambda().eq(Accounting::getHospId, hospId).eq(Accounting::getId, costAccountShareSaveDto.getAccountingId()));
|
|
|
+ if (Objects.isNull(accounting)){
|
|
|
+ throw new CostException(500,"输入的成本科目不存在");
|
|
|
+ }
|
|
|
}
|
|
|
// 检验输入的责任中心与匹配的成本科目是否存在
|
|
|
List<CostAccountShare> costAccountShareList = baseMapper.selectList(new QueryWrapper<CostAccountShare>().lambda().eq(CostAccountShare::getHospId,hospId));
|
|
@@ -85,10 +116,17 @@ public class CostAccountShareServiceImpl extends ServiceImpl<CostAccountShareMap
|
|
|
throw new CostException(500,"输入的责任中心对应的成本科目已存在");
|
|
|
}
|
|
|
}
|
|
|
- CostAccountShare costAccountShareRequest = BeanUtil.convertObj(costAccountShareSaveDto, CostAccountShare.class);
|
|
|
- costAccountShareRequest.setHospId(hospId);
|
|
|
- costAccountShareRequest.setCreateTime(System.currentTimeMillis());
|
|
|
- baseMapper.insert(costAccountShareRequest);
|
|
|
+ // 检验输入的这个责任中心是否允许输入成本科目
|
|
|
+ Integer shareLevel = responsibility.getShareLevel();
|
|
|
+ CostShareLevel costShareLevel = costShareLevelService.getOne(new QueryWrapper<CostShareLevel>().lambda()
|
|
|
+ .eq(CostShareLevel::getHospId, hospId).eq(CostShareLevel::getId, shareLevel));
|
|
|
+ if (Objects.nonNull(costShareLevel)){
|
|
|
+ if (costAccountShareSaveDto.getAccountingId()>0 && NumberConstant.ZERO.equals(costShareLevel.getCalcType())){
|
|
|
+ throw new CostException(500,"合并计算不允许选择成本科目");
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ throw new CostException(500,"对不起该责任中心没有计算方式");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -99,6 +137,8 @@ public class CostAccountShareServiceImpl extends ServiceImpl<CostAccountShareMap
|
|
|
@Override
|
|
|
@Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
|
|
|
public void updateByCostAccountShare(CostAccountShareEditDto costAccountShareEditDto) {
|
|
|
+ User user = (User) SecurityUtils.getSubject().getPrincipal();
|
|
|
+ Integer hospId = user.getHospId();
|
|
|
Integer id = costAccountShareEditDto.getId();
|
|
|
CostAccountShare costAccountShare = baseMapper.selectById(id);
|
|
|
if (Objects.isNull(costAccountShare)){
|
|
@@ -106,11 +146,87 @@ public class CostAccountShareServiceImpl extends ServiceImpl<CostAccountShareMap
|
|
|
}
|
|
|
baseMapper.deleteById(id);
|
|
|
// 新增责任中心成本对照数据
|
|
|
+ CostAccountShareSaveDto costAccountShareSaveDto = BeanUtil.convertObj(costAccountShareEditDto, CostAccountShareSaveDto.class);
|
|
|
+ // 检验输入的数据是否符合规则
|
|
|
+ checkAccountShare(costAccountShareSaveDto,hospId);
|
|
|
+
|
|
|
CostAccountShare costAccountShareRequest = BeanUtil.convertObj(costAccountShareEditDto, CostAccountShare.class);
|
|
|
costAccountShareRequest.setId(null);
|
|
|
+ costAccountShareRequest.setHospId(hospId);
|
|
|
costAccountShareRequest.setParamList(costAccountShare.getParamList());
|
|
|
costAccountShareRequest.setCreateTime(System.currentTimeMillis());
|
|
|
baseMapper.insert(costAccountShareRequest);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改成本分摊参数的设置
|
|
|
+ *
|
|
|
+ * @param shareParamEditDto
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
|
|
|
+ public void updateShareParam(ShareParamEditDto shareParamEditDto) {
|
|
|
+ User user = (User) SecurityUtils.getSubject().getPrincipal();
|
|
|
+ Integer hospId = user.getHospId();
|
|
|
+ Integer id = shareParamEditDto.getId();
|
|
|
+ CostAccountShare costAccountShare = baseMapper.selectOne(new QueryWrapper<CostAccountShare>().lambda()
|
|
|
+ .eq(CostAccountShare::getHospId, hospId)
|
|
|
+ .eq(CostAccountShare::getId, id));
|
|
|
+ if (Objects.isNull(costAccountShare)){
|
|
|
+ throw new CostException(500,"责任中心成本数据不存在");
|
|
|
+ }
|
|
|
+ List<ShareParamProportionVO> shareParamProportionVOList = shareParamEditDto.getShareParamProportionVOList();
|
|
|
+ // 检验输入的成本分摊参数是否存在
|
|
|
+ List<CostShareParamVO> costShareParamServiceAll = costShareParamService.getAll(hospId);
|
|
|
+ Map<Integer, List<CostShareParamVO>> listMap = costShareParamServiceAll.stream().collect(Collectors.groupingBy(CostShareParamVO::getId));
|
|
|
+ shareParamProportionVOList.forEach(i->{
|
|
|
+ if (CollectionUtils.isEmpty(listMap.get(i.getId()))){
|
|
|
+ throw new CostException(500,"分摊名称:"+i.getShareParamName()+"未找到");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ // 检验输入的数据的和是否是100
|
|
|
+ AtomicReference<Integer> sum= new AtomicReference<>(0);
|
|
|
+ shareParamProportionVOList.forEach(i->{
|
|
|
+ sum.updateAndGet(v -> v + i.getShareParamPopout());
|
|
|
+ });
|
|
|
+ int max = Integer.parseInt(sum.toString());
|
|
|
+ if (!NumberConstant.ONE_HUNDRED.equals(max)){
|
|
|
+ throw new CostException(500,"分摊比例的和不是100");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 判断添加的分摊是否存在一样的
|
|
|
+ HashMap<Integer, ShareParamProportionVO> hashMap = new HashMap<>();
|
|
|
+ shareParamProportionVOList.forEach(i->{
|
|
|
+ Integer paramId = i.getId();
|
|
|
+ if (hashMap.containsKey(paramId)){
|
|
|
+ throw new CostException(500,"不可以添加相同的分摊参数");
|
|
|
+ }
|
|
|
+ hashMap.put(paramId,i);
|
|
|
+ });
|
|
|
+
|
|
|
+ // TODO 暂时还考虑不到如何筛选选中的
|
|
|
+ String paramList = JsonUtil.toJSONString(shareParamProportionVOList);
|
|
|
+ costAccountShare.setParamList(paramList);
|
|
|
+ baseMapper.updateById(costAccountShare);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取责任中心成本表的分摊参数的集合
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @param hospId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<ShareParamProportionVO> selectShareParamById(Integer id, Integer hospId) {
|
|
|
+ CostAccountShare costAccountShare = baseMapper.selectOne(new QueryWrapper<CostAccountShare>().lambda()
|
|
|
+ .eq(CostAccountShare::getHospId, hospId).eq(CostAccountShare::getId, id));
|
|
|
+ if (Objects.isNull(costAccountShare)){
|
|
|
+ throw new CostException(500,"责任中心成本不存在");
|
|
|
+ }
|
|
|
+ String paramList = costAccountShare.getParamList();
|
|
|
+ return JsonUtil.toList(paramList, ShareParamProportionVO.class);
|
|
|
+ }
|
|
|
+
|
|
|
}
|