|
@@ -1,6 +1,8 @@
|
|
|
package com.imed.costaccount.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
@@ -8,6 +10,8 @@ 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.common.util.Result;
|
|
|
+import com.imed.costaccount.constants.NumberConstant;
|
|
|
import com.imed.costaccount.mapper.DepartmentMapper;
|
|
|
import com.imed.costaccount.model.Department;
|
|
|
import com.imed.costaccount.model.Hospital;
|
|
@@ -15,6 +19,7 @@ import com.imed.costaccount.model.User;
|
|
|
import com.imed.costaccount.model.dto.DepartmentRequest;
|
|
|
import com.imed.costaccount.model.vo.DepartmentVO;
|
|
|
import com.imed.costaccount.service.DepartmentService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.shiro.SecurityUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -23,11 +28,13 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+@Slf4j
|
|
|
@Service("departmentService")
|
|
|
public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Department> implements DepartmentService {
|
|
|
|
|
@@ -43,7 +50,7 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
- public PageUtils queryList(Integer current, Integer pageSize,Integer hospId, String name) {
|
|
|
+ public PageUtils queryList(Integer current, Integer pageSize,Long hospId, String name) {
|
|
|
Page<Department> departPage = new Page<>(current, pageSize);
|
|
|
Page<Department> pages = this.page(departPage, new QueryWrapper<Department>().lambda()
|
|
|
.eq(!StringUtils.isEmpty(hospId), Department::getHospId, hospId)
|
|
@@ -72,7 +79,7 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
- public List<Department> getByDepartment(Integer id,String departmentName,String departmentCode,Integer hospId) {
|
|
|
+ public List<Department> getByDepartment(Integer id,String departmentName,String departmentCode,Long hospId) {
|
|
|
LambdaQueryWrapper<Department> wrapper = new QueryWrapper<Department>().lambda()
|
|
|
.eq(!StringUtils.isEmpty(id), Department::getId, id)
|
|
|
.like(!StringUtils.isEmpty(departmentName), Department::getDepartmentName, departmentName)
|
|
@@ -92,7 +99,7 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
|
|
@Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
|
|
|
public void addDepartment(DepartmentRequest departmentRequest) {
|
|
|
User user = (User) SecurityUtils.getSubject().getPrincipal();
|
|
|
- Integer hospId = user.getHospId();
|
|
|
+ Long hospId = user.getHospId();
|
|
|
// 查询所有的科室信息
|
|
|
List<Department> departmentList = baseMapper.selectList(new QueryWrapper<Department>().lambda().eq(Department::getHospId, hospId));
|
|
|
Map<String, List<Department>> map =
|
|
@@ -116,8 +123,8 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
|
|
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
|
|
|
public void updateByDepartment(DepartmentRequest departmentRequest) {
|
|
|
User user = (User) SecurityUtils.getSubject().getPrincipal();
|
|
|
- Integer hospId = user.getHospId();
|
|
|
- Integer id = departmentRequest.getId();
|
|
|
+ Long hospId = user.getHospId();
|
|
|
+ Long id = departmentRequest.getId();
|
|
|
Department department = baseMapper.selectById(id);
|
|
|
if (Objects.isNull(department)){
|
|
|
throw new CostException("未找到相关科室信息");
|
|
@@ -137,4 +144,83 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
|
|
departmentResponse.setHospId(hospId);
|
|
|
baseMapper.insert(departmentResponse);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导入科室信息
|
|
|
+ *
|
|
|
+ * @param list
|
|
|
+ * @param hospId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Result importDepartment(List<List<Object>> list, Long hospId) {
|
|
|
+ for (int i = list.size() - 1; i >= 0; i--) {
|
|
|
+ if (i == NumberConstant.ZERO || i == NumberConstant.ONE || i == NumberConstant.TWO || i == NumberConstant.THREE) {
|
|
|
+ list.remove(list.get(i));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.info("读取的数据为:{}", list);
|
|
|
+ List<Department> departmentList = new ArrayList<>();
|
|
|
+ List<String> errRowNums = new ArrayList<>();
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
+ List<Object> data = list.get(i);
|
|
|
+ log.info("得到用户输入的数据为:{}", data);
|
|
|
+ Department department = new Department();
|
|
|
+ department.setHospId(hospId);
|
|
|
+ department.setCreateTime(System.currentTimeMillis());
|
|
|
+ int size = data.size();
|
|
|
+ if (size != 5) {
|
|
|
+ // 补充读取的null问题
|
|
|
+ if (size == 4) {
|
|
|
+ data.add(StrUtil.EMPTY);
|
|
|
+ }
|
|
|
+ for (int j = 0; j < 3; j++) {
|
|
|
+ if (Objects.isNull(data.get(j))) {
|
|
|
+ data.set(j, StrUtil.EMPTY);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (int j = 0; j < 3; j++) {
|
|
|
+ String str = String.valueOf(data.get(j));
|
|
|
+ log.info("得到的字符串{}", str);
|
|
|
+ if (StrUtil.isBlank(str)) {
|
|
|
+ errRowNums.add("" + (i + 3));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (j == 0) {
|
|
|
+ // Excel里面输入医院名称 根据医院名称解析
|
|
|
+ Hospital hospital = hospitalService.getByName(str);
|
|
|
+ department.setHospId(hospital.getId());
|
|
|
+ } else if (j == 1) {
|
|
|
+ department.setDepartmentName(str);
|
|
|
+ } else {
|
|
|
+ department.setDepartmentCode(str);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ departmentList.add(department);
|
|
|
+ }
|
|
|
+ if (CollUtil.isNotEmpty(errRowNums)) {
|
|
|
+ String collect = errRowNums.stream().collect(Collectors.joining(StrUtil.COMMA));
|
|
|
+ throw new CostException(500, "第" + collect + "行数据异常");
|
|
|
+ }
|
|
|
+ // 校验输入的Department是否存在 输入的科室里面筛选出已经存在的科室信息
|
|
|
+ List<Department> realDepartments = new ArrayList<>();
|
|
|
+ departmentList.forEach(i -> {
|
|
|
+ Department one = getOne(
|
|
|
+ new QueryWrapper<Department>().lambda()
|
|
|
+ .eq(Department::getDepartmentCode, i.getDepartmentCode())
|
|
|
+ .eq(Department::getHospId, i.getHospId())
|
|
|
+ );
|
|
|
+ if (Objects.nonNull(one)) {
|
|
|
+ realDepartments.add(one);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ departmentList = departmentList.stream().filter(i -> !realDepartments.stream().map(Department::getDepartmentCode).collect(Collectors.toList()).contains(i.getDepartmentCode())).collect(Collectors.toList());
|
|
|
+ this.saveBatch(departmentList);
|
|
|
+ if (CollectionUtils.isEmpty(realDepartments)){
|
|
|
+ return Result.build(200,"数据导入成功",null);
|
|
|
+ }else {
|
|
|
+ return Result.build(200, "有" + realDepartments.size() + "条数据已存在,未被导入", null);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|