|
|
@@ -1,10 +1,25 @@
|
|
|
package com.kym.service.admin.impl;
|
|
|
|
|
|
+import cn.dev33.satoken.stp.StpUtil;
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
+import com.github.yulichang.toolkit.JoinWrappers;
|
|
|
+import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
|
|
+import com.kym.common.utils.CommUtil;
|
|
|
+import com.kym.common.utils.IDGenerator;
|
|
|
+import com.kym.entity.admin.StationNotice;
|
|
|
import com.kym.entity.admin.SystemNotice;
|
|
|
+import com.kym.entity.admin.queryParams.NoticeQueryParams;
|
|
|
+import com.kym.entity.admin.vo.NoticeStationVo;
|
|
|
+import com.kym.entity.common.PageBean;
|
|
|
import com.kym.mapper.admin.SystemNoticeMapper;
|
|
|
+import com.kym.service.admin.StationNoticeService;
|
|
|
import com.kym.service.admin.SystemNoticeService;
|
|
|
import com.kym.service.mybatisplus.MyBaseServiceImpl;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
|
@@ -17,4 +32,45 @@ import org.springframework.stereotype.Service;
|
|
|
@Service
|
|
|
public class SystemNoticeServiceImpl extends MyBaseServiceImpl<SystemNoticeMapper, SystemNotice> implements SystemNoticeService {
|
|
|
|
|
|
+ private final StationNoticeService stationNoticeService;
|
|
|
+
|
|
|
+ public SystemNoticeServiceImpl(StationNoticeService stationNoticeService) {
|
|
|
+ this.stationNoticeService = stationNoticeService;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增公告
|
|
|
+ *
|
|
|
+ * @param vo
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public void createNotice(NoticeStationVo vo) {
|
|
|
+ var systemNotice = new SystemNotice();
|
|
|
+ BeanUtils.copyProperties(vo, systemNotice);
|
|
|
+ save(systemNotice.setAdminUserId(StpUtil.getLoginIdAsLong()).setAdminUserName(StpUtil.getSession().getString("username")).setBaseId(IDGenerator.INS().nextId()));
|
|
|
+ stationNoticeService.saveBatch(vo.getStationIdList().stream().map(stationId -> new StationNotice().setNoticeId(systemNotice.getId()).setStationId(stationId)).toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页查询公告列表
|
|
|
+ *
|
|
|
+ * @param params
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public PageBean<NoticeStationVo> listSystemNotice(NoticeQueryParams params) {
|
|
|
+ PageHelper.startPage(params.getPageNum(), params.getPageSize());
|
|
|
+ MPJLambdaWrapper<SystemNotice> wrapper = JoinWrappers.lambda(SystemNotice.class)
|
|
|
+ .selectAsClass(SystemNotice.class, NoticeStationVo.class)
|
|
|
+ .selectCollection(StationNotice.class, NoticeStationVo::getStationIdList, map ->map.result(StationNotice::getStationId))
|
|
|
+ .leftJoin(StationNotice.class, StationNotice::getNoticeId, StationNotice::getId)
|
|
|
+ .eq(CommUtil.isNotEmptyAndNull(params.getStatus()), SystemNotice::getStatus, params.getStatus())
|
|
|
+ .like(CommUtil.isNotEmptyAndNull(params.getTitle()), SystemNotice::getTitle, params.getTitle())
|
|
|
+ .like(CommUtil.isNotEmptyAndNull(params.getContent()), SystemNotice::getContent, params.getContent())
|
|
|
+ .orderByDesc(SystemNotice::getUpdateTime);
|
|
|
+ List<NoticeStationVo> res = this.selectJoinList(NoticeStationVo.class, wrapper);
|
|
|
+ return new PageBean<>(res);
|
|
|
+ }
|
|
|
+
|
|
|
}
|