|
@@ -1,12 +1,14 @@
|
|
|
package com.jpsoft.smart.modules.business.controller;
|
|
|
|
|
|
import com.github.pagehelper.Page;
|
|
|
+import com.jpsoft.smart.config.OSSConfig;
|
|
|
import com.jpsoft.smart.modules.base.entity.AlarmConfig;
|
|
|
import com.jpsoft.smart.modules.base.entity.CompanyInfo;
|
|
|
import com.jpsoft.smart.modules.base.entity.PersonInfo;
|
|
|
import com.jpsoft.smart.modules.base.service.AlarmConfigService;
|
|
|
import com.jpsoft.smart.modules.base.service.CompanyInfoService;
|
|
|
import com.jpsoft.smart.modules.base.service.PersonInfoService;
|
|
|
+import com.jpsoft.smart.modules.common.utils.OSSUtil;
|
|
|
import com.jpsoft.smart.modules.common.utils.PojoUtils;
|
|
|
import com.jpsoft.smart.modules.common.dto.Sort;
|
|
|
import com.jpsoft.smart.modules.common.dto.MessageResult;
|
|
@@ -18,10 +20,7 @@ import io.swagger.annotations.ApiImplicitParam;
|
|
|
import io.swagger.annotations.ApiImplicitParams;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
-import org.apache.poi.ss.usermodel.Row;
|
|
|
-import org.apache.poi.ss.usermodel.Sheet;
|
|
|
-import org.apache.poi.ss.usermodel.Workbook;
|
|
|
-import org.apache.poi.ss.usermodel.WorkbookFactory;
|
|
|
+import org.apache.poi.ss.usermodel.*;
|
|
|
import org.joda.time.DateTime;
|
|
|
import org.joda.time.Days;
|
|
|
import org.joda.time.Months;
|
|
@@ -33,17 +32,14 @@ import org.springframework.format.annotation.DateTimeFormat;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
-import java.io.FileInputStream;
|
|
|
-import java.io.FileOutputStream;
|
|
|
-import java.io.IOException;
|
|
|
-import java.io.InputStream;
|
|
|
+import java.io.*;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@RestController
|
|
|
-@RequestMapping("/workAttendance")
|
|
|
-@Api(description = "workAttendance")
|
|
|
+@RequestMapping("/business/workAttendance")
|
|
|
+@Api(description = "考勤统计表")
|
|
|
public class WorkAttendanceController {
|
|
|
private Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
|
|
@@ -59,201 +55,8 @@ public class WorkAttendanceController {
|
|
|
@Autowired
|
|
|
private AlarmConfigService alarmConfigService;
|
|
|
|
|
|
- @ApiOperation(value="创建空记录")
|
|
|
- @GetMapping("create")
|
|
|
- public MessageResult<WorkAttendance> create(){
|
|
|
- MessageResult<WorkAttendance> msgResult = new MessageResult<>();
|
|
|
-
|
|
|
- WorkAttendance workAttendance = new WorkAttendance();
|
|
|
-
|
|
|
- msgResult.setData(workAttendance);
|
|
|
- msgResult.setResult(true);
|
|
|
-
|
|
|
- return msgResult;
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value="添加信息")
|
|
|
- @PostMapping("add")
|
|
|
- public MessageResult<WorkAttendance> add(@RequestBody WorkAttendance workAttendance,@RequestAttribute String subject){
|
|
|
- MessageResult<WorkAttendance> msgResult = new MessageResult<>();
|
|
|
-
|
|
|
- try {
|
|
|
- workAttendance.setId(UUID.randomUUID().toString());
|
|
|
- workAttendance.setDelFlag(false);
|
|
|
- workAttendance.setCreateBy(subject);
|
|
|
- workAttendance.setCreateTime(new Date());
|
|
|
-
|
|
|
- int affectCount = workAttendanceService.insert(workAttendance);
|
|
|
-
|
|
|
- if (affectCount > 0) {
|
|
|
- msgResult.setResult(true);
|
|
|
- msgResult.setData(workAttendance);
|
|
|
- } else {
|
|
|
- msgResult.setResult(false);
|
|
|
- msgResult.setMessage("数据库添加失败");
|
|
|
- }
|
|
|
- }
|
|
|
- catch(Exception ex){
|
|
|
- logger.error(ex.getMessage(),ex);
|
|
|
-
|
|
|
- msgResult.setResult(false);
|
|
|
- msgResult.setMessage(ex.getMessage());
|
|
|
- }
|
|
|
-
|
|
|
- return msgResult;
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value="获取信息")
|
|
|
- @GetMapping("edit/{id}")
|
|
|
- public MessageResult<WorkAttendance> edit(@PathVariable("id") String id){
|
|
|
- MessageResult<WorkAttendance> msgResult = new MessageResult<>();
|
|
|
-
|
|
|
- try {
|
|
|
- WorkAttendance workAttendance = workAttendanceService.get(id);
|
|
|
-
|
|
|
- if (workAttendance != null) {
|
|
|
- msgResult.setResult(true);
|
|
|
- msgResult.setData(workAttendance);
|
|
|
- } else {
|
|
|
- msgResult.setResult(false);
|
|
|
- msgResult.setMessage("数据库不存在该记录!");
|
|
|
- }
|
|
|
- }
|
|
|
- catch(Exception ex){
|
|
|
- logger.error(ex.getMessage(),ex);
|
|
|
-
|
|
|
- msgResult.setResult(false);
|
|
|
- msgResult.setMessage(ex.getMessage());
|
|
|
- }
|
|
|
-
|
|
|
- return msgResult;
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value="更新用户")
|
|
|
- @PostMapping("update")
|
|
|
- public MessageResult<WorkAttendance> update(@RequestBody WorkAttendance workAttendance,@RequestAttribute String subject){
|
|
|
- MessageResult<WorkAttendance> msgResult = new MessageResult<>();
|
|
|
-
|
|
|
- try {
|
|
|
- workAttendance.setUpdateBy(subject);
|
|
|
- workAttendance.setUpdateTime(new Date());
|
|
|
-
|
|
|
- int affectCount = workAttendanceService.update(workAttendance);
|
|
|
-
|
|
|
- if (affectCount > 0) {
|
|
|
- msgResult.setResult(true);
|
|
|
- msgResult.setData(workAttendance);
|
|
|
- } else {
|
|
|
- msgResult.setResult(false);
|
|
|
- msgResult.setMessage("数据库更新失败");
|
|
|
- }
|
|
|
- }
|
|
|
- catch(Exception ex){
|
|
|
- logger.error(ex.getMessage(),ex);
|
|
|
-
|
|
|
- msgResult.setResult(false);
|
|
|
- msgResult.setMessage(ex.getMessage());
|
|
|
- }
|
|
|
-
|
|
|
- return msgResult;
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value="删除")
|
|
|
- @PostMapping("delete/{id}")
|
|
|
- public MessageResult<Integer> delete(@PathVariable("id") String id,@RequestAttribute String subject){
|
|
|
- MessageResult<Integer> msgResult = new MessageResult<>();
|
|
|
-
|
|
|
- try {
|
|
|
- WorkAttendance workAttendance = workAttendanceService.get(id);
|
|
|
- workAttendance.setDelFlag(true);
|
|
|
- workAttendance.setUpdateBy(subject);
|
|
|
- workAttendance.setUpdateTime(new Date());
|
|
|
-
|
|
|
- int affectCount = workAttendanceService.update(workAttendance);
|
|
|
-
|
|
|
- if (affectCount > 0) {
|
|
|
- msgResult.setResult(true);
|
|
|
- msgResult.setData(affectCount);
|
|
|
- } else {
|
|
|
- msgResult.setResult(false);
|
|
|
- msgResult.setMessage("删除失败");
|
|
|
- }
|
|
|
- }
|
|
|
- catch(Exception ex){
|
|
|
- logger.error(ex.getMessage(),ex);
|
|
|
-
|
|
|
- msgResult.setResult(false);
|
|
|
- msgResult.setMessage(ex.getMessage());
|
|
|
- }
|
|
|
-
|
|
|
- return msgResult;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- @ApiOperation(value="批量删除")
|
|
|
- @PostMapping("batchDelete")
|
|
|
- public MessageResult<Integer> batchDelete(@RequestBody List<String> idList,@RequestAttribute String subject){
|
|
|
- MessageResult<Integer> msgResult = new MessageResult<>();
|
|
|
-
|
|
|
- try {
|
|
|
- int affectCount = 0;
|
|
|
-
|
|
|
- for (String id : idList) {
|
|
|
- WorkAttendance workAttendance = workAttendanceService.get(id);
|
|
|
- workAttendance.setDelFlag(true);
|
|
|
- workAttendance.setUpdateBy(subject);
|
|
|
- workAttendance.setUpdateTime(new Date());
|
|
|
-
|
|
|
- affectCount += workAttendanceService.update(workAttendance);
|
|
|
- }
|
|
|
-
|
|
|
- if (affectCount > 0) {
|
|
|
- msgResult.setResult(true);
|
|
|
- msgResult.setData(affectCount);
|
|
|
- } else {
|
|
|
- msgResult.setResult(false);
|
|
|
- msgResult.setMessage("删除失败");
|
|
|
- }
|
|
|
- }
|
|
|
- catch(Exception ex){
|
|
|
- logger.error(ex.getMessage(),ex);
|
|
|
-
|
|
|
- msgResult.setResult(false);
|
|
|
- msgResult.setMessage(ex.getMessage());
|
|
|
- }
|
|
|
-
|
|
|
- return msgResult;
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value="列表")
|
|
|
- @RequestMapping(value = "pageList",method = RequestMethod.POST)
|
|
|
- public MessageResult<Map> pageList(
|
|
|
- String id,
|
|
|
- @RequestParam(value="pageIndex",defaultValue="1") int pageIndex,
|
|
|
- @RequestParam(value="pageSize",defaultValue="20") int pageSize,
|
|
|
- @RequestAttribute String subject){
|
|
|
-
|
|
|
- //当前用户ID
|
|
|
- System.out.println(subject);
|
|
|
-
|
|
|
- MessageResult<Map> msgResult = new MessageResult<>();
|
|
|
-
|
|
|
- Map<String,Object> searchParams = new HashMap<>();
|
|
|
-
|
|
|
- List<Sort> sortList = new ArrayList<>();
|
|
|
- sortList.add(new Sort("id_","asc"));
|
|
|
-
|
|
|
- if (StringUtils.isNotEmpty(id)) {
|
|
|
- searchParams.put("id","%" + id + "%");
|
|
|
- }
|
|
|
-
|
|
|
- Page<WorkAttendance> page = workAttendanceService.pageSearch(searchParams,pageIndex,pageSize,true,sortList);
|
|
|
-
|
|
|
- msgResult.setResult(true);
|
|
|
- msgResult.setData(PojoUtils.pageWrapper(page));
|
|
|
-
|
|
|
- return msgResult;
|
|
|
- }
|
|
|
+ @Autowired
|
|
|
+ private OSSConfig ossConfig;
|
|
|
|
|
|
@ApiOperation(value="导出考勤记录")
|
|
|
@ApiImplicitParams({
|
|
@@ -263,7 +66,7 @@ public class WorkAttendanceController {
|
|
|
@ApiImplicitParam(name = "subject",value = "subject", required = false,paramType="form")
|
|
|
})
|
|
|
@RequestMapping(value = "exportXls",method = RequestMethod.POST)
|
|
|
- public MessageResult<List> exportXls(
|
|
|
+ public MessageResult<String> exportXls(
|
|
|
String companyId,
|
|
|
@DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,
|
|
|
@DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate,
|
|
@@ -272,9 +75,17 @@ public class WorkAttendanceController {
|
|
|
//当前用户ID
|
|
|
System.out.println(subject);
|
|
|
|
|
|
- MessageResult<List> msgResult = new MessageResult<>();
|
|
|
+ MessageResult<String> msgResult = new MessageResult<>();
|
|
|
|
|
|
try {
|
|
|
+ if (startDate==null){
|
|
|
+ startDate = DateTime.now().dayOfMonth().withMinimumValue().toDate();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (endDate==null){
|
|
|
+ endDate = DateTime.now().plusMonths(1).dayOfMonth().withMinimumValue().toDate();
|
|
|
+ }
|
|
|
+
|
|
|
//todo 起始时间与结束时间间隔最大1个月
|
|
|
DateTime startTime = new DateTime(startDate);
|
|
|
DateTime endTime = new DateTime(endDate);
|
|
@@ -293,7 +104,12 @@ public class WorkAttendanceController {
|
|
|
int dayOfWorkAttendanceNum = alarmConfigList.size();
|
|
|
|
|
|
//todo 查询单位人员
|
|
|
- List<PersonInfo> personInfoList = personInfoService.findByCompanyCode(companyInfo.getCode() + "%");
|
|
|
+ List<Sort> sortList = new ArrayList<>();
|
|
|
+ sortList.add(new Sort("position1_","asc"));
|
|
|
+ sortList.add(new Sort("position2_","asc"));
|
|
|
+ sortList.add(new Sort("position3_","asc"));
|
|
|
+
|
|
|
+ List<PersonInfo> personInfoList = personInfoService.findByCompanyCode(companyInfo.getCode() + "%",sortList);
|
|
|
|
|
|
int days = Days.daysBetween(startTime,endTime).getDays();
|
|
|
|
|
@@ -383,9 +199,9 @@ public class WorkAttendanceController {
|
|
|
|
|
|
//todo 生成报表
|
|
|
// String tmplFilePath = "E:\\workAttendanceReport.xlsx";
|
|
|
- createReport(startTime,endTime,personMapList);
|
|
|
+ String downloadUrl = createReport(startTime,endTime,personMapList);
|
|
|
|
|
|
- msgResult.setData(personMapList);
|
|
|
+ msgResult.setData(downloadUrl);
|
|
|
msgResult.setResult(true);
|
|
|
}
|
|
|
catch (Exception ex){
|
|
@@ -397,7 +213,20 @@ public class WorkAttendanceController {
|
|
|
return msgResult;
|
|
|
}
|
|
|
|
|
|
- private void createReport(DateTime startTime,DateTime endTime,List<Map> personMapList) throws Exception {
|
|
|
+ private CellStyle createCellStyle(Workbook wb){
|
|
|
+ CellStyle cellStyle = wb.createCellStyle();
|
|
|
+
|
|
|
+ cellStyle.setBorderTop(BorderStyle.THIN);
|
|
|
+ cellStyle.setBorderBottom(BorderStyle.THIN);
|
|
|
+ cellStyle.setBorderLeft(BorderStyle.THIN);
|
|
|
+ cellStyle.setBorderRight(BorderStyle.THIN);
|
|
|
+ cellStyle.setWrapText(true);
|
|
|
+ cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
+
|
|
|
+ return cellStyle;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String createReport(DateTime startTime,DateTime endTime,List<Map> personMapList) throws Exception {
|
|
|
int days = Days.daysBetween(startTime,endTime).getDays();
|
|
|
ClassPathResource resource = new ClassPathResource("static/workAttendanceReport.xlsx");
|
|
|
|
|
@@ -483,7 +312,7 @@ public class WorkAttendanceController {
|
|
|
}
|
|
|
|
|
|
if (WorkAttendance.SUCCESS.equals(item.getResult())){
|
|
|
- sb.append("正常打卡");
|
|
|
+ sb.append("打卡");
|
|
|
}
|
|
|
else if (WorkAttendance.LATE.equals(item.getResult())){
|
|
|
sb.append("迟到");
|
|
@@ -507,10 +336,35 @@ public class WorkAttendanceController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- FileOutputStream output = new FileOutputStream("E:\\output.xlsx");
|
|
|
+ CellStyle cellStyle1 = createCellStyle(wb);
|
|
|
+
|
|
|
+ for (int i=0;i<personMapList.size();i++) {
|
|
|
+ Row row = sheet.getRow(startRowIndex + i);
|
|
|
+
|
|
|
+ if (row!=null) {
|
|
|
+ for (int j = 0; j < row.getLastCellNum(); j++) {
|
|
|
+ if (row.getCell(j) != null) {
|
|
|
+ row.getCell(j).setCellStyle(cellStyle1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //todo 将wb保存到oss
|
|
|
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
|
|
|
+ wb.write(output);
|
|
|
+
|
|
|
+ byte[] buffer = output.toByteArray();
|
|
|
+ ByteArrayInputStream input = new ByteArrayInputStream(buffer);
|
|
|
+
|
|
|
+ String fileName = "考勤统计表.xlsx";
|
|
|
+
|
|
|
+ String downloadUrl = OSSUtil.upload(ossConfig,"workAttendance",fileName,input);
|
|
|
|
|
|
wb.write(output);
|
|
|
wb.close();
|
|
|
output.close();
|
|
|
+
|
|
|
+ return downloadUrl;
|
|
|
}
|
|
|
}
|