Reiskuchen 5 роки тому
батько
коміт
c9da34af96

+ 8 - 1
fhKeeper/formulahousekeeper/management-platform/pom.xml

@@ -104,7 +104,14 @@
             <artifactId>tess4j</artifactId>
         </dependency>
 
-
+        <!--手动引入opencv 否则无法maven打包-->
+        <dependency>
+            <groupId>org.opencv</groupId>
+            <artifactId>opencv</artifactId>
+            <version>4.2.0</version>
+            <scope>system</scope>
+            <systemPath>${basedir}/opencv/opencv-420.jar</systemPath>
+        </dependency>
     </dependencies>
 
 

+ 11 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/controller/UserController.java

@@ -115,5 +115,16 @@ public class UserController {
     public HttpRespMsg importUser(@RequestParam MultipartFile file) {
         return userService.importUser(file, request);
     }
+
+
+    /**
+     * 切换权限
+     * 负责人可以将本公司的管理员切换至普通员工或者反之
+     * id 目标id
+     */
+    @RequestMapping("/switchPermission")
+    public HttpRespMsg switchPermission(@RequestParam String id) {
+        return userService.switchPermission(id, request);
+    }
 }
 

+ 2 - 1
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/mapper/ScreenshotMapper.java

@@ -18,7 +18,8 @@ import java.util.Map;
  * @since 2020-01-02
  */
 public interface ScreenshotMapper extends BaseMapper<Screenshot> {
-    List<Map<String, Object>> getLatestScreenshotList(@Param("companyId")Integer companyId);
+    List<Map<String, Object>> getLatestScreenshotList(@Param("companyId")Integer companyId,
+                                                      @Param("date")String date);
 
     HttpRespMsg saveAndProcessImage(ScreenshotVO screenshotvo);
 }

+ 2 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/UserService.java

@@ -33,4 +33,6 @@ public interface UserService extends IService<User> {
     HttpRespMsg insertUser(String name, String phone, Integer role, HttpServletRequest request);
 
     HttpRespMsg importUser(MultipartFile multipartFile, HttpServletRequest request);
+
+    HttpRespMsg switchPermission(String id, HttpServletRequest request);
 }

+ 7 - 8
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/ReportServiceImpl.java

@@ -133,18 +133,17 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
 
             //生成Excel文件
             String fileUrlSuffix = date + "日报" + new SimpleDateFormat("hh-mm-ss").format(new Date()) + ".xls";
-            try {
-                FileOutputStream fos = new FileOutputStream(path + fileUrlSuffix);
-                workbook.write(fos);
-                fos.flush();
-                fos.close();
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
+            FileOutputStream fos = new FileOutputStream(path + fileUrlSuffix);
+            workbook.write(fos);
+            fos.flush();
+            fos.close();
             httpRespMsg.data = "/upload/" + fileUrlSuffix;
         } catch (NullPointerException e) {
             httpRespMsg.setError("验证失败");
             return httpRespMsg;
+        } catch (IOException e) {
+            httpRespMsg.setError("文件生成错误");
+            return httpRespMsg;
         }
         return httpRespMsg;
     }

+ 2 - 1
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/ScreenshotServiceImpl.java

@@ -82,7 +82,8 @@ public class ScreenshotServiceImpl extends ServiceImpl<ScreenshotMapper, Screens
         //获取每一个人最后一张截图
         try {
             List<Map<String, Object>> resultMap = screenshotMapper
-                    .getLatestScreenshotList(userMapper.selectById(request.getHeader("Token")).getCompanyId());
+                    .getLatestScreenshotList(userMapper.selectById(request.getHeader("Token")).getCompanyId(),
+                            LocalDate.now(ZoneOffset.of("+8")).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
             for (Map<String, Object> map : resultMap) {
                 //对于每一张图 将时间戳转换为时间
                 map.put("time", new SimpleDateFormat("HH:mm:ss").format(map.get("indate")));

+ 0 - 1
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/TimeCalculationServiceImpl.java

@@ -13,7 +13,6 @@ import org.springframework.stereotype.Service;
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import java.time.LocalDate;
-import java.time.LocalDateTime;
 import java.time.ZoneOffset;
 import java.time.format.DateTimeFormatter;
 import java.time.format.DateTimeParseException;

+ 37 - 6
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/UserServiceImpl.java

@@ -12,10 +12,7 @@ import com.management.platform.util.MD5Util;
 import com.management.platform.util.SnowFlake;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
-import org.apache.poi.ss.usermodel.Cell;
-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.*;
 import org.apache.poi.xssf.usermodel.XSSFCell;
 import org.apache.poi.xssf.usermodel.XSSFRow;
 import org.apache.poi.xssf.usermodel.XSSFSheet;
@@ -111,6 +108,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
                     .eq("company_id", userMapper.selectById(request.getHeader("Token")).getCompanyId()));
         } catch (NullPointerException e) {
             httpRespMsg.setError("验证失败");
+            return httpRespMsg;
         }
         return httpRespMsg;
     }
