From 67e6c962b4f0db50b2d51de089ed8599d89f6805 Mon Sep 17 00:00:00 2001 From: Burce Date: Tue, 8 Oct 2019 10:52:58 +0800 Subject: [PATCH] =?UTF-8?q?[=E6=8B=9B=E5=95=86]adjust?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/iformall/common/LogColumn.java | 12 ++ .../domain/vo/invest/TableTriple.java | 24 ++++ .../service/invest/InvestBaseService.java | 16 +++ .../service/invest/InvestBizService.java | 17 +++ .../iformall/service/invest/InvestHelper.java | 86 ++++++++++++ .../invest/impl/InvestBizServiceImpl.java | 131 ++++++++++++++++++ 6 files changed, 286 insertions(+) create mode 100644 mallinkService/src/main/java/com/iformall/common/LogColumn.java create mode 100644 mallinkService/src/main/java/com/iformall/domain/vo/invest/TableTriple.java create mode 100755 mallinkService/src/main/java/com/iformall/service/invest/InvestBaseService.java create mode 100644 mallinkService/src/main/java/com/iformall/service/invest/InvestBizService.java create mode 100644 mallinkService/src/main/java/com/iformall/service/invest/InvestHelper.java create mode 100644 mallinkService/src/main/java/com/iformall/service/invest/impl/InvestBizServiceImpl.java diff --git a/mallinkService/src/main/java/com/iformall/common/LogColumn.java b/mallinkService/src/main/java/com/iformall/common/LogColumn.java new file mode 100644 index 000000000..4199b22ec --- /dev/null +++ b/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 ""; +} diff --git a/mallinkService/src/main/java/com/iformall/domain/vo/invest/TableTriple.java b/mallinkService/src/main/java/com/iformall/domain/vo/invest/TableTriple.java new file mode 100644 index 000000000..b0518a4f0 --- /dev/null +++ b/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 implements Comparable>, Serializable { + private final K column; + private final L before ; + private final R after ; + + + + @Override + public int compareTo(TableTriple other) { + return new CompareToBuilder().append(getColumn(), other.getColumn()) + .append(getBefore(), other.getBefore()) + .append(getAfter(), other.getAfter()).toComparison(); + } +} diff --git a/mallinkService/src/main/java/com/iformall/service/invest/InvestBaseService.java b/mallinkService/src/main/java/com/iformall/service/invest/InvestBaseService.java new file mode 100755 index 000000000..7e92f266c --- /dev/null +++ b/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 getByIdNotNull(Serializable id); +} + diff --git a/mallinkService/src/main/java/com/iformall/service/invest/InvestBizService.java b/mallinkService/src/main/java/com/iformall/service/invest/InvestBizService.java new file mode 100644 index 000000000..2c5805556 --- /dev/null +++ b/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 queryPage(InvestPageQuery params); + + boolean saveCustomerAndDemand(InvestDemandVo customerDemandVo) ; + + boolean updateCustomerAndDemand(InvestDemandVo customerDemandVo) ; + + InvestDemandVo findById(Long id) ; +} diff --git a/mallinkService/src/main/java/com/iformall/service/invest/InvestHelper.java b/mallinkService/src/main/java/com/iformall/service/invest/InvestHelper.java new file mode 100644 index 000000000..a5311c838 --- /dev/null +++ b/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 Page buildQueryPage(InvestPageQuery pageQuery) { + Page 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); + } + } +} diff --git a/mallinkService/src/main/java/com/iformall/service/invest/impl/InvestBizServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/invest/impl/InvestBizServiceImpl.java new file mode 100644 index 000000000..18e893153 --- /dev/null +++ b/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 queryPage(InvestPageQuery params) { + InvestHelper.allNotNull(params); + Page page = InvestHelper.buildQueryPage(params); + InvestPageResult investPage = new InvestPageResult<>(); + //1、客户需求 + InvestDemandEntity queryTask = params.getQueryData(); + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(queryTask); + IPage demandPage = demandService.page(page, queryWrapper); + if (CollectionUtils.isEmpty(demandPage.getRecords())) { + return investPage; + } + + List resultList = getITargeInfoList(demandPage); + + BeanUtils.copyProperties(demandPage, investPage); + investPage.setRecords(resultList); + return investPage; + } + + private List getITargeInfoList(IPage demandPage) { + List demandList = demandPage.getRecords(); + //2、客户信息 + Collection customers = customerService.listByIds(demandList + .stream().map(InvestDemandEntity::getCustomerId).collect(Collectors.toList())); + Map customersMap = customers.stream().collect(Collectors.toMap(InvestCustomerEntity::getId, customer -> customer)); + + //3、目标信息 + Collection shops = shopService.getByIds(demandList.stream().map(InvestDemandEntity::getTargetId).collect(Collectors.toList())); + Map shopsMap = shops.stream().collect(Collectors.toMap(WxShop::getId, shop -> shop)); + + //4 品牌 + Collection brands = brandService.getByIds(customers.stream().map(InvestCustomerEntity::getBrandId).collect(Collectors.toList())); + Map brandMap = brands.stream().collect(Collectors.toMap(WxBrand::getId, brand -> brand)); + + List 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; + } +}