|
|
@@ -0,0 +1,132 @@
|
|
|
+package com.sckw.slope.detection.service;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
+import com.github.pagehelper.PageInfo;
|
|
|
+import com.sckw.core.exception.BusinessException;
|
|
|
+import com.sckw.core.model.constant.NumberConstant;
|
|
|
+import com.sckw.core.model.enums.DeviceEnum;
|
|
|
+import com.sckw.core.model.page.PageRes;
|
|
|
+import com.sckw.core.utils.StringUtils;
|
|
|
+import com.sckw.core.web.response.HttpResult;
|
|
|
+import com.sckw.slope.detection.dao.mysql.KwsDeviceModelMapper;
|
|
|
+import com.sckw.slope.detection.model.dos.mysql.KwsDevice;
|
|
|
+import com.sckw.slope.detection.model.dos.mysql.KwsDeviceModel;
|
|
|
+import com.sckw.slope.detection.model.dos.mysql.KwsProjectArea;
|
|
|
+import com.sckw.slope.detection.model.dos.mysql.KwsProjectDevice;
|
|
|
+import com.sckw.slope.detection.model.dto.HeaderData;
|
|
|
+import com.sckw.slope.detection.model.param.DeviceModelAdd;
|
|
|
+import com.sckw.slope.detection.model.param.DeviceModelQuery;
|
|
|
+import com.sckw.slope.detection.model.vo.DeviceModelVo;
|
|
|
+import com.sckw.slope.detection.model.vo.DeviceVo;
|
|
|
+import com.sckw.slope.detection.model.vo.ProjectVo;
|
|
|
+import jakarta.servlet.http.HttpServletRequest;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.http.HttpResponse;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author sky
|
|
|
+ * @description 设备model service
|
|
|
+ * @date 2023-10-31 10:10:27
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class DeviceModelService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ CommonService commonService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ KwsDeviceModelMapper kwsDeviceModelMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 项目管理分页查询
|
|
|
+ *
|
|
|
+ * @param deviceModelQuery 请求分页
|
|
|
+ * @param response http流
|
|
|
+ * @return 返回值
|
|
|
+ */
|
|
|
+ public PageRes select(DeviceModelQuery deviceModelQuery, HttpResponse response) {
|
|
|
+ PageHelper.startPage(deviceModelQuery.getPage(), deviceModelQuery.getPageSize());
|
|
|
+ List<DeviceModelVo> list = kwsDeviceModelMapper.selectListAll(deviceModelQuery);
|
|
|
+ PageInfo<DeviceModelVo> pageInfo = new PageInfo<>(list);
|
|
|
+ if (CollectionUtils.isEmpty(list)) {
|
|
|
+ return PageRes.build(pageInfo, list);
|
|
|
+ }
|
|
|
+ for (DeviceModelVo vo : list) {
|
|
|
+ vo.setStatusText(DeviceEnum.getName(vo.getStatus()));
|
|
|
+ }
|
|
|
+
|
|
|
+ return PageRes.build(pageInfo, list);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设备型号新增
|
|
|
+ *
|
|
|
+ * @param deviceModelAdd 请求参数
|
|
|
+ * @param request http流
|
|
|
+ * @return 返回值
|
|
|
+ */
|
|
|
+ @Transactional
|
|
|
+ public HttpResult add(DeviceModelAdd deviceModelAdd, HttpServletRequest request) {
|
|
|
+ HeaderData headerData = commonService.getHeaderData(request);
|
|
|
+ KwsDeviceModel deviceModel = new KwsDeviceModel();
|
|
|
+ BeanUtils.copyProperties(deviceModelAdd, deviceModel);
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ deviceModel.setCreateBy(Long.parseLong(headerData.getCreateBy()));
|
|
|
+ deviceModel.setCreateTime(now);
|
|
|
+ deviceModel.setStatus(DeviceEnum.IDENTIFYING.getCode());
|
|
|
+ deviceModel.setUpdateBy(Long.parseLong(headerData.getUpdateBy()));
|
|
|
+ deviceModel.setUpdateTime(now);
|
|
|
+ deviceModel.setDelFlag(NumberConstant.ZERO);
|
|
|
+ deviceModel.setMountainId(headerData.getCompanyId());
|
|
|
+ kwsDeviceModelMapper.insert(deviceModel);
|
|
|
+ return HttpResult.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ public HttpResult detail(Long id, HttpServletRequest response) {
|
|
|
+ KwsDeviceModel device = kwsDeviceModelMapper.selectOne(new LambdaQueryWrapper<KwsDeviceModel>()
|
|
|
+ .eq(KwsDeviceModel::getId, id));
|
|
|
+ DeviceModelVo vo = new DeviceModelVo();
|
|
|
+ BeanUtils.copyProperties(device, vo);
|
|
|
+ vo.setStatusText(DeviceEnum.getName(vo.getStatus()));
|
|
|
+
|
|
|
+ return HttpResult.ok(vo);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ public HttpResult update(DeviceModelAdd deviceAdd, HttpServletRequest response) {
|
|
|
+ KwsDeviceModel device = new KwsDeviceModel();
|
|
|
+ BeanUtils.copyProperties(deviceAdd, device);
|
|
|
+ device.setId(deviceAdd.getId());
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ device.setUpdateBy(Long.parseLong(commonService.getHeaderData(response).getUpdateBy()));
|
|
|
+ device.setUpdateTime(now);
|
|
|
+ kwsDeviceModelMapper.updateById(device);
|
|
|
+ return HttpResult.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ public HttpResult dels(String ids) {
|
|
|
+ List<Long> list = StringUtils.splitStrToList(ids, Long.class);
|
|
|
+ int update = kwsDeviceModelMapper.update(null, new LambdaUpdateWrapper<KwsDeviceModel>()
|
|
|
+ .in(KwsDeviceModel::getId, list)
|
|
|
+ .set(KwsDeviceModel::getDelFlag, NumberConstant.ONE));
|
|
|
+ if (update < 1) {
|
|
|
+ throw new BusinessException("删除型号异常");
|
|
|
+ }
|
|
|
+ return HttpResult.ok("删除型号成功");
|
|
|
+ }
|
|
|
+}
|