/*
|
* Copyright (c) 2018-2025, ztt All rights reserved.
|
*
|
* Redistribution and use in source and binary forms, with or without
|
* modification, are permitted provided that the following conditions are met:
|
*
|
* Redistributions of source code must retain the above copyright notice,
|
* this list of conditions and the following disclaimer.
|
* Redistributions in binary form must reproduce the above copyright
|
* notice, this list of conditions and the following disclaimer in the
|
* documentation and/or other materials provided with the distribution.
|
* Neither the name of the pig4cloud.com developer nor the names of its
|
* contributors may be used to endorse or promote products derived from
|
* this software without specific prior written permission.
|
* Author: ztt
|
*/
|
|
package com.chinaztt.mes.production.controller;
|
|
import com.alibaba.excel.EasyExcel;
|
import com.alibaba.excel.ExcelWriter;
|
import com.alibaba.excel.write.metadata.WriteSheet;
|
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
|
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSONObject;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.chinaztt.mes.basic.entity.Workstation;
|
import com.chinaztt.mes.basic.service.WorkstationService;
|
import com.chinaztt.mes.common.wrapper.QueryWrapperUtil;
|
import com.chinaztt.mes.production.dto.DutyRecordDTO;
|
import com.chinaztt.mes.production.entity.DutyRecord;
|
import com.chinaztt.mes.production.excel.*;
|
import com.chinaztt.mes.production.service.DutyRecordService;
|
import com.chinaztt.mes.production.util.BackUtils;
|
import com.chinaztt.ztt.common.core.util.R;
|
import com.chinaztt.ztt.common.log.annotation.SysLog;
|
import com.chinaztt.ztt.common.security.annotation.Inner;
|
import com.google.common.collect.Lists;
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
import lombok.AllArgsConstructor;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.servlet.http.HttpServletResponse;
|
import java.io.IOException;
|
import java.net.URLEncoder;
|
import java.util.Arrays;
|
import java.util.Iterator;
|
import java.util.List;
|
import java.util.Optional;
|
import java.util.stream.Collectors;
|
|
|
/**
|
* 上班记录
|
*
|
* @author cxf
|
* @date 2021-01-20 09:11:25
|
*/
|
@RestController
|
@AllArgsConstructor
|
@RequestMapping("/dutyRecord")
|
@Api(value = "dutyRecord", tags = "上班记录管理")
|
public class DutyRecordController {
|
|
private final DutyRecordService dutyRecordService;
|
private final BackUtils backUtils;
|
|
/**
|
* 分页查询
|
*
|
* @param page 分页对象
|
* @param dutyRecordDTO 上班记录
|
* @return
|
*/
|
@ApiOperation(value = "分页查询", notes = "分页查询")
|
@GetMapping("/page")
|
@PreAuthorize("@pms.hasPermission('production_dutyrecord_view','product_workbench')")
|
public R getDutyRecordPage(Page page, DutyRecordDTO dutyRecordDTO) {
|
return R.ok(dutyRecordService.getDutyRecordPage(page, QueryWrapperUtil.gen(dutyRecordDTO)));
|
}
|
|
/**
|
* 导出
|
*
|
* @param dutyRecordDTO 上班记录-人工明细
|
* @return
|
*/
|
@ApiOperation(value = "导出", notes = "导出")
|
@Inner(false)
|
@GetMapping("/exportDutyRecord")
|
public void exportDutyRecord(HttpServletResponse response, DutyRecordDTO dutyRecordDTO) throws IOException {
|
response.setContentType("application/vnd.ms-excel");
|
response.setCharacterEncoding("UTF-8");
|
// 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系
|
String fileName = URLEncoder.encode("人工记录", "UTF-8");
|
response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
|
try {
|
//新建ExcelWriter
|
ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()).build();
|
//获取sheet0对象
|
WriteSheet mainSheet = EasyExcel.writerSheet(0, "人工记录").head(DutyRecordData.class).build();
|
//向sheet0写入数据 传入空list这样只导出表头
|
excelWriter.write(dutyRecordService.exportList(QueryWrapperUtil.gen(dutyRecordDTO)), mainSheet);
|
//获取sheet1对象
|
WriteSheet detailSheet = EasyExcel.writerSheet(1, "人员出勤").head(PersonBoardData.class).build();
|
//向sheet1写入数据 传入空list这样只导出表头
|
excelWriter.write(dutyRecordService.exportPersonBoard(QueryWrapperUtil.gen(dutyRecordDTO)), detailSheet);
|
//获取sheet2对象
|
WriteSheet attendanceSheet = EasyExcel.writerSheet(2, "考勤统计").head(AttendanceData.class).build();
|
//向sheet2写入数据 传入空list这样只导出表头
|
excelWriter.write(dutyRecordService.exportAttendance(QueryWrapperUtil.gen(dutyRecordDTO)), attendanceSheet);
|
//获取sheet3对象
|
WriteSheet shiftWageSheet = EasyExcel.writerSheet(3, "班次工资").head(ShiftWageData.class).build();
|
//向sheet3写入数据 传入空list这样只导出表头
|
excelWriter.write(dutyRecordService.exportShiftWage(QueryWrapperUtil.gen(dutyRecordDTO)), shiftWageSheet);
|
//关闭流
|
excelWriter.finish();
|
} catch (IOException e) {
|
throw new RuntimeException("导出失败");
|
}
|
}
|
|
/**
|
* 通过id查询上班记录
|
*
|
* @param id id
|
* @return R
|
*/
|
@ApiOperation(value = "通过id查询", notes = "通过id查询")
|
@GetMapping("/{id}")
|
@PreAuthorize("@pms.hasPermission('production_dutyrecord_view','product_workbench')")
|
public R getById(@PathVariable("id") Long id) {
|
return R.ok(dutyRecordService.getDtoById(id));
|
}
|
|
/**
|
* 新增上班记录
|
*
|
* @param dutyRecordDTO 上班记录
|
* @return R
|
*/
|
@ApiOperation(value = "新增上班记录", notes = "新增上班记录")
|
@SysLog("新增上班记录")
|
@PostMapping
|
@PreAuthorize("@pms.hasPermission('production_dutyrecord_add','product_workbench')")
|
public R save(@RequestBody DutyRecordDTO dutyRecordDTO) {
|
DutyRecordDTO dutyRecord = dutyRecordService.saveDto(dutyRecordDTO);
|
backUtils.backDutyRecordById(dutyRecordDTO.getId(), "新增");
|
return R.ok(dutyRecord);
|
}
|
|
|
/**
|
* 展示该工作站对应的所有的机台
|
*
|
* @param workCenter
|
* @return R
|
*/
|
@ApiOperation(value = "展示该工作站对应的所有的机台", notes = "展示该工作站对应的所有的机台")
|
@SysLog("展示该工作站对应的所有的机台")
|
@GetMapping("/getWorkstation")
|
@PreAuthorize("@pms.hasPermission('production_dutyrecord_add','product_workbench')")
|
public R getWorkstation(@RequestParam("workCenter") String workCenter) {
|
return R.ok(dutyRecordService.getWorkstationList(workCenter));
|
}
|
|
|
/**
|
* 展示该工作中心对应的未提交班次信息
|
*
|
* @param workCenter
|
* @return R
|
*/
|
@ApiOperation(value = "展示该工作中心对应的未提交班次信息", notes = "展示该工作中心对应的未提交班次信息")
|
@SysLog("展示该工作中心对应的未提交班次信息")
|
@GetMapping("/getUnsubmitWorkstation")
|
public R getUnsubmitWorkstation(@RequestParam("workCenter") String workCenter) {
|
return R.ok(dutyRecordService.getUnsubmitWorkstationList(workCenter));
|
}
|
|
|
|
/**
|
* 批量新增上班记录
|
* @param dutyRecordDTO
|
* @return
|
*/
|
@ApiOperation(value = "批量新增上班记录", notes = "批量新增上班记录")
|
@SysLog("批量新增上班记录")
|
@PostMapping("/batch")
|
@PreAuthorize("@pms.hasPermission('product_add_shift_batch','product_workbench')")
|
public R batchSave(@RequestBody DutyRecordDTO dutyRecordDTO) {
|
List<DutyRecordDTO> records = dutyRecordService.batchSave(dutyRecordDTO);
|
backUtils.batchbackDutyRecordByIds(records.stream().map(DutyRecordDTO::getId).collect(Collectors.toList()), "批量新增");
|
Optional<DutyRecordDTO> first = records.stream().filter(p -> p.getWorkstationId().equals(dutyRecordDTO.getWorkstationId())).findFirst();
|
if (first.isPresent()) {
|
return R.ok(first.get());
|
}
|
return R.ok();
|
}
|
|
/**
|
* 修改上班记录
|
*
|
* @param dutyRecordDTO 上班记录
|
* @return R
|
*/
|
@ApiOperation(value = "修改上班记录", notes = "修改上班记录")
|
@SysLog("修改上班记录")
|
@PutMapping
|
@PreAuthorize("@pms.hasPermission('production_dutyrecord_edit','product_workbench')")
|
public R updateById(@RequestBody DutyRecordDTO dutyRecordDTO) {
|
//工作台模块限制直接更新
|
if(dutyRecordDTO.getIsLimitUpd()) {
|
Boolean isSubmit = dutyRecordService.getById(dutyRecordDTO.getId()).getIsSubmit();
|
if (isSubmit) {
|
throw new RuntimeException("班次已提交,不可编辑");
|
}
|
}
|
boolean result = dutyRecordService.updateById(dutyRecordDTO);
|
backUtils.backDutyRecordById(dutyRecordDTO.getId(), dutyRecordDTO.getOperationType());
|
return R.ok(dutyRecordService.getDtoById(dutyRecordDTO.getId()));
|
}
|
|
/**
|
* 通过id删除上班记录
|
*
|
* @param id id
|
* @return R
|
*/
|
@ApiOperation(value = "通过id删除上班记录", notes = "通过id删除上班记录")
|
@SysLog("通过id删除上班记录")
|
@DeleteMapping("/{id}")
|
@PreAuthorize("@pms.hasPermission('production_dutyrecord_del','product_workbench')")
|
public R removeById(@PathVariable Long id) {
|
backUtils.backDeleteDutyRecordById(Arrays.asList(id));
|
return R.ok(dutyRecordService.deleteById(id));
|
}
|
|
/**
|
* 通过上班记录id查询人员List
|
*
|
* @param id id
|
* @return R
|
*/
|
@ApiOperation(value = "通过上班记录id查询人员List", notes = "通过上班记录id查询人员List")
|
@GetMapping("/getPersonByDutyRecordId/{id}")
|
public R getPersonByDutyRecordId(@PathVariable("id") Long id) {
|
return R.ok(dutyRecordService.getPersonByDutyRecordId(id));
|
}
|
|
/**
|
* 通过上班记录idList查询人员List
|
*
|
* @param idList
|
* @return R
|
*/
|
@ApiOperation(value = "通过上班记录idList查询人员List", notes = "通过上班记录idList查询人员List")
|
@GetMapping("/getPersonByDutyRecordIdList")
|
public R getPersonByDutyRecordIdList(@RequestParam("idList") List<Long> idList) {
|
return R.ok(dutyRecordService.getPersonByDutyRecordIdList(idList));
|
}
|
|
/**
|
* 通过上班记录id查询产量
|
*
|
* @param id id
|
* @return R
|
*/
|
@ApiOperation(value = "通过上班记录id查询产量", notes = "通过上班记录id查询产量")
|
@GetMapping("/getOutputByDutyRecordId/{id}")
|
public R getOutputByDutyRecordId(@PathVariable("id") Long id) {
|
return R.ok(dutyRecordService.getOutputByDutyRecordId(id));
|
}
|
|
|
/**
|
* 通过上班记录idList查询产量
|
*
|
* @param idList
|
* @return R
|
*/
|
@ApiOperation(value = "通过上班记录idList查询产量", notes = "通过上班记录idList查询产量")
|
@GetMapping("/getOutputByDutyRecordIdList")
|
public R getOutputByDutyRecordIdList(@RequestParam("idList") List<Long> idList) {
|
return R.ok(dutyRecordService.getOutputByDutyRecordIdList(idList));
|
}
|
|
|
|
|
/**
|
* 通过工作站id查询班次
|
*
|
* @param id id
|
* @return R
|
*/
|
@ApiOperation(value = "通过工作站id查询班次", notes = "通过工作站id查询班次")
|
@GetMapping("/getDutyRecordByWorkstationId/{id}")
|
public R getDutyRecordByWorkstationId(@PathVariable("id") Long id) {
|
return R.ok(dutyRecordService.getDutyRecordByWorkstationId(id));
|
}
|
|
/**
|
* 通过id查询操作记录
|
*
|
* @param id id
|
* @return R
|
*/
|
@ApiOperation(value = "通过id查询操作记录", notes = "通过id查询操作记录")
|
@GetMapping("/getOperatingRecord/{id}")
|
public R getOperatingRecord(@PathVariable("id") Long id) {
|
return R.ok(dutyRecordService.getOperatingRecord(id));
|
}
|
|
/**
|
* 分页查询人工记录
|
*
|
* @param page 分页对象
|
* @param dutyRecordDTO 上班记录
|
* @return
|
*/
|
@ApiOperation(value = "分页查询人工记录", notes = "分页查询人工记录")
|
@GetMapping("/getArtificialRecord")
|
public R getArtificialRecord(Page page, DutyRecordDTO dutyRecordDTO) {
|
return R.ok(dutyRecordService.getArtificialRecord(page, QueryWrapperUtil.gen(dutyRecordDTO)));
|
}
|
|
/**
|
* 工作台班次未提交提醒用于定时任务
|
*
|
* @return
|
*/
|
@ApiOperation(value = "工作台班次未提交提醒", notes = "工作台班次未提交提醒")
|
@GetMapping("/sendUnsubmitMsgAuto")
|
@XxlJob("sendUnsubmitMsgAutoHandler")
|
public R sendUnsubmitMsg(){
|
return R.ok(dutyRecordService.sendUnsubmitMsg());
|
}
|
|
|
/**
|
* 班次批量提交
|
*
|
* @param ids
|
* @return R
|
*/
|
@ApiOperation(value = "班次批量提交", notes = "班次批量提交")
|
@SysLog("班次批量提交")
|
@PostMapping("/batchSubmit")
|
public R batchSubmit(@RequestBody List<Long> ids) {
|
return R.ok(dutyRecordService.batchSubmit(ids));
|
}
|
|
|
|
/**
|
* 批量修改工时计算上班记录
|
*
|
* @param dutyRecordDTOList 上班记录
|
* @return R
|
*/
|
@ApiOperation(value = "批量修改工时计算上班记录", notes = "批量修改工时计算上班记录")
|
@SysLog("批量修改工时计算上班记录")
|
@PostMapping("updateBatchById")
|
@PreAuthorize("@pms.hasPermission('production_dutyrecord_edit','product_workbench')")
|
public R updateBatchById(@RequestBody List<DutyRecordDTO> dutyRecordDTOList) {
|
dutyRecordService.updateBatch(dutyRecordDTOList);
|
for (DutyRecordDTO dutyRecordDTO:dutyRecordDTOList) {
|
backUtils.backDutyRecordById(dutyRecordDTO.getId(), dutyRecordDTO.getOperationType());
|
}
|
return R.ok();
|
}
|
}
|