|
@@ -0,0 +1,98 @@
|
|
|
+package com.usky.iot.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.usky.common.core.bean.CommonPage;
|
|
|
+import com.usky.common.core.exception.BusinessException;
|
|
|
+import com.usky.common.security.utils.SecurityUtils;
|
|
|
+import com.usky.iot.domain.CrmCustomInfo;
|
|
|
+import com.usky.iot.mapper.CrmCustomInfoMapper;
|
|
|
+import com.usky.iot.service.CrmCustomInfoService;
|
|
|
+import com.usky.common.mybatis.core.AbstractCrudService;
|
|
|
+import com.usky.iot.service.vo.CrmCustomInfoRequestVO;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.Optional;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 客户管理信息表 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author han
|
|
|
+ * @since 2023-06-26
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class CrmCustomInfoServiceImpl extends AbstractCrudService<CrmCustomInfoMapper, CrmCustomInfo> implements CrmCustomInfoService {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void add(CrmCustomInfo crmCustomInfo){
|
|
|
+ if(checkNameUnique(crmCustomInfo)){
|
|
|
+ throw new BusinessException("新增客户管理失败,项目名称"+crmCustomInfo.getProjectName()+"已经存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ if(crmCustomInfo.getExpireTime().compareTo(LocalDateTime.now())<0){
|
|
|
+ crmCustomInfo.setMaintainStatus(2);
|
|
|
+ }else{
|
|
|
+ crmCustomInfo.setMaintainStatus(1);
|
|
|
+ }
|
|
|
+ crmCustomInfo.setCreatedBy(SecurityUtils.getUsername());
|
|
|
+ crmCustomInfo.setCreatedTime(LocalDateTime.now());
|
|
|
+ crmCustomInfo.setTenantId(SecurityUtils.getTenantId());
|
|
|
+ this.save(crmCustomInfo);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void edit(CrmCustomInfo crmCustomInfo){
|
|
|
+ if(checkNameUnique(crmCustomInfo)){
|
|
|
+ throw new BusinessException("修改客户管理信息失败,项目名称"+crmCustomInfo.getProjectName()+"已经存在");
|
|
|
+ }
|
|
|
+ crmCustomInfo.setUpdatedBy(SecurityUtils.getUsername());
|
|
|
+ crmCustomInfo.setUpdatedTime(LocalDateTime.now());
|
|
|
+ this.updateById(crmCustomInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void remove(Integer id){
|
|
|
+ CrmCustomInfo crmCustomInfo = this.getById(id);
|
|
|
+ Optional.ofNullable(crmCustomInfo).orElseThrow(()->new BusinessException("客户管理信息不存在"));
|
|
|
+ crmCustomInfo.setDeleteFlag(1);
|
|
|
+ this.updateById(crmCustomInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CommonPage<CrmCustomInfo> page(CrmCustomInfoRequestVO cus){
|
|
|
+ IPage<CrmCustomInfo> page = new Page<>(cus.getCurrent(),cus.getSize());
|
|
|
+ LambdaQueryWrapper<CrmCustomInfo> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.like(StringUtils.isNotBlank(cus.getProjectName()),CrmCustomInfo::getProjectName,cus.getProjectName())
|
|
|
+ .like(StringUtils.isNotBlank(cus.getCompanyName()),CrmCustomInfo::getCompanyName,cus.getCompanyName())
|
|
|
+ .eq(cus.getMaintainStatus() != null,CrmCustomInfo::getMaintainStatus,cus.getMaintainStatus())
|
|
|
+ .between(StringUtils.isNotBlank(cus.getStartTime())&&StringUtils.isNotBlank(cus.getEndTime()),CrmCustomInfo::getExpireTime,cus.getStartTime(),cus.getEndTime())
|
|
|
+ .eq(CrmCustomInfo::getDeleteFlag,0)
|
|
|
+ .orderByDesc(CrmCustomInfo::getId);
|
|
|
+ page = this.page(page,queryWrapper);
|
|
|
+
|
|
|
+ return new CommonPage<>(page.getRecords(),page.getTotal(),cus.getSize(),cus.getCurrent());
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean checkNameUnique(CrmCustomInfo crmCustomInfo){
|
|
|
+ Integer id = null == crmCustomInfo.getId()?-1:crmCustomInfo.getId();
|
|
|
+ LambdaQueryWrapper<CrmCustomInfo> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.eq(CrmCustomInfo::getProjectName,crmCustomInfo.getProjectName())
|
|
|
+ .eq(CrmCustomInfo::getDeleteFlag,0);
|
|
|
+ CrmCustomInfo one = this.getOne(queryWrapper);
|
|
|
+ return null != one && !Objects.equals(one.getId(),id);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|