Browse Source

排班导出

459242451@qq.com 3 years ago
parent
commit
6bfd9fd003

+ 26 - 4
pom.xml

@@ -2,15 +2,15 @@
 <project xmlns="http://maven.apache.org/POM/4.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-	<modelVersion>4.0.0</modelVersion>
-	
+    <modelVersion>4.0.0</modelVersion>
+
     <groupId>com.ruoyi</groupId>
     <artifactId>ruoyi</artifactId>
     <version>3.8.1</version>
 
     <name>ruoyi</name>
     <description>启东市铁路沿线监测平台系统</description>
-    
+
     <properties>
         <ruoyi.version>3.8.1</ruoyi.version>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -33,7 +33,7 @@
         <velocity.version>2.3</velocity.version>
         <jwt.version>0.9.1</jwt.version>
     </properties>
-	
+
     <!-- 依赖声明 -->
     <dependencyManagement>
         <dependencies>
@@ -204,6 +204,28 @@
                 <version>5.7.11</version>
             </dependency>
 
+            <!-- easypoi -->
+            <dependency>
+                <groupId>cn.afterturn</groupId>
+                <artifactId>easypoi-spring-boot-starter</artifactId>
+                <version>4.3.0</version>
+            </dependency>
+            <dependency>
+                <groupId>cn.afterturn</groupId>
+                <artifactId>easypoi-base</artifactId>
+                <version>4.3.0</version>
+            </dependency>
+            <dependency>
+                <groupId>cn.afterturn</groupId>
+                <artifactId>easypoi-web</artifactId>
+                <version>4.3.0</version>
+            </dependency>
+            <dependency>
+                <groupId>cn.afterturn</groupId>
+                <artifactId>easypoi-annotation</artifactId>
+                <version>4.3.0</version>
+            </dependency>
+
         </dependencies>
     </dependencyManagement>
 

+ 74 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/qdtl/TlInspectionPlanController.java

@@ -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);
+    }
+
 }

BIN
ruoyi-admin/src/main/resources/excel/schedule.xlsx


+ 22 - 0
ruoyi-common/pom.xml

@@ -141,6 +141,28 @@
             <version>1.1.3</version>
         </dependency>
 
+        <!-- easypoi -->
+        <dependency>
+            <groupId>cn.afterturn</groupId>
+            <artifactId>easypoi-spring-boot-starter</artifactId>
+            <version>4.3.0</version>
+        </dependency>
+        <dependency>
+            <groupId>cn.afterturn</groupId>
+            <artifactId>easypoi-base</artifactId>
+            <version>4.3.0</version>
+        </dependency>
+        <dependency>
+            <groupId>cn.afterturn</groupId>
+            <artifactId>easypoi-web</artifactId>
+            <version>4.3.0</version>
+        </dependency>
+        <dependency>
+            <groupId>cn.afterturn</groupId>
+            <artifactId>easypoi-annotation</artifactId>
+            <version>4.3.0</version>
+        </dependency>
+
     </dependencies>
 
 </project>

+ 14 - 17
ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java

@@ -1,5 +1,8 @@
 package com.ruoyi.framework.config;
 
+import com.ruoyi.framework.security.filter.JwtAuthenticationTokenFilter;
+import com.ruoyi.framework.security.handle.AuthenticationEntryPointImpl;
+import com.ruoyi.framework.security.handle.LogoutSuccessHandlerImpl;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Bean;
 import org.springframework.http.HttpMethod;
@@ -16,24 +19,20 @@ import org.springframework.security.web.authentication.logout.LogoutFilter;
 import org.springframework.security.web.firewall.HttpFirewall;
 import org.springframework.security.web.firewall.StrictHttpFirewall;
 import org.springframework.web.filter.CorsFilter;
-import com.ruoyi.framework.security.filter.JwtAuthenticationTokenFilter;
-import com.ruoyi.framework.security.handle.AuthenticationEntryPointImpl;
-import com.ruoyi.framework.security.handle.LogoutSuccessHandlerImpl;
 
 /**
  * spring security配置
- * 
+ *
  * @author ruoyi
  */
 @EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true)
-public class SecurityConfig extends WebSecurityConfigurerAdapter
-{
+public class SecurityConfig extends WebSecurityConfigurerAdapter {
     /**
      * 自定义用户认证逻辑
      */
     @Autowired
     private UserDetailsService userDetailsService;
-    
+
     /**
      * 认证失败处理类
      */
@@ -51,13 +50,13 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
      */
     @Autowired
     private JwtAuthenticationTokenFilter authenticationTokenFilter;
-    
+
     /**
      * 跨域过滤器
      */
     @Autowired
     private CorsFilter corsFilter;
-    
+
     /**
      * 解决 无法直接注入 AuthenticationManager
      *
@@ -66,8 +65,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
      */
     @Bean
     @Override
-    public AuthenticationManager authenticationManagerBean() throws Exception
-    {
+    public AuthenticationManager authenticationManagerBean() throws Exception {
         return super.authenticationManagerBean();
     }
 
@@ -87,8 +85,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
      * authenticated       |   用户登录后可访问
      */
     @Override
-    protected void configure(HttpSecurity httpSecurity) throws Exception
-    {
+    protected void configure(HttpSecurity httpSecurity) throws Exception {
         httpSecurity
                 // CSRF禁用,因为不使用session
                 .csrf().disable()
@@ -107,6 +104,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
                         "/**/*.html",
                         "/**/*.css",
                         "/**/*.js",
+                        "/qdtl/plan/exportSchedule",
                         "/profile/**"
                 ).permitAll()
                 .antMatchers("/swagger-ui.html").anonymous()
@@ -130,8 +128,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
      * 强散列哈希加密实现
      */
     @Bean
-    public BCryptPasswordEncoder bCryptPasswordEncoder()
-    {
+    public BCryptPasswordEncoder bCryptPasswordEncoder() {
         return new BCryptPasswordEncoder();
     }
 
@@ -139,13 +136,13 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
      * 身份认证接口
      */
     @Override
-    protected void configure(AuthenticationManagerBuilder auth) throws Exception
-    {
+    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
         auth.userDetailsService(userDetailsService).passwordEncoder(bCryptPasswordEncoder());
     }
 
     /**
      * 配置地址栏不能识别 // 的情况
+     *
      * @return
      */
     @Bean

+ 1 - 1
ruoyi-system/src/main/java/com/ruoyi/qdtl/service/impl/TlInspectionPlanServiceImpl.java

@@ -157,7 +157,7 @@ public class TlInspectionPlanServiceImpl implements ITlInspectionPlanService {
         // 如果startDate或者endDate为空,则默认展示最近7天的
         if (StrUtil.hasBlank(startDate, endDate)) {
             startDate = DateUtil.today();
-            endDate = DateUtil.formatDate(DateUtil.offsetDay(new Date(), 7));
+            endDate = DateUtil.formatDate(DateUtil.offsetDay(new Date(), 6));
         }
         List<PlanSchedule> result = new ArrayList<>();
         List<TlInspectionPlan> list = tlInspectionPlanMapper.queryByDatePeriod(startDate, endDate);

+ 6 - 0
sql/ry_20210908.sql

@@ -1203,6 +1203,12 @@ alter table tl_inspection_plan
 alter table tl_inspection_plan
     add xun_num int default 1 null comment '巡检次数';
 
+alter table tl_plan_record
+    add start_time varchar(20) default '' null comment '开始时刻';
+
+alter table tl_plan_record
+    add end_time varchar(20) default '' null comment '结束时刻';
+
 -- 已同步