churf
2023-08-23 bc5cdaed182da3914fdb215fe73d3755b06c3ea6
新增表单自定义校验,显示优化
5 files modified
427 ■■■■■ changed files
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/task/rest/TaskDaliyController.java 76 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/task/service/TaskDaliyService.java 3 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/task/service/impl/TaskDaliyServiceImpl.java 24 ●●●●● patch | view | raw | blame | history
eladmin-web-master/src/api/task/taskDaliy.js 11 ●●●●● patch | view | raw | blame | history
eladmin-web-master/src/views/task/taskDaliy/index.vue 313 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/task/rest/TaskDaliyController.java
@@ -1,18 +1,18 @@
/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
 *  Copyright 2019-2020 Zheng Jie
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package me.zhengjie.modules.task.rest;
import cn.hutool.core.date.DateTime;
@@ -21,6 +21,7 @@
import me.zhengjie.modules.task.domain.TaskDaliyMongo;
import me.zhengjie.modules.task.service.TaskDaliyService;
import me.zhengjie.modules.task.service.dto.TaskDaliyQueryCriteria;
import me.zhengjie.modules.task.service.impl.TaskDaliyServiceImpl;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
@@ -30,16 +31,17 @@
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.Date;
import javax.servlet.http.HttpServletResponse;
/**
* @website https://eladmin.vip
* @author 赵士淞
* @date 2022-12-30
**/
 * @author 赵士淞
 * @website https://eladmin.vip
 * @date 2022-12-30
 **/
