| | |
| | | package com.whyc.service; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.whyc.dto.ExperimentConditionDTO; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.mapper.ExperimentBaseDataKZMapper; |
| | | import com.whyc.mapper.ExperimentMapper; |
| | | import com.whyc.pojo.Experiment; |
| | | import com.whyc.pojo.ExperimentBaseDataKZ; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | @Service |
| | |
| | | |
| | | @Resource |
| | | private ExperimentMapper mapper; |
| | | @Resource |
| | | private ExperimentBaseDataKZMapper kzMapper; |
| | | |
| | | /** |
| | | * 绕组:rz, |
| | | * 空载:kz, |
| | | * 负载:fz, |
| | | * 升温:sw, |
| | | * 超速:cs, |
| | | * 空载反电动势:kzfdds, |
| | | * 振动:zd, |
| | | * 耐压:ny, |
| | | * 转动惯量:zdgl, |
| | | * @param type |
| | | * @return |
| | | */ |
| | | public Response getExperimentId(String type) { |
| | | String id = null; |
| | | //查询当前试验类型的最大编号 |
| | | QueryWrapper<Experiment> wrapper = Wrappers.query(); |
| | | Calendar calendar = Calendar.getInstance(); |
| | | Date now = new Date(); |
| | | SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd"); |
| | | String nowFormat = dateFormat.format(now); |
| | | String idLike = type.toUpperCase()+"_"+nowFormat; |
| | | wrapper.select("id").likeRight("id",idLike).orderByDesc("id").last(" limit 1"); |
| | | Experiment experiment = mapper.selectOne(wrapper); |
| | | if(experiment!=null) { |
| | | int idPrefixLength = nowFormat.length(); |
| | | int idSuffix = Integer.parseInt(experiment.getId().substring(idPrefixLength)); |
| | | id = idLike+(idSuffix+1); |
| | | }else{ |
| | | id = idLike+"001"; |
| | | } |
| | | return new Response().set(1,id); |
| | | |
| | | } |
| | | |
| | | public Response addKZ(Experiment experiment) { |
| | | //插入experiment数据 |
| | | experiment.setCreateTime(new Date()); |
| | | mapper.insert(experiment); |
| | | //插入experiment_base_data数据 |
| | | kzMapper.insert((ExperimentBaseDataKZ) experiment.getBaseData()); |
| | | return new Response().setMsg(1,"新增成功"); |
| | | } |
| | | |
| | | /*======History======*/ |
| | | |
| | | public Response<PageInfo<Experiment>> getPage(Integer pageNum, Integer pageSize, ExperimentConditionDTO condition) { |
| | | PageHelper.startPage(pageNum,pageSize); |