|  |  |  | 
|---|
|  |  |  | package com.moral.api.service.impl; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
|---|
|  |  |  | import com.moral.api.entity.OrganizationUnitAlarm; | 
|---|
|  |  |  | import com.moral.api.mapper.OrganizationUnitAlarmMapper; | 
|---|
|  |  |  | import com.moral.api.pojo.dto.organizationUnitAlarm.OrganizationUnitAlarmDTO; | 
|---|
|  |  |  | import com.moral.api.pojo.form.organizationUnitAlarm.OrganizationUnitAlarmInsertForm; | 
|---|
|  |  |  | import com.moral.api.pojo.dto.organizationUnitAlarm.OrganizationUnitAlarmQueryDTO; | 
|---|
|  |  |  | import com.moral.api.pojo.form.organizationUnitAlarm.OrganizationUnitAlarmQueryForm; | 
|---|
|  |  |  | import com.moral.api.pojo.form.organizationUnitAlarm.OrganizationUnitAlarmUpdateForm; | 
|---|
|  |  |  | import com.moral.api.service.OrganizationUnitAlarmService; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 
|---|
|  |  |  | import com.moral.api.util.CacheUtils; | 
|---|
|  |  |  | import com.moral.constant.Constants; | 
|---|
|  |  |  | import com.moral.constant.ResponseCodeEnum; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * <p> | 
|---|
|  |  |  | 
|---|
|  |  |  | @Service | 
|---|
|  |  |  | public class OrganizationUnitAlarmServiceImpl extends ServiceImpl<OrganizationUnitAlarmMapper, OrganizationUnitAlarm> implements OrganizationUnitAlarmService { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public OrganizationUnitAlarmDTO insertOrganizationUnitAlarm(OrganizationUnitAlarmInsertForm organizationInsertForm) { | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | OrganizationUnitAlarmMapper organizationUnitAlarmMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public OrganizationUnitAlarmQueryDTO query(OrganizationUnitAlarmQueryForm form) { | 
|---|
|  |  |  | //创建返回对象 | 
|---|
|  |  |  | OrganizationUnitAlarmQueryDTO dto = new OrganizationUnitAlarmQueryDTO(); | 
|---|
|  |  |  | //取参 | 
|---|
|  |  |  | Integer pageCount = form.getPage(); | 
|---|
|  |  |  | Integer size = form.getSize(); | 
|---|
|  |  |  | Integer organizationId = form.getOrganizationId(); | 
|---|
|  |  |  | Integer versionId = form.getVersionId(); | 
|---|
|  |  |  | //构造查询条件 | 
|---|
|  |  |  | QueryWrapper<OrganizationUnitAlarm> wrapper = new QueryWrapper<>(); | 
|---|
|  |  |  | wrapper.eq("is_delete", Constants.NOT_DELETE); | 
|---|
|  |  |  | wrapper.eq("organization_id",organizationId); | 
|---|
|  |  |  | wrapper.eq("version_id",versionId); | 
|---|
|  |  |  | Page<OrganizationUnitAlarm> wrapperPage = new Page<>(pageCount, size); | 
|---|
|  |  |  | Page<OrganizationUnitAlarm> resultPage = organizationUnitAlarmMapper.selectPage(wrapperPage, wrapper); | 
|---|
|  |  |  | List<OrganizationUnitAlarm> records = resultPage.getRecords(); | 
|---|
|  |  |  | //封装返回结果 | 
|---|
|  |  |  | List<OrganizationUnitAlarmDTO> dtos = new ArrayList<>(); | 
|---|
|  |  |  | records.forEach(value->dtos.add(new OrganizationUnitAlarmDTO(value))); | 
|---|
|  |  |  | dto.setOrganizationUnitAlarmDTOS(dtos); | 
|---|
|  |  |  | dto.setCode(ResponseCodeEnum.SUCCESS.getCode()); | 
|---|
|  |  |  | dto.setMsg(ResponseCodeEnum.SUCCESS.getMsg()); | 
|---|
|  |  |  | dto.setCurrent(resultPage.getCurrent()); | 
|---|
|  |  |  | dto.setPages(resultPage.getPages()); | 
|---|
|  |  |  | dto.setSize(resultPage.getSize()); | 
|---|
|  |  |  | dto.setTotal(resultPage.getTotal()); | 
|---|
|  |  |  | return dto; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public OrganizationUnitAlarmDTO update(OrganizationUnitAlarmUpdateForm form) { | 
|---|
|  |  |  | //创建返回对象 | 
|---|
|  |  |  | OrganizationUnitAlarmDTO dto = new OrganizationUnitAlarmDTO(); | 
|---|
|  |  |  | //取参 | 
|---|
|  |  |  | OrganizationUnitAlarm organizationUnitAlarm = form.formConvertEntity(); | 
|---|
|  |  |  | //查询更新前的记录用于插入日志 | 
|---|
|  |  |  | OrganizationUnitAlarm oldRecord = organizationUnitAlarmMapper.selectById(organizationUnitAlarm.getId()); | 
|---|
|  |  |  | //更新 | 
|---|
|  |  |  | organizationUnitAlarmMapper.updateById(organizationUnitAlarm); | 
|---|
|  |  |  | //获取更新后的记录用于插入日志 | 
|---|
|  |  |  | OrganizationUnitAlarm newRecord = organizationUnitAlarmMapper.selectById(organizationUnitAlarm.getId()); | 
|---|
|  |  |  | //刷新deviceInfo缓存 | 
|---|
|  |  |  | CacheUtils.refreshDeviceAlarmInfo(); | 
|---|
|  |  |  | //封装返回对象 | 
|---|
|  |  |  | dto.setCode(ResponseCodeEnum.SUCCESS.getCode()); | 
|---|
|  |  |  | dto.setMsg(ResponseCodeEnum.SUCCESS.getMsg()); | 
|---|
|  |  |  | return dto; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|