| | |
| | | package cn.iocoder.yudao.module.erp.service.finance; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| | | import cn.iocoder.yudao.framework.common.exception.ServiceException; |
| | | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| | | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| | | import cn.iocoder.yudao.module.erp.controller.admin.finance.vo.account.ErpAccountImportExcelVO; |
| | | import cn.iocoder.yudao.module.erp.controller.admin.finance.vo.account.ErpAccountImportReqVO; |
| | | import cn.iocoder.yudao.module.erp.controller.admin.finance.vo.account.ErpAccountImportRespVO; |
| | | import cn.iocoder.yudao.module.erp.controller.admin.finance.vo.account.ErpAccountPageReqVO; |
| | | import cn.iocoder.yudao.module.erp.controller.admin.finance.vo.account.ErpAccountSaveReqVO; |
| | | import cn.iocoder.yudao.module.erp.dal.dataobject.finance.ErpAccountDO; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.validation.annotation.Validated; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Collection; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.List; |
| | | |
| | | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| | | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList; |
| | | import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.*; |
| | | |
| | | /** |
| | |
| | | return accountMapper.selectPage(pageReqVO); |
| | | } |
| | | |
| | | @Override |
| | | public ErpAccountImportRespVO importAccountList(List<ErpAccountImportExcelVO> importAccounts, |
| | | ErpAccountImportReqVO importReqVO) { |
| | | // 1. 校验非空 |
| | | importAccounts = filterList(importAccounts, item -> StrUtil.isNotBlank(item.getName())); |
| | | if (CollUtil.isEmpty(importAccounts)) { |
| | | throw exception(ACCOUNT_IMPORT_LIST_IS_EMPTY); |
| | | } |
| | | // 2. 逐条处理 |
| | | ErpAccountImportRespVO respVO = ErpAccountImportRespVO.builder() |
| | | .createAccountNames(new ArrayList<>()) |
| | | .updateAccountNames(new ArrayList<>()) |
| | | .failureAccountNames(new LinkedHashMap<>()) |
| | | .build(); |
| | | importAccounts.forEach(importAccount -> { |
| | | try { |
| | | ErpAccountDO existAccount = accountMapper.selectByName(importAccount.getName()); |
| | | if (existAccount == null) { |
| | | // 新增 |
| | | ErpAccountDO account = BeanUtils.toBean(importAccount, ErpAccountDO.class); |
| | | accountMapper.insert(account); |
| | | respVO.getCreateAccountNames().add(importAccount.getName()); |
| | | return; |
| | | } |
| | | // 已存在,判断是否允许更新 |
| | | if (!importReqVO.getUpdateSupport()) { |
| | | respVO.getFailureAccountNames().put(importAccount.getName(), |
| | | StrUtil.format(ACCOUNT_NAME_EXISTS.getMsg(), importAccount.getName())); |
| | | return; |
| | | } |
| | | ErpAccountDO updateAccount = BeanUtils.toBean(importAccount, ErpAccountDO.class) |
| | | .setId(existAccount.getId()); |
| | | accountMapper.updateById(updateAccount); |
| | | respVO.getUpdateAccountNames().add(importAccount.getName()); |
| | | } catch (ServiceException ex) { |
| | | respVO.getFailureAccountNames().put(importAccount.getName(), ex.getMessage()); |
| | | } |
| | | }); |
| | | return respVO; |
| | | } |
| | | |
| | | } |