@@ -138,6 +136,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
             }
         } catch (NullPointerException e) {
             httpRespMsg.setError("验证失败");
+            return httpRespMsg;
         }
         return httpRespMsg;
     }
@@ -157,6 +156,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
             }
         } catch (NullPointerException e) {
             httpRespMsg.setError("验证失败");
+            return httpRespMsg;
         }
         return httpRespMsg;
     }
@@ -221,6 +221,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
             }
         } catch (NullPointerException e) {
             httpRespMsg.setError("验证失败");
+            return httpRespMsg;
         }
         return httpRespMsg;
     }
@@ -259,8 +260,12 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
                 }
                 //此处新建账号 默认密码为000000 默认 姓名第一列 手机号第二列
                 Long id = SnowFlake.nextId();
-                String name = row.getCell(0).getStringCellValue();
-                String phone = row.getCell(1).getStringCellValue();
+                XSSFCell nameCell = row.getCell(0);
+                XSSFCell phoneCell = row.getCell(1);
+                nameCell.setCellType(CellType.STRING);
+                phoneCell.setCellType(CellType.STRING);
+                String name = nameCell.getStringCellValue();
+                String phone = phoneCell.getStringCellValue();
                 phoneList.add(phone);
                 userList.add(new User()
                         .setId(id.toString())
@@ -288,6 +293,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
             httpRespMsg.setError("文件处理出错");
             return httpRespMsg;
         } catch (NullPointerException e) {
+            e.printStackTrace();
             httpRespMsg.setError("数据格式有误或存在空数据 导出失败");
             return httpRespMsg;
         } catch (Exception e) {
@@ -297,4 +303,29 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
         }
         return httpRespMsg;
     }
+
+    //切换权限状态
+    @Override
+    public HttpRespMsg switchPermission(String id, HttpServletRequest request) {
+        HttpRespMsg httpRespMsg = new HttpRespMsg();
+        try {
+            User requester = userMapper.selectById(request.getHeader("Token")),
+                    target = userMapper.selectById(id);
+            //管理员只能新增员工
+            if (requester.getRole() != 1) {
+                httpRespMsg.setError("仅负责人有权限更改其他人员权限");
+            } else if (!target.getCompanyId().equals(requester.getCompanyId())) {
+                httpRespMsg.setError("只可修改同一公司人员的权限");
+            } else if (target.getRole() == 1) {
+                httpRespMsg.setError("不可修改负责人的权限");
+            } else {
+                target.setRole(target.getRole() == 0 ? 2 : 0);
+                userMapper.updateById(target);
+            }
+        } catch (NullPointerException e) {
+            httpRespMsg.setError("缺少数据 未查询到相应人员信息");
+            return httpRespMsg;
+        }
+        return httpRespMsg;
+    }
 }

+ 3 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/resources/mapper/ScreenshotMapper.xml

@@ -36,6 +36,9 @@
         <if test="companyId != null and companyId != ''">
             AND c.company_id=#{companyId}
         </if>
+        <if test="date != null and date != ''">
+            AND a.date_str=#{date}
+        </if>
     </select>
 
 </mapper>

+ 13 - 8
fhKeeper/formulahousekeeper/timesheet/src/http.js

