From 95fb7b2bd69ffacd5b561a82945f52fba328cdb3 Mon Sep 17 00:00:00 2001 From: Burce Date: Sun, 29 Sep 2019 12:49:05 +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 --- .../iformall/config/MyBatisConfiguration.java | 6 + .../invest/InvestDemandController.java | 49 +++-- .../invest/InvestFollowRecordController.java | 2 +- .../invest/InvestOperateRecordController.java | 2 +- .../invest/InvestRemindController.java | 2 +- .../invest/InvestTaskController.java | 30 ++- .../com/iformall/log/SystemLogAspect.java | 4 +- .../iformall/service/test/InvestTests.java | 66 +++++-- .../java/com/iformall/common/ErrorCode.java | 10 +- .../iformall/domain/po/BaseInvestEntity.java | 187 +----------------- .../domain/po/InvestCustomerEntity.java | 9 +- .../domain/po/InvestDemandEntity.java | 8 +- .../iformall/domain/po/InvestTaskEntity.java | 1 - .../com/iformall/enums/EnumInvestType.java | 2 + .../com/iformall/service/WxBrandService.java | 5 + .../iformall/service/WxBusinessService.java | 6 + .../com/iformall/service/WxShopService.java | 5 +- .../service/impl/WxBrandServiceImpl.java | 7 + .../service/impl/WxBusinessServiceImpl.java | 7 + .../service/impl/WxShopServiceImpl.java | 5 + .../service/invest/InvestDemandService.java | 12 +- .../service/invest/InvestTaskService.java | 6 +- .../impl/InvestCustomerServiceImpl.java | 58 ++++-- .../invest/impl/InvestDemandServiceImpl.java | 126 +++++++++++- .../invest/impl/InvestRemindServiceImpl.java | 1 - .../invest/impl/InvestTaskServiceImpl.java | 92 ++++----- 26 files changed, 394 insertions(+), 314 deletions(-) diff --git a/mallinkAdmin/src/main/java/com/iformall/config/MyBatisConfiguration.java b/mallinkAdmin/src/main/java/com/iformall/config/MyBatisConfiguration.java index 740c66e99..7a6706938 100644 --- a/mallinkAdmin/src/main/java/com/iformall/config/MyBatisConfiguration.java +++ b/mallinkAdmin/src/main/java/com/iformall/config/MyBatisConfiguration.java @@ -24,4 +24,10 @@ public class MyBatisConfiguration { return multiTenancy; } + @Bean + public PaginationInterceptor paginationInterceptor() { + PaginationInterceptor page = new PaginationInterceptor(); + page.setDialectType("mysql"); + return page; + } } 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 f6aeed183..bfc8f11bd 100755 --- a/mallinkAdmin/src/main/java/com/iformall/controller/invest/InvestDemandController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/invest/InvestDemandController.java @@ -1,9 +1,15 @@ package com.iformall.controller.invest; import java.util.Arrays; -import java.util.List; + +import com.iformall.annotation.SystemServiceLog; +import com.iformall.common.ErrorCode; +import com.iformall.common.InvestResultData; import com.iformall.common.ResultData; import com.iformall.domain.po.InvestDemandEntity; +import com.iformall.domain.vo.invest.InvestDemandVo; +import com.iformall.domain.vo.invest.InvestPage; +import com.iformall.exception.MallinkException; import com.iformall.service.invest.InvestDemandService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -31,31 +37,41 @@ public class InvestDemandController { /** * 分页列表 */ - @ApiOperation("分页列表接口") - @PostMapping("/list") - public ResultData list(@RequestBody InvestDemandEntity params){ - List page = investDemandService.queryPage(params); - - return new ResultData(page); + @SystemServiceLog + @ApiOperation(value = "分页列表接口") + @GetMapping("/list") + public InvestResultData> list(@ModelAttribute InvestDemandEntity params) { + try { + InvestPage page = investDemandService.queryPage(params); + return new InvestResultData(page); + } catch (MallinkException e) { + log.error("list error", e); + return new InvestResultData(e.getErrorCode(), e.getMessage()); + } catch (Exception e) { + log.error("list error", e); + return new InvestResultData(ErrorCode.SYS_BEAN_EMPTY_PROPERTY_ERROR); + } } /** * 信息 */ + @SystemServiceLog @GetMapping("/info/{id}") - public ResultData info(@PathVariable("id") Long id){ - InvestDemandEntity investDemand = investDemandService.getById(id); + public InvestResultData info(@PathVariable("id") Long id){ + InvestDemandVo investDemand = investDemandService.findById(id); - return new ResultData(investDemand); + return new InvestResultData(investDemand); } /** * 保存 */ + @SystemServiceLog @PostMapping("/save") - public ResultData save(@RequestBody InvestDemandEntity investDemand){ - investDemandService.save(investDemand); + public ResultData save(InvestDemandVo investDemand) { + investDemandService.saveCustomerAndDemand(investDemand); return new ResultData(); } @@ -63,9 +79,10 @@ public class InvestDemandController { /** * 修改 */ + @SystemServiceLog @PostMapping("/update") - public ResultData update(@RequestBody InvestDemandEntity investDemand){ - investDemandService.updateById(investDemand); + public ResultData update(InvestDemandVo investDemand) { + investDemandService.updateCustomerAndDemand(investDemand); return new ResultData(); } @@ -73,8 +90,8 @@ public class InvestDemandController { /** * 删除 */ - @GetMapping("/delete") - public ResultData delete(@RequestBody Long[] ids){ + //@GetMapping("/delete") + public ResultData delete(Long[] ids) { investDemandService.removeByIds(Arrays.asList(ids)); return new ResultData(); diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/invest/InvestFollowRecordController.java b/mallinkAdmin/src/main/java/com/iformall/controller/invest/InvestFollowRecordController.java index 7ceec0e30..fc568a618 100755 --- a/mallinkAdmin/src/main/java/com/iformall/controller/invest/InvestFollowRecordController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/invest/InvestFollowRecordController.java @@ -32,7 +32,7 @@ public class InvestFollowRecordController { * 分页列表 */ @ApiOperation("分页列表接口") - @PostMapping("/list") + @GetMapping("/list") public ResultData list(@RequestBody InvestFollowRecordEntity params){ List page = investFollowRecordService.queryPage(params); diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/invest/InvestOperateRecordController.java b/mallinkAdmin/src/main/java/com/iformall/controller/invest/InvestOperateRecordController.java index 95493f051..381bdcd21 100755 --- a/mallinkAdmin/src/main/java/com/iformall/controller/invest/InvestOperateRecordController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/invest/InvestOperateRecordController.java @@ -33,7 +33,7 @@ public class InvestOperateRecordController { * 分页列表 */ @ApiOperation("分页列表接口") - @PostMapping("/list") + @GetMapping("/list") public ResultData list(@RequestBody InvestOperateRecordEntity params){ List page = investOperateRecordService.queryPage(params); 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 3e93edce4..53c1edc0d 100755 --- a/mallinkAdmin/src/main/java/com/iformall/controller/invest/InvestRemindController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/invest/InvestRemindController.java @@ -34,7 +34,7 @@ public class InvestRemindController { * 分页列表 */ @ApiOperation("分页列表接口") - @PostMapping("/list") + @GetMapping("/list") public ResultData list(@RequestBody InvestRemindEntity params){ List page = investRemindService.queryPage(params); 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 83c3810eb..2825ac82b 100755 --- a/mallinkAdmin/src/main/java/com/iformall/controller/invest/InvestTaskController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/invest/InvestTaskController.java @@ -1,10 +1,15 @@ package com.iformall.controller.invest; import java.util.Arrays; -import java.util.List; +import com.iformall.annotation.SystemServiceLog; +import com.iformall.common.ErrorCode; +import com.iformall.common.InvestResultData; import com.iformall.common.ResultData; import com.iformall.domain.po.InvestTaskEntity; +import com.iformall.domain.vo.invest.InvestPage; +import com.iformall.domain.vo.invest.InvestTaskVo; +import com.iformall.exception.MallinkException; import com.iformall.service.invest.InvestTaskService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -32,17 +37,27 @@ public class InvestTaskController { /** * 分页列表 */ + @SystemServiceLog @ApiOperation("分页列表接口") - @PostMapping("/list") - public ResultData list(InvestTaskEntity params){ - List page = investTaskService.queryPage(params); - return new ResultData(page); + @GetMapping("/list") + public InvestResultData> list(@ModelAttribute InvestTaskEntity params){ + try { + InvestPage page = investTaskService.queryPage(params); + return new InvestResultData(page); + } catch (MallinkException e) { + log.error("list error", e); + return new InvestResultData(e.getErrorCode(), e.getMessage()); + } catch (Exception e) { + log.error("list error", e); + return new InvestResultData(ErrorCode.SYS_BEAN_EMPTY_PROPERTY_ERROR); + } } /** * 信息 */ + @SystemServiceLog @GetMapping("/info/{id}") public ResultData info(@PathVariable("id") Long id){ InvestTaskEntity investTask = investTaskService.getById(id); @@ -53,6 +68,7 @@ public class InvestTaskController { /** * 保存 */ + @SystemServiceLog @PostMapping("/save") public ResultData save(@RequestBody InvestTaskEntity investTask){ investTaskService.save(investTask); @@ -63,6 +79,7 @@ public class InvestTaskController { /** * 修改 */ + @SystemServiceLog @PostMapping("/update") public ResultData update(@RequestBody InvestTaskEntity investTask){ investTaskService.updateById(investTask); @@ -73,7 +90,8 @@ public class InvestTaskController { /** * 删除 */ - @GetMapping("/delete") + @SystemServiceLog + @PostMapping("/delete") public ResultData delete(@RequestBody Long[] ids){ investTaskService.removeByIds(Arrays.asList(ids)); diff --git a/mallinkAdmin/src/main/java/com/iformall/log/SystemLogAspect.java b/mallinkAdmin/src/main/java/com/iformall/log/SystemLogAspect.java index 02bbae52a..1b75a265e 100644 --- a/mallinkAdmin/src/main/java/com/iformall/log/SystemLogAspect.java +++ b/mallinkAdmin/src/main/java/com/iformall/log/SystemLogAspect.java @@ -25,6 +25,7 @@ import org.springframework.web.context.request.ServletRequestAttributes; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import java.lang.reflect.Method; +import java.util.Arrays; import java.util.Date; @Aspect @@ -142,7 +143,8 @@ public class SystemLogAspect { } } } - return description; + //TODO 调试使用 + return String.format("%s%s",description, Arrays.asList(arguments)); } /** diff --git a/mallinkAdmin/src/test/java/com/iformall/service/test/InvestTests.java b/mallinkAdmin/src/test/java/com/iformall/service/test/InvestTests.java index b7c8866fc..c25bba605 100644 --- a/mallinkAdmin/src/test/java/com/iformall/service/test/InvestTests.java +++ b/mallinkAdmin/src/test/java/com/iformall/service/test/InvestTests.java @@ -1,11 +1,13 @@ package com.iformall.service.test; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.iformall.domain.po.*; +import com.iformall.domain.vo.invest.InvestPage; import com.iformall.enums.*; import com.iformall.mapper.WxBrandMapper; import com.iformall.service.MallUserInfoService; @@ -124,7 +126,7 @@ public class InvestTests { for (String name : names) { InvestCustomerEntity customerEntity = new InvestCustomerEntity(); customerEntity.setBrandId(idCounter.longValue()); - customerEntity.setBusiness(businessCounter.intValue()); + customerEntity.setBusinessId(businessCounter.intValue()); customerEntity.setName(name); customerEntity.setTenantId(tenantId); customerEntity.setPhone("15811234898"); @@ -138,26 +140,37 @@ public class InvestTests { } @Test - public void createTask() { + public void createTaskBatch() { List mallUsers = mallUsers(); AtomicLong idCounter = new AtomicLong(10000); AtomicInteger businessCounter = new AtomicInteger(1); for (MallUserInfo userInfo : mallUsers) { - InvestTaskEntity taskEntity = new InvestTaskEntity(); - taskEntity.setTargetId(idCounter.longValue()); - taskEntity.setOwner(JSON.toJSONString(Arrays.asList(userInfo.getId()))); - taskEntity.setStatus(EnumTaskStatus.NEGOTIATING); - taskEntity.setTenantId(userInfo.getTenantId()); - Map content = Maps.newHashMap(); - content.put("business", businessCounter.intValue()); - content.put("lastDate", DateUtils.formatDateTime(new Date())); - taskEntity.setContent(JSON.toJSONString(content)); - taskService.save(taskEntity); + createTask(idCounter.longValue(), JSON.toJSONString(Arrays.asList(userInfo.getId())), businessCounter.intValue(), DateUtils.formatDateTime(new Date())); idCounter.incrementAndGet(); businessCounter.incrementAndGet(); } } + private void createTask(Long targetId, String ownerJson, int businessId, String lastDate) { + InvestTaskEntity taskEntity = new InvestTaskEntity(); + taskEntity.setTargetId(targetId); + taskEntity.setOwner(ownerJson); + JSONArray userIds = JSONArray.parseArray(ownerJson); + EnumTaskStatus taskStatus; + if (userIds.size() == 0) { + taskStatus = EnumTaskStatus.CREATED; + } else { + taskStatus = EnumTaskStatus.NEGOTIATING; + } + taskEntity.setStatus(taskStatus); + taskEntity.setTenantId(tenantId); + Map content = Maps.newHashMap(); + content.put("business", businessId); + content.put("lastDate", lastDate); + taskEntity.setContent(JSON.toJSONString(content)); + taskService.save(taskEntity); + } + @Test public void createDemand() { List customers = customerService.list(); @@ -168,10 +181,10 @@ public class InvestTests { InvestDemandEntity demandEntity = new InvestDemandEntity(); demandEntity.setCustomerId(customers.get(rand.nextInt(customers.size())).getId()); demandEntity.setTargetId(idCounter.longValue()); + demandEntity.setTargetType(EnumInvestType.SHOP); demandEntity.setOwner(userInfo.getId()); demandEntity.setTenantId(userInfo.getTenantId()); Map intent = Maps.newHashMap(); - intent.put("shop", idCounter.longValue()); //意向商铺 intent.put("rent_area", 100); //意向租凭面积(平米) intent.put("opening_time", DateUtils.formatDateTime(new Date())); //预计开业时间 demandEntity.setIntent(JSON.toJSONString(intent)); @@ -239,13 +252,7 @@ public class InvestTests { @Test public void query() throws JsonProcessingException { - MappingJackson2HttpMessageConverter converter = null; - for (HttpMessageConverter httpMessageConverter : httpMessageConverters) { - if (httpMessageConverter instanceof MappingJackson2HttpMessageConverter) - converter = (MappingJackson2HttpMessageConverter) httpMessageConverter; - } - - ObjectMapper mapper = converter.getObjectMapper(); + ObjectMapper mapper = objectMapper(); List operates = operateRecordService.queryPage(null); List follows = followRecordService.queryPage(null); @@ -261,4 +268,23 @@ public class InvestTests { log.info("demands: {}", mapper.writeValueAsString(demands)); } + @Bean + public ObjectMapper objectMapper() { + MappingJackson2HttpMessageConverter converter = null; + for (HttpMessageConverter httpMessageConverter : httpMessageConverters) { + if (httpMessageConverter instanceof MappingJackson2HttpMessageConverter) + converter = (MappingJackson2HttpMessageConverter) httpMessageConverter; + } + + return converter.getObjectMapper(); + } + + @Test + public void pager() throws Exception { + InvestDemandEntity demandQuery = new InvestDemandEntity(); + demandQuery.setPageIndex(1); + demandQuery.setPageSize(10); + InvestPage page = demandService.queryPage(demandQuery); + log.debug("page : {}", objectMapper().writeValueAsString(page)); + } } diff --git a/mallinkService/src/main/java/com/iformall/common/ErrorCode.java b/mallinkService/src/main/java/com/iformall/common/ErrorCode.java index f82afc516..9e2ab4f0a 100644 --- a/mallinkService/src/main/java/com/iformall/common/ErrorCode.java +++ b/mallinkService/src/main/java/com/iformall/common/ErrorCode.java @@ -516,7 +516,15 @@ public enum ErrorCode{ // 品牌 51000 begin BRAND_NOT_FOUND(51000, "品牌不存在"), - // 品牌 52000 end + // 品牌 51999 end + + // 业态 52000 begin + BUSINESS_NOT_FOUND(52000, "业态不存在"), + // 业态 52999 end + + // 招商管理 53000 begin + CUSTOMER_NOT_FOUND(53000, "客户信息不存在"), + // 招商管理 53999 end ; diff --git a/mallinkService/src/main/java/com/iformall/domain/po/BaseInvestEntity.java b/mallinkService/src/main/java/com/iformall/domain/po/BaseInvestEntity.java index 4c1490555..d4a492036 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/BaseInvestEntity.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/BaseInvestEntity.java @@ -35,32 +35,33 @@ public class BaseInvestEntity implements Serializable { * 租户ID */ @io.swagger.annotations.ApiModelProperty(value = "租户ID", name = "tenantId") + @JsonProperty(access = JsonProperty.Access.READ_ONLY) private String tenantId; /** * 创建时间 */ - @io.swagger.annotations.ApiModelProperty(value = "创建时间", name = "createDate", example = "2018-10-01 12:18:48") + @io.swagger.annotations.ApiModelProperty(value = "创建时间", name = "createDate", example = "2018-10-01 12:18:48",readOnly = true) @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @JsonProperty(access = JsonProperty.Access.READ_ONLY) private Date createDate; /** * 更新时间 */ - @io.swagger.annotations.ApiModelProperty(value = "更新时间", name = "updateDate", example = "2018-10-01 12:18:48") + @io.swagger.annotations.ApiModelProperty(value = "更新时间", name = "updateDate", example = "2018-10-01 12:18:48",readOnly = true) + @JsonProperty(access = JsonProperty.Access.READ_ONLY) @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") private Date updateDate; + @io.swagger.annotations.ApiModelProperty(value = "倒序字段集合", name = "descs") @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) @TableField(exist = false) - private String sortColumn; + private List descs; + @io.swagger.annotations.ApiModelProperty(value = "升序字段集合", name = "ascs") @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) @TableField(exist = false) - private String sortOrder; - - @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) - @TableField(exist = false) - private String sortColumns; + private List ascs; @io.swagger.annotations.ApiModelProperty(value = "当前页", name = "pageIndex",example = "1") @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) @@ -72,174 +73,4 @@ public class BaseInvestEntity implements Serializable { @TableField(exist = false) private Integer pageSize ; - public String getSortColumns() { - if(StringUtils.isBlank(sortColumn)){ - return sortColumns; - } - - try { - //扫描子类SortColumn注解的属性,替换sortColumn - if(StringUtils.isNotBlank(sortColumn)) { - List fieldList = new ArrayList<>() ; - Class tempClass = this.getClass(); - while (tempClass != null) {//当父类为null的时候说明到达了最上层的父类(Object类). - fieldList.addAll(Arrays.asList(tempClass.getDeclaredFields())); - tempClass = tempClass.getSuperclass(); //得到父类,然后赋给自己 - } - - //扫描注解,优先解析注解 - for (Field field : fieldList) { - SortColumn sortColumnField = field.getAnnotation(SortColumn.class); - if (sortColumnField != null && field.getName().equals(sortColumn)) { - return sortColumnField.column() + " "+sortOrder; - } - } - - //判断是否合法 - boolean find = false; - for (Field field : fieldList){ - if (field.getName().equals(sortColumn)) { - find = true; - break; - } - } - if(!find) { - return null; - } - - //默认驼峰解析 - return underscoreName(sortColumn) +" "+sortOrder; - } - } catch (Exception e) { - log.error("BaseEntity.getSortColumn解析失败",e); - e.printStackTrace(); - } - return sortColumns; - } - - /** - * 转换为下划线 - * - * @param camelCaseName - * @return - */ - private String underscoreName(String camelCaseName) { - StringBuilder result = new StringBuilder(); - if (camelCaseName != null && camelCaseName.length() > 0) { - result.append(camelCaseName.substring(0, 1).toLowerCase()); - for (int i = 1; i < camelCaseName.length(); i++) { - char ch = camelCaseName.charAt(i); - if (Character.isUpperCase(ch)) { - result.append("_"); - result.append(Character.toLowerCase(ch)); - } else { - result.append(ch); - } - } - } - return result.toString(); - } - - public void setSortColumns(SortField... fields) - { - if (fields == null || fields.length == 0) { - return; - } - for (int k = 0; k < fields.length; k++) { - if (fields[k] == null) { - return; - } - } - StringBuilder sb = new StringBuilder(fields[0].toString()); - for (int k = 1; k < fields.length; k++) { - sb.append(","); - sb.append(fields[k].toString()); - } - this.sortColumns=sb.toString(); - } - - /** - * json数组转Long集合 - * - * @return - */ - public List parseJsonArray(String json) { - if (Objects.nonNull(json)) { - List ids = JSONArray.parseArray(json, Long.class); - return ids; - } - return null; - } - - public enum SortField { - Id_ASC("`id` ASC"), - Id_DESC("`id` DESC"), - - CreateDate_ASC("`create_date` ASC"), - CreateDate_DESC("`create_date` DESC"), - - UpdateDate_ASC("`update_date` ASC"), - UpdateDate_DESC("`update_date` DESC"), - - Createtime_ASC("`createtime` ASC"), - Createtime_DESC("`createtime` DESC"), - - CreateTime_ASC("`create_time` ASC"), - CreateTime_DESC("`create_time` DESC"), - - ReportTime_ASC("`reportTime` ASC"), - ReportTime_DESC("`reportTime` DESC"), - - ActiveTime_ASC("`active_time` ASC"), - ActiveTime_DESC("`active_time` DESC"), - - TopTime_ASC("`top_time` ASC"), - TopTime_DESC("`top_time` DESC"), - - MerchantId_ASC("`merchant_id` ASC"), - MerchantId_DESC("`merchant_id` DESC"), - - LimitDate_ASC("`limit_date` ASC"), - LimitDate_DESC("`limit_date` DESC"), - - SortNum_ASC("`sort_num` ASC"), - SortNum_DESC("`sort_num` DESC"), - - Sort_ASC("`sort` ASC"), - Sort_DESC("`sort` DESC"), - - Points_ASC("`points` ASC"), - Points_DESC("`points` DESC"), - - Period_ASC("`period` ASC"), - Period_DESC("`period` DESC"), - - UsedPower_ASC("`usedPower` ASC"), - UsedPower_DESC("`usedPower` DESC"), - - Date_ASC("`date` ASC"), - Date_DESC("`date` DESC"), - - TradeAmt_ASC("`trade_amt` ASC"), - TradeAmt_DESC("`trade_amt` DESC"), - - ReportDate_ASC("`report_date` ASC"), - ReportDate_DESC("`report_date` DESC"), - ; - - private String value; - - SortField(String value) { - this.value = value; - } - public String getValue() { - return value; - } - @Override - public String toString() { - return this.getValue(); - } - } - - } 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 90c79b277..ba702e374 100755 --- a/mallinkService/src/main/java/com/iformall/domain/po/InvestCustomerEntity.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/InvestCustomerEntity.java @@ -1,17 +1,12 @@ package com.iformall.domain.po; -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; -import java.io.Serializable; -import java.util.Date; import com.iformall.enums.EnumCustomerRatingType; import com.iformall.enums.EnumCustomerType; import com.iformall.enums.EnumInvestChannel; import lombok.Data; -import com.fasterxml.jackson.annotation.JsonFormat; /** * 客户列表 @@ -37,8 +32,8 @@ public class InvestCustomerEntity extends BaseInvestEntity { /** * 经营业态 */ - @io.swagger.annotations.ApiModelProperty(value = "经营业态", name = "business") - private Integer business; + @io.swagger.annotations.ApiModelProperty(value = "经营业态", name = "businessId") + private Integer businessId; /** * 品牌ID */ 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 09ecd6234..b77f63a9b 100755 --- a/mallinkService/src/main/java/com/iformall/domain/po/InvestDemandEntity.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/InvestDemandEntity.java @@ -1,16 +1,11 @@ package com.iformall.domain.po; -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; -import java.io.Serializable; -import java.util.Date; import com.fasterxml.jackson.annotation.JsonIgnore; import com.iformall.enums.EnumInvestType; import lombok.Data; -import com.fasterxml.jackson.annotation.JsonFormat; /** * 客户需求 @@ -36,7 +31,8 @@ public class InvestDemandEntity extends BaseInvestEntity { /** * 客户意向 */ - @io.swagger.annotations.ApiModelProperty(value = "客户意向", name = "intent") + @io.swagger.annotations.ApiModelProperty(value = "客户意向", name = "intent", + example = "{\"rent_area\":100,\"opening_time\": 2019-09-03}") private String intent; /** * 目标类型:0-商铺招租;1-其他 diff --git a/mallinkService/src/main/java/com/iformall/domain/po/InvestTaskEntity.java b/mallinkService/src/main/java/com/iformall/domain/po/InvestTaskEntity.java index 12a072644..31c52c6b7 100755 --- a/mallinkService/src/main/java/com/iformall/domain/po/InvestTaskEntity.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/InvestTaskEntity.java @@ -32,7 +32,6 @@ public class InvestTaskEntity extends BaseInvestEntity { * 目标类型:0-商铺招租;1-其他 */ @io.swagger.annotations.ApiModelProperty(value = "目标类型:0-商铺招租;1-其他", name = "targetType") - @JsonIgnore private EnumInvestType targetType; /** * 目标ID diff --git a/mallinkService/src/main/java/com/iformall/enums/EnumInvestType.java b/mallinkService/src/main/java/com/iformall/enums/EnumInvestType.java index 2f5823e14..87dae795c 100644 --- a/mallinkService/src/main/java/com/iformall/enums/EnumInvestType.java +++ b/mallinkService/src/main/java/com/iformall/enums/EnumInvestType.java @@ -1,6 +1,7 @@ package com.iformall.enums; import com.baomidou.mybatisplus.annotation.EnumValue; +import com.fasterxml.jackson.annotation.JsonValue; /** * 招商类型:0-商铺招租;1-其他 @@ -27,6 +28,7 @@ public enum EnumInvestType { this.info = info; } + @JsonValue public Integer getCode() { return code; } diff --git a/mallinkService/src/main/java/com/iformall/service/WxBrandService.java b/mallinkService/src/main/java/com/iformall/service/WxBrandService.java index fb871b7ea..1454993ff 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxBrandService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxBrandService.java @@ -3,7 +3,10 @@ package com.iformall.service; import com.github.pagehelper.PageInfo; import com.iformall.common.ResultData; import com.iformall.domain.po.WxBrand; +import com.iformall.domain.po.WxShop; +import java.io.Serializable; +import java.util.Collection; import java.util.List; import java.util.Map; @@ -30,6 +33,8 @@ public interface WxBrandService { */ WxBrand getById(Long id); + List getByIds(Collection ids); + /** * 根据Id删除实体 * diff --git a/mallinkService/src/main/java/com/iformall/service/WxBusinessService.java b/mallinkService/src/main/java/com/iformall/service/WxBusinessService.java index f2cfee7d7..3dcc72f14 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxBusinessService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxBusinessService.java @@ -2,7 +2,11 @@ package com.iformall.service; import com.github.pagehelper.PageInfo; import com.iformall.common.ResultData; +import com.iformall.domain.po.WxBrand; import com.iformall.domain.po.WxBusiness; + +import java.io.Serializable; +import java.util.Collection; import java.util.List; import java.util.Map; @@ -41,6 +45,8 @@ public interface WxBusinessService { */ WxBusiness getById(Integer id); + List getByIds(Collection ids); + List> businessDataList(WxBusiness wxBusiness,Long userid); diff --git a/mallinkService/src/main/java/com/iformall/service/WxShopService.java b/mallinkService/src/main/java/com/iformall/service/WxShopService.java index 982224fb8..1e61923eb 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxShopService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxShopService.java @@ -1,5 +1,6 @@ package com.iformall.service; +import java.io.Serializable; import java.util.*; import com.github.pagehelper.PageInfo; import com.iformall.common.ResultData; @@ -30,7 +31,9 @@ public interface WxShopService { * @return */ WxShop getById(Long id); - + + List getByIds(Collection ids); + /** * 保存或更新实体 * diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxBrandServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxBrandServiceImpl.java index 17f0ff845..11bfff1d3 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxBrandServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxBrandServiceImpl.java @@ -18,6 +18,8 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.io.Serializable; +import java.util.Collection; import java.util.Date; import java.util.List; import java.util.Map; @@ -42,6 +44,11 @@ public class WxBrandServiceImpl implements WxBrandService { return wxBrandMapper.selectById(id); } + @Override + public List getByIds(Collection ids) { + return wxBrandMapper.selectBatchIds(ids); + } + @Override public void deleteById(Long id) { wxBrandMapper.deleteById(id); diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxBusinessServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxBusinessServiceImpl.java index b7c1ab7ee..8c08e7d7f 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxBusinessServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxBusinessServiceImpl.java @@ -19,9 +19,11 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.io.Serializable; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import java.util.Map; @@ -64,6 +66,11 @@ public class WxBusinessServiceImpl implements WxBusinessService { return wxBusinessMapper.selectById(id); } + @Override + public List getByIds(Collection ids) { + return wxBusinessMapper.selectBatchIds(ids); + } + @Override public List> businessDataList(WxBusiness wxBusiness, Long userid) { diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxShopServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxShopServiceImpl.java index f5fedd963..d291ae1b4 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxShopServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxShopServiceImpl.java @@ -26,6 +26,7 @@ import org.springframework.stereotype.Service; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.io.Serializable; import java.util.*; @Service @@ -70,6 +71,10 @@ public class WxShopServiceImpl implements WxShopService { return wxShopMapper.selectById(id); } + public List getByIds(Collection ids) { + return wxShopMapper.selectBatchIds(ids) ; + } + @Override public ResultData saveOrUpdate(WxShop record) { if (record.getId() == null) { 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 de6e77565..5ed55e8f7 100755 --- a/mallinkService/src/main/java/com/iformall/service/invest/InvestDemandService.java +++ b/mallinkService/src/main/java/com/iformall/service/invest/InvestDemandService.java @@ -2,8 +2,8 @@ package com.iformall.service.invest; import com.baomidou.mybatisplus.extension.service.IService; import com.iformall.domain.po.InvestDemandEntity; - -import java.util.List; +import com.iformall.domain.vo.invest.InvestDemandVo; +import com.iformall.domain.vo.invest.InvestPage; /** * 客户需求 @@ -14,6 +14,12 @@ import java.util.List; */ public interface InvestDemandService extends IService { - List queryPage(InvestDemandEntity params); + InvestPage queryPage(InvestDemandEntity params) throws Exception; + + boolean saveCustomerAndDemand(InvestDemandVo customerDemandVo) ; + + boolean updateCustomerAndDemand(InvestDemandVo customerDemandVo) ; + + InvestDemandVo findById(Long id) ; } 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 4c5482b49..cf056530a 100755 --- a/mallinkService/src/main/java/com/iformall/service/invest/InvestTaskService.java +++ b/mallinkService/src/main/java/com/iformall/service/invest/InvestTaskService.java @@ -2,8 +2,8 @@ package com.iformall.service.invest; import com.baomidou.mybatisplus.extension.service.IService; import com.iformall.domain.po.InvestTaskEntity; - -import java.util.List; +import com.iformall.domain.vo.invest.InvestPage; +import com.iformall.domain.vo.invest.InvestTaskVo; /** * 招商任务 @@ -14,6 +14,6 @@ import java.util.List; */ public interface InvestTaskService extends IService { - List queryPage(InvestTaskEntity params); + InvestPage queryPage(InvestTaskEntity params); } diff --git a/mallinkService/src/main/java/com/iformall/service/invest/impl/InvestCustomerServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/invest/impl/InvestCustomerServiceImpl.java index a7cb22de3..91150e0fa 100755 --- a/mallinkService/src/main/java/com/iformall/service/invest/impl/InvestCustomerServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/invest/impl/InvestCustomerServiceImpl.java @@ -34,33 +34,65 @@ public class InvestCustomerServiceImpl extends ServiceImpl updateWrapper) { - return super.update(entity, updateWrapper); + checkBusiness(entity); + checkBrand(entity); + checkType(entity); + return super.update(entity, updateWrapper); } @TableLog @Override public boolean saveOrUpdate(InvestCustomerEntity entity) { - return super.saveOrUpdate(entity); + checkBusiness(entity); + checkBrand(entity); + checkType(entity); + return super.saveOrUpdate(entity); } @TableLog @Override public boolean updateById(InvestCustomerEntity entity) { - return super.updateById(entity); + checkBusiness(entity); + checkBrand(entity); + checkType(entity); + return super.updateById(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")); + } + } + + /** + * 校验品牌 + * @param entity + */ + private void checkBrand(InvestCustomerEntity entity) { + WxBrand brand = brandService.getById(entity.getBrandId()); + if (Objects.isNull(brand)) { + throw new MallinkException(ErrorCode.BRAND_NOT_FOUND); + } + } } 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 927fb6a82..e55a10093 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,47 +1,163 @@ package com.iformall.service.invest.impl; import com.baomidou.mybatisplus.core.conditions.Wrapper; +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.InvestDemandEntity; +import com.iformall.domain.po.*; +import com.iformall.domain.vo.invest.InvestDemandVo; +import com.iformall.domain.vo.invest.InvestPage; 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 com.iformall.service.invest.InvestHelper; +import org.apache.commons.collections.CollectionUtils; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.List; - import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import java.util.*; +import java.util.stream.Collectors; + @Service public class InvestDemandServiceImpl extends ServiceImpl implements InvestDemandService { + @Autowired + private WxShopService shopService; + @Autowired + private MallUserInfoService userInfoService; + @Autowired + private InvestCustomerService customerService; + @Autowired + private WxBrandService brandService; + + @Override + public InvestPage queryPage(InvestDemandEntity params) { + InvestHelper.checkAllNotNull(params); + Page page = InvestHelper.buildQueryPage(params); + InvestPage investPage = new InvestPage<>(); + //1、客户需求 + IPage demandPage = this.page(page); + if (CollectionUtils.isEmpty(demandPage.getRecords())) { + return investPage; + } + + 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 demandEntity : demandList) { + InvestCustomerEntity customer = customersMap.get(demandEntity.getCustomerId()); + WxShop shop = shopsMap.get(demandEntity.getTargetId()); + WxBrand brand = null; + if (Objects.nonNull(customer)) { + brand = brandMap.get(customer.getBrandId()); + } + resultList.add(buildCustomerDemandVo(demandEntity, customer, brand, shop)); + } + + BeanUtils.copyProperties(demandPage, investPage); + investPage.setRecords(resultList); + investPage.setTotal(demandPage.getTotal()); + return investPage; + } + + @Override + public boolean saveCustomerAndDemand(InvestDemandVo customerDemandVo) { + savaOrUpdateCustomerDemand(customerDemandVo); + return true; + } + + @Override + public boolean updateCustomerAndDemand(InvestDemandVo customerDemandVo) { + savaOrUpdateCustomerDemand(customerDemandVo); + return true; + } + + + private void savaOrUpdateCustomerDemand(InvestDemandVo customerDemandVo) { + InvestHelper.checkAllNotNull(customerDemandVo); + InvestHelper.checkAllNotNull(customerDemandVo.getBrand(), customerDemandVo.getCustomer()); + InvestCustomerEntity customerEntity = new InvestCustomerEntity(); + BeanUtils.copyProperties(customerDemandVo, customerEntity); + customerService.saveOrUpdate(customerEntity); + InvestDemandEntity demandEntity = new InvestDemandEntity(); + BeanUtils.copyProperties(customerDemandVo, demandEntity); + this.saveOrUpdate(demandEntity); + } + @Override - public List queryPage(InvestDemandEntity params) { - return this.list() ; + public InvestDemandVo findById(Long id) { + InvestHelper.checkAllNotNull(id); + InvestDemandEntity demandEntity = this.getById(id); + InvestHelper.checkAllNotNull(demandEntity); + InvestCustomerEntity customerEntity = customerService.getById(demandEntity.getCustomerId()); + InvestHelper.checkAllNotNull(customerEntity); + WxBrand brand = brandService.getById(customerEntity.getBrandId()); + WxShop shop = shopService.getById(demandEntity.getTargetId()); + InvestDemandVo customerDemandVo = buildCustomerDemandVo(demandEntity, customerEntity, brand, shop); + return customerDemandVo; } + private InvestDemandVo buildCustomerDemandVo(InvestDemandEntity demandEntity, InvestCustomerEntity customer, WxBrand brand, WxShop shop) { + InvestDemandVo customerDemandVo = InvestDemandVo.builder() + .brand(brand) + .customer(customer) + .targetInfo(shop) + .build(); + BeanUtils.copyProperties(demandEntity, customerDemandVo); + return customerDemandVo; + } @TableLog @Override public boolean save(InvestDemandEntity entity) { + checkBeforeSaveOrUpdate(entity); return super.save(entity); } @TableLog @Override public boolean update(InvestDemandEntity entity, Wrapper updateWrapper) { + checkBeforeSaveOrUpdate(entity); return super.update(entity, updateWrapper); } @TableLog @Override public boolean saveOrUpdate(InvestDemandEntity entity) { + checkBeforeSaveOrUpdate(entity); return super.saveOrUpdate(entity); } @TableLog @Override public boolean updateById(InvestDemandEntity entity) { + checkBeforeSaveOrUpdate(entity); return super.updateById(entity); } + + private void checkBeforeSaveOrUpdate(InvestDemandEntity entity) { + InvestHelper.checkCustomerExit(customerService, entity.getCustomerId()); + InvestHelper.checkUserExit(userInfoService, entity.getOwner()); + InvestHelper.checkShop(shopService, entity); + } + } 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 2fc850097..3b5fb224f 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 @@ -8,7 +8,6 @@ import com.iformall.service.invest.InvestRemindService; import org.springframework.stereotype.Service; import java.util.List; -import java.util.Map; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 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 bb4f8dbce..1a540253b 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,24 +1,23 @@ package com.iformall.service.invest.impl; import com.baomidou.mybatisplus.core.conditions.Wrapper; -import com.iformall.common.ErrorCode; +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.MallUserInfo; -import com.iformall.domain.po.WxShop; -import com.iformall.enums.EnumInvestType; -import com.iformall.enums.EnumShopStatus; -import com.iformall.exception.MallinkException; +import com.iformall.domain.po.*; +import com.iformall.domain.vo.invest.InvestPage; +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; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.List; -import java.util.Objects; +import java.util.*; import java.util.stream.Collectors; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @@ -33,17 +32,38 @@ public class InvestTaskServiceImpl extends ServiceImpl queryPage(InvestTaskEntity params) { + InvestHelper.checkAllNotNull(params); + Page page = InvestHelper.buildQueryPage(params); + InvestPage investPage = new InvestPage<>(); + //1、任务信息 + IPage taskPage = this.page(page); + if (CollectionUtils.isEmpty(taskPage.getRecords())) { + return investPage; + } + + List taskList = taskPage.getRecords(); + + //2、目标信息 + Collection shops = shopService.getByIds(taskList.stream().map(InvestTaskEntity::getTargetId).collect(Collectors.toList())); + Map shopsMap = shops.stream().collect(Collectors.toMap(WxShop::getId, shop -> shop)); + + List resultList = new ArrayList<>(); + for (InvestTaskEntity demandEntity : taskList) { + WxShop shop = shopsMap.get(demandEntity.getTargetId()); + resultList.add(InvestTaskVo.builder().targetInfo(shop).build()); + } + + BeanUtils.copyProperties(taskPage, investPage); + investPage.setRecords(resultList); + investPage.setTotal(taskPage.getTotal()); + return investPage; } @TableLog @Override public boolean save(InvestTaskEntity entity) { - // 1 check shop 状态 - checkShop(entity); - // 2 check user - checkUserExit(entity); + checkBeforeSaveOrUpdate(entity); return super.save(entity); } @@ -52,9 +72,7 @@ public class InvestTaskServiceImpl extends ServiceImpl updateWrapper) { // 1 check shop 状态 - checkShop(entity); - // 2 check user - checkUserExit(entity); + checkBeforeSaveOrUpdate(entity); return super.update(entity, updateWrapper); } @@ -62,9 +80,7 @@ public class InvestTaskServiceImpl extends ServiceImpl userIds = entity.parseJsonArray(entity.getOwner()); - if (CollectionUtils.isNotEmpty(userIds)) { - List usersFromDb = userInfoService.getByIds(userIds).stream().map(MallUserInfo::getId).collect(Collectors.toList()); - List notExsitIds = userIds.stream().filter(uid -> !usersFromDb.contains(uid)).collect(Collectors.toList()); - if (CollectionUtils.isNotEmpty(notExsitIds)) { - throw new MallinkException(ErrorCode.USER_IS_EMPTY.getCode(), notExsitIds + ErrorCode.USER_IS_EMPTY.getMessage()); - } - } + private void checkBeforeSaveOrUpdate(InvestTaskEntity entity) { + // 1 check shop 状态 + InvestHelper.checkShop(shopService, entity); + // 2 check user + InvestHelper.checkUserExit(userInfoService, entity.getOwner()); } }