| | |
| | | import com.sinata.common.exception.ServiceException; |
| | | import com.sinata.common.utils.BeanUtils; |
| | | import com.sinata.common.utils.CollUtils; |
| | | import com.sinata.common.utils.StringUtils; |
| | | import com.sinata.system.domain.MwAttachment; |
| | | import com.sinata.system.domain.MwContract; |
| | | import com.sinata.system.domain.SysDepartment; |
| | | import com.sinata.system.domain.dto.MwContractDTO; |
| | | import com.sinata.system.domain.query.MwContractQuery; |
| | | import com.sinata.system.domain.vo.MwAttachmentVO; |
| | |
| | | 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; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public PageDTO<MwContractVO> pageList(MwContractQuery query) { |
| | | if (Objects.isNull(query.getDepartmentId())) { |
| | | SysDepartment myDepartment = sysDepartmentService.getMyDepartment(); |
| | | if (Objects.isNull(myDepartment)) { |
| | | return PageDTO.empty(0L, 0L); |
| | | } |
| | | query.setDepartmentId(myDepartment.getId()); |
| | | String treeCode = sysDepartmentService.getTreeCodeByDepartmentId(query.getDepartmentId()); |
| | | if (StringUtils.isBlank(treeCode)) { |
| | | return PageDTO.empty(0L, 0L); |
| | | } |
| | | Page<MwContractVO> page = baseMapper.pageList(new Page<>(query.getPageCurr(), query.getPageSize()), query); |
| | | Page<MwContractVO> page = baseMapper.pageList(new Page<>(query.getPageCurr(), query.getPageSize()), query, treeCode); |
| | | return PageDTO.of(page); |
| | | } |
| | | |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void add(MwContractDTO dto) { |
| | | MwContract mwContract = BeanUtils.copyBean(dto, MwContract.class); |
| | | 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(); |
| | |
| | | //执行删除 |
| | | removeById(id); |
| | | } |
| | | |
| | | /** |
| | | * 查询未过期合同列表 |
| | | * |
| | | * @param date |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<MwContractVO> queryListTerminationDateBeforeNow(Date date) { |
| | | return baseMapper.queryListTerminationDateBeforeNow(date); |
| | | } |
| | | } |