CalendarEventServiceImpl.java 3.56 KB
Newer Older
1 2 3 4 5 6 7 8
package pwc.taxtech.atms.service.impl;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import pwc.taxtech.atms.calendar.dao.*;
import pwc.taxtech.atms.calendar.dao.ext.CalendarExtMapper;
9
import pwc.taxtech.atms.calendar.dto.CalendarEventDto;
10
import pwc.taxtech.atms.calendar.entity.CalendarEvent;
11 12
import pwc.taxtech.atms.calendar.entity.CalendarEventExample;
import pwc.taxtech.atms.common.util.DateUtils;
13
import pwc.taxtech.atms.dto.OperationResultDto;
14
import pwc.taxtech.atms.dto.calendar.CalendarDisplayQueryParamDto;
15 16 17
import pwc.taxtech.atms.service.ICalendarEventService;

import javax.annotation.Resource;
Mccoy Z Xia's avatar
Mccoy Z Xia committed
18
import java.util.ArrayList;
19
import java.util.Date;
20
import java.util.List;
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35

/**
 * <p> @Description </p>
 *
 * @Author: Mccoy Z Xia (Xia zhixin)
 * @Date: 2019-07-10 14:32
 * @Version: 1.0
 **/
@Service
public class CalendarEventServiceImpl extends BaseService implements ICalendarEventService {

    private static final Logger log = LoggerFactory.getLogger(CalendarEventServiceImpl.class);

    @Resource
    private CalendarEventMapper calendarEventMapper;
36 37
    @Resource
    private CalendarExtMapper calendarExtMapper;
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55

    @Override
    public OperationResultDto addEvent(CalendarEvent event) {
        if (event.getId() == null) {
            event.setId(idService.nextId());
        }
        Date nowDate = new Date();
        event.setCreateTime(nowDate);
        event.setUpdateTime(nowDate);

        int count = 0;
        try {
            count = calendarEventMapper.insert(event);
        } catch (Exception e) {
            log.error("addConfiguration error", e);
        }
        boolean result = count > 0;
        String msg = result ? "1" : "-1";
56
        return new OperationResultDto(result, msg, event.getId().toString());
57 58 59 60 61
    }

    @Override
    public OperationResultDto updateEvent(CalendarEvent event) {
        int count = 0;
Mccoy Z Xia's avatar
Mccoy Z Xia committed
62
        event.setCreateTime(null);
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
        event.setUpdateTime(new Date());
        try {
            count = calendarEventMapper.updateByPrimaryKeySelective(event);
        } catch (Exception e) {
            log.error("updateConfiguration error", e);
        }
        boolean result = count > 0;
        String msg = result ? "1" : "-1";
        return new OperationResultDto(result, msg);
    }

    @Override
    public OperationResultDto deleteEvent(Long id) {
        int count = 0;
        try {
            count = calendarEventMapper.deleteByPrimaryKey(id);
        } catch (Exception e) {
            log.error("deleteConfiguration error", e);
        }
        boolean result = count > 0;
        String msg = result ? "1" : "-1";
        return new OperationResultDto(result, msg);
    }
86

Mccoy Z Xia's avatar
Mccoy Z Xia committed
87 88 89 90 91 92 93 94 95 96 97 98
    @Override
    public OperationResultDto getEventByEntityId(Long entityId) {
        List<CalendarEventDto> dtoList = new ArrayList<>();

        try {
            dtoList = calendarExtMapper.getEventByEntityId(entityId);
        } catch (Exception e) {
            log.error("getEventByEntityId error", e);
        }
        return OperationResultDto.success(dtoList);
    }

Mccoy Z Xia's avatar
Mccoy Z Xia committed
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
    @Override
    public OperationResultDto batchUpdate(List<CalendarEvent> list) {
        Date updateTime = new Date();
        try {
            list.forEach(p -> {
                p.setUpdateTime(updateTime);
//                authUserHelper.getCurrentUserId();
                calendarEventMapper.updateByPrimaryKeySelective(p);
            });
        } catch (Exception e) {
            log.error("getEventByEntityId error", e);
        }

        return OperationResultDto.success();
    }

115
}