lin
2024-03-14 d2ef8745f1370566fdca904726df21103bf36ed5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.task.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springblade.common.constant.DictConstant;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.modules.place.entity.PlaceEntity;
import org.springblade.modules.place.service.IPlaceService;
import org.springblade.modules.system.entity.Dict;
import org.springblade.modules.task.dto.TaskHotelReportingDTO;
import org.springblade.modules.task.entity.TaskHotelReportingEntity;
import org.springblade.modules.task.mapper.TaskHotelReportingMapper;
import org.springblade.modules.task.service.ITaskHotelReportingService;
import org.springblade.modules.task.service.ITaskService;
import org.springblade.modules.task.vo.TaskHotelReportingVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import javax.annotation.Resource;
import java.util.Date;
 
/**
 * 旅馆安全自查任务 服务实现类
 *
 * @author BladeX
 * @since 2023-11-06
 */
@Service
public class TaskHotelReportingServiceImpl extends ServiceImpl<TaskHotelReportingMapper, TaskHotelReportingEntity> implements ITaskHotelReportingService {
 
    @Resource
    @Lazy
    private ITaskService taskService;
 
    @Autowired
    private IPlaceService placeService;
 
    @Override
    public IPage<TaskHotelReportingVO> selectTaskHotelReportingPage(IPage<TaskHotelReportingVO> page, TaskHotelReportingVO taskHotelReporting) {
        return page.setRecords(baseMapper.selectTaskHotelReportingPage(page, taskHotelReporting));
    }
 
 
    @Override
    public boolean saveHotelReporting(TaskHotelReportingDTO taskHotelReporting) {
        String name = DictConstant.HOTEL_SECURITY;
        // 九小场所
        if (taskHotelReporting.getEventType().equals(1)) {
            taskHotelReporting.setReportType(7);
            name = DictConstant.FIRE_CHECK;
        }
        Long aLong = taskService.saveTask(2, name, 1, "", AuthUtil.getUserId(),
            taskHotelReporting.getHouseCode(), taskHotelReporting.getReportType(),0);
        if (aLong > 0) {
            // 通过houseCode 获取场所id
            QueryWrapper<PlaceEntity> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("is_deleted", 0).eq("house_code", taskHotelReporting.getHouseCode());
            PlaceEntity placeEntity = placeService.getOne(queryWrapper);
            taskHotelReporting.setPlaceId(placeEntity.getId());
            taskHotelReporting.setTaskId(aLong);
            taskHotelReporting.setCheckUserId(AuthUtil.getUserId());
            return baseMapper.insert(taskHotelReporting) > 0;
        }
        return false;
    }
 
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean updateHotelReporting(TaskHotelReportingVO taskHotelReporting) throws Exception {
        Long aLong = taskService.updateTask(null, null, null, "", AuthUtil.getUserId(), taskHotelReporting.getTaskId(), taskHotelReporting.getStatus());
        if (aLong > 0) {
            if (null!=taskHotelReporting.getStatus()
                && taskHotelReporting.getStatus()!=4) {
                taskHotelReporting.setConfirmFlag(taskHotelReporting.getStatus().toString());
                taskHotelReporting.setConfirmUserId(AuthUtil.getUserId());
                taskHotelReporting.setConfirmTime(new Date());
            }
            boolean b = baseMapper.updateById(taskHotelReporting) > 0;
            if (b) {
                return b;
            }
            throw new Exception("更新失败!");
        }
        return false;
    }
}