| @@ -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<InvestPageResult<InvestDemandVo>> list(InvestPageQuery<InvestDemandEntity> 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<InvestDemandVo> 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)); | |||
| } | |||
| /** | |||
| @@ -46,7 +46,7 @@ public class InvestRemindController extends InvestBaseController { | |||
| */ | |||
| @GetMapping("/info/{id}") | |||
| public InvestResultData<InvestRemindEntity> info(@PathVariable("id") Long id) { | |||
| return execute(id, p -> investRemindService.getById(p)); | |||
| return execute(id, p -> investRemindService.getByIdNotNull(p)); | |||
| } | |||
| /** | |||
| @@ -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)); | |||
| } | |||
| /** | |||
| @@ -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<String, Object> 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<String, Object> 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<String, Object> 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<String, Object> getFeildMap(Object entity) throws IllegalAccessException { | |||
| if (Objects.isNull(entity)) { | |||
| return null; | |||
| } | |||
| Map<String, Object> map = new HashMap<>(); | |||
| List<Field> 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<TableTriple<String, Object, Object>> getContent(Map<String, Object> before, Map<String, Object> after) { | |||
| if (Objects.isNull(before) || Objects.isNull(after)) { | |||
| return mapToList(before, after); | |||
| } | |||
| MapDifference<String, Object> diffInner = Maps.difference(before, after); | |||
| List<TableTriple<String, Object, Object>> diffRows = Lists.newArrayList(); | |||
| if (diffInner.areEqual()) { | |||
| return diffRows; | |||
| } | |||
| Map<String, MapDifference.ValueDifference<Object>> differenceMap = diffInner.entriesDiffering(); | |||
| for (Map.Entry<String, MapDifference.ValueDifference<Object>> entry : differenceMap.entrySet()) { | |||
| String s = entry.getKey(); | |||
| MapDifference.ValueDifference<Object> objectValueDifference = entry.getValue(); | |||
| Object innerBefore = objectValueDifference.leftValue(); | |||
| Object innerAfter = objectValueDifference.rightValue(); | |||
| if (innerBefore instanceof Map) { | |||
| diffRows.addAll(getContent((Map<String, Object>) innerBefore, (Map<String, Object>) innerAfter)); | |||
| } else { | |||
| diffRows.add(TableTriple.of(s, innerBefore, innerAfter)); | |||
| } | |||
| } | |||
| return diffRows; | |||
| } | |||
| private List<TableTriple<String, Object, Object>> mapToList(Map<String, Object> before, Map<String, Object> after) { | |||
| List<TableTriple<String, Object, Object>> list = Lists.newArrayList(); | |||
| Set<String> 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<String, Object>) innerAfter)); | |||
| } else { | |||
| list.add(TableTriple.of(key, "", innerAfter)); | |||
| } | |||
| } else { | |||
| Object innerBefore = before.get(key); | |||
| if (innerBefore instanceof Map) { | |||
| list.addAll(mapToList((Map<String, Object>) innerBefore, null)); | |||
| } else { | |||
| list.add(TableTriple.of(key, innerBefore, "")); | |||
| } | |||
| } | |||
| } | |||
| return list; | |||
| } | |||
| private <T> T getById(MethodSignature signature, Serializable id) { | |||
| Class service = signature.getDeclaringType(); | |||
| QueryWrapper<T> wrapper = new QueryWrapper<>(); | |||
| wrapper.eq("id", id); | |||
| return (T) ((InvestBaseServiceImpl) SpringContextUtils.getBean(service)).getOne(wrapper); | |||
| } | |||
| } | |||
| @@ -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) { | |||
| @@ -17,6 +17,8 @@ public class InvestBaseEntity implements Serializable { | |||
| private static final long serialVersionUID = 1L; | |||
| public static final String COLUMN_TYPE = "json"; | |||
| /** | |||
| * 主键ID | |||
| */ | |||
| @@ -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; | |||
| /** | |||
| * 更新时间 | |||
| @@ -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-其他 | |||
| @@ -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; | |||
| /** | |||
| * 创建时间 | |||
| */ | |||
| @@ -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, "报纸"), | |||
| @@ -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; | |||
| * @date 2019-09-23 18:40:43 | |||
| */ | |||
| public interface InvestCustomerService extends IService<InvestCustomerEntity> { | |||
| public interface InvestCustomerService extends IService<InvestCustomerEntity>,InvestBaseService<InvestCustomerEntity> { | |||
| List queryPage(InvestPageQuery<InvestCustomerEntity> params); | |||
| } | |||
| @@ -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; | |||
| * @date 2019-09-23 18:40:42 | |||
| */ | |||
| public interface InvestDemandService extends IService<InvestDemandEntity> { | |||
| InvestPageResult<InvestDemandVo> queryPage(InvestPageQuery<InvestDemandEntity> params); | |||
| boolean saveCustomerAndDemand(InvestDemandVo customerDemandVo) ; | |||
| boolean updateCustomerAndDemand(InvestDemandVo customerDemandVo) ; | |||
| public interface InvestDemandService extends IService<InvestDemandEntity>,InvestBaseService<InvestDemandEntity> { | |||
| InvestDemandVo findById(Long id) ; | |||
| } | |||
| @@ -12,7 +12,7 @@ import com.iformall.domain.vo.invest.InvestPageResult; | |||
| * @date 2019-09-23 18:40:43 | |||
| */ | |||
| public interface InvestFollowRecordService extends IService<InvestFollowRecordEntity> { | |||
| public interface InvestFollowRecordService extends IService<InvestFollowRecordEntity>,InvestBaseService<InvestFollowRecordEntity> { | |||
| InvestPageResult<InvestFollowRecordEntity> queryPage(InvestPageQuery<InvestFollowRecordEntity> params); | |||
| } | |||
| @@ -12,7 +12,7 @@ import com.iformall.domain.vo.invest.InvestPageResult; | |||
| * @date 2019-09-23 18:40:43 | |||
| */ | |||
| public interface InvestRemindService extends IService<InvestRemindEntity> { | |||
| public interface InvestRemindService extends IService<InvestRemindEntity>,InvestBaseService<InvestRemindEntity> { | |||
| InvestPageResult<InvestRemindEntity> queryPage(InvestPageQuery<InvestRemindEntity> params); | |||
| } | |||
| @@ -13,8 +13,9 @@ import com.iformall.domain.vo.invest.InvestTaskVo; | |||
| * @date 2019-09-23 18:40:43 | |||
| */ | |||
| public interface InvestTaskService extends IService<InvestTaskEntity> { | |||
| public interface InvestTaskService extends IService<InvestTaskEntity>,InvestBaseService<InvestTaskEntity> { | |||
| InvestPageResult<InvestTaskVo> queryPage(InvestPageQuery<InvestTaskEntity> params); | |||
| } | |||
| @@ -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<M extends BaseMapper<T>, T> extends ServiceImpl<M, T> { | |||
| public class InvestBaseServiceImpl<M extends BaseMapper<T>, T> extends ServiceImpl<M, T> implements InvestBaseService<T> { | |||
| @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<T> consumer) { | |||
| boolean saveAction(T entity, Consumer<T> consumer) { | |||
| checkUserAndTenant(entity,consumer); | |||
| return super.save(entity); | |||
| } | |||
| @TableLog | |||
| public boolean updateActon(T entity, Wrapper<T> updateWrapper,Consumer<T> consumer) { | |||
| boolean updateActon(T entity, Wrapper<T> updateWrapper, Consumer<T> consumer) { | |||
| checkUserAndTenant(entity,consumer); | |||
| return super.update(entity, updateWrapper); | |||
| } | |||
| @TableLog | |||
| public boolean saveOrUpdateAction(T entity,Consumer<T> consumer) { | |||
| boolean saveOrUpdateAction(T entity, Consumer<T> consumer) { | |||
| checkUserAndTenant(entity,consumer); | |||
| return super.saveOrUpdate(entity); | |||
| } | |||
| @TableLog | |||
| public boolean updateByIdAction(T entity,Consumer<T> consumer) { | |||
| boolean updateByIdAction(T entity, Consumer<T> consumer) { | |||
| checkUserAndTenant(entity,consumer); | |||
| return super.updateById(entity); | |||
| } | |||
| void checkUserAndTenant(T input,Consumer<T> 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<M extends BaseMapper<T>, T> extends ServiceImpl<M | |||
| targetId = entity.getTargetId(); | |||
| investType = entity.getTargetType(); | |||
| } | |||
| if (EnumInvestType.SHOP.equals(investType)) { | |||
| WxShop shop = shopService.getById(targetId); | |||
| checkShopNotNull(shop); | |||
| @@ -97,13 +97,8 @@ public class InvestBaseService<M extends BaseMapper<T>, T> extends ServiceImpl<M | |||
| * @param shop | |||
| */ | |||
| private void checkShopNotNull(WxShop shop) { | |||
| if (Objects.isNull(shop)) { | |||
| throw new MallinkException(ErrorCode.SHOP_IS_NOT_FOUND); | |||
| } | |||
| if (Objects.equals(shop.getStatus(), EnumShopStatus.RENT.getCode())) { | |||
| throw new MallinkException(ErrorCode.SHOP_IS_RENT); | |||
| } | |||
| InvestHelper.notNull(shop, ErrorCode.SHOP_IS_NOT_FOUND); | |||
| InvestHelper.isTrue(Objects.equals(shop.getStatus(), EnumShopStatus.NOT_RENT.getCode()), ErrorCode.SHOP_IS_RENT, null); | |||
| } | |||
| /** | |||
| @@ -118,9 +113,7 @@ public class InvestBaseService<M extends BaseMapper<T>, T> extends ServiceImpl<M | |||
| if (CollectionUtils.isNotEmpty(ids)) { | |||
| List<Long> usersFromDb = userInfoService.getByIds(ids).stream().map(MallUserInfo::getId).collect(Collectors.toList()); | |||
| List<Long> 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<M extends BaseMapper<T>, T> extends ServiceImpl<M | |||
| void checkUserExit(MallUserInfoService userInfoService, Long id) { | |||
| if (Objects.nonNull(id)) { | |||
| MallUserInfo userInfo = userInfoService.getById(id); | |||
| if (Objects.isNull(userInfo)) | |||
| throwException(ErrorCode.USER_IS_EMPTY, id); | |||
| InvestHelper.isTrue(Objects.nonNull(userInfo), ErrorCode.USER_IS_EMPTY, id); | |||
| } | |||
| } | |||
| void checkCustomerExit(InvestCustomerService customerService, Long id) { | |||
| InvestCustomerEntity customerEntity = customerService.getById(id); | |||
| if (Objects.isNull(customerEntity)) { | |||
| throwException(ErrorCode.INVEST_CUSTOMER_NOT_FOUND, id); | |||
| } | |||
| InvestHelper.isTrue(Objects.nonNull(customerEntity), ErrorCode.INVEST_CUSTOMER_NOT_FOUND, id); | |||
| } | |||
| /** | |||
| * 校验参数是否为空 | |||
| * | |||
| * @param values | |||
| */ | |||
| protected void checkAllNotNull(final Object... values) { | |||
| if (!ObjectUtils.allNotNull(values)) { | |||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||
| } | |||
| void checkBusiness(WxBusinessService businessService, Integer businessId) { | |||
| WxBusiness business = businessService.getById(businessId) ; | |||
| InvestHelper.notNull(business, ErrorCode.BUSINESS_NOT_FOUND); | |||
| } | |||
| /** | |||
| * 校验结果是否为空 | |||
| * | |||
| * @param value | |||
| */ | |||
| protected void checkResult(final Object value, Object info) { | |||
| if (Objects.isNull(value)) { | |||
| throwException(ErrorCode.INVEST_DATA_NOT_FOUND, info); | |||
| } | |||
| void checkBrand(WxBrandService brandService, Long brandId) { | |||
| WxBrand brand = brandService.getById(brandId); | |||
| InvestHelper.notNull(brand, ErrorCode.BRAND_NOT_FOUND); | |||
| } | |||
| protected 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; | |||
| protected Page<T> buildQueryPage(InvestPageQuery<T> pageQuery) { | |||
| return InvestHelper.buildQueryPage(pageQuery) ; | |||
| } | |||
| @@ -178,8 +149,9 @@ public class InvestBaseService<M extends BaseMapper<T>, T> extends ServiceImpl<M | |||
| throw new MallinkException(ErrorCode.SYS_METHOD_NOT_SUPPORT); | |||
| } | |||
| void throwException(ErrorCode errorCode, Object info) { | |||
| throw new MallinkException(errorCode.getCode(), errorCode.getMessage(info)); | |||
| String stringToJson(String json) { | |||
| Object object = JsonUtil.readValue(json, Object.class); | |||
| return JsonUtil.obj2Json(object); | |||
| } | |||
| } | |||
| @@ -4,10 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.Wrapper; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.TableLog; | |||
| import com.iformall.domain.po.InvestCustomerEntity; | |||
| import com.iformall.domain.po.WxBrand; | |||
| import com.iformall.domain.po.WxBusiness; | |||
| import com.iformall.domain.vo.invest.InvestPageQuery; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.mapper.InvestCustomerDao; | |||
| import com.iformall.service.WxBrandService; | |||
| import com.iformall.service.WxBusinessService; | |||
| @@ -18,8 +15,10 @@ import org.springframework.stereotype.Service; | |||
| import java.util.List; | |||
| import java.util.Objects; | |||
| import static com.iformall.service.invest.InvestHelper.isTrue; | |||
| @Service | |||
| public class InvestCustomerServiceImpl extends InvestBaseService<InvestCustomerDao, InvestCustomerEntity> implements InvestCustomerService { | |||
| public class InvestCustomerServiceImpl extends InvestBaseServiceImpl<InvestCustomerDao, InvestCustomerEntity> implements InvestCustomerService { | |||
| @Autowired | |||
| private WxBrandService brandService; | |||
| @@ -31,62 +30,50 @@ public class InvestCustomerServiceImpl extends InvestBaseService<InvestCustomerD | |||
| return this.list(); | |||
| } | |||
| @TableLog | |||
| @Override | |||
| public boolean save(InvestCustomerEntity entity) { | |||
| return super.saveAction(entity, input -> checkBeforeSaveOrUpdate(input)); | |||
| } | |||
| @Override | |||
| public boolean update(InvestCustomerEntity entity, Wrapper<InvestCustomerEntity> 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<InvestCustomerEntity> 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<InvestCustomerEntity> updateWrapper) { | |||
| notSupport(); | |||
| return false ; | |||
| } | |||
| } | |||
| @@ -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<InvestDemandDao, InvestDemandEntity> implements InvestDemandService { | |||
| public class InvestDemandServiceImpl extends InvestBaseServiceImpl<InvestDemandDao, InvestDemandEntity> implements InvestDemandService { | |||
| @Autowired | |||
| private WxShopService shopService; | |||
| @@ -36,122 +23,22 @@ public class InvestDemandServiceImpl extends InvestBaseService<InvestDemandDao, | |||
| private MallUserInfoService userInfoService; | |||
| @Autowired | |||
| private InvestCustomerService customerService; | |||
| @Autowired | |||
| private WxBrandService brandService; | |||
| @Override | |||
| public InvestPageResult<InvestDemandVo> queryPage(InvestPageQuery<InvestDemandEntity> params) { | |||
| checkAllNotNull(params); | |||
| Page page = buildQueryPage(params); | |||
| InvestPageResult<InvestDemandVo> investPage = new InvestPageResult<>(); | |||
| //1、客户需求 | |||
| InvestDemandEntity queryTask = params.getQueryData(); | |||
| LambdaQueryWrapper<InvestDemandEntity> queryWrapper = new LambdaQueryWrapper<>(queryTask); | |||
| IPage<InvestDemandEntity> demandPage = this.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; | |||
| } | |||
| @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<InvestDemandEntity> 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<InvestDemandDao, | |||
| checkUserExit(userInfoService, entity.getOwner()); | |||
| checkShop(shopService, entity); | |||
| if(Objects.nonNull(entity.getIntent())) { | |||
| entity.setIntent(JSON.toJSONString(entity.getIntent())); | |||
| entity.setIntent(stringToJson(entity.getIntent())); | |||
| } | |||
| } | |||
| @Deprecated | |||
| @Override | |||
| public boolean saveOrUpdate(InvestDemandEntity entity) { | |||
| notSupport(); | |||
| return false; | |||
| } | |||
| @Deprecated | |||
| @Override | |||
| public boolean update(Wrapper<InvestDemandEntity> updateWrapper) { | |||
| notSupport(); | |||
| return false ; | |||
| } | |||
| } | |||
| @@ -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<InvestFollowRecordDao, InvestFollowRecordEntity> implements InvestFollowRecordService { | |||
| public class InvestFollowRecordServiceImpl extends InvestBaseServiceImpl<InvestFollowRecordDao, InvestFollowRecordEntity> implements InvestFollowRecordService { | |||
| @Autowired | |||
| private InvestDemandService demandService ; | |||
| @@ -34,7 +31,7 @@ public class InvestFollowRecordServiceImpl extends InvestBaseService<InvestFollo | |||
| @Override | |||
| public InvestPageResult<InvestFollowRecordEntity> queryPage(InvestPageQuery<InvestFollowRecordEntity> params) { | |||
| checkAllNotNull(params); | |||
| InvestHelper.allNotNull(params); | |||
| Page page = buildQueryPage(params); | |||
| InvestFollowRecordEntity queryTask = params.getQueryData(); | |||
| LambdaQueryWrapper<InvestFollowRecordEntity> queryWrapper = new LambdaQueryWrapper<>(queryTask); | |||
| @@ -50,7 +47,25 @@ public class InvestFollowRecordServiceImpl extends InvestBaseService<InvestFollo | |||
| @Override | |||
| public boolean save(InvestFollowRecordEntity entity) { | |||
| return super.saveAction(entity, input -> 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<InvestFollo | |||
| notSupport(); | |||
| return false; | |||
| } | |||
| private void checkBeforeSaveOrUpdate(InvestFollowRecordEntity entity) { | |||
| checkAllNotNull(entity); | |||
| checkAllNotNull(InvestUserContext.getUserId()); | |||
| InvestBaseEntity baseInvestEntity; | |||
| if(Objects.equals(entity.getType(), EnumFollowType.DEMAND)) { | |||
| baseInvestEntity = demandService.getById(entity.getFollowId()); | |||
| } else if(Objects.equals(entity.getType(), EnumFollowType.TASK)) { | |||
| baseInvestEntity = taskService.getById(entity.getFollowId()); | |||
| } else { | |||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL) ; | |||
| } | |||
| checkAllNotNull(baseInvestEntity); | |||
| if(Objects.nonNull(entity.getContent())) { | |||
| entity.setContent(JSON.toJSONString(entity.getContent())); | |||
| } | |||
| } | |||
| } | |||
| @@ -4,26 +4,26 @@ 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.InvestOperateRecordEntity; | |||
| import com.iformall.domain.vo.invest.InvestPageQuery; | |||
| import com.iformall.domain.vo.invest.InvestPageResult; | |||
| import com.iformall.domain.vo.invest.InvestUserContext; | |||
| import com.iformall.mapper.InvestOperateRecordDao; | |||
| import com.iformall.service.invest.InvestHelper; | |||
| import com.iformall.service.invest.InvestOperateRecordService; | |||
| import org.apache.commons.collections.CollectionUtils; | |||
| import org.springframework.beans.BeanUtils; | |||
| import org.springframework.stereotype.Service; | |||
| @Service | |||
| public class InvestOperateRecordServiceImpl extends InvestBaseService<InvestOperateRecordDao, InvestOperateRecordEntity> implements InvestOperateRecordService { | |||
| public class InvestOperateRecordServiceImpl extends InvestBaseServiceImpl<InvestOperateRecordDao, InvestOperateRecordEntity> implements InvestOperateRecordService { | |||
| @Override | |||
| public InvestPageResult<InvestOperateRecordEntity> queryPage(InvestPageQuery<InvestOperateRecordEntity> params) { | |||
| checkAllNotNull(params); | |||
| InvestHelper.allNotNull(params); | |||
| //1、分页信息 | |||
| Page queryPage = buildQueryPage(params); | |||
| Page<InvestOperateRecordEntity> queryPage = buildQueryPage(params); | |||
| //2、查询数据 | |||
| InvestOperateRecordEntity queryParams = params.getQueryData(); | |||
| LambdaQueryWrapper<InvestOperateRecordEntity> queryWrapper = new LambdaQueryWrapper<>(queryParams); | |||
| @@ -37,28 +37,36 @@ public class InvestOperateRecordServiceImpl extends InvestBaseService<InvestOper | |||
| return investPage; | |||
| } | |||
| @TableLog | |||
| @Override | |||
| public boolean save(InvestOperateRecordEntity entity) { | |||
| return super.save(entity); | |||
| return super.saveAction(entity, this::checkBeforeSaveOrUpdate); | |||
| } | |||
| void checkBeforeSaveOrUpdate(InvestOperateRecordEntity entity) { | |||
| InvestHelper.notNull(entity.getTbl(), ""); | |||
| InvestHelper.notNull(entity.getTid(), ""); | |||
| entity.setOperator(InvestUserContext.getUserId()); | |||
| } | |||
| @Deprecated | |||
| @Override | |||
| public boolean update(InvestOperateRecordEntity entity, Wrapper<InvestOperateRecordEntity> 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; | |||
| } | |||
| } | |||
| @@ -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<InvestRemindDao, InvestRemindEntity> implements InvestRemindService { | |||
| public class InvestRemindServiceImpl extends InvestBaseServiceImpl<InvestRemindDao, InvestRemindEntity> implements InvestRemindService { | |||
| @Autowired | |||
| private MallUserInfoService userInfoService; | |||
| @Override | |||
| public InvestPageResult<InvestRemindEntity> queryPage(InvestPageQuery<InvestRemindEntity> params) { | |||
| checkAllNotNull(params); | |||
| InvestHelper.allNotNull(params); | |||
| //1、分页信息 | |||
| Page queryPage = buildQueryPage(params); | |||
| Page<InvestRemindEntity> queryPage = buildQueryPage(params); | |||
| //2、查询数据 | |||
| InvestRemindEntity queryParams = params.getQueryData(); | |||
| checkUserExit(userInfoService, InvestUserContext.getUserId()); | |||
| LambdaQueryWrapper<InvestRemindEntity> queryWrapper = new LambdaQueryWrapper<>(queryParams); | |||
| IPage<InvestRemindEntity> taskPage = this.page(queryPage, queryWrapper); | |||
| @@ -47,28 +46,28 @@ public class InvestRemindServiceImpl extends InvestBaseService<InvestRemindDao, | |||
| @Override | |||
| public boolean save(InvestRemindEntity entity) { | |||
| return super.saveAction(entity, input -> checkBeforeSaveOrUpdate(input)); | |||
| return super.saveAction(entity, this::checkBeforeSaveOrUpdate); | |||
| } | |||
| @Override | |||
| public boolean update(InvestRemindEntity entity, Wrapper<InvestRemindEntity> 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())); | |||
| } | |||
| } | |||
| } | |||
| @@ -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<InvestTaskDao, InvestTaskEntity> implements InvestTaskService { | |||
| public class InvestTaskServiceImpl extends InvestBaseServiceImpl<InvestTaskDao, InvestTaskEntity> implements InvestTaskService { | |||
| @Autowired | |||
| private WxShopService shopService; | |||
| @@ -33,8 +34,8 @@ public class InvestTaskServiceImpl extends InvestBaseService<InvestTaskDao, Inve | |||
| @Override | |||
| public InvestPageResult<InvestTaskVo> queryPage(InvestPageQuery<InvestTaskEntity> params) { | |||
| checkAllNotNull(params); | |||
| Page queryPage = buildQueryPage(params); | |||
| InvestHelper.allNotNull(params); | |||
| Page<InvestTaskEntity> queryPage = buildQueryPage(params); | |||
| //1、任务信息 | |||
| InvestTaskEntity queryTask = params.getQueryData(); | |||
| LambdaQueryWrapper<InvestTaskEntity> queryWrapper = new LambdaQueryWrapper<>(queryTask); | |||
| @@ -74,37 +75,45 @@ public class InvestTaskServiceImpl extends InvestBaseService<InvestTaskDao, Inve | |||
| @Override | |||
| public boolean save(InvestTaskEntity entity) { | |||
| return super.saveAction(entity, input -> checkBeforeSaveOrUpdate(input)); | |||
| return super.saveAction(entity, this::checkBeforeSaveOrUpdate); | |||
| } | |||
| @TableLog | |||
| @Override | |||
| public boolean update(InvestTaskEntity entity, Wrapper<InvestTaskEntity> 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<InvestTaskEntity> updateWrapper) { | |||
| notSupport(); | |||
| return false ; | |||
| } | |||
| } | |||
| @@ -42,4 +42,8 @@ public class SpringContextUtils implements ApplicationContextAware { | |||
| return applicationContext.getType(name); | |||
| } | |||
| public static <T> T getBean(Class<T> clazz) { | |||
| return applicationContext.getBean(clazz); | |||
| } | |||
| } | |||