Commit c91b88f6 by 钱炳权

任务删除功能完成

parent 805d86fb
......@@ -41,7 +41,7 @@ public class MissionInfoController {
try {
Boolean flag = missionInfoService.delMissionInfoById(id);
if (flag) {
return AjaxResult.success();
return AjaxResult.success("任务删除成功!");
} else {
throw new RuntimeException();
}
......
......@@ -16,21 +16,24 @@ public class MissionInfo {
private int state;
private Long runTime;
private String stateName;
private int fatherId;
public MissionInfo() {
}
public MissionInfo( int tableId, Date createTime, String missionName, int state, Long runTime) {
public MissionInfo( int tableId, Date createTime, String missionName, int state, Long runTime,int fatherId ) {
this.tableId = tableId;
this.createTime = createTime;
this.missionName = missionName;
this.state = state;
this.runTime = runTime;
this.fatherId = fatherId;
}
public MissionInfo(Date createTime, String missionName, Long runTime, String stateName) {
public MissionInfo(Date createTime, String missionName, Long runTime, String stateName,int fatherId ) {
this.createTime = createTime;
this.missionName = missionName;
this.runTime = runTime;
this.stateName = stateName;
this.fatherId = fatherId;
}
}
......@@ -10,7 +10,7 @@ import java.util.List;
@Component("MissionInfoMapper")
public interface MissionInfoMapper {
MissionInfo selectByMissionId(int missionId);
MissionInfo selectByMissionId(int id);
/**
* 查询任务信息列表
*/
......
......@@ -27,4 +27,5 @@ public interface TestMapper {
boolean editTestName(String testName,int id);
void update(Test test);
;
}
package com.example.fuzzControll.service.impl;
import com.example.fuzzControll.domain.po.MissionInfo;
import com.example.fuzzControll.domain.po.Test;
import com.example.fuzzControll.exception.mysqlException.MysqlException;
import com.example.fuzzControll.mapper.MissionInfoMapper;
import com.example.fuzzControll.mapper.TestMapper;
import com.example.fuzzControll.service.MissionInfoService;
import com.example.fuzzControll.tools.component.StringUtils;
import com.example.fuzzControll.tools.system.GlobalClass;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -13,16 +18,30 @@ import org.springframework.transaction.annotation.Transactional;
public class MissionInfoServiceImpl implements MissionInfoService {
@Autowired
MissionInfoMapper missionInfoMapper;
@Autowired
TestMapper testMapper;
@Override
@Transactional(rollbackFor = MysqlException.class)
public boolean delMissionInfoById(int id) {
/*删除任务需要同步删除测试里面的字段数据*/
try {
MissionInfo missionInfo = GlobalClass.missionInfoMapper.selectByMissionId(id);
if(missionInfo==null){
log.error("No mission id!");
throw new RuntimeException();
}
missionInfoMapper.delMissionInfoById(id);
int testId = missionInfo.getFatherId();
//给mission整一个fatherid
Test test = testMapper.getTestById(testId);
String newMinssionIds = StringUtils.getArrayFormatStringAfterDelete(test.getMissionIds(), id);
test.setMissionIds(newMinssionIds);
testMapper.update(test);
return true;
} catch (Exception e) {
throw new RuntimeException(e);
log.error("Deleting mission info error:[{}]", e.getMessage());
throw new MysqlException("");
}
}
}
......@@ -180,10 +180,10 @@ public class TestMissionServiceImpl implements TestMissionService {
String protocol = fuzzParams.getProtocol();
MissionInfo missionInfo;
if (Arrays.asList(SystemRunningParams.AflnetProtocol).contains(protocol)) {
missionInfo = new MissionInfo(TableClassEnum.AFLNET.getTableId(), new Date(), protocol, MissionStateEnum.STARTING.getStateCode(), 0L);
missionInfo = new MissionInfo(TableClassEnum.AFLNET.getTableId(), new Date(), protocol, MissionStateEnum.STARTING.getStateCode(), 0L,id);
isAflnet = true;
} else if (Arrays.asList(SystemRunningParams.KittyProtocol).contains(protocol)) {
missionInfo = new MissionInfo(TableClassEnum.KITTY_RESULT.getTableId(), new Date(), protocol, MissionStateEnum.STARTING.getStateCode(), 0L);
missionInfo = new MissionInfo(TableClassEnum.KITTY_RESULT.getTableId(), new Date(), protocol, MissionStateEnum.STARTING.getStateCode(), 0L,id);
isAflnet = false;
} else {
log.error("Unknown protocol!");
......
package com.example.fuzzControll.tools.component;
import lombok.extern.slf4j.Slf4j;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
@Slf4j
public class StringUtils {
/**
* 向[]格式字符转插入数据变成[a,b]
......@@ -10,11 +17,35 @@ public class StringUtils {
source = "[]";
String temp = source.replace("]", "");
finalString = temp + insert + "]";
}else{
} else {
String temp = source.replace("]", "");
finalString = temp +","+ insert + "]";
finalString = temp + "," + insert + "]";
}
return finalString;
}
/**
* 给[a,b]格式字符删除指定id
*/
public static String getArrayFormatStringAfterDelete(String missionIds, int id) {
/*取出id并提出删除的id*/
String[] ids = missionIds.replace("[", "").replace("]", "").split(",");
if (Arrays.stream(ids).noneMatch(s->String.valueOf(id).equals(s))) {
log.error("Data error!");
throw new RuntimeException();
}
List<String> temp = Arrays.stream(ids).filter(s -> !String.valueOf(id).equals(s)).collect(Collectors.toList());
String newMissionIds = "";
if (temp.size() == 0) {
newMissionIds = "[]";
} else {
newMissionIds = "[" + temp.get(0);
for (int i = 1; i < temp.size(); i++) {
newMissionIds = newMissionIds + "," + temp.get(i);
}
newMissionIds = newMissionIds + "]";
}
return newMissionIds;
}
}
......@@ -11,6 +11,7 @@
<result property="missionName" column="missionName" />
<result property="state" column="state" />
<result property="runTime" column="runTime" />
<result property="fatherId" column="fatherId" />
</resultMap>
<resultMap type="com.example.fuzzControll.domain.po.MissionInfo" id="MissionInfoInVo">
<result property="id" column="id" />
......@@ -18,16 +19,17 @@
<result property="missionName" column="missionName" />
<result property="stateName" column="state" />
<result property="runTime" column="runTime" />
<result property="fatherId" column="fatherId" />
</resultMap>
<sql id="selectMissionInfo">
select id,createTime,missionName ,state,runTime from missionInfo
select id,createTime,missionName ,state,runTime,fatherId from missionInfo
</sql>
<sql id="selectMissionInfoInDataBase">
select id, tableId, createTime,missionName ,state,runTime from missionInfo
select id, tableId, createTime,missionName ,state,runTime,fatherId from missionInfo
</sql>
<insert id="insertMission">
insert into missionInfo( tableId, createTime, missionName, state, runTime)
values ( #{tableId}, #{createTime}, #{missionName}, #{state}, #{runTime})
insert into missionInfo( tableId, createTime, missionName, state, runTime,fatherId)
values ( #{tableId}, #{createTime}, #{missionName}, #{state}, #{runTime},#{fatherId})
<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Integer">
SELECT LAST_INSERT_ID()
</selectKey>
......@@ -41,6 +43,7 @@
<if test="missionName != null and missionName != ''">missionName = #{missionName},</if>
<if test="state != null"> state = #{state},</if>
<if test="runTime != null ">runTime = #{runTime},</if>
<if test="fatherId != null ">fatherId = #{fatherId},</if>
</set>
where id = #{id}
</update>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment