Просмотр исходного кода

[招商]adjust

release_toaliyun_real
Burce 6 лет назад
Родитель
Сommit
4d5180501d
1 измененных файлов: 264 добавлений и 0 удалений
  1. +264
    -0
      mallinkAdmin/src/test/java/com/iformall/service/test/InvestTests.java

+ 264
- 0
mallinkAdmin/src/test/java/com/iformall/service/test/InvestTests.java Просмотреть файл

@@ -0,0 +1,264 @@
package com.iformall.service.test;

import com.alibaba.fastjson.JSON;
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.enums.*;
import com.iformall.mapper.WxBrandMapper;
import com.iformall.service.MallUserInfoService;
import com.iformall.service.invest.*;
import com.iformall.utils.DateUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.util.ThreadContext;
import org.apache.shiro.web.subject.WebSubject;
import org.junit.Before;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Bean;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.mock.web.MockHttpSession;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.WebApplicationContext;

import javax.annotation.Resource;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Collectors;

@Slf4j
@Rollback(false)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@Transactional(rollbackFor = Exception.class)
@RunWith(SpringRunner.class)
@SpringBootTest
public class InvestTests {
@Resource
private org.apache.shiro.mgt.SecurityManager securityManager;
@Resource
private WebApplicationContext webApplicationContext;
private MockHttpServletRequest mockHttpServletRequest;
private MockHttpServletResponse mockHttpServletResponse;
private MockMvc mockMvc;

@Autowired
InvestCustomerService customerService;
@Autowired
InvestTaskService taskService;
@Autowired
InvestDemandService demandService;
@Autowired
InvestOperateRecordService operateRecordService;
@Autowired
InvestRemindService remindService;
@Autowired
InvestFollowRecordService followRecordService;
@Autowired
MallUserInfoService mallUserInfoService;
@Resource
WxBrandMapper brandMapper;
static final String[] names = {"张三", "李四", "王五", "徐六", "胡八",};
Random rand = new Random();
String tenantId = "456";

@Before
public void setUp() {
mockHttpServletRequest = new MockHttpServletRequest(webApplicationContext.getServletContext());
mockHttpServletResponse = new MockHttpServletResponse();
MockHttpSession mockHttpSession = new MockHttpSession(webApplicationContext.getServletContext());
mockHttpServletRequest.setSession(mockHttpSession);
SecurityUtils.setSecurityManager(securityManager);
mockMvc = MockMvcBuilders
.webAppContextSetup(webApplicationContext)
.build();
login("yftest", "123456zz");
}

private void login(String username, String password) {
Subject subject = new WebSubject.Builder(mockHttpServletRequest, mockHttpServletResponse)
.buildWebSubject();
UsernamePasswordToken token = new UsernamePasswordToken(username, password, true);
subject.login(token);
ThreadContext.bind(subject);
}

@Bean
public List<MallUserInfo> mallUsers() {
MallUserInfo query = new MallUserInfo();
query.setStatus(1);
query.setIsAdmin(1);
query.setTenantId(tenantId);
return mallUserInfoService.findList(query);
}

@Bean
public List<WxBrand> brands() {
WxBrand query = new WxBrand();
query.setIsDel(0);
query.setTenantId(tenantId);
return brandMapper.findList(query);
}

@Test
public void createCustomer() {
//create customer
AtomicLong idCounter = new AtomicLong(10000);
AtomicInteger businessCounter = new AtomicInteger(1);
for (String name : names) {
InvestCustomerEntity customerEntity = new InvestCustomerEntity();
customerEntity.setBrandId(idCounter.longValue());
customerEntity.setBusiness(businessCounter.intValue());
customerEntity.setName(name);
customerEntity.setTenantId(tenantId);
customerEntity.setPhone("15811234898");
customerEntity.setInvestChannel(EnumInvestChannel.getEnum(businessCounter.intValue() % 8));
customerEntity.setRating(EnumCustomerRatingType.getEnum(businessCounter.intValue() % 6));
customerEntity.setType(EnumCustomerType.getEnum(businessCounter.intValue() / 4));
customerService.saveOrUpdate(customerEntity);
idCounter.incrementAndGet();
businessCounter.incrementAndGet();
}
}

@Test
public void createTask() {
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);
idCounter.incrementAndGet();
businessCounter.incrementAndGet();
}
}

