| | |
| | | import com.sinata.system.service.MwContractService; |
| | | import com.sinata.system.service.SysDepartmentService; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.dao.DuplicateKeyException; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void add(MwContractDTO dto) { |
| | | MwContract mwContract = BeanUtils.copyBean(dto, MwContract.class); |
| | | save(mwContract); |
| | | try { |
| | | save(mwContract); |
| | | } catch (DuplicateKeyException e) { |
| | | throw new ServiceException("合同编号重复"); |
| | | } |
| | | |
| | | if (CollUtils.isNotEmpty(dto.getAttachmentList())) { |
| | | List<MwAttachment> mwAttachments = BeanUtils.copyToList(dto.getAttachmentList(), MwAttachment.class); |
| | | mwAttachments.forEach(attachment -> { |
| | |
| | | throw new ServiceException("合同id不能为空"); |
| | | } |
| | | MwContract mwContract = BeanUtils.copyBean(dto, MwContract.class); |
| | | updateById(mwContract); |
| | | |
| | | try { |
| | | updateById(mwContract); |
| | | } catch (DuplicateKeyException e) { |
| | | throw new ServiceException("合同编号重复"); |
| | | } |
| | | if (CollUtils.isNotEmpty(dto.getAttachmentList())) { |
| | | //删除原来的附件 |
| | | mwAttachmentService.lambdaUpdate().eq(MwAttachment::getType, AttachmentTypeEnum.CONTRACT.getCode()).eq(MwAttachment::getTargetId, dto.getId()).remove(); |