@@ -36,7 +36,7 @@ export default {
      * @param exception 异常的回调函数
      */
     post (url, data, response, exception) {
-        var user = sessionStorage.getItem('user') , token = "";
+        let user = sessionStorage.getItem('user') , token = "";
         if(user != null){
             token = JSON.parse(user).id
             // data.token = token
@@ -72,15 +72,17 @@ export default {
      * @param exception 异常的回调函数
      */
     get (url , response, exception) {
-        var user = sessionStorage.getItem('user') , token = "";
+        let user = sessionStorage.getItem('user') , token = "";
         if(user != null){
-            token = JSON.parse(user).headImgurl
+            token = JSON.parse(user).id
+            // data.token = token
         }
         axios({
             method: 'get',
             url: handleUrl(url),
             headers: {
-                'Content-Type': 'application/json; charset=UTF-8'
+                'Content-Type': 'application/json; charset=UTF-8',
+                'Token': token
             }
         }).then(
             (result) => {
@@ -104,10 +106,10 @@ export default {
      * @param exception 异常的回调函数
      */
     uploadFile (url, data, response, exception) {
-        var user = sessionStorage.getItem('user') , token = "";
+        let user = sessionStorage.getItem('user') , token = "";
         if(user != null){
-            token = JSON.parse(user).headImgurl
-            data.append("token", token);
+            token = JSON.parse(user).id
+            // data.token = token
         }
         axios({
             method: 'post',
@@ -115,7 +117,10 @@ export default {
             data: handleParams(data),
             dataType: 'json',
             processData: false,
-            contentType: false
+            contentType: false,
+            headers: {
+                'Token': token
+            }
         }).then(
             (result) => {
                 response(handleResults(result, data))

+ 1 - 0
fhKeeper/formulahousekeeper/timesheet/src/port.js

@@ -5,6 +5,7 @@ export default {
         delete: '/user/deleteUser', //删除用户
         insert: '/user/insertUser', //单独新增用户
         import: '/user/importUser', //批量导入用户
+        permission: '/user/switchPermission', //切换权限
     },
 
     //时间

+ 93 - 1
fhKeeper/formulahousekeeper/timesheet/src/views/team/index.vue

@@ -7,7 +7,15 @@
           <el-link type="primary" :underline="false" @click="openInsertDialog">添加人员</el-link>
         </el-form-item>
         <el-form-item style="float:right;">
-          <el-link type="primary" :underline="false">批量导入N/A</el-link>
+          <el-upload
+            ref="upload"
+            action="#"
+            :limit="1"
+            :http-request="importUser"
+            :show-file-list="false"
+          >
+            <el-link type="primary" :underline="false">批量导入</el-link>
+          </el-upload>
         </el-form-item>
       </el-form>
     </el-col>
@@ -31,6 +39,16 @@
       </el-table-column>
       <el-table-column label="操作">
         <template slot-scope="scope">
+          <el-button
+            size="small"
+            v-if="scope.row.role == 0 && user.role == 1"
+            @click="switchRole(scope.$index)"
+          >切换为管理员</el-button>
+          <el-button
+            size="small"
+            v-if="scope.row.role == 2 && user.role == 1"
+            @click="switchRole(scope.$index)"
+          >切换为员工</el-button>
           <el-button size="small" type="danger" @click="deleteUser(scope.$index)">删除</el-button>
         </template>
       </el-table-column>
@@ -174,6 +192,80 @@ export default {
       });
     },
 
+    //获取所有员工的列表
+    importUser(item) {
+      //首先判断文件类型
+      let str = item.file.name.split(".");
+      let format = str[str.length - 1];
+      if (format != "xls" && format != "xlsx") {
+        this.$message({
+          message: "请选择.xls或.xlsx文件",
+          type: "error"
+        });
+      } else {
+        this.listLoading = true;
+        let formData = new FormData();
+        formData.append("file", item.file);
+        this.http.uploadFile(
+          this.port.manage.import,
+          formData,
+          res => {
+            this.$refs.upload.clearFiles();
+            this.listLoading = false;
+            if (res.code == "ok") {
+              //重新读取列表
+              this.getUser();
+            } else {
+              this.$message({
+                message: res.msg,
+                type: "error"
+              });
+            }
+          },
+          error => {
+            this.$refs.upload.clearFiles();
+            this.listLoading = false;
+            this.$message({
+              message: error,
+              type: "error"
+            });
+          }
+        );
+      }
+    },
+
+    //切换角色 0/2
+    switchRole(index) {
+      this.listLoading = true;
+      this.http.post(
+        this.port.manage.permission,
+        { id: this.list[index].id },
+        res => {
+          this.listLoading = false;
+          if (res.code == "ok") {
+            this.$message({
+              message: "切换角色成功",
+              type: "success"
+            });
+            //重新读取列表
+            this.getUser();
+          } else {
+            this.$message({
+              message: res.msg,
+              type: "error"
+            });
+          }
+        },
+        error => {
+          this.listLoading = false;
+          this.$message({
+            message: error,
+            type: "error"
+          });
+        }
+      );
+    },
+
     //三天之内删了你 数据库都给你清了
     deleteUser(index) {
       this.$confirm(