@RestController
@RequiredArgsConstructor
@Api(tags = "任务日报管理")
@@ -60,15 +62,15 @@
    @Log("查询任务日报")
    @ApiOperation("查询任务日报")
    @PreAuthorize("@el.check('taskDaliy:list')")
    public ResponseEntity<Object> queryTaskDaliy(TaskDaliyQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(taskDaliyService.queryAll(criteria,pageable),HttpStatus.OK);
    public ResponseEntity<Object> queryTaskDaliy(TaskDaliyQueryCriteria criteria, Pageable pageable) {
        return new ResponseEntity<>(taskDaliyService.queryAll(criteria, pageable), HttpStatus.OK);
    }
    @GetMapping(value= "/withHours")
    @GetMapping(value = "/withHours")
    @Log("查询任务日报")
    @ApiOperation("查询任务日报")
    @PreAuthorize("@el.check('taskDaliy:list')")
    public ResponseEntity<Object> queryTaskDaliyWithTaskUser(TaskDaliyQueryCriteria criteria, Pageable pageable){
    public ResponseEntity<Object> queryTaskDaliyWithTaskUser(TaskDaliyQueryCriteria criteria, Pageable pageable) {
        //return new ResponseEntity<>(taskDaliyService.queryAllWithTaskUser(criteria,pageable),HttpStatus.OK);
        return null;
    }
@@ -77,23 +79,23 @@
    @Log("查询任务日报")
    @ApiOperation("查询任务日报")
    @PreAuthorize("@el.check('taskDaliy:list')")
    public ResponseEntity<Object> queryTaskDaliy(TaskDaliyQueryCriteria criteria){
        return new ResponseEntity<>(taskDaliyService.queryAll(criteria),HttpStatus.OK);
    public ResponseEntity<Object> queryTaskDaliy(TaskDaliyQueryCriteria criteria) {
        return new ResponseEntity<>(taskDaliyService.queryAll(criteria), HttpStatus.OK);
    }
    @PostMapping
    @Log("新增任务日报")
    @ApiOperation("新增任务日报")
    @PreAuthorize("@el.check('taskDaliy:add')")
    public ResponseEntity<Object> createTaskDaliy(@Validated @RequestBody TaskDaliyMongo resources){
        return new ResponseEntity<>(taskDaliyService.create(resources),HttpStatus.CREATED);
    public ResponseEntity<Object> createTaskDaliy(@Validated @RequestBody TaskDaliyMongo resources) {
        return new ResponseEntity<>(taskDaliyService.create(resources), HttpStatus.CREATED);
    }
    @PutMapping
    @Log("修改任务日报")
    @ApiOperation("修改任务日报")
    @PreAuthorize("@el.check('taskDaliy:edit')")
    public ResponseEntity<Object> updateTaskDaliy(@Validated @RequestBody TaskDaliyMongo resources){
    public ResponseEntity<Object> updateTaskDaliy(@Validated @RequestBody TaskDaliyMongo resources) {
        taskDaliyService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }
@@ -111,23 +113,31 @@
    @Log("查询某月已完成工时")
    @ApiOperation("查询某月已完成工时")
    @PreAuthorize("@el.check('taskDaliy:list')")
    public ResponseEntity<Object> queryCompletedWork(TaskDaliyQueryCriteria criteria){
        return new ResponseEntity<>(taskDaliyService.queryCompletedWork(criteria, false),HttpStatus.OK);
    public ResponseEntity<Object> queryCompletedWork(TaskDaliyQueryCriteria criteria) {
        return new ResponseEntity<>(taskDaliyService.queryCompletedWork(criteria, false), HttpStatus.OK);
    }
    @GetMapping(value = "/taskTotalConsumedHours")
    @Log("查询任务的总消耗工时")
    @ApiOperation("查询任务的总消耗工时")
    @PreAuthorize("@el.check('taskDaliy:list')")
    public ResponseEntity<Object> queryTaskTotalConsumedHours(TaskDaliyQueryCriteria criteria){
        return new ResponseEntity<>(taskDaliyService.queryTaskTotalConsumedHours(criteria),HttpStatus.OK);
    public ResponseEntity<Object> queryTaskTotalConsumedHours(TaskDaliyQueryCriteria criteria) {
        return new ResponseEntity<>(taskDaliyService.queryTaskTotalConsumedHours(criteria), HttpStatus.OK);
    }
    @GetMapping(value = "/getDetail")
    @Log("查询任务的总消耗工时")
    @ApiOperation("获取任务日报的相关信息")
    @PreAuthorize("@el.check('taskDaliy:list')")
    public ResponseEntity<Object> getDailyDetail(String taskUserId, String fillDate){
        return new ResponseEntity<>(taskDaliyService.getDailyDetail(taskUserId,fillDate),HttpStatus.OK);
    public ResponseEntity<Object> getDailyDetail(String taskUserId, String fillDate) {
        return new ResponseEntity<>(taskDaliyService.getDailyDetail(taskUserId, fillDate), HttpStatus.OK);
    }
    @GetMapping(value = "/checkTask")
    @Log("查询任务的总消耗工时")
    @ApiOperation("判断当前这个日报填写的这个进度是否合法")
    @PreAuthorize("@el.check('taskDaliy:list')")
    public ResponseEntity<Object> checkTask(Long taskProgress, String taskUserId) {
        return new ResponseEntity<>(taskDaliyService.checkTask(taskProgress, taskUserId.split(",")[0]),HttpStatus.OK);
    }
}
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/task/service/TaskDaliyService.java
@@ -117,4 +117,7 @@
    TaskDaliyMongo getDailyDetail(String taskUserId, String fillDate);
    boolean checkTask(Long taskProgress, String taskUserId);
}
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/task/service/impl/TaskDaliyServiceImpl.java
@@ -226,25 +226,27 @@
        return null;
    }
    private static void check(TaskDaliyMongo resources, List<TaskDaliyMongo> taskDaliyMongoList) {
    public static boolean check(TaskDaliyMongo resources, List<TaskDaliyMongo> taskDaliyMongoList) {
        List<TaskDaliyMongo> beforeList = taskDaliyMongoList.stream().filter(item -> item.getFillDate().before(resources.getFillDate())).collect(Collectors.toList());
        List<TaskDaliyMongo> afterList = taskDaliyMongoList.stream().filter(item -> item.getFillDate().after(resources.getFillDate())).collect(Collectors.toList());
        for (TaskDaliyMongo beforeListMongo : beforeList) {
            if (resources.getTaskProgress() <= beforeListMongo.getTaskProgress()) {
                throw new BadRequestException("任务进度必须比前一次多且比后一次少!");
                return false;
            }
        }
        for (TaskDaliyMongo afterListMongo : afterList) {
            if (resources.getTaskProgress() >= afterListMongo.getTaskProgress()) {
                throw new BadRequestException("任务进度必须比前一次多且比后一次少!");
                return false;
            }
        }
        return true;
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    @CacheEvict(cacheNames = "task",allEntries = true)
    @CacheEvict(cacheNames = "taskUser",allEntries = true)
    public void update(TaskDaliyMongo resources) {
//        List<TaskDaliyMongo> taskUserMongoList = mongoTemplate.find(new Query(new Criteria("userId").is(SecurityUtils.getCurrentUserId()).and("taskUserMongo").is(resources.getTaskUserMongo())), TaskDaliyMongo.class);
//        check(resources,taskUserMongoList);
@@ -254,7 +256,6 @@
        byId.setTaskStatus("task_status_in_hand");
        mongoTemplate.save(byId);
        //更新的是日报~
    }
    /**
@@ -592,4 +593,17 @@
            throw new RuntimeException(e);
        }
    }
    @Override
    public boolean checkTask(Long taskProgress, String taskUserId) {
        //获取当前用户,当前任务,所有的日报
        List<TaskDaliyMongo> daliyMongoList = mongoTemplate.find(new Query(new Criteria("userId").is(SecurityUtils.getCurrentUserId()).and("taskUserMongo.id").is(taskUserId)), TaskDaliyMongo.class);
        for (int i = 0; i < daliyMongoList.size(); i++) {
            //如果有一个日报的任务进度要比这个大,就返回假
            if(daliyMongoList.get(i).getTaskProgress() > taskProgress){
                return false;
            }
        }
        return true;
    }
}
eladmin-web-master/src/api/task/taskDaliy.js
@@ -80,4 +80,13 @@
  })
}
export default { get, getAll, add, edit, del, completedWork, complianceWork, taskTotalConsumedHours, getTaskDaliyWithHours, getDailyDetail }
export function checkTaskHours(params) {
  return request({
    url: 'api/taskDaliy/checkTask?taskProgress=' + params.taskProgress + '&taskUserId=' + params.taskUserId,
    method: 'get',
    async: false,
    params
  })
}
export default { get, getAll, add, edit, del, completedWork, complianceWork, taskTotalConsumedHours, getTaskDaliyWithHours, getDailyDetail, checkTaskHours }
eladmin-web-master/src/views/task/taskDaliy/index.vue
@@ -172,7 +172,15 @@
            </el-select>
          </el-form-item>
          <el-form-item label="分配任务" prop="taskUserMongo">
            <el-select v-model="form.taskUserMongo.id" filterable clearable placeholder="请选择" style="width: 340px;" :disabled="form.flag" @change="formTaskUserChange">
            <el-select v-if="formTaskUserIds.length > 0" :key="form.taskUserMongo.id" v-model="form.taskUserMongo.id" filterable clearable placeholder="请选择" style="width: 340px;" :disabled="form.flag" @change="formTaskUserChange">
              <el-option
                v-for="item in formTaskUserIds"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              />
            </el-select>
            <el-select v-else filterable clearable placeholder="请选择" style="width: 340px;" :disabled="form.flag" @change="formTaskUserChange">
              <el-option
                v-for="item in formTaskUserIds"
                :key="item.id"
@@ -259,6 +267,32 @@
          </template>
        </el-table-column>
      </el-table>
      <el-dialog
        title="提示"
        :visible.sync="centerDialogVisibleTaskHours"
        width="30%"
        center
      >
        <span>本次日报的消耗工时已超过任务工时,确定要继续吗?</span>
        <span slot="footer" class="dialog-footer">
          <el-button @click="centerDialogVisibleTaskHours = false">取 消</el-button>
          <el-button type="primary" @click="submitDialogTaskHours">确 定</el-button>
        </span>
      </el-dialog>
      <el-dialog
        title="提示"
        :visible.sync="centerDialogVisibleTaskProgress"
        width="30%"
        center
      >
        <span>本次日报的任务进度比您原本的任务进度要少,确定要继续吗?</span>
        <span slot="footer" class="dialog-footer">
          <el-button @click="centerDialogVisibleTaskProgress = false">取 消</el-button>
          <el-button type="primary" @click="submitDialogTaskProgress">确 定</el-button>
        </span>
      </el-dialog>
      <!--分页组件-->
      <pagination />
    </div>
@@ -389,13 +423,26 @@
      tobeTask: '未着手任务',
      tobeTasked: '临期任务',
      currentTask: null,
      taskLoading: true
      taskLoading: true,
      centerDialogVisibleTaskHours: false,
      centerDialogVisibleTaskProgress: false,
      confirmHours: false,
      confirmProgress: false,
      newValue: '',
      oldValue: '',
      resData: true
    }
  },
  computed: {
    ...mapGetters([
      'user'
    ])
  },
  watch: {
    'form.consumedHours': function(newVal, oldVal) {
      this.newValue = newVal
      this.oldValue = oldVal
    }
  },
  methods: {
    // 钩子:在获取表格数据之前执行,false 则代表不获取数据
@@ -425,6 +472,145 @@
      this.getOngoingTasks()
      this.getTaskNotStarted()
      return true
    },
    // 新增与编辑前做的操作
    [CRUD.HOOK.afterToCU](crud, form) {
      // 判断表单结算状态
      if (this.form.settlementStatus === constant.SETTLEMENT_STATUS_SETTLED) {
        // 表单禁用标记(结算状态)
        this.disabledFlagBySettlement = true
      } else {
        // 表单禁用标记(结算状态)
        this.disabledFlagBySettlement = false
      }
      // 随机数
      this.random = Math.random()
    },
    [CRUD.HOOK.afterSubmit]() {
      this.form.flag = false
      this.currentTask = null
      this.formTasks = []
      this.formTaskUserIds = []
      this.confirmHours = false
      this.confirmProgress = false
    },
    [CRUD.HOOK.afterEditError]() {
      this.form.flag = false
      this.currentTask = null
      this.formTasks = []
      this.formTaskUserIds = []
      this.confirmHours = false
      this.confirmProgress = false
    },
    [CRUD.HOOK.afterEditCancel]() {
      this.form.flag = false
      this.currentTask = null
      this.formTasks = []
      this.formTaskUserIds = []
      this.confirmHours = false
      this.confirmProgress = false
    },
    [CRUD.HOOK.afterAddCancel]() {
      this.form.flag = false
      this.currentTask = null
      this.formTasks = []
      this.formTaskUserIds = []
      this.confirmHours = false
      this.confirmProgress = false
    },
    [CRUD.HOOK.afterAddError]() {
      this.form.flag = false
      this.currentTask = null
      this.formTasks = []
      this.formTaskUserIds = []
      this.confirmHours = false
      this.confirmProgress = false
    },
    // 钩子:新建 - 之前
    [CRUD.HOOK.beforeToAdd]() {
      this.form.userId = this.user.id
      this.form.userNickName = this.user.nickName
      // 判断用户最大角色级别是否是角色级别:超级管理员或角色级别:总经理
      if (this.userRolesLevelMin !== this.roleLevelSuper && this.userRolesLevelMin !== this.roleLevelGeneral) {
        // 表单赋值
        this.form.userId = this.user.id
        this.form.userNickName = this.user.nickName
        // 表单用户变更
        this.formUserChange()
        this.formTaskChange()
      }
      if (this.currentTask) {
        this.form.projectId = this.currentTask.projectId
        this.formProjectChange(() => {
          this.form.taskId = this.currentTask.taskId
          this.formTaskChange(() => { this.form.taskUserMongo.id = this.currentTask.id })
        })
        this.form.taskHours = this.currentTask.performanceHours
        this.form.alreadyConsumedHours = this.currentTask.alreadyConsumedHours
        this.form.flag = true
      }
    },
    // 钩子:编辑 - 之前
    [CRUD.HOOK.beforeToEdit]() {
      this.form.userId = this.user.id
      this.form.userNickName = this.user.nickName
      crudTask.getAllOfDaily({ projectId: this.form.projectId }).then(res => {
        // 检索任务列表
        this.formTasks = res
      })
      crudTaskUser.getAllTaskUser().then(res => {
        if (res === []) {
          this.formTaskUserIds = []
        }
        this.formTaskUserIds = res
        // 循环表单任务列表
        for (let i = 0; i < this.formTaskUserIds.length; i++) {
          // 判断是否为选中任务
          if (this.formTaskUserIds[i].id === this.form.taskUserMongo.id) {
            this.form.taskHours = this.formTaskUserIds[i].performanceHours
            this.form.alreadyConsumedHours = this.formTaskUserIds[i].alreadyConsumedHours
          }
        }
      })
    },
    [CRUD.HOOK.afterRefresh]() {
      this.taskLoading = false
    },
    [CRUD.HOOK.beforeSubmit]() {
      // 先check一下
      this.resData = this.getCheckResult(this.form.taskProgress, this.form.taskUserMongo.id)
      console.log(2)
      console.log(this.resData)
      if (this.resData === false && !this.confirmProgress) {
        // 为假
        this.centerDialogVisibleTaskProgress = true
        this.waitForPropertyConfirmProgress()
        return false
      }
      const result = (this.form.alreadyConsumedHours - 0) + (this.newValue - 0) - (this.oldValue - 0)
      if (result > this.form.taskHours && !this.confirmHours) {
        this.centerDialogVisibleTaskHours = true
        this.waitForPropertyConfirmHours()
        return false
      }
      return true
    },
    getCheckResult(taskProgress, taskUserId) {
      return (async function() {
        console.log(1)
        const result = await crudTaskDaliy.checkTaskHours({ 'taskProgress': taskProgress, 'taskUserId': taskUserId })
        console.log(3)
        return result
      })()
    },
    getAdventTasks() {
      crudTaskUser.getAdventTasks().then(res => {
@@ -479,103 +665,11 @@
        })
      }
    },
    // 新增与编辑前做的操作
    [CRUD.HOOK.afterToCU](crud, form) {
      // 判断表单结算状态
      if (this.form.settlementStatus === constant.SETTLEMENT_STATUS_SETTLED) {
        // 表单禁用标记(结算状态)
        this.disabledFlagBySettlement = true
      } else {
        // 表单禁用标记(结算状态)
        this.disabledFlagBySettlement = false
      }
      // 随机数
      this.random = Math.random()
    },
    [CRUD.HOOK.afterSubmit]() {
      this.form.flag = false
      this.currentTask = null
      this.formTasks = []
      this.formTaskUserIds = []
    },
    [CRUD.HOOK.afterEditError]() {
      this.form.flag = false
      this.currentTask = null
      this.formTasks = []
      this.formTaskUserIds = []
    },
    [CRUD.HOOK.afterEditCancel]() {
      this.form.flag = false
      this.currentTask = null
      this.formTasks = []
      this.formTaskUserIds = []
    },
    [CRUD.HOOK.afterAddCancel]() {
      this.form.flag = false
      this.currentTask = null
      this.formTasks = []
      this.formTaskUserIds = []
    },
    [CRUD.HOOK.afterAddError]() {
      this.form.flag = false
      this.currentTask = null
      this.formTasks = []
      this.formTaskUserIds = []
    },
    // 钩子:新建 - 之前
    [CRUD.HOOK.beforeToAdd]() {
      this.form.userId = this.user.id
      this.form.userNickName = this.user.nickName
      // 判断用户最大角色级别是否是角色级别:超级管理员或角色级别:总经理
      if (this.userRolesLevelMin !== this.roleLevelSuper && this.userRolesLevelMin !== this.roleLevelGeneral) {
        // 表单赋值
        this.form.userId = this.user.id
        this.form.userNickName = this.user.nickName
        // 表单用户变更
        this.formUserChange()
        this.formTaskChange()
      }
      if (this.currentTask) {
        this.form.projectId = this.currentTask.projectId
        this.formProjectChange(() => {
          this.form.taskId = this.currentTask.taskId
          this.formTaskChange(() => { this.form.taskUserMongo.id = this.currentTask.id })
        })
        this.form.taskHours = this.currentTask.performanceHours
        this.form.alreadyConsumedHours = this.currentTask.alreadyConsumedHours
        this.form.flag = true
      }
    },
    // 钩子:编辑 - 之前
    [CRUD.HOOK.beforeToEdit]() {
      this.form.userId = this.user.id
      this.form.userNickName = this.user.nickName
      crudTask.getAllOfDaily({ projectId: this.form.projectId }).then(res => {
        // 检索任务列表
        this.formTasks = res
      })
      crudTaskUser.getAllTaskUser().then(res => {
        if (res === []) {
          this.formTaskUserIds = []
        }
        this.formTaskUserIds = res
        // 循环表单任务列表
        for (let i = 0; i < this.formTaskUserIds.length; i++) {
          // 判断是否为选中任务
          if (this.formTaskUserIds[i].id === this.form.taskUserMongo.id) {
            this.form.taskHours = this.formTaskUserIds[i].performanceHours
            this.form.alreadyConsumedHours = this.formTaskUserIds[i].alreadyConsumedHours
          }
        }
      })
    },
    formDateChange() {
      crudTaskDaliy.getDailyDetail({ taskUserId: this.form.taskUserMongo.id, fillDate: this.form.fillDate }).then(res => {
        this.form.taskProgress = res.taskProgress
        this.form.consumedHours = res.consumedHours
        this.form.remarks = res.remarks
      })
    },
    // 表单用户变更
@@ -613,7 +707,6 @@
        crudTask.getAllOfDaily({ projectId: this.form.projectId }).then(res => {
          // 检索任务列表
          this.formTasks = res
          if (cb) {
            cb()
          }
@@ -655,8 +748,32 @@
      this.currentTask = object
      this.crud.toAdd()
    },
    [CRUD.HOOK.afterRefresh]() {
      this.taskLoading = false
    submitDialogTaskHours() {
      this.centerDialogVisibleTaskHours = false
      this.confirmHours = true
    },
    submitDialogTaskProgress() {
      this.centerDialogVisibleTaskProgress = false
      this.confirmProgress = true
    },
    waitForPropertyConfirmHours() {
      new Promise(resolve => {
        this.$watch('confirmHours', (newValue) => {
          if (newValue === true) {
            console.log(newValue)
            resolve(this.crud.submitCU())
          }
        })
      })
    },
    waitForPropertyConfirmProgress() {
      new Promise(resolve => {
        this.$watch('confirmProgress', (newValue) => {
          if (newValue === true) {
            resolve(this.crud.submitCU())
          }
        })
      })
    }
  }
}