Reiskuchen 5 gadi atpakaļ
vecāks
revīzija
3badf141b9

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

@@ -104,9 +104,9 @@ public class UserController {
      * role 角色 0-普通员工 2-管理员
      */
     @RequestMapping("/insertUser")
-    public HttpRespMsg insertUser(String id,
-                                  @RequestParam String name, @RequestParam String phone, @RequestParam Integer role) {
-        return userService.insertUser(id, name, phone, role, request);
+    public HttpRespMsg insertUser(String id, @RequestParam String name, @RequestParam String phone,
+                                  @RequestParam Integer role, Double cost) {
+        return userService.insertUser(id, name, phone, role, cost, request);
     }
 
     /**

+ 16 - 7
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/entity/User.java

@@ -1,28 +1,31 @@
 package com.management.platform.entity;
 
-import com.baomidou.mybatisplus.extension.activerecord.Model;
-import com.baomidou.mybatisplus.annotation.TableId;
-import java.time.LocalDateTime;
+import com.baomidou.mybatisplus.annotation.FieldStrategy;
 import com.baomidou.mybatisplus.annotation.TableField;
-import java.io.Serializable;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.extension.activerecord.Model;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.experimental.Accessors;
 
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
+
 /**
  * <p>
- * 
+ *
  * </p>
  *
  * @author 吴涛涛
- * @since 2020-01-13
+ * @since 2020-02-09
  */
 @Data
 @EqualsAndHashCode(callSuper = false)
 @Accessors(chain = true)
 public class User extends Model<User> {
 
-    private static final long serialVersionUID=1L;
+    private static final long serialVersionUID = 1L;
 
     /**
      * 主键 雪花算法生成
@@ -72,6 +75,12 @@ public class User extends Model<User> {
     @TableField("company_id")
     private Integer companyId;
 
+    /**
+     * 时薪
+     */
+    @TableField(value = "cost", updateStrategy = FieldStrategy.IGNORED)
+    private BigDecimal cost;
+
 
     @Override
     protected Serializable pkVal() {

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

@@ -1,7 +1,7 @@
 package com.management.platform.service;
 
-import com.management.platform.entity.User;
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.management.platform.entity.User;
 import com.management.platform.util.HttpRespMsg;
 import org.springframework.web.multipart.MultipartFile;
 
@@ -30,7 +30,7 @@ public interface UserService extends IService<User> {
 
     HttpRespMsg insertCompany(String companyName, String name, String phone);
 
-    HttpRespMsg insertUser(String id, String name, String phone, Integer role, HttpServletRequest request);
+    HttpRespMsg insertUser(String id, String name, String phone, Integer role, Double cost, HttpServletRequest request);
 
     HttpRespMsg importUser(MultipartFile multipartFile, HttpServletRequest request);
 

+ 15 - 5
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/ProjectServiceImpl.java

@@ -2,19 +2,20 @@ package com.management.platform.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.management.platform.entity.Project;
 import com.management.platform.entity.Report;
-import com.management.platform.entity.User;
 import com.management.platform.mapper.ProjectMapper;
 import com.management.platform.mapper.ReportMapper;
 import com.management.platform.mapper.UserMapper;
 import com.management.platform.service.ProjectService;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.management.platform.util.HttpRespMsg;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
+import java.math.BigDecimal;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -112,13 +113,22 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
         HttpRespMsg httpRespMsg = new HttpRespMsg();
         try {
             Integer companyId = userMapper.selectById(request.getHeader("Token")).getCompanyId();
-            List<Map<String, Object>> resultList = projectMapper.getTimeCost(companyId);
-            for (Map<String, Object> map : resultList) {
+            Map<String, Object> resultMap = new HashMap<>();
+            List<Map<String, Object>> list = projectMapper.getTimeCost(companyId);
+            BigDecimal totalMoneyCost = BigDecimal.valueOf(0);
+            for (Map<String, Object> map : list) {
                 if (!map.containsKey("cost")) {
                     map.put("cost", 0);
                 }
+                if (!map.containsKey("costMoney")) {
+                    map.put("costMoney", 0);
+                } else {
+                    totalMoneyCost = totalMoneyCost.add(BigDecimal.valueOf((Double) map.get("costMoney")));
+                }
             }
-            httpRespMsg.data = resultList;
+            resultMap.put("costList", list);
+            resultMap.put("totalMoneyCost", totalMoneyCost);
+            httpRespMsg.data = resultMap;
         } catch (NullPointerException e) {
             httpRespMsg.setError("验证失败");
             return httpRespMsg;

+ 26 - 16
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/UserServiceImpl.java

@@ -1,22 +1,17 @@
 package com.management.platform.service.impl;
 
-import java.time.LocalDateTime;
-import java.time.LocalDate;
-
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.management.platform.entity.Company;
 import com.management.platform.entity.User;
 import com.management.platform.entity.vo.UserVO;
 import com.management.platform.mapper.CompanyMapper;
 import com.management.platform.mapper.UserMapper;
 import com.management.platform.service.UserService;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.management.platform.util.HttpRespMsg;
 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.*;
+import org.apache.poi.ss.usermodel.CellType;
 import org.apache.poi.xssf.usermodel.XSSFCell;
 import org.apache.poi.xssf.usermodel.XSSFRow;
 import org.apache.poi.xssf.usermodel.XSSFSheet;
@@ -28,6 +23,8 @@ import org.springframework.web.multipart.MultipartFile;
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import java.io.*;
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
 import java.time.ZoneOffset;
 import java.util.ArrayList;
 import java.util.List;
@@ -252,10 +249,13 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
 
     //新增或修改用户
     @Override
-    public HttpRespMsg insertUser(String targetId, String name, String phone, Integer role, HttpServletRequest request) {
+    public HttpRespMsg insertUser(String targetId, String name, String phone, Integer role, Double cost,
+                                  HttpServletRequest request) {
         HttpRespMsg httpRespMsg = new HttpRespMsg();
         try {
             User creator = userMapper.selectById(request.getHeader("Token"));
+            //处理时薪
+            BigDecimal costValue = cost == null ? null : BigDecimal.valueOf(cost);
             if (targetId == null) {
                 //新增
                 if (creator.getRole() == 2 && role != 0) {
@@ -274,7 +274,8 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
                                 .setPassword(MD5Util.getPassword("000000"))
                                 .setPhone(phone)
                                 .setRole(role)
-                                .setCompanyId(creator.getCompanyId());
+                                .setCompanyId(creator.getCompanyId())
+                                .setCost(costValue);
                         if (userMapper.selectCount(new QueryWrapper<User>().eq("company_id", creator.getCompanyId())) >= (companyMapper.selectById(creator.getCompanyId()).getStaffCountMax())) {
                             httpRespMsg.setError("公司人员已达上限");
                             return httpRespMsg;
@@ -286,7 +287,11 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
                 }
             } else {
                 //修改
-                userMapper.updateById(userMapper.selectById(targetId).setName(name).setPhone(phone).setRole(role));
+                userMapper.updateById(userMapper.selectById(targetId)
+                        .setName(name)
+                        .setPhone(phone)
+                        .setRole(role)
+                        .setCost(costValue));
             }
         } catch (NullPointerException e) {
             httpRespMsg.setError("数据有误 验证失败");
@@ -330,17 +335,21 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
                 if (row == null) {
                     continue;
                 }
-                //此处新建账号 默认密码为000000 默认 姓名第一列 手机号第二列
+                //此处新建账号 默认密码为000000 默认 姓名第一列 手机号第二列 时薪第三列
                 Long id = SnowFlake.nextId();
                 XSSFCell nameCell = row.getCell(0);
                 XSSFCell phoneCell = row.getCell(1);
+                XSSFCell costCell = row.getCell(2);
                 nameCell.setCellType(CellType.STRING);
                 phoneCell.setCellType(CellType.STRING);
-                if ("姓名".equals(nameCell.getStringCellValue()) && "手机号".equals(phoneCell.getStringCellValue()) && rowIndex == 0) {
-                    continue;
-                }
+                costCell.setCellType(CellType.STRING);
                 String name = nameCell.getStringCellValue();
                 String phone = phoneCell.getStringCellValue();
+                if (name.equals("姓名") && phone.equals("手机号") && rowIndex == 0) {
+                    continue;
+                }
+                String costString = costCell.getStringCellValue();
+                BigDecimal cost = costString != null ? new BigDecimal(costString) : null;
                 phoneList.add(phone);
                 userList.add(new User()
                         .setId(id.toString())
@@ -348,7 +357,8 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
                         .setPassword(MD5Util.getPassword("000000"))
                         .setPhone(phone)
                         .setRole(0)
-                        .setCompanyId(companyId));
+                        .setCompanyId(companyId)
+                        .setCost(cost));
             }
             //最后删掉这个文件
 //            if (!file.delete()) {
@@ -369,7 +379,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
             return httpRespMsg;
         } catch (NullPointerException e) {
             e.printStackTrace();
-            httpRespMsg.setError("数据格式有误或存在空数据 导失败");
+            httpRespMsg.setError("数据格式有误或存在空数据 导失败");
             return httpRespMsg;
         } catch (Exception e) {
             e.printStackTrace();

+ 1 - 1
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/util/CodeGenerator.java

@@ -204,7 +204,7 @@ public class CodeGenerator {
         //若想要生成的实体类继承某个Controller,则可打开下面注释。写上需要继承的Controller的位置即可
 //        strategy.setSuperControllerClass("com.baomidou.ant.common.BaseController");
         //此处user是表名,多个英文逗号分割
-        strategy.setInclude("time_calculation");
+        strategy.setInclude("user");
 //        strategy.setExclude();//数据库表全生成
 //        strategy.setInclude(scanner("user").split(","));//表名,多个英文逗号分割
         strategy.setControllerMappingHyphenStyle(true);

+ 2 - 1
fhKeeper/formulahousekeeper/management-platform/src/main/resources/mapper/ProjectMapper.xml

@@ -16,9 +16,10 @@
 
     <!--获取查询者所在公司每个项目的工时成本-->
     <select id="getTimeCost" resultType="java.util.Map">
-        SELECT a.id, a.project_name AS project, SUM(b.working_time) AS cost
+        SELECT a.id, a.project_name AS project, SUM(b.working_time) AS cost, SUM(b.working_time * c.cost) AS costMoney
         FROM project AS a
         LEFT JOIN report AS b ON b.project_id = a.id
+        JOIN user AS c ON b.creator_id = c.id
         WHERE a.company_id = #{companyId}
         GROUP BY a.id
         ORDER BY a.id ASC

+ 2 - 1
fhKeeper/formulahousekeeper/management-platform/src/main/resources/mapper/UserMapper.xml

@@ -12,11 +12,12 @@
         <result column="create_time" property="createTime" />
         <result column="role" property="role" />
         <result column="company_id" property="companyId" />
+        <result column="cost" property="cost" />
     </resultMap>
 
     <!-- 通用查询结果列 -->
     <sql id="Base_Column_List">
-        id, name, phone, password, portrait_url, create_time, role, company_id
+        id, name, phone, password, portrait_url, create_time, role, company_id, cost
     </sql>
 
 </mapper>

+ 2 - 2
fhKeeper/formulahousekeeper/timesheet/src/views/project/cost.vue

@@ -18,7 +18,7 @@
                 this.http.post(this.port.project.listCost, {},
                 res => {
                     if (res.code == "ok") {
-                        var xList = [],yList = [] , list = res.data;
+                        var xList = [], yList = [], list = res.data.costList, totalMoneyCost = res.data.totalMoneyCost;
                         for(var i in list) {
                             xList.push(list[i].project);
                             yList.push({
@@ -31,7 +31,7 @@
                         _this.myChart = myChart;
                         var option = {
                             title: {
-                                text: '项目成本统计',
+                                text: '项目成本统计 总计' + totalMoneyCost + '元',
                                 left:'left',
                             },
                             // 工具箱

+ 72 - 40
fhKeeper/formulahousekeeper/timesheet/src/views/team/index.vue

@@ -4,21 +4,32 @@
     <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
       <el-form :inline="true">
         <el-form-item>
-            <div class="nowTime">
-                <i class="el-icon-s-home"></i>
-                {{user.companyName}}
-            </div>
+          <div class="nowTime">
+            <i class="el-icon-s-home"></i>
+            {{user.companyName}}
+          </div>
         </el-form-item>
         <el-form-item style="float:right;">
           <el-link type="primary" :underline="false" @click="openInsertDialog(null)">添加人员</el-link>
         </el-form-item>
         <el-form-item style="float:right;">
-          <el-upload ref="upload" action="#" :limit="1" :http-request="importUser" :show-file-list="false">
+          <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-item style="float:right;">
-            <el-link type="primary" :underline="false" href="./upload/人员导入模板.xlsx" download="人员导入模板.xlsx">模板下载</el-link>
+          <el-link
+            type="primary"
+            :underline="false"
+            href="./upload/人员导入模板.xlsx"
+            download="人员导入模板.xlsx"
+          >模板下载</el-link>
         </el-form-item>
       </el-form>
     </el-col>
@@ -40,6 +51,7 @@
           scope.row.role == 1 ? "负责人" : "管理员"}}
         </template>
       </el-table-column>
+      <el-table-column prop="cost" label="成本"></el-table-column>
       <el-table-column label="操作" width="280">
         <template slot-scope="scope">
           <el-button
@@ -52,8 +64,18 @@
             v-if="scope.row.role == 2 && user.role == 1"
             @click="switchRole(scope.$index)"
           >切换为员工</el-button>
-          <el-button size="small" type="primary" v-if="scope.row.role != 1" @click="openInsertDialog(scope.$index)">编辑</el-button>
-          <el-button size="small" type="danger" v-if="scope.row.role == 0" @click="deleteUser(scope.$index)">删除</el-button>
+          <el-button
+            size="small"
+            type="primary"
+            v-if="scope.row.role != 1"
+            @click="openInsertDialog(scope.$index)"
+          >编辑</el-button>
+          <el-button
+            size="small"
+            type="danger"
+            v-if="scope.row.role == 0"
+            @click="deleteUser(scope.$index)"
+          >删除</el-button>
         </template>
       </el-table-column>
     </el-table>
@@ -78,7 +100,11 @@
           <el-input v-model="insertForm.name" placeholder="请输入姓名" clearable></el-input>
         </el-form-item>
         <el-form-item label="电话" prop="phone">
-          <el-input v-model="insertForm.phone" placeholder="请输入电话" clearable></el-input>
+          <el-input v-model="insertForm.phone" placeholder="请输入电话号码" clearable></el-input>
+        </el-form-item>
+        <el-form-item label="成本" prop="cost">
+          <!-- 这里目前只能输入整数 但实际上数据库里是可以存的 需要调整校验方式 -->
+          <el-input v-model.number="insertForm.cost" placeholder="请输入成本 单位:元/小时" clearable></el-input>
         </el-form-item>
         <el-form-item label="角色" prop="role">
           <el-select v-model="insertForm.role" placeholder="请选择角色" style="width: 100%">
@@ -109,15 +135,17 @@ export default {
       list: [],
       dialogVisible: false,
       insertForm: {
-        id:null,
+        id: null,
         name: null,
         phone: null,
-        role: null
+        role: null,
+        cost: null
       },
       rules: {
         name: [{ required: true, message: "请输入姓名", trigger: "blur" }],
         phone: [{ required: true, message: "请输入电话", trigger: "blur" }],
-        role: [{ required: true, message: "请选择角色", trigger: "blur" }]
+        role: [{ required: true, message: "请选择角色", trigger: "blur" }],
+        cost: [{ required: false, message: "请输入成本", trigger: "blur" }]
       }
     };
   },
@@ -166,13 +194,14 @@ export default {
         if (valid) {
           this.listLoading = true;
           var form = {
-              name: this.insertForm.name,
-              phone: this.insertForm.phone,
-              role: this.insertForm.role
-            };
-            if(this.insertForm.id != null) {
-                form.id = this.insertForm.id;
-            }
+            name: this.insertForm.name,
+            phone: this.insertForm.phone,
+            role: this.insertForm.role,
+            cost: this.insertForm.cost
+          };
+          if (this.insertForm.id != null) {
+            form.id = this.insertForm.id;
+          }
           this.http.post(
             this.port.manage.insert,
             form,
@@ -180,7 +209,8 @@ export default {
               this.listLoading = false;
               if (res.code == "ok") {
                 this.$message({
-                  message: this.insertForm.id!=null?'修改':'创建'+"成功",
+                  message:
+                    this.insertForm.id != null ? "修改" : "创建" + "成功",
                   type: "success"
                 });
                 this.dialogVisible = false;
@@ -226,10 +256,10 @@ export default {
             this.$refs.upload.clearFiles();
             this.listLoading = false;
             if (res.code == "ok") {
-                this.$message({
-                  message: "导入成功",
-                  type: "success"
-                });
+              this.$message({
+                message: "导入成功",
+                type: "success"
+              });
               //重新读取列表
               this.getUser();
             } else {
@@ -329,22 +359,24 @@ export default {
 
     //打开单独新增的Dialog
     openInsertDialog(i) {
-        if(i != null) {
-            this.insertForm = {
-                id: this.list[i].id,
-                name: this.list[i].name,
-                phone: this.list[i].phone,
-                role: this.list[i].role
-            };
-        } else {
-            this.insertForm = {
-                id: null,
-                name: null,
-                phone: null,
-                role: null
-            };
-        }
-        this.dialogVisible = true;
+      if (i != null) {
+        this.insertForm = {
+          id: this.list[i].id,
+          name: this.list[i].name,
+          phone: this.list[i].phone,
+          role: this.list[i].role,
+          cost: this.list[i].cost
+        };
+      } else {
+        this.insertForm = {
+          id: null,
+          name: null,
+          phone: null,
+          role: null,
+          cost: null
+        };
+      }
+      this.dialogVisible = true;
     }
   },