| @@ -24,4 +24,10 @@ public class MyBatisConfiguration { | |||
| return multiTenancy; | |||
| } | |||
| @Bean | |||
| public PaginationInterceptor paginationInterceptor() { | |||
| PaginationInterceptor page = new PaginationInterceptor(); | |||
| page.setDialectType("mysql"); | |||
| return page; | |||
| } | |||
| } | |||
| @@ -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<InvestPage<InvestDemandVo>> list(@ModelAttribute InvestDemandEntity params) { | |||
| try { | |||
| InvestPage<InvestDemandVo> 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<InvestDemandVo> 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(); | |||
| @@ -32,7 +32,7 @@ public class InvestFollowRecordController { | |||
| * 分页列表 | |||
| */ | |||
| @ApiOperation("分页列表接口") | |||
| @PostMapping("/list") | |||
| @GetMapping("/list") | |||
| public ResultData list(@RequestBody InvestFollowRecordEntity params){ | |||
| List page = investFollowRecordService.queryPage(params); | |||
| @@ -33,7 +33,7 @@ public class InvestOperateRecordController { | |||
| * 分页列表 | |||
| */ | |||
| @ApiOperation("分页列表接口") | |||
| @PostMapping("/list") | |||
| @GetMapping("/list") | |||
| public ResultData list(@RequestBody InvestOperateRecordEntity params){ | |||
| List page = investOperateRecordService.queryPage(params); | |||
| @@ -34,7 +34,7 @@ public class InvestRemindController { | |||
| * 分页列表 | |||
| */ | |||
| @ApiOperation("分页列表接口") | |||
| @PostMapping("/list") | |||
| @GetMapping("/list") | |||
| public ResultData list(@RequestBody InvestRemindEntity params){ | |||
| List page = investRemindService.queryPage(params); | |||
| @@ -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<InvestPage<InvestTaskVo>> list(@ModelAttribute InvestTaskEntity params){ | |||
| try { | |||
| InvestPage<InvestTaskVo> 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)); | |||
| @@ -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)); | |||
| } | |||
| /** | |||
| @@ -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<MallUserInfo> 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<String, Object> 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<String, Object> content = Maps.newHashMap(); | |||
| content.put("business", businessId); | |||
| content.put("lastDate", lastDate); | |||
| taskEntity.setContent(JSON.toJSONString(content)); | |||
| taskService.save(taskEntity); | |||
| } | |||
| @Test | |||
| public void createDemand() { | |||
| List<InvestCustomerEntity> 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<String, Object> 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)); | |||
| } | |||
| } | |||
| @@ -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 | |||
| ; | |||
| @@ -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<String> 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<String> 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<Field> 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<Long> parseJsonArray(String json) { | |||
| if (Objects.nonNull(json)) { | |||
| List<Long> 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(); | |||
| } | |||
| } | |||
| } | |||
| @@ -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 | |||
| */ | |||
| @@ -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-其他 | |||
| @@ -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 | |||
| @@ -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; | |||
| } | |||
| @@ -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<WxBrand> getByIds(Collection<? extends Serializable> ids); | |||
| /** | |||
| * 根据Id删除实体 | |||
| * | |||
| @@ -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<WxBusiness> getByIds(Collection<? extends Serializable> ids); | |||
| List<Map<String,Object>> businessDataList(WxBusiness wxBusiness,Long userid); | |||
| @@ -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<WxShop> getByIds(Collection<? extends Serializable> ids); | |||
| /** | |||
| * 保存或更新实体 | |||
| * | |||
| @@ -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<WxBrand> getByIds(Collection<? extends Serializable> ids) { | |||
| return wxBrandMapper.selectBatchIds(ids); | |||
| } | |||
| @Override | |||
| public void deleteById(Long id) { | |||
| wxBrandMapper.deleteById(id); | |||
| @@ -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<WxBusiness> getByIds(Collection<? extends Serializable> ids) { | |||
| return wxBusinessMapper.selectBatchIds(ids); | |||
| } | |||
| @Override | |||
| public List<Map<String, Object>> businessDataList(WxBusiness wxBusiness, Long userid) { | |||
| @@ -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<WxShop> getByIds(Collection<? extends Serializable> ids) { | |||
| return wxShopMapper.selectBatchIds(ids) ; | |||
| } | |||
| @Override | |||
| public ResultData saveOrUpdate(WxShop record) { | |||
| if (record.getId() == null) { | |||
| @@ -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<InvestDemandEntity> { | |||
| List queryPage(InvestDemandEntity params); | |||
| InvestPage<InvestDemandVo> queryPage(InvestDemandEntity params) throws Exception; | |||
| boolean saveCustomerAndDemand(InvestDemandVo customerDemandVo) ; | |||
| boolean updateCustomerAndDemand(InvestDemandVo customerDemandVo) ; | |||
| InvestDemandVo findById(Long id) ; | |||
| } | |||
| @@ -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<InvestTaskEntity> { | |||
| List queryPage(InvestTaskEntity params); | |||
| InvestPage<InvestTaskVo> queryPage(InvestTaskEntity params); | |||
| } | |||
| @@ -34,33 +34,65 @@ public class InvestCustomerServiceImpl extends ServiceImpl<InvestCustomerDao, In | |||
| @TableLog | |||
| @Override | |||
| public boolean save(InvestCustomerEntity entity) { | |||
| WxBrand brand = brandService.getById(entity.getBrandId()); | |||
| if (Objects.isNull(brand)) { | |||
| throw new MallinkException(ErrorCode.BRAND_NOT_FOUND); | |||
| } | |||
| if (Objects.isNull(entity.getType())) { | |||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), | |||
| ErrorCode.SYS_PARAMETER_NOT_NULL.getMessage("type")); | |||
| } | |||
| return super.save(entity); | |||
| checkBusiness(entity); | |||
| checkBrand(entity); | |||
| checkType(entity); | |||
| return super.save(entity); | |||
| } | |||
| @TableLog | |||
| @Override | |||
| public boolean update(InvestCustomerEntity entity, Wrapper<InvestCustomerEntity> 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); | |||
| } | |||
| } | |||
| } | |||
| @@ -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<InvestDemandDao, InvestDemandEntity> implements InvestDemandService { | |||
| @Autowired | |||
| private WxShopService shopService; | |||
| @Autowired | |||
| private MallUserInfoService userInfoService; | |||
| @Autowired | |||
| private InvestCustomerService customerService; | |||
| @Autowired | |||
| private WxBrandService brandService; | |||
| @Override | |||
| public InvestPage<InvestDemandVo> queryPage(InvestDemandEntity params) { | |||
| InvestHelper.checkAllNotNull(params); | |||
| Page page = InvestHelper.buildQueryPage(params); | |||
| InvestPage<InvestDemandVo> investPage = new InvestPage<>(); | |||
| //1、客户需求 | |||
| IPage<InvestDemandEntity> demandPage = this.page(page); | |||
| if (CollectionUtils.isEmpty(demandPage.getRecords())) { | |||
| return investPage; | |||
| } | |||
| 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 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<InvestDemandEntity> 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); | |||
| } | |||
| } | |||
| @@ -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; | |||
| @@ -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<InvestTaskDao, InvestTask | |||
| private MallUserInfoService userInfoService; | |||
| @Override | |||
| public List queryPage(InvestTaskEntity params) { | |||
| return this.list() ; | |||
| public InvestPage<InvestTaskVo> queryPage(InvestTaskEntity params) { | |||
| InvestHelper.checkAllNotNull(params); | |||
| Page page = InvestHelper.buildQueryPage(params); | |||
| InvestPage<InvestTaskVo> investPage = new InvestPage<>(); | |||
| //1、任务信息 | |||
| IPage<InvestTaskEntity> taskPage = this.page(page); | |||
| if (CollectionUtils.isEmpty(taskPage.getRecords())) { | |||
| return investPage; | |||
| } | |||
| List<InvestTaskEntity> taskList = taskPage.getRecords(); | |||
| //2、目标信息 | |||
| Collection<WxShop> shops = shopService.getByIds(taskList.stream().map(InvestTaskEntity::getTargetId).collect(Collectors.toList())); | |||
| Map<Long, WxShop> shopsMap = shops.stream().collect(Collectors.toMap(WxShop::getId, shop -> shop)); | |||
| List<InvestTaskVo> 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<InvestTaskDao, InvestTask | |||
| @Override | |||
| public boolean update(InvestTaskEntity entity, Wrapper<InvestTaskEntity> 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<InvestTaskDao, InvestTask | |||
| @Override | |||
| public boolean saveOrUpdate(InvestTaskEntity entity) { | |||
| // 1 check shop 状态 | |||
| checkShop(entity); | |||
| // 2 check user | |||
| checkUserExit(entity); | |||
| checkBeforeSaveOrUpdate(entity); | |||
| return super.saveOrUpdate(entity); | |||
| } | |||
| @@ -72,37 +88,15 @@ public class InvestTaskServiceImpl extends ServiceImpl<InvestTaskDao, InvestTask | |||
| @Override | |||
| public boolean updateById(InvestTaskEntity entity) { | |||
| // 1 check shop 状态 | |||
| checkShop(entity); | |||
| // 2 check user | |||
| checkUserExit(entity); | |||
| checkBeforeSaveOrUpdate(entity); | |||
| return super.updateById(entity); | |||
| } | |||
| private void checkShop(InvestTaskEntity entity) { | |||
| if (EnumInvestType.SHOP.equals(entity.getTargetType())) { | |||
| WxShop shop = shopService.getById(entity.getTargetId()); | |||
| 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); | |||
| } | |||
| } | |||
| } | |||
| /** | |||
| * 校验用户是否存在 | |||
| * @param entity | |||
| */ | |||
| private void checkUserExit(InvestTaskEntity entity) { | |||
| List<Long> userIds = entity.parseJsonArray(entity.getOwner()); | |||
| if (CollectionUtils.isNotEmpty(userIds)) { | |||
| List<Long> usersFromDb = userInfoService.getByIds(userIds).stream().map(MallUserInfo::getId).collect(Collectors.toList()); | |||
| List<Long> 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()); | |||
| } | |||
| } | |||