package com.iailab.module.mcs.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.iailab.framework.common.page.PageData; import com.iailab.framework.common.service.impl.CrudServiceImpl; import com.iailab.common.utils.Constant; import com.iailab.framework.common.util.object.ConvertUtils; import com.iailab.common.utils.DateUtils; import com.iailab.module.mcs.dao.StModelRunlogDao; import com.iailab.module.mcs.dto.StModelRunlogDTO; import com.iailab.module.mcs.entity.StModelRunlogEntity; import com.iailab.module.mcs.service.StModelRunlogService; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import javax.annotation.Resource; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; /** * 运行日志表 * * @author lirm ${email} * @since 1.0.0 2023-06-21 */ @Service public class StModelRunlogServiceImpl extends CrudServiceImpl implements StModelRunlogService { @Resource private StModelRunlogDao runlogDao; @Override public QueryWrapper getWrapper(Map params){ String modelCode = (String)params.get("modelCode"); String modelName = (String)params.get("modelName"); QueryWrapper wrapper = new QueryWrapper<>(); wrapper.like(StringUtils.isNotBlank(modelCode), "model_code", modelCode); wrapper.like(StringUtils.isNotBlank(modelName), "model_name", modelName); return wrapper; } @Override public List getLastFxLog(Integer limit) { Map params = new HashMap<>(1); params.put("runType", "separation_control"); params.put("limit", limit == null ? 5 : limit); return runlogDao.getLastLog(params); } @Override public List getLastJyLog(Integer limit) { Map params = new HashMap<>(1); params.put("runType", "dosing_control"); params.put("limit", limit == null ? 5 : limit); return runlogDao.getLastLog(params); } @Override public void cleanRunlogTask(Map tMap) { runlogDao.cleanRunlogTask(tMap); } @Override public PageData queryPage(Map params) { long curPage = 1; long limit = 10; if(params.get(Constant.PAGE) != null){ curPage = Long.parseLong((String)params.get(Constant.PAGE)); } if(params.get(Constant.LIMIT) != null){ limit = Long.parseLong((String)params.get(Constant.LIMIT)); } IPage page = baseDao.queryList(new Page<>(curPage, limit), params); return getPageData(page, StModelRunlogDTO.class); } @Override public List listAll(Map params) { return runlogDao.listAll(params); } @Override public void add(StModelRunlogDTO dto) { StModelRunlogEntity entity = ConvertUtils.sourceToTarget(dto, StModelRunlogEntity.class); baseDao.insert(entity); } @Override public void migrationModelRunlog(Map tMap) { List list = runlogDao.selectList(getDateWrapper(tMap)); if (CollectionUtils.isEmpty(list)){ return; } runlogDao.migrationModelRunlog(list); runlogDao.delete(getDateWrapper(tMap)); } public QueryWrapper getDateWrapper(Map params) { String startDate = DateUtils.format(params.get("startdate"),DateUtils.DATE_TIME_PATTERN); String endDate = DateUtils.format(params.get("enddate"),DateUtils.DATE_TIME_PATTERN); QueryWrapper wrapper = new QueryWrapper<>(); wrapper.ge(StringUtils.isNotBlank(startDate), "run_time", startDate); wrapper.le(StringUtils.isNotBlank(endDate), "run_time", endDate); return wrapper; } }