Commit ec039315 authored by nie'hong's avatar nie'hong

添加导出

parent 1346ecd3
...@@ -51,10 +51,10 @@ public interface WorkTimeOrderMapper extends BaseMapper<WorkTimeOrder> { ...@@ -51,10 +51,10 @@ public interface WorkTimeOrderMapper extends BaseMapper<WorkTimeOrder> {
/** /**
* @param year * @param year
* @param month * @param month
* @param userId * @param userIds
* @return * @return
*/ */
List<DayWorkTimeAndType> listByDateAndUserId(@Param("year") Integer year, @Param("month") Integer month, @Param("userId") Integer userId); List<DayWorkTimeAndType> listByDateAndUserId(@Param("year") Integer year, @Param("month") Integer month, @Param("userIds") List<Integer> userIds);
/** /**
......
package cn.wisenergy.mapper; package cn.wisenergy.mapper;
import cn.wisenergy.model.app.WorkUser; import cn.wisenergy.model.app.WorkUser;
import cn.wisenergy.model.dto.StatisticsTableDto;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
...@@ -26,5 +28,6 @@ public interface WorkUserMapper extends BaseMapper<WorkUser> { ...@@ -26,5 +28,6 @@ public interface WorkUserMapper extends BaseMapper<WorkUser> {
Integer updateUserInfo(WorkUser user); Integer updateUserInfo(WorkUser user);
List<StatisticsTableDto> getStatisticsTableDtos(List<Integer> userIds);
} }
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
</sql> </sql>
<resultMap id="dayWorkTimeAndType" type="cn.wisenergy.model.dto.DayWorkTimeAndType"> <resultMap id="dayWorkTimeAndType" type="cn.wisenergy.model.dto.DayWorkTimeAndType">
<result property="userId" column="user_id"/>
<result property="day" column="day(work_day)"/> <result property="day" column="day(work_day)"/>
<result property="type" column="type"/> <result property="type" column="type"/>
<result property="workTime" column="sum(work_time)"/> <result property="workTime" column="sum(work_time)"/>
...@@ -143,10 +144,13 @@ ...@@ -143,10 +144,13 @@
</select> </select>
<select id="listByDateAndUserId" resultMap="dayWorkTimeAndType"> <select id="listByDateAndUserId" resultMap="dayWorkTimeAndType">
select user_id,day(work_day),CASE when `type` = 3 then 1 when `type` = 4 then 2 else 0 end AS `type`, sum(work_time) select user_id,day(work_day),CASE when `type` = 3 then "请假" when `type` = 4 then "调休" else "正常" end AS `type`, sum(work_time)
from <include refid="table"/> from <include refid="table"/>
where year(work_day) = #{year} AND month(work_day) = #{month} AND user_id = #{userId} AND status in (2,5) where year(work_day) = #{year} AND month(work_day) = #{month} AND (status = 2 OR status=5)AND user_id IN
group by user_id,day(work_day), CASE when `type` = 3 then 1 when `type` = 4 then 2 else 0 end <foreach collection="userIds" separator="," close=")" item="userId" open="(">
#{userId}
</foreach>
group by user_id,day(work_day), CASE when `type` = 3 then "请假" when `type` = 4 then "调休" else "正常" end
order by day(work_day) order by day(work_day)
</select> </select>
......
...@@ -85,6 +85,14 @@ ...@@ -85,6 +85,14 @@
from <include refid="table"/> from <include refid="table"/>
where id = #{userId} where id = #{userId}
</select> </select>
<select id="getStatisticsTableDtos" resultType="cn.wisenergy.model.dto.StatisticsTableDto">
select u.id AS user_id, u.name AS dept_name, d.dept_name
from work_user u join work_dept d on u.dept_id=d.id
where u.id in
<foreach collection="list" open="(" close=")" separator="," item="id">
#{id}
</foreach>
</select>
<update id="updateUserInfo" parameterType="cn.wisenergy.model.app.WorkUser"> <update id="updateUserInfo" parameterType="cn.wisenergy.model.app.WorkUser">
update <include refid="table"/> update <include refid="table"/>
......
...@@ -17,6 +17,12 @@ public class DayWorkTimeAndType implements Serializable { ...@@ -17,6 +17,12 @@ public class DayWorkTimeAndType implements Serializable {
private static final long serialVersionUID = 1198786417184957375L; private static final long serialVersionUID = 1198786417184957375L;
/**
* 用户主键
*/
@ApiModelProperty(name = "userId", value = "用户主键")
private Integer userId;
/** /**
* 日期中的日 * 日期中的日
*/ */
...@@ -24,10 +30,10 @@ public class DayWorkTimeAndType implements Serializable { ...@@ -24,10 +30,10 @@ public class DayWorkTimeAndType implements Serializable {
private Integer day; private Integer day;
/** /**
* 工时类型,0:正常,1:请假,2:调休 * 工时类型,正常,请假,调休
*/ */
@ApiModelProperty(name = "type", value = "工时类型,0:正常,1:请假,2:调休") @ApiModelProperty(name = "type", value = "工时类型,正常,请假,调休")
private Integer type; private String type;
/** /**
* 工时 * 工时
......
...@@ -3,6 +3,7 @@ package cn.wisenergy.service; ...@@ -3,6 +3,7 @@ package cn.wisenergy.service;
import cn.wisenergy.model.dto.GetMonthlyCollectParam; import cn.wisenergy.model.dto.GetMonthlyCollectParam;
import cn.wisenergy.model.dto.WorkTimeAndCostCollect; import cn.wisenergy.model.dto.WorkTimeAndCostCollect;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import java.util.List; import java.util.List;
...@@ -27,4 +28,12 @@ public interface StatisticsService { ...@@ -27,4 +28,12 @@ public interface StatisticsService {
* @param userId * @param userId
*/ */
List<WorkTimeAndCostCollect> getCurrentMonthWorkTimeCollect(Integer userId, String startTime); List<WorkTimeAndCostCollect> getCurrentMonthWorkTimeCollect(Integer userId, String startTime);
/**
* 导出一个部门下员工一个月中每天的工时
* @param param
* @return
*/
HSSFWorkbook exportWorkTimeExcel(GetMonthlyCollectParam param);
} }
...@@ -14,11 +14,15 @@ import io.swagger.annotations.Api; ...@@ -14,11 +14,15 @@ 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;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
import java.net.URLEncoder;
import java.util.List; import java.util.List;
/** /**
...@@ -77,4 +81,33 @@ public class StatisticsController extends BaseController { ...@@ -77,4 +81,33 @@ public class StatisticsController extends BaseController {
return getResult(monthlyStatistics); return getResult(monthlyStatistics);
} }
@ApiOperation(value = "导出部门员工一个月每天的工时", notes = "导出部门员工一个月每天的工时")
@GetMapping("/exportWorkTime")
public void export(GetMonthlyCollectParam param, HttpServletResponse response) {
log.info("StatisticsController[]getDeptInfo[]input.param" + param);
// 获取excel
HSSFWorkbook sheets = statisticsService.exportWorkTimeExcel(param);
// 获取excel中的第2行第2列中的部门名称
String deptName = sheets.getSheet("Sheet1").getRow(1).getCell(1).getStringCellValue();
// 文件名
String fileName = deptName + "-" + param.getYear() + "-" + param.getMonth();
//响应类型为application/octet- stream情况下使用了这个头信息的话,那就意味着不想直接显示内容
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
//attachment为以附件方式下载
try {
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(
fileName + ".xls",
"utf-8"));
response.setHeader("Cache-Control", "No-cache");
response.flushBuffer();
sheets.write(response.getOutputStream());
sheets.close();
} catch (Exception e) {
throw new BaseCustomException(BASE_RESP_CODE_ENUM.SERVER_ERROR);
}
}
} }
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