| | |
| | | package com.whyc.service; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.mapper.ExperimentMapper; |
| | | import com.whyc.mapper.ExperimentWindingStep1Mapper; |
| | | import com.whyc.mapper.ExperimentWindingStep2Mapper; |
| | | import com.whyc.mapper.ProjectMapper; |
| | | import com.whyc.pojo.Experiment; |
| | | import com.whyc.pojo.ExperimentWindingStep1; |
| | | import com.whyc.pojo.ExperimentWindingStep2; |
| | | import com.whyc.pojo.Project; |
| | | import com.whyc.mapper.*; |
| | | import com.whyc.pojo.*; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.jdbc.datasource.DataSourceTransactionManager; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.UUID; |
| | | |
| | | @Service |
| | | public class WindingExperimentService { |
| | |
| | | @Resource |
| | | private ProjectMapper projectMapper; |
| | | |
| | | |
| | | @Resource |
| | | private UserMapper userMapper; |
| | | |
| | | /** |
| | | * 绕组实验 开始实验 |
| | | * @param experiment |
| | | * @return |
| | | */ |
| | | public Response<Object> addWindingExperiment(Experiment experiment) { |
| | | String id = "RZ_"; |
| | | id+=new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()); |
| | | experiment.setId(id); |
| | | experiment.setCreateTime(new Date()); |
| | | experiment.setStatus(0); |
| | | experiment.setStatus(1); |
| | | try { |
| | | if (mapper.insertmanual(experiment) > 0) { |
| | | if (mapper.insert(experiment) > 0) { |
| | | return new Response().setMsg(1, "添加成功"); |
| | | } else { |
| | | return new Response().setMsg(0, "添加失败"); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 绕组实验步骤1 |
| | | * 绕组实验步骤 step参数 1 2 对应实验步骤1、2 |
| | | * @param list |
| | | * @return |
| | | */ |
| | | public Response<Object> addExperimentWindingStep1(List<ExperimentWindingStep1> list) { |
| | | Boolean flag = true; |
| | | TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition); |
| | | try { |
| | | for (int i = 0; i < list.size(); i++) { |
| | | ExperimentWindingStep1 windingStep1 = list.get(i); |
| | | if (mapper1.insert(windingStep1) > 0) { |
| | | flag = true; |
| | | if (list != null) { |
| | | Experiment experiment = null; |
| | | String realName; |
| | | try { |
| | | ExperimentWindingStep1 step1 = list.get(0); |
| | | QueryWrapper<Experiment> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("id", step1.getExperimentId()); |
| | | experiment = mapper.selectOne(wrapper); |
| | | if (experiment == null) { |
| | | return new Response().setMsg(0, "添加失败,试验编号不存在"); |
| | | } else { |
| | | flag = false; |
| | | // System.out.println("wrapper = " + wrapper); |
| | | } |
| | | realName = mapper1.getRealName(step1.getExperimentId()); |
| | | if (realName == null) { |
| | | return new Response().setMsg(0, "添加失败,uid未查询到对应试验人"); |
| | | } |
| | | // System.out.println("realName = " + realName); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return new Response().setMsg(0, "添加失败"); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | dataSourceTransactionManager.rollback(transactionStatus); //事务回滚 |
| | | return new Response().setMsg(0, "添加失败"); |
| | | } |
| | | if (flag) { |
| | | dataSourceTransactionManager.commit(transactionStatus); |
| | | return new Response().setMsg(1, "添加成功"); |
| | | } else { |
| | | dataSourceTransactionManager.rollback(transactionStatus); |
| | | |
| | | TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition); |
| | | try { |
| | | for (int i = 0; i < list.size(); i++) { |
| | | ExperimentWindingStep1 windingStep1 = list.get(i); |
| | | windingStep1.setUuid("rz"+new SimpleDateFormat("yyyyMMddHHmmss").format(new Date())); |
| | | windingStep1.setSaveTime(new Date()); |
| | | windingStep1.setDeviceId(experiment.getDeviceId());//存设备类型 |
| | | windingStep1.setRealName(realName); //测试人 |
| | | windingStep1.setStatus(1); //状态:0-未开始,1-进行中,2-已完成 |
| | | windingStep1.setRzLink(experiment.getRzLink()); //各相绕组连接情况 0 引出; 1 内部连接 |
| | | if (mapper1.insert(windingStep1) > 0) { |
| | | flag = true; |
| | | } else { |
| | | flag = false; |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | dataSourceTransactionManager.rollback(transactionStatus); //事务回滚 |
| | | return new Response().setMsg(0, "添加失败"); |
| | | } |
| | | if (flag) { |
| | | dataSourceTransactionManager.commit(transactionStatus); |
| | | return new Response().setMsg(1, "添加成功"); |
| | | } else { |
| | | dataSourceTransactionManager.rollback(transactionStatus); |
| | | return new Response().setMsg(0, "添加失败"); |
| | | } |
| | | }else { |
| | | return new Response().setMsg(0, "添加失败"); |
| | | } |
| | | |
| | |
| | | */ |
| | | public Response<Object> addExperimentWindingStep2(List<ExperimentWindingStep2> list) { |
| | | Boolean flag = true; |
| | | if (list != null) { |
| | | for (int i = 0; i < list.size(); i++) { |
| | | ExperimentWindingStep2 experimentWindingStep2 = list.get(i); |
| | | experimentWindingStep2.setSaveTime(new Date()); |
| | | list.set(i, experimentWindingStep2); |
| | | } |
| | | } |
| | | TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition); |
| | | try { |
| | | for (int i = 0; i < list.size(); i++) { |
| | |
| | | } |
| | | |
| | | |
| | | public Response delExperimentWindingbyId(String experimentId,String uuid) { |
| | | |
| | | QueryWrapper<ExperimentWindingStep1> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("experiment_id",experimentId); |
| | | wrapper.eq("uuid",uuid); |
| | | List<ExperimentWindingStep1> list = mapper1.selectList(wrapper); |
| | | if (list == null) { |
| | | // System.out.println(" null "); |
| | | return new Response().setMsg(0, "删除失败,请查检参数是否正确"); |
| | | }else { |
| | | // System.out.println("list = " + list.size()); |
| | | } |
| | | try { |
| | | mapper1.delExperimentWindingbyUuid(experimentId,uuid); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return new Response().setMsg(0, "删除失败"); |
| | | } |
| | | |
| | | return new Response().setMsg(1, "删除成功"); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 根据 experimentId 编辑参数 |
| | | * step参数 1 2 对应实验步骤1、2 |
| | | * @param windingStep1s |
| | | * @return |
| | | */ |
| | | public Response updateExperimentWindingStep1(List<ExperimentWindingStep1> windingStep1s) { |
| | | boolean bl = true; |
| | | TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition); |
| | | if (windingStep1s != null && windingStep1s.size() > 0) { |
| | | Date saveTime = new Date(); |
| | | for (int i = 0; i < windingStep1s.size(); i++) { |
| | | try { |
| | | ExperimentWindingStep1 windingStep1 = windingStep1s.get(i); |
| | | windingStep1.setSaveTime(saveTime); |
| | | if (mapper1.updateByUuidAndIndex(windingStep1) > 0) { |
| | | bl = true; |
| | | } else { |
| | | bl = false; |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | dataSourceTransactionManager.rollback(transactionStatus); //事务回滚 |
| | | return new Response().setMsg(0, "修改失败"); |
| | | } |
| | | } |
| | | } |
| | | if (bl) { |
| | | dataSourceTransactionManager.commit(transactionStatus); |
| | | return new Response().setMsg(1, "修改成功"); |
| | | } else { |
| | | dataSourceTransactionManager.rollback(transactionStatus); //事务回滚 |
| | | return new Response().setMsg(0, "修改失败"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 根据 experiment_id 编辑试验数据 |
| | | * @param windingStep2s |
| | | * @return |
| | | */ |
| | | public Response updateExperimentWindingStep2(List<ExperimentWindingStep2> windingStep2s) { |
| | | boolean bl = true; |
| | | TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition); |
| | | if (windingStep2s != null && windingStep2s.size() > 0) { |
| | | for (int i = 0; i < windingStep2s.size(); i++) { |
| | | try { |
| | | ExperimentWindingStep2 windingStep2 = windingStep2s.get(i); |
| | | if (mapper2.updateById(windingStep2) > 0) { |
| | | bl = true; |
| | | } else { |
| | | bl = false; |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | dataSourceTransactionManager.rollback(transactionStatus); //事务回滚 |
| | | return new Response().setMsg(0, "修改失败"); |
| | | } |
| | | } |
| | | } |
| | | if (bl) { |
| | | dataSourceTransactionManager.commit(transactionStatus); |
| | | return new Response().setMsg(1, "修改成功"); |
| | | } else { |
| | | dataSourceTransactionManager.rollback(transactionStatus); //事务回滚 |
| | | return new Response().setMsg(0, "修改失败"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 根据唯一ID编辑实验数据1 |
| | | * @param windingStep1s |
| | | * @return |
| | | */ |
| | | public Response updateExperimentWindingStep1ById(List<ExperimentWindingStep1> windingStep1s) { |
| | | boolean bl = true; |
| | | TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition); |
| | | if (windingStep1s != null && windingStep1s.size() > 0) { |
| | | for (int i = 0; i < windingStep1s.size(); i++) { |
| | | try { |
| | | ExperimentWindingStep1 windingStep1 = windingStep1s.get(i); |
| | | if (mapper1.updateByPrimaryKey(windingStep1) > 0) { |
| | | bl = true; |
| | | } else { |
| | | bl = false; |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | dataSourceTransactionManager.rollback(transactionStatus); //事务回滚 |
| | | return new Response().setMsg(0, "修改失败"); |
| | | } |
| | | } |
| | | } |
| | | if (bl) { |
| | | dataSourceTransactionManager.commit(transactionStatus); |
| | | return new Response().setMsg(1, "修改成功"); |
| | | } else { |
| | | dataSourceTransactionManager.rollback(transactionStatus); //事务回滚 |
| | | return new Response().setMsg(0, "修改失败"); |
| | | } |
| | | } |
| | | |
| | | public Response updateExperimentWindingStep2ById(List<ExperimentWindingStep2> windingStep2s) { |
| | | boolean bl = true; |
| | | TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition); |
| | | if (windingStep2s != null && windingStep2s.size() > 0) { |
| | | for (int i = 0; i < windingStep2s.size(); i++) { |
| | | try { |
| | | ExperimentWindingStep2 windingStep2 = windingStep2s.get(i); |
| | | if (mapper2.updateByPrimaryKey(windingStep2) > 0) { |
| | | bl = true; |
| | | } else { |
| | | bl = false; |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | dataSourceTransactionManager.rollback(transactionStatus); //事务回滚 |
| | | return new Response().setMsg(0, "修改失败"); |
| | | } |
| | | } |
| | | } |
| | | if (bl) { |
| | | dataSourceTransactionManager.commit(transactionStatus); |
| | | return new Response().setMsg(1, "修改成功"); |
| | | } else { |
| | | dataSourceTransactionManager.rollback(transactionStatus); //事务回滚 |
| | | return new Response().setMsg(0, "修改失败"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 实验数据 step参数 1 2 对应实验步骤1、2 |
| | | * |
| | | * |
| | | * |
| | | * @param experimentId |
| | | * @param rzLink |
| | | * @param step |
| | | * @param pageNum |
| | | * @param pageSize |
| | | * @return |
| | | */ |
| | | public Response getExperimentWindingStep1(String experimentId, int rzLink, int step, int pageNum, int pageSize) { |
| | | |
| | | PageHelper.startPage(pageNum, pageSize); |
| | | List<ExperimentWindingStep1> list = mapper1.selectlistByCondition(experimentId,rzLink,step); |
| | | PageInfo<ExperimentWindingStep1> pageInfo = new PageInfo<>(list); |
| | | return new Response<PageInfo<ExperimentWindingStep1>>().set(1, pageInfo); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 实验数据2 |
| | | * @param pageNum |
| | | * @param pageSize |
| | | * @return |
| | | */ |
| | | public Response getExperimentWindingStep2(int pageNum, int pageSize) { |
| | | |
| | | PageHelper.startPage(pageNum, pageSize); |
| | | List<ExperimentWindingStep2> list = mapper2.selectList(null); |
| | | |
| | | PageInfo<ExperimentWindingStep2> pageInfo = new PageInfo<>(list); |
| | | return new Response<PageInfo<ExperimentWindingStep2>>().set(1, pageInfo); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取测试名 |
| | | * @param name |
| | | * @return |
| | | */ |
| | | public Response<Object> getRealName(Integer name) { |
| | | Response<Object> response = new Response<>(); |
| | | QueryWrapper<User> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("id", name); |
| | | User user = userMapper.selectOne(wrapper); |
| | | if (null != user) { |
| | | response.set(1, user.getRealName()); |
| | | }else{ |
| | | response.setMsg(0,"查询失败"); |
| | | } |
| | | return response; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 状态:-1-取消,0-未开始,1-进行中,2-完成 |
| | | * * 不对controller接口提供取消功能 |
| | | * @param id |
| | | * @return |
| | | */ |
| | | public Response updateFlag(String id) { |
| | | Response<Object> response = new Response<>(); |
| | | QueryWrapper<Experiment> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("id",id); |
| | | Experiment experiment1 = mapper.selectOne(queryWrapper); |
| | | if (experiment1 ==null){ |
| | | response.setMsg(0,"试验编号有误"); |
| | | } |
| | | try { |
| | | Experiment experiment = new Experiment<>(); |
| | | experiment.setId(id); |
| | | experiment.setEndTime(new Date()); |
| | | mapper.updateFlag(experiment); |
| | | mapper1.updateRzFlag(id); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | response.setMsg(0,"更新失败"); |
| | | } |
| | | return response.setMsg(1,"更新成功"); |
| | | } |
| | | } |