Commit ebf8e92d authored by licc's avatar licc

excel 上传提交

parent 56371e55
...@@ -6,10 +6,10 @@ ...@@ -6,10 +6,10 @@
<id column="id" property="id"/> <id column="id" property="id"/>
<result column="user_id" property="userId"/> <result column="user_id" property="userId"/>
<result column="type" property="type"/> <result column="type" property="type"/>
<result column="card_number" property="cardNumber"/> <result column="card_id" property="cardId"/>
<result column="money" property="money"/> <result column="money" property="money"/>
<result column="result" property="result"/> <result column="result" property="result"/>
<result column="limit" property="limit"/> <result column="pay_limit" property="payLimit"/>
<result column="create_time" property="createTime"/> <result column="create_time" property="createTime"/>
<result column="update_time" property="updateTime"/> <result column="update_time" property="updateTime"/>
</resultMap> </resultMap>
...@@ -24,20 +24,20 @@ ...@@ -24,20 +24,20 @@
</sql> </sql>
<sql id="cols_exclude_id"> <sql id="cols_exclude_id">
user_id,type, card_id,money,result,limit, create_time,update_time user_id,type, card_id,money,result,pay_limit, create_time,update_time
</sql> </sql>
<sql id="vals"> <sql id="vals">
#{userId},#{type},#{cardNumber},#{money},#{result},#{limit},now(),now() #{userId},#{type},#{cardId},#{money},#{result},#{payLimit},now(),now()
</sql> </sql>
<sql id="updateCondition"> <sql id="updateCondition">
<if test="userId != null">user_id = #{userId},</if> <if test="userId != null">user_id = #{userId},</if>
<if test="type != null">type =#{type},</if> <if test="type != null">type =#{type},</if>
<if test="cardNumber != null">card_number =#{cardNumber},</if> <if test="cardId != null">card_id =#{cardId},</if>
<if test="money != null">money =#{money},</if> <if test="money != null">money =#{money},</if>
<if test="result != null">result =#{result},</if> <if test="result != null">result =#{result},</if>
<if test="limit != null">limit =#{limit},</if> <if test="payLimit != null">pay_limit =#{payLimit},</if>
update_time =now() update_time =now()
</sql> </sql>
...@@ -45,10 +45,10 @@ ...@@ -45,10 +45,10 @@
<if test="id != null">id = #{id}</if> <if test="id != null">id = #{id}</if>
<if test="userId != null">and user_id = #{userId}</if> <if test="userId != null">and user_id = #{userId}</if>
<if test="type != null">and type =#{type}</if> <if test="type != null">and type =#{type}</if>
<if test="cardNumber != null">and card_number =#{cardNumber}</if> <if test="cardId != null">and card_id =#{cardId}</if>
<if test="money != null">and money =#{money}</if> <if test="money != null">and money =#{money}</if>
<if test="result != null">and result =#{result}</if> <if test="result != null">and result =#{result}</if>
<if test="limit != null">and limit =#{limit}</if> <if test="payLimit != null">and pay_limit =#{payLimit}</if>
<if test="createTime != null">and create_time &gt;= #{createTime}</if> <if test="createTime != null">and create_time &gt;= #{createTime}</if>
<if test="updateTime != null">and #{updateTime} &gt;= update_time</if> <if test="updateTime != null">and #{updateTime} &gt;= update_time</if>
</sql> </sql>
...@@ -62,15 +62,16 @@ ...@@ -62,15 +62,16 @@
) )
</insert> </insert>
<select id="getList" resultType="cn.wisenergy.model.vo.PayRecordShowVo"> <select id="getList" resultType="cn.wisenergy.model.vo.PayRecordShowVo">
select id as recordId,type,result,limit,create_time as payTime select
<include refid="cols_all"/>
from from
<include refid="table"/> <include refid="table"/>
<where> <where>
<if test="userId != null"> <if test="userId != null">
user_id=#{userId} user_id=#{userId}
</if> </if>
limit #{startNum},#{endNum}
order by create_time desc order by create_time desc
limit #{startNum},#{endNum}
</where> </where>
</select> </select>
......
...@@ -47,7 +47,8 @@ ...@@ -47,7 +47,8 @@
<if test="updateTime != null">and #{updateTime} &gt;= update_time</if> <if test="updateTime != null">and #{updateTime} &gt;= update_time</if>
</sql> </sql>
<insert id="add" parameterType="cn.wisenergy.model.app.SchemeInfo" keyProperty="id" useGeneratedKeys="true"> <insert id="add" parameterType="cn.wisenergy.model.app.SchemeInfo" keyProperty="id"
keyColumn="id" useGeneratedKeys="true">
insert into insert into
<include refid="table"/> <include refid="table"/>
(<include refid="cols_exclude_id"/>) (<include refid="cols_exclude_id"/>)
......
...@@ -56,7 +56,7 @@ public class PayRecord implements Serializable { ...@@ -56,7 +56,7 @@ public class PayRecord implements Serializable {
* 充值次数 * 充值次数
*/ */
@ApiModelProperty(value = "充值次数",name = "limit") @ApiModelProperty(value = "充值次数",name = "limit")
private Integer limit; private Integer payLimit;
/** /**
* 创建时间 * 创建时间
......
...@@ -4,6 +4,7 @@ import cn.wisenergy.model.common.BaseEntity; ...@@ -4,6 +4,7 @@ import cn.wisenergy.model.common.BaseEntity;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;
...@@ -11,8 +12,9 @@ import java.util.Date; ...@@ -11,8 +12,9 @@ import java.util.Date;
/** /**
* @author 86187 * @author 86187
*/ */
@EqualsAndHashCode(callSuper = true)
@Data @Data
@ApiModel(value = "SchemeInnfo") @ApiModel(value = "SchemeInfo")
public class SchemeInfo extends BaseEntity implements Serializable { public class SchemeInfo extends BaseEntity implements Serializable {
private static final long serialVersionUID = 7020644673356401949L; private static final long serialVersionUID = 7020644673356401949L;
/** /**
......
...@@ -92,8 +92,8 @@ public class Volunteer extends BaseEntity implements Serializable { ...@@ -92,8 +92,8 @@ public class Volunteer extends BaseEntity implements Serializable {
/** /**
* 计划投档数 * 计划投档数
*/ */
@ApiModelProperty(value = "计划投档数", name = "castArchivesNum") @ApiModelProperty(value = "投档计划数", name = "castArchivesNum")
@ExcelProperty(value = "计划投档数") @ExcelProperty(value = "投档计划数")
private Integer castArchivesNum; private Integer castArchivesNum;
/** /**
......
package cn.wisenergy.service.app; package cn.wisenergy.service.app;
import cn.wisenergy.common.utils.R; import cn.wisenergy.common.utils.R;
import cn.wisenergy.model.app.SchemeInfo;
import cn.wisenergy.model.app.Volunteer; import cn.wisenergy.model.app.Volunteer;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
...@@ -38,4 +39,6 @@ public interface VolunteerService extends IService<Volunteer> { ...@@ -38,4 +39,6 @@ public interface VolunteerService extends IService<Volunteer> {
* @throws IOException 异常 * @throws IOException 异常
*/ */
void ceshi(MultipartFile file, HttpServletResponse response) throws IOException; void ceshi(MultipartFile file, HttpServletResponse response) throws IOException;
R<SchemeInfo> add(SchemeInfo schemeInfo);
} }
...@@ -36,6 +36,9 @@ public class VolunteerServiceImpl extends ServiceImpl<VolunteerMapper, Volunteer ...@@ -36,6 +36,9 @@ public class VolunteerServiceImpl extends ServiceImpl<VolunteerMapper, Volunteer
@Autowired @Autowired
private SchemeMapper schemeMapper; private SchemeMapper schemeMapper;
@Autowired
private VolunteerService volunteerService;
@Override @Override
public R<Boolean> batchAdd(List<Volunteer> list) { public R<Boolean> batchAdd(List<Volunteer> list) {
return null; return null;
...@@ -52,15 +55,20 @@ public class VolunteerServiceImpl extends ServiceImpl<VolunteerMapper, Volunteer ...@@ -52,15 +55,20 @@ public class VolunteerServiceImpl extends ServiceImpl<VolunteerMapper, Volunteer
if (!valid) { if (!valid) {
throw new BaseException("请传入Excel文件"); throw new BaseException("请传入Excel文件");
} }
VolunteerListener excelListener = new VolunteerListener();
//1、保存方案信息 //2.读取数据进行入库操作
EasyExcel.read(file.getInputStream(), Volunteer.class, new VolunteerListener()).sheet().doRead();
List<Volunteer> list = excelListener.getList();
//3、保存方案和志愿信息
SchemeInfo schemeInfo = new SchemeInfo(); SchemeInfo schemeInfo = new SchemeInfo();
schemeInfo.setSchemeName(schemeName); schemeInfo.setSchemeName(schemeName);
schemeInfo.setType(type); schemeInfo.setType(type);
schemeInfo.setUploadTime(new Date()); schemeInfo.setUploadTime(new Date());
schemeInfo.setIsDelete(0); schemeInfo.setIsDelete(0);
saveSchemeAndVolunteer(schemeInfo, file); saveSchemeAndVolunteer(schemeInfo, list);
} }
@Override @Override
...@@ -69,33 +77,51 @@ public class VolunteerServiceImpl extends ServiceImpl<VolunteerMapper, Volunteer ...@@ -69,33 +77,51 @@ public class VolunteerServiceImpl extends ServiceImpl<VolunteerMapper, Volunteer
throw new BaseException("操作错误"); throw new BaseException("操作错误");
} }
VolunteerListener excelListener = new VolunteerListener();
//判断文件类型= //判断文件类型=
boolean valid = this.validContentType(file.getOriginalFilename()); boolean valid = this.validContentType(file.getOriginalFilename());
if (!valid) { if (!valid) {
throw new BaseException("请传入Excel文件"); throw new BaseException("请传入Excel文件");
} }
//2.读取数据进行入库操作 //2.读取数据进行入库操作
EasyExcel.read(file.getInputStream(), Volunteer.class, new VolunteerListener(this)).sheet().doRead(); EasyExcel.read(file.getInputStream(), Volunteer.class, excelListener).sheet().doRead();
List<Volunteer> sult = excelListener.getList();
log.info("返回的excel集合:" + sult);
log.info("返回的excel集合:" + sult);
for (Volunteer volunteer : sult) {
}
}
@Override
public R<SchemeInfo> add(SchemeInfo schemeInfo) {
int count = schemeMapper.add(schemeInfo);
log.info("返回对象:" + schemeInfo);
int id = schemeInfo.getId();
log.info("主键id:" + id);
return R.ok(schemeInfo);
} }
/** /**
* 保存方案和志愿信息 * 保存方案和志愿信息
* *
* @param schemeInfo 方案信息 * @param schemeInfo 方案信息
* @param file 志愿文件 * @param list 志愿信息
* @throws IOException 异常
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void saveSchemeAndVolunteer(SchemeInfo schemeInfo, MultipartFile file) throws IOException { public void saveSchemeAndVolunteer(SchemeInfo schemeInfo, List<Volunteer> list) {
//1、保存方案信息 //1、保存方案信息
int count = schemeMapper.add(schemeInfo); int count = schemeMapper.insert(schemeInfo);
if (count == 0) { if (count == 0) {
throw new RuntimeException("保存方案信息失败!"); throw new RuntimeException("保存方案信息失败!");
} }
//2.读取数据进行入库操作 //保存志愿信息
EasyExcel.read(file.getInputStream(), Volunteer.class, new VolunteerListener(this)).sheet().doRead(); for (Volunteer volunteer : list) {
}
} }
/** /**
......
...@@ -15,14 +15,13 @@ import java.util.stream.Collectors; ...@@ -15,14 +15,13 @@ import java.util.stream.Collectors;
/** /**
* Excel批量添加社区居民 监听器 * Excel批量添加社区居民 监听器
*
* @author 86187
*/ */
@Slf4j @Slf4j
public class VolunteerListener extends AnalysisEventListener<Volunteer> { public class VolunteerListener extends AnalysisEventListener<Volunteer> {
private List<Volunteer> list; private List<Volunteer> list=new ArrayList<>();
private VolunteerService volunteerService;
private final int batch = 50000; private final int batch = 50000;
/** /**
...@@ -36,11 +35,6 @@ public class VolunteerListener extends AnalysisEventListener<Volunteer> { ...@@ -36,11 +35,6 @@ public class VolunteerListener extends AnalysisEventListener<Volunteer> {
private boolean isCorrectFormat = true; private boolean isCorrectFormat = true;
public VolunteerListener(VolunteerService volunteerService) {
this.volunteerService = volunteerService;
list = new ArrayList<>();
}
/** /**
* 这个每一条数据解析都会来调用 == * 这个每一条数据解析都会来调用 ==
* *
...@@ -56,6 +50,9 @@ public class VolunteerListener extends AnalysisEventListener<Volunteer> { ...@@ -56,6 +50,9 @@ public class VolunteerListener extends AnalysisEventListener<Volunteer> {
log.info("解析到一条志愿数据>>>>>>>>>>:{}", volunteer); log.info("解析到一条志愿数据>>>>>>>>>>:{}", volunteer);
//此处做校验 本次没有校验 //此处做校验 本次没有校验
if (volunteer != null) { if (volunteer != null) {
volunteer.setIsDelete(0);
volunteer.setCreateTime(new Date());
volunteer.setUpdateTime(new Date());
if (StringUtils.isEmpty(volunteer.getMajorName())) { if (StringUtils.isEmpty(volunteer.getMajorName())) {
throw new RuntimeException("专业不能为空!"); throw new RuntimeException("专业不能为空!");
} }
...@@ -99,17 +96,6 @@ public class VolunteerListener extends AnalysisEventListener<Volunteer> { ...@@ -99,17 +96,6 @@ public class VolunteerListener extends AnalysisEventListener<Volunteer> {
list.add(volunteer); list.add(volunteer);
} }
//每500条插入一次数据库
if (list.size() >= batch) {
//判断数据库是否已有手机号的数据
log.info("invoke批量插入志愿数据,条数为>>>>>>>>>>:{}", list.size());
if (list.size() > 0) {
volunteerService.saveBatch(list);
}
//保存后清除,防止大量数据导致内存耗尽
list.clear();
}
} }
/** /**
...@@ -119,16 +105,28 @@ public class VolunteerListener extends AnalysisEventListener<Volunteer> { ...@@ -119,16 +105,28 @@ public class VolunteerListener extends AnalysisEventListener<Volunteer> {
*/ */
@Override @Override
public void doAfterAllAnalysed(AnalysisContext analysisContext) { public void doAfterAllAnalysed(AnalysisContext analysisContext) {
log.info("doAfterAllAnalysed解析玩一个志愿sheet工作表>>>>>>>>>>"); // log.info("doAfterAllAnalysed解析玩一个志愿sheet工作表>>>>>>>>>>");
//如果集合不为空 // //如果集合不为空
if (!CollectionUtils.isEmpty(list)) { // if (!CollectionUtils.isEmpty(list)) {
log.info("批量插入志愿数据,条数为>>>>>>>>>>:{}", list.size()); // log.info("批量插入志愿数据,条数为>>>>>>>>>>:{}", list.size());
if (list.size() > 0) { // if (list.size() > 0) {
volunteerService.saveBatch(list); // volunteerService.saveBatch(list);
} // }
} // }
}
public List<Volunteer> getList() {
List<Volunteer> result = new ArrayList<>();
result.addAll(list);
return result;
} }
public void setList(List<Volunteer> list) {
this.list = list;
}
/** /**
* 校验导入模板表头是否正确 * 校验导入模板表头是否正确
* *
......
...@@ -2,13 +2,11 @@ package cn.wisenergy.web.admin.controller.app; ...@@ -2,13 +2,11 @@ package cn.wisenergy.web.admin.controller.app;
import cn.wisenergy.common.expection.BaseException; import cn.wisenergy.common.expection.BaseException;
import cn.wisenergy.common.utils.R; import cn.wisenergy.common.utils.R;
import cn.wisenergy.model.app.SchemeQueryRecord; import cn.wisenergy.model.app.SchemeInfo;
import cn.wisenergy.model.vo.SchemeQueryVo; import cn.wisenergy.model.vo.SchemeQueryVo;
import cn.wisenergy.model.vo.SchemeRecordQueryVo;
import cn.wisenergy.model.vo.VolunteerVo; import cn.wisenergy.model.vo.VolunteerVo;
import cn.wisenergy.service.app.SchemeService; import cn.wisenergy.service.app.SchemeService;
import cn.wisenergy.service.app.VolunteerService; import cn.wisenergy.service.app.VolunteerService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
...@@ -22,6 +20,7 @@ import javax.servlet.http.HttpServletResponse; ...@@ -22,6 +20,7 @@ import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
/** /**
* @author 86187
* @ Description: PC-方案 * @ Description: PC-方案
* @ Author : 86187 * @ Author : 86187
* @ Date : 2021/1/14 10:50 * @ Date : 2021/1/14 10:50
...@@ -71,8 +70,18 @@ public class SchemeController { ...@@ -71,8 +70,18 @@ public class SchemeController {
throw new BaseException("操作错误"); throw new BaseException("操作错误");
} }
volunteerService.ceshi(file, response); volunteerService.ceshi(file, response);
return R.ok("添加成功"); return R.ok("添加成功");
} }
@ApiOperation(value = "测试主键自增", notes = "测试主键自增")
@ApiImplicitParam(name = "schemeInfo", value = "信息", dataType = "SchemeInfo")
@PostMapping("/add")
public R<SchemeInfo> add(@RequestBody SchemeInfo schemeInfo) {
R<SchemeInfo> scheme = volunteerService.add(schemeInfo);
log.info("scheme:" + scheme);
return scheme;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment