|
|
|
@ -14,21 +14,35 @@ import com.kiisoo.ic.store.entity.PoiStoreStaffVO;
|
|
|
|
|
import com.kiisoo.ic.store.mapper.PoiStoreDOMapper;
|
|
|
|
|
import com.kiisoo.ic.store.mapper.PoiStoreStaffDOMapper;
|
|
|
|
|
import com.kiisoo.ic.system.bean.AccountBean;
|
|
|
|
|
import com.kiisoo.ic.system.bean.ImportAccountErrorBean;
|
|
|
|
|
import com.kiisoo.ic.system.bean.PrivilageUserBean;
|
|
|
|
|
import com.kiisoo.ic.system.entity.PrivilageAccountDO;
|
|
|
|
|
import com.kiisoo.ic.system.entity.PrivilageRoleDO;
|
|
|
|
|
import com.kiisoo.ic.system.entity.PrivilageUserDO;
|
|
|
|
|
import com.kiisoo.ic.system.enums.AccountEnum;
|
|
|
|
|
import com.kiisoo.ic.system.mapper.PrivilageRoleDOMapper;
|
|
|
|
|
import com.kiisoo.ic.system.mapper.PrivilageUserDOMapper;
|
|
|
|
|
import com.kiisoo.ic.system.service.PrivilageAccountService;
|
|
|
|
|
import com.kiisoo.ic.system.service.PrivilageRoleService;
|
|
|
|
|
import com.kiisoo.ic.system.service.PrivilageUserRoleService;
|
|
|
|
|
import com.kiisoo.ic.system.service.PrivilageUserService;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import javax.management.relation.Role;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -55,6 +69,8 @@ public class PoiStoreStaffService {
|
|
|
|
|
private PrivilageUserRoleService privilageUserRoleService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private QrCodeService qrCodeService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private PrivilageRoleDOMapper privilageRoleDOMapper;
|
|
|
|
|
/**
|
|
|
|
|
* 根据条件查询导购信息
|
|
|
|
|
*
|
|
|
|
@ -174,4 +190,248 @@ public class PoiStoreStaffService {
|
|
|
|
|
return qrCodeService.getQrCode(qrCodeDO);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 批量上传推广人员
|
|
|
|
|
* @param files
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public List<ImportAccountErrorBean> uploadStaff(MultipartFile[] files) throws IOException, InvocationTargetException, IllegalAccessException {
|
|
|
|
|
//错误list
|
|
|
|
|
List<ImportAccountErrorBean> errorBeanList = new ArrayList<>();
|
|
|
|
|
//商品VOList
|
|
|
|
|
List<PoiStoreStaffVO> poiStoreStaffVOList = new ArrayList<>();
|
|
|
|
|
if (files == null || files.length == 0) {
|
|
|
|
|
ImportAccountErrorBean errorBean = new ImportAccountErrorBean();
|
|
|
|
|
errorBean.setError("文件上传异常");
|
|
|
|
|
errorBeanList.add(errorBean);
|
|
|
|
|
return errorBeanList;
|
|
|
|
|
}
|
|
|
|
|
for(MultipartFile file : files){
|
|
|
|
|
if (file.isEmpty()) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
String sourceName = file.getOriginalFilename();
|
|
|
|
|
InputStream fileInput = file.getInputStream();
|
|
|
|
|
Workbook book;
|
|
|
|
|
if (isExcel2007(sourceName)) {
|
|
|
|
|
book = new XSSFWorkbook(fileInput);
|
|
|
|
|
} else {
|
|
|
|
|
book = new HSSFWorkbook(fileInput);
|
|
|
|
|
}
|
|
|
|
|
// 第一个sheet
|
|
|
|
|
Sheet sheet = book.getSheetAt(0);
|
|
|
|
|
// 行数
|
|
|
|
|
int totalRows = sheet.getPhysicalNumberOfRows();
|
|
|
|
|
if(totalRows == 3){
|
|
|
|
|
ImportAccountErrorBean errorBean = new ImportAccountErrorBean();
|
|
|
|
|
errorBean.setError("文件内没有人员信息");
|
|
|
|
|
errorBeanList.add(errorBean);
|
|
|
|
|
return errorBeanList;
|
|
|
|
|
}
|
|
|
|
|
for (int r = 3; r < totalRows; r++) {
|
|
|
|
|
Row row = sheet.getRow(r);
|
|
|
|
|
if (row == null) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
//检查必填项为空,并插入goodsVOList
|
|
|
|
|
PoiStoreStaffVO poiStoreStaffVO = checkStaffExcelBlank(row, r, errorBeanList);
|
|
|
|
|
poiStoreStaffVOList.add(poiStoreStaffVO);
|
|
|
|
|
}
|
|
|
|
|
//检查重复项 查询条件
|
|
|
|
|
checkRepeat(poiStoreStaffVOList, errorBeanList);
|
|
|
|
|
|
|
|
|
|
//插表
|
|
|
|
|
if(errorBeanList.size() == 0){
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
errorBeanList.sort(Comparator.comparing(ImportAccountErrorBean::getRow));
|
|
|
|
|
}
|
|
|
|
|
return errorBeanList;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 检查项
|
|
|
|
|
* @param poiStoreStaffVOList 人员VOList
|
|
|
|
|
* @param errorBeanList 错误List
|
|
|
|
|
*/
|
|
|
|
|
public void checkRepeat(List<PoiStoreStaffVO> poiStoreStaffVOList, List<ImportAccountErrorBean> errorBeanList){
|
|
|
|
|
//表格内重复
|
|
|
|
|
for(int i=0;i<poiStoreStaffVOList.size();i++){
|
|
|
|
|
String staffCode = poiStoreStaffVOList.get(i).getStaffCode();
|
|
|
|
|
for(int j = i;j<poiStoreStaffVOList.size();j++){
|
|
|
|
|
if(j != i && poiStoreStaffVOList.get(j).getStaffCode().equals(staffCode)){
|
|
|
|
|
ImportAccountErrorBean errorBean = new ImportAccountErrorBean();
|
|
|
|
|
errorBean.setError("第" + (i + 1) +"行工号,表格内有重复");
|
|
|
|
|
errorBean.setRow(i + 1);
|
|
|
|
|
errorBeanList.add(errorBean);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//与数据库重复
|
|
|
|
|
AtomicInteger rowNum = new AtomicInteger(2);
|
|
|
|
|
poiStoreStaffVOList.forEach(staff -> {
|
|
|
|
|
//查询是否存在
|
|
|
|
|
QueryWrapper<PoiStoreStaff> wrapper = new QueryWrapper<>();
|
|
|
|
|
wrapper.eq("staffCode", staff.getStaffCode());
|
|
|
|
|
PoiStoreStaff poiStoreStaff = poiStoreStaffDOMapper.selectOne(wrapper);
|
|
|
|
|
if(poiStoreStaff != null){
|
|
|
|
|
ImportAccountErrorBean errorBean = new ImportAccountErrorBean();
|
|
|
|
|
errorBean.setError("第" + rowNum.get() +"行工号,与数据库内有重复");
|
|
|
|
|
errorBean.setRow(rowNum.get());
|
|
|
|
|
errorBeanList.add(errorBean);
|
|
|
|
|
}
|
|
|
|
|
//判断手机号
|
|
|
|
|
if(StringUtils.isNoneBlank(staff.getMobil())){
|
|
|
|
|
if(!isPhone(staff.getMobil())){
|
|
|
|
|
ImportAccountErrorBean errorBean = new ImportAccountErrorBean();
|
|
|
|
|
errorBean.setError("第" + rowNum.get() +"行手机号不正确");
|
|
|
|
|
errorBean.setRow(rowNum.get());
|
|
|
|
|
errorBeanList.add(errorBean);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//查询店铺
|
|
|
|
|
if(StringUtils.isNoneBlank(staff.getStoreName())&&StringUtils.isNoneBlank(staff.getStaffCode())){
|
|
|
|
|
QueryWrapper<PoiStore> wrapperStore = new QueryWrapper<>();
|
|
|
|
|
wrapperStore.eq("name",staff.getStoreName()).eq("code",staff.getStoreCode()).last("limit 1");
|
|
|
|
|
PoiStore shop = poiStoreDOMapper.selectOne(wrapperStore);
|
|
|
|
|
if(shop!=null){
|
|
|
|
|
staff.setStoreId(shop.getId());
|
|
|
|
|
}else{
|
|
|
|
|
ImportAccountErrorBean errorBean = new ImportAccountErrorBean();
|
|
|
|
|
errorBean.setError("第" + rowNum.get() +"行店铺不存在");
|
|
|
|
|
errorBean.setRow(rowNum.get());
|
|
|
|
|
errorBeanList.add(errorBean);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//查询角色
|
|
|
|
|
if(StringUtils.isNoneBlank(staff.getRole())){
|
|
|
|
|
QueryWrapper<PrivilageRoleDO> wrapperRole = new QueryWrapper<>();
|
|
|
|
|
wrapperRole.eq("name",staff.getRole()).last("limit 1");
|
|
|
|
|
PrivilageRoleDO role = privilageRoleDOMapper.selectOne(wrapperRole);
|
|
|
|
|
if(role!=null){
|
|
|
|
|
staff.setRoleId(role.getId());
|
|
|
|
|
}else{
|
|
|
|
|
ImportAccountErrorBean errorBean = new ImportAccountErrorBean();
|
|
|
|
|
errorBean.setError("第" + rowNum.get() +"行角色不存在");
|
|
|
|
|
errorBean.setRow(rowNum.get());
|
|
|
|
|
errorBeanList.add(errorBean);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
rowNum.incrementAndGet();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 检查excel字段为空
|
|
|
|
|
* @param row 行
|
|
|
|
|
* @param r 行数
|
|
|
|
|
* @param errorBeanList 错误List
|
|
|
|
|
* @return
|
|
|
|
|
* @throws InvocationTargetException 异常
|
|
|
|
|
* @throws IllegalAccessException 异常
|
|
|
|
|
*/
|
|
|
|
|
private PoiStoreStaffVO checkStaffExcelBlank(Row row, int r, List<ImportAccountErrorBean> errorBeanList) throws InvocationTargetException, IllegalAccessException {
|
|
|
|
|
PoiStoreStaffVO poiStoreStaffVO = new PoiStoreStaffVO();
|
|
|
|
|
//所有列(跟下面的属性对上)
|
|
|
|
|
String cellNames = "推广人员姓名,工号,手机号,所属店铺,店铺编号,角色";
|
|
|
|
|
List<String> paramList = Arrays.asList("name","staffCode","mobil","storeName","storeCode","role");
|
|
|
|
|
String[] cellNameArr = cellNames.split(",");
|
|
|
|
|
//必填列
|
|
|
|
|
String mustCellNames = "推广人员姓名,工号,所属店铺,店铺编号,角色";
|
|
|
|
|
Map<String, String> mustCellMap = Arrays.stream(mustCellNames.split(",")).collect(Collectors.toMap(name -> name, name -> name));
|
|
|
|
|
//必填但空List
|
|
|
|
|
List<String> blankNameList = new ArrayList<>();
|
|
|
|
|
for(int i=0;i<cellNameArr.length;i++){
|
|
|
|
|
String cellValue = getCellValue(row.getCell(i));
|
|
|
|
|
//属性值放入VO
|
|
|
|
|
org.apache.commons.beanutils.BeanUtils.setProperty(poiStoreStaffVO, paramList.get(i), cellValue);
|
|
|
|
|
//必填为空
|
|
|
|
|
if(StringUtils.isBlank(cellValue) && mustCellMap.get(cellNameArr[i]) != null){
|
|
|
|
|
blankNameList.add(cellNameArr[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//必填但空string
|
|
|
|
|
String blankNames = blankNameList.stream().collect(Collectors.joining(",","",""));
|
|
|
|
|
if(StringUtils.isNotBlank(blankNames)){
|
|
|
|
|
ImportAccountErrorBean errorBean = new ImportAccountErrorBean();
|
|
|
|
|
errorBean.setError("第" + (r + 1) + "行:"+blankNames+"不能为空,请输入完整重新导入!");
|
|
|
|
|
errorBean.setRow(r + 1);
|
|
|
|
|
errorBeanList.add(errorBean);
|
|
|
|
|
}
|
|
|
|
|
return poiStoreStaffVO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 手机号判断
|
|
|
|
|
* @param phone
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public boolean isPhone(String phone){
|
|
|
|
|
String reg = "^1([358][0-9]|4[579]|66|7[0135678]|9[89])[0-9]{8}$";
|
|
|
|
|
return reg.matches(phone);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 读取cell单元格的值,如果为日期格式,进行转换
|
|
|
|
|
*
|
|
|
|
|
* @param cell 单元格
|
|
|
|
|
* @return 单元格中的值(字符串形式)
|
|
|
|
|
*/
|
|
|
|
|
private String getCellValue(Cell cell) {
|
|
|
|
|
if (cell == null) {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cell.getCellTypeEnum() == CellType.STRING) {
|
|
|
|
|
return String.valueOf(cell.getRichStringCellValue());
|
|
|
|
|
} else if (cell.getCellTypeEnum() == CellType.BOOLEAN) {
|
|
|
|
|
return String.valueOf(cell.getBooleanCellValue());
|
|
|
|
|
} else if (cell.getCellTypeEnum() == CellType.FORMULA) {
|
|
|
|
|
return cell.getCellFormula();
|
|
|
|
|
} else if (cell.getCellTypeEnum() == CellType.NUMERIC) {
|
|
|
|
|
short format = cell.getCellStyle().getDataFormat();
|
|
|
|
|
|
|
|
|
|
SimpleDateFormat sdf;
|
|
|
|
|
if (format == 14 || format == 31 || format == 57 || format == 58
|
|
|
|
|
|| (176 <= format && format <= 178) || (182 <= format && format <= 196)
|
|
|
|
|
|| (210 <= format && format <= 213) || (208 == format)) {
|
|
|
|
|
// 日期
|
|
|
|
|
sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
} else if (format == 20 || format == 32 || 200 <= format && format <= 209) {
|
|
|
|
|
// 时间
|
|
|
|
|
sdf = new SimpleDateFormat("HH:mm");
|
|
|
|
|
} else {
|
|
|
|
|
// 不是日期格式
|
|
|
|
|
return String.valueOf(cell.getNumericCellValue());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double value = cell.getNumericCellValue();
|
|
|
|
|
Date date = org.apache.poi.ss.usermodel.DateUtil.getJavaDate(value);
|
|
|
|
|
if (date == null) {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
String result;
|
|
|
|
|
try {
|
|
|
|
|
result = sdf.format(date);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 描述:是否是2007的excel,返回true是2007
|
|
|
|
|
*/
|
|
|
|
|
private static boolean isExcel2007(String filePath) {
|
|
|
|
|
return filePath.matches("^.+\\.(?i)(xlsx)$");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|