| | |
| | | */ |
| | | package me.zhengjie.modules.task.service.impl; |
| | | |
| | | import java.io.IOException; |
| | | import java.sql.Timestamp; |
| | | import java.text.DateFormat; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.Instant; |
| | | import java.util.*; |
| | | import java.util.function.Function; |
| | | import java.util.regex.Pattern; |
| | | import java.util.stream.Collectors; |
| | | import java.util.stream.Stream; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | import cn.hutool.core.date.DateTime; |
| | | import me.zhengjie.modules.system.service.impl.UserServiceImpl; |
| | | import me.zhengjie.modules.task.domain.*; |
| | | import org.springframework.data.domain.Page; |
| | | import org.springframework.data.domain.Pageable; |
| | | import org.springframework.data.mongodb.core.MongoTemplate; |
| | | import org.springframework.data.mongodb.core.query.Criteria; |
| | |
| | | import me.zhengjie.modules.attendance.repository.AttendanceLeaveRepository; |
| | | import me.zhengjie.modules.attendance.service.dto.AttendanceLeaveQueryCriteria; |
| | | import me.zhengjie.modules.constant.Constant; |
| | | import me.zhengjie.modules.project.domain.Project; |
| | | import me.zhengjie.modules.project.repository.ProjectRepository; |
| | | import me.zhengjie.modules.system.domain.User; |
| | | import me.zhengjie.modules.system.repository.DictDetailRepository; |
| | | import me.zhengjie.modules.system.repository.UserRepository; |
| | | import me.zhengjie.modules.system.service.RoleService; |
| | |
| | | import me.zhengjie.modules.task.service.dto.TaskDaliyQueryCriteria; |
| | | import me.zhengjie.modules.task.service.mapstruct.TaskDaliyMapper; |
| | | import me.zhengjie.utils.DateUtil; |
| | | import me.zhengjie.utils.FileUtil; |
| | | import me.zhengjie.utils.PageUtil; |
| | | import me.zhengjie.utils.QueryHelp; |
| | | import me.zhengjie.utils.SecurityUtils; |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public TaskDaliyDto create(TaskDaliyMongo resources) { |
| | | TaskDaliyMongo taskDaliyMongo = new TaskDaliyMongo(); |
| | | taskDaliyMongo.setUserId(SecurityUtils.getCurrentUserId()); |
| | | taskDaliyMongo.setFillDate(resources.getFillDate()); |
| | | taskDaliyMongo.setConsumedHours(resources.getConsumedHours()); |
| | | |
| | | Criteria criteria = new Criteria(); |
| | | criteria.and("userId").is(SecurityUtils.getCurrentUserId()); |
| | | criteria.and("taskUserMongo").is(resources.getTaskUserMongo()); |
| | | /* |
| | | 获取这个用户的这个任务的所有的日报 |
| | | |
| | | 如果这个用户在这个任务中没有填写过日报 --直接新增即可 |
| | | 如果这个用户在这个任务中填写过日报 |
| | | 1.已用户填写的日报时间为基准,新添的日报需要大于前面所有的任务进度,反之报错 |
| | | 2.已用户填写的日报时间为基准,新增的日报需要小于前面所有的任务进度 |
| | | */ |
| | | |
| | | List<TaskDaliyMongo> taskUserMongoList = mongoTemplate.find(new Query(new Criteria("userId").is(SecurityUtils.getCurrentUserId()).and("taskUserMongo").is(resources.getTaskUserMongo())), TaskDaliyMongo.class); |
| | | |
| | | if (taskUserMongoList.size() == 0) { |
| | | mongoTemplate.save(resources); |
| | | return null; |
| | | } else { |
| | | List<TaskDaliyMongo> daliyMongoList = mongoTemplate.find(new Query(new Criteria("userId").is(SecurityUtils.getCurrentUserId()).and("taskUserMongo").is(resources.getTaskUserMongo()).and("fillDate").is(resources.getFillDate())), TaskDaliyMongo.class); |
| | | if (daliyMongoList.size() == 0) { |
| | | //这天没填写过日报 |
| | | check(resources, taskUserMongoList); |
| | | mongoTemplate.save(resources); |
| | | return null; |
| | | } |
| | | |
| | | TaskDaliyMongo taskDaliyMongo = daliyMongoList.get(0); |
| | | check(resources, taskUserMongoList); |
| | | taskDaliyMongo.setTaskProgress(resources.getTaskProgress()); |
| | | taskDaliyMongo.setTaskUserMongo(resources.getTaskUserMongo()); |
| | | taskDaliyMongo.setRemarks(resources.getRemarks()); |
| | | taskDaliyMongo.setSettlementStatus(resources.getSettlementStatus()); |
| | | taskDaliyMongo.setConsumedHours(resources.getConsumedHours()); |
| | | |
| | | mongoTemplate.save(taskDaliyMongo); |
| | | } |
| | | |
| | | |
| | | return null; |
| | | } |
| | | |
| | | private static void 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("任务进度必须比前一次多且比后一次少!"); |
| | | } |
| | | } |
| | | |
| | | for (TaskDaliyMongo afterListMongo : afterList) { |
| | | if (resources.getTaskProgress() >= afterListMongo.getTaskProgress()) { |
| | | throw new BadRequestException("任务进度必须比前一次多且比后一次少!"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void update(TaskDaliyMongo resources) { |
| | | TaskDaliyMongo taskDaliyMongo = new TaskDaliyMongo(); |
| | | taskDaliyMongo.setId(resources.getId()); |
| | | taskDaliyMongo.setTaskUserMongo(resources.getTaskUserMongo()); |
| | | taskDaliyMongo.setFillDate(resources.getFillDate()); |
| | | taskDaliyMongo.setConsumedHours(resources.getConsumedHours()); |
| | | taskDaliyMongo.setTaskProgress(resources.getTaskProgress()); |
| | | taskDaliyMongo.setSettlementStatus(resources.getSettlementStatus()); |
| | | taskDaliyMongo.setUserId(SecurityUtils.getCurrentUserId()); |
| | | mongoTemplate.save(taskDaliyMongo); |
| | | List<TaskDaliyMongo> taskUserMongoList = mongoTemplate.find(new Query(new Criteria("userId").is(SecurityUtils.getCurrentUserId()).and("taskUserMongo").is(resources.getTaskUserMongo())), TaskDaliyMongo.class); |
| | | check(resources,taskUserMongoList); |
| | | mongoTemplate.save(resources); |
| | | //更新的是日报~ |
| | | |
| | | } |
| | |
| | | // 返回 |
| | | return taskDailyInterface.getConsumedHours(); |
| | | } |
| | | |
| | | @Override |
| | | public TaskDaliyMongo getDailyDetail(String taskUserId, String fillDate) { |
| | | try { |
| | | Criteria criteriaMongo = new Criteria(); |
| | | //查询一下这个任务的这一天的日报 |
| | | SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd"); |
| | | Date date = ft.parse(fillDate); |
| | | Calendar instance = Calendar.getInstance(); |
| | | instance.setTime(date); |
| | | instance.add(Calendar.DAY_OF_YEAR, 1); |
| | | date = instance.getTime(); |
| | | criteriaMongo.and("taskUserMongo").is(taskUserId); |
| | | criteriaMongo.and("fillDate").is(date); |
| | | List<TaskDaliyMongo> daliyMongoList = mongoTemplate.find(Query.query(criteriaMongo), TaskDaliyMongo.class); |
| | | if (daliyMongoList.size() == 0) { |
| | | //这一天还没填写过日报 |
| | | return null; |
| | | } else { |
| | | //这一天填写了日报 |
| | | return daliyMongoList.get(0); |
| | | } |
| | | } catch (ParseException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | } |