From 4b2e14887b0c0d858c912c3a38e22951da8f1ebe Mon Sep 17 00:00:00 2001 From: Burce Date: Tue, 8 Oct 2019 10:51: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 --- .../invest/InvestDemandController.java | 13 +- .../invest/InvestRemindController.java | 2 +- .../invest/InvestTaskController.java | 2 +- .../com/iformall/log/TableOperateAspect.java | 176 ++++++++++++++++-- .../java/com/iformall/common/ErrorCode.java | 7 +- .../iformall/domain/po/InvestBaseEntity.java | 2 + .../domain/po/InvestCustomerEntity.java | 15 +- .../domain/po/InvestDemandEntity.java | 4 +- .../domain/po/InvestOperateRecordEntity.java | 17 +- .../com/iformall/enums/EnumInvestChannel.java | 1 + .../service/invest/InvestCustomerService.java | 3 +- .../service/invest/InvestDemandService.java | 14 +- .../invest/InvestFollowRecordService.java | 2 +- .../service/invest/InvestRemindService.java | 2 +- .../service/invest/InvestTaskService.java | 3 +- ...ervice.java => InvestBaseServiceImpl.java} | 92 ++++----- .../impl/InvestCustomerServiceImpl.java | 73 +++----- .../invest/impl/InvestDemandServiceImpl.java | 144 +++----------- .../impl/InvestFollowRecordServiceImpl.java | 47 +++-- .../impl/InvestOperateRecordServiceImpl.java | 28 ++- .../invest/impl/InvestRemindServiceImpl.java | 19 +- .../invest/impl/InvestTaskServiceImpl.java | 43 +++-- .../iformall/utils/SpringContextUtils.java | 4 + 23 files changed, 371 insertions(+), 342 deletions(-) rename mallinkService/src/main/java/com/iformall/service/invest/impl/{InvestBaseService.java => InvestBaseServiceImpl.java} (61%) diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/invest/InvestDemandController.java b/mallinkAdmin/src/main/java/com/iformall/controller/invest/InvestDemandController.java index e706481fc..4d1632c22 100755 --- a/mallinkAdmin/src/main/java/com/iformall/controller/invest/InvestDemandController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/invest/InvestDemandController.java @@ -6,6 +6,7 @@ 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; +import com.iformall.service.invest.InvestBizService; import com.iformall.service.invest.InvestDemandService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -28,6 +29,10 @@ import java.util.Arrays; @RequestMapping("invest/demand") @Api(tags = "需求管理") public class InvestDemandController extends InvestBaseController { + + @Autowired + private InvestBizService investBizService ; + @Autowired private InvestDemandService investDemandService; @@ -38,7 +43,7 @@ public class InvestDemandController extends InvestBaseController { @ApiOperation(value = "分页列表接口") @GetMapping("/list") public InvestResultData> list(InvestPageQuery params) { - return execute(params, p -> investDemandService.queryPage(p)); + return execute(params, p -> investBizService.queryPage(p)); } @@ -48,7 +53,7 @@ public class InvestDemandController extends InvestBaseController { @SystemServiceLog @GetMapping("/info/{id}") public InvestResultData info(@PathVariable("id") Long id) { - return execute(id, p -> investDemandService.findById(p)); + return execute(id, p -> investBizService.findById(p)); } /** @@ -57,7 +62,7 @@ public class InvestDemandController extends InvestBaseController { @SystemServiceLog @PostMapping("/save") public InvestResultData save(InvestDemandVo investDemand) { - return execute(investDemand, p -> investDemandService.saveCustomerAndDemand(p)); + return execute(investDemand, p -> investBizService.saveCustomerAndDemand(p)); } /** @@ -66,7 +71,7 @@ public class InvestDemandController extends InvestBaseController { @SystemServiceLog @PostMapping("/update") public InvestResultData update(InvestDemandVo investDemand) { - return execute(investDemand, p -> investDemandService.updateCustomerAndDemand(p)); + return execute(investDemand, p -> investBizService.updateCustomerAndDemand(p)); } /** diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/invest/InvestRemindController.java b/mallinkAdmin/src/main/java/com/iformall/controller/invest/InvestRemindController.java index 216e3a927..037cabc8b 100755 --- a/mallinkAdmin/src/main/java/com/iformall/controller/invest/InvestRemindController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/invest/InvestRemindController.java @@ -46,7 +46,7 @@ public class InvestRemindController extends InvestBaseController { */ @GetMapping("/info/{id}") public InvestResultData info(@PathVariable("id") Long id) { - return execute(id, p -> investRemindService.getById(p)); + return execute(id, p -> investRemindService.getByIdNotNull(p)); } /** diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/invest/InvestTaskController.java b/mallinkAdmin/src/main/java/com/iformall/controller/invest/InvestTaskController.java index 58a21b991..c5ec0c60c 100755 --- a/mallinkAdmin/src/main/java/com/iformall/controller/invest/InvestTaskController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/invest/InvestTaskController.java @@ -49,7 +49,7 @@ public class InvestTaskController extends InvestBaseController { @SystemServiceLog @GetMapping("/info/{id}") public InvestResultData info(@PathVariable("id") Long id){ - return execute(id, p -> investTaskService.getById(id)); + return execute(id, p -> investTaskService.getByIdNotNull(id)); } /** diff --git a/mallinkAdmin/src/main/java/com/iformall/log/TableOperateAspect.java b/mallinkAdmin/src/main/java/com/iformall/log/TableOperateAspect.java index 993d3e168..86395b875 100644 --- a/mallinkAdmin/src/main/java/com/iformall/log/TableOperateAspect.java +++ b/mallinkAdmin/src/main/java/com/iformall/log/TableOperateAspect.java @@ -1,15 +1,35 @@ package com.iformall.log; +import com.alibaba.fastjson.JSON; +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.google.common.collect.MapDifference; +import com.google.common.collect.Maps; +import com.iformall.common.LogColumn; +import com.iformall.domain.po.InvestBaseEntity; +import com.iformall.domain.po.InvestOperateRecordEntity; +import com.iformall.domain.vo.invest.TableTriple; +import com.iformall.enums.EnumTableOperateType; +import com.iformall.service.invest.InvestOperateRecordService; +import com.iformall.service.invest.impl.InvestBaseServiceImpl; +import com.iformall.utils.SpringContextUtils; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.compress.utils.Lists; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.reflect.FieldUtils; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Pointcut; import org.aspectj.lang.reflect.MethodSignature; -import org.springframework.core.env.Environment; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import java.util.Arrays; +import java.io.Serializable; +import java.lang.reflect.Field; +import java.lang.reflect.ParameterizedType; +import java.util.*; /** * @@ -19,11 +39,8 @@ import java.util.Arrays; @Component public class TableOperateAspect { - private final Environment env; - - public TableOperateAspect(Environment env) { - this.env = env; - } + @Autowired + private InvestOperateRecordService operateRecordService; @Pointcut("@annotation(com.iformall.common.TableLog)") public void pointcut() { @@ -34,15 +51,150 @@ public class TableOperateAspect { MethodSignature signature = (MethodSignature) joinPoint.getSignature(); log.debug("before , {}.{}() with argument[s] = {}", signature.getDeclaringType(), signature.getName(), Arrays.toString(joinPoint.getArgs())); - Object object = null; + Object result = null; + Object entity = null; + Map beforeMap = null; + Long tid = null; try { - object = joinPoint.proceed(); + entity = joinPoint.getArgs()[0]; + tid = getId(entity); + beforeMap = getFeildMap(getById(signature, tid)); + } catch (Exception e) { + log.error("before ", e); + } + try { + result = joinPoint.proceed(); } catch (Throwable throwable) { - log.error("Illegal argument: {} in {}.{}()", Arrays.toString(joinPoint.getArgs()), + log.error("proceed error , Illegal argument: {} in {}.{}()", Arrays.toString(joinPoint.getArgs()), joinPoint.getSignature().getDeclaringTypeName(), joinPoint.getSignature().getName(), throwable); } finally { - log.debug("after , result: {}", object); + log.debug("after , result: {}", result); + } + try { + saveRecord(signature, beforeMap, entity, tid); + } catch (Exception e) { + log.error("save table Record ", e); + } + return result; + } + + private Long getId(Object entity) { + Long tid; + if (entity instanceof InvestBaseEntity) { + tid = ((InvestBaseEntity) entity).getId(); + } else { + tid = (Long) entity; } - return object; + return tid; + } + + private void saveRecord(MethodSignature signature, Map beforeMap, Object arg, Long tid) throws IllegalAccessException { + EnumTableOperateType operateType = getOperateType(signature.getName()); + if (Objects.equals(operateType, EnumTableOperateType.DELETE)) { + arg = null; + } + if (Objects.isNull(tid)) { + tid = getId(arg); + } + Map afterMap = getFeildMap(arg); + List content = getContent(beforeMap, afterMap); + log.debug("operate content: {}", JSON.toJSONString(content)); + InvestOperateRecordEntity recordEntity = new InvestOperateRecordEntity(); + if (CollectionUtils.isEmpty(content)) { + return; + } + recordEntity.setContent(JSON.toJSONString(content)); + recordEntity.setOperateType(operateType); + recordEntity.setTbl(getTbl(signature)); + recordEntity.setTid(tid); + operateRecordService.save(recordEntity); + log.debug("saveRecord: {}", JSON.toJSONString(recordEntity)); + } + + private String getTbl(MethodSignature signature) { + ParameterizedType type = (ParameterizedType) signature.getDeclaringType().getGenericSuperclass(); + Class clazz = (Class) type.getActualTypeArguments()[1]; + TableName tableName = (TableName) clazz.getAnnotation(TableName.class); + return tableName.value(); + } + + private EnumTableOperateType getOperateType(String methodName) { + if (StringUtils.contains(methodName, "update")) { + return EnumTableOperateType.UPDATE; + } else if (StringUtils.contains(methodName, "remove")) { + return EnumTableOperateType.DELETE; + } + return EnumTableOperateType.ADD; + } + + private Map getFeildMap(Object entity) throws IllegalAccessException { + if (Objects.isNull(entity)) { + return null; + } + Map map = new HashMap<>(); + List fields = FieldUtils.getFieldsListWithAnnotation(entity.getClass(), LogColumn.class); + for (Field field : fields) { + String annotationVal = field.getAnnotation(LogColumn.class).value(); + Object value = FieldUtils.readDeclaredField(entity, field.getName(), true); + if (Objects.equals(annotationVal, InvestBaseEntity.COLUMN_TYPE)) { + value = JSON.parseObject((String) value, Map.class); + } + map.put(field.getName(), value); + } + return map; + } + + private List> getContent(Map before, Map after) { + if (Objects.isNull(before) || Objects.isNull(after)) { + return mapToList(before, after); + } + MapDifference diffInner = Maps.difference(before, after); + List> diffRows = Lists.newArrayList(); + if (diffInner.areEqual()) { + return diffRows; + } + Map> differenceMap = diffInner.entriesDiffering(); + for (Map.Entry> entry : differenceMap.entrySet()) { + String s = entry.getKey(); + MapDifference.ValueDifference objectValueDifference = entry.getValue(); + Object innerBefore = objectValueDifference.leftValue(); + Object innerAfter = objectValueDifference.rightValue(); + if (innerBefore instanceof Map) { + diffRows.addAll(getContent((Map) innerBefore, (Map) innerAfter)); + } else { + diffRows.add(TableTriple.of(s, innerBefore, innerAfter)); + } + } + return diffRows; + } + + private List> mapToList(Map before, Map after) { + List> list = Lists.newArrayList(); + Set keys = Objects.isNull(before) ? after.keySet() : before.keySet(); + for (String key : keys) { + if (Objects.isNull(before)) { + Object innerAfter = after.get(key); + if (innerAfter instanceof Map) { + list.addAll(mapToList(null, (Map) innerAfter)); + } else { + list.add(TableTriple.of(key, "", innerAfter)); + } + } else { + Object innerBefore = before.get(key); + if (innerBefore instanceof Map) { + list.addAll(mapToList((Map) innerBefore, null)); + } else { + list.add(TableTriple.of(key, innerBefore, "")); + } + } + } + return list; + } + + private T getById(MethodSignature signature, Serializable id) { + Class service = signature.getDeclaringType(); + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("id", id); + return (T) ((InvestBaseServiceImpl) SpringContextUtils.getBean(service)).getOne(wrapper); } } diff --git a/mallinkService/src/main/java/com/iformall/common/ErrorCode.java b/mallinkService/src/main/java/com/iformall/common/ErrorCode.java index 4806eebb6..7d82f0cc2 100644 --- a/mallinkService/src/main/java/com/iformall/common/ErrorCode.java +++ b/mallinkService/src/main/java/com/iformall/common/ErrorCode.java @@ -1,6 +1,5 @@ package com.iformall.common; -import org.springframework.util.ObjectUtils; import java.text.MessageFormat; @@ -527,7 +526,8 @@ public enum ErrorCode{ // 招商管理 53000 begin INVEST_CUSTOMER_NOT_FOUND(53000, "客户信息不存在"), INVEST_UNKNOW_ERRROR(53001, "客户信息不存在"), - INVEST_DATA_NOT_FOUND(53002, "信息不存在"), + INVEST_PARAMETER_NOT_FOUND(53002, "不能为空"), + INVEST_RESULT_NOT_FOUND(53003, "不存在"), // 招商管理 53999 end @@ -555,8 +555,7 @@ public enum ErrorCode{ if (param.length == 0) { return message; } - //return MessageFormat.format(message, param); - return MessageFormat.format("{0}, {1}", ObjectUtils.nullSafeToString(param), message); + return MessageFormat.format(message, param); } public static ErrorCode getByCode(int code) { diff --git a/mallinkService/src/main/java/com/iformall/domain/po/InvestBaseEntity.java b/mallinkService/src/main/java/com/iformall/domain/po/InvestBaseEntity.java index f200d716b..e4c43e122 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/InvestBaseEntity.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/InvestBaseEntity.java @@ -17,6 +17,8 @@ public class InvestBaseEntity implements Serializable { private static final long serialVersionUID = 1L; + public static final String COLUMN_TYPE = "json"; + /** * 主键ID */ diff --git a/mallinkService/src/main/java/com/iformall/domain/po/InvestCustomerEntity.java b/mallinkService/src/main/java/com/iformall/domain/po/InvestCustomerEntity.java index 5b51c4e95..0209807ba 100755 --- a/mallinkService/src/main/java/com/iformall/domain/po/InvestCustomerEntity.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/InvestCustomerEntity.java @@ -4,8 +4,8 @@ import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.Version; -import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonProperty; +import com.iformall.common.LogColumn; import com.iformall.enums.EnumCustomerRatingType; import com.iformall.enums.EnumCustomerType; import com.iformall.enums.EnumInvestChannel; @@ -27,39 +27,46 @@ public class InvestCustomerEntity extends InvestBaseEntity { /** * 客户名称 */ + @LogColumn @io.swagger.annotations.ApiModelProperty(value = "客户名称", name = "name") private String name; /** * 电话 */ + @LogColumn @io.swagger.annotations.ApiModelProperty(value = "电话", name = "phone") private String phone; /** * 经营业态 */ + @LogColumn @io.swagger.annotations.ApiModelProperty(value = "经营业态", name = "businessId") private Integer businessId; /** * 品牌ID */ + @LogColumn @io.swagger.annotations.ApiModelProperty(value = "品牌ID", name = "brandId") private Long brandId; /** * 客户分类:0-潜在客户;1-意向客户;2-合作客户;3-谈判失败 */ @io.swagger.annotations.ApiModelProperty(value = "客户分类:0-潜在客户;1-意向客户;2-合作客户;3-谈判失败", name = "type") - private EnumCustomerType type; + @LogColumn + private EnumCustomerType type; /** * 客户预评级:0-无;1-主力店;2-次主力店;3-甲;4-乙;5-丙 */ @io.swagger.annotations.ApiModelProperty(value = "客户预评级:0-无;1-主力店;2-次主力店;3-甲;4-乙;5-丙", name = "rating") - private EnumCustomerRatingType rating; + @LogColumn + private EnumCustomerRatingType rating; /** * 招商渠道:0-无;1-电视;2-广播;3-报纸;4-刊物;5-物联网;6-招商活动;7-中介机构;8-自定义渠道 */ @io.swagger.annotations.ApiModelProperty(value = "招商渠道:0-无;1-电视;2-广播;3-报纸;4-刊物;5-物联网;6-招商活动;7-中介机构;8-自定义渠道", name = "investChannel") - private EnumInvestChannel investChannel; + @LogColumn + private EnumInvestChannel investChannel = EnumInvestChannel.NONE; /** * 更新时间 diff --git a/mallinkService/src/main/java/com/iformall/domain/po/InvestDemandEntity.java b/mallinkService/src/main/java/com/iformall/domain/po/InvestDemandEntity.java index d8e9d3507..19cd5687d 100755 --- a/mallinkService/src/main/java/com/iformall/domain/po/InvestDemandEntity.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/InvestDemandEntity.java @@ -4,8 +4,8 @@ import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.Version; -import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonProperty; +import com.iformall.common.LogColumn; import com.iformall.enums.EnumInvestType; import lombok.Data; @@ -26,6 +26,7 @@ public class InvestDemandEntity extends InvestBaseEntity { * 负责人 */ @io.swagger.annotations.ApiModelProperty(value = "负责人", name = "owner") + @LogColumn private Long owner; /** * 客户ID @@ -37,6 +38,7 @@ public class InvestDemandEntity extends InvestBaseEntity { */ @io.swagger.annotations.ApiModelProperty(value = "客户意向", name = "intent", example = "{\"rent_area\":100,\"opening_time\": 2019-09-03}") + @LogColumn(COLUMN_TYPE) private String intent; /** * 目标类型:0-商铺招租;1-其他 diff --git a/mallinkService/src/main/java/com/iformall/domain/po/InvestOperateRecordEntity.java b/mallinkService/src/main/java/com/iformall/domain/po/InvestOperateRecordEntity.java index 2cc6728f9..5ee137927 100755 --- a/mallinkService/src/main/java/com/iformall/domain/po/InvestOperateRecordEntity.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/InvestOperateRecordEntity.java @@ -5,10 +5,10 @@ import com.baomidou.mybatisplus.annotation.TableName; import java.util.Date; +import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonIgnore; import com.iformall.enums.EnumTableOperateType; import lombok.Data; -import com.fasterxml.jackson.annotation.JsonFormat; /** * 操作记录 @@ -42,17 +42,12 @@ public class InvestOperateRecordEntity extends InvestBaseEntity { @io.swagger.annotations.ApiModelProperty(value = "操作类型:0-ADD;1-UPDATE;2-DELETE", name = "operateType") private EnumTableOperateType operateType; /** - * 更新前 + * 更新内容 */ - @io.swagger.annotations.ApiModelProperty(value = "更新前", name = "before") - @TableField(value = "`before`") - private String before; - /** - * 更新后 - */ - @io.swagger.annotations.ApiModelProperty(value = "更新后", name = "after") - @TableField(value = "`after`") - private String after; + @JsonFormat + @io.swagger.annotations.ApiModelProperty(value = "更新前", name = "content") + private String content; + /** * 创建时间 */ diff --git a/mallinkService/src/main/java/com/iformall/enums/EnumInvestChannel.java b/mallinkService/src/main/java/com/iformall/enums/EnumInvestChannel.java index f48850f37..acc9af97c 100644 --- a/mallinkService/src/main/java/com/iformall/enums/EnumInvestChannel.java +++ b/mallinkService/src/main/java/com/iformall/enums/EnumInvestChannel.java @@ -7,6 +7,7 @@ import com.fasterxml.jackson.annotation.JsonValue; * 招商渠道:0-无;1-电视;2-广播;3-报纸;4-刊物;5-物联网;6-招商活动;7-中介机构;8-自定义渠道 */ public enum EnumInvestChannel { + NONE(0, ""), TV(1, "电视"), BROADCAST(2, "广播"), NEWSPAPER(3, "报纸"), diff --git a/mallinkService/src/main/java/com/iformall/service/invest/InvestCustomerService.java b/mallinkService/src/main/java/com/iformall/service/invest/InvestCustomerService.java index 7571e56c9..da3ff152b 100755 --- a/mallinkService/src/main/java/com/iformall/service/invest/InvestCustomerService.java +++ b/mallinkService/src/main/java/com/iformall/service/invest/InvestCustomerService.java @@ -2,7 +2,6 @@ package com.iformall.service.invest; import com.baomidou.mybatisplus.extension.service.IService; import com.iformall.domain.po.InvestCustomerEntity; -import com.iformall.domain.po.InvestFollowRecordEntity; import com.iformall.domain.vo.invest.InvestPageQuery; import java.util.List; @@ -14,7 +13,7 @@ import java.util.List; * @email * @date 2019-09-23 18:40:43 */ -public interface InvestCustomerService extends IService { +public interface InvestCustomerService extends IService,InvestBaseService { List queryPage(InvestPageQuery params); } diff --git a/mallinkService/src/main/java/com/iformall/service/invest/InvestDemandService.java b/mallinkService/src/main/java/com/iformall/service/invest/InvestDemandService.java index 8f4cab0d8..29b3a7cd8 100755 --- a/mallinkService/src/main/java/com/iformall/service/invest/InvestDemandService.java +++ b/mallinkService/src/main/java/com/iformall/service/invest/InvestDemandService.java @@ -1,11 +1,8 @@ package com.iformall.service.invest; import com.baomidou.mybatisplus.extension.service.IService; -import com.iformall.domain.po.InvestCustomerEntity; 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; + /** * 客户需求 @@ -14,14 +11,7 @@ import com.iformall.domain.vo.invest.InvestPageResult; * @email * @date 2019-09-23 18:40:42 */ -public interface InvestDemandService extends IService { - - InvestPageResult queryPage(InvestPageQuery params); - - boolean saveCustomerAndDemand(InvestDemandVo customerDemandVo) ; - - boolean updateCustomerAndDemand(InvestDemandVo customerDemandVo) ; +public interface InvestDemandService extends IService,InvestBaseService { - InvestDemandVo findById(Long id) ; } diff --git a/mallinkService/src/main/java/com/iformall/service/invest/InvestFollowRecordService.java b/mallinkService/src/main/java/com/iformall/service/invest/InvestFollowRecordService.java index dadca3faf..360879828 100755 --- a/mallinkService/src/main/java/com/iformall/service/invest/InvestFollowRecordService.java +++ b/mallinkService/src/main/java/com/iformall/service/invest/InvestFollowRecordService.java @@ -12,7 +12,7 @@ import com.iformall.domain.vo.invest.InvestPageResult; * @email * @date 2019-09-23 18:40:43 */ -public interface InvestFollowRecordService extends IService { +public interface InvestFollowRecordService extends IService,InvestBaseService { InvestPageResult queryPage(InvestPageQuery params); } diff --git a/mallinkService/src/main/java/com/iformall/service/invest/InvestRemindService.java b/mallinkService/src/main/java/com/iformall/service/invest/InvestRemindService.java index 1dd7476f7..79d393eac 100755 --- a/mallinkService/src/main/java/com/iformall/service/invest/InvestRemindService.java +++ b/mallinkService/src/main/java/com/iformall/service/invest/InvestRemindService.java @@ -12,7 +12,7 @@ import com.iformall.domain.vo.invest.InvestPageResult; * @email * @date 2019-09-23 18:40:43 */ -public interface InvestRemindService extends IService { +public interface InvestRemindService extends IService,InvestBaseService { InvestPageResult queryPage(InvestPageQuery params); } diff --git a/mallinkService/src/main/java/com/iformall/service/invest/InvestTaskService.java b/mallinkService/src/main/java/com/iformall/service/invest/InvestTaskService.java index 8647a14c2..58385f370 100755 --- a/mallinkService/src/main/java/com/iformall/service/invest/InvestTaskService.java +++ b/mallinkService/src/main/java/com/iformall/service/invest/InvestTaskService.java @@ -13,8 +13,9 @@ import com.iformall.domain.vo.invest.InvestTaskVo; * @email * @date 2019-09-23 18:40:43 */ -public interface InvestTaskService extends IService { +public interface InvestTaskService extends IService,InvestBaseService { InvestPageResult queryPage(InvestPageQuery params); + } diff --git a/mallinkService/src/main/java/com/iformall/service/invest/impl/InvestBaseService.java b/mallinkService/src/main/java/com/iformall/service/invest/impl/InvestBaseServiceImpl.java similarity index 61% rename from mallinkService/src/main/java/com/iformall/service/invest/impl/InvestBaseService.java rename to mallinkService/src/main/java/com/iformall/service/invest/impl/InvestBaseServiceImpl.java index de34bc1c5..3ede362d5 100644 --- a/mallinkService/src/main/java/com/iformall/service/invest/impl/InvestBaseService.java +++ b/mallinkService/src/main/java/com/iformall/service/invest/impl/InvestBaseServiceImpl.java @@ -1,13 +1,11 @@ package com.iformall.service.invest.impl; - import com.alibaba.fastjson.JSONArray; import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.iformall.common.ErrorCode; -import com.iformall.common.TableLog; import com.iformall.domain.po.*; import com.iformall.domain.vo.invest.InvestPageQuery; import com.iformall.domain.vo.invest.InvestUserContext; @@ -15,10 +13,14 @@ import com.iformall.enums.EnumInvestType; import com.iformall.enums.EnumShopStatus; import com.iformall.exception.MallinkException; import com.iformall.service.MallUserInfoService; +import com.iformall.service.WxBrandService; +import com.iformall.service.WxBusinessService; import com.iformall.service.WxShopService; +import com.iformall.service.invest.InvestBaseService; import com.iformall.service.invest.InvestCustomerService; +import com.iformall.service.invest.InvestHelper; +import com.iformall.utils.JsonUtil; import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.lang3.ObjectUtils; import java.io.Serializable; import java.util.List; @@ -26,42 +28,39 @@ import java.util.Objects; import java.util.function.Consumer; import java.util.stream.Collectors; -public class InvestBaseService, T> extends ServiceImpl { +public class InvestBaseServiceImpl, T> extends ServiceImpl implements InvestBaseService { @Override - public T getById(Serializable id) { + public T getByIdNotNull(Serializable id) { + InvestHelper.checkResult(id,"id=null"); T t = super.getById(id); - checkResult(t, id); + InvestHelper.checkResult(t,"id=null"); return t; } - @TableLog - public boolean saveAction(T entity, Consumer consumer) { + boolean saveAction(T entity, Consumer consumer) { checkUserAndTenant(entity,consumer); return super.save(entity); } - @TableLog - public boolean updateActon(T entity, Wrapper updateWrapper,Consumer consumer) { + boolean updateActon(T entity, Wrapper updateWrapper, Consumer consumer) { checkUserAndTenant(entity,consumer); return super.update(entity, updateWrapper); } - @TableLog - public boolean saveOrUpdateAction(T entity,Consumer consumer) { + boolean saveOrUpdateAction(T entity, Consumer consumer) { checkUserAndTenant(entity,consumer); return super.saveOrUpdate(entity); } - @TableLog - public boolean updateByIdAction(T entity,Consumer consumer) { + boolean updateByIdAction(T entity, Consumer consumer) { checkUserAndTenant(entity,consumer); return super.updateById(entity); } void checkUserAndTenant(T input,Consumer consumer) { - checkAllNotNull(input); - checkAllNotNull(InvestUserContext.getUser()); + InvestHelper.notNull(input, "参数"); + InvestHelper.notNull(InvestUserContext.getUser(), ErrorCode.USER_IS_EMPTY); ((InvestBaseEntity) input).setTenantId(InvestUserContext.getUser().getTenantId()); consumer.accept(input); } @@ -84,6 +83,7 @@ public class InvestBaseService, T> extends ServiceImpl, T> extends ServiceImpl, T> extends ServiceImpl usersFromDb = userInfoService.getByIds(ids).stream().map(MallUserInfo::getId).collect(Collectors.toList()); List notExsitIds = ids.stream().filter(uid -> !usersFromDb.contains(uid)).collect(Collectors.toList()); - if (CollectionUtils.isNotEmpty(notExsitIds)) { - throwException(ErrorCode.USER_IS_EMPTY, notExsitIds); - } + InvestHelper.isTrue(CollectionUtils.isEmpty(notExsitIds), ErrorCode.USER_IS_EMPTY, notExsitIds); } } } @@ -128,49 +121,27 @@ public class InvestBaseService, T> extends ServiceImpl buildQueryPage(InvestPageQuery pageQuery) { + return InvestHelper.buildQueryPage(pageQuery) ; } @@ -178,8 +149,9 @@ public class InvestBaseService, T> extends ServiceImpl implements InvestCustomerService { +public class InvestCustomerServiceImpl extends InvestBaseServiceImpl implements InvestCustomerService { @Autowired private WxBrandService brandService; @@ -31,62 +30,50 @@ public class InvestCustomerServiceImpl extends InvestBaseService checkBeforeSaveOrUpdate(input)); - } - - @Override - public boolean update(InvestCustomerEntity entity, Wrapper updateWrapper) { - return super.updateActon(entity, updateWrapper,input -> checkBeforeSaveOrUpdate(input)); + return super.saveAction(entity, this::checkBeforeSaveOrUpdate); } - @Deprecated - @Override - public boolean saveOrUpdate(InvestCustomerEntity entity) { - notSupport(); - return false ; - } + @TableLog + @Override + public boolean update(InvestCustomerEntity entity, Wrapper updateWrapper) { + return super.updateActon(entity, updateWrapper, this::checkBeforeSaveOrUpdate); + } - @Override - public boolean updateById(InvestCustomerEntity entity) { - return super.updateByIdAction(entity, input -> checkBeforeSaveOrUpdate(input)); - } + @TableLog + @Override + public boolean updateById(InvestCustomerEntity entity) { + return super.updateByIdAction(entity, this::checkBeforeSaveOrUpdate); + } private void checkBeforeSaveOrUpdate(InvestCustomerEntity entity) { - checkBusiness(entity); - checkBrand(entity); + checkBusiness(businessService, entity.getBusinessId()); + checkBrand(brandService, entity.getBrandId()); checkType(entity); } - private void checkBusiness(InvestCustomerEntity entity) { - WxBusiness business = businessService.getById(entity.getBusinessId()) ; - if (Objects.isNull(business)) { - throw new MallinkException(ErrorCode.BUSINESS_NOT_FOUND); - } - } - /** * 校验客户类型 * @param entity */ private void checkType(InvestCustomerEntity entity) { - if (Objects.isNull(entity.getType())) { - throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), - ErrorCode.SYS_PARAMETER_NOT_NULL.getMessage("type")); - } + isTrue(Objects.nonNull(entity.getType()), ErrorCode.SYS_PARAMETER_NOT_NULL, "客户类型"); } - /** - * 校验品牌 - * @param entity - */ - private void checkBrand(InvestCustomerEntity entity) { - WxBrand brand = brandService.getById(entity.getBrandId()); - if (Objects.isNull(brand)) { - throw new MallinkException(ErrorCode.BRAND_NOT_FOUND); - } + + @Deprecated + @Override + public boolean saveOrUpdate(InvestCustomerEntity entity) { + notSupport(); + return false ; + } + + @Deprecated + @Override + public boolean update(Wrapper updateWrapper) { + notSupport(); + return false ; } } diff --git a/mallinkService/src/main/java/com/iformall/service/invest/impl/InvestDemandServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/invest/impl/InvestDemandServiceImpl.java index a86a790e0..ce90c0660 100755 --- a/mallinkService/src/main/java/com/iformall/service/invest/impl/InvestDemandServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/invest/impl/InvestDemandServiceImpl.java @@ -1,34 +1,21 @@ package com.iformall.service.invest.impl; -import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.Wrapper; -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.common.TableLog; 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.mapper.InvestDemandDao; import com.iformall.service.MallUserInfoService; -import com.iformall.service.WxBrandService; import com.iformall.service.WxShopService; import com.iformall.service.invest.InvestCustomerService; import com.iformall.service.invest.InvestDemandService; -import org.apache.commons.collections.CollectionUtils; -import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.*; -import java.util.stream.Collectors; +import java.util.Objects; @Service -public class InvestDemandServiceImpl extends InvestBaseService implements InvestDemandService { +public class InvestDemandServiceImpl extends InvestBaseServiceImpl implements InvestDemandService { @Autowired private WxShopService shopService; @@ -36,122 +23,22 @@ public class InvestDemandServiceImpl extends InvestBaseService queryPage(InvestPageQuery params) { - checkAllNotNull(params); - Page page = buildQueryPage(params); - InvestPageResult investPage = new InvestPageResult<>(); - //1、客户需求 - InvestDemandEntity queryTask = params.getQueryData(); - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(queryTask); - IPage demandPage = this.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; - } - - @Override - public boolean saveCustomerAndDemand(InvestDemandVo customerDemandVo) { - return savaOrUpdateCustomerDemand(customerDemandVo); - } - - @Override - public boolean updateCustomerAndDemand(InvestDemandVo customerDemandVo) { - return savaOrUpdateCustomerDemand(customerDemandVo); - } - - - private boolean savaOrUpdateCustomerDemand(InvestDemandVo customerDemandVo) { - checkAllNotNull(customerDemandVo); - checkAllNotNull(customerDemandVo.getBrand(), customerDemandVo.getCustomer()); - InvestCustomerEntity customerEntity = new InvestCustomerEntity(); - BeanUtils.copyProperties(customerDemandVo, customerEntity); - customerService.saveOrUpdate(customerEntity); - InvestDemandEntity demandEntity = new InvestDemandEntity(); - BeanUtils.copyProperties(customerDemandVo, demandEntity); - return this.saveOrUpdate(demandEntity); - } - - @Override - public InvestDemandVo findById(Long id) { - checkAllNotNull(id); - InvestDemandEntity demandEntity = this.getById(id); - checkAllNotNull(demandEntity); - InvestCustomerEntity customerEntity = customerService.getById(demandEntity.getCustomerId()); - checkAllNotNull(customerEntity); - WxBrand brand = brandService.getById(customerEntity.getBrandId()); - WxShop shop = shopService.getById(demandEntity.getTargetId()); - InvestDemandVo customerDemandVo = buildResultItem(demandEntity, customerEntity, brand, shop); - return customerDemandVo; - } - - 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; - } @Override public boolean save(InvestDemandEntity entity) { - return super.saveAction(entity, input -> checkBeforeSaveOrUpdate(input)); + return super.saveAction(entity, this::checkBeforeSaveOrUpdate); } + @TableLog @Override public boolean update(InvestDemandEntity entity, Wrapper updateWrapper) { - return super.updateActon(entity, updateWrapper,input -> checkBeforeSaveOrUpdate(input)); - } - - @Deprecated - @Override - public boolean saveOrUpdate(InvestDemandEntity entity) { - notSupport(); - return false ; + return super.updateActon(entity, updateWrapper, this::checkBeforeSaveOrUpdate); } + @TableLog @Override public boolean updateById(InvestDemandEntity entity) { - return super.updateByIdAction(entity, input -> checkBeforeSaveOrUpdate(input)); + return super.updateByIdAction(entity, this::checkBeforeSaveOrUpdate); } private void checkBeforeSaveOrUpdate(InvestDemandEntity entity) { @@ -159,8 +46,21 @@ public class InvestDemandServiceImpl extends InvestBaseService updateWrapper) { + notSupport(); + return false ; + } } diff --git a/mallinkService/src/main/java/com/iformall/service/invest/impl/InvestFollowRecordServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/invest/impl/InvestFollowRecordServiceImpl.java index 90b25fd79..5fb82cbec 100755 --- a/mallinkService/src/main/java/com/iformall/service/invest/impl/InvestFollowRecordServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/invest/impl/InvestFollowRecordServiceImpl.java @@ -1,21 +1,18 @@ package com.iformall.service.invest.impl; -import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.Wrapper; 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.common.ErrorCode; -import com.iformall.domain.po.InvestBaseEntity; import com.iformall.domain.po.InvestFollowRecordEntity; import com.iformall.domain.vo.invest.InvestPageQuery; import com.iformall.domain.vo.invest.InvestPageResult; -import com.iformall.domain.vo.invest.InvestUserContext; import com.iformall.enums.EnumFollowType; -import com.iformall.exception.MallinkException; import com.iformall.mapper.InvestFollowRecordDao; import com.iformall.service.invest.InvestDemandService; import com.iformall.service.invest.InvestFollowRecordService; +import com.iformall.service.invest.InvestHelper; import com.iformall.service.invest.InvestTaskService; import org.apache.commons.collections.CollectionUtils; import org.springframework.beans.BeanUtils; @@ -25,7 +22,7 @@ import org.springframework.stereotype.Service; import java.util.Objects; @Service -public class InvestFollowRecordServiceImpl extends InvestBaseService implements InvestFollowRecordService { +public class InvestFollowRecordServiceImpl extends InvestBaseServiceImpl implements InvestFollowRecordService { @Autowired private InvestDemandService demandService ; @@ -34,7 +31,7 @@ public class InvestFollowRecordServiceImpl extends InvestBaseService queryPage(InvestPageQuery params) { - checkAllNotNull(params); + InvestHelper.allNotNull(params); Page page = buildQueryPage(params); InvestFollowRecordEntity queryTask = params.getQueryData(); LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(queryTask); @@ -50,7 +47,25 @@ public class InvestFollowRecordServiceImpl extends InvestBaseService checkBeforeSaveOrUpdate(input)); + return super.saveAction(entity, this::checkBeforeSaveOrUpdate); + } + + private void checkBeforeSaveOrUpdate(InvestFollowRecordEntity entity) { + InvestHelper.allNotNull(entity); + InvestHelper.notNull(entity.getFollowId(), "followId"); + Object object = null; + if(Objects.equals(entity.getType(), EnumFollowType.DEMAND)) { + object = demandService.getById(entity.getFollowId()); + } else if(Objects.equals(entity.getType(), EnumFollowType.TASK)) { + object = taskService.getById(entity.getFollowId()); + } else { + InvestHelper.throwException(ErrorCode.SYS_PARAMETER_NOT_NULL, "followType"); + } + InvestHelper.notNull(object, ""); + + if(Objects.nonNull(entity.getContent())) { + entity.setContent(stringToJson(entity.getContent())); + } } @Deprecated @@ -73,22 +88,4 @@ public class InvestFollowRecordServiceImpl extends InvestBaseService implements InvestOperateRecordService { +public class InvestOperateRecordServiceImpl extends InvestBaseServiceImpl implements InvestOperateRecordService { @Override public InvestPageResult queryPage(InvestPageQuery params) { - checkAllNotNull(params); + InvestHelper.allNotNull(params); //1、分页信息 - Page queryPage = buildQueryPage(params); + Page queryPage = buildQueryPage(params); //2、查询数据 InvestOperateRecordEntity queryParams = params.getQueryData(); LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(queryParams); @@ -37,28 +37,36 @@ public class InvestOperateRecordServiceImpl extends InvestBaseService updateWrapper) { - return super.update(entity, updateWrapper); + notSupport(); + return false; } @Deprecated @Override public boolean saveOrUpdate(InvestOperateRecordEntity entity) { - return super.saveOrUpdate(entity); + notSupport(); + return false; } @Deprecated @Override public boolean updateById(InvestOperateRecordEntity entity) { - return super.updateById(entity); + notSupport(); + return false; } } diff --git a/mallinkService/src/main/java/com/iformall/service/invest/impl/InvestRemindServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/invest/impl/InvestRemindServiceImpl.java index c9751b97c..bd3002d53 100755 --- a/mallinkService/src/main/java/com/iformall/service/invest/impl/InvestRemindServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/invest/impl/InvestRemindServiceImpl.java @@ -1,6 +1,5 @@ package com.iformall.service.invest.impl; -import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; @@ -11,6 +10,7 @@ import com.iformall.domain.vo.invest.InvestPageResult; import com.iformall.domain.vo.invest.InvestUserContext; import com.iformall.mapper.InvestRemindDao; import com.iformall.service.MallUserInfoService; +import com.iformall.service.invest.InvestHelper; import com.iformall.service.invest.InvestRemindService; import org.apache.commons.collections.CollectionUtils; import org.springframework.beans.BeanUtils; @@ -21,19 +21,18 @@ import java.util.Objects; @Service -public class InvestRemindServiceImpl extends InvestBaseService implements InvestRemindService { +public class InvestRemindServiceImpl extends InvestBaseServiceImpl implements InvestRemindService { @Autowired private MallUserInfoService userInfoService; @Override public InvestPageResult queryPage(InvestPageQuery params) { - checkAllNotNull(params); + InvestHelper.allNotNull(params); //1、分页信息 - Page queryPage = buildQueryPage(params); + Page queryPage = buildQueryPage(params); //2、查询数据 InvestRemindEntity queryParams = params.getQueryData(); - checkUserExit(userInfoService, InvestUserContext.getUserId()); LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(queryParams); IPage taskPage = this.page(queryPage, queryWrapper); @@ -47,28 +46,28 @@ public class InvestRemindServiceImpl extends InvestBaseService checkBeforeSaveOrUpdate(input)); + return super.saveAction(entity, this::checkBeforeSaveOrUpdate); } @Override public boolean update(InvestRemindEntity entity, Wrapper updateWrapper) { - return super.updateActon(entity, updateWrapper, input -> checkBeforeSaveOrUpdate(input)); + return super.updateActon(entity, updateWrapper, this::checkBeforeSaveOrUpdate); } @Override public boolean saveOrUpdate(InvestRemindEntity entity) { - return super.saveOrUpdateAction(entity, input -> checkBeforeSaveOrUpdate(input)); + return super.saveOrUpdateAction(entity, this::checkBeforeSaveOrUpdate); } @Override public boolean updateById(InvestRemindEntity entity) { - return super.updateByIdAction(entity, input -> checkBeforeSaveOrUpdate(input)); + return super.updateByIdAction(entity, this::checkBeforeSaveOrUpdate); } private void checkBeforeSaveOrUpdate(InvestRemindEntity input) { input.setOwner(InvestUserContext.getUserId()); if (Objects.nonNull(input.getContent())) { - input.setContent(JSON.toJSONString(input.getContent())); + input.setContent(stringToJson(input.getContent())); } } } diff --git a/mallinkService/src/main/java/com/iformall/service/invest/impl/InvestTaskServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/invest/impl/InvestTaskServiceImpl.java index 123083115..ee77ebb27 100755 --- a/mallinkService/src/main/java/com/iformall/service/invest/impl/InvestTaskServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/invest/impl/InvestTaskServiceImpl.java @@ -1,10 +1,10 @@ package com.iformall.service.invest.impl; -import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.Wrapper; 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.common.TableLog; import com.iformall.domain.po.InvestTaskEntity; import com.iformall.domain.po.WxShop; import com.iformall.domain.vo.invest.InvestPageQuery; @@ -13,6 +13,7 @@ import com.iformall.domain.vo.invest.InvestTaskVo; import com.iformall.mapper.InvestTaskDao; import com.iformall.service.MallUserInfoService; import com.iformall.service.WxShopService; +import com.iformall.service.invest.InvestHelper; import com.iformall.service.invest.InvestTaskService; import org.apache.commons.collections.CollectionUtils; import org.springframework.beans.BeanUtils; @@ -24,7 +25,7 @@ import java.util.stream.Collectors; @Service -public class InvestTaskServiceImpl extends InvestBaseService implements InvestTaskService { +public class InvestTaskServiceImpl extends InvestBaseServiceImpl implements InvestTaskService { @Autowired private WxShopService shopService; @@ -33,8 +34,8 @@ public class InvestTaskServiceImpl extends InvestBaseService queryPage(InvestPageQuery params) { - checkAllNotNull(params); - Page queryPage = buildQueryPage(params); + InvestHelper.allNotNull(params); + Page queryPage = buildQueryPage(params); //1、任务信息 InvestTaskEntity queryTask = params.getQueryData(); LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(queryTask); @@ -74,37 +75,45 @@ public class InvestTaskServiceImpl extends InvestBaseService checkBeforeSaveOrUpdate(input)); + return super.saveAction(entity, this::checkBeforeSaveOrUpdate); } + @TableLog @Override public boolean update(InvestTaskEntity entity, Wrapper updateWrapper) { - return super.updateActon(entity, updateWrapper, input -> checkBeforeSaveOrUpdate(input)); - } - - @Deprecated - @Override - public boolean saveOrUpdate(InvestTaskEntity entity) { - notSupport(); - return false ; + return super.updateActon(entity, updateWrapper, this::checkBeforeSaveOrUpdate); } + @TableLog @Override public boolean updateById(InvestTaskEntity entity) { - return super.updateByIdAction(entity, input -> checkBeforeSaveOrUpdate(input)); + return super.updateByIdAction(entity, this::checkBeforeSaveOrUpdate); } - private void checkBeforeSaveOrUpdate(InvestTaskEntity entity) { // 1 check shop 状态 checkShop(shopService, entity); // 2 check user checkUserExit(userInfoService, entity.getOwner()); if (Objects.nonNull(entity.getOwner())) { - entity.setOwner(JSON.toJSONString(entity.getOwner())); + entity.setOwner(stringToJson(entity.getOwner())); } if (Objects.nonNull(entity.getContent())) { - entity.setContent(JSON.toJSONString(entity.getContent())); + entity.setContent(stringToJson(entity.getContent())); } } + + @Deprecated + @Override + public boolean saveOrUpdate(InvestTaskEntity entity) { + notSupport(); + return false ; + } + + @Deprecated + @Override + public boolean update(Wrapper updateWrapper) { + notSupport(); + return false ; + } } diff --git a/mallinkService/src/main/java/com/iformall/utils/SpringContextUtils.java b/mallinkService/src/main/java/com/iformall/utils/SpringContextUtils.java index c644138eb..e5f566f90 100644 --- a/mallinkService/src/main/java/com/iformall/utils/SpringContextUtils.java +++ b/mallinkService/src/main/java/com/iformall/utils/SpringContextUtils.java @@ -42,4 +42,8 @@ public class SpringContextUtils implements ApplicationContextAware { return applicationContext.getType(name); } + public static T getBean(Class clazz) { + return applicationContext.getBean(clazz); + } + } \ No newline at end of file