|
@@ -0,0 +1,91 @@
|
|
|
|
|
+package com.crm.manager.service.impl;
|
|
|
|
|
+
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
|
+import com.crm.manager.dao.mapper.TenantMapper;
|
|
|
|
|
+import com.crm.manager.dao.repository.TenantRepository;
|
|
|
|
|
+import com.crm.manager.service.TenantService;
|
|
|
|
|
+import com.crm.rely.backend.core.constant.Constants;
|
|
|
|
|
+import com.crm.rely.backend.core.dto.base.BaseResultWithPagerDto;
|
|
|
|
|
+import com.crm.rely.backend.core.dto.base.PageDto;
|
|
|
|
|
+import com.crm.rely.backend.core.dto.base.ResultWithPagerDto;
|
|
|
|
|
+import com.crm.rely.backend.core.dto.tenant.TenantSearchDto;
|
|
|
|
|
+import com.crm.rely.backend.core.entity.tenant.info.TenantAddEntity;
|
|
|
|
|
+import com.crm.rely.backend.core.entity.tenant.info.TenantEditEntity;
|
|
|
|
|
+import com.crm.rely.backend.core.entity.tenant.info.TenantRespEntity;
|
|
|
|
|
+import com.crm.rely.backend.core.entity.tenant.info.TenantSearchEntity;
|
|
|
|
|
+import com.crm.rely.backend.core.pojo.table.MerchantTable;
|
|
|
|
|
+import com.crm.rely.backend.exception.ServiceException;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
+
|
|
|
|
|
+@Service
|
|
|
|
|
+@Slf4j
|
|
|
|
|
+public class TenantServiceImpl implements TenantService {
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private TenantRepository tenantRepository;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private TenantMapper tenantMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public String add(TenantAddEntity entity) {
|
|
|
|
|
+ log.info("添加商户:{}", JSON.toJSONString(entity));
|
|
|
|
|
+ MerchantTable merchantTable = new MerchantTable();
|
|
|
|
|
+ BeanUtils.copyProperties(entity, merchantTable);
|
|
|
|
|
+ tenantRepository.save(merchantTable);
|
|
|
|
|
+ return "添加成功";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public TenantRespEntity findSingle(Long id) {
|
|
|
|
|
+ log.info("查询商户:{}", id);
|
|
|
|
|
+ MerchantTable merchantTable = tenantRepository.findOne(id);
|
|
|
|
|
+ TenantRespEntity respEntity = new TenantRespEntity();
|
|
|
|
|
+ BeanUtils.copyProperties(merchantTable, respEntity);
|
|
|
|
|
+ return respEntity;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public String edit(TenantEditEntity entity) {
|
|
|
|
|
+ log.info("修改商户:{}", JSON.toJSONString(entity));
|
|
|
|
|
+ MerchantTable merchantTable = new MerchantTable();
|
|
|
|
|
+ BeanUtils.copyProperties(entity, merchantTable);
|
|
|
|
|
+ tenantRepository.save(merchantTable);
|
|
|
|
|
+ return "修改成功";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public String delete(Long id) {
|
|
|
|
|
+ log.info("删除商户:{}", id);
|
|
|
|
|
+ tenantRepository.delete(id);
|
|
|
|
|
+ return "删除成功";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public BaseResultWithPagerDto<List<TenantSearchDto>> searchPage(TenantSearchEntity entity) throws ServiceException {
|
|
|
|
|
+ PageDto pageDto = new PageDto();
|
|
|
|
|
+ Integer count = tenantMapper.searchByPageCount(entity);
|
|
|
|
|
+ if (count == null || count <= 0) {
|
|
|
|
|
+ return ResultWithPagerDto.success(pageDto);
|
|
|
|
|
+ }
|
|
|
|
|
+ pageDto = PageDto.format(entity, count);
|
|
|
|
|
+ List<MerchantTable> merchantTables = tenantMapper.searchByPageList(entity);
|
|
|
|
|
+ if (merchantTables == null || merchantTables.size() <= 0) {
|
|
|
|
|
+ throw new ServiceException(Constants.SYSTEM_ERROR);
|
|
|
|
|
+ }
|
|
|
|
|
+ List<TenantSearchDto> userInfoSearchDtos = merchantTables.stream().map(table -> {
|
|
|
|
|
+ TenantSearchDto dto = new TenantSearchDto();
|
|
|
|
|
+ BeanUtils.copyProperties(table, dto);
|
|
|
|
|
+ return dto;
|
|
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ return new BaseResultWithPagerDto(pageDto, userInfoSearchDtos);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|