|
@@ -1,18 +1,31 @@
|
|
|
package com.ruoyi.web.controller.qdtl;
|
|
|
|
|
|
+import cn.afterturn.easypoi.entity.vo.TemplateExcelConstants;
|
|
|
+import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
|
|
|
+import cn.afterturn.easypoi.view.PoiBaseView;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.date.Week;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import com.ruoyi.common.annotation.Log;
|
|
|
import com.ruoyi.common.core.controller.BaseController;
|
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
import com.ruoyi.common.core.page.TableDataInfo;
|
|
|
import com.ruoyi.common.enums.BusinessType;
|
|
|
+import com.ruoyi.qdtl.domain.PlanSchedule;
|
|
|
import com.ruoyi.qdtl.domain.TlInspectionPlan;
|
|
|
import com.ruoyi.qdtl.domain.TlInspectionPlanUser;
|
|
|
import com.ruoyi.qdtl.service.ITlInspectionPlanService;
|
|
|
import com.ruoyi.qdtl.service.ITlInspectionPlanUserService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
+import org.springframework.ui.ModelMap;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -107,9 +120,70 @@ public class TlInspectionPlanController extends BaseController {
|
|
|
return toAjax(tlInspectionPlanService.deleteTlInspectionPlanByIds(ids));
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 查询排班表
|
|
|
+ *
|
|
|
+ * @param nickName
|
|
|
+ * @param startDate
|
|
|
+ * @param endDate
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@PreAuthorize("@ss.hasPermi('qdtl:plan:query')")
|
|
|
@GetMapping(value = "/getSchedule")
|
|
|
public AjaxResult getSchedule(@RequestParam(required = false) String nickName, @RequestParam(required = false) String startDate, @RequestParam(required = false) String endDate) {
|
|
|
return AjaxResult.success(tlInspectionPlanService.getSchedule(nickName, startDate, endDate));
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导出排班表
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @GetMapping(value = "/exportSchedule")
|
|
|
+ public void exportSchedule(ModelMap modelMap, @RequestParam(required = false) String nickName, @RequestParam(required = false) String startDate, @RequestParam(required = false) String endDate, HttpServletRequest request,
|
|
|
+ HttpServletResponse response) {
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ // 如果startDate或者endDate为空,则默认展示最近7天的
|
|
|
+ if (StrUtil.hasBlank(startDate, endDate)) {
|
|
|
+ startDate = DateUtil.today();
|
|
|
+ endDate = DateUtil.formatDate(DateUtil.offsetDay(new Date(), 6));
|
|
|
+ }
|
|
|
+ List<PlanSchedule> schedule = tlInspectionPlanService.getSchedule(nickName, startDate, endDate);
|
|
|
+ List<Map<String, Object>> dateList = new ArrayList<>();
|
|
|
+ if (schedule != null && schedule.size() > 0) {
|
|
|
+ List<PlanSchedule.PlanDetail> planDetails = schedule.get(0).getPlanDetails();
|
|
|
+ for (PlanSchedule.PlanDetail planDetail : planDetails) {
|
|
|
+ Map<String, Object> map = new HashMap<>(4);
|
|
|
+ map.put("dateGroup", planDetail.getQueryDate() + "\r\n" + Week.of(planDetail.getWeek()).toChinese());
|
|
|
+ map.put("dateUser", "t." + planDetail.getQueryDate() + "user");
|
|
|
+ dateList.add(map);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<Map<String, Object>> valList = new ArrayList<>();
|
|
|
+ for (PlanSchedule planSchedule : schedule) {
|
|
|
+ Map<String, Object> map = new HashMap<>(16);
|
|
|
+ map.put("effectDate", planSchedule.getEffectDate());
|
|
|
+ map.put("locations", String.join("\r\n", planSchedule.getLocations()));
|
|
|
+ map.put("timeUnit", String.join("\r\n", planSchedule.getTimeUnit()));
|
|
|
+ for (PlanSchedule.PlanDetail planDetail : planSchedule.getPlanDetails()) {
|
|
|
+ map.put(planDetail.getQueryDate() + "user", planDetail.getNickName());
|
|
|
+ }
|
|
|
+ valList.add(map);
|
|
|
+ }
|
|
|
+ result.put("dataList", valList);
|
|
|
+ result.put("dateList", dateList);
|
|
|
+
|
|
|
+ result.put("datePeriod", startDate + "至" + endDate);
|
|
|
+
|
|
|
+ TemplateExportParams params = new TemplateExportParams(
|
|
|
+ "excel/schedule.xlsx");
|
|
|
+ params.setColForEach(true);
|
|
|
+
|
|
|
+ modelMap.put(TemplateExcelConstants.FILE_NAME, startDate + "至" + endDate + "排班表");
|
|
|
+ modelMap.put(TemplateExcelConstants.PARAMS, params);
|
|
|
+ modelMap.put(TemplateExcelConstants.MAP_DATA, result);
|
|
|
+ PoiBaseView.render(modelMap, request, response,
|
|
|
+ TemplateExcelConstants.EASYPOI_TEMPLATE_EXCEL_VIEW);
|
|
|
+ }
|
|
|
+
|
|
|
}
|