123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- package com.huimv.admin.service.impl;
- import cn.hutool.core.util.ObjectUtil;
- import com.alibaba.fastjson.JSONObject;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.huimv.admin.common.utils.Result;
- import com.huimv.admin.common.utils.ResultCode;
- import com.huimv.admin.entity.EnvDevice;
- import com.huimv.admin.entity.dto.DeviceDto;
- import com.huimv.admin.mapper.EnvDeviceMaintainMapper;
- import com.huimv.admin.mapper.EnvDeviceMapper;
- import com.huimv.admin.service.IEnvDeviceService;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import javax.servlet.http.HttpServletRequest;
- import java.text.NumberFormat;
- import java.util.List;
- import java.util.Map;
- /**
- * <p>
- * 服务实现类
- * </p>
- *
- * @author author
- * @since 2023-02-13
- */
- @Service
- public class EnvDeviceServiceImpl extends ServiceImpl<EnvDeviceMapper, EnvDevice> implements IEnvDeviceService {
- @Autowired
- private EnvDeviceMapper envDeviceMapper;
- @Autowired
- private EnvDeviceMaintainMapper envDeviceMaintainMapper;
- @Override
- public Result count(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) {
- String farmId = paramsMap.get("farmId");
- QueryWrapper<EnvDevice> queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("farm_id", farmId);
- Integer count = envDeviceMapper.selectCount(queryWrapper);
- QueryWrapper<EnvDevice> queryWrapper1 = new QueryWrapper<>();
- queryWrapper1.eq("device_status", 1);
- Integer count1 = envDeviceMapper.selectCount(queryWrapper1);
- Integer OffDeviceCount = count- count1;
- //创建一个数值格式化对象
- NumberFormat numberFormat = NumberFormat.getInstance();
- //设置精确到小数点后两位
- numberFormat.setMaximumFractionDigits(2);
- String onDeviceRate = numberFormat.format((float)count1 / (float) count* 100) + "%";
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("DeviceCount", count);
- jsonObject.put("OnDeviceCount", count1);
- jsonObject.put("OffDeviceCount", OffDeviceCount);
- jsonObject.put("OnDeviceRate", onDeviceRate);
- return new Result(ResultCode.SUCCESS, jsonObject);
- }
- @Override
- public Result list(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) {
- String farmId = paramsMap.get("farmId");
- String pageSize = paramsMap.get("pageSize");
- String pageNo = paramsMap.get("pageNo");
- if (pageSize==null||pageSize=="") {
- pageSize = "10";
- }
- if (pageNo==null||pageNo=="") {
- pageNo = "1";
- }
- QueryWrapper<EnvDevice> queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("farm_id", farmId);
- Page<EnvDevice> page = new Page(Integer.parseInt(pageNo),Integer.parseInt(pageSize));
- return new Result(ResultCode.SUCCESS,envDeviceMapper.selectPage(page, queryWrapper));
- }
- @Override
- public Result add(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) {
- String farmId = paramsMap.get("farmId");
- String DeviceName = paramsMap.get("DeviceName");
- String BuildLocation = paramsMap.get("BuildLocation");
- String DeviceBrand = paramsMap.get("DeviceBrand");
- String remark = paramsMap.get("remark");
- if (remark == null || remark == "") {
- remark = null;
- }
- EnvDevice envDevice = new EnvDevice();
- envDevice.setFarmId(Integer.parseInt(farmId));
- envDevice.setDeviceName(DeviceName);
- envDevice.setBuildLocation(BuildLocation);
- envDevice.setDeviceBrand(DeviceBrand);
- envDevice.setRemark(remark);
- QueryWrapper<EnvDevice> queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("device_name", DeviceName).eq("farm_id",farmId);
- EnvDevice device = envDeviceMapper.selectOne(queryWrapper);
- if (ObjectUtil.isEmpty(device)) {
- envDeviceMapper.insert(envDevice);
- } else {
- return new Result(ResultCode.FAIL, "设备名称已存在");
- }
- return new Result(ResultCode.SUCCESS,"添加成功");
- }
- @Override
- public Result edit(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) {
- String farmId = paramsMap.get("farmId");
- String id = paramsMap.get("id");
- String DeviceName = paramsMap.get("DeviceName");
- String BuildLocation = paramsMap.get("BuildLocation");
- String DeviceBrand = paramsMap.get("DeviceBrand");
- String remark = paramsMap.get("remark");
- if (remark == null || remark == "") {
- remark = null;
- }
- QueryWrapper<EnvDevice> queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("id", id);
- EnvDevice envDevice = envDeviceMapper.selectOne(queryWrapper);
- envDevice.setFarmId(Integer.parseInt(farmId));
- envDevice.setDeviceName(DeviceName);
- envDevice.setDeviceBrand(DeviceBrand);
- envDevice.setBuildLocation(BuildLocation);
- envDevice.setRemark(remark);
- QueryWrapper<EnvDevice> queryWrapper1 = new QueryWrapper<>();
- queryWrapper1.eq("device_name", DeviceName);
- if (ObjectUtil.isEmpty(envDeviceMapper.selectOne(queryWrapper1))) {
- envDeviceMapper.updateById(envDevice);
- } else {
- return new Result(ResultCode.FAIL, "设备名称已存在");
- }
- return new Result(ResultCode.SUCCESS);
- }
- @Override
- public Result delete(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) {
- String farmId = paramsMap.get("farmId");
- String id = paramsMap.get("id");
- QueryWrapper<EnvDevice> queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("id", id).eq("farm_id", farmId);
- envDeviceMapper.delete(queryWrapper);
- return new Result(ResultCode.SUCCESS,"删除成功");
- }
- }
|