package com.iailab.module.prod.service.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.iailab.framework.common.constant.Constant;
|
import com.iailab.common.dto.echarts.BarLineDTO;
|
import com.iailab.common.dto.echarts.SeriesItem;
|
import com.iailab.framework.common.page.PageData;
|
import com.iailab.framework.common.service.impl.BaseServiceImpl;
|
import com.iailab.framework.common.util.object.ConvertUtils;
|
import com.iailab.module.prod.dao.IndexEvaluateSystemDao;
|
import com.iailab.module.prod.dto.IndexEvaluateSystemDTO;
|
import com.iailab.module.prod.entity.IndexEvaluateSystemEntity;
|
import com.iailab.module.prod.service.IndexEvaluateSystemService;
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.util.CollectionUtils;
|
|
import java.math.BigDecimal;
|
import java.util.*;
|
|
@Service
|
public class IndexEvaluateSystemServiceImpl extends BaseServiceImpl<IndexEvaluateSystemDao, IndexEvaluateSystemEntity> implements IndexEvaluateSystemService {
|
|
@Override
|
public PageData<IndexEvaluateSystemDTO> page(Map<String, Object> params) {
|
IPage<IndexEvaluateSystemEntity> page = baseDao.selectPage(
|
getPage(params, Constant.CREATE_DATE, false),
|
getWrapper(params)
|
);
|
return getPageData(page, IndexEvaluateSystemDTO.class);
|
}
|
|
private QueryWrapper<IndexEvaluateSystemEntity> getWrapper(Map<String, Object> params) {
|
String pid = (String) params.get("pid");
|
|
QueryWrapper<IndexEvaluateSystemEntity> wrapper = new QueryWrapper<>();
|
wrapper.eq(StringUtils.isNotBlank("pid"), "pid", pid);
|
|
return wrapper;
|
}
|
|
@Override
|
public IndexEvaluateSystemDTO get(String id) {
|
IndexEvaluateSystemEntity entity = baseDao.selectById(id);
|
|
return ConvertUtils.sourceToTarget(entity, IndexEvaluateSystemDTO.class);
|
}
|
|
@Override
|
public void save(IndexEvaluateSystemDTO dto) {
|
IndexEvaluateSystemEntity entity = ConvertUtils.sourceToTarget(dto, IndexEvaluateSystemEntity.class);
|
|
insert(entity);
|
}
|
|
@Override
|
public void update(IndexEvaluateSystemDTO dto) {
|
IndexEvaluateSystemEntity entity = ConvertUtils.sourceToTarget(dto, IndexEvaluateSystemEntity.class);
|
|
updateById(entity);
|
}
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public void delete(String[] ids) {
|
baseDao.deleteBatchIds(Arrays.asList(ids));
|
}
|
|
@Override
|
public List<IndexEvaluateSystemEntity> list(String pid) {
|
List<IndexEvaluateSystemEntity> list = baseDao.selectList(new QueryWrapper<IndexEvaluateSystemEntity>().eq("pid", pid));
|
return list;
|
}
|
|
@Override
|
public Map<String, String> systemWeightList() {
|
Map map = new HashMap();
|
List<IndexEvaluateSystemEntity> list = baseDao.selectList(new QueryWrapper<IndexEvaluateSystemEntity>().eq("pid", 0));
|
list.stream().forEach(
|
item -> {
|
map.put(item.getCode(), item.getWeight());
|
}
|
);
|
return map;
|
}
|
|
@Override
|
public BarLineDTO getChart(String pid) {
|
BarLineDTO barLineDTO = new BarLineDTO();
|
List<SeriesItem> series = new ArrayList<>();
|
List<Object[]> data = new ArrayList<>();
|
SeriesItem seriesItem = new SeriesItem();
|
List<String> legend = new ArrayList<>();
|
List<IndexEvaluateSystemEntity> list = baseDao.selectList(new QueryWrapper<IndexEvaluateSystemEntity>().eq("pid", pid));
|
Object[] objects = new Object[list.size()];
|
for (int i = 0; i < list.size(); i++) {
|
legend.add(list.get(i).getEvaluateIndex());
|
Map<String, String> map = new HashMap<>();
|
map.put("value", list.get(i).getWeight() == null ? "" : list.get(i).getWeight().toString());
|
map.put("name", list.get(i).getEvaluateIndex());
|
objects[i] = map;
|
}
|
data.add(objects);
|
seriesItem.setData(data);
|
series.add(seriesItem);
|
barLineDTO.setSeries(series);
|
barLineDTO.setLegend(legend);
|
return barLineDTO;
|
}
|
|
@Override
|
public void updataWeight(List<IndexEvaluateSystemEntity> list) {
|
list.stream().forEach(
|
item -> {
|
baseDao.updateById(item);
|
}
|
);
|
}
|
|
@Override
|
public void updataSystemWeight(Map<String, String> params) {
|
String number = params.get("number");
|
String quality = params.get("quality");
|
String consume = params.get("consume");
|
String process = params.get("process");
|
String manage = params.get("manage");
|
|
IndexEvaluateSystemEntity numberEntity = baseDao.selectOne(new QueryWrapper<IndexEvaluateSystemEntity>().eq("code", "SYS0001"));
|
numberEntity.setWeight(Integer.parseInt(number));
|
|
IndexEvaluateSystemEntity qualityEntity = baseDao.selectOne(new QueryWrapper<IndexEvaluateSystemEntity>().eq("code", "SYS0002"));
|
qualityEntity.setWeight(Integer.parseInt(quality));
|
|
IndexEvaluateSystemEntity consumeEntity = baseDao.selectOne(new QueryWrapper<IndexEvaluateSystemEntity>().eq("code", "SYS0003"));
|
consumeEntity.setWeight(Integer.parseInt(consume));
|
|
IndexEvaluateSystemEntity processEntity = baseDao.selectOne(new QueryWrapper<IndexEvaluateSystemEntity>().eq("code", "SYS0004"));
|
processEntity.setWeight(Integer.parseInt(process));
|
|
IndexEvaluateSystemEntity manageEntity = baseDao.selectOne(new QueryWrapper<IndexEvaluateSystemEntity>().eq("code", "SYS0005"));
|
manageEntity.setWeight(Integer.parseInt(manage));
|
|
baseDao.updateById(numberEntity);
|
baseDao.updateById(qualityEntity);
|
baseDao.updateById(consumeEntity);
|
baseDao.updateById(processEntity);
|
baseDao.updateById(manageEntity);
|
}
|
|
|
@Override
|
public List<Double> getWeight() {
|
BigDecimal val100 = new BigDecimal("100");
|
List<Double> result = new ArrayList<>();
|
QueryWrapper<IndexEvaluateSystemEntity> wrapper = new QueryWrapper<>();
|
wrapper.orderByAsc("sort");
|
List<IndexEvaluateSystemEntity> list = baseDao.selectList(wrapper);
|
if (CollectionUtils.isEmpty(list)) {
|
return result;
|
}
|
list.forEach(item -> {
|
result.add(new BigDecimal(item.getWeight()).divide(val100, 3, BigDecimal.ROUND_HALF_UP).doubleValue());
|
});
|
return result;
|
}
|
|
}
|