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 implements IndexEvaluateSystemService { @Override public PageData page(Map params) { IPage page = baseDao.selectPage( getPage(params, Constant.CREATE_DATE, false), getWrapper(params) ); return getPageData(page, IndexEvaluateSystemDTO.class); } private QueryWrapper getWrapper(Map params) { String pid = (String) params.get("pid"); QueryWrapper 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 list(String pid) { List list = baseDao.selectList(new QueryWrapper().eq("pid", pid)); return list; } @Override public Map systemWeightList() { Map map = new HashMap(); List list = baseDao.selectList(new QueryWrapper().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 series = new ArrayList<>(); List data = new ArrayList<>(); SeriesItem seriesItem = new SeriesItem(); List legend = new ArrayList<>(); List list = baseDao.selectList(new QueryWrapper().eq("pid", pid)); Object[] objects = new Object[list.size()]; for (int i = 0; i < list.size(); i++) { legend.add(list.get(i).getEvaluateIndex()); Map 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 list) { list.stream().forEach( item -> { baseDao.updateById(item); } ); } @Override public void updataSystemWeight(Map 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().eq("code", "SYS0001")); numberEntity.setWeight(Integer.parseInt(number)); IndexEvaluateSystemEntity qualityEntity = baseDao.selectOne(new QueryWrapper().eq("code", "SYS0002")); qualityEntity.setWeight(Integer.parseInt(quality)); IndexEvaluateSystemEntity consumeEntity = baseDao.selectOne(new QueryWrapper().eq("code", "SYS0003")); consumeEntity.setWeight(Integer.parseInt(consume)); IndexEvaluateSystemEntity processEntity = baseDao.selectOne(new QueryWrapper().eq("code", "SYS0004")); processEntity.setWeight(Integer.parseInt(process)); IndexEvaluateSystemEntity manageEntity = baseDao.selectOne(new QueryWrapper().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 getWeight() { BigDecimal val100 = new BigDecimal("100"); List result = new ArrayList<>(); QueryWrapper wrapper = new QueryWrapper<>(); wrapper.orderByAsc("sort"); List 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; } }