|
@@ -0,0 +1,116 @@
|
|
|
|
+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.PageUtils;
|
|
|
|
+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.dto.CostAccountShareEditDto;
|
|
|
|
+import com.imed.costaccount.model.dto.CostAccountShareSaveDto;
|
|
|
|
+import com.imed.costaccount.model.vo.CostAccountShareVO;
|
|
|
|
+import com.imed.costaccount.service.CostAccountShareService;
|
|
|
|
+import com.imed.costaccount.utils.BeanUtil;
|
|
|
|
+import org.apache.shiro.SecurityUtils;
|
|
|
|
+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("costAccountShareService")
|
|
|
|
+public class CostAccountShareServiceImpl extends ServiceImpl<CostAccountShareMapper, CostAccountShare> implements CostAccountShareService {
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private ResponsibilityServiceImpl responsibilityService;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 分页查询责任中心成本对照相关数据
|
|
|
|
+ *
|
|
|
|
+ * @param page
|
|
|
|
+ * @param pageSize
|
|
|
|
+ * @param name
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public PageUtils queryList(Integer page, Integer pageSize, String name, Integer hospId) {
|
|
|
|
+ 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)
|
|
|
|
+ .orderByAsc(CostAccountShare::getShareLevel));
|
|
|
|
+ List<CostAccountShare> costAccountShareList = pages.getRecords();
|
|
|
|
+ List<CostAccountShareVO> costAccountShareVOList = BeanUtil.convertList(costAccountShareList, CostAccountShareVO.class);
|
|
|
|
+ PageUtils pageUtils = new PageUtils(pages);
|
|
|
|
+ pageUtils.setList(costAccountShareVOList);
|
|
|
|
+ return pageUtils;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 保存责任中心成本对照表
|
|
|
|
+ *
|
|
|
|
+ * @param costAccountShareSaveDto
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
|
|
|
|
+ public void addCostAccountShare(CostAccountShareSaveDto costAccountShareSaveDto) {
|
|
|
|
+ User user = (User) SecurityUtils.getSubject().getPrincipal();
|
|
|
|
+ Integer hospId = user.getHospId();
|
|
|
|
+ // 检验输入的责任中心是否存在
|
|
|
|
+ Integer responsibilityId = costAccountShareSaveDto.getResponsibilityId();
|
|
|
|
+ Responsibility responsibility = responsibilityService.getOne(new QueryWrapper<Responsibility>().lambda().eq(Responsibility::getId, responsibilityId));
|
|
|
|
+ if (Objects.isNull(responsibility)){
|
|
|
|
+ throw new CostException(500,"输入的责任不存在");
|
|
|
|
+ }
|
|
|
|
+ if (costAccountShareSaveDto.getAccountingId() > 0){
|
|
|
|
+ throw new CostException(500,"输入的成本科目不存在");
|
|
|
|
+ }
|
|
|
|
+ // 检验输入的责任中心与匹配的成本科目是否存在
|
|
|
|
+ List<CostAccountShare> costAccountShareList = baseMapper.selectList(new QueryWrapper<CostAccountShare>().lambda().eq(CostAccountShare::getHospId,hospId));
|
|
|
|
+ Map<String, List<CostAccountShare>> costAccountMap = costAccountShareList.stream().collect(Collectors.groupingBy(CostAccountShare::getResponsibilityCode));
|
|
|
|
+ List<CostAccountShare> list = costAccountMap.get(costAccountShareSaveDto.getResponsibilityCode());
|
|
|
|
+ if (!CollectionUtils.isEmpty(list)){
|
|
|
|
+ String accountingCode = list.get(0).getAccountingCode();
|
|
|
|
+ if (accountingCode.equals(costAccountShareSaveDto.getAccountingCode())){
|
|
|
|
+ throw new CostException(500,"输入的责任中心对应的成本科目已存在");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ CostAccountShare costAccountShareRequest = BeanUtil.convertObj(costAccountShareSaveDto, CostAccountShare.class);
|
|
|
|
+ costAccountShareRequest.setHospId(hospId);
|
|
|
|
+ costAccountShareRequest.setCreateTime(System.currentTimeMillis());
|
|
|
|
+ baseMapper.insert(costAccountShareRequest);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 修改成本中心责任对照表
|
|
|
|
+ *
|
|
|
|
+ * @param costAccountShareEditDto
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
|
|
|
|
+ public void updateByCostAccountShare(CostAccountShareEditDto costAccountShareEditDto) {
|
|
|
|
+ Integer id = costAccountShareEditDto.getId();
|
|
|
|
+ CostAccountShare costAccountShare = baseMapper.selectById(id);
|
|
|
|
+ if (Objects.isNull(costAccountShare)){
|
|
|
|
+ throw new CostException(500,"责任中心成本数据不存在");
|
|
|
|
+ }
|
|
|
|
+ baseMapper.deleteById(id);
|
|
|
|
+ // 新增责任中心成本对照数据
|
|
|
|
+ CostAccountShare costAccountShareRequest = BeanUtil.convertObj(costAccountShareEditDto, CostAccountShare.class);
|
|
|
|
+ costAccountShareRequest.setId(null);
|
|
|
|
+ costAccountShareRequest.setParamList(costAccountShare.getParamList());
|
|
|
|
+ costAccountShareRequest.setCreateTime(System.currentTimeMillis());
|
|
|
|
+ baseMapper.insert(costAccountShareRequest);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|