|
@@ -0,0 +1,66 @@
|
|
|
+package com.huimv.cattle.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.huimv.cattle.pojo.DataSource;
|
|
|
+import com.huimv.cattle.mapper.DataSourceMapper;
|
|
|
+import com.huimv.cattle.service.DataSourceService;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.huimv.common.utils.Result;
|
|
|
+import com.huimv.common.utils.ResultCode;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author zn
|
|
|
+ * @since 2022-12-15
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSource> implements DataSourceService {
|
|
|
+ //默认牧场
|
|
|
+// private static final String DEFAULT_FARM_CODE = "330211";
|
|
|
+ @Autowired
|
|
|
+ private DataSourceMapper dataSourceMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result getDataSource(Map<String, String> paramsMap) {
|
|
|
+ QueryWrapper<DataSource> totalQueryWrapper = new QueryWrapper();
|
|
|
+ return new Result(ResultCode.SUCCESS, dataSourceMapper.selectOne(totalQueryWrapper));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result setDataSouce(Map<String, String> paramsMap) {
|
|
|
+ //
|
|
|
+ String datasourceStatus = "0";
|
|
|
+ if (paramsMap.get("datasourceStatus") != null) {
|
|
|
+ datasourceStatus = paramsMap.get("datasourceStatus");
|
|
|
+ }
|
|
|
+ QueryWrapper<DataSource> totalQueryWrapper = new QueryWrapper();
|
|
|
+ DataSource dataSource = dataSourceMapper.selectOne(totalQueryWrapper);
|
|
|
+ if (dataSource == null) {
|
|
|
+ dataSource = new DataSource();
|
|
|
+ dataSource.setDsStatus(Integer.parseInt(datasourceStatus));
|
|
|
+ dataSourceMapper.insert(dataSource);
|
|
|
+ } else {
|
|
|
+ dataSource.setDsStatus(Integer.parseInt(datasourceStatus));
|
|
|
+ dataSourceMapper.updateById(dataSource);
|
|
|
+ }
|
|
|
+ return new Result(ResultCode.SUCCESS);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Integer getDataSourceStatus(Map<String, String> paramsMap) {
|
|
|
+ QueryWrapper<DataSource> totalQueryWrapper = new QueryWrapper();
|
|
|
+ DataSource dataSource = dataSourceMapper.selectOne(totalQueryWrapper);
|
|
|
+ if (dataSource == null) {
|
|
|
+ return 0;
|
|
|
+ } else {
|
|
|
+ return dataSource.getDsStatus();
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|