|
@@ -0,0 +1,122 @@
|
|
|
+package com.fjhx.service.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.fjhx.common.attachment.IAttachmentApi;
|
|
|
+import com.fjhx.service.entity.dto.GetServiceContractRecordPageDto;
|
|
|
+import com.fjhx.service.entity.po.ServiceContractRecord;
|
|
|
+import com.fjhx.service.entity.vo.ServiceContractRecordVo;
|
|
|
+import com.fjhx.service.mapper.ServiceContractRecordMapper;
|
|
|
+import com.fjhx.service.service.ServiceContractRecordService;
|
|
|
+import org.springblade.common.constant.AttachmentConstant;
|
|
|
+import org.springblade.core.mp.base.BasicsServiceImpl;
|
|
|
+import org.springblade.core.mp.utils.PageUtil;
|
|
|
+import org.springblade.system.attachment.entity.Attachment;
|
|
|
+import org.springblade.system.user.entity.User;
|
|
|
+import org.springblade.system.user.feign.IUserClient;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 服务记录 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author zlj
|
|
|
+ * @since 2023-02-17
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class ServiceContractRecordServiceImpl extends BasicsServiceImpl<ServiceContractRecordMapper, ServiceContractRecord> implements ServiceContractRecordService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IAttachmentApi iAttachmentApi;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IUserClient iUserClient;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<ServiceContractRecordVo> getPage(GetServiceContractRecordPageDto dto) {
|
|
|
+
|
|
|
+ Wrapper<ServiceContractRecord> wrapper = Wrappers.<ServiceContractRecord>lambdaQuery()
|
|
|
+ .and(ObjectUtil.isNotEmpty(dto.getKeyword()), q -> q
|
|
|
+ .like(ServiceContractRecord::getServiceContractCode, dto.getKeyword()));
|
|
|
+
|
|
|
+ Page<ServiceContractRecordVo> page = PageUtil.toPage(page(dto.getPage(), wrapper), ServiceContractRecordVo.class);
|
|
|
+ List<ServiceContractRecordVo> records = page.getRecords();
|
|
|
+
|
|
|
+ if (records.size() == 0) {
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ Set<String> userIdSet = new HashSet<>();
|
|
|
+ Set<String> serviceContractRecordIdList = new HashSet<>();
|
|
|
+
|
|
|
+ for (ServiceContractRecordVo record : records) {
|
|
|
+ String[] split = record.getServiceUser().split(",");
|
|
|
+ userIdSet.addAll(Arrays.asList(split));
|
|
|
+ serviceContractRecordIdList.add(record.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, List<Attachment>> attachmentMap = iAttachmentApi.getByBusiIdsToMap(new ArrayList<>(serviceContractRecordIdList));
|
|
|
+ Map<String, User> userMap = iUserClient.userInfoByIdsToMap(new ArrayList<>(userIdSet));
|
|
|
+
|
|
|
+ for (ServiceContractRecordVo record : records) {
|
|
|
+ // 赋值附件
|
|
|
+ record.setAttachmentList(attachmentMap.get(record.getId()));
|
|
|
+
|
|
|
+ // 赋值服务人员
|
|
|
+ StringJoiner userNameJoiner = new StringJoiner(",");
|
|
|
+ String serviceUser = record.getServiceUser();
|
|
|
+ String[] split = serviceUser.split(",");
|
|
|
+ for (String userId : split) {
|
|
|
+ User user = userMap.get(userId);
|
|
|
+ if (user == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ userNameJoiner.add(user.getRealName());
|
|
|
+ }
|
|
|
+ record.setServiceUserName(userNameJoiner.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void add(ServiceContractRecordVo vo) {
|
|
|
+ save(vo);
|
|
|
+ addAttachmentList(vo.getAttachmentList(), vo.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void edit(ServiceContractRecordVo vo) {
|
|
|
+ updateById(vo);
|
|
|
+ iAttachmentApi.deleteByBusiId(vo.getId());
|
|
|
+ addAttachmentList(vo.getAttachmentList(), vo.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void delete(ServiceContractRecordVo vo) {
|
|
|
+ removeById(vo.getId());
|
|
|
+ iAttachmentApi.deleteByBusiId(vo.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加附件
|
|
|
+ */
|
|
|
+ private void addAttachmentList(List<Attachment> attachmentList, String serviceContractRecordId) {
|
|
|
+ if (ObjectUtil.isEmpty(attachmentList)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (Attachment attachment : attachmentList) {
|
|
|
+ attachment.setBusiId(serviceContractRecordId);
|
|
|
+ attachment.setBusiType(AttachmentConstant.BusiType.SERVICE_CONTRACT_RECORD);
|
|
|
+ }
|
|
|
+ iAttachmentApi.batchInsert(attachmentList);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|