| @@ -18,7 +18,7 @@ import org.apache.commons.lang3.StringUtils; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.transaction.annotation.Transactional; | |||
| import org.springframework.data.redis.core.StringRedisTemplate; | |||
| import org.springframework.web.bind.annotation.*; | |||
| import org.springframework.web.multipart.MultipartFile; | |||
| @@ -26,6 +26,8 @@ import javax.servlet.http.HttpServletRequest; | |||
| import javax.servlet.http.HttpServletResponse; | |||
| import java.util.ArrayList; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| import java.util.concurrent.TimeUnit; | |||
| import java.util.stream.Collectors; | |||
| @RestController | |||
| @@ -52,6 +54,9 @@ public class WxCUserBasicInfoController extends BaseController { | |||
| @Autowired | |||
| WxLevelConfigService wxLevelConfigService; | |||
| @Autowired | |||
| StringRedisTemplate stringRedisTemplate; | |||
| private void setUserInfoLevel(WxCUserBasicInfo info) { | |||
| if (info.getPoins() == null || info.getPoins() == 0) { | |||
| @@ -59,7 +64,7 @@ public class WxCUserBasicInfoController extends BaseController { | |||
| } else { | |||
| info.setLevel("无"); | |||
| List<WxLevelConfig> levelList = wxLevelConfigService.getByTenantId(info.getTenantId()); | |||
| for(WxLevelConfig levelConfig: levelList) { | |||
| for (WxLevelConfig levelConfig : levelList) { | |||
| if (info.getPoins() >= levelConfig.getPoints()) { | |||
| info.setLevel(levelConfig.getLevel()); | |||
| } | |||
| @@ -73,7 +78,7 @@ public class WxCUserBasicInfoController extends BaseController { | |||
| WxCUserTags uTag = wxCUserTagsService.getById(info.getTagId()); | |||
| if (StringUtils.isNotBlank(uTag.getTags())) { | |||
| List<Long> ids = JSONObject.parseArray(uTag.getTags(), Long.class); | |||
| info.setTagsList(wxCUserTagsService.findTagList(getTenantId(),ids)); | |||
| info.setTagsList(wxCUserTagsService.findTagList(getTenantId(), ids)); | |||
| } | |||
| } | |||
| } | |||
| @@ -140,8 +145,8 @@ public class WxCUserBasicInfoController extends BaseController { | |||
| MallUserInfo currentUser = getUser(); | |||
| WxCUserBasicInfo oldInfo = wxCUserBasicInfoService.getById(wxCUserBasicInfo.getId()); | |||
| if (!oldInfo.getPhone().equals(wxCUserBasicInfo.getPhone())) { | |||
| if(checkUniquePhone(wxCUserBasicInfo.getPhone(), currentUser.getTenantId()) > 0){ | |||
| return new ResultData(ErrorCode.USER_PHONE_IS_FOUND.getCode(),"手机号已存在"); | |||
| if (checkUniquePhone(wxCUserBasicInfo.getPhone(), currentUser.getTenantId()) > 0) { | |||
| return new ResultData(ErrorCode.USER_PHONE_IS_FOUND.getCode(), "手机号已存在"); | |||
| } | |||
| } | |||
| wxCUserBasicInfo.setTenantId(getTenantId()); | |||
| @@ -164,7 +169,7 @@ public class WxCUserBasicInfoController extends BaseController { | |||
| wxCUserBasicInfo.setTagId(record.getId()); | |||
| } | |||
| wxCUserBasicInfoService.update(wxCUserBasicInfo); | |||
| wxCUserTagsService.triggerAssignTags(EnumAssignTagsTrigger.ASSIGN_TAGS_TRIGGER_IMPORT,wxCUserBasicInfo); | |||
| wxCUserTagsService.triggerAssignTags(EnumAssignTagsTrigger.ASSIGN_TAGS_TRIGGER_IMPORT, wxCUserBasicInfo); | |||
| return new ResultData(); | |||
| } | |||
| @@ -214,30 +219,51 @@ public class WxCUserBasicInfoController extends BaseController { | |||
| } | |||
| @RequestMapping("/exportData") | |||
| public void exportData(HttpServletRequest request, HttpServletResponse response){ | |||
| public void exportData(HttpServletRequest request, HttpServletResponse response) { | |||
| logger.debug("[" + getIpAddr() + "] WxCUserBasicInfoController::exportData"); | |||
| wxCUserBasicInfoService.exportData(request,response,getTenantId()); | |||
| wxCUserBasicInfoService.exportData(request, response, getTenantId()); | |||
| } | |||
| @RequestMapping("/exportTemplate") | |||
| public void exportTemplate(HttpServletRequest request, HttpServletResponse response){ | |||
| public void exportTemplate(HttpServletRequest request, HttpServletResponse response) { | |||
| logger.debug("[" + getIpAddr() + "] WxCUserBasicInfoController::exportTemplate"); | |||
| wxCUserBasicInfoService.exportTemplate(request,response,getTenantId()); | |||
| wxCUserBasicInfoService.exportTemplate(request, response, getTenantId()); | |||
| } | |||
| @Transactional | |||
| @RequestMapping("/importTemplate") | |||
| public ResultData importTemplate(@RequestParam("file") MultipartFile file){ | |||
| public ResultData importTemplate(@RequestParam("file") MultipartFile file) { | |||
| logger.debug("[" + getIpAddr() + "] WxCUserBasicInfoController::importTemplate"); | |||
| if (file.isEmpty()) { | |||
| throw new MallinkException(500,"上传文件不能为空"); | |||
| throw new MallinkException(500, "上传文件不能为空"); | |||
| } | |||
| //得到当前用户ID | |||
| String userId = getUser().getId().toString(); | |||
| //查询当前用户得到的值是否为空,为空继续,不为空,返回模板正在导入 | |||
| Boolean allCount = stringRedisTemplate.opsForHash().hasKey(userId, "allCount"); | |||
| if (allCount) { | |||
| return new ResultData(Result.SUCCESS, "模板正在导入"); | |||
| } | |||
| return wxCUserBasicInfoService.importTemplate(file,getTenantId()); | |||
| stringRedisTemplate.opsForHash().putIfAbsent(userId, "allCount",1+""); | |||
| stringRedisTemplate.opsForHash().putIfAbsent(userId, "successCount",0+""); | |||
| wxCUserBasicInfoService.importTemplate(file, getTenantId(), userId); | |||
| stringRedisTemplate.expire(userId,30,TimeUnit.MINUTES); | |||
| return new ResultData(Result.SUCCESS, "模板正在导入"); | |||
| } | |||
| @GetMapping("/queryTemplateCount") | |||
| public ResultData queryTemplateCount() { | |||
| String userId = getUser().getId().toString(); | |||
| Long size = stringRedisTemplate.opsForHash().size(userId); | |||
| if(size>0){ | |||
| Map entries = stringRedisTemplate.opsForHash().entries(userId); | |||
| return new ResultData(Result.SUCCESS,"查询成功",entries); | |||
| } | |||
| return new ResultData(Result.SUCCESS,"查询成功","ok"); | |||
| } | |||
| } | |||
| } | |||
| @@ -103,7 +103,7 @@ public interface WxCUserBasicInfoService { | |||
| void exportTemplate(HttpServletRequest request, HttpServletResponse response, String tenantId); | |||
| ResultData importTemplate(MultipartFile file, String tenantId); | |||
| ResultData importTemplate(MultipartFile file, String tenantId, String userId); | |||
| long findCount(WxCUserBasicInfoDto dto); | |||
| @@ -5,12 +5,10 @@ import cn.afterturn.easypoi.excel.entity.ImportParams; | |||
| import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult; | |||
| import cn.afterturn.easypoi.handler.impl.ExcelDataHandlerDefaultImpl; | |||
| import cn.afterturn.easypoi.handler.inter.IExcelDataHandler; | |||
| import com.alibaba.fastjson.JSON; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| import com.github.pagehelper.PageHelper; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.IdWorker; | |||
| import com.iformall.common.Result; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.dto.WxCUserBasicInfoDto; | |||
| import com.iformall.domain.po.WxCUser; | |||
| @@ -21,7 +19,6 @@ import com.iformall.domain.vo.CUserBaseInfoT; | |||
| import com.iformall.domain.vo.CUserBaseVo; | |||
| import com.iformall.domain.vo.CUserTagVo; | |||
| import com.iformall.enums.EnumAssignTagsTrigger; | |||
| import com.iformall.enums.EnumTag; | |||
| import com.iformall.mapper.WxCUserBasicInfoMapper; | |||
| import com.iformall.mapper.WxCUserMapper; | |||
| import com.iformall.mapper.WxCUserTagsMapper; | |||
| @@ -38,8 +35,9 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.data.redis.core.StringRedisTemplate; | |||
| import org.springframework.scheduling.annotation.Async; | |||
| import org.springframework.stereotype.Service; | |||
| import org.springframework.util.StopWatch; | |||
| import org.springframework.web.multipart.MultipartFile; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| @@ -51,6 +49,7 @@ import java.util.ArrayList; | |||
| import java.util.Date; | |||
| import java.util.List; | |||
| import java.util.UUID; | |||
| import java.util.concurrent.TimeUnit; | |||
| @Service | |||
| public class WxCUserBasicInfoServiceImpl implements WxCUserBasicInfoService { | |||
| @@ -71,6 +70,9 @@ public class WxCUserBasicInfoServiceImpl implements WxCUserBasicInfoService { | |||
| @Autowired | |||
| WxCUserTagsService wxCUserTagsService; | |||
| @Autowired | |||
| StringRedisTemplate stringRedisTemplate; | |||
| @Override | |||
| public PageInfo<WxCUserBasicInfo> listAsPage(WxCUserBasicInfo record, Integer pageIndex, Integer pageSize) { | |||
| return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxCUserBasicInfoMapper.findList(record)); | |||
| @@ -438,7 +440,7 @@ public class WxCUserBasicInfoServiceImpl implements WxCUserBasicInfoService { | |||
| */ | |||
| private WxCUserBasicInfo InitUserBaseInfo(CUserBaseInfoT uBase, String tenantId) { | |||
| public WxCUserBasicInfo InitUserBaseInfo(CUserBaseInfoT uBase, String tenantId) { | |||
| if (StringUtils.isBlank(uBase.getPhone())) { | |||
| return null; | |||
| } | |||
| @@ -487,8 +489,10 @@ public class WxCUserBasicInfoServiceImpl implements WxCUserBasicInfoService { | |||
| } | |||
| @Async | |||
| @Override | |||
| public ResultData importTemplate(MultipartFile file, String tenantId) { | |||
| public ResultData importTemplate(MultipartFile file, String tenantId, String userId) { | |||
| final IdWorker idWorker = IdWorker.get(); | |||
| @@ -507,18 +511,19 @@ public class WxCUserBasicInfoServiceImpl implements WxCUserBasicInfoService { | |||
| List<CUserBaseInfoT> failList = datalist.getFailList(); | |||
| logger.info("验证通过的数量:" + successList.size()); | |||
| logger.info("验证未通过的数量:" + failList.size()); | |||
| for (CUserBaseInfoT uBase : successList) { | |||
| //如果不存在就添加 | |||
| stringRedisTemplate.opsForHash().put(userId,"allCount",successList.size()+""); | |||
| successList.parallelStream().forEach(uBase->{ | |||
| if (StringUtils.isBlank(uBase.getPhone())) { | |||
| logger.error("手机号为空", uBase.toString()); | |||
| continue; | |||
| return; | |||
| } | |||
| WxCUserBasicInfo userBase = InitUserBaseInfo(uBase, tenantId); | |||
| if (userBase == null) { | |||
| continue; | |||
| return; | |||
| } | |||
| Date curDate = new Date(); | |||
| WxCUserBasicInfo oldUserBase = null; | |||
| WxCUserBasicInfo userBaseQ = new WxCUserBasicInfo(); | |||
| userBaseQ.setTenantId(tenantId); | |||
| @@ -535,7 +540,7 @@ public class WxCUserBasicInfoServiceImpl implements WxCUserBasicInfoService { | |||
| oldUserBase.setEducation(userBase.getEducation()); | |||
| oldUserBase.setBirthdate(userBase.getBirthdate()); | |||
| oldUserBase.setAddress(userBase.getAddress()); | |||
| oldUserBase.setUpdateDate(userBase.getUpdateDate()); | |||
| oldUserBase.setUpdateDate(new Date()); | |||
| oldUserBase.setCreateDate(userBase.getCreateDate()); | |||
| } else { | |||
| // check c_user 是否存在 | |||
| @@ -590,30 +595,33 @@ public class WxCUserBasicInfoServiceImpl implements WxCUserBasicInfoService { | |||
| } | |||
| } | |||
| if (oldUserBase != null) | |||
| if (oldUserBase != null){ | |||
| wxCUserTagsService.assignTags(tagIdList,oldUserBase); | |||
| else | |||
| }else{ | |||
| wxCUserTagsService.assignTags(tagIdList,userBase); | |||
| } | |||
| } | |||
| //触发自动打标签 | |||
| if (oldUserBase != null) | |||
| if (oldUserBase != null) { | |||
| wxCUserTagsService.triggerAssignTags(EnumAssignTagsTrigger.ASSIGN_TAGS_TRIGGER_IMPORT,oldUserBase); | |||
| else | |||
| } | |||
| else{ | |||
| wxCUserTagsService.triggerAssignTags(EnumAssignTagsTrigger.ASSIGN_TAGS_TRIGGER_IMPORT,userBase); | |||
| } | |||
| } | |||
| //记数 | |||
| stringRedisTemplate.opsForHash().increment(userId,"successCount",1); | |||
| }); | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| } | |||
| /* | |||
| for (WxCUserBasicInfo userBase : datalist) { | |||
| userBase.setTenantId(tenantId); | |||
| } | |||
| e.printStackTrace(); | |||
| logger.error("导入模板失败:"+e.getMessage()); | |||
| stringRedisTemplate.opsForHash().delete(userId,"allCount"); | |||
| stringRedisTemplate.opsForHash().delete(userId,"successCount"); | |||
| } | |||
| */ | |||
| return new ResultData(Result.SUCCESS, "导入成功"); | |||
| //结束也清空 | |||
| stringRedisTemplate.opsForHash().delete(userId,"allCount"); | |||
| stringRedisTemplate.opsForHash().delete(userId,"successCount"); | |||
| return new ResultData(); | |||
| } | |||
| @Override | |||
| @@ -1,28 +1,29 @@ | |||
| package com.iformall.service.impl; | |||
| import java.text.SimpleDateFormat; | |||
| import java.util.*; | |||
| import java.util.regex.Pattern; | |||
| import com.alibaba.fastjson.JSON; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| import com.iformall.domain.po.*; | |||
| import com.github.pagehelper.PageHelper; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.IdWorker; | |||
| import com.iformall.domain.po.WxCUser; | |||
| import com.iformall.domain.po.WxCUserBasicInfo; | |||
| import com.iformall.domain.po.WxCUserTags; | |||
| import com.iformall.domain.po.WxTags; | |||
| import com.iformall.enums.EnumAssignTagsTrigger; | |||
| import com.iformall.enums.EnumCUserBaseInfoSex; | |||
| import com.iformall.enums.EnumTag; | |||
| import com.iformall.enums.EnumTagTypeFlag; | |||
| import com.iformall.mapper.*; | |||
| import com.iformall.service.WxCUserBasicInfoService; | |||
| import com.iformall.service.WxCUserTagsService; | |||
| import com.iformall.service.WxTagsService; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| import com.github.pagehelper.PageHelper; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.IdWorker; | |||
| import com.iformall.service.WxCUserTagsService; | |||
| import java.text.SimpleDateFormat; | |||
| import java.util.*; | |||
| import java.util.regex.Pattern; | |||
| @Service | |||
| public class WxCUserTagsServiceImpl implements WxCUserTagsService { | |||
| @@ -34,13 +35,9 @@ public class WxCUserTagsServiceImpl implements WxCUserTagsService { | |||
| @Autowired | |||
| WxCUserBasicInfoMapper wxCUserBasicInfoMapper; | |||
| @Autowired | |||
| WxCUserBasicInfoService wxCUserBasicInfoService; | |||
| @Autowired | |||
| WxCouponOrderMapper wxCouponOrderMapper; | |||
| @Autowired | |||
| WxCUserMapper wxCUserMapper; | |||
| @@ -206,7 +203,7 @@ public class WxCUserTagsServiceImpl implements WxCUserTagsService { | |||
| if (user.getTagId() == null || | |||
| !user.getTagId().equals(record.getId())) { | |||
| user.setTagId(record.getId()); | |||
| wxCUserBasicInfoService.update(user); | |||
| wxCUserBasicInfoMapper.updateByPrimaryKeySelective(user); | |||
| } | |||
| WxTags wxTags = new WxTags(); | |||
| wxTags.setIds(tagIdList); | |||
| @@ -513,7 +510,7 @@ public class WxCUserTagsServiceImpl implements WxCUserTagsService { | |||
| switch (trigger) { | |||
| case ASSIGN_TAGS_TRIGGER_IMPORT: { | |||
| WxCUserBasicInfo param = (WxCUserBasicInfo) obj; | |||
| WxCUserBasicInfo user = wxCUserBasicInfoService.getById(param.getId()); | |||
| WxCUserBasicInfo user = wxCUserBasicInfoMapper.selectByPrimaryKey(param.getId()); | |||
| if (user != null) { | |||
| if (param.getSex() != null) { | |||
| //性别 | |||
| @@ -542,7 +539,7 @@ public class WxCUserTagsServiceImpl implements WxCUserTagsService { | |||
| break; | |||
| case ASSIGN_TAGS_TRIGGER_CAR:{ | |||
| WxCUser param = (WxCUser) obj; | |||
| WxCUserBasicInfo user = wxCUserBasicInfoService.getById(param.getId()); | |||
| WxCUserBasicInfo user = wxCUserBasicInfoMapper.selectByPrimaryKey(param.getId()); | |||
| if (user != null) { | |||
| //车 | |||
| resList = assignTypeId11(user); | |||
| @@ -551,7 +548,7 @@ public class WxCUserTagsServiceImpl implements WxCUserTagsService { | |||
| break; | |||
| case ASSIGN_TAGS_TRIGGER_PHONE: { | |||
| WxCUser param = (WxCUser) obj; | |||
| WxCUserBasicInfo user = wxCUserBasicInfoService.getById(param.getId()); | |||
| WxCUserBasicInfo user = wxCUserBasicInfoMapper.selectByPrimaryKey(param.getId()); | |||
| if (user != null) { | |||
| if (param.getPhone() != null) { | |||
| //来源 | |||
| @@ -564,7 +561,7 @@ public class WxCUserTagsServiceImpl implements WxCUserTagsService { | |||
| break; | |||
| case ASSIGN_TAGS_TRIGGER_BUY:{ | |||
| WxCUser param = (WxCUser) obj; | |||
| WxCUserBasicInfo user = wxCUserBasicInfoService.getById(param.getId()); | |||
| WxCUserBasicInfo user = wxCUserBasicInfoMapper.selectByPrimaryKey(param.getId()); | |||
| if (user != null) { | |||
| //消费时段 | |||
| resList = assignTypeId18(user, param); | |||
| @@ -578,7 +575,7 @@ public class WxCUserTagsServiceImpl implements WxCUserTagsService { | |||
| case ASSIGN_TAGS_TRIGGER_LOGIN: { | |||
| WxCUser param = (WxCUser) obj; | |||
| WxCUserBasicInfo user = wxCUserBasicInfoService.getById(param.getId()); | |||
| WxCUserBasicInfo user = wxCUserBasicInfoMapper.selectByPrimaryKey(param.getId()); | |||
| if (user != null) { | |||
| if (param.getGender() != null) { | |||
| //性别 | |||