Browse Source

修改飞亚达订餐-增加支持批量修改用户的地址、账户类型数据

longmeizhen@avic-s.com 2 years ago
parent
commit
0f9325feab

+ 2 - 0
src/main/java/com/palmnest/service/dinner/manager/ConsumerManager.java

@@ -97,4 +97,6 @@ public interface ConsumerManager extends GenericManager<Consumer, Long> {
 	Map<String, List<ConsumerDto>> getConsByOrgId(String orgId, String time);
 
 	List<Map<String, Object>> findListForReport(Map<String, Object> paramets);
+
+	Map<String, Object> importUserAddress(InputStream ins, String orgId);
 }

+ 164 - 1
src/main/java/com/palmnest/service/dinner/manager/impl/ConsumerManagerImpl.java

@@ -4,6 +4,7 @@ import com.palmnest.application.bean.Page;
 import com.palmnest.application.core.util.RegularPattern;
 import com.palmnest.application.core.util.StringUtil;
 import com.palmnest.application.dto.ConsumerDto;
+import com.palmnest.application.dto.output.ElementDto;
 import com.palmnest.dao.ElementGroupDao;
 import com.palmnest.dao.dinner.*;
 import com.palmnest.dao.estateserve.AppUserDao;
@@ -11,6 +12,7 @@ import com.palmnest.dao.estateserve.VirtualArchDao;
 import com.palmnest.model.dinner.*;
 import com.palmnest.model.estateserve.AppUser;
 import com.palmnest.model.property.VirtualArchitecture;
+import com.palmnest.service.ElementGroupManager;
 import com.palmnest.service.dinner.manager.ConsumerManager;
 import com.palmnest.service.estateserve.AppUserManager;
 import com.palmnest.service.impl.GenericManagerImpl;
@@ -60,7 +62,7 @@ public class ConsumerManagerImpl extends GenericManagerImpl<Consumer, Long> impl
 	@Autowired
 	private AppUserDao            appUserDao;
 	@Autowired
-	private ElementGroupDao       elementGroupDao;
+	private ElementGroupManager elementGroupManager;
 	@Autowired
 	private AppUserManager        appUserManager;
 	@Autowired
@@ -466,4 +468,165 @@ public class ConsumerManagerImpl extends GenericManagerImpl<Consumer, Long> impl
 		return mapList;
 	}
 
+	private List<ElementDto>  getAddress(Integer orgId){
+		List<ElementDto> addressDtoList = elementGroupManager.getOrgElementGroupInfo(orgId, "dinnerAddress");
+		Collections.sort(addressDtoList, new Comparator<ElementDto>() {
+			@Override
+			public int compare(ElementDto o1, ElementDto o2) {
+				String name1 = o1.getId().toString();
+				String name2 = o2.getId().toString();
+				return name1.compareTo(name2);
+			}
+		});
+		return addressDtoList;
+	}
+
+	@Override
+	public Map<String, Object> importUserAddress(InputStream ins, String orgId) {
+		Map<String, Object> retMap    = new HashMap<String, Object>();
+		List<Object>        userList  = new ArrayList<Object>();
+		int                 bugCount  = 0;
+		StringBuffer        bugStr    = new StringBuffer("");
+		StringBuffer        countStr  = new StringBuffer("");
+		List<String>        mobiles   = new ArrayList<String>();
+		Sheet               sheet     = null;
+
+		try {
+			Workbook workbook = WorkbookFactory.create(ins);
+			sheet = workbook.getSheet("ConsumerAddress");
+		} catch (Exception e) {
+			bugCount++;
+			bugStr.append("模板格式有问题,请下载最新的模板");
+		}
+		try {
+			if (sheet == null) {
+				bugCount++;
+				bugStr.append("模板格式有问题,请下载最新的模板");
+			} else {
+				int rows = sheet.getLastRowNum();
+				//如果大于2000行数据
+				if (rows > 20000) {
+					bugCount++;
+					bugStr.append("数据量太大,不能大于2w行");
+				} else if (rows < 1) {
+					bugCount++;
+					bugStr.append("数据为空,请录入账单信息");
+				} else {
+
+					List<ElementDto> addressList = getAddress(Integer.parseInt(orgId));
+
+					for (int i = 1; i <= rows; i++) {
+						if (sheet.getRow(i) == null) {
+							continue;
+						}
+						if (sheet.getRow(i).getCell(0) == null) {
+							bugStr.append("第" + i + "行第1列数据有问题,请检查,问题:姓名必填,请导出系统模板匹配录入<br/>");
+							bugCount++;
+							continue;
+						}
+						sheet.getRow(i).getCell(0).setCellType(Cell.CELL_TYPE_STRING);
+						if (StringUtils.isBlank(sheet.getRow(i).getCell(0).getStringCellValue())) {
+							bugStr.append("第" + i + "行第1列数据有问题,请检查,问题:姓名必填,请导出系统模板匹配录入<br/>");
+							bugCount++;
+							continue;
+						}
+						String userName = sheet.getRow(i).getCell(0).getStringCellValue();
+
+
+						if (sheet.getRow(i).getCell(1) == null) {
+							bugStr.append("第" + i + "行第2列数据有问题,请检查,问题:手机号码必填,请导出系统模板匹配录入<br/>");
+							bugCount++;
+							continue;
+						}
+						sheet.getRow(i).getCell(1).setCellType(Cell.CELL_TYPE_STRING);
+						if (StringUtils.isBlank(sheet.getRow(i).getCell(1).getStringCellValue())) {
+							bugStr.append("第" + i + "行第2列数据有问题,请检查,问题:手机号码必填,请导出系统模板匹配录入<br/>");
+							bugCount++;
+							continue;
+						}
+						String  mobile = sheet.getRow(i).getCell(1).getStringCellValue();
+						boolean bool   = RegularPattern.isMobileNO(mobile);//验证手机格式是否正确
+						if (StringUtils.isNotEmpty(mobile) && !bool) {
+							bugStr.append("第" + i + "行第2列数据有问题,请检查,问题:" + mobile + "手机号码格式有问题,请导出系统模板匹配录入<br/>");
+							bugCount++;
+							continue;
+						}
+						AppUser cons = appUserDao.getAppUsersByPhoneAndOrg(mobile, orgId, "1");
+						if (cons != null && !"-1".equals(cons.getUserType())) {
+							countStr.append("第" + i + "行第2列数据有问题,请检查,问题:" + mobile + "该手机号码已存在账号,请导出系统模板匹配录入<br/>");
+							mobiles.add(mobile);
+						}
+
+						if (sheet.getRow(i).getCell(3) == null) {
+							bugStr.append("第" + i + "行第4列数据有问题,请检查,问题:送餐地址必填,请导出系统模板匹配录入<br/>");
+							bugCount++;
+							continue;
+						}
+						sheet.getRow(i).getCell(3).setCellType(Cell.CELL_TYPE_STRING);
+						if (StringUtils.isBlank(sheet.getRow(i).getCell(3).getStringCellValue())) {
+							bugStr.append("第" + i + "行第4列数据有问题,请检查,问题:送餐地址必填,请导出系统模板匹配录入<br/>");
+							bugCount++;
+							continue;
+						}
+						String address = sheet.getRow(i).getCell(3).getStringCellValue();
+						Long addressId = null;
+						//判断该地址在不在系统内
+						for(ElementDto el : addressList){
+							if(!address.equals(el.getItemname())){
+								continue;
+							}
+							addressId = el.getId();
+							break;
+						}
+						if(null == addressId){
+							bugStr.append("第" + i + "行第4列数据有问题,请检查,问题:送餐地址不在系统中,请导出系统模板匹配录入<br/>");
+							bugCount++;
+							continue;
+						}
+						if (sheet.getRow(i).getCell(4) == null) {
+							bugStr.append("第" + i + "行第5列数据有问题,请检查,问题:账户类型必填,请导出系统模板匹配录入<br/>");
+							bugCount++;
+							continue;
+						}
+						sheet.getRow(i).getCell(4).setCellType(Cell.CELL_TYPE_STRING);
+						if (StringUtils.isBlank(sheet.getRow(i).getCell(4).getStringCellValue())) {
+							bugStr.append("第" + i + "行第5列数据有问题,请检查,问题:账户类型必填,请导出系统模板匹配录入<br/>");
+							bugCount++;
+							continue;
+						}
+						String roleTypeStr = sheet.getRow(i).getCell(4).getStringCellValue();
+						Integer roleType = 2;
+						if("个人账号".equals(roleTypeStr)){
+							roleType=2;
+						}else if("管理员".equals(roleTypeStr)){
+							roleType=1;
+						}else if("可被代订".equals(roleTypeStr)){
+							roleType=3;
+						}
+
+						cons.setAddress(addressId.toString());
+						cons.setRoleType(roleType.toString());
+						userList.add(cons);
+					}
+				}
+			}
+			retMap.put("bugCount", bugCount);
+			retMap.put("countStr", countStr);
+			retMap.put("bugStr", bugStr.toString());
+			retMap.put("userList", userList);
+			retMap.put("okCount", userList.size());
+			return retMap;
+
+		} catch (Exception e) {
+			log.error(e.getMessage());
+			retMap.put("bugCount", bugCount);
+			retMap.put("countStr", countStr);
+			retMap.put("bugStr", bugStr.toString());
+			retMap.put("userList", userList);
+			retMap.put("okCount", userList.size());
+			e.printStackTrace();
+			return retMap;
+		}
+	}
+
 }

+ 3 - 0
src/main/java/com/palmnest/service/dinner/service/ConsumerUserService.java

@@ -182,4 +182,7 @@ public interface ConsumerUserService {
 
 	String setPath(String fileName);
 
+
+	AppResultDto importUserAddress(String orgId, InputStream ins, String userId);
+
 }

+ 30 - 0
src/main/java/com/palmnest/service/dinner/service/impl/ConsumerUserServiceImpl.java

@@ -1078,5 +1078,35 @@ public class ConsumerUserServiceImpl implements ConsumerUserService {
 		log.info("path:" + path);
 		return path;
 	}
+
+	@Override
+	public AppResultDto importUserAddress(String orgId, InputStream ins, String userId){
+		Map<String, Object> map      = consumerManager.importUserAddress(ins, orgId);
+		int                 bugCount = Integer.parseInt(map.get("bugCount").toString());
+		if (bugCount > 0) {//如果bug数量大于0,说明有异常,直接返回异常即可
+			return AppResultUtil.createErrorDto("100", map.get("bugStr").toString());
+		} else {//否则的话就将用户信息保存到数据库表中
+			if (map.containsKey("userList")) {
+				List<AppUser> list      = (List<AppUser>) map.get("userList");
+				try {
+					if (list != null && list.size() > 0) {
+						for(AppUser user : list){
+							if(null == user.getId()){
+								continue;
+							}
+							appUserManager.saveOrUpdateAppUser(user);
+						}
+					}
+					return AppResultUtil.createErrorDto("100", "导入的模板有误");
+				} catch (Exception e) {
+					log.error(e.getMessage());
+					e.printStackTrace();
+					return AppResultUtil.createErrorDto("100", "导入用户数据失败:DinnerUserServiceImpl/importUserAddress:" + e.getMessage());
+				}
+			} else {
+				return AppResultUtil.createErrorDto("100", "导入用户数据失败:获取不到userList");
+			}
+		}
+	}
 	
 }

+ 34 - 0
src/main/java/com/palmnest/webapp/controller/dinner/ConsumerUserController.java

@@ -609,4 +609,38 @@ public class ConsumerUserController extends BaseFormController {
 	}
 
 
+	/**
+	 * 导入用户信息
+	 *
+	 * @param excelFile
+	 * @param request
+	 * @param response
+	 * @return
+	 * @throws Exception
+	 */
+	@RequestMapping(value = "importUserAddress")
+	@ResponseBody
+	public AppResultDto importUserAddress(@RequestParam("excelFile") MultipartFile excelFile, HttpServletRequest request, HttpServletResponse response) throws Exception {
+		User   user   = (User) request.getSession().getAttribute("UserCache");
+		String userId = "";
+		if (user != null) {
+			userId = String.valueOf(user.getId());
+		}
+		String orgId  = request.getParameter("orgId");
+		String orgIds = getUserManageOrgIds(user);
+		if (StringUtils.isEmpty(orgId)) {
+			if (StringUtils.isNotEmpty(orgIds)) {
+				String[] orgs = orgIds.split(";");
+				if (orgs != null && orgs.length > 0) {
+					orgId = orgIds.split(";")[0];
+				}
+			} else {
+				return AppResultUtil.createErrorDto("100", "项目不允许为空");
+			}
+		}
+		AppResultDto dto = consumerUserService.importUserAddress(orgId, excelFile.getInputStream(), userId);
+		return dto;
+	}
+
+
 }

+ 38 - 0
src/main/java/com/palmnest/webapp/controller/dinner/wechat/WechatConsumerController.java

@@ -6,6 +6,7 @@ import com.palmnest.application.core.util.AppResultUtil;
 import com.palmnest.application.dto.input.ConsumerInputDto;
 import com.palmnest.application.dto.output.ElementDto;
 import com.palmnest.model.Element;
+import com.palmnest.model.User;
 import com.palmnest.model.dinner.Consumer;
 import com.palmnest.service.dinner.service.ConsumerUserService;
 import com.palmnest.service.estateserve.ScWxuserManager;
@@ -15,8 +16,12 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.multipart.MultipartFile;
 
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.List;
@@ -216,5 +221,38 @@ public class WechatConsumerController extends BaseFormController {
 		return AppResultUtil.createSuccesDto();
 	}
 
+	/**
+	 * 导入用户信息
+	 *
+	 * @param excelFile
+	 * @param request
+	 * @param response
+	 * @return
+	 * @throws Exception
+	 */
+	@RequestMapping(value = "importUserAddress")
+	@ResponseBody
+	public AppResultDto importUserAddress(@RequestParam("excelFile") MultipartFile excelFile, HttpServletRequest request, HttpServletResponse response) throws Exception {
+		User user   = (User) request.getSession().getAttribute("UserCache");
+		String userId = "";
+		if (user != null) {
+			userId = String.valueOf(user.getId());
+		}
+		String orgId  = request.getParameter("orgId");
+		String orgIds = getUserManageOrgIds(user);
+		if (StringUtils.isEmpty(orgId)) {
+			if (StringUtils.isNotEmpty(orgIds)) {
+				String[] orgs = orgIds.split(";");
+				if (orgs != null && orgs.length > 0) {
+					orgId = orgIds.split(";")[0];
+				}
+			} else {
+				return AppResultUtil.createErrorDto("100", "项目不允许为空");
+			}
+		}
+		AppResultDto dto = consumerUserService.importUserAddress(orgId, excelFile.getInputStream(), userId);
+		return dto;
+	}
+
 
 }