123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- package com.imed.costaccount.service.impl;
- 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;
- 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.DateUtils;
- import com.imed.costaccount.common.util.JacksonUtil;
- import com.imed.costaccount.common.util.PageUtils;
- import com.imed.costaccount.constants.NumberConstant;
- import com.imed.costaccount.common.enums.DateStyleEnum;
- import com.imed.costaccount.mapper.CostCostingGroupMapper;
- import com.imed.costaccount.mapper.CostIncomeFileMapper;
- import com.imed.costaccount.mapper.CostIncomeGroupMapper;
- import com.imed.costaccount.mapper.ShareParamValueMapper;
- import com.imed.costaccount.model.*;
- import com.imed.costaccount.model.vo.CostIncomeFileVO;
- import com.imed.costaccount.model.vo.IncomeErrorMessage;
- import com.imed.costaccount.service.CostIncomeFileService;
- 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.web.multipart.MultipartFile;
- import java.util.Date;
- import java.util.List;
- import java.util.Objects;
- import java.util.stream.Collectors;
- @Service("costIncomeFileService")
- public class CostIncomeFileServiceImpl extends ServiceImpl<CostIncomeFileMapper, CostIncomeFile> implements CostIncomeFileService {
- private static final String INCOME_FILETYPE = "收入数据";
- private static final String COST_FILETYPE = "成本数据";
- private static final String SHAREPARAM_FILETYPE = "成本分摊参数数据";
- private final CostIncomeGroupMapper costIncomeGroupMapper;
- private final CostCostingGroupMapper costCostingGroupMapper;
- private final ShareParamValueMapper paramValueMapper;
- public CostIncomeFileServiceImpl(CostIncomeGroupMapper costIncomeGroupMapper, CostCostingGroupMapper costCostingGroupMapper, ShareParamValueMapper paramValueMapper) {
- this.costIncomeGroupMapper = costIncomeGroupMapper;
- this.costCostingGroupMapper = costCostingGroupMapper;
- this.paramValueMapper = paramValueMapper;
- }
- /**
- * 保存文件上传记录
- *
- * @param list 文件数据
- * @param user 当前用户
- * @param file 上传文件
- * @param hospId 医院Id
- * @param incomeErrorMessageList 错误信息
- * @param uploadFile 文件路径
- * @return
- */
- @Override
- public CostIncomeFile saveCostIncomeFile(List<List<Object>> list, User user, MultipartFile file, Long hospId, List<IncomeErrorMessage> incomeErrorMessageList, String uploadFile, Integer fileType, Integer year, Integer month) {
- CostIncomeFile costIncomeFile = new CostIncomeFile();
- String substring = file.getOriginalFilename().substring(0, file.getOriginalFilename().lastIndexOf(".")) + System.currentTimeMillis() + ".xsl";
- costIncomeFile.setFileName(substring);
- costIncomeFile.setFileUrl(uploadFile);
- costIncomeFile.setTotalAmount(list.size());
- if (!CollectionUtils.isEmpty(incomeErrorMessageList)) {
- costIncomeFile.setSuccessAmount(NumberConstant.ZERO);
- costIncomeFile.setErrorList(JacksonUtil.obj2Str(incomeErrorMessageList));
- } else {
- costIncomeFile.setSuccessAmount(list.size());
- }
- if (NumberConstant.ONE.equals(fileType)) {
- costIncomeFile.setFileType(SHAREPARAM_FILETYPE);
- } else if (NumberConstant.TWO.equals(fileType)) {
- costIncomeFile.setFileType(INCOME_FILETYPE);
- } else if (NumberConstant.THREE.equals(fileType)) {
- costIncomeFile.setFileType(COST_FILETYPE);
- } else {
- costIncomeFile.setFileType(file.getContentType());
- }
- costIncomeFile.setHospId(hospId);
- costIncomeFile.setUserName(user.getName());
- costIncomeFile.setUserId(user.getId());
- costIncomeFile.setDateYear(year);
- costIncomeFile.setDateMonth(month);
- costIncomeFile.setCreateTime(System.currentTimeMillis());
- this.save(costIncomeFile);
- return costIncomeFile;
- }
- /**
- * 分页查询查询记录数据
- *
- * @param current
- * @param pageSize
- * @param fileName
- * @param dateTime
- * @param hospId
- * @return
- */
- @Override
- public PageUtils queryList(Integer current, Integer pageSize, String fileName, String dateTime, Long hospId) {
- int year = 0;
- int month = 0;
- if (StrUtil.isNotBlank(dateTime)) {
- Date date = DateUtils.StringToDate(dateTime, DateStyleEnum.YYYY_MM);
- year = DateUtil.year(date);
- month = DateUtil.month(date) + 1;
- }
- Page<CostIncomeFile> costIncomeFilePage = new Page<>(current, pageSize);
- Page<CostIncomeFile> page = this.page(costIncomeFilePage, new QueryWrapper<CostIncomeFile>().lambda()
- .eq(CostIncomeFile::getHospId, hospId)
- .like(StrUtil.isNotBlank(fileName), CostIncomeFile::getFileName, fileName)
- .eq(StrUtil.isNotBlank(dateTime),CostIncomeFile::getDateYear,year)
- .eq(StrUtil.isNotBlank(dateTime),CostIncomeFile::getDateMonth,month)
- .orderByDesc(CostIncomeFile::getCreateTime));
- List<CostIncomeFile> records = page.getRecords();
- List<CostIncomeFileVO> costIncomeFileVOList = BeanUtil.convertList(records, CostIncomeFileVO.class);
- costIncomeFileVOList.forEach(i -> {
- String errorList = i.getErrorList();
- if (StrUtil.isNotBlank(errorList)) {
- i.setErrStatus(NumberConstant.ONE);
- }
- i.setDateTime(DateUtil.format(DateUtil.date(i.getCreateTime()), "yyyy-MM-dd"));
- });
- PageUtils pageUtils = new PageUtils(page);
- pageUtils.setList(costIncomeFileVOList);
- return pageUtils;
- }
- /**
- * 撤销导入
- *
- * @param id
- * @param hospId
- */
- @Override
- @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
- public void deleteImport(Long id, Long hospId) {
- CostIncomeFile costIncomeFile = this.getById(id);
- if (Objects.isNull(costIncomeFile)) {
- throw new CostException(500, "文件记录不存在");
- }
- String fileType = costIncomeFile.getFileType();
- if (INCOME_FILETYPE.equals(fileType)) {
- // 根据文件的Id 和 医院Id获取数据
- List<CostIncomeGroup> costIncomeGroupList = costIncomeGroupMapper.selectList(new QueryWrapper<CostIncomeGroup>().lambda()
- .eq(CostIncomeGroup::getHospId, hospId).eq(CostIncomeGroup::getFileId, id));
- if (CollectionUtils.isEmpty(costIncomeGroupList)) {
- throw new CostException(410, "数据已撤销");
- }
- List<Long> list = costIncomeGroupList.stream().map(CostIncomeGroup::getId).collect(Collectors.toList());
- costIncomeGroupMapper.deleteBatchIds(list);
- } else if (COST_FILETYPE.equals(fileType)) {
- // 根据文件的Id 和 医院Id获取数据
- List<CostCostingGroup> costIncomeGroupList = costCostingGroupMapper.selectList(new QueryWrapper<CostCostingGroup>().lambda()
- .eq(CostCostingGroup::getHospId, hospId).eq(CostCostingGroup::getFileId, id));
- if (CollectionUtils.isEmpty(costIncomeGroupList)) {
- throw new CostException(410, "数据已撤销");
- }
- List<Long> list = costIncomeGroupList.stream().map(CostCostingGroup::getId).collect(Collectors.toList());
- costCostingGroupMapper.deleteBatchIds(list);
- }
- if (SHAREPARAM_FILETYPE.equals(fileType)) {
- // 根据文件的Id 和 医院Id获取数据
- List<ShareParamValue> shareParamValues = paramValueMapper.selectList(
- new LambdaQueryWrapper<ShareParamValue>()
- .eq(ShareParamValue::getHospId, hospId)
- .eq(ShareParamValue::getFileId, id));
- if (CollectionUtils.isEmpty(shareParamValues)) {
- throw new CostException(410, "数据已撤销");
- }
- List<Long> list = shareParamValues.stream().map(ShareParamValue::getId).collect(Collectors.toList());
- paramValueMapper.deleteBatchIds(list);
- }
- costIncomeFile.setRollbackStatus(NumberConstant.ONE);
- this.updateById(costIncomeFile);
- }
- /**
- * 错误详情
- *
- * @param id
- * @param hospId
- * @return
- */
- @Override
- public List<IncomeErrorMessage> getErrorList(Long id, Long hospId) {
- CostIncomeFile costIncomeFile = this.getById(id);
- if (Objects.isNull(costIncomeFile)) {
- throw new CostException(500, "文件记录不存在");
- }
- String errorList = costIncomeFile.getErrorList();
- if (StrUtil.isBlank(errorList)) {
- return null;
- }
- // List<IncomeErrorMessage> incomeErrorMessageList = JsonUtil.toList(errorList, IncomeErrorMessage.class);
- List<IncomeErrorMessage> incomeErrorMessageList = JacksonUtil.str2ObjList(errorList, List.class, IncomeErrorMessage.class);
- return incomeErrorMessageList;
- }
- /**
- * 文件记录删除
- *
- * @param idList 文件记录的Id集合
- */
- @Override
- @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
- public void deleteByIds(List<Long> idList) {
- this.removeByIds(idList);
- }
- }
|