区域接口
parent
1a63ec533d
commit
58d218a6dc
@ -0,0 +1,17 @@
|
|||||||
|
package com.tz.platform.system.feign;
|
||||||
|
|
||||||
|
import com.tz.platform.feign.IFeignRegion;
|
||||||
|
import com.tz.platform.feign.vo.RegionVO;
|
||||||
|
import com.tz.platform.system.feign.biz.FeignRegionBiz;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
public class FeignRegionController implements IFeignRegion {
|
||||||
|
private FeignRegionBiz biz;
|
||||||
|
@Override
|
||||||
|
public List<RegionVO> list() {
|
||||||
|
return biz.list();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
package com.tz.platform.system.feign.biz;
|
||||||
|
|
||||||
|
import com.tz.platform.common.core.tools.BeanUtils;
|
||||||
|
import com.tz.platform.entity.Region;
|
||||||
|
import com.tz.platform.feign.vo.RegionVO;
|
||||||
|
import com.tz.platform.repository.RegionDao;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class FeignRegionBiz {
|
||||||
|
@Autowired
|
||||||
|
private RegionDao regionDao;
|
||||||
|
|
||||||
|
public List<RegionVO> list(){
|
||||||
|
List<Region> regionList = regionDao.findAll();
|
||||||
|
return BeanUtils.copyProperties(regionList,RegionVO.class);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package com.tz.platform.user.pc;
|
||||||
|
|
||||||
|
import com.tz.platform.common.core.base.BaseController;
|
||||||
|
import com.tz.platform.common.core.base.Result;
|
||||||
|
import com.tz.platform.user.pc.biz.ImportUserBiz;
|
||||||
|
import com.tz.platform.user.pc.dto.ListUploadUserDTO;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/user/upload")
|
||||||
|
public class UploadUserController extends BaseController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ImportUserBiz biz;
|
||||||
|
|
||||||
|
@PostMapping(value = "importUser")
|
||||||
|
public Result<ListUploadUserDTO> importUser(MultipartFile file){
|
||||||
|
return biz.importUser(file,getUserNo());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,127 @@
|
|||||||
|
package com.tz.platform.user.pc.biz;
|
||||||
|
|
||||||
|
import cn.hutool.crypto.digest.DigestUtil;
|
||||||
|
import com.tz.platform.common.core.base.Result;
|
||||||
|
import com.tz.platform.common.core.config.SystemUtil;
|
||||||
|
import com.tz.platform.common.core.enmus.UserTypeEnum;
|
||||||
|
import com.tz.platform.common.core.tools.ExcelUtil;
|
||||||
|
import com.tz.platform.common.core.tools.StrUtil;
|
||||||
|
import com.tz.platform.entity.User;
|
||||||
|
import com.tz.platform.feign.IFeignProvince;
|
||||||
|
import com.tz.platform.feign.IFeignRegion;
|
||||||
|
import com.tz.platform.feign.IFeignStudentLevel;
|
||||||
|
import com.tz.platform.feign.vo.ProvinceVO;
|
||||||
|
import com.tz.platform.feign.vo.RegionVO;
|
||||||
|
import com.tz.platform.feign.vo.StudentLevelVo;
|
||||||
|
import com.tz.platform.repository.UserDao;
|
||||||
|
import com.tz.platform.user.pc.dto.ListUploadUserDTO;
|
||||||
|
import com.tz.platform.user.pc.dto.UploadUserDTO;
|
||||||
|
import org.apache.poi.ss.usermodel.Row;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class ImportUserBiz {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserDao userDao;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IFeignProvince feignProvince;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IFeignStudentLevel feignStudentLevel;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public Result<ListUploadUserDTO> importUser(MultipartFile file, Long userNo){
|
||||||
|
if(userNo == null|| userNo<=0){
|
||||||
|
return Result.error("无权操作");
|
||||||
|
}
|
||||||
|
List<ProvinceVO> provinceList = feignProvince.list();
|
||||||
|
List<StudentLevelVo> levelList = feignStudentLevel.list();
|
||||||
|
try {
|
||||||
|
ExcelUtil util = new ExcelUtil(file.getInputStream());
|
||||||
|
List<UploadUserDTO> uploadList = new ArrayList<>();
|
||||||
|
List<String> studentNoList =new ArrayList<>();
|
||||||
|
for(int rowNo = 1;rowNo <=util.getLastRowNum();rowNo++) {
|
||||||
|
Row row = util.getRow(rowNo);
|
||||||
|
UploadUserDTO d = new UploadUserDTO();
|
||||||
|
String studentNo = util.getCellValue(row.getCell(0));
|
||||||
|
String name = util.getCellValue(row.getCell(1));
|
||||||
|
String school = util.getCellValue(row.getCell(2));
|
||||||
|
String mobile = util.getCellValue(row.getCell(3));
|
||||||
|
String province = util.getCellValue(row.getCell(4));
|
||||||
|
String level = util.getCellValue(row.getCell(5));
|
||||||
|
if(StringUtils.isEmpty(studentNo)){
|
||||||
|
d.setStatus("空学号");
|
||||||
|
continue;
|
||||||
|
}else{
|
||||||
|
if(studentNoList.contains(studentNo)){
|
||||||
|
d.setStatus("学号重复");
|
||||||
|
}else{
|
||||||
|
studentNoList.add(studentNo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
d.setStudentNo(studentNo);
|
||||||
|
d.setName(name);
|
||||||
|
d.setSchool(school);
|
||||||
|
d.setMobile(mobile);
|
||||||
|
d.setProvince(province);
|
||||||
|
d.setLevel(level);
|
||||||
|
uploadList.add(d);
|
||||||
|
}
|
||||||
|
List<User> existList = userDao.findAllByStudentNoIn(studentNoList);
|
||||||
|
List<String> tmpList = existList.stream().map(User::getStudentNo).collect(Collectors.toList());
|
||||||
|
List<UploadUserDTO> willAddList = uploadList.stream().filter(uploadUserDTO -> {
|
||||||
|
boolean rs =!tmpList.contains(uploadUserDTO.getStudentNo());
|
||||||
|
if(rs ==false){
|
||||||
|
uploadUserDTO.setStatus("已存在");
|
||||||
|
}
|
||||||
|
return rs;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
List<User> userList = new ArrayList<>();
|
||||||
|
willAddList.forEach(dto->{
|
||||||
|
User user = new User();
|
||||||
|
user.setUsername(dto.getStudentNo());
|
||||||
|
user.setStudentNo(dto.getStudentNo());
|
||||||
|
user.setGmtCreate(new Date());
|
||||||
|
user.setGmtModified(new Date());
|
||||||
|
user.setSchool(dto.getSchool());
|
||||||
|
user.setProvince(dto.getProvince());
|
||||||
|
user.setName(dto.getName());
|
||||||
|
user.setMobile(dto.getMobile());
|
||||||
|
StudentLevelVo level = levelList.stream().filter(l -> l.getName().equals(dto.getLevel())).findFirst().orElse(null);
|
||||||
|
if(level !=null){
|
||||||
|
user.setLevelId(level.getId());
|
||||||
|
}
|
||||||
|
ProvinceVO province = provinceList.stream().filter(p-> p.getName().contains(dto.getProvince())).findFirst().orElse(null);
|
||||||
|
if(province!=null){
|
||||||
|
user.setProvince(dto.getProvince());
|
||||||
|
user.setProvinceId(province.getId());
|
||||||
|
user.setRegionId(province.getRegionId());
|
||||||
|
}
|
||||||
|
user.setUserType(UserTypeEnum.USER.getCode());
|
||||||
|
user.setMobileSalt(StrUtil.get32UUID());
|
||||||
|
user.setMobilePsw(DigestUtil.sha1Hex(user.getMobileSalt() + SystemUtil.INIT_PASSWORD));
|
||||||
|
user.setUserType(UserTypeEnum.USER.getCode());
|
||||||
|
userList.add(user);
|
||||||
|
});
|
||||||
|
userDao.saveAll(userList);
|
||||||
|
ListUploadUserDTO dto = new ListUploadUserDTO();
|
||||||
|
dto.setList(uploadList);
|
||||||
|
return Result.success(dto);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return Result.error("文件解析失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue