|
@@ -0,0 +1,196 @@
|
|
|
|
+package com.fjhx.service.service.impl;
|
|
|
|
+
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
|
+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.company.entity.Company;
|
|
|
|
+import com.fjhx.company.service.ICompanyService;
|
|
|
|
+import com.fjhx.product.entity.Product;
|
|
|
|
+import com.fjhx.product.service.IProductService;
|
|
|
|
+import com.fjhx.service.entity.dto.GetServiceContractPageDto;
|
|
|
|
+import com.fjhx.service.entity.po.ServiceContract;
|
|
|
|
+import com.fjhx.service.entity.po.ServiceContractProduct;
|
|
|
|
+import com.fjhx.service.entity.vo.ServiceContractProductVo;
|
|
|
|
+import com.fjhx.service.entity.vo.ServiceContractVo;
|
|
|
|
+import com.fjhx.service.mapper.ServiceContractMapper;
|
|
|
|
+import com.fjhx.service.service.ServiceContractProductService;
|
|
|
|
+import com.fjhx.service.service.ServiceContractService;
|
|
|
|
+import com.fjhx.utils.CodeEnum;
|
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
|
+import org.apache.commons.collections4.MapUtils;
|
|
|
|
+import org.springblade.common.constant.AttachmentConstant;
|
|
|
|
+import org.springblade.core.mp.base.BasicsEntity;
|
|
|
|
+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.math.BigDecimal;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * <p>
|
|
|
|
+ * 服务合同 服务实现类
|
|
|
|
+ * </p>
|
|
|
|
+ *
|
|
|
|
+ * @author zlj
|
|
|
|
+ * @since 2023-02-17
|
|
|
|
+ */
|
|
|
|
+@Service
|
|
|
|
+public class ServiceContractServiceImpl extends BasicsServiceImpl<ServiceContractMapper, ServiceContract> implements ServiceContractService {
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private IUserClient userClient;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private ServiceContractProductService serviceContractProductService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private ICompanyService companyService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private IProductService productService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private IAttachmentApi iAttachmentApi;
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Page<ServiceContractVo> getPage(GetServiceContractPageDto dto) {
|
|
|
|
+
|
|
|
|
+ Wrapper<ServiceContract> wrapper = Wrappers.<ServiceContract>lambdaQuery()
|
|
|
|
+ .select(BasicsEntity::getId,
|
|
|
|
+ ServiceContract::getCompanyId,
|
|
|
|
+ ServiceContract::getCode,
|
|
|
|
+ ServiceContract::getProgress,
|
|
|
|
+ BasicsEntity::getCreateTime,
|
|
|
|
+ BasicsEntity::getCreateUser,
|
|
|
|
+ ServiceContract::getCustomerName,
|
|
|
|
+ ServiceContract::getCustomerContactPersonName,
|
|
|
|
+ ServiceContract::getStatus,
|
|
|
|
+ ServiceContract::getContractAmount,
|
|
|
|
+ ServiceContract::getAccountReceived
|
|
|
|
+ )
|
|
|
|
+ .and(ObjectUtil.isNotEmpty(dto.getKeyword()), q -> q.like(ServiceContract::getCode, dto.getKeyword()))
|
|
|
|
+ .orderByDesc(BasicsEntity::getCreateTime);
|
|
|
|
+
|
|
|
|
+ Page<ServiceContractVo> page = PageUtil.toPage(page(dto.getPage(), wrapper), ServiceContractVo.class);
|
|
|
|
+ List<ServiceContractVo> records = page.getRecords();
|
|
|
|
+
|
|
|
|
+ if (records.size() == 0) {
|
|
|
|
+ return page;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 归属公司id列表
|
|
|
|
+ List<String> companyIdList = records.stream().map(ServiceContract::getCompanyId).collect(Collectors.toList());
|
|
|
|
+ Map<String, String> companyMap = companyService.listByIds(companyIdList)
|
|
|
|
+ .stream().collect(Collectors.toMap(BasicsEntity::getId, Company::getNameChinese));
|
|
|
|
+
|
|
|
|
+ // 用户id列表
|
|
|
|
+ List<String> createUserIdList = records.stream().map(BasicsEntity::getCreateUser).collect(Collectors.toList());
|
|
|
|
+ Map<String, User> userMap = userClient.userInfoByIdsToMap(createUserIdList);
|
|
|
|
+
|
|
|
|
+ for (ServiceContractVo record : records) {
|
|
|
|
+ record.setCompanyName(companyMap.get(record.getCompanyId()));
|
|
|
|
+
|
|
|
|
+ User user = userMap.get(record.getCreateUser());
|
|
|
|
+ if (ObjectUtil.isNotEmpty(user)) {
|
|
|
|
+ record.setCreateUserName(user.getRealName());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return page;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void add(ServiceContractVo serviceContractVo) {
|
|
|
|
+ serviceContractVo.setCode(CodeEnum.SERVICE_CONTRACT.getCode());
|
|
|
|
+ serviceContractVo.setCreate();
|
|
|
|
+ serviceContractVo.setAccountReceived(BigDecimal.ZERO);
|
|
|
|
+ save(serviceContractVo);
|
|
|
|
+
|
|
|
|
+ List<? extends ServiceContractProduct> serviceContractProductList = serviceContractVo.getServiceContractProductList();
|
|
|
|
+ if (ObjectUtil.isNotEmpty(serviceContractProductList)) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ for (ServiceContractProduct serviceContractProduct : serviceContractProductList) {
|
|
|
|
+ serviceContractProduct.setServiceContractId(serviceContractVo.getId());
|
|
|
|
+ }
|
|
|
|
+ serviceContractProductService.saveBatch(BeanUtil.copyToList(serviceContractProductList, ServiceContractProduct.class));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void edit(ServiceContractVo serviceContractVo) {
|
|
|
|
+ serviceContractVo.setUpdate();
|
|
|
|
+ updateById(serviceContractVo);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public ServiceContractVo getDetail(String id) {
|
|
|
|
+
|
|
|
|
+ ServiceContractVo serviceContractVo = BeanUtil.copyProperties(getById(id), ServiceContractVo.class);
|
|
|
|
+
|
|
|
|
+ // 服务合同产品关联
|
|
|
|
+ List<ServiceContractProductVo> serviceContractVos = BeanUtil.copyToList(
|
|
|
|
+ serviceContractProductService.list(Wrappers.<ServiceContractProduct>lambdaQuery()
|
|
|
|
+ .eq(ServiceContractProduct::getServiceContractId, id)),
|
|
|
|
+ ServiceContractProductVo.class);
|
|
|
|
+
|
|
|
|
+ // 获取产品map
|
|
|
|
+ Map<String, Product> productMap = getProductMapByProductId(serviceContractVos);
|
|
|
|
+
|
|
|
|
+ // 赋值产品信息
|
|
|
|
+ for (ServiceContractProductVo contractVo : serviceContractVos) {
|
|
|
|
+ String productId = contractVo.getProductId();
|
|
|
|
+ Product product = productMap.get(productId);
|
|
|
|
+ if (product != null) {
|
|
|
|
+ contractVo.setMainIcon(product.getMainIcon());
|
|
|
|
+ contractVo.setNameChinese(product.getNameChinese());
|
|
|
|
+ contractVo.setProductModelChinese(product.getProductModelChinese());
|
|
|
|
+ contractVo.setUnit(product.getUnit());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 赋值服务合同产品关联列表
|
|
|
|
+ serviceContractVo.setServiceContractProductList(serviceContractVos);
|
|
|
|
+ return serviceContractVo;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取产品map
|
|
|
|
+ */
|
|
|
|
+ private Map<String, Product> getProductMapByProductId(List<ServiceContractProductVo> serviceContractVos) {
|
|
|
|
+ List<String> productIdList = serviceContractVos.stream().map(ServiceContractProduct::getProductId).collect(Collectors.toList());
|
|
|
|
+ List<Product> productList = productService.listByIds(productIdList);
|
|
|
|
+
|
|
|
|
+ // 获取主图
|
|
|
|
+ Map<String, List<Attachment>> attachmentMap = iAttachmentApi.getByBusiIdsToMap(productIdList);
|
|
|
|
+ if (MapUtils.isNotEmpty(attachmentMap)) {
|
|
|
|
+ for (Product product : productList) {
|
|
|
|
+ List<Attachment> attachments = attachmentMap.get(product.getId());
|
|
|
|
+ if (CollectionUtils.isEmpty(attachments)) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ // 筛选出主图
|
|
|
|
+ List<String> mainIcons = attachments.stream()
|
|
|
|
+ .filter(obj -> obj.getBusiType() == AttachmentConstant.BusiType.MIAN_IMAG)
|
|
|
|
+ .map(Attachment::getPath)
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ if (CollectionUtils.isNotEmpty(mainIcons)) {
|
|
|
|
+ product.setMainIcon(mainIcons.get(0));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return productList.stream().collect(Collectors.toMap(BasicsEntity::getId, item -> item));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|