幼儿导入功能

This commit is contained in:
paidaxing444
2020-09-27 16:32:49 +08:00
parent cc0c36ea89
commit 8e1658187f
8 changed files with 362 additions and 78 deletions

View File

@ -3,7 +3,11 @@ package com.ruoyi.project.benyi.controller;
import java.util.List;
import java.util.ArrayList;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.framework.security.LoginUser;
import com.ruoyi.framework.security.service.TokenService;
import com.ruoyi.project.common.SchoolCommon;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
@ -23,6 +27,7 @@ import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;
/**
* 幼儿信息Controller
@ -37,6 +42,8 @@ public class ByChildController extends BaseController {
private IByChildService byChildService;
@Autowired
private SchoolCommon schoolCommon;
@Autowired
private TokenService tokenService;
/**
* 查询幼儿信息列表
@ -84,6 +91,26 @@ public class ByChildController extends BaseController {
return util.exportExcel(list, "child");
}
@Log(title = "用户管理", businessType = BusinessType.IMPORT)
@PreAuthorize("@ss.hasPermi('benyi:child:import')")
@PostMapping("/importData")
public AjaxResult importData(MultipartFile file) throws Exception {
ExcelUtil<ByChild> util = new ExcelUtil<ByChild>(ByChild.class);
List<ByChild> childList = util.importExcel(file.getInputStream());
LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
String operName = loginUser.getUsername();
Long deptId = loginUser.getUser().getDeptId();
String bjbh=schoolCommon.getClassId();
String message = byChildService.importChild(childList, operName,deptId,bjbh);
return AjaxResult.success(message);
}
@GetMapping("/importTemplate")
public AjaxResult importTemplate() {
ExcelUtil<ByChild> util = new ExcelUtil<ByChild>(ByChild.class);
return util.importTemplateExcel("幼儿数据");
}
/**
* 获取幼儿信息详细信息
*/

View File

