forked from kidgrow-microservices-platform

zhaoxiaohao
2021-04-22 d6c989a5d9122e5cf969dd640a92b8e12caf8aa6
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
package com.kidgrow.oprationcenter.service.impl;
 
import com.kidgrow.common.service.impl.SuperServiceImpl;
import com.kidgrow.oprationcenter.mapper.AppointmentTimeMapper;
import com.kidgrow.oprationcenter.model.AppointmentTime;
import com.kidgrow.oprationcenter.service.IAppointmentTimeService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.MapUtils;
import org.springframework.stereotype.Service;
 
import java.util.List;
import java.util.Map;
 
/**
 * 石家庄喜高科技有限责任公司 版权所有 © Copyright 2020<br>
 *
 * @Description: <br>
 * @Project: <br>
 * @CreateDate: Created in 2021/3/1 14:33 <br>
 * @Author: <a href="78125310@kidgrow.com">dougang</a>
 */
@Slf4j
@Service
public class AppointmentTimeServiceImpl extends SuperServiceImpl<AppointmentTimeMapper, AppointmentTime> implements IAppointmentTimeService {
 
    /**
     * 保存
     *
     * @param map
     * @return
     */
    @Override
    public boolean save(Map<String, Object> map) {
        AppointmentTime time = null;
        boolean flag = false;
 
        String[] items = (String[]) MapUtils.getObject(map, "list");
        String id = MapUtils.getString(map, "id");
 
        baseMapper.delByAdvisoryId(Long.parseLong(id));
 
        for (String item : items) {
            String[] tmp = item.split("_");
 
            time = new AppointmentTime();
            time.setAdvisoryId(Long.parseLong(id));
            time.setName(tmp[0]);
            if ("1".equals(tmp[1])) {
                time.setMorning(1);
            } else if ("2".equals(tmp[1])) {
                time.setAfternoon(1);
            } else if ("3".equals(tmp[1])) {
                time.setEvening(1);
            }
            int insert = baseMapper.insert(time);
            if (insert == 0) {
                flag = true;
                break;
            }
        }
 
        return flag ? false : true;
    }
 
    /**
     * 查询
     * @param id
     * @return
     */
    @Override
    public String queryByAdvisoryId(Long id) {
        StringBuffer result = new StringBuffer();
        List<AppointmentTime> appointmentTimes = baseMapper.queryByAdvisoryId(id);
 
        if (appointmentTimes.size() > 0) {
            for (AppointmentTime app : appointmentTimes) {
                if (app.getMorning() == 1) {
                    result.append(app.getName() + "_1");
                    result.append(",");
                } else if (app.getAfternoon() == 1) {
                    result.append(app.getName() + "_2");
                    result.append(",");
                } else if (app.getEvening() == 1) {
                    result.append(app.getName() + "_3");
                    result.append(",");
                }
            }
 
            if (result.length() > 0) {
                result.substring(0, result.length() - 1);
            }
        }
        return result.toString();
    }
 
    @Override
    public List<AppointmentTime> findByAdvisoryId(Long id) {
        return baseMapper.queryByAdvisoryId(id);
    }
 
    @Override
    public int delByAdvisoryId(Long id) {
        return baseMapper.delByAdvisoryId(id);
    }
}