|
@@ -14,6 +14,12 @@ import cn.hutool.core.util.IdUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.alibaba.excel.EasyExcel;
|
|
import com.alibaba.excel.EasyExcel;
|
|
|
import com.alibaba.excel.read.listener.PageReadListener;
|
|
import com.alibaba.excel.read.listener.PageReadListener;
|
|
|
|
|
+import com.alibaba.excel.write.handler.CellWriteHandler;
|
|
|
|
|
+import com.alibaba.excel.write.handler.context.CellWriteHandlerContext;
|
|
|
|
|
+import com.alibaba.excel.write.metadata.holder.WriteWorkbookHolder;
|
|
|
|
|
+import com.alibaba.excel.write.metadata.style.WriteCellStyle;
|
|
|
|
|
+import com.alibaba.excel.write.metadata.style.WriteFont;
|
|
|
|
|
+import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
|
|
|
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
|
|
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
@@ -22,6 +28,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.google.common.collect.Lists;
|
|
import com.google.common.collect.Lists;
|
|
|
import com.yami.shop.bean.app.param.UserRegisterParam;
|
|
import com.yami.shop.bean.app.param.UserRegisterParam;
|
|
|
import com.yami.shop.bean.model.Channel;
|
|
import com.yami.shop.bean.model.Channel;
|
|
|
|
|
+import com.yami.shop.bean.model.SysDictData;
|
|
|
import com.yami.shop.bean.model.User;
|
|
import com.yami.shop.bean.model.User;
|
|
|
import com.yami.shop.bean.po.EnterpriseUserErrExcelInfo;
|
|
import com.yami.shop.bean.po.EnterpriseUserErrExcelInfo;
|
|
|
import com.yami.shop.bean.po.EnterpriseUserExcelInfo;
|
|
import com.yami.shop.bean.po.EnterpriseUserExcelInfo;
|
|
@@ -34,6 +41,8 @@ import com.yami.shop.common.util.IPHelper;
|
|
|
import com.yami.shop.common.util.PageParam;
|
|
import com.yami.shop.common.util.PageParam;
|
|
|
import com.yami.shop.common.util.RedisUtil;
|
|
import com.yami.shop.common.util.RedisUtil;
|
|
|
import com.yami.shop.dao.ChannelMapper;
|
|
import com.yami.shop.dao.ChannelMapper;
|
|
|
|
|
+import com.yami.shop.dao.SysDictDataMapper;
|
|
|
|
|
+import com.yami.shop.dao.SysDictTypeMapper;
|
|
|
import com.yami.shop.dao.UserMapper;
|
|
import com.yami.shop.dao.UserMapper;
|
|
|
import com.yami.shop.service.UserExtensionService;
|
|
import com.yami.shop.service.UserExtensionService;
|
|
|
import com.yami.shop.service.UserService;
|
|
import com.yami.shop.service.UserService;
|
|
@@ -42,21 +51,22 @@ import com.yami.shop.utils.ExportUtils;
|
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.SneakyThrows;
|
|
import lombok.SneakyThrows;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.apache.poi.ss.usermodel.CellStyle;
|
|
|
|
|
-import org.apache.poi.ss.usermodel.Row;
|
|
|
|
|
-import org.apache.poi.ss.usermodel.Sheet;
|
|
|
|
|
-import org.apache.poi.ss.usermodel.Workbook;
|
|
|
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
+import org.apache.poi.ss.usermodel.*;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
+import javax.servlet.ServletOutputStream;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
import java.net.URLEncoder;
|
|
import java.net.URLEncoder;
|
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
import java.util.Objects;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @author lgh on 2018/09/11.
|
|
* @author lgh on 2018/09/11.
|
|
@@ -70,6 +80,9 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
private final ChannelMapper channelMapper;
|
|
private final ChannelMapper channelMapper;
|
|
|
private final UserExtensionService userExtensionService;
|
|
private final UserExtensionService userExtensionService;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private SysDictDataMapper dictDataMapper;
|
|
|
|
|
+
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public User getUserByUserId(String userId) {
|
|
public User getUserByUserId(String userId) {
|
|
@@ -124,16 +137,55 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void downloadExcelGoods(HttpServletResponse response) {
|
|
public void downloadExcelGoods(HttpServletResponse response) {
|
|
|
|
|
+ ServletOutputStream outputStream = null;
|
|
|
try {
|
|
try {
|
|
|
- List<EnterpriseUserExcelInfo> list = Lists.newArrayList();
|
|
|
|
|
|
|
+ // 重置响应,避免之前的数据影响
|
|
|
|
|
+ response.reset();
|
|
|
|
|
+
|
|
|
|
|
+ // 先设置响应头
|
|
|
response.setCharacterEncoding("utf-8");
|
|
response.setCharacterEncoding("utf-8");
|
|
|
|
|
+ response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
String fileName = URLEncoder.encode("企业员工导入模板", "UTF-8").replaceAll("\\+", "%20");
|
|
String fileName = URLEncoder.encode("企业员工导入模板", "UTF-8").replaceAll("\\+", "%20");
|
|
|
response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
|
|
response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
|
|
|
- EasyExcel.write(response.getOutputStream(), EnterpriseUserExcelInfo.class)
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // 查询数据
|
|
|
|
|
+ List<SysDictData> userAttrTypeList = dictDataMapper.selectDictDataByType("user_attr_type");
|
|
|
|
|
+ String userAttrName = null;
|
|
|
|
|
+ if (userAttrTypeList != null && !userAttrTypeList.isEmpty()) {
|
|
|
|
|
+ userAttrName = userAttrTypeList.stream()
|
|
|
|
|
+ .filter(data -> data.getDictCode() != 1L)
|
|
|
|
|
+ .map(SysDictData::getDictLabel)
|
|
|
|
|
+ .collect(Collectors.joining(";"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 准备数据
|
|
|
|
|
+ List<EnterpriseUserExcelInfo> list = Lists.newArrayList();
|
|
|
|
|
+ EnterpriseUserExcelInfo enterpriseUserExcelInfo = new EnterpriseUserExcelInfo();
|
|
|
|
|
+ enterpriseUserExcelInfo.setChannel("必填!");
|
|
|
|
|
+ enterpriseUserExcelInfo.setRealName("必填!");
|
|
|
|
|
+
|
|
|
|
|
+ if (StringUtils.isNotEmpty(userAttrName)) {
|
|
|
|
|
+ enterpriseUserExcelInfo.setUserAttrName("必填!" + userAttrName);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ enterpriseUserExcelInfo.setUserAttrName("必填!且值为1");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ enterpriseUserExcelInfo.setPhone("必填!必须输入真实手机号,且该手机号码有微信");
|
|
|
|
|
+ list.add(enterpriseUserExcelInfo);
|
|
|
|
|
+
|
|
|
|
|
+ // 获取输出流
|
|
|
|
|
+ outputStream = response.getOutputStream();
|
|
|
|
|
+
|
|
|
|
|
+ // 写入Excel
|
|
|
|
|
+ EasyExcel.write(outputStream, EnterpriseUserExcelInfo.class)
|
|
|
.registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
|
|
.registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
|
|
|
- .sheet("列表").doWrite(list);
|
|
|
|
|
- } catch (IOException e) {
|
|
|
|
|
- throw new GlobalException("文件下载异常");
|
|
|
|
|
|
|
+ .sheet("列表")
|
|
|
|
|
+ .doWrite(list);
|
|
|
|
|
+ // 刷新流
|
|
|
|
|
+ outputStream.flush();
|
|
|
|
|
+
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("下载Excel模板失败", e);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -141,6 +193,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
@SneakyThrows
|
|
@SneakyThrows
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void uploadExcelGoods(MultipartFile file,String username) {
|
|
public void uploadExcelGoods(MultipartFile file,String username) {
|
|
|
|
|
+ List<SysDictData> userAttrTypeList = dictDataMapper.selectDictDataByType("user_attr_type");//查询人员属性
|
|
|
List<EnterpriseUserExcelInfo> goodsInfoList = Lists.newArrayList();
|
|
List<EnterpriseUserExcelInfo> goodsInfoList = Lists.newArrayList();
|
|
|
String batchNo = String.valueOf(System.currentTimeMillis());
|
|
String batchNo = String.valueOf(System.currentTimeMillis());
|
|
|
EasyExcel.read(file.getInputStream(), EnterpriseUserExcelInfo.class, new PageReadListener<EnterpriseUserExcelInfo>(goodsInfoList::addAll)).sheet().doRead();
|
|
EasyExcel.read(file.getInputStream(), EnterpriseUserExcelInfo.class, new PageReadListener<EnterpriseUserExcelInfo>(goodsInfoList::addAll)).sheet().doRead();
|
|
@@ -150,12 +203,14 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
CullenUtils.validateDataThrowException(c.getPhone()==null,"手机号不能为空...");
|
|
CullenUtils.validateDataThrowException(c.getPhone()==null,"手机号不能为空...");
|
|
|
CullenUtils.validateDataThrowException(c.getChannel()==null,"渠道不能为空...");
|
|
CullenUtils.validateDataThrowException(c.getChannel()==null,"渠道不能为空...");
|
|
|
CullenUtils.validateDataThrowException(c.getRealName()==null,"姓名不能为空...");
|
|
CullenUtils.validateDataThrowException(c.getRealName()==null,"姓名不能为空...");
|
|
|
|
|
+ CullenUtils.validateDataThrowException(c.getUserAttrName()==null,"人员属性不能为空...");
|
|
|
|
|
+ String userAttrType = getUserAttrType(c.getUserAttrName().replaceAll("\\s+", ""), userAttrTypeList);
|
|
|
String phone = c.getPhone().replaceAll("\\s+", "");
|
|
String phone = c.getPhone().replaceAll("\\s+", "");
|
|
|
- if (phone.length()!=11||!CullenUtils.isNumeric(phone)) {
|
|
|
|
|
- userMapper.addUserLog(username,batchNo,"0",c.getChannel(),c.getRealName(),c.getPhone());
|
|
|
|
|
|
|
+ if (phone.length()!=11||!CullenUtils.isNumeric(phone)||"0".equals(userAttrType)) {
|
|
|
|
|
+ userMapper.addUserLog(username,batchNo,"0",c.getChannel(),c.getRealName(),c.getPhone(),userAttrType);
|
|
|
}else {
|
|
}else {
|
|
|
- addUser(new EnterpriseUserPo(getChannel(c.getChannel()), c.getRealName(), c.getPhone()));
|
|
|
|
|
- userMapper.addUserLog(username,batchNo,"1",c.getChannel(),c.getRealName(),c.getPhone());
|
|
|
|
|
|
|
+ addUser(new EnterpriseUserPo(getChannel(c.getChannel()), c.getRealName(), c.getPhone(),userAttrType));
|
|
|
|
|
+ userMapper.addUserLog(username,batchNo,"1",c.getChannel(),c.getRealName(),c.getPhone(),userAttrType);
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
@@ -208,6 +263,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
user.setStatus(1);
|
|
user.setStatus(1);
|
|
|
user.setLevel(1);
|
|
user.setLevel(1);
|
|
|
user.setLevelType(0);
|
|
user.setLevelType(0);
|
|
|
|
|
+ user.setUserAttrType(po.getUserAttrType());
|
|
|
user.setChannelId(po.getChannelId());
|
|
user.setChannelId(po.getChannelId());
|
|
|
user.setChannelId(po.getChannelId());
|
|
user.setChannelId(po.getChannelId());
|
|
|
user.setUserId(IdUtil.simpleUUID());
|
|
user.setUserId(IdUtil.simpleUUID());
|
|
@@ -221,6 +277,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
user.setRealName(po.getRealName());
|
|
user.setRealName(po.getRealName());
|
|
|
user.setChannelId(po.getChannelId());
|
|
user.setChannelId(po.getChannelId());
|
|
|
user.setUserId(userInfo.getUserId());
|
|
user.setUserId(userInfo.getUserId());
|
|
|
|
|
+ user.setUserAttrType(po.getUserAttrType());
|
|
|
userMapper.updateById(user);
|
|
userMapper.updateById(user);
|
|
|
}else {
|
|
}else {
|
|
|
if (userInfo.getChannelId().equals(po.getChannelId())){
|
|
if (userInfo.getChannelId().equals(po.getChannelId())){
|
|
@@ -232,6 +289,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
user.setRealName(po.getRealName());
|
|
user.setRealName(po.getRealName());
|
|
|
user.setChannelId(po.getChannelId());
|
|
user.setChannelId(po.getChannelId());
|
|
|
user.setUserId(userInfo.getUserId());
|
|
user.setUserId(userInfo.getUserId());
|
|
|
|
|
+ user.setUserAttrType(po.getUserAttrType());
|
|
|
userMapper.updateById(user);
|
|
userMapper.updateById(user);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -325,7 +383,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
"已过期积分", "已消耗积分"
|
|
"已过期积分", "已消耗积分"
|
|
|
};
|
|
};
|
|
|
// 创建合并单元格的表头
|
|
// 创建合并单元格的表头
|
|
|
- ExportUtils.createMergedHeader(sheet, headerStyle,"员工列表");
|
|
|
|
|
|
|
+ ExportUtils.createMergedHeader(sheet, headerStyle,"员工列表",7);
|
|
|
|
|
|
|
|
// 创建列标题行
|
|
// 创建列标题行
|
|
|
ExportUtils.createColumnHeaders(sheet, headerStyle,headers);
|
|
ExportUtils.createColumnHeaders(sheet, headerStyle,headers);
|
|
@@ -403,4 +461,22 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
// 已消耗积分
|
|
// 已消耗积分
|
|
|
ExportUtils.createCell(sheet,row, 7,0,0, orderRefundVo.getUsed(), numberStyle);
|
|
ExportUtils.createCell(sheet,row, 7,0,0, orderRefundVo.getUsed(), numberStyle);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ private String getUserAttrType(String userAttrName,List<SysDictData> sysDictDataList){
|
|
|
|
|
+ if (StringUtils.isNotEmpty(userAttrName)){
|
|
|
|
|
+ if (!sysDictDataList.isEmpty()){
|
|
|
|
|
+ for (SysDictData sysDictData : sysDictDataList) {
|
|
|
|
|
+ if (sysDictData.getDictLabel().equals(userAttrName)){
|
|
|
|
|
+ return sysDictData.getDictValue();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return "0";
|
|
|
|
|
+ }else if (userAttrName.equals("1")){
|
|
|
|
|
+ return userAttrName;
|
|
|
|
|
+ }else {
|
|
|
|
|
+ return "0";
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return "0";
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|