|
@@ -5,9 +5,12 @@ import cn.hutool.json.JSONArray;
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
import com.huimv.env.manage.entity.EnvDeviceRegister;
|
|
|
import com.huimv.env.manage.mapper.BasePigpenMapper;
|
|
|
import com.huimv.env.manage.mapper.LampConfigAllMapper;
|
|
|
+import com.huimv.env.manage.saas.dao.entity.BasePigpen;
|
|
|
import com.huimv.env.manage.saas.dao.entity.LampConfig;
|
|
|
import com.huimv.env.manage.mapper.LampConfigMapper;
|
|
|
import com.huimv.env.manage.saas.dao.entity.LampConfigAll;
|
|
@@ -48,13 +51,16 @@ public class LampConfigServiceImpl extends ServiceImpl<LampConfigMapper, LampCon
|
|
|
@Override
|
|
|
public Result savelampConfig( LampConfig lampConfig, HttpServletRequest request) {
|
|
|
String deviceId = lampConfig.getDeviceId();
|
|
|
- if (ObjectUtil.isEmpty(lampConfigMapper.exists(new QueryWrapper<LampConfig>().eq("device_id",deviceId)))){
|
|
|
- this.save(lampConfig);
|
|
|
- return new Result(10000,"添加成功",true);
|
|
|
- }else {
|
|
|
- return new Result(10001,"设备已存在",false);
|
|
|
+ Integer unitId = lampConfig.getUnitId();
|
|
|
+ String location = lampConfig.getLocation();
|
|
|
+ if (lampConfigMapper.exists(new QueryWrapper<LampConfig>().eq("device_id",deviceId))){
|
|
|
+ return new Result(10001,"保温灯已存在",false);
|
|
|
}
|
|
|
-
|
|
|
+ if (lampConfigMapper.exists(new QueryWrapper<LampConfig>().eq("unit_id",unitId).eq("location",location))){
|
|
|
+ return new Result(10002,"该位置已有保温灯",false);
|
|
|
+ }
|
|
|
+ this.save(lampConfig);
|
|
|
+ return new Result(10000,"添加成功",true);
|
|
|
|
|
|
}
|
|
|
|
|
@@ -62,9 +68,7 @@ public class LampConfigServiceImpl extends ServiceImpl<LampConfigMapper, LampCon
|
|
|
public Result lsitAllLamp(Map<String, String> map, HttpServletRequest request) {
|
|
|
String farmCode = map.get("farmCode");
|
|
|
List<LampConfig> lampConfigs = lampConfigMapper.selectList(new QueryWrapper<LampConfig>().eq("farm_code", farmCode));
|
|
|
-
|
|
|
List endList = new ArrayList();
|
|
|
-
|
|
|
for (LampConfig lampConfig : lampConfigs) {
|
|
|
Map endMap = new HashMap();
|
|
|
endMap.put("binding",lampConfig.getBinding());
|
|
@@ -74,10 +78,15 @@ public class LampConfigServiceImpl extends ServiceImpl<LampConfigMapper, LampCon
|
|
|
endMap.put("unitId",lampConfig.getUnitId());
|
|
|
endMap.put("lampName",lampConfig.getLampName());
|
|
|
endMap.put("location",lampConfig.getLocation());
|
|
|
- endMap.put("pigpenName",basePigpenMapper.selectById(lampConfig.getId()).getPigpenName());
|
|
|
+ BasePigpen basePigpen = basePigpenMapper.selectById(lampConfig.getUnitId());
|
|
|
+ if (ObjectUtil.isNotEmpty(basePigpen)){
|
|
|
+ endMap.put("pigpenName",basePigpen.getPigpenName());
|
|
|
+ }else {
|
|
|
+ endMap.put("pigpenName","该设备未绑定");
|
|
|
+ }
|
|
|
+ endList.add(endMap);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
return ResultUtil.isNull(endList);
|
|
|
}
|
|
|
|
|
@@ -99,6 +108,9 @@ public class LampConfigServiceImpl extends ServiceImpl<LampConfigMapper, LampCon
|
|
|
String unitId = map.get("unitId");
|
|
|
String location = map.get("location");
|
|
|
|
|
|
+ if (lampConfigMapper.exists(new QueryWrapper<LampConfig>().eq("unit_id",unitId).eq("location",location))){
|
|
|
+ return new Result(10002,"该位置已有保温灯",false);
|
|
|
+ }
|
|
|
|
|
|
LampConfig lampConfig = new LampConfig();
|
|
|
|
|
@@ -134,11 +146,44 @@ public class LampConfigServiceImpl extends ServiceImpl<LampConfigMapper, LampCon
|
|
|
|
|
|
@Override
|
|
|
public Result allToConfig(Map<String, String> map, HttpServletRequest request) {
|
|
|
- String initDayAge = map.get("initDayAge");
|
|
|
- String dayAgeList = map.get("dayAgeList");
|
|
|
- JSONArray jsonArray = JSONUtil.parseArray(dayAgeList);
|
|
|
+ try {
|
|
|
+ String initDayAge = map.get("initDayAge");
|
|
|
+ String dayAgeList = map.get("dayAgeList");
|
|
|
+ //
|
|
|
+ String boardGear = map.get("boardGear");
|
|
|
+ String unitId = map.get("unitId");
|
|
|
+ String id = map.get("id");
|
|
|
+
|
|
|
+ JSONArray jsonArray = JSONUtil.parseArray(dayAgeList);
|
|
|
+
|
|
|
+ LampConfig lampConfig = new LampConfig();
|
|
|
+ lampConfig.setInitAge(Integer.parseInt(initDayAge));
|
|
|
+ lampConfig.setBoardGear(Integer.parseInt(boardGear));
|
|
|
+ StringBuilder dayAgeListStr = new StringBuilder();
|
|
|
+ for (Object o : jsonArray) {
|
|
|
+ dayAgeListStr.append(o.toString()).append(";");
|
|
|
+ }
|
|
|
+ lampConfig.setAgeList(dayAgeListStr.toString());
|
|
|
+ UpdateWrapper<LampConfig> wrapper = new UpdateWrapper<>();
|
|
|
+ if (StringUtils.isBlank(id)){
|
|
|
+ LampConfigAll lampConfigAll = new LampConfigAll();
|
|
|
+ lampConfigAll.setBoardGear(Integer.parseInt(boardGear));
|
|
|
+// lampConfigAll.setListDayage();
|
|
|
+ lampConfigAll.setInitDayage(Integer.parseInt(initDayAge));
|
|
|
+// lampConfigAll.setFarmCode();
|
|
|
+// lampConfigAll.setUnitId();
|
|
|
+ wrapper.eq("unit_id",unitId);
|
|
|
+ }else {
|
|
|
+ wrapper.eq("id",id);
|
|
|
+ }
|
|
|
+ lampConfigMapper.update(lampConfig,wrapper);
|
|
|
+
|
|
|
+ return new Result(10000,"全局配置成功",true);
|
|
|
+ }catch (Exception e){
|
|
|
+ System.out.println(e);
|
|
|
+ return new Result(10001,"配置失败",true);
|
|
|
+ }
|
|
|
|
|
|
- return null;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -173,7 +218,37 @@ public class LampConfigServiceImpl extends ServiceImpl<LampConfigMapper, LampCon
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Result updateLamp(Map<String, String> map, HttpServletRequest request) {
|
|
|
- return null;
|
|
|
+ public Result updateLamp(Map<String, Integer> map, HttpServletRequest request) {
|
|
|
+ Integer uploadStart = map.get("uploadStart");
|
|
|
+ Integer id = map.get("id");
|
|
|
+ Integer unitId = map.get("unitId");
|
|
|
+ LampConfig lampConfig = new LampConfig();
|
|
|
+ lampConfig.setUploadStart(uploadStart);
|
|
|
+ if (ObjectUtil.isNotEmpty(unitId)){
|
|
|
+ lampConfigMapper.update(lampConfig,new QueryWrapper<LampConfig>().eq("unit_id",unitId));
|
|
|
+ }else {
|
|
|
+ lampConfig.setId(id);
|
|
|
+ lampConfigMapper.updateById(lampConfig);
|
|
|
+ }
|
|
|
+
|
|
|
+ return new Result(10000,"配置成功",true);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result listByLampId(Map<String, String> map, HttpServletRequest request) {
|
|
|
+ String lampId = map.get("lampId");
|
|
|
+ LampConfig lampConfig = lampConfigMapper.selectById(lampId);
|
|
|
+ if (ObjectUtil.isEmpty(lampConfig)){
|
|
|
+ lampConfig = new LampConfig();
|
|
|
+ lampConfig.setInitAge(0);
|
|
|
+ lampConfig.setAgeList("0,33;");
|
|
|
+ }
|
|
|
+ Map endMap =new HashMap();
|
|
|
+ endMap.put("initDayage",lampConfig.getInitAge());
|
|
|
+ endMap.put("listDayage",lampConfig.getAgeList().split(";"));
|
|
|
+ endMap.put("id",lampConfig.getId());
|
|
|
+ endMap.put("lampName",lampConfig.getLampName());
|
|
|
+ endMap.put("deviceId",lampConfig.getDeviceId());
|
|
|
+ return new Result(ResultCode.SUCCESS,endMap);
|
|
|
}
|
|
|
}
|