package com.cloud.attendance.controller;
|
|
import com.alibaba.fastjson.JSONObject;
|
import com.cloud.attendance.model.AttDay;
|
import com.cloud.attendance.model.EsAttExcelData;
|
import com.cloud.attendance.service.AttDayService;
|
import com.cloud.attendance.service.QueryEsService;
|
import com.cloud.attendance.utils.EnumStr;
|
import com.cloud.attendance.utils.ExportExcelUtils;
|
import com.cloud.model.common.Result;
|
import io.swagger.annotations.*;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.commons.lang3.StringUtils;
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.format.annotation.DateTimeFormat;
|
import org.springframework.http.MediaType;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletResponse;
|
import java.text.SimpleDateFormat;
|
import java.util.*;
|
import java.util.List;
|
import java.util.Map;
|
|
@Slf4j
|
@Api( value = "AttDayController",description = "考勤记录查询")
|
@RestController
|
@RequestMapping("/api-a/att")
|
public class AttDayController {
|
|
@Autowired
|
private AttDayService attDayService;
|
@Autowired
|
private QueryEsService queryEsService;
|
|
private String queryEsParam = "queryEsParam";
|
|
private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
private SimpleDateFormat sdfTime = new SimpleDateFormat("HH:mm:ss");
|
private SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd");
|
@ApiOperation(value = "查询单人某月考勤记录", notes = "查询考勤记录", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "mouthDate", value = "年-月 2018-11", required = true, dataType = "string", paramType = "query" ,example="2018-11"),
|
@ApiImplicitParam(name = "personId", value = "查询人id 9f25143b-2663-52cf-973b-72295c19fae1", required = true, dataType = "string", paramType = "query",example="5767")
|
})
|
@PostMapping("/queryperson")
|
public Result queryperson( String mouthDate, String personId){
|
try{
|
log.info("mouthDate:"+mouthDate+"personId:"+personId);
|
return Result.ok("查询单人某月考勤记录成功", attDayService.findPerDayRecord(mouthDate,personId));
|
}catch(Exception e){
|
log.error(e.getLocalizedMessage());
|
return Result.error(e);
|
}
|
}
|
|
@ApiOperation(value = "导出单人某月考勤记录", notes = "导出单人某月考勤记录", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "mouthDate", value = "年-月 2018-11", required = true, dataType = "string", paramType = "query" ,example="2018-11"),
|
@ApiImplicitParam(name = "personId", value = "查询人id 9f25143b-2663-52cf-973b-72295c19fae1", required = true, dataType = "string", paramType = "query",example="5767")
|
})
|
@GetMapping("/poiPersonMouuthDataExcel")
|
public void excelPersonData(String mouthDate,String personId,HttpServletResponse response,HttpServletRequest req){
|
personId = req.getParameter("personId");
|
mouthDate = req.getParameter("mouthDate");
|
log.info("mouthDate:"+mouthDate+"personId:"+personId);
|
Map<String, Object> perDayRecord = attDayService.findPerDayRecord(mouthDate, personId);
|
Object employeeName = perDayRecord.get("employeeName");
|
Object identity = perDayRecord.get("identity");
|
EsAttExcelData<List<Object>> data = new EsAttExcelData<List<Object>>();
|
data.setName(""+employeeName+mouthDate+"月考勤记录");
|
List<String> titles = new ArrayList();
|
// {"pid","pname","photo","identity","indeviceid","indevicename","onlinetime","Snapshotpath"}
|
titles.add("日期");titles.add("考勤时间(首次)"); titles.add("首次考勤位置");
|
titles.add("考勤时间(末次)");// titles.add("人员Id");
|
titles.add("末次考勤位置");titles.add("考勤状态");
|
data.setTitles(titles);
|
List<List<Object>> rows = new ArrayList();
|
List<AttDay> attDays = ( List<AttDay>) perDayRecord.get("dayList");
|
for (AttDay attDay : attDays) {
|
ArrayList<Object> obj = new ArrayList<>();
|
obj.add(attDay.getSignDate()!=null?sdfDate.format(attDay.getSignDate()):"");
|
obj.add(attDay.getInTime()!=null?sdfTime.format(attDay.getInTime()):"");
|
obj.add(attDay.getInDeviceName());
|
obj.add(attDay.getOutTime()!=null?sdfTime.format(attDay.getOutTime()):"");
|
obj.add(attDay.getOutDeviceName());
|
obj.add(attDay.getDayStatus());
|
rows.add(obj);
|
}
|
try {
|
data.setRows(rows);
|
String fileName = "" + (employeeName==null?"":employeeName) + mouthDate + "月考勤记录.xlsx"; // .xlsx + (identity==null?"":identity)
|
String s = new String((fileName).getBytes("utf-8"), "utf-8");
|
ExportExcelUtils.exportObjectExcel(response,fileName,data);
|
// return Result.ok("导出单人某月考勤记录成功","导出单人某月考勤记录");
|
} catch (Exception e){
|
e.printStackTrace();
|
}
|
}
|
@ApiOperation(value = "查询多人某月考勤记录", notes = "查询多人某月考勤记录", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_UTF8_VALUE
|
, response = Result.class)
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "mouthDate", value = "年-月 2018-11", required = true, dataType = "String", paramType = "query"),
|
@ApiImplicitParam(name = "gradeValue", value = "年级 暂无", required = false, dataType = "String", paramType = "query"),
|
@ApiImplicitParam(name = "classValue", value = "班级 暂无", required = false, dataType = "String", paramType = "query"),
|
@ApiImplicitParam(name = "identity", value = "身份 student/teacher", required = true, dataType = "String", paramType = "query"),
|
@ApiImplicitParam(name = "delFlag", value = "是否已删除 true包含/false不包含", required = false, dataType = "boolean", paramType = "query"),
|
@ApiImplicitParam(name = "days", value = "30 默认30", required = false, dataType = "long", paramType = "query"),
|
@ApiImplicitParam(name = "orgIds", value = "组织机构id集合", required = false, dataType = "String", paramType = "query")
|
})
|
@PostMapping("/morequery")
|
public Result save(@RequestParam String mouthDate,@RequestParam(required = false) String gradeValue,
|
@RequestParam(required = false) String classValue,
|
@RequestParam(required = false) String orgIds,@RequestParam(required = false) Boolean delFlag, // 是否包含已删除
|
@RequestParam(required = false,defaultValue ="30") Integer days
|
,@RequestParam(required = true) String identity){
|
if ("".equals(gradeValue)||"all".equalsIgnoreCase(gradeValue)){ gradeValue =null; }
|
if ("".equals(classValue)||"all".equalsIgnoreCase(classValue))classValue = null;
|
log.info("mouthDate:"+mouthDate+"gradeValue:"+gradeValue+"classValue:"+classValue+"identity:"+identity+"days"+days+"orgIds:"+orgIds);
|
return Result.ok("查询多人"+mouthDate+"月考勤记录成功", attDayService.findAllDayRecord(mouthDate,gradeValue,classValue,identity,days,delFlag,orgIds));
|
}
|
|
@ApiOperation(value = "请假或补签接口", notes = "修改某人某天考勤记录---暂不用18-11-09", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "recordId", value = "考勤记录Id", required = true, dataType = "long", paramType = "query"),
|
@ApiImplicitParam(name = "mouthDay", value = "年-月-日", required = false,dataType = "date", paramType = "query"),
|
@ApiImplicitParam(name = "leaveOrRepair", value = "leave 请假 repair 补签", required = true, dataType = "String", paramType = "query")
|
})
|
@PostMapping("/updateRecord")
|
public Result updateRecord(@RequestParam Long recordId,
|
@RequestParam(required = false) Date mouthDay,
|
@RequestParam String leaveOrRepair){
|
if ("".equals(mouthDay)){
|
mouthDay = null;
|
}
|
log.info("recordId:"+recordId+"mouthDay:"+mouthDay+"leaveOrRepair"+leaveOrRepair);
|
return Result.ok("请假或补签成功", attDayService.updateDayRecord(recordId,mouthDay,leaveOrRepair));
|
}
|
|
@ApiOperation(value = "流水记录查询接口", notes = "流水记录查询", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "contentValue", value = "姓名/身份证号/学号 曹 1211", required = false, dataType = "string", paramType = "query"),
|
@ApiImplicitParam(name = "location", value = "位置 北门考勤机", required = false, dataType = "string", paramType = "query"),
|
@ApiImplicitParam(name = "identity", value = "身份 学生student老师teacher", required = false, dataType = "string", paramType = "query"),
|
@ApiImplicitParam(name = "orgIds", value = "组织机构id 集合", required = false, dataType = "string", paramType = "query"),
|
@ApiImplicitParam(name = "gradeValue", value = "年级", required = false, dataType = "String", paramType = "query"),
|
@ApiImplicitParam(name = "classValue", value = "班级", required = false, dataType = "String", paramType = "query"),
|
@ApiImplicitParam(name = "order", value = "排序 descending ascending", required = false, dataType = "String", paramType = "query"),
|
@ApiImplicitParam(name = "orderName", value = "排序列 pname identity indevicename onlinetime", required = false, dataType = "String", paramType = "query"),
|
@ApiImplicitParam(name = "delFlag", value = "是否包含已上除 true包含/false", required = false, dataType = "boolean", paramType = "query"),
|
@ApiImplicitParam(name = "startTime", value = "起始时间 2018/11/03 12:00:00", required = true, dataType = "date",
|
paramType = "query",example = "2018/11/30 12:00:00"),
|
@ApiImplicitParam(name = "endTime", value = "结束时间 2018/11/29 12:00:00", required = true, dataType = "date", paramType = "query"
|
,example = "2018/11/29 12:00:00"),
|
@ApiImplicitParam(name = "page", value = "页数 1", required = false, dataType = "int32", paramType = "query"),
|
@ApiImplicitParam(name = "size", value = "每页条数 10", required = false, dataType = "int32", paramType = "query")
|
})
|
@PostMapping("/queryEsRecord")
|
public Result queryEsRecord(
|
@RequestParam(required = false) String contentValue,@RequestParam(required = false) String location,
|
@RequestParam(required = false) String identity,@RequestParam(required = false) String gradeValue,
|
@RequestParam(required = false) String classValue, @RequestParam(required = false) String orgIds, // 多组织机构数据 , 拼接
|
@RequestParam(name = "order",required = false,defaultValue = "descending") String sortDate,
|
@RequestParam(name = "delFlag",required = false,defaultValue = "false") Boolean delFlag,
|
@RequestParam Date startTime, // @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
|
@RequestParam Date endTime, // @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
|
@RequestParam(required = false,defaultValue = "1") Integer page,String orderName,
|
@RequestParam(required = false,defaultValue = "10") Integer size, HttpServletRequest request){
|
if ("".equals(contentValue)){contentValue =null;}
|
if ("".equals(location)){location =null;}
|
if ("".equals(identity)||"all".equalsIgnoreCase(identity)){identity = null;}
|
if ("".equals(gradeValue)||"all".equalsIgnoreCase(gradeValue)){gradeValue = null;}
|
if ("".equals(classValue)||"all".equalsIgnoreCase(classValue)){classValue = null;}
|
if (sortDate.equalsIgnoreCase("descending")){
|
sortDate = "desc";
|
}else { sortDate = "asc"; }
|
List<String> orgIdList = new ArrayList<>();
|
if (!StringUtils.isBlank(orgIds)){
|
String[] ids = orgIds.split(",");
|
orgIdList = Arrays.asList(ids);
|
}
|
Map<String,Object> map = new HashMap<String, Object>();
|
map.put("contentValue",contentValue); map.put("location",location); map.put("identity",identity);
|
map.put("delFlag",delFlag); map.put("orgIds",orgIdList);map.put("orderName",orderName);
|
map.put("gradeValue",gradeValue); map.put("classValue",classValue );map.put("sortDate",sortDate);
|
map.put("startTime",startTime);map.put("endTime",endTime); map.put("page",page); map.put("size",size);
|
request.getSession().setAttribute(queryEsParam,map);
|
log.info("流水记录查询 参数:"+map);
|
return Result.ok("流水记录查询成功", queryEsService.queryAttRecord(contentValue,location,
|
identity,gradeValue,classValue,delFlag,orgIdList,orderName,sortDate,startTime,endTime, page, size));
|
}
|
@ApiOperation(value = "搜索流水记录导出接口", notes = "流水记录导出", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
|
@ApiImplicitParams({
|
})
|
@RequestMapping(value = "/searchExcel", method = RequestMethod.GET)
|
public void poiEsRecord( HttpServletResponse response,HttpServletRequest request){
|
EsAttExcelData<JSONObject> data = new EsAttExcelData<JSONObject>();
|
data.setName("考勤流水记录");
|
List<String> titles = new ArrayList();
|
String contentValue=null,location=null,identity=null,gradeValue =null,classValue =null,sortDate=null,orderName = null;
|
Date startTime =null,endTime =null;Integer page = null,size =null; Boolean delFlag = false;List<String> orgIds = null;
|
// {"pid","pname","photo","identity","indeviceid","indevicename","onlinetime","Snapshotpath"}
|
titles.add("人员Id"); titles.add("姓名");titles.add("身份证号");titles.add("人员属性");titles.add("考勤时间");
|
// titles.add("人员图片");
|
titles.add("设备Id");titles.add("设备名称");titles.add("设备地址");
|
// titles.add("抓拍图片");
|
data.setTitles(titles);
|
Map<String,Object> params = (Map<String, Object>) request.getSession().getAttribute(queryEsParam);
|
if(params !=null){
|
contentValue = (String) params.get("contentValue");
|
location = (String) params.get("location");
|
identity = (String) params.get("identity");
|
gradeValue = (String) params.get("gradeValue");
|
classValue = (String) params.get("classValue");
|
delFlag = (Boolean) params.get("delFlag");
|
orgIds = (List<String>) params.get("orgIds");
|
sortDate = (String) params.get("sortDate");
|
orderName = (String) params.get("orderName");
|
startTime = (Date) params.get("startTime");
|
endTime = (Date) params.get("endTime");
|
page = (Integer) params.get("page");
|
size = (Integer) params.get("size");
|
}else{
|
RuntimeException re = new RuntimeException("导出考勤数据失败,请重新搜索数据再导出。");
|
throw re;
|
}
|
Map<String, Object> record = queryEsService.queryAttRecord(contentValue, location,
|
identity, gradeValue, classValue,delFlag,orgIds, orderName, sortDate,startTime, endTime, 1, 10000);
|
List<List<Object>> rows = new ArrayList();
|
List<JSONObject> esAttList = (List<JSONObject>) record.get("esAttList");
|
|
data.setRows(esAttList);
|
try {
|
String s = new String(("考勤记录.xlsx").getBytes("utf-8"), "utf-8");
|
ExportExcelUtils.exportExcel(response,s,data);
|
// return Result.ok("导出考勤数据成功!",null);
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
|
}
|
/* @ApiOperation(value = "流水记录导出接口", notes = "流水记录导出--暂不用", httpMethod = "GET", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
@ApiImplicitParams({
|
})*/
|
// @RequestMapping(value = "/AllRecordExcel", method = RequestMethod.GET)
|
public Result poiAllEsRecord( HttpServletResponse response,HttpServletRequest request){
|
XSSFWorkbook wb =null;
|
EsAttExcelData data = new EsAttExcelData();
|
data.setName("考勤流水记录");
|
List<String> titles = new ArrayList();
|
String contentValue=null,location=null,identity=null,gradeValue =null,classValue =null,sortDate = null,orderName = null;
|
Date startTime =null,endTime =null;Integer page = null,size =null;Boolean delFlag = false;List<String> orgIds = null;
|
// {"pid","pname","photo","identity","indeviceid","indevicename","onlinetime","Snapshotpath"}
|
titles.add("人员Id"); titles.add("名字"); titles.add("人员图片");titles.add("身份");
|
titles.add("设备Id");titles.add("设备名称"); titles.add("考勤时间");titles.add("抓拍图片");
|
data.setTitles(titles);
|
Map<String,Object> params = (Map<String, Object>) request.getSession().getAttribute("queryEsParam");
|
if(params !=null){
|
contentValue = (String) params.get("contentValue");location = (String) params.get("location");
|
identity = (String) params.get("identity");gradeValue = (String) params.get("gradeValue");
|
classValue = (String) params.get("classValue");delFlag = (Boolean) params.get("delFlag");
|
orgIds = (List<String>) params.get("orgIds");sortDate = (String) params.get("sortDate");
|
orderName = (String) params.get("orderName");startTime = (Date) params.get("startTime");
|
endTime = (Date) params.get("endTime");page = (Integer) params.get("page");
|
size = (Integer) params.get("size");
|
}else{
|
RuntimeException re = new RuntimeException("导出考勤数据失败!");
|
throw re;
|
}
|
Map<String, Object> record = queryEsService.queryAttRecord(contentValue, location,
|
identity, gradeValue, classValue,delFlag,orgIds, orderName, sortDate, startTime, endTime, 1, 10000);
|
Integer total = (Integer) record.get("total");
|
if (total>0){
|
List<JSONObject> esAttList = null; page = 2;
|
do {
|
/* for (int i=0,item = esAttList.size(); i<item;i++){
|
List<Object> row = new ArrayList();
|
row.add("id"+i);
|
row.add("名字"+i);
|
row.add("http://192.168.1.203"+i);
|
row.add(sdf.format(new Date()));
|
rows.add(row);
|
}*/
|
esAttList = (List<JSONObject>) record.get("esAttList");
|
data.setRows(esAttList);
|
//生成本地
|
/*File f = new File("c:/test.xlsx");
|
FileOutputStream out = new FileOutputStream(f);
|
ExportExcelUtils.exportExcel(data, out);
|
out.close();*/
|
try {
|
ExportExcelUtils.exportMoreExcel(response, "多人考勤流水记录" + (page - 1) + ".xlsx", data);
|
record = queryEsService.queryAttRecord(contentValue, location,
|
identity, gradeValue, classValue,delFlag,orgIds, orderName, sortDate, startTime, endTime, page++, 10000);
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}while(esAttList.size()>0 || page >9);
|
}
|
return Result.ok("导出考勤数据成功!",null);
|
}
|
|
@ApiOperation(value = "查询个人单日考勤流水接口", notes = "查询个人单日考勤流水查询", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "id", value = "personId 9f25143b-2663-52cf-973b-72295c19fae1", required = true, dataType = "string", paramType = "query"),
|
@ApiImplicitParam(name = "beginTime", value = "起始时间 2019-03-21", required = true, dataType = "date",
|
paramType = "query",example = "2018/11/06"),
|
@ApiImplicitParam(name = "endTime", value = "结束时间 2019-03-21", required = true, dataType = "date", paramType = "query"
|
,example = "2018/11/06")
|
})
|
// @AuthNoneIgnore
|
@PostMapping("/queryPersonById")
|
public Result queryPersonById(@RequestParam String id,@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date beginTime,
|
@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date endTime){
|
try{
|
return Result.ok("查询个人单日考勤流水成功!",
|
queryEsService.queryPersonById(id,beginTime,endTime));
|
}catch (Exception e){
|
e.printStackTrace();
|
log.error(e.getLocalizedMessage());
|
return Result.error(e);
|
}
|
}
|
|
@ApiOperation(value = "导出单人单日考勤记录", notes = "导出单人单日考勤记录", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "id", value = "personId 9f25143b-2663-52cf-973b-72295c19fae1", required = true, dataType = "string", paramType = "query"),
|
@ApiImplicitParam(name = "dayTime", value = "起始时间 2018-11-06", required = true, dataType = "date",
|
paramType = "query",example = "2018-11-06")
|
})
|
@RequestMapping(value = "/poiPersonDayDataExcel",method = RequestMethod.GET)
|
public void excelPersonDayData(@RequestParam(value = "id") String personId,
|
@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date dayTime,
|
HttpServletResponse response,
|
HttpServletRequest req){
|
try{
|
String id = req.getParameter("id");
|
log.info(id+"id参数变化");
|
String mouthDate = sdfDate.format(dayTime);
|
log.info("导出单人单日参数:beginTime:"+mouthDate+"personId:"+id);
|
Map<String, Object> perDayRecord = queryEsService.queryPersonById(id, dayTime, dayTime);
|
Object employeeName = perDayRecord.get(EnumStr.pnameShow);
|
Object idCard = perDayRecord.get(EnumStr.idCardField);if (idCard == null){idCard ="";}
|
EsAttExcelData<List<Object>> data = new EsAttExcelData<List<Object>>();
|
String fileName = ""+(employeeName==null||"".equals(employeeName)?idCard:employeeName)+mouthDate+"考勤记录"; // (identity==null?"":identity)+
|
data.setName(fileName);
|
log.info("employeeName:"+employeeName+"idCard:"+idCard+"mouthDate:"+mouthDate);
|
List<String> titles = new ArrayList();
|
// {"pid","pname","photo","identity","indeviceid","indevicename","onlinetime","Snapshotpath"}
|
// titles.add("人员Id"); titles.add("设备ID"); // 2018-12-21
|
titles.add("考勤时间"); titles.add("考勤位置");
|
// titles.add("抓拍图片");
|
data.setTitles(titles);
|
List<List<Object>> rows = new ArrayList();
|
List<JSONObject> attDays = (List<JSONObject>) perDayRecord.get("dayList");
|
for (JSONObject attDay : attDays) {
|
ArrayList<Object> obj = new ArrayList<>();
|
// obj.add(attDay.getString("pid"));
|
// obj.add(attDay.getString("indeviceid"));
|
obj.add(attDay.getString("onlinetime"));
|
obj.add(attDay.getString("indevicename")); // indevicename
|
// obj.add(attDay.getString("Snapshotpath"));
|
rows.add(obj);
|
}
|
data.setRows(rows);
|
String s = new String((fileName+".xlsx").getBytes("utf-8"), "utf-8");
|
ExportExcelUtils.exportObjectExcel(response,s,data);
|
// return Result.ok("导出单人单日考勤记录成功","导出单人单日考勤记录");
|
}catch(Exception e){
|
log.error(e.getLocalizedMessage());
|
// return Result.error(e);
|
}
|
}
|
|
}
|