调整代码
This commit is contained in:
parent
9b4fa7c3a7
commit
7728c5365d
@ -1,6 +1,5 @@
|
|||||||
package com.cm.systemcity.controller.apis.communityboss;
|
package com.cm.systemcity.controller.apis.communityboss;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import com.cm.common.base.AbstractController;
|
import com.cm.common.base.AbstractController;
|
||||||
import com.cm.common.constants.ISystemConstant;
|
import com.cm.common.constants.ISystemConstant;
|
||||||
import com.cm.common.exception.*;
|
import com.cm.common.exception.*;
|
||||||
@ -11,16 +10,12 @@ import com.cm.common.result.SuccessResultData;
|
|||||||
import com.cm.common.result.SuccessResultList;
|
import com.cm.common.result.SuccessResultList;
|
||||||
import com.cm.systemcity.pojo.dtos.community.CommunityDTO;
|
import com.cm.systemcity.pojo.dtos.community.CommunityDTO;
|
||||||
import com.cm.systemcity.pojo.dtos.communityboss.CommunityBossDTO;
|
import com.cm.systemcity.pojo.dtos.communityboss.CommunityBossDTO;
|
||||||
import com.cm.systemcity.pojo.vos.communityboss.CommunityBossExcelVO;
|
|
||||||
import com.cm.systemcity.pojo.vos.communityboss.CommunityBossVO;
|
import com.cm.systemcity.pojo.vos.communityboss.CommunityBossVO;
|
||||||
import com.cm.systemcity.service.communityboss.ICommunityBossService;
|
import com.cm.systemcity.service.communityboss.ICommunityBossService;
|
||||||
import com.cm.systemcity.util.ExcelUtil;
|
|
||||||
import io.swagger.annotations.*;
|
import io.swagger.annotations.*;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.commons.lang3.math.NumberUtils;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -39,24 +34,6 @@ public class CommunityBossController extends AbstractController {
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ICommunityBossService communityBossService;
|
private ICommunityBossService communityBossService;
|
||||||
@Autowired
|
|
||||||
private ExcelUtil excelUtil;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@PostMapping(value = "/uploadExcel", consumes = "multipart/*", headers = "content-type=multipart/form-data")
|
|
||||||
@ApiOperation(value = "片长信息Excel导入数据", notes = "片长信息Excel导入数据", httpMethod = "POST")
|
|
||||||
@ApiResponses(value = {
|
|
||||||
@ApiResponse(code = 200, message = "上传成功!" ,response = SuccessResult.class),
|
|
||||||
@ApiResponse(code = 500, message = "上传失败!" ,response = ErrorResult.class)
|
|
||||||
})
|
|
||||||
public SuccessResultData<JSONObject> uploadExcel(@ApiParam(value = "用户信息Excel导入数据", required = true) MultipartFile file) throws Exception {
|
|
||||||
List<CommunityBossExcelVO> dtoList = excelUtil.readExcelFileToDTO(file, CommunityBossExcelVO.class);
|
|
||||||
return communityBossService.saveExcelCommunutyBoos(dtoList);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ApiOperation(value = "片长新增", notes = "片长新增接口")
|
@ApiOperation(value = "片长新增", notes = "片长新增接口")
|
||||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||||
|
@ -31,16 +31,6 @@ public interface ICommunityBossService {
|
|||||||
int COMMUNITY_BOSS_LEVEL_2 = 2;
|
int COMMUNITY_BOSS_LEVEL_2 = 2;
|
||||||
int COMMUNITY_BOSS_LEVEL_3 = 3;
|
int COMMUNITY_BOSS_LEVEL_3 = 3;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 导入EXCEL
|
|
||||||
* @param excelVOList
|
|
||||||
* @return
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
SuccessResultData<JSONObject> saveExcelCommunutyBoos(List<CommunityBossExcelVO> excelVOList) throws Exception;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增片长
|
* 新增片长
|
||||||
*
|
*
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.cm.systemcity.service.communityboss.impl;
|
package com.cm.systemcity.service.communityboss.impl;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import com.cm.common.base.AbstractService;
|
import com.cm.common.base.AbstractService;
|
||||||
import com.cm.common.constants.ISystemConstant;
|
import com.cm.common.constants.ISystemConstant;
|
||||||
import com.cm.common.exception.RemoveException;
|
import com.cm.common.exception.RemoveException;
|
||||||
@ -8,28 +7,22 @@ import com.cm.common.exception.SaveException;
|
|||||||
import com.cm.common.exception.SearchException;
|
import com.cm.common.exception.SearchException;
|
||||||
import com.cm.common.exception.UpdateException;
|
import com.cm.common.exception.UpdateException;
|
||||||
import com.cm.common.plugin.oauth.service.user.IUserService;
|
import com.cm.common.plugin.oauth.service.user.IUserService;
|
||||||
import com.cm.common.plugin.pojo.bos.UserResourceBO;
|
|
||||||
import com.cm.common.plugin.service.file.IFileService;
|
|
||||||
import com.cm.common.pojo.ListPage;
|
import com.cm.common.pojo.ListPage;
|
||||||
import com.cm.common.result.SuccessResult;
|
import com.cm.common.result.SuccessResult;
|
||||||
import com.cm.common.result.SuccessResultData;
|
import com.cm.common.result.SuccessResultData;
|
||||||
import com.cm.common.result.SuccessResultList;
|
import com.cm.common.result.SuccessResultList;
|
||||||
import com.cm.common.token.app.AppTokenManager;
|
import com.cm.common.token.app.AppTokenManager;
|
||||||
import com.cm.common.utils.UUIDUtil;
|
|
||||||
import com.cm.systemcity.dao.communityboss.ICommunityBossDao;
|
import com.cm.systemcity.dao.communityboss.ICommunityBossDao;
|
||||||
import com.cm.systemcity.pojo.dtos.citybuilding.CityBuildingDTO;
|
import com.cm.systemcity.pojo.dtos.citybuilding.CityBuildingDTO;
|
||||||
import com.cm.systemcity.pojo.dtos.citydistrict.CityDistrictDTO;
|
import com.cm.systemcity.pojo.dtos.citydistrict.CityDistrictDTO;
|
||||||
import com.cm.systemcity.pojo.dtos.community.CommunityDTO;
|
import com.cm.systemcity.pojo.dtos.community.CommunityDTO;
|
||||||
import com.cm.systemcity.pojo.dtos.communityboss.CommunityBossAreaDTO;
|
import com.cm.systemcity.pojo.dtos.communityboss.CommunityBossAreaDTO;
|
||||||
import com.cm.systemcity.pojo.dtos.communityboss.CommunityBossDTO;
|
import com.cm.systemcity.pojo.dtos.communityboss.CommunityBossDTO;
|
||||||
import com.cm.systemcity.pojo.dtos.dict.DictDTO;
|
|
||||||
import com.cm.systemcity.pojo.vos.communityboss.CommunityBossExcelVO;
|
|
||||||
import com.cm.systemcity.service.citybuilding.ICityBuildingService;
|
import com.cm.systemcity.service.citybuilding.ICityBuildingService;
|
||||||
import com.cm.systemcity.service.citydistrict.ICityDistrictService;
|
import com.cm.systemcity.service.citydistrict.ICityDistrictService;
|
||||||
import com.cm.systemcity.service.community.ICommunityService;
|
import com.cm.systemcity.service.community.ICommunityService;
|
||||||
import com.cm.systemcity.service.communityboss.ICommunityBossService;
|
import com.cm.systemcity.service.communityboss.ICommunityBossService;
|
||||||
import com.cm.systemcity.service.dict.IDictService;
|
import com.cm.systemcity.service.dict.IDictService;
|
||||||
import com.cm.systemcity.util.ExcelUtil;
|
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
import com.github.pagehelper.PageInfo;
|
import com.github.pagehelper.PageInfo;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
@ -61,171 +54,12 @@ public class CommunityBossServiceImpl extends AbstractService implements ICommun
|
|||||||
@Autowired
|
@Autowired
|
||||||
private ICityBuildingService cityBuildingService;
|
private ICityBuildingService cityBuildingService;
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ExcelUtil excelUtil;
|
|
||||||
private static final String CITY_DICT_ID = "9d179f05-3ea0-48f7-853c-d3b7124b791c";
|
private static final String CITY_DICT_ID = "9d179f05-3ea0-48f7-853c-d3b7124b791c";
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 导入EXCEL
|
|
||||||
* @param excelVOList
|
|
||||||
* @return
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public SuccessResultData<JSONObject> saveExcelCommunutyBoos(List<CommunityBossExcelVO> excelVOList) throws Exception{
|
|
||||||
List<Map<String,Object>> errorList = new ArrayList<>();
|
|
||||||
List<String> usernameList = new ArrayList<String>();
|
|
||||||
for (CommunityBossExcelVO vo : excelVOList) {
|
|
||||||
if(StringUtils.isBlank(vo.getNowLevel().toString())){
|
|
||||||
errorList.add(excelUtil.setExportParams(vo.getNowName(),"等级为空"));
|
|
||||||
excelVOList.remove(vo);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if(StringUtils.isBlank(vo.getAreaName())){
|
|
||||||
errorList.add(excelUtil.setExportParams(vo.getNowName(),"办事处或街镇为空"));
|
|
||||||
excelVOList.remove(vo);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if(StringUtils.isBlank(vo.getNowUserName())){
|
|
||||||
errorList.add(excelUtil.setExportParams(vo.getNowName(),"账号为空"));
|
|
||||||
excelVOList.remove(vo);
|
|
||||||
continue;
|
|
||||||
}else{
|
|
||||||
usernameList.add(vo.getNowUserName());
|
|
||||||
}
|
|
||||||
if(vo.getNowLevel() > 1){
|
|
||||||
if(StringUtils.isBlank(vo.getCommunityName())){
|
|
||||||
errorList.add(excelUtil.setExportParams(vo.getNowName(),"级别大于一级时所在社区不能为空"));
|
|
||||||
excelVOList.remove(vo);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if(StringUtils.isBlank(vo.getUpUserName())){
|
|
||||||
errorList.add(excelUtil.setExportParams(vo.getNowName(),"级别大于一级时上级领导账号不能为空"));
|
|
||||||
excelVOList.remove(vo);
|
|
||||||
continue;
|
|
||||||
}else{
|
|
||||||
usernameList.add(vo.getUpUserName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 数据去重
|
|
||||||
Set set = new HashSet();
|
|
||||||
set.addAll(usernameList);
|
|
||||||
usernameList.clear();
|
|
||||||
usernameList.addAll(set);
|
|
||||||
|
|
||||||
List<UserResourceBO> UserResourceBO = userService.listUserResourceByUsernames(usernameList);
|
|
||||||
|
|
||||||
f1:
|
|
||||||
for (CommunityBossExcelVO vo : excelVOList) {
|
|
||||||
Map<String, Object> params = new HashMap<>();
|
|
||||||
for (UserResourceBO userResourceBO : UserResourceBO) {
|
|
||||||
if (vo.getNowUserName().equals(userResourceBO.getUserUsername())){
|
|
||||||
params.put("communityBossId",userResourceBO.getUserId());
|
|
||||||
int count = communityBossDao.countCommunityBoss(params);
|
|
||||||
if (count > 0) {
|
|
||||||
errorList.add(excelUtil.setExportParams(vo.getNowName(),"该片长已存在"));
|
|
||||||
//片长以存在
|
|
||||||
continue f1;
|
|
||||||
}
|
|
||||||
params.put("communityBossUsername",userResourceBO.getUserUsername());
|
|
||||||
params.put("communityBossName",userResourceBO.getUserName());
|
|
||||||
}
|
|
||||||
if (vo.getUpUserName().equals(userResourceBO.getUserUsername())){
|
|
||||||
params.put("communityBossParentId",userResourceBO.getUserId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(params.get("communityBossId") == null){
|
|
||||||
errorList.add(excelUtil.setExportParams(vo.getNowName(),"人员信息不存在"));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
DictDTO dictDTO = dictService.getDictByNameAndParentId(CITY_DICT_ID,vo.getAreaName());
|
|
||||||
if(dictDTO == null){
|
|
||||||
errorList.add(excelUtil.setExportParams(vo.getNowName(),"办事处或者街镇不存在"));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if(params.get("communityBossParentId") == null){
|
|
||||||
errorList.add(excelUtil.setExportParams(vo.getNowName(),"领导信息不存在"));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
params.put("areaId",dictDTO.getDictId());
|
|
||||||
params.put("areaName",dictDTO.getDictName());
|
|
||||||
params.put("communityBossLevel",vo.getNowLevel());
|
|
||||||
setSaveInfo(params);
|
|
||||||
communityBossDao.saveCommunityBoss(params);
|
|
||||||
if (!StringUtils.isBlank(vo.getCommunityName())){
|
|
||||||
LOG.debug("绑定片长和社区关系");
|
|
||||||
String[] cns = vo.getCommunityName().split(",");
|
|
||||||
for (String cn : cns) {
|
|
||||||
Map<String,Object> p1 = new HashMap<>();
|
|
||||||
p1.put("communityName",cn);
|
|
||||||
CommunityDTO cd = communityService.getCommunity(p1);
|
|
||||||
if (cd == null){
|
|
||||||
errorList.add(excelUtil.setExportParams(vo.getNowName(),"社区不存在绑定社区失败"));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
String[] communityIds = cd.getCommunityId().split(",");
|
|
||||||
String communityBossId = params.get("communityBossId").toString();
|
|
||||||
saveCommunityBossCommunity(communityBossId, communityIds);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!StringUtils.isBlank(vo.getDistrictName())){
|
|
||||||
LOG.debug("绑定片长和小区关系");
|
|
||||||
String[] dns = vo.getDistrictName().split(",");
|
|
||||||
for (String dn : dns) {
|
|
||||||
CityDistrictDTO cdd = cityDistrictService.getCityDistrictByName(dn);
|
|
||||||
if(cdd == null){
|
|
||||||
errorList.add(excelUtil.setExportParams(vo.getNowName(),"小区不存在绑定小区失败"));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
String[] districtIds = cdd.getCityDistrictId().split(",");
|
|
||||||
String communityBossId = params.get("communityBossId").toString();
|
|
||||||
saveCommunityBossDistrict(communityBossId, districtIds);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!StringUtils.isBlank(vo.getBuildingName())){
|
|
||||||
LOG.debug("绑定片长和楼宇关系");
|
|
||||||
String[] bns = vo.getBuildingName().split(",");
|
|
||||||
for (String bn : bns) {
|
|
||||||
CityBuildingDTO cbd = cityBuildingService.getCityBuildingByName(bn);
|
|
||||||
if (cbd == null) {
|
|
||||||
errorList.add(excelUtil.setExportParams(vo.getNowName(),"楼宇不存在绑定楼宇失败"));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
String[] buildingIds = cbd.getBuildingName().split(",");
|
|
||||||
String communityBossId = params.get("communityBossId").toString();
|
|
||||||
saveCommunityBossBuilding(communityBossId, buildingIds);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String excelFileId = excelUtil.export(errorList);
|
|
||||||
|
|
||||||
JSONObject json = new JSONObject();
|
|
||||||
json.put("code","200");
|
|
||||||
json.put("msg","导入成功");
|
|
||||||
json.put("excelFileId",excelFileId);
|
|
||||||
return new SuccessResultData<>(json);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SuccessResult saveCommunityBoss(Map<String, Object> params) throws SaveException, SearchException {
|
public SuccessResult saveCommunityBoss(Map<String, Object> params) throws SaveException, SearchException {
|
||||||
Map<String, Object> communityBossParams = new HashMap<>();
|
Map<String, Object> communityBossParams = new HashMap<>();
|
||||||
communityBossParams.put("communityBossId", params.get("communityBossId").toString());
|
communityBossParams.put("communityBossId", params.get("communityBossId").toString());
|
||||||
int count = communityBossDao.countCommunityBoss(communityBossParams);
|
|
||||||
if (count > 0) {
|
|
||||||
throw new SearchException("该人员已是片长,请重新选择");
|
|
||||||
}
|
|
||||||
setSaveInfo(params);
|
setSaveInfo(params);
|
||||||
communityBossDao.saveCommunityBoss(params);
|
communityBossDao.saveCommunityBoss(params);
|
||||||
LOG.debug("绑定片长和社区关系");
|
LOG.debug("绑定片长和社区关系");
|
||||||
|
@ -1,248 +0,0 @@
|
|||||||
package com.cm.systemcity.util;
|
|
||||||
|
|
||||||
import com.cm.common.plugin.service.file.IFileService;
|
|
||||||
import com.cm.common.utils.DateUtil;
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
||||||
import org.apache.poi.ss.usermodel.*;
|
|
||||||
import org.apache.poi.xssf.usermodel.XSSFRow;
|
|
||||||
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|
||||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.lang.management.ManagementFactory;
|
|
||||||
import java.lang.management.MemoryUsage;
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.text.DecimalFormat;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* EXCEL工具
|
|
||||||
* @version 1.0
|
|
||||||
* @author LY
|
|
||||||
* @date 2021/3/10 16:48
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Component
|
|
||||||
public class ExcelUtil {
|
|
||||||
public static final String XLS = ".xls";
|
|
||||||
public static final String XLSX = ".xlsx";
|
|
||||||
|
|
||||||
@Value("${file.uploadPath}")
|
|
||||||
private String uploadUrl;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private IFileService fileService;
|
|
||||||
/**
|
|
||||||
* 导入EXCEL
|
|
||||||
* @param file
|
|
||||||
* @param clazz
|
|
||||||
* @param <T>
|
|
||||||
* @return
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
public <T> List<T> readExcelFileToDTO(MultipartFile file, Class<T> clazz) throws IOException {
|
|
||||||
return readExcelFileToDTO(file, clazz, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T> List<T> readExcelFileToDTO(MultipartFile file, Class<T> clazz, Integer sheetId) throws IOException {
|
|
||||||
//将文件转成workbook类型
|
|
||||||
Workbook workbook = buildWorkbook(file);
|
|
||||||
//第一个表
|
|
||||||
return readSheetToDTO(workbook.getSheetAt(sheetId), clazz);
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T> List<T> readSheetToDTO(Sheet sheet, Class<T> clazz) throws IOException {
|
|
||||||
List<T> result = new ArrayList<>();
|
|
||||||
List<Map<String, String>> sheetValue = changeSheetToMapList(sheet);
|
|
||||||
for (Map<String, String> valueMap : sheetValue) {
|
|
||||||
T dto = buildDTOByClass(clazz, valueMap);
|
|
||||||
if (dto != null) {
|
|
||||||
result.add(dto);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//类型转换
|
|
||||||
private Workbook buildWorkbook(MultipartFile file) throws IOException {
|
|
||||||
String filename = file.getOriginalFilename();
|
|
||||||
if (filename.endsWith(XLS)) {
|
|
||||||
return new HSSFWorkbook(file.getInputStream());
|
|
||||||
} else if (filename.endsWith(XLSX)) {
|
|
||||||
return new XSSFWorkbook(file.getInputStream());
|
|
||||||
} else {
|
|
||||||
throw new IOException("unknown file format: " + filename);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<Map<String, String>> changeSheetToMapList(Sheet sheet) {
|
|
||||||
List<Map<String, String>> result = new ArrayList<>();
|
|
||||||
int rowNumber = sheet.getPhysicalNumberOfRows();
|
|
||||||
String[] titles = getSheetRowValues(sheet.getRow(0)); // 第一行作为表头
|
|
||||||
for (int i = 1; i < rowNumber; i++) {
|
|
||||||
String[] values = getSheetRowValues(sheet.getRow(i));
|
|
||||||
Map<String, String> valueMap = new HashMap<>();
|
|
||||||
for (int j = 0; j < titles.length; j++) {
|
|
||||||
valueMap.put(titles[j], values[j]);
|
|
||||||
}
|
|
||||||
result.add(valueMap);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private <T> T buildDTOByClass(Class<T> clazz, Map<String, String> valueMap) {
|
|
||||||
try {
|
|
||||||
T dto = clazz.newInstance();
|
|
||||||
for (Field field : clazz.getDeclaredFields()) {
|
|
||||||
ApiModelProperty desc = field.getAnnotation(ApiModelProperty.class);
|
|
||||||
String value = valueMap.get(desc.value());
|
|
||||||
if (value != null) {
|
|
||||||
if(field.getType().getName().equalsIgnoreCase("java.lang.Integer")) {
|
|
||||||
Method method = clazz.getMethod(getSetMethodName(field.getName()), field.getType());
|
|
||||||
//Integer i = Integer.parseInt(value.substring(0,value.indexOf(".")));
|
|
||||||
Integer i = Integer.parseInt(value);
|
|
||||||
method.invoke(dto, i);
|
|
||||||
}else{
|
|
||||||
Method method = clazz.getMethod(getSetMethodName(field.getName()), field.getType());
|
|
||||||
method.invoke(dto, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return dto ;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.getStackTrace();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getSetMethodName(String name) {
|
|
||||||
String firstChar = name.substring(0, 1);
|
|
||||||
return "set" + firstChar.toUpperCase() + name.substring(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String[] getSheetRowValues(Row row) {
|
|
||||||
if (row == null) {
|
|
||||||
return new String[]{};
|
|
||||||
} else {
|
|
||||||
int cellNumber = row.getLastCellNum();
|
|
||||||
List<String> cellValueList = new ArrayList<>();
|
|
||||||
for (int i = 0; i < cellNumber; i++) {
|
|
||||||
cellValueList.add(getValueOnCell(row.getCell(i)));
|
|
||||||
}
|
|
||||||
return cellValueList.toArray(new String[0]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getValueOnCell(Cell cell) {
|
|
||||||
if (cell == null) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
switch (cell.getCellTypeEnum()) {
|
|
||||||
case STRING: return cell.getStringCellValue();
|
|
||||||
//case NUMERIC: return String.format("%.2f", cell.getNumericCellValue());
|
|
||||||
case NUMERIC:
|
|
||||||
DecimalFormat df = new DecimalFormat("0");
|
|
||||||
return String.valueOf(df.format(cell.getNumericCellValue()));
|
|
||||||
case BOOLEAN: return cell.getBooleanCellValue() ? "true" : "false";
|
|
||||||
case FORMULA:
|
|
||||||
try {
|
|
||||||
return cell.getStringCellValue();
|
|
||||||
} catch (Exception e) {
|
|
||||||
// return String.format("%.2f", cell.getNumericCellValue());
|
|
||||||
return String.valueOf(cell.getNumericCellValue());
|
|
||||||
}
|
|
||||||
case BLANK:
|
|
||||||
return "";
|
|
||||||
default: return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public String export(List<Map<String,Object>> data) throws Exception{
|
|
||||||
String[] title = {"姓名", "原因"};
|
|
||||||
// 创建工作薄
|
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
|
||||||
// 创建工作表
|
|
||||||
XSSFSheet sheet = workbook.createSheet("sheet1");
|
|
||||||
XSSFRow sheetRow = sheet.createRow(0);
|
|
||||||
|
|
||||||
for (int i = 0; i < data.size(); i++) {
|
|
||||||
sheetRow = sheet.createRow(i+1);
|
|
||||||
sheetRow.createCell(0).setCellValue( data.get(i).get("name").toString());
|
|
||||||
sheetRow.createCell(1).setCellValue( data.get(i).get("option").toString());
|
|
||||||
}
|
|
||||||
String filePath = uploadUrl;
|
|
||||||
|
|
||||||
String fileName = DateUtil.getSdfTimes()+".xls";
|
|
||||||
File file = new File(filePath+"\\"+fileName);
|
|
||||||
Map<String,Object> fileIdMap = new HashMap<>();
|
|
||||||
fileService.saveUploadErrorExcelFileInfo(fileName,filePath,file.length(),fileIdMap);
|
|
||||||
OutputStream out = new FileOutputStream(file);
|
|
||||||
workbook.write(out);
|
|
||||||
workbook.close();
|
|
||||||
out.close();
|
|
||||||
return fileIdMap.get("fileId").toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public Map<String,Object> setExportParams(String name,String option){
|
|
||||||
Map<String,Object> params = new HashMap<>();
|
|
||||||
params.put("name",name);
|
|
||||||
params.put("option",option);
|
|
||||||
return params;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
String[] data = {"73982", "1", "NH", "1", "2018122510", "2", "0", "0", "0", "12233", "0", "楼层组件优化", "0"};
|
|
||||||
|
|
||||||
MemoryUsage startMemory = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
|
|
||||||
|
|
||||||
// 创建工作薄
|
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
|
||||||
// 创建工作表
|
|
||||||
XSSFSheet sheet = workbook.createSheet("sheet1");
|
|
||||||
|
|
||||||
//设置数据
|
|
||||||
for (int row = 0; row < 3; row++) {
|
|
||||||
XSSFRow sheetRow = sheet.createRow(row);
|
|
||||||
for (int column = 0; column < data.length; column++) {
|
|
||||||
sheetRow.createCell(column).setCellValue(data[column]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//写入文件
|
|
||||||
try {
|
|
||||||
workbook.write(new FileOutputStream(new File("111")));
|
|
||||||
workbook.close();
|
|
||||||
} catch (Exception ex) {
|
|
||||||
System.out.println(ex.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -24,7 +24,7 @@ spring:
|
|||||||
max-request-size: 1GB
|
max-request-size: 1GB
|
||||||
datasource:
|
datasource:
|
||||||
druid:
|
druid:
|
||||||
url: jdbc:mysql://49.233.36.36:6688/db_cloud?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&autoReconnect=true&failOverReadOnly=false&useSSL=false
|
url: jdbc:mysql://49.233.36.36:6688/db_cloud_city?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&autoReconnect=true&failOverReadOnly=false&useSSL=false
|
||||||
db-type: mysql
|
db-type: mysql
|
||||||
driver-class-name: com.mysql.jdbc.Driver
|
driver-class-name: com.mysql.jdbc.Driver
|
||||||
username: wanggeng
|
username: wanggeng
|
||||||
|
@ -1 +0,0 @@
|
|||||||
|
|
@ -2,7 +2,7 @@
|
|||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
<mapper namespace="com.cm.systemcity.dao.communityboss.ICommunityBossDao">
|
<mapper namespace="com.cm.systemcity.dao.communityboss.ICommunityBossDao">
|
||||||
|
|
||||||
<cache/>
|
<!-- <cache/>-->
|
||||||
|
|
||||||
<resultMap id="communityBossDTO" type="com.cm.systemcity.pojo.dtos.communityboss.CommunityBossDTO">
|
<resultMap id="communityBossDTO" type="com.cm.systemcity.pojo.dtos.communityboss.CommunityBossDTO">
|
||||||
<id property="communityBossId" column="community_boss_id"/>
|
<id property="communityBossId" column="community_boss_id"/>
|
||||||
@ -59,12 +59,11 @@
|
|||||||
<insert id="saveCommunityBoss" parameterType="map" flushCache="true">
|
<insert id="saveCommunityBoss" parameterType="map" flushCache="true">
|
||||||
INSERT INTO city_community_boss(
|
INSERT INTO city_community_boss(
|
||||||
community_boss_id,
|
community_boss_id,
|
||||||
community_boss_username,
|
|
||||||
community_boss_name,
|
|
||||||
community_boss_parent_id,
|
community_boss_parent_id,
|
||||||
community_boss_level,
|
community_boss_level,
|
||||||
area_id,
|
area_id,
|
||||||
area_name,
|
area_name,
|
||||||
|
grid_summary,
|
||||||
creator,
|
creator,
|
||||||
gmt_create,
|
gmt_create,
|
||||||
modifier,
|
modifier,
|
||||||
@ -72,12 +71,11 @@
|
|||||||
is_delete
|
is_delete
|
||||||
) VALUES(
|
) VALUES(
|
||||||
#{communityBossId},
|
#{communityBossId},
|
||||||
#{communityBossUsername},
|
|
||||||
#{communityBossName},
|
|
||||||
#{communityBossParentId},
|
#{communityBossParentId},
|
||||||
#{communityBossLevel},
|
#{communityBossLevel},
|
||||||
#{areaId},
|
#{areaId},
|
||||||
#{areaName},
|
#{areaName},
|
||||||
|
#{gridSummary},
|
||||||
#{creator},
|
#{creator},
|
||||||
#{gmtCreate},
|
#{gmtCreate},
|
||||||
#{modifier},
|
#{modifier},
|
||||||
@ -123,6 +121,9 @@
|
|||||||
</if>
|
</if>
|
||||||
<if test="areaName != null and areaName != ''">
|
<if test="areaName != null and areaName != ''">
|
||||||
area_name = #{areaName},
|
area_name = #{areaName},
|
||||||
|
</if>
|
||||||
|
<if test="gridSummary != null and gridSummary != ''">
|
||||||
|
grid_summary = #{gridSummary},
|
||||||
</if>
|
</if>
|
||||||
modifier = #{modifier},
|
modifier = #{modifier},
|
||||||
gmt_modified = #{gmtModified}
|
gmt_modified = #{gmtModified}
|
||||||
@ -134,28 +135,13 @@
|
|||||||
<select id="listCommunityBoss" parameterType="map" resultMap="communityBossDTO" useCache="true">
|
<select id="listCommunityBoss" parameterType="map" resultMap="communityBossDTO" useCache="true">
|
||||||
SELECT
|
SELECT
|
||||||
t1.community_boss_id,
|
t1.community_boss_id,
|
||||||
t1.community_boss_name,
|
|
||||||
t1.community_boss_username,
|
|
||||||
t1.community_boss_level,
|
t1.community_boss_level,
|
||||||
t1.area_id,
|
t1.area_id,
|
||||||
t1.area_name,
|
t1.area_name,
|
||||||
t2.community_boss_id community_boss_parent_id,
|
t1.community_boss_parent_id,
|
||||||
t2.community_boss_name community_boss_parent_name,
|
t1.grid_summary
|
||||||
t3.user_phone community_boss_phone
|
|
||||||
FROM
|
FROM
|
||||||
city_community_boss t1
|
city_community_boss t1
|
||||||
LEFT JOIN
|
|
||||||
city_community_boss t2
|
|
||||||
ON
|
|
||||||
t1.community_boss_parent_id = t2.community_boss_id
|
|
||||||
AND
|
|
||||||
t2.is_delete = 0
|
|
||||||
INNER JOIN
|
|
||||||
sys_user t3
|
|
||||||
ON
|
|
||||||
t1.community_boss_id = t3.user_id
|
|
||||||
AND
|
|
||||||
t3.is_delete = 0
|
|
||||||
WHERE
|
WHERE
|
||||||
t1.is_delete = 0
|
t1.is_delete = 0
|
||||||
<if test="keywords != null and keywords != ''">
|
<if test="keywords != null and keywords != ''">
|
||||||
@ -206,28 +192,13 @@
|
|||||||
<select id="getCommunityBoss" parameterType="map" resultMap="communityBossDTO" useCache="false">
|
<select id="getCommunityBoss" parameterType="map" resultMap="communityBossDTO" useCache="false">
|
||||||
SELECT
|
SELECT
|
||||||
t1.community_boss_id,
|
t1.community_boss_id,
|
||||||
t1.community_boss_name,
|
|
||||||
t1.community_boss_username,
|
|
||||||
t1.community_boss_level,
|
t1.community_boss_level,
|
||||||
t1.area_id,
|
t1.area_id,
|
||||||
t1.area_name,
|
t1.area_name,
|
||||||
t2.community_boss_id community_boss_parent_id,
|
t1.community_boss_parent_id
|
||||||
t2.community_boss_name community_boss_parent_name,
|
t1.grid_summary
|
||||||
t3.user_phone community_boss_phone
|
|
||||||
FROM
|
FROM
|
||||||
city_community_boss t1
|
city_community_boss t1
|
||||||
LEFT JOIN
|
|
||||||
city_community_boss t2
|
|
||||||
ON
|
|
||||||
t1.community_boss_parent_id = t2.community_boss_id
|
|
||||||
AND
|
|
||||||
t2.is_delete = 0
|
|
||||||
INNER JOIN
|
|
||||||
sys_user t3
|
|
||||||
ON
|
|
||||||
t1.community_boss_id = t3.user_id
|
|
||||||
AND
|
|
||||||
t3.is_delete = 0
|
|
||||||
WHERE
|
WHERE
|
||||||
t1.is_delete = 0
|
t1.is_delete = 0
|
||||||
<if test="communityBossId != null and communityBossId != ''">
|
<if test="communityBossId != null and communityBossId != ''">
|
||||||
@ -295,24 +266,14 @@
|
|||||||
<select id="listCommunityBossByCommunity" parameterType="map" resultMap="communityBossDTO" useCache="false">
|
<select id="listCommunityBossByCommunity" parameterType="map" resultMap="communityBossDTO" useCache="false">
|
||||||
SELECT
|
SELECT
|
||||||
t1.community_boss_id,
|
t1.community_boss_id,
|
||||||
t1.community_boss_username,
|
t1.community_boss_parent_id,
|
||||||
t1.community_boss_name,
|
|
||||||
t2.community_id,
|
t2.community_id,
|
||||||
t3.user_phone community_boss_phone
|
|
||||||
FROM
|
FROM
|
||||||
city_community_boss t1
|
city_community_boss t1
|
||||||
LEFT JOIN
|
LEFT JOIN
|
||||||
city_community_boss_community t2
|
city_community_boss_community t2
|
||||||
ON
|
ON
|
||||||
t1.community_boss_id = t2.community_boss_id
|
t1.community_boss_id = t2.community_boss_id
|
||||||
INNER JOIN
|
|
||||||
sys_user t3
|
|
||||||
ON
|
|
||||||
t1.community_boss_id = t3.user_id
|
|
||||||
AND
|
|
||||||
t3.is_delete = 0
|
|
||||||
WHERE
|
|
||||||
t1.is_delete = 0
|
|
||||||
<if test="communityId != null and communityId != '' and communityId != 'nocummonity'">
|
<if test="communityId != null and communityId != '' and communityId != 'nocummonity'">
|
||||||
AND
|
AND
|
||||||
t2.community_id = #{communityId}
|
t2.community_id = #{communityId}
|
||||||
@ -337,10 +298,8 @@
|
|||||||
</if>
|
</if>
|
||||||
GROUP BY
|
GROUP BY
|
||||||
t1.community_boss_id,
|
t1.community_boss_id,
|
||||||
t1.community_boss_username,
|
t1.community_boss_parent_id,
|
||||||
t1.community_boss_name,
|
t2.community_id
|
||||||
t2.community_id,
|
|
||||||
t3.user_phone
|
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<!-- 片长详情列表 -->
|
<!-- 片长详情列表 -->
|
||||||
@ -350,37 +309,24 @@
|
|||||||
FROM (
|
FROM (
|
||||||
SELECT
|
SELECT
|
||||||
t1.community_boss_id,
|
t1.community_boss_id,
|
||||||
t1.community_boss_name,
|
t1.community_boss_parent_id,
|
||||||
t1.community_boss_username,
|
|
||||||
t1.community_boss_level,
|
t1.community_boss_level,
|
||||||
t1.area_id,
|
t1.area_id,
|
||||||
t1.area_name,
|
t1.area_name,
|
||||||
t2.community_boss_id community_boss_parent_id,
|
GROUP_CONCAT(t3.community_id) community_ids,
|
||||||
t2.community_boss_name community_boss_parent_name,
|
GROUP_CONCAT(t3.community_name) community_names
|
||||||
t3.user_phone community_boss_phone,
|
|
||||||
GROUP_CONCAT(t5.community_id) community_ids,
|
|
||||||
GROUP_CONCAT(t5.community_name) community_names
|
|
||||||
FROM
|
FROM
|
||||||
city_community_boss t1
|
city_community_boss t1
|
||||||
LEFT JOIN city_community_boss t2 ON t1.community_boss_parent_id = t2.community_boss_id
|
LEFT JOIN city_community_boss_community t2 ON t1.community_boss_id = t2.community_boss_id
|
||||||
AND t2.is_delete = 0
|
LEFT JOIN city_community t3 ON t2.community_id = t3.community_id AND t3.is_delete = 0
|
||||||
INNER JOIN sys_user t3 ON t1.community_boss_id = t3.user_id
|
|
||||||
AND t3.is_delete = 0
|
|
||||||
LEFT JOIN city_community_boss_community t4 ON t1.community_boss_id = t4.community_boss_id
|
|
||||||
LEFT JOIN city_community t5 ON t4.community_id = t5.community_id
|
|
||||||
AND t5.is_delete = 0
|
|
||||||
WHERE
|
WHERE
|
||||||
t1.is_delete = 0
|
t1.is_delete = 0
|
||||||
GROUP BY
|
GROUP BY
|
||||||
t1.community_boss_id,
|
t1.community_boss_id,
|
||||||
t1.community_boss_name,
|
t1.community_boss_parent_id,
|
||||||
t1.community_boss_username,
|
|
||||||
t1.community_boss_level,
|
t1.community_boss_level,
|
||||||
t1.area_id,
|
t1.area_id,
|
||||||
t1.area_name,
|
t1.area_name
|
||||||
t2.community_boss_id,
|
|
||||||
t2.community_boss_name,
|
|
||||||
t3.user_phone
|
|
||||||
) mt1
|
) mt1
|
||||||
WHERE
|
WHERE
|
||||||
1 = 1
|
1 = 1
|
||||||
@ -433,7 +379,6 @@
|
|||||||
t1.area_id,
|
t1.area_id,
|
||||||
t1.area_name,
|
t1.area_name,
|
||||||
t1.community_boss_id,
|
t1.community_boss_id,
|
||||||
t1.community_boss_name
|
|
||||||
FROM
|
FROM
|
||||||
city_community_boss t1
|
city_community_boss t1
|
||||||
WHERE
|
WHERE
|
||||||
@ -443,8 +388,6 @@
|
|||||||
</if>
|
</if>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- 新增片长和小区关系 -->
|
<!-- 新增片长和小区关系 -->
|
||||||
<insert id="saveCommunityBossDistrict" parameterType="map" flushCache="true">
|
<insert id="saveCommunityBossDistrict" parameterType="map" flushCache="true">
|
||||||
INSERT INTO city_community_boss_district(
|
INSERT INTO city_community_boss_district(
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package com.cm.systemcity;
|
package com.cm.systemcity;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
|
Loading…
Reference in New Issue
Block a user