Administrator
2023-08-11 5ad4e2b2e881204102cd0a5e96da936db19f39c7
ard-work/src/main/java/com/ruoyi/app/patrolplan/service/impl/ArdAppPatrolplanServiceImpl.java
@@ -14,8 +14,10 @@
import com.ruoyi.alarmpoints.well.domain.ArdAlarmpointsWellVo;
import com.ruoyi.alarmpoints.well.mapper.ArdAlarmpointsWellMapper;
import com.ruoyi.app.patrolplan.domain.ArdAppPatrolpoint;
import com.ruoyi.app.patrolplan.domain.ArdAppPatrolpointRecord;
import com.ruoyi.app.patrolplan.domain.ArdAppPatroluser;
import com.ruoyi.app.patrolplan.mapper.ArdAppPatrolpointMapper;
import com.ruoyi.app.patrolplan.mapper.ArdAppPatrolpointRecordMapper;
import com.ruoyi.app.patrolplan.mapper.ArdAppPatroluserMapper;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.entity.SysUserVo;
@@ -57,6 +59,9 @@
    @Resource
    private SysUserMapper sysUserMapper;
    @Resource
    private ArdAppPatrolpointRecordMapper recordMapper;
    /**
     * 查询app巡检计划
@@ -156,18 +161,46 @@
    @Override
    @Transactional
    public int deleteArdApp(String id) {
        //ardAppPatroluserMapper.deleteArdAppPatroluserByReserved1(id);
        /*ardAppPatrolpointMapper.deleteArdAppPatrolpointById(id);
        if(ardAppPatrolplanMapper.deleteArdAppPatrolplanByPatroEndTime(id)>0){
            return Results.succeed("删除成功!");
        }else {
            return Results.error("删除失败!");
        }*/
        try {
            Boolean del = false;
            //查询计划时间是否结束
            ArdAppPatrolplan planList = ardAppPatrolplanMapper.selectById(id);
            String cycle = planList.getCycle();
            String end = planList.getPatroEndTime();
            if(cycle.equals("day")){
                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
                String date = dateFormat.format(new Date());
                end = date +" "+end;
            }
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String toDay = dateFormat.format(new Date());
            int once = toDay.compareTo(end);
            if(once<0){
                del = true;
            }
            if(!del){
                //查询是否有打卡记录
                QueryWrapper<ArdAppPatrolpointRecord> recordQueryWrapper = new QueryWrapper<>();
                recordQueryWrapper.eq("plan_id",id);
                List<ArdAppPatrolpointRecord> recordList = recordMapper.selectList(recordQueryWrapper);
                if(recordList.size()>0){
                    del = true;
                }
            }
            if(del){
            int result = ardAppPatrolplanMapper.deleteArdAppPatrolplanById(id);//删除巡检计划
            ardAppPatrolpointMapper.deleteArdAppPatrolpointByPlanId(id);//删除巡检计划下挂点位
            ardAppPatroluserMapper.deleteArdAppPatroluserByPlanId(id);//删除巡检计划下挂用户
            return result;
            }else {
                String userId = SecurityUtils.getUserId();
                SysUser sysUser = sysUserMapper.selectUserById(userId);
                String userName = sysUser.getNickName();
                planList.setDelName(userName);
                planList.setDelTime(dateFormat.format(new Date()));
                int result = ardAppPatrolplanMapper.updateById(planList);
                return result;
            }
        } catch (Exception e){
            e.printStackTrace();
            return 0;