|
@@ -0,0 +1,158 @@
|
|
|
+package cn.iocoder.yudao.module.customer.service.businessopportunity;
|
|
|
+
|
|
|
+import cn.hutool.core.util.IdUtil;
|
|
|
+import cn.iocoder.yudao.framework.security.core.LoginUser;
|
|
|
+import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
|
|
|
+import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
|
|
|
+import cn.iocoder.yudao.module.employee.api.EmployeeApi;
|
|
|
+import cn.iocoder.yudao.module.employee.api.dto.EmployeeRespDTO;
|
|
|
+import cn.iocoder.yudao.module.infra.api.file.FileApi;
|
|
|
+import cn.iocoder.yudao.module.infra.api.file.dto.FileDTO;
|
|
|
+import cn.iocoder.yudao.module.system.api.dept.DeptApi;
|
|
|
+import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import javax.annotation.Resource;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+import cn.iocoder.yudao.module.customer.controller.admin.businessopportunity.vo.*;
|
|
|
+import cn.iocoder.yudao.module.customer.dal.dataobject.businessopportunity.CustomerBusinessOpportunityDO;
|
|
|
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
+import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
|
|
+import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
+
|
|
|
+import cn.iocoder.yudao.module.customer.dal.mysql.businessopportunity.CustomerBusinessOpportunityMapper;
|
|
|
+
|
|
|
+import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
+import static cn.iocoder.yudao.module.employee.enums.ErrorCodeConstants.CUSTOMER_BUSINESS_OPPORTUNITY_NOT_EXISTS;
|
|
|
+
|
|
|
+
|
|
|
+ * 客户商机 Service 实现类
|
|
|
+ *
|
|
|
+ * @author zhaopq
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@Validated
|
|
|
+public class CustomerBusinessOpportunityServiceImpl implements CustomerBusinessOpportunityService {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private CustomerBusinessOpportunityMapper businessOpportunityMapper;
|
|
|
+ @Resource
|
|
|
+ private FileApi fileApi;
|
|
|
+ @Resource
|
|
|
+ private DeptApi deptApi;
|
|
|
+ @Resource
|
|
|
+ private EmployeeApi employeeApi;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Long createBusinessOpportunity(CustomerBusinessOpportunitySaveReqVO createReqVO) {
|
|
|
+
|
|
|
+ LoginUser user = SecurityFrameworkUtils.getLoginUser();
|
|
|
+ Long tenantId = user != null && user.getTenantId() != null ? user.getTenantId() : 0L;
|
|
|
+ Long userId = user != null && user.getId() != null ? user.getId() : 0L;
|
|
|
+ createReqVO.setTenantId(tenantId);
|
|
|
+
|
|
|
+ EmployeeRespDTO loginEmployee = employeeApi.getEmployeeByUserId(userId);
|
|
|
+
|
|
|
+ if (loginEmployee != null) {
|
|
|
+ createReqVO.setCreatorEmployeeId(loginEmployee.getId());
|
|
|
+ createReqVO.setCreatorEmployeeName(loginEmployee.getName());
|
|
|
+ createReqVO.setDeptId(loginEmployee.getDeptId());
|
|
|
+ }
|
|
|
+
|
|
|
+ String infoId = IdUtil.fastSimpleUUID();
|
|
|
+ createReqVO.setOpportunityId(infoId);
|
|
|
+ CustomerBusinessOpportunityDO businessOpportunity = BeanUtils.toBean(createReqVO, CustomerBusinessOpportunityDO.class);
|
|
|
+ businessOpportunityMapper.insert(businessOpportunity);
|
|
|
+
|
|
|
+ fileApi.updateFileBiz(createReqVO.getFileIdList(), infoId);
|
|
|
+
|
|
|
+ return businessOpportunity.getId();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void updateBusinessOpportunity(CustomerBusinessOpportunitySaveReqVO updateReqVO) {
|
|
|
+
|
|
|
+ validateBusinessOpportunityExists(updateReqVO.getId());
|
|
|
+
|
|
|
+ fileApi.updateFileBiz(updateReqVO.getFileIdList(), updateReqVO.getOpportunityId());
|
|
|
+
|
|
|
+ LoginUser user = SecurityFrameworkUtils.getLoginUser();
|
|
|
+ Long tenantId = user != null && user.getTenantId() != null ? user.getTenantId() : 0L;
|
|
|
+ Long userId = user != null && user.getId() != null ? user.getId() : 0L;
|
|
|
+
|
|
|
+ EmployeeRespDTO loginEmployee = employeeApi.getEmployeeByUserId(userId);
|
|
|
+
|
|
|
+ if (loginEmployee != null) {
|
|
|
+ updateReqVO.setCreatorEmployeeId(loginEmployee.getId());
|
|
|
+ updateReqVO.setCreatorEmployeeName(loginEmployee.getName());
|
|
|
+ updateReqVO.setDeptId(loginEmployee.getDeptId());
|
|
|
+ }
|
|
|
+
|
|
|
+ CustomerBusinessOpportunityDO updateObj = BeanUtils.toBean(updateReqVO, CustomerBusinessOpportunityDO.class);
|
|
|
+ businessOpportunityMapper.updateById(updateObj);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void deleteBusinessOpportunity(Long id) {
|
|
|
+
|
|
|
+ validateBusinessOpportunityExists(id);
|
|
|
+
|
|
|
+ businessOpportunityMapper.deleteById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void validateBusinessOpportunityExists(Long id) {
|
|
|
+ if (businessOpportunityMapper.selectById(id) == null) {
|
|
|
+ throw exception(CUSTOMER_BUSINESS_OPPORTUNITY_NOT_EXISTS);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CustomerBusinessOpportunityDO getBusinessOpportunity(Long id) {
|
|
|
+ return businessOpportunityMapper.selectById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @TenantIgnore
|
|
|
+ public CustomerBusinessOpportunityRespVO getById(Long id) {
|
|
|
+
|
|
|
+ if (id == null) {
|
|
|
+ throw new IllegalArgumentException("ID cannot be null");
|
|
|
+ }
|
|
|
+
|
|
|
+ CustomerBusinessOpportunityDO opportunityDO = businessOpportunityMapper.selectById(id);
|
|
|
+ if (opportunityDO == null) {
|
|
|
+ throw exception(CUSTOMER_BUSINESS_OPPORTUNITY_NOT_EXISTS);
|
|
|
+ }
|
|
|
+
|
|
|
+ CustomerBusinessOpportunityRespVO respVO = BeanUtils.toBean(opportunityDO, CustomerBusinessOpportunityRespVO.class);
|
|
|
+ if (respVO == null) {
|
|
|
+
|
|
|
+ throw new RuntimeException("Failed to convert DO to VO");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<FileDTO> fileList = fileApi.getFileDTOListByBiz(opportunityDO.getOpportunityId());
|
|
|
+ if (fileList != null) {
|
|
|
+
|
|
|
+ respVO.setFileList(fileList);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (opportunityDO.getDeptId() != null) {
|
|
|
+ DeptRespDTO dept = deptApi.getDept(opportunityDO.getDeptId());
|
|
|
+ respVO.setDeptName(dept.getName());
|
|
|
+ if (dept != null && StringUtils.isNotBlank(dept.getName())) {
|
|
|
+ respVO.setDeptName(dept.getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return respVO;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PageResult<CustomerBusinessOpportunityDO> getBusinessOpportunityPage(CustomerBusinessOpportunityPageReqVO pageReqVO) {
|
|
|
+ return businessOpportunityMapper.selectPage(pageReqVO);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|