package com.iailab.module.mcs.service.impl;
|
|
import com.alibaba.fastjson.JSONArray;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.iailab.framework.common.service.impl.CrudServiceImpl;
|
import com.iailab.module.mcs.dao.StModelSettingDao;
|
import com.iailab.module.mcs.dto.StModelSettingDTO;
|
import com.iailab.module.mcs.entity.StModelSettingEntity;
|
import com.iailab.module.mcs.service.StModelSettingService;
|
import org.apache.commons.lang3.StringUtils;
|
import javax.annotation.Resource;
|
import org.springframework.stereotype.Service;
|
import org.springframework.util.CollectionUtils;
|
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* @author lirm 1343021927@qq.com
|
* @since 1.0.0 2023-05-10
|
*/
|
@Service
|
public class StModelSettingServiceImpl extends CrudServiceImpl<StModelSettingDao, StModelSettingEntity, StModelSettingDTO>
|
implements StModelSettingService {
|
|
@Resource
|
private StModelSettingDao StModelSettingDao;
|
|
@Override
|
public List<StModelSettingDTO> getAll(Map<String, Object> params) {
|
return StModelSettingDao.getAll(params);
|
}
|
|
@Override
|
public QueryWrapper<StModelSettingEntity> getWrapper(Map<String, Object> params) {
|
String id = (String) params.get("id");
|
|
QueryWrapper<StModelSettingEntity> wrapper = new QueryWrapper<>();
|
wrapper.eq(StringUtils.isNotBlank(id), "id", id);
|
|
return wrapper;
|
}
|
|
@Override
|
public void deleteByModelId(String modelId) {
|
StModelSettingDao.deleteByModelId(modelId);
|
}
|
|
@Override
|
public Map<String, Object> getByModelId(String modelId) {
|
Map<String, Object> result = new HashMap<>();
|
List<StModelSettingEntity> list = baseDao.selectList(new QueryWrapper<StModelSettingEntity>().eq("model_id", modelId));
|
if (!CollectionUtils.isEmpty(list)) {
|
list.forEach(item -> {
|
if ("int".equals(item.getValueType())) {
|
int value = Integer.parseInt(item.getSettingValue());
|
result.put(item.getSettingKey(), value);
|
} else if ("double".equals(item.getValueType())) {
|
double value = Double.parseDouble(item.getSettingValue());
|
result.put(item.getSettingKey(), value);
|
} else if ("string".equals(item.getValueType())) {
|
String value = item.getSettingValue();
|
result.put(item.getSettingKey(), value);
|
} else if ("decimalArray".equals(item.getValueType())) {
|
JSONArray valueArray = JSONArray.parseArray(item.getSettingValue());
|
double[] value = new double[valueArray.size()];
|
for(int i = 0; i < valueArray.size(); i ++) {
|
value[i] = Double.parseDouble(valueArray.get(i).toString());
|
}
|
} else {
|
result.put(item.getSettingKey(), item.getSettingValue());
|
}
|
});
|
}
|
return result;
|
}
|
|
}
|