Commit 6deccbf5 authored by liaoanyuan's avatar liaoanyuan

新增毕业院校查询和方案Excel导出

parent 2d0cf026
package cn.wisenergy.mapper;
import cn.wisenergy.model.app.Graduation;
import cn.wisenergy.model.dto.BannerDto;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import java.util.List;
import java.util.Map;
public interface GraduationMapper extends BaseMapper<Graduation> {
/**
* 获取广告列表
* @return 毕业院校列表
*/
List<Graduation> getList();
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.wisenergy.mapper.GraduationMapper">
<resultMap id="graduationMap" type="cn.wisenergy.model.app.Graduation">
<id column="id" property="id"/>
<result column="school_name" property="schoolName"/>
<result column="position" property="position"/>
<result column="describe" property="describe"/>
<result column="create_time" property="createTime"/>
<result column="update_time" property="updateTime"/>
</resultMap>
<sql id="table">
graduation
</sql>
<sql id="cols_all">
id,
<include refid="cols_exclude_id"/>
</sql>
<sql id="cols_exclude_id">
school_name,`position`,`describe`,create_time,update_time
</sql>
<sql id="vals">
#{schoolName},#{position},#{describe},now(),now()
</sql>
<sql id="updateCondition">
<if test="schoolName != null">school_name =#{schoolName},</if>
<if test="position != null">`position` =#{position},</if>
<if test="describe != null">`describe` =#{describe},</if>
update_time =now()
</sql>
<sql id="criteria">
<if test="schoolName != null">and school_name =#{schoolName},</if>
<if test="position != null">and `position` =#{position},</if>
<if test="describe != null">and `describe` =#{describe},</if>
<if test="createTime != null">and create_time >= #{createTime}</if>
<if test="updateTime != null">and #{updateTime} >= update_time</if>
</sql>
<update id="edit" parameterType="cn.wisenergy.model.app.Graduation">
UPDATE
<include refid="table"/>
<set>
<include refid="updateCondition"/>
</set>
<where>
id = #{id}
</where>
</update>
<select id="getList" resultMap="graduationMap">
select
<include refid="cols_all"/>
from
<include refid="table"/>
</select>
</mapper>
package cn.wisenergy.model.app;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* 毕业院校实体类
*/
@Data
@ApiModel(value = "Graduation")
public class Graduation implements Serializable {
private static final long serialVersionUID = 7511175256020154565L;
/**
* 院校主键id
*/
@ApiModelProperty(value = "院校主键id",name = "id")
private Integer id;
/**
* 学校名称
*/
@ApiModelProperty(value = "学校名称",name = "schoolName")
private String schoolName;
/**
* 学校地址
*/
@ApiModelProperty(value = "学校地址",name = "position")
private String position;
/**
* 学校描述
*/
@ApiModelProperty(value = "学校描述",name = "describe")
private String describe;
/**
* 创建时间
*/
@ApiModelProperty(value = "创建时间",name = "creteTime")
private Date createTime;
/**
*更改时间
*/
@ApiModelProperty(value = "更改时间",name = "updateTime")
private Date updateTime;
}
package cn.wisenergy.service.app;
import cn.wisenergy.common.utils.R;
import cn.wisenergy.model.app.Graduation;
import java.util.List;
public interface GraduationSerivce {
R<List<Graduation>> getList();
}
......@@ -38,5 +38,11 @@ public interface RefillCardService {
*/
R<Boolean> createCard(Integer id);
/**
* 导出excel
* @param batchNumber 批次号
* @param response
* @return Excel数据
*/
R<Boolean> createExcel(String batchNumber, HttpServletResponse response);
}
......@@ -35,11 +35,18 @@ public interface SchemeRecordService {
R<List<Volunteer>> getVolunteerList(Integer userId,Integer recordId);
/**
* 方案导出
* 方案pdf导出
* @param userId 用户id
* @param recordId 方案查询记录id
* @return 0:导出成功,1:导出失败
*/
R<Boolean> export(Integer userId, Integer recordId, HttpServletResponse response);
/**
* 方案excel导出
* @param userId 用户id
* @param recordId 方案查询记录id
* @return 0:导出成功,1:导出失败
*/
R<Boolean> createExcel(Integer userId, Integer recordId, HttpServletResponse response);
}
package cn.wisenergy.service.app.impl;
import cn.wisenergy.common.utils.R;
import cn.wisenergy.mapper.GraduationMapper;
import cn.wisenergy.model.app.Graduation;
import cn.wisenergy.service.app.GraduationSerivce;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
@Slf4j
public class GraduationSerivceImpl implements GraduationSerivce {
@Autowired
private GraduationMapper graduationMapper;
@Override
public R<List<Graduation>> getList() {
List<Graduation> list = graduationMapper.getList();
return R.ok(list);
}
}
......@@ -5,12 +5,15 @@ import cn.wisenergy.common.utils.R;
import cn.wisenergy.mapper.SchemeRecordMapper;
import cn.wisenergy.mapper.UserVolunteerMapper;
import cn.wisenergy.mapper.VolunteerMapper;
import cn.wisenergy.model.app.CardInfo;
import cn.wisenergy.model.app.SchemeQueryRecord;
import cn.wisenergy.model.app.UserVolunteer;
import cn.wisenergy.model.app.Volunteer;
import cn.wisenergy.model.dto.ExportCardDto;
import cn.wisenergy.model.vo.SchemeRecordQueryVo;
import cn.wisenergy.service.app.SchemeRecordService;
import cn.wisenergy.service.common.PdfUtil;
import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageInfo;
......@@ -21,6 +24,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
......@@ -188,6 +192,63 @@ public class SchemeRecordServiceImpl extends ServiceImpl<SchemeRecordMapper, Sch
return R.ok(0, true);
}
@Override
public R<Boolean> createExcel(Integer userId, Integer recordId, HttpServletResponse response) {
log.info("SchemeRecordServiceImpl[].createExcel[].input.param:userId,recordId"+userId,recordId);
if (null == userId || null == recordId) {
return R.error("入参为空!");
}
//1、根据用户id和方案记录id,获取志愿ids
QueryWrapper<UserVolunteer> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("user_id", userId);
queryWrapper.eq("scheme_record_id", recordId);
List<UserVolunteer> list = userVolunteerMapper.selectList(queryWrapper);
if (CollectionUtils.isEmpty(list)) {
return R.error("数据为空");
}
List<Integer> ids = list.stream().map(UserVolunteer::getVolunteerId).collect(Collectors.toList());
List<Volunteer> result = volunteerMapper.getListByIds(ids);
result.sort(Comparator.comparing(Volunteer::getLowestMark).reversed());
//生成Excel
try {
// 设置内容格式 以及 编码方式
response.setContentType("application/vnd.ms-excel");
response.setCharacterEncoding("utf-8");
// 使用java8新特性的stream流去处理数据,把空的数据过滤掉
List<Volunteer> resultBo = result.stream().filter(Objects::nonNull)
.map(t -> {
return Volunteer.builder()
.majorName(t.getMajorName())
.academy(t.getAcademy())
.courseDemand(t.getCourseDemand())
.nature(t.getNature())
.yearLimit(t.getYearLimit())
.planNum(t.getPlanNum())
.castArchivesNum(null==t.getCastArchivesNum()?0:t.getCastArchivesNum())
.launchNum(null==t.getLaunchNum()?0:t.getLaunchNum())
.lowestMark(null==t.getLowestMark()?String.valueOf(0):t.getLowestMark())
.lowestRank(null==t.getLowestRank()?String.valueOf(0):t.getLowestRank())
.build();
}).collect(Collectors.toList());
//创建文件名称
Long lon = System.currentTimeMillis();
response.setHeader("Content-disposition", "attachment;filename=" + lon + ".xlsx");
// sheet名称
EasyExcel.write(response.getOutputStream(), Volunteer.class).sheet(lon.toString()).doWrite(resultBo);
return R.ok(0,true);
} catch (Exception e) {
return R.ok(1,false);
}
}
/**
* 分页处理
......
......@@ -125,8 +125,8 @@ public class UserServiceImpl extends ServiceImpl<UsersMapper, User> implements U
rechargeTimes+=1;
}
}
userInfoDto.setWeChatMoney(weChatMoney.toString());
userInfoDto.setAlipayMoney(alipayMoney.toString());
userInfoDto.setWeChatMoney(String.valueOf(weChatMoney));
userInfoDto.setAlipayMoney(String.valueOf(alipayMoney));
userInfoDto.setRechargeTimes(rechargeTimes);
}
......
package cn.wisenergy.web.admin.controller.app;
import cn.wisenergy.common.utils.R;
import cn.wisenergy.model.app.Graduation;
import cn.wisenergy.service.app.GraduationSerivce;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@Api(tags = "毕业院校查询")
@RestController
@RequestMapping("/school")
@Slf4j
public class GraduationController {
@Autowired
private GraduationSerivce graduationSerivce;
@ApiOperation(value = "毕业院校查询", notes = "毕业院校查询",httpMethod = "GET")
@GetMapping(value = "/getList")
public R<List<Graduation>> getSchool(){
return graduationSerivce.getList();
}
}
......@@ -77,11 +77,22 @@ public class SchemeRecordController {
})
@GetMapping("/export")
public R<Boolean> export(Integer userId, Integer recordId, HttpServletResponse response) {
log.info("volunteer-service[]SchemeRecordController[]getVolunteerList[]input.param.userId:{},recordId:" + userId, recordId);
log.info("volunteer-service[]SchemeRecordController[]getVolunteerList[]input.param.userId,recordId:" + userId, recordId);
if (null == userId || null == recordId) {
return R.error("入参为空!");
}
return schemeRecordService.export(userId, recordId,response);
}
@ApiOperation(value = "方案Excel导出",notes = "方案Excel导出",httpMethod = "GET")
@ApiImplicitParams({
@ApiImplicitParam(name = "userId", value = "用户id", dataType = "int", required = true),
@ApiImplicitParam(name = "recordId", value = "记录id", dataType = "int", required = true)
})
@GetMapping(value = "/createExcel")
public R<Boolean> createExcel(Integer userId, Integer recordId, HttpServletResponse response){
log.info("volunteer-service[]SchemeRecordController[]createExcel[]input.param.userId,recordId:" + userId, recordId);
return schemeRecordService.createExcel(userId,recordId,response);
}
}
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