Преглед изворни кода

[招商]adjust

release_toaliyun_real
Burce пре 6 година
родитељ
комит
67e6c962b4
6 измењених фајлова са 286 додато и 0 уклоњено
  1. +12
    -0
      mallinkService/src/main/java/com/iformall/common/LogColumn.java
  2. +24
    -0
      mallinkService/src/main/java/com/iformall/domain/vo/invest/TableTriple.java
  3. +16
    -0
      mallinkService/src/main/java/com/iformall/service/invest/InvestBaseService.java
  4. +17
    -0
      mallinkService/src/main/java/com/iformall/service/invest/InvestBizService.java
  5. +86
    -0
      mallinkService/src/main/java/com/iformall/service/invest/InvestHelper.java
  6. +131
    -0
      mallinkService/src/main/java/com/iformall/service/invest/impl/InvestBizServiceImpl.java

+ 12
- 0
mallinkService/src/main/java/com/iformall/common/LogColumn.java Прегледај датотеку

@@ -0,0 +1,12 @@
package com.iformall.common;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface LogColumn {
String value() default "";
}

+ 24
- 0
mallinkService/src/main/java/com/iformall/domain/vo/invest/TableTriple.java Прегледај датотеку

@@ -0,0 +1,24 @@
package com.iformall.domain.vo.invest;

import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.builder.CompareToBuilder;

import java.io.Serializable;

@EqualsAndHashCode
@Data(staticConstructor = "of")
public class TableTriple<K,L,R> implements Comparable<TableTriple<K,L,R>>, Serializable {
private final K column;
private final L before ;
private final R after ;



@Override
public int compareTo(TableTriple<K, L, R> other) {
return new CompareToBuilder().append(getColumn(), other.getColumn())
.append(getBefore(), other.getBefore())
.append(getAfter(), other.getAfter()).toComparison();
}
}

+ 16
- 0
mallinkService/src/main/java/com/iformall/service/invest/InvestBaseService.java Прегледај датотеку

@@ -0,0 +1,16 @@
package com.iformall.service.invest;

import java.io.Serializable;

/**
* 招商任务
*
* @author
* @email
* @date 2019-09-23 18:40:43
*/
public interface InvestBaseService<T> {

T getByIdNotNull(Serializable id);
}


+ 17
- 0
mallinkService/src/main/java/com/iformall/service/invest/InvestBizService.java Прегледај датотеку

@@ -0,0 +1,17 @@
package com.iformall.service.invest;

import com.iformall.domain.po.InvestDemandEntity;
import com.iformall.domain.vo.invest.InvestDemandVo;
import com.iformall.domain.vo.invest.InvestPageQuery;
import com.iformall.domain.vo.invest.InvestPageResult;

public interface InvestBizService {

InvestPageResult<InvestDemandVo> queryPage(InvestPageQuery<InvestDemandEntity> params);

boolean saveCustomerAndDemand(InvestDemandVo customerDemandVo) ;

boolean updateCustomerAndDemand(InvestDemandVo customerDemandVo) ;

InvestDemandVo findById(Long id) ;
}

+ 86
- 0
mallinkService/src/main/java/com/iformall/service/invest/InvestHelper.java Прегледај датотеку

@@ -0,0 +1,86 @@
package com.iformall.service.invest;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.iformall.common.ErrorCode;
import com.iformall.domain.vo.invest.InvestPageQuery;
import com.iformall.exception.MallinkException;
import org.apache.commons.lang3.ObjectUtils;

import java.text.MessageFormat;
import java.util.Objects;

public class InvestHelper {

public static <T> Page<T> buildQueryPage(InvestPageQuery<T> pageQuery) {
Page<T> page = new Page<>();
page.setCurrent(pageQuery.getPageNum());
page.setSize(pageQuery.getPageSize());
page.setAscs(pageQuery.getAscs());
page.setDescs(pageQuery.getDescs());
page.setOptimizeCountSql(true);
page.setSearchCount(true);
return page;
}

/**
* @param object the object to check
* @param message the exception message to use if the assertion fails
* @throws MallinkException if the object is {@code null}
*/
public static void notNull(Object object, String message) {
if (object == null) {
throwException(ErrorCode.INVEST_PARAMETER_NOT_FOUND, message);
}
}

/**
* @param object the object to check
* @param errorCode the exception message to use if the assertion fails
* @throws MallinkException if the object is {@code null}
*/
public static void notNull(Object object, ErrorCode errorCode) {
if (object == null) {
throwException(errorCode, null);
}
}

/**
* @param values the objects to check
*/
public static void allNotNull(final Object... values) {
if (!ObjectUtils.allNotNull(values)) {
throwException(ErrorCode.INVEST_PARAMETER_NOT_FOUND, values.getClass().getTypeName());
}
}

/**
* @param expression
* @param errorCode
*/
public static void isTrue(boolean expression, ErrorCode errorCode, Object info) {
if (!expression) {
throwException(errorCode, info);
}
}

public static void throwException(ErrorCode errorCode, Object info) {
String message;
if (Objects.isNull(info)) {
message = errorCode.getMessage();
} else {
message = MessageFormat.format("{0} {1}", info, errorCode.getMessage());
}
throw new MallinkException(errorCode.getCode(), message);
}

/**
*
* @param value the object to check
* @param message the exception message to use if the assertion fails
*/
public static void checkResult(Object value, String message) {
if (Objects.isNull(value)) {
throwException(ErrorCode.INVEST_RESULT_NOT_FOUND, message);
}
}
}

+ 131
- 0
mallinkService/src/main/java/com/iformall/service/invest/impl/InvestBizServiceImpl.java Прегледај датотеку

@@ -0,0 +1,131 @@
package com.iformall.service.invest.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.iformall.domain.po.InvestCustomerEntity;
import com.iformall.domain.po.InvestDemandEntity;
import com.iformall.domain.po.WxBrand;
import com.iformall.domain.po.WxShop;
import com.iformall.domain.vo.invest.InvestDemandVo;
import com.iformall.domain.vo.invest.InvestPageQuery;
import com.iformall.domain.vo.invest.InvestPageResult;
import com.iformall.service.WxBrandService;
import com.iformall.service.WxShopService;
import com.iformall.service.invest.InvestBizService;
import com.iformall.service.invest.InvestCustomerService;
import com.iformall.service.invest.InvestDemandService;
import com.iformall.service.invest.InvestHelper;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import java.util.stream.Collectors;

@Service
public class InvestBizServiceImpl implements InvestBizService {

@Autowired
private InvestDemandService demandService;
@Autowired
private WxShopService shopService;
@Autowired
private InvestCustomerService customerService;
@Autowired
private WxBrandService brandService;

@Override
public InvestPageResult<InvestDemandVo> queryPage(InvestPageQuery<InvestDemandEntity> params) {
InvestHelper.allNotNull(params);
Page<InvestDemandEntity> page = InvestHelper.buildQueryPage(params);
InvestPageResult<InvestDemandVo> investPage = new InvestPageResult<>();
//1、客户需求
InvestDemandEntity queryTask = params.getQueryData();
LambdaQueryWrapper<InvestDemandEntity> queryWrapper = new LambdaQueryWrapper<>(queryTask);
IPage<InvestDemandEntity> demandPage = demandService.page(page, queryWrapper);
if (CollectionUtils.isEmpty(demandPage.getRecords())) {
return investPage;
}

List<InvestDemandVo> resultList = getITargeInfoList(demandPage);

BeanUtils.copyProperties(demandPage, investPage);
investPage.setRecords(resultList);
return investPage;
}

private List<InvestDemandVo> getITargeInfoList(IPage<InvestDemandEntity> demandPage) {
List<InvestDemandEntity> demandList = demandPage.getRecords();
//2、客户信息
Collection<InvestCustomerEntity> customers = customerService.listByIds(demandList
.stream().map(InvestDemandEntity::getCustomerId).collect(Collectors.toList()));
Map<Long, InvestCustomerEntity> customersMap = customers.stream().collect(Collectors.toMap(InvestCustomerEntity::getId, customer -> customer));

//3、目标信息
Collection<WxShop> shops = shopService.getByIds(demandList.stream().map(InvestDemandEntity::getTargetId).collect(Collectors.toList()));
Map<Long, WxShop> shopsMap = shops.stream().collect(Collectors.toMap(WxShop::getId, shop -> shop));

//4 品牌
Collection<WxBrand> brands = brandService.getByIds(customers.stream().map(InvestCustomerEntity::getBrandId).collect(Collectors.toList()));
Map<Long, WxBrand> brandMap = brands.stream().collect(Collectors.toMap(WxBrand::getId, brand -> brand));

List<InvestDemandVo> resultList = new ArrayList<>();
for (InvestDemandEntity item : demandList) {
InvestCustomerEntity customer = customersMap.get(item.getCustomerId());
WxShop shop = shopsMap.get(item.getTargetId());
WxBrand brand = null;
if (Objects.nonNull(customer)) {
brand = brandMap.get(customer.getBrandId());
}
resultList.add(buildResultItem(item, customer, brand, shop));
}
return resultList;
}

@Transactional(rollbackFor = Exception.class)
@Override
public boolean saveCustomerAndDemand(InvestDemandVo customerDemandVo) {
InvestHelper.allNotNull(customerDemandVo);
InvestHelper.allNotNull(customerDemandVo.getBrand(), customerDemandVo.getCustomer());
InvestCustomerEntity customerEntity = customerDemandVo.getCustomer();
customerService.save(customerEntity);
InvestDemandEntity demandEntity = new InvestDemandEntity();
BeanUtils.copyProperties(customerDemandVo, demandEntity);
return demandService.save(demandEntity);
}

@Transactional(rollbackFor = Exception.class)
@Override
public boolean updateCustomerAndDemand(InvestDemandVo customerDemandVo) {
InvestHelper.allNotNull(customerDemandVo);
InvestHelper.allNotNull(customerDemandVo.getBrand(), customerDemandVo.getCustomer());
InvestCustomerEntity customerEntity = customerDemandVo.getCustomer();
customerService.updateById(customerEntity);
InvestDemandEntity demandEntity = new InvestDemandEntity();
BeanUtils.copyProperties(customerDemandVo, demandEntity);
return demandService.updateById(demandEntity);
}

@Override
public InvestDemandVo findById(Long id) {
InvestHelper.allNotNull(id);
InvestDemandEntity demandEntity = demandService.getByIdNotNull(id);
InvestCustomerEntity customerEntity = customerService.getByIdNotNull(demandEntity.getCustomerId());
WxBrand brand = brandService.getById(customerEntity.getBrandId());
WxShop shop = shopService.getById(demandEntity.getTargetId());
return buildResultItem(demandEntity, customerEntity, brand, shop);
}

private InvestDemandVo buildResultItem(InvestDemandEntity item, InvestCustomerEntity customer, WxBrand brand, WxShop shop) {
InvestDemandVo resultItemVo = InvestDemandVo.builder()
.brand(brand)
.customer(customer)
.targetInfo(shop)
.build();
BeanUtils.copyProperties(item, resultItemVo);
return resultItemVo;
}
}

Loading…
Откажи
Сачувај