|
@@ -0,0 +1,122 @@
|
|
|
+package com.platform.service.sb.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
+import com.platform.common.bean.AbstractPageResultBean;
|
|
|
+import com.platform.common.exception.BusinessException;
|
|
|
+import com.platform.common.util.IdGeneratorUtils;
|
|
|
+import com.platform.dao.bean.MyPage;
|
|
|
+import com.platform.dao.dto.sb.SbLocationDTO;
|
|
|
+import com.platform.dao.entity.sb.SbLocation;
|
|
|
+import com.platform.dao.mapper.sb.SbLocationMapper;
|
|
|
+import com.platform.service.base.impl.BaseServiceImpl;
|
|
|
+import com.platform.service.sb.SbLocationService;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import tk.mybatis.mapper.weekend.Weekend;
|
|
|
+import tk.mybatis.mapper.weekend.WeekendCriteria;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Description 位号信息 service 实现类
|
|
|
+ * @Author liuyu
|
|
|
+ * @Date 2020-04-24 09:27:01
|
|
|
+ * @Version Copyright (c) 2019,北京乾元坤和科技有限公司 All rights reserved.
|
|
|
+ */
|
|
|
+@AllArgsConstructor
|
|
|
+@Service("sbLocationService")
|
|
|
+public class SbLocationServiceImpl extends BaseServiceImpl<SbLocationMapper, SbLocation, SbLocationDTO> implements SbLocationService {
|
|
|
+ @Override
|
|
|
+ public int batchDelete(List<String> ids) {
|
|
|
+ Weekend<SbLocation> weekend = new Weekend<>(SbLocation.class);
|
|
|
+ WeekendCriteria<SbLocation, Object> weekendCriteria = weekend.weekendCriteria();
|
|
|
+ weekendCriteria.andIn(SbLocation::getId, ids);
|
|
|
+ mapper.deleteByExample(weekend);
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 复制某个设备的位号,要去除已经存在的名称相同的
|
|
|
+ * @param model
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public String copyFormSb(SbLocationDTO model) {
|
|
|
+ SbLocationDTO record = new SbLocationDTO();
|
|
|
+ record.setSbId(model.getSbId());
|
|
|
+ List<SbLocation> partList = getModelListByDTO(record);
|
|
|
+
|
|
|
+ SbLocationDTO copyRecord = new SbLocationDTO();
|
|
|
+ copyRecord.setSbId(model.getCopySbId());
|
|
|
+ List<SbLocation> copyPartList = getModelListByDTO(copyRecord);
|
|
|
+ List<SbLocation> addPartList = new ArrayList<SbLocation>();
|
|
|
+ for(SbLocation copyPart:copyPartList){
|
|
|
+ boolean find = false;
|
|
|
+ for(SbLocation part:partList){
|
|
|
+ if(copyPart.getName().equals(part.getName())){
|
|
|
+ find = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(!find){
|
|
|
+ SbLocation partInfo = copyPart;
|
|
|
+ partInfo.setId(IdGeneratorUtils.getObjectId());
|
|
|
+ partInfo.setSbId(model.getSbId());
|
|
|
+ addPartList.add(partInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(CollectionUtil.isNotEmpty(addPartList)){
|
|
|
+ mapper.insertListforComplex(addPartList);
|
|
|
+ }
|
|
|
+
|
|
|
+ return "复制位号:" +addPartList.size() + "个";
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public AbstractPageResultBean<SbLocation> selectPageInfo(SbLocationDTO record, int pageNum, int pageSize) {
|
|
|
+ PageHelper.startPage(pageNum, pageSize);
|
|
|
+ AbstractPageResultBean<SbLocation> pageInfo = new MyPage(mapper.selectPageList(record));
|
|
|
+ return pageInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public SbLocation getModelById(Object id) {
|
|
|
+ SbLocation model = mapper.selectById(id);
|
|
|
+ return model;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<SbLocation> getModelListByDTO(SbLocationDTO model) {
|
|
|
+ List<SbLocation> result = super.getModelListByDTO(model);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public SbLocation saveModelByDTO(SbLocationDTO model) {
|
|
|
+
|
|
|
+ Weekend<SbLocation> weekendExsit = new Weekend<>(SbLocation.class);
|
|
|
+ weekendExsit.weekendCriteria().andEqualTo(SbLocation::getSbId, model.getSbId()).andEqualTo(SbLocation::getNo, model.getNo());
|
|
|
+ Integer exsitCount = mapper.selectCountByExample(weekendExsit);
|
|
|
+ if(exsitCount>0){
|
|
|
+ throw new BusinessException("编号已存在,请重新编号");
|
|
|
+ }
|
|
|
+ //Weekend<SbLocation> weekend = new Weekend<>(SbLocation.class);
|
|
|
+ //weekend.weekendCriteria().andIsNotNull(SbLocation::getId);
|
|
|
+ //Integer count = mapper.selectCountByExample(weekend);
|
|
|
+ //model.setNo(IdGeneratorUtils.getPartNo(++count));
|
|
|
+ return super.saveModelByDTO(model);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void modModelByDTO(SbLocationDTO model) {
|
|
|
+ Weekend<SbLocation> weekendExsit = new Weekend<>(SbLocation.class);
|
|
|
+ weekendExsit.weekendCriteria().andEqualTo(SbLocation::getSbId, model.getSbId()).andEqualTo(SbLocation::getNo, model.getNo());
|
|
|
+ SbLocation sbLocation = mapper.selectOneByExample(weekendExsit);
|
|
|
+ if(sbLocation != null && !sbLocation.getId().equals(model.getId())){
|
|
|
+ throw new BusinessException("编号已存在,请重新编号");
|
|
|
+ }
|
|
|
+ super.modModelByDTO(model);
|
|
|
+ }
|
|
|
+}
|