@ -25,13 +25,13 @@ public class ByChild extends BaseEntity {
/**
* 学校id
*/
@Excel(name = "学校id")
// @Excel(name = "学校id")
private Long schoolid;
/**
* 班级id
*/
@Excel(name = "班级id")
// @Excel(name = "班级id")
private String classid;
/**
@ -43,13 +43,13 @@ public class ByChild extends BaseEntity {
/**
* 英文名
*/
@Excel(name = "英文名")
// @Excel(name = "英文名")
private String enName;
/**
* 小名
*/
@Excel(name = "小名")
// @Excel(name = "小名")
private String infantName;
/**
@ -61,205 +61,202 @@ public class ByChild extends BaseEntity {
/**
* 性别
*/
@Excel(name = "性别")
// @Excel(name = "性别")
private String xb;
/**
* 民族
*/
@Excel(name = "民族")
// @Excel(name = "民族")
private String mz;
/**
* 证件号码
*/
@Excel(name = "证件号码")
// @Excel(name = "证件号码")
private String zjhm;
/**
* 出生日期
*/
@JsonFormat(pattern = "yyyy-MM-dd")
@Excel(name = "出生日期", width = 30, dateFormat = "yyyy-MM-dd")
// @Excel(name = "出生日期", width = 30, dateFormat = "yyyy-MM-dd")
private Date csrq;
/**
* 出生所在省
*/
@Excel(name = "出生所在省")
// @Excel(name = "出生所在省")
private String birthProvince;
/**
* 出生所在省名称
*/
@Excel(name = "出生所在省名称")
// @Excel(name = "出生所在省名称")
private String birthProvincename;
/**
* 出生所在地市
*/
@Excel(name = "出生所在地市")
// @Excel(name = "出生所在地市")
private String birthCity;
/**
* 出生所在市名称
*/
@Excel(name = "出生所在市名称")
// @Excel(name = "出生所在市名称")
private String birthCityname;
/**
* 出生地区
*/
@Excel(name = "出生地区")
// @Excel(name = "出生地区")
private String birthArea;
/**
* 出生所在区名称
*/
@Excel(name = "出生所在区名称")
// @Excel(name = "出生所在区名称")
private String birthAreaname;
/**
* 户口所在地
*/
@Excel(name = "户口所在地")
// @Excel(name = "户口所在地")
private String registeredProvince;
/**
* 户口所在地名称
*/
@Excel(name = "户口所在地名称")
// @Excel(name = "户口所在地名称")
private String registeredProvincename;
/**
* 户口所在地市
*/
@Excel(name = "户口所在地市")
// @Excel(name = "户口所在地市")
private String registeredCity;
/**
* 户口所在市名称
*/
@Excel(name = "户口所在市名称")
// @Excel(name = "户口所在市名称")
private String registeredCityname;
/**
* 户口所在区
*/
@Excel(name = "户口所在区")
// @Excel(name = "户口所在区")
private String registeredArea;
/**
* 户口所在区名称
*/
@Excel(name = "户口所在区名称")
// @Excel(name = "户口所在区名称")
private String registeredAreaname;
/**
* 住址省
*/
@Excel(name = "住址省")
// @Excel(name = "住址省")
private String addrProvince;
/**
* 住址省名称
*/
@Excel(name = "住址省名称")
// @Excel(name = "住址省名称")
private String addrProvincename;
/**
* 住址市
*/
@Excel(name = "住址市")
// @Excel(name = "住址市")
private String addrCity;
/**
* 住址市名称
*/
@Excel(name = "住址市名称")
// @Excel(name = "住址市名称")
private String addrCityname;
/**
* 住址区
*/
@Excel(name = "住址区")
// @Excel(name = "住址区")
private String addrArea;
/**
* 住址区名称
*/
@Excel(name = "住址区名称")
// @Excel(name = "住址区名称")
private String addrAreaname;
/**
* 详细地址
*/
@Excel(name = "详细地址")
// @Excel(name = "详细地址")
private String addrDetail;
/**
* 曾经就读幼儿园
*/
@Excel(name = "曾经就读幼儿园")
// @Excel(name = "曾经就读幼儿园")
private String everSchool;
/**
* 是否学习英语
*/
@Excel(name = "是否学习英语")
// @Excel(name = "是否学习英语")
private String learnEnglish;
/**
* 入园渠道
*/
@Excel(name = "入园渠道")
// @Excel(name = "入园渠道")
private String source;
/**
* 状态
*/
@Excel(name = "状态")
// @Excel(name = "状态")
private String status;
/**
* 入园时间
*/
@JsonFormat(pattern = "yyyy-MM-dd")
@Excel(name = "入园时间", width = 30, dateFormat = "yyyy-MM-dd")
// @Excel(name = "入园时间", width = 30, dateFormat = "yyyy-MM-dd")
private Date enterDate;
/**
* 离园时间
*/
@JsonFormat(pattern = "yyyy-MM-dd")
@Excel(name = "离园时间", width = 30, dateFormat = "yyyy-MM-dd")
// @Excel(name = "离园时间", width = 30, dateFormat = "yyyy-MM-dd")
private Date outDate;
/**
* 第一语言
*/
@Excel(name = "第一语言")
// @Excel(name = "第一语言")
private String firstLanguage;
/**
* 第二语言
*/
@Excel(name = "第二语言")
// @Excel(name = "第二语言")
private String seconderLanguage;
/**
* 其他语言
*/
@Excel(name = "其他语言")
// @Excel(name = "其他语言")
private String otherLanguage;
/**
* 创建人
*/
@Excel(name = "创建人")
// @Excel(name = "创建人")
private Long createuserid;
private ByChildContactpeople byChildContactpeople;
@ -549,10 +546,6 @@ public class ByChild extends BaseEntity {
}
public void setId(Long id) {
this.id = id;
}

View File

@ -74,4 +74,15 @@ public interface ByChildMapper {
* @return 班级信息集合
*/
public List<ByChild> selectststicstClassList(ByChild byChild);
/**
* 导入用户数据
*
* @param userChild 用户数据列表
* @param operName 操作用户
* @param deptId 部门id
* @param bjbh 班级编号
* @return 结果
*/
public String importChild(List<ByChild> userChild, String operName, Long deptId, String bjbh);
}

View File

@ -74,4 +74,15 @@ public interface IByChildService {
* @return 班级信息集合
*/
public List<ByChild> selectststicstClassList(ByChild byChild);
/**
* 导入用户数据
*
* @param userChild 用户数据列表
* @param operName 操作用户
* @param deptId 部门id
* @param bjbh 班级编号
* @return 结果
*/
public String importChild(List<ByChild> userChild, String operName, Long deptId, String bjbh);
}

View File

@ -2,8 +2,15 @@ package com.ruoyi.project.benyi.service.impl;
import java.util.List;
import com.ruoyi.common.exception.CustomException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.aspectj.lang.annotation.DataScope;
import com.ruoyi.project.system.domain.SysUser;
import com.ruoyi.project.system.service.impl.SysUserServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.benyi.mapper.ByChildMapper;
@ -18,6 +25,7 @@ import com.ruoyi.project.benyi.service.IByChildService;
*/
@Service
public class ByChildServiceImpl implements IByChildService {
private static final Logger log = LoggerFactory.getLogger(SysUserServiceImpl.class);
@Autowired
private ByChildMapper byChildMapper;
@ -111,4 +119,49 @@ public class ByChildServiceImpl implements IByChildService {
public List<ByChild> selectststicstClassList(ByChild byChild) {
return byChildMapper.selectststicstClassList(byChild);
}
/**
* 导入用户数据
*
* @param userChild 用户数据列表
* @param operName 操作用户
* @param deptId 部门id
* @param bjbh 班级编号
* @return 结果
*/
@Override
public String importChild(List<ByChild> userChild, String operName, Long deptId, String bjbh) {
if (StringUtils.isNull(userChild) || userChild.size() == 0) {
throw new CustomException("导入幼儿数据不能为空!");
}
int successNum = 0;
int failureNum = 0;
StringBuilder successMsg = new StringBuilder();
StringBuilder failureMsg = new StringBuilder();
for (ByChild byChild : userChild) {
try {
if (bjbh == null || "".equals(bjbh)) {
} else {
byChild.setClassid(bjbh);
}
byChild.setSchoolid(deptId);
byChild.setCreateBy(operName);
this.insertByChild(byChild);
successNum++;
successMsg.append("<br/>" + successNum + "、幼儿 " + byChild.getName() + " 导入成功");
} catch (Exception e) {
failureNum++;
String msg = "<br/>" + failureNum + "、幼儿 " + byChild.getName() + " 导入失败:";
failureMsg.append(msg + e.getMessage());
log.error(msg, e);
}
}
if (failureNum > 0) {
failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
throw new CustomException(failureMsg.toString());
} else {
successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");
}
return successMsg.toString();
}
}

View File

@ -100,7 +100,7 @@ public class SchoolCommon {
* 判断当前用户是否拥有班级
**/
public String getClassId() {
String strClassId = "-1";
// String strClassId = "-1";
SysUser sysUser = getUser();
ByClass byClass = new ByClass();
//根据用户id来设置主班教师,配班教师,助理教师的教师id