|
@@ -0,0 +1,182 @@
|
|
|
|
+package com.imed.costaccount.service.impl;
|
|
|
|
+
|
|
|
|
+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.BeanUtil;
|
|
|
|
+import com.imed.costaccount.common.util.PageUtils;
|
|
|
|
+import com.imed.costaccount.constants.NumberConstant;
|
|
|
|
+import com.imed.costaccount.mapper.CostIncomeGroupSetMapper;
|
|
|
|
+import com.imed.costaccount.model.CostIncomeGroupSet;
|
|
|
|
+import com.imed.costaccount.model.Responsibility;
|
|
|
|
+import com.imed.costaccount.model.dto.CostIncomeGroupSetEditDto;
|
|
|
|
+import com.imed.costaccount.model.dto.CostIncomeGroupSetSaveDto;
|
|
|
|
+import com.imed.costaccount.model.vo.CostIncomeGroupSetVO;
|
|
|
|
+import com.imed.costaccount.service.CostIncomeGroupSetService;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.transaction.annotation.Propagation;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
|
+
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+import java.util.Objects;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+@Service("costIncomeGroupSetService")
|
|
|
|
+public class CostIncomeGroupSetServiceImpl extends ServiceImpl<CostIncomeGroupSetMapper, CostIncomeGroupSet> implements CostIncomeGroupSetService {
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private ResponsibilityServiceImpl responsibilityService;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 分页查询
|
|
|
|
+ *
|
|
|
|
+ * @param current
|
|
|
|
+ * @param pageSize
|
|
|
|
+ * @param hospId
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public PageUtils queryList(Integer current, Integer pageSize, Long hospId) {
|
|
|
|
+ Page<CostIncomeGroupSet> costIncomeGroupSetPage = new Page<>(current, pageSize);
|
|
|
|
+ Page<CostIncomeGroupSet> pages = this.page(costIncomeGroupSetPage, new QueryWrapper<CostIncomeGroupSet>().lambda()
|
|
|
|
+ .eq(CostIncomeGroupSet::getHospId, hospId)
|
|
|
|
+ .orderByDesc(CostIncomeGroupSet::getCreateTime));
|
|
|
|
+ List<CostIncomeGroupSet> records = pages.getRecords();
|
|
|
|
+ List<Responsibility> responsibilityList = responsibilityService.list(new QueryWrapper<Responsibility>().lambda()
|
|
|
|
+ .eq(Responsibility::getHospId, hospId));
|
|
|
|
+ List<CostIncomeGroupSetVO> costIncomeGroupSetVOList = BeanUtil.convertList(records, CostIncomeGroupSetVO.class);
|
|
|
|
+ if (!CollectionUtils.isEmpty(responsibilityList)) {
|
|
|
|
+ Map<String, List<Responsibility>> listMap = responsibilityList.stream().collect(Collectors.groupingBy(Responsibility::getResponsibilityCode));
|
|
|
|
+ costIncomeGroupSetVOList.forEach(i -> {
|
|
|
|
+ String responsibilityCode = i.getResponsibilityCode();
|
|
|
|
+ if (!StringUtils.isEmpty(responsibilityCode)) {
|
|
|
|
+ List<Responsibility> responsibilities = listMap.get(responsibilityCode);
|
|
|
|
+ if (!CollectionUtils.isEmpty(responsibilities)) {
|
|
|
|
+ i.setResponsibilityName(responsibilities.get(0).getResponsibilityName());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ PageUtils pageUtils = new PageUtils(pages);
|
|
|
|
+ pageUtils.setList(costIncomeGroupSetVOList);
|
|
|
|
+ return pageUtils;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 根据Id获取对应的收入归集设置的数据
|
|
|
|
+ *
|
|
|
|
+ * @param id
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public CostIncomeGroupSetVO getByIncomeGroupId(Long id, Long hospId) {
|
|
|
|
+ CostIncomeGroupSet costIncomeGroupSet = baseMapper.selectById(id);
|
|
|
|
+ if (Objects.isNull(costIncomeGroupSet)) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ CostIncomeGroupSetVO costIncomeGroupSetVO = BeanUtil.convertObj(costIncomeGroupSet, CostIncomeGroupSetVO.class);
|
|
|
|
+ List<Responsibility> responsibilityList = responsibilityService.list(new QueryWrapper<Responsibility>().lambda()
|
|
|
|
+ .eq(Responsibility::getHospId, hospId));
|
|
|
|
+ if (!CollectionUtils.isEmpty(responsibilityList)) {
|
|
|
|
+ Map<String, List<Responsibility>> listMap = responsibilityList.stream().collect(Collectors.groupingBy(Responsibility::getResponsibilityCode));
|
|
|
|
+ String responsibilityCode = costIncomeGroupSetVO.getResponsibilityCode();
|
|
|
|
+ if (!StringUtils.isEmpty(responsibilityCode)) {
|
|
|
|
+ List<Responsibility> responsibilities = listMap.get(responsibilityCode);
|
|
|
|
+ if (!CollectionUtils.isEmpty(responsibilities)) {
|
|
|
|
+ costIncomeGroupSetVO.setResponsibilityName(responsibilities.get(0).getResponsibilityName());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return costIncomeGroupSetVO;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 保存收入归集设置的数据
|
|
|
|
+ *
|
|
|
|
+ * @param costIncomeGroupSetSaveDto
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
|
|
|
|
+ public void addCostIncomeGroupSet(CostIncomeGroupSetSaveDto costIncomeGroupSetSaveDto, Long hospId) {
|
|
|
|
+ // 检验输入的数据是否符合要求
|
|
|
|
+ checkIncomeGroupSet(costIncomeGroupSetSaveDto, hospId);
|
|
|
|
+ CostIncomeGroupSet costIncomeGroupSet = BeanUtil.convertObj(costIncomeGroupSetSaveDto, CostIncomeGroupSet.class);
|
|
|
|
+ costIncomeGroupSet.setCreateTime(System.currentTimeMillis());
|
|
|
|
+ costIncomeGroupSet.setHospId(hospId);
|
|
|
|
+ baseMapper.insert(costIncomeGroupSet);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 检验输入的数据是否符合要求
|
|
|
|
+ * @param costIncomeGroupSetSaveDto
|
|
|
|
+ * @param hospId
|
|
|
|
+ */
|
|
|
|
+ private void checkIncomeGroupSet(CostIncomeGroupSetSaveDto costIncomeGroupSetSaveDto, Long hospId) {
|
|
|
|
+ Integer sum = costIncomeGroupSetSaveDto.getOpenDepartmentProportion() + costIncomeGroupSetSaveDto.getStartDepartmentProportion();
|
|
|
|
+ if (!NumberConstant.ONE_HUNDRED.equals(sum)) {
|
|
|
|
+ throw new CostException(500, "输入的比例和不是100");
|
|
|
|
+ }
|
|
|
|
+ if (NumberConstant.TWO.equals(costIncomeGroupSetSaveDto.getOpenDepartmentStatus())
|
|
|
|
+ && NumberConstant.TWO.equals(costIncomeGroupSetSaveDto.getStartDepartmentStatus())) {
|
|
|
|
+ if (StringUtils.isEmpty(costIncomeGroupSetSaveDto.getResponsibilityCode())){
|
|
|
|
+ throw new CostException(500, "两个成本中心需要输入对应的责任中心");
|
|
|
|
+ }else {
|
|
|
|
+ costIncomeGroupSetSaveDto.setOpenDepartmentProportion(NumberConstant.ZERO);
|
|
|
|
+ costIncomeGroupSetSaveDto.setStartDepartmentProportion(NumberConstant.ZERO);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // 检验原始数据里面是否存在
|
|
|
|
+ List<CostIncomeGroupSet> costIncomeGroupSets = baseMapper.selectList(new QueryWrapper<CostIncomeGroupSet>().lambda()
|
|
|
|
+ .eq(CostIncomeGroupSet::getHospId, hospId));
|
|
|
|
+ List<CostIncomeGroupSet> costIncomeGroupSetList = costIncomeGroupSets.stream().filter(i ->
|
|
|
|
+ i.getOpenDepartmentStatus().equals(costIncomeGroupSetSaveDto.getOpenDepartmentStatus()) &&
|
|
|
|
+ i.getStartDepartmentStatus().equals(costIncomeGroupSetSaveDto.getStartDepartmentStatus())
|
|
|
|
+ ).collect(Collectors.toList());
|
|
|
|
+ if (!CollectionUtils.isEmpty(costIncomeGroupSetList)){
|
|
|
|
+ throw new CostException(500,"开单与执行的对应类型已经存在");
|
|
|
|
+ }
|
|
|
|
+ // 如果一个是收入中心一个是成本中心 那本自动调整比例设置为0 100 如果两个收益中心的话需要按照不理 都是成本中心就是0
|
|
|
|
+ if (!costIncomeGroupSetSaveDto.getOpenDepartmentStatus().equals(costIncomeGroupSetSaveDto.getStartDepartmentStatus())){
|
|
|
|
+ if (NumberConstant.ONE.equals(costIncomeGroupSetSaveDto.getOpenDepartmentStatus())){
|
|
|
|
+ costIncomeGroupSetSaveDto.setOpenDepartmentProportion(NumberConstant.ONE_HUNDRED);
|
|
|
|
+ costIncomeGroupSetSaveDto.setStartDepartmentProportion(NumberConstant.ZERO);
|
|
|
|
+ }else {
|
|
|
|
+ costIncomeGroupSetSaveDto.setOpenDepartmentProportion(NumberConstant.ZERO);
|
|
|
|
+ costIncomeGroupSetSaveDto.setStartDepartmentProportion(NumberConstant.ONE_HUNDRED);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 修改收入归集设置的数据
|
|
|
|
+ *
|
|
|
|
+ * @param costIncomeGroupSetEditDto
|
|
|
|
+ * @param hospId
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
|
|
|
|
+ public void updateByIncomeGroup(CostIncomeGroupSetEditDto costIncomeGroupSetEditDto, Long hospId) {
|
|
|
|
+ Long id = costIncomeGroupSetEditDto.getId();
|
|
|
|
+ CostIncomeGroupSet costIncomeGroupSet = baseMapper.selectById(id);
|
|
|
|
+ if (Objects.isNull(costIncomeGroupSet)) {
|
|
|
|
+ throw new CostException(500, "收入归集设置数据不存在");
|
|
|
|
+ }
|
|
|
|
+ baseMapper.deleteById(id);
|
|
|
|
+ CostIncomeGroupSetSaveDto costIncomeGroupSetSaveDto = BeanUtil.convertObj(costIncomeGroupSetEditDto, CostIncomeGroupSetSaveDto.class);
|
|
|
|
+ // 检验输入的数据是否存在
|
|
|
|
+ checkIncomeGroupSet(costIncomeGroupSetSaveDto,hospId);
|
|
|
|
+ CostIncomeGroupSet incomeGroupSet = BeanUtil.convertObj(costIncomeGroupSetEditDto, CostIncomeGroupSet.class);
|
|
|
|
+ incomeGroupSet.setHospId(hospId);
|
|
|
|
+ incomeGroupSet.setCreateTime(System.currentTimeMillis());
|
|
|
|
+ incomeGroupSet.setResponsibilityCode(costIncomeGroupSet.getResponsibilityCode());
|
|
|
|
+ incomeGroupSet.setAccountCode(costIncomeGroupSet.getAccountCode());
|
|
|
|
+ baseMapper.insert(incomeGroupSet);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|