@Test
public void createDemand() {
List<InvestCustomerEntity> customers = customerService.list();
List<MallUserInfo> mallUsers = mallUsers();
AtomicLong idCounter = new AtomicLong(10000);
AtomicInteger businessCounter = new AtomicInteger(1);
for (MallUserInfo userInfo : mallUsers) {
InvestDemandEntity demandEntity = new InvestDemandEntity();
demandEntity.setCustomerId(customers.get(rand.nextInt(customers.size())).getId());
demandEntity.setTargetId(idCounter.longValue());
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));
demandService.save(demandEntity);
idCounter.incrementAndGet();
businessCounter.incrementAndGet();
}
}

@Test
public void createRemind() {
List<MallUserInfo> mallUsers = mallUsers();
AtomicLong idCounter = new AtomicLong(10000);
AtomicInteger businessCounter = new AtomicInteger(1);
for (MallUserInfo userInfo : mallUsers) {
InvestRemindEntity remindEntity = new InvestRemindEntity();
remindEntity.setBeginDate(new Date());
remindEntity.setEndDate(new Date());
remindEntity.setOwner(userInfo.getId());
remindEntity.setMinute(businessCounter.longValue() * 5);
remindEntity.setTenantId(tenantId);
Map<String, Object> content = Maps.newHashMap();
content.put("text", "今天约了王老板,目标要签订框架协议"); //文本内容
content.put("customer_id", idCounter.longValue()); //客户对接人
content.put("negotiation_type", EnumNegotiationType.COME_VISIT.getCode()); //洽谈方式
remindEntity.setContent(JSON.toJSONString(content));
remindService.save(remindEntity);
idCounter.incrementAndGet();
businessCounter.incrementAndGet();
}
}

@Test
public void createFollowRecod() {
List<MallUserInfo> mallUsers = mallUsers();
List<InvestCustomerEntity> customerEntity = customerService.list();
AtomicLong idCounter = new AtomicLong(10000);
AtomicInteger businessCounter = new AtomicInteger(1);
for (MallUserInfo userInfo : mallUsers) {
List<MallUserInfo> members = Lists.newArrayList(mallUsers.stream()
.limit(2)
.filter(mallUser -> !Objects.equals(mallUser.getId(), userInfo.getId()))
.collect(Collectors.toList()));
InvestFollowRecordEntity followRecordEntity = new InvestFollowRecordEntity();
followRecordEntity.setOwner(userInfo.getId());
followRecordEntity.setTenantId(userInfo.getTenantId());
followRecordEntity.setType(EnumFollowType.getEnum(businessCounter.intValue() % 2));
followRecordEntity.setCustomerId(customerEntity.get(rand.nextInt(customerEntity.size())).getId());
Map<String, Object> content = Maps.newHashMap();
content.put("date", DateUtils.formatDateTime(new Date())); //文本内容
content.put("address", "北京"); //客户对接人
content.put("text", "今天约了王老板,目标要签订框架协议"); //客户对接人
content.put("document", null); //客户对接人
content.put("member", members.stream().map(MallUserInfo::getId).collect(Collectors.toList())); //辅谈人
content.put("negotiation_type", EnumNegotiationType.COME_VISIT.getCode()); //洽谈方式
followRecordEntity.setContent(JSON.toJSONString(content));
followRecordService.save(followRecordEntity);
idCounter.incrementAndGet();
businessCounter.incrementAndGet();
}
}

@Autowired
private HttpMessageConverter<?>[] httpMessageConverters;

@Test
public void query() throws JsonProcessingException {
MappingJackson2HttpMessageConverter converter = null;
for (HttpMessageConverter<?> httpMessageConverter : httpMessageConverters) {
if (httpMessageConverter instanceof MappingJackson2HttpMessageConverter)
converter = (MappingJackson2HttpMessageConverter) httpMessageConverter;
}

ObjectMapper mapper = converter.getObjectMapper();

List operates = operateRecordService.queryPage(null);
List follows = followRecordService.queryPage(null);
List customers = customerService.list(null);
List tasks = taskService.list(null);
List reminds = remindService.list(null);
List demands = demandService.list(null);
log.info("operates: {}", mapper.writeValueAsString(operates));
log.info("follows: {}", mapper.writeValueAsString(follows));
log.info("customers: {}", mapper.writeValueAsString(customers));
log.info("tasks: {}", mapper.writeValueAsString(tasks));
log.info("reminds: {}", mapper.writeValueAsString(reminds));
log.info("demands: {}", mapper.writeValueAsString(demands));
}

}

Загрузка…
Отмена
Сохранить