|
|
@@ -1,77 +1,117 @@
|
|
|
package com.railway.business.baseinfo.service.impl;
|
|
|
|
|
|
+import com.railway.business.baseinfo.domain.BaseDeptStation;
|
|
|
import com.railway.business.baseinfo.domain.BusDmcgyq;
|
|
|
+import com.railway.business.baseinfo.domain.query.DmcgyqQuery;
|
|
|
import com.railway.business.baseinfo.mapper.BusDmcgyqMapper;
|
|
|
+import com.railway.business.baseinfo.service.IBaseStationService;
|
|
|
import com.railway.business.baseinfo.service.IBusDmcgyqService;
|
|
|
+import com.railway.common.exception.ServiceException;
|
|
|
import com.railway.common.utils.SecurityUtils;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
/**
|
|
|
-* 基础数据-地面磁感应器
|
|
|
-* @author zcf
|
|
|
-* @date 2021/10/26
|
|
|
-*/
|
|
|
+ * 基础数据-地面磁感应器
|
|
|
+ *
|
|
|
+ * @author zcf
|
|
|
+ * @date 2021/10/26
|
|
|
+ */
|
|
|
@Service
|
|
|
@Transactional(readOnly = true)
|
|
|
-public class BusDmcgyqServiceImpl implements IBusDmcgyqService{
|
|
|
+public class BusDmcgyqServiceImpl implements IBusDmcgyqService {
|
|
|
+
|
|
|
+ private final IBaseStationService stationService;
|
|
|
+ private final BusDmcgyqMapper busDmcgyqMapper;
|
|
|
+
|
|
|
+ public BusDmcgyqServiceImpl(IBaseStationService stationService, BusDmcgyqMapper busDmcgyqMapper) {
|
|
|
+ this.stationService = stationService;
|
|
|
+ this.busDmcgyqMapper = busDmcgyqMapper;
|
|
|
+ }
|
|
|
|
|
|
- private final BusDmcgyqMapper busDmcgyqMapper;
|
|
|
+ /**
|
|
|
+ * 新增
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public int create(BusDmcgyq busDmcgyq) {
|
|
|
+ // 校验设备是否已经存在
|
|
|
+ checkDmcgyq(busDmcgyq);
|
|
|
+ // 设置默认字段值
|
|
|
+ BaseDeptStation deptStation = stationService.getInfo(busDmcgyq.getDeptId(),
|
|
|
+ busDmcgyq.getLineId(), busDmcgyq.getStationId());
|
|
|
+ busDmcgyq.setDeptStationId(deptStation.getId());
|
|
|
+ busDmcgyq.setCreateTime(new Date());
|
|
|
+ busDmcgyq.setCreateBy(SecurityUtils.getUserIdString());
|
|
|
+ return busDmcgyqMapper.insert(busDmcgyq);
|
|
|
+ }
|
|
|
|
|
|
- public BusDmcgyqServiceImpl(BusDmcgyqMapper busDmcgyqMapper) {
|
|
|
- this.busDmcgyqMapper = busDmcgyqMapper;
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * 删除
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public int delete(Long[] ids) {
|
|
|
+ int r = 0;
|
|
|
+ for (Long id : ids) {
|
|
|
+ int j = busDmcgyqMapper.delete(id);
|
|
|
+ r = r + j;
|
|
|
+ }
|
|
|
+ return r;
|
|
|
+ }
|
|
|
|
|
|
- /**
|
|
|
- * 新增
|
|
|
- */
|
|
|
- @Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public int create(BusDmcgyq busDmcgyq) {
|
|
|
- busDmcgyq.setCreateTime(new Date());
|
|
|
- busDmcgyq.setCreateBy(SecurityUtils.getUserIdString());
|
|
|
- return busDmcgyqMapper.insert(busDmcgyq);
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * 更新
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public int update(BusDmcgyq busDmcgyq) {
|
|
|
+ // 校验设备是否已经存在
|
|
|
+ checkDmcgyq(busDmcgyq);
|
|
|
+ // 设置默认字段值
|
|
|
+ BaseDeptStation deptStation = stationService.getInfo(busDmcgyq.getDeptId(),
|
|
|
+ busDmcgyq.getLineId(), busDmcgyq.getStationId());
|
|
|
+ busDmcgyq.setDeptStationId(deptStation.getId());
|
|
|
+ busDmcgyq.setUpdateTime(new Date());
|
|
|
+ busDmcgyq.setUpdateBy(SecurityUtils.getUserIdString());
|
|
|
+ return busDmcgyqMapper.update(busDmcgyq);
|
|
|
+ }
|
|
|
|
|
|
- /**
|
|
|
- * 删除
|
|
|
- */
|
|
|
- @Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public int delete(Long[] ids) {
|
|
|
- int r =0;
|
|
|
- for (Long id : ids) {
|
|
|
- int j= busDmcgyqMapper.delete(id);
|
|
|
- r = r + j;
|
|
|
- }
|
|
|
- return r;
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * 获取单个
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public BusDmcgyq getInfo(Long id) {
|
|
|
+ return busDmcgyqMapper.getInfo(id);
|
|
|
+ }
|
|
|
|
|
|
- /**
|
|
|
- * 更新
|
|
|
- */
|
|
|
- @Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public int update(BusDmcgyq busDmcgyq) {
|
|
|
- busDmcgyq.setUpdateTime(new Date());
|
|
|
- busDmcgyq.setUpdateBy(SecurityUtils.getUserIdString());
|
|
|
- return busDmcgyqMapper.update(busDmcgyq);
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * 查询列表
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<BusDmcgyq> getList(BusDmcgyq busDmcgyq) {
|
|
|
+ return busDmcgyqMapper.getList(busDmcgyq);
|
|
|
+ }
|
|
|
|
|
|
- /**
|
|
|
- * 获取单个
|
|
|
- */
|
|
|
- @Override
|
|
|
- public BusDmcgyq getInfo(Long id) {
|
|
|
- return busDmcgyqMapper.getInfo(id);
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ public List<String> listTeam(DmcgyqQuery query) {
|
|
|
+ return busDmcgyqMapper.listTeam(query);
|
|
|
+ }
|
|
|
|
|
|
- /**
|
|
|
- * 查询列表
|
|
|
- */
|
|
|
- @Override
|
|
|
- public List<BusDmcgyq> getList(BusDmcgyq busDmcgyq) {
|
|
|
- return busDmcgyqMapper.getList(busDmcgyq);
|
|
|
- }
|
|
|
+ private void checkDmcgyq(BusDmcgyq busDmcgyq){
|
|
|
+ BusDmcgyq query = new BusDmcgyq();
|
|
|
+ query.setTeam(busDmcgyq.getTeam());
|
|
|
+ query.setSbbh(busDmcgyq.getSbbh());
|
|
|
+ List<BusDmcgyq> dmcgyqList = this.getList(query);
|
|
|
+ if (CollectionUtils.isNotEmpty(dmcgyqList)) {
|
|
|
+ // 如果按照组号和设备编号查询的结果大于1,或者仅1条时,主键字段是新的,表示已经存在
|
|
|
+ if(dmcgyqList.size() > 1 || !dmcgyqList.get(0).getId().equals(busDmcgyq.getId())) {
|
|
|
+ throw new ServiceException("地面磁感应器设备组“" + busDmcgyq.getTeam() + "”已经存在编号为"
|
|
|
+ + busDmcgyq.getSbbh() + "的设备,请检查!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|