测试用例后端代码.txt 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553
  1. package com.idea.oa.testPlan.controller;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.github.pagehelper.PageInfo;
  4. import com.github.pagehelper.StringUtil;
  5. import com.idea.oa.task.model.ProTaskRelation;
  6. import com.idea.oa.task.model.ProTaskRelationExample;
  7. import com.idea.oa.task.service.ProTaskRelationService;
  8. import com.idea.oa.task.utils.ConstantsInfo;
  9. import com.idea.oa.testPlan.model.*;
  10. import com.idea.oa.testPlan.model.in.TestPlanIn;
  11. import com.idea.oa.testPlan.service.TestPlanCommanderService;
  12. import com.idea.oa.testPlan.service.TestPlanService;
  13. import com.rockstar.common.base.BaseController;
  14. import com.rockstar.common.domain.AjaxResult;
  15. import com.rockstar.frame.model.extend.DateTrans;
  16. import com.rockstar.frame.model.extend.TableSplitResult;
  17. import com.rockstar.frame.model.extend.Tablepar;
  18. import com.rockstar.shiro.util.ShiroUtils;
  19. import com.rockstar.util.SnowflakeIdWorker;
  20. import io.swagger.annotations.Api;
  21. import org.apache.commons.lang3.StringUtils;
  22. import org.springframework.beans.factory.annotation.Autowired;
  23. import org.springframework.stereotype.Controller;
  24. import org.springframework.web.bind.annotation.PathVariable;
  25. import org.springframework.web.bind.annotation.PostMapping;
  26. import org.springframework.web.bind.annotation.RequestMapping;
  27. import org.springframework.web.bind.annotation.ResponseBody;
  28. import java.util.Date;
  29. import java.util.List;
  30. /**
  31. * Created by pengyq on 2020.
  32. */
  33. @Controller
  34. @RequestMapping(value = "TestPlanController")
  35. @Api(value = "测试管理/测试计划")
  36. public class TestPlanController extends BaseController {
  37. @Autowired
  38. private ProTaskRelationService proTaskRelationService;
  39. //主表
  40. @Autowired
  41. private TestPlanService modelService;
  42. @Autowired
  43. private TestPlanCommanderService testPlanCommanderService;
  44. @PostMapping(value = "list", produces = {"application/json;charset=UTF-8"})
  45. @ResponseBody
  46. public Object list(Tablepar tablepar, TestPlan model, DateTrans dt) {
  47. PageInfo<TestPlan> page = modelService.list(tablepar, model, dt);
  48. TableSplitResult<TestPlan> result = new TableSplitResult<TestPlan>(page.getPageNum(), page.getTotal(), page.getList());
  49. return result;
  50. }
  51. /**
  52. * 对应页面(测试管理/测试计划)获取列表数组
  53. *
  54. * @param tablepar
  55. * @param model
  56. * @param dt
  57. * @return
  58. */
  59. @PostMapping(value = "listVo", produces = {"application/json;charset=UTF-8"})
  60. @ResponseBody
  61. public Object listVo(Tablepar tablepar, TestPlanIn model, DateTrans dt) {
  62. List<TestPlanIn> list = modelService.listVo(tablepar, model, dt);
  63. return list;
  64. }
  65. /**
  66. * 对应页面(测试管理/测试计划)获取列表总数
  67. *
  68. * @param model
  69. * @param dt
  70. * @return
  71. */
  72. @PostMapping(value = "getTotal", produces = {"application/json;charset=UTF-8"})
  73. @ResponseBody
  74. public Object getTotal(TestPlanIn model, DateTrans dt) {
  75. Long total = modelService.getTotal(model, dt);
  76. return total;
  77. }
  78. @PostMapping(value = "listAll", produces = {"application/json;charset=UTF-8"})
  79. @ResponseBody
  80. public Object listAll(TestPlan model, DateTrans dt) {
  81. return modelService.listAll(model, dt);
  82. }
  83. /**
  84. * 添加对象数据,对象数组中有多个负责人id,所以需要解析他们,并插入他们
  85. *
  86. * @param info
  87. * @return
  88. */
  89. @PostMapping(value = "add", produces = {"application/json;charset=UTF-8"})
  90. @ResponseBody
  91. public AjaxResult add(String info) {
  92. System.out.println(info);
  93. if (info != null) {
  94. List<TestPlanIn> testPlanIns = JSONArray.parseArray(info, TestPlanIn.class);
  95. StringBuilder addFirst=new StringBuilder();
  96. for (TestPlanIn testPlanIn : testPlanIns) {
  97. testPlanIn.setCreatedAt(new Date());
  98. testPlanIn.setUpdatedAt(testPlanIn.getCreatedAt());
  99. testPlanIn.setCreatedBy(ShiroUtils.getUser().getId());
  100. testPlanIn.setUpdatedBy(testPlanIn.getCreatedBy());
  101. testPlanIn.setStatus(0);
  102. testPlanIn.setId(SnowflakeIdWorker.getUUID());
  103. //添加主目录
  104. modelService.insertWithoutId(testPlanIn);
  105. addFirst.append(testPlanIn.getId()+',');
  106. //下面是添加负责人
  107. String handleUserId = testPlanIn.getHandleUserId();
  108. if (!StringUtil.isEmpty(handleUserId)) {
  109. String[] userIds = handleUserId.split(",");
  110. for (int i = 0; i < userIds.length; i++) {
  111. TestPlanCommander testPlanCommander = new TestPlanCommander();
  112. testPlanCommander.setPlanId(testPlanIn.getId());
  113. testPlanCommander.setCommanderId(userIds[i]);
  114. testPlanCommander.setSort(i);
  115. testPlanCommander.setCreatedAt(new Date());
  116. testPlanCommander.setCreatedBy(ShiroUtils.getUser().getId());
  117. testPlanCommander.setStatus(0);
  118. testPlanCommanderService.insert(testPlanCommander);
  119. }
  120. }
  121. }
  122. // 判断是否存在关联任务id,注意任务编号已经改成任务id
  123. if(StringUtils.isNotEmpty(testPlanIns.get(0).getTaskNo())) {
  124. ProTaskRelationExample example1 = new ProTaskRelationExample();
  125. example1.createCriteria().andTaskIdEqualTo(testPlanIns.get(0).getTaskNo()).andTaskRelationNameEqualTo(ConstantsInfo.TEST_PLAN);
  126. List<ProTaskRelation> proTaskRelations = proTaskRelationService.selectByExample(example1);
  127. if(proTaskRelations!=null&&proTaskRelations.size()>0){
  128. ProTaskRelation proTaskRelation = proTaskRelations.get(0);
  129. proTaskRelation.setStatus(ConstantsInfo.RELATION_TASK_COM);
  130. proTaskRelation.setFirst(addFirst.toString());
  131. proTaskRelationService.updateByPrimaryKeySelective(proTaskRelation);
  132. }
  133. }
  134. return result(1);
  135. } else {
  136. return result(-1);
  137. }
  138. }
  139. @PostMapping(value = "remove/{id}", produces = {"application/json;charset=UTF-8"})
  140. @ResponseBody
  141. public AjaxResult remove(@PathVariable("id") String id) {
  142. int result = 0;
  143. {//这是正式删除
  144. // result = modelService.deleteByPrimaryKey(id);
  145. // TestPlanCommanderExample testUsecaseStepExample = new TestPlanCommanderExample();
  146. // testUsecaseStepExample.createCriteria().andPlanIdEqualTo(id);
  147. // testPlanCommanderService.deleteByExample(testUsecaseStepExample);
  148. }
  149. {//这是修改删除
  150. TestPlanIn record = new TestPlanIn();
  151. record.setId(id);
  152. record.setStatus(1);
  153. record.setUpdatedBy(ShiroUtils.getUser().getId());
  154. record.setUpdatedAt(new Date());
  155. result = modelService.updateByPrimaryKeySelective(record);
  156. TestPlanCommander testUsecaseStep = new TestPlanCommander();
  157. testUsecaseStep.setStatus(1);
  158. TestPlanCommanderExample testUsecaseStepExample = new TestPlanCommanderExample();
  159. testUsecaseStepExample.createCriteria().andPlanIdEqualTo(id);
  160. testPlanCommanderService.updateByExampleSelective(testUsecaseStep, testUsecaseStepExample);
  161. }
  162. return result(result);
  163. }
  164. /**
  165. * 修改对象数据,对象数组中有多个负责人id,所以需要解析他们,并插入他们
  166. *
  167. * @param info
  168. * @return
  169. */
  170. @PostMapping(value = "edit", produces = {"application/json;charset=UTF-8"})
  171. @ResponseBody
  172. public AjaxResult editSave(String info) {
  173. System.out.println("edit:" + info);
  174. if (info != null) {
  175. List<TestPlanIn> testPlanIns = JSONArray.parseArray(info, TestPlanIn.class);
  176. for (TestPlanIn testPlanIn : testPlanIns) {
  177. if (!StringUtil.isEmpty(testPlanIn.getId())) {
  178. testPlanIn.setUpdatedBy(ShiroUtils.getUser().getId());
  179. testPlanIn.setUpdatedAt(new Date());
  180. testPlanIn.setCreatedAt(null);
  181. testPlanIn.setCreatedBy(null);
  182. modelService.updateByPrimaryKeySelective(testPlanIn);
  183. //先删除负责人,再添加负责人
  184. TestPlanCommanderExample example = new TestPlanCommanderExample();
  185. example.createCriteria().andPlanIdEqualTo(testPlanIn.getId());
  186. testPlanCommanderService.deleteByExample(example);
  187. //下面是添加负责人
  188. String handleUserId = testPlanIn.getHandleUserId();
  189. if (!StringUtil.isEmpty(handleUserId)) {
  190. String[] userIds = handleUserId.split(",");
  191. for (int i = 0; i < userIds.length; i++) {
  192. TestPlanCommander testPlanCommander = new TestPlanCommander();
  193. testPlanCommander.setPlanId(testPlanIn.getId());
  194. testPlanCommander.setCommanderId(userIds[i]);
  195. testPlanCommander.setSort(i);
  196. testPlanCommander.setCreatedAt(new Date());
  197. testPlanCommander.setCreatedBy(ShiroUtils.getUser().getId());
  198. testPlanCommander.setStatus(0);
  199. testPlanCommanderService.insert(testPlanCommander);
  200. }
  201. }
  202. }else{
  203. testPlanIn.setCreatedAt(new Date());
  204. testPlanIn.setUpdatedAt(testPlanIn.getCreatedAt());
  205. testPlanIn.setCreatedBy(ShiroUtils.getUser().getId());
  206. testPlanIn.setUpdatedBy(testPlanIn.getCreatedBy());
  207. testPlanIn.setStatus(0);
  208. testPlanIn.setId(SnowflakeIdWorker.getUUID());
  209. //添加主目录
  210. modelService.insertWithoutId(testPlanIn);
  211. //下面是添加负责人
  212. String handleUserId = testPlanIn.getHandleUserId();
  213. if (!StringUtil.isEmpty(handleUserId)) {
  214. String[] userIds = handleUserId.split(",");
  215. for (int i = 0; i < userIds.length; i++) {
  216. TestPlanCommander testPlanCommander = new TestPlanCommander();
  217. testPlanCommander.setPlanId(testPlanIn.getId());
  218. testPlanCommander.setCommanderId(userIds[i]);
  219. testPlanCommander.setSort(i);
  220. testPlanCommander.setCreatedAt(new Date());
  221. testPlanCommander.setCreatedBy(ShiroUtils.getUser().getId());
  222. testPlanCommander.setStatus(0);
  223. testPlanCommanderService.insert(testPlanCommander);
  224. }
  225. }
  226. }
  227. }
  228. return result(1);
  229. } else {
  230. return result(-1);
  231. }
  232. }
  233. /**
  234. * 修改计划状态
  235. * @param info
  236. * @return
  237. */
  238. @PostMapping(value = "editStatus", produces = {"application/json;charset=UTF-8"})
  239. @ResponseBody
  240. public AjaxResult editStatus(String info) {
  241. System.out.println("editStatus:" + info);
  242. if (info != null) {
  243. List<TestPlanIn> testPlanIns = JSONArray.parseArray(info, TestPlanIn.class);
  244. for (TestPlanIn testPlanIn : testPlanIns) {
  245. if (!StringUtil.isEmpty(testPlanIn.getId())) {
  246. TestPlanIn newTestPlanIn = new TestPlanIn();
  247. newTestPlanIn.setId(testPlanIn.getId());
  248. //对状态说明或者备注
  249. newTestPlanIn.setStatusremark(testPlanIn.getStatusremark());
  250. newTestPlanIn.setStatus(testPlanIn.getStatus());
  251. newTestPlanIn.setUpdatedBy(ShiroUtils.getUser().getId());
  252. newTestPlanIn.setUpdatedAt(new Date());
  253. modelService.updateByPrimaryKeySelective(newTestPlanIn);
  254. }
  255. }
  256. return result(1);
  257. } else {
  258. return result(-1);
  259. }
  260. }
  261. @PostMapping(value = "getById", produces = {"application/json;charset=UTF-8"})
  262. @ResponseBody
  263. public TestPlan getById(String id) {
  264. return modelService.selectByPrimaryKey(id);
  265. }
  266. /**
  267. * 前端根据id获取数据
  268. *
  269. * @param id
  270. * @return
  271. */
  272. @PostMapping(value = "getVoById", produces = {"application/json;charset=UTF-8"})
  273. @ResponseBody
  274. public TestPlanIn getVoById(String id) {
  275. return modelService.getVoById(id);
  276. }
  277. /**
  278. * 前端根据ids获取数据, ids是类似数组的字符串,例如:1684651,6431,或者:135456135 又或者:1651631,等
  279. *
  280. * @param ids
  281. * @return
  282. */
  283. @PostMapping(value = "getVoByIds", produces = {"application/json;charset=UTF-8"})
  284. @ResponseBody
  285. public List<TestPlanIn> getVoByIds(String ids) {
  286. return modelService.getVoByIds(ids);
  287. }
  288. }
  289. package com.idea.oa.testPlan.controller;
  290. import com.alibaba.fastjson.JSONArray;
  291. import com.github.pagehelper.PageInfo;
  292. import com.idea.oa.testPlan.model.TestUsecase;
  293. import com.idea.oa.testPlan.model.TestUsecaseStep;
  294. import com.idea.oa.testPlan.model.TestUsecaseStepExample;
  295. import com.idea.oa.testPlan.model.in.TestUsecaseIn;
  296. import com.idea.oa.testPlan.service.TestUsecaseService;
  297. import com.idea.oa.testPlan.service.TestUsecaseStepService;
  298. import com.rockstar.common.base.BaseController;
  299. import com.rockstar.common.domain.AjaxResult;
  300. import com.rockstar.frame.model.extend.DateTrans;
  301. import com.rockstar.frame.model.extend.TableSplitResult;
  302. import com.rockstar.frame.model.extend.Tablepar;
  303. import com.rockstar.shiro.util.ShiroUtils;
  304. import io.swagger.annotations.Api;
  305. import org.springframework.beans.factory.annotation.Autowired;
  306. import org.springframework.stereotype.Controller;
  307. import org.springframework.util.StringUtils;
  308. import org.springframework.web.bind.annotation.*;
  309. import java.util.ArrayList;
  310. import java.util.Date;
  311. import java.util.List;
  312. /**
  313. * Created by pengyq on 2020.
  314. */
  315. @Controller
  316. @RequestMapping(value = "TestUsecaseController")
  317. @Api(value = "测试管理/用例库")
  318. public class TestUsecaseController extends BaseController {
  319. //主表
  320. @Autowired
  321. private TestUsecaseService modelService;
  322. @Autowired
  323. private TestUsecaseStepService testUsecaseStepService;
  324. @PostMapping(value = "list", produces = {"application/json;charset=UTF-8"})
  325. @ResponseBody
  326. public Object list(Tablepar tablepar, TestUsecase model, DateTrans dt) {
  327. PageInfo<TestUsecase> page = modelService.list(tablepar, model, dt);
  328. TableSplitResult<TestUsecase> result = new TableSplitResult<TestUsecase>(page.getPageNum(), page.getTotal(), page.getList());
  329. return result;
  330. }
  331. /**
  332. * 测试管理/用例库下的列表展示
  333. *
  334. * @param tablepar
  335. * @param model
  336. * @param dt
  337. * @return
  338. */
  339. @PostMapping(value = "listVo", produces = {"application/json;charset=UTF-8"})
  340. @ResponseBody
  341. public Object listVo(Tablepar tablepar, TestUsecaseIn model, DateTrans dt) {
  342. PageInfo<TestUsecaseIn> page = modelService.listVo(tablepar, model, dt);
  343. TableSplitResult<TestUsecaseIn> result = new TableSplitResult<TestUsecaseIn>(page.getPageNum(), page.getTotal(), page.getList());
  344. return result;
  345. }
  346. /**
  347. * 测试管理/用例库下的列表展示,并展示是否已经被某个测试计划id选中
  348. *
  349. * @param tablepar
  350. * @param model
  351. * @param dt
  352. * @return
  353. */
  354. @PostMapping(value = "listVoWithHasSelect", produces = {"application/json;charset=UTF-8"})
  355. @ResponseBody
  356. public Object listVoWithHasSelect(Tablepar tablepar, TestUsecaseIn model, DateTrans dt) {
  357. PageInfo<TestUsecaseIn> page = modelService.listVoWithHasSelect(tablepar, model, dt);
  358. TableSplitResult<TestUsecaseIn> result = new TableSplitResult<TestUsecaseIn>(page.getPageNum(), page.getTotal(), page.getList());
  359. return result;
  360. }
  361. @PostMapping(value = "listAll", produces = {"application/json;charset=UTF-8"})
  362. @ResponseBody
  363. public Object listAll(TestUsecase model, DateTrans dt) {
  364. return modelService.listAll(model, dt);
  365. }
  366. /**
  367. * 导出用例时获取所有数据
  368. *
  369. * @param model
  370. * @param dt
  371. * @return
  372. */
  373. @PostMapping(value = "findAllByInfo", produces = {"application/json;charset=UTF-8"})
  374. @ResponseBody
  375. public Object findAllByInfo(TestUsecaseIn model, DateTrans dt) {
  376. return modelService.findAllByInfo(model, dt);
  377. }
  378. @PostMapping(value = "add", produces = {"application/json;charset=UTF-8"})
  379. @ResponseBody
  380. public AjaxResult add(TestUsecaseIn record) {
  381. System.out.println("add start");
  382. // System.out.println(testUsecaseSteps);
  383. System.out.println(record);
  384. record.setCreatedAt(new Date());
  385. record.setUpdatedAt(record.getCreatedAt());
  386. record.setCreatedBy(ShiroUtils.getUser().getId());
  387. record.setUpdatedBy(record.getCreatedBy());
  388. record.setStatus(0);
  389. String usecaseId = modelService.insertReturnId(record);
  390. if (record != null) {
  391. if (record.getTestUsecaseSteps() != null) {
  392. List<TestUsecaseStep> list = JSONArray.parseArray(record.getTestUsecaseSteps(), TestUsecaseStep.class);
  393. System.out.println(list);
  394. TestUsecaseStep testUsecaseStep = null;
  395. for (int i = 0; i < list.size(); i++) {
  396. testUsecaseStep = list.get(i);
  397. testUsecaseStep.setUsecaseId(usecaseId);
  398. // if (StringUtils.isEmpty(testUsecaseStep.getId())) {
  399. testUsecaseStep.setCreatedAt(new Date());
  400. testUsecaseStep.setUpdatedAt(record.getCreatedAt());
  401. testUsecaseStep.setCreatedBy(ShiroUtils.getUser().getId());
  402. testUsecaseStep.setUpdatedBy(record.getCreatedBy());
  403. testUsecaseStep.setStatus(0);
  404. testUsecaseStepService.insert(testUsecaseStep);
  405. // } else {
  406. // record.setUpdatedAt(new Date());
  407. // record.setUpdatedBy(ShiroUtils.getUser().getId());
  408. // testUsecaseStepService.updateByPrimaryKeySelective(testUsecaseStep);
  409. // }
  410. }
  411. }
  412. return this.success();
  413. } else {
  414. return this.error();
  415. }
  416. }
  417. @PostMapping(value = "remove/{id}", produces = {"application/json;charset=UTF-8"})
  418. @ResponseBody
  419. public AjaxResult remove(@PathVariable("id") String id) {
  420. // int result = modelService.deleteByPrimaryKey(id);
  421. TestUsecase record = new TestUsecase();
  422. record.setId(id);
  423. record.setStatus(1);
  424. record.setUpdatedBy(ShiroUtils.getUser().getId());
  425. record.setUpdatedAt(new Date());
  426. int result = modelService.updateByPrimaryKeySelective(record);
  427. TestUsecaseStep testUsecaseStep = new TestUsecaseStep();
  428. testUsecaseStep.setStatus(1);
  429. testUsecaseStep.setUpdatedBy(ShiroUtils.getUser().getId());
  430. testUsecaseStep.setUpdatedAt(new Date());
  431. TestUsecaseStepExample testUsecaseStepExample = new TestUsecaseStepExample();
  432. testUsecaseStepExample.createCriteria().andUsecaseIdEqualTo(id);
  433. testUsecaseStepService.updateByExampleSelective(testUsecaseStep, testUsecaseStepExample);
  434. return result(result);
  435. }
  436. @PostMapping(value = "edit", produces = {"application/json;charset=UTF-8"})
  437. @ResponseBody
  438. public AjaxResult editSave(TestUsecaseIn record) {
  439. System.out.println("edit start");
  440. // System.out.println(testUsecaseSteps);
  441. System.out.println(record);
  442. record.setUpdatedBy(ShiroUtils.getUser().getId());
  443. record.setUpdatedAt(new Date());
  444. record.setCreatedAt(null);
  445. record.setCreatedBy(null);
  446. record.setStatus(null);
  447. int result = modelService.updateByPrimaryKeySelective(record);
  448. if (result > 0) {//修改成功
  449. //如果修改成功进行下面的操作
  450. //1.修改或者添加步骤并把步骤id记录下来,最后删除步骤id以外的丢弃步骤
  451. ArrayList<String> inids = new ArrayList<>();
  452. if (record.getTestUsecaseSteps() != null) {
  453. List<TestUsecaseStep> list = JSONArray.parseArray(record.getTestUsecaseSteps(), TestUsecaseStep.class);
  454. // System.out.println(list);
  455. TestUsecaseStep testUsecaseStep = null;
  456. for (int i = 0; i < list.size(); i++) {
  457. testUsecaseStep = list.get(i);
  458. testUsecaseStep.setUsecaseId(record.getId());
  459. if (StringUtils.isEmpty(testUsecaseStep.getId())) {
  460. testUsecaseStep.setCreatedAt(new Date());
  461. testUsecaseStep.setUpdatedAt(record.getCreatedAt());
  462. testUsecaseStep.setCreatedBy(ShiroUtils.getUser().getId());
  463. testUsecaseStep.setUpdatedBy(record.getCreatedBy());
  464. testUsecaseStep.setStatus(0);
  465. String s = testUsecaseStepService.insertReturnId(testUsecaseStep);
  466. if (s != null) {
  467. inids.add(s);
  468. }
  469. } else {
  470. inids.add(testUsecaseStep.getId());
  471. testUsecaseStep.setUpdatedAt(new Date());
  472. testUsecaseStep.setUpdatedBy(ShiroUtils.getUser().getId());
  473. testUsecaseStepService.updateByPrimaryKeySelective(testUsecaseStep);
  474. }
  475. }
  476. }
  477. TestUsecaseStep testUsecaseStep = new TestUsecaseStep();
  478. testUsecaseStep.setStatus(1);
  479. testUsecaseStep.setUpdatedBy(ShiroUtils.getUser().getId());
  480. testUsecaseStep.setUpdatedAt(new Date());
  481. TestUsecaseStepExample testUsecaseStepExample = new TestUsecaseStepExample();
  482. testUsecaseStepExample.createCriteria().andUsecaseIdEqualTo(record.getId()).andIdNotIn(inids);
  483. testUsecaseStepService.updateByExampleSelective(testUsecaseStep, testUsecaseStepExample);
  484. } else {//修改失败
  485. }
  486. // int result = modelService.updateByPrimaryKeySelective(model);
  487. return result(result);
  488. }
  489. @PostMapping(value = "getById", produces = {"application/json;charset=UTF-8"})
  490. @ResponseBody
  491. public TestUsecase getById(String id) {
  492. return modelService.selectByPrimaryKey(id);
  493. }
  494. @PostMapping(value = "test", produces = {"application/json;charset=UTF-8"})
  495. @ResponseBody
  496. public Object getTest() {
  497. System.out.println("test");
  498. return null;
  499. }
  500. @PostMapping(value = "getVoById", produces = {"application/json;charset=UTF-8"})
  501. @ResponseBody
  502. public TestUsecaseIn getVoById(String id) {
  503. return modelService.getVoById(id);
  504. }
  505. }
  506. package com.idea.oa.testPlan.service;
  507. import com.github.pagehelper.PageHelper;
  508. import com.github.pagehelper.PageInfo;
  509. import com.idea.oa.testPlan.mapper.TestPlanExtendMapper;
  510. import com.idea.oa.testPlan.mapper.TestPlanMapper;
  511. import com.idea.oa.testPlan.model.TestPlan;
  512. import com.idea.oa.testPlan.model.TestPlanExample;
  513. import com.idea.oa.testPlan.model.in.TestPlanIn;
  514. import com.rockstar.common.base.BaseService;
  515. import com.rockstar.common.support.Convert;
  516. import com.rockstar.frame.model.extend.DateTrans;
  517. import com.rockstar.frame.model.extend.Tablepar;
  518. import com.rockstar.util.DateUtils;
  519. import com.rockstar.util.SnowflakeIdWorker;
  520. import com.rockstar.util.StringUtils;
  521. import org.springframework.beans.factory.annotation.Autowired;
  522. import org.springframework.stereotype.Service;
  523. import java.util.Date;
  524. import java.util.List;
  525. @Service
  526. public class TestPlanService implements BaseService<TestPlan, TestPlanExample> {
  527. //文件mapper
  528. @Autowired
  529. private TestPlanMapper modelMapper;
  530. @Autowired
  531. private TestPlanExtendMapper testPlanExtendMapper;
  532. /**
  533. * 分页查询
  534. *
  535. * @return
  536. */
  537. public PageInfo<TestPlan> list(Tablepar tablepar, TestPlan model, DateTrans dt) {
  538. PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());
  539. List<TestPlan> list = modelMapper.selectByExample(getCondition(model,dt));
  540. PageInfo<TestPlan> pageInfo = new PageInfo<>(list);
  541. return pageInfo;
  542. }
  543. /**
  544. * 查询指定
  545. *
  546. * @return
  547. */
  548. public List<TestPlan> listAll(TestPlan model, DateTrans dt) {
  549. return modelMapper.selectByExample(getCondition(model,dt));
  550. }
  551. private TestPlanExample getCondition(TestPlan model, DateTrans dt) {
  552. TestPlanExample ex = new TestPlanExample();
  553. ex.setOrderByClause("created_at asc");
  554. TestPlanExample.Criteria criteria = ex.createCriteria();
  555. if(StringUtils.isNotEmpty(model.getPlanName())){
  556. criteria.andPlanNameLike("%"+model.getPlanName()+"%");
  557. }
  558. if(StringUtils.isNotEmpty(model.getProId())){
  559. criteria.andProIdEqualTo(model.getProId());
  560. }
  561. if(StringUtils.isNotEmpty(model.getTaskNo())){
  562. criteria.andTaskNoEqualTo(model.getTaskNo());
  563. }
  564. if(dt != null){
  565. if(StringUtils.isNotEmpty(dt.getDate_from_1())){
  566. criteria.andCreatedAtGreaterThanOrEqualTo(DateUtils.string2Date(dt.getDate_from_1()));
  567. }
  568. if(StringUtils.isNotEmpty(dt.getDate_to_1())){
  569. criteria.andCreatedAtLessThanOrEqualTo(DateUtils.string2Date(dt.getDate_to_1()));
  570. }
  571. }
  572. return ex;
  573. }
  574. @Override
  575. public int deleteByPrimaryKey(String ids) {
  576. List<String> lista = Convert.toListStrArray(ids);
  577. TestPlanExample example = new TestPlanExample();
  578. example.createCriteria().andIdIn(lista);
  579. return modelMapper.deleteByExample(example);
  580. }
  581. @Override
  582. public TestPlan selectByPrimaryKey(String id) {
  583. return modelMapper.selectByPrimaryKey(id);
  584. }
  585. @Override
  586. public int updateByPrimaryKeySelective(TestPlan record) {
  587. return modelMapper.updateByPrimaryKeySelective(record);
  588. }
  589. @Override
  590. public int updateByExampleSelective(TestPlan record, TestPlanExample example) {
  591. return modelMapper.updateByExampleSelective(record, example);
  592. }
  593. @Override
  594. public int updateByExample(TestPlan record, TestPlanExample example) {
  595. return modelMapper.updateByExample(record, example);
  596. }
  597. @Override
  598. public List<TestPlan> selectByExample(TestPlanExample example) {
  599. return modelMapper.selectByExample(example);
  600. }
  601. @Override
  602. public long countByExample(TestPlanExample example) {
  603. return modelMapper.countByExample(example);
  604. }
  605. public long countByExample(TestPlan model, DateTrans dt) {
  606. return modelMapper.countByExample(getCondition(model,dt));
  607. }
  608. @Override
  609. public int deleteByExample(TestPlanExample example) {
  610. return modelMapper.deleteByExample(example);
  611. }
  612. public int insert(TestPlan record){
  613. record.setId(SnowflakeIdWorker.getUUID());
  614. return insertWithoutId(record);
  615. }
  616. public int insertWithoutId(TestPlan record){
  617. return modelMapper.insert(record);
  618. }
  619. @Override
  620. public int insertSelective(TestPlan record) {
  621. record.setId(SnowflakeIdWorker.getUUID());
  622. record.setCreatedAt(new Date());
  623. return modelMapper.insertSelective(record);
  624. }
  625. public List<TestPlanIn> listVo(Tablepar tablepar, TestPlanIn model, DateTrans dt) {
  626. int i = (tablepar.getPageNum() - 1) * tablepar.getPageSize();
  627. tablepar.setPageNum(i);
  628. List<TestPlanIn> list=testPlanExtendMapper.listVo(tablepar, model, dt);
  629. return list;
  630. }
  631. public Long getTotal(TestPlanIn model, DateTrans dt) {
  632. return testPlanExtendMapper.getTotal( model, dt);
  633. }
  634. public TestPlanIn getVoById(String id) {
  635. if (StringUtils.isEmpty(id)){
  636. return null;
  637. }
  638. TestPlanIn testPlanIn = new TestPlanIn();
  639. testPlanIn.setId(id);
  640. List<TestPlanIn> testPlanIns = testPlanExtendMapper.listVo(new Tablepar(), testPlanIn, new DateTrans());
  641. if (testPlanIns.isEmpty()){
  642. return null;
  643. }else{
  644. return testPlanIns.get(0);
  645. }
  646. }
  647. /**
  648. * 前端根据ids获取数据, ids是类似数组的字符串,例如:1684651,6431,或者:135456135 又或者:1651631,等
  649. * @param ids
  650. * @return
  651. */
  652. public List<TestPlanIn> getVoByIds(String ids) {
  653. if (StringUtils.isEmpty(ids)){
  654. return null;
  655. }
  656. String[] split = ids.split(",");
  657. TestPlanIn testPlanIn = new TestPlanIn();
  658. testPlanIn.setIds(split);
  659. List<TestPlanIn> testPlanIns = testPlanExtendMapper.listVo(new Tablepar(), testPlanIn, new DateTrans());
  660. if (testPlanIns.isEmpty()){
  661. return null;
  662. }else{
  663. return testPlanIns;
  664. }
  665. }
  666. }
  667. package com.idea.oa.testPlan.service;
  668. import com.alibaba.fastjson.JSONArray;
  669. import com.github.pagehelper.PageHelper;
  670. import com.github.pagehelper.PageInfo;
  671. import com.idea.oa.testPlan.mapper.TestUsecaseExtendMapper;
  672. import com.idea.oa.testPlan.mapper.TestUsecaseMapper;
  673. import com.idea.oa.testPlan.model.TestUsecase;
  674. import com.idea.oa.testPlan.model.TestUsecaseExample;
  675. import com.idea.oa.testPlan.model.in.TestUsecaseIn;
  676. import com.rockstar.common.base.BaseService;
  677. import com.rockstar.common.support.Convert;
  678. import com.rockstar.frame.model.extend.DateTrans;
  679. import com.rockstar.frame.model.extend.Tablepar;
  680. import com.rockstar.util.DateUtils;
  681. import com.rockstar.util.SnowflakeIdWorker;
  682. import com.rockstar.util.StringUtils;
  683. import org.springframework.beans.factory.annotation.Autowired;
  684. import org.springframework.stereotype.Service;
  685. import java.util.Date;
  686. import java.util.List;
  687. import java.util.Map;
  688. @Service
  689. public class TestUsecaseService implements BaseService<TestUsecase, TestUsecaseExample> {
  690. //文件mapper
  691. @Autowired
  692. private TestUsecaseMapper modelMapper;
  693. @Autowired
  694. private TestUsecaseExtendMapper testUsecaseExtendMapper;
  695. /**
  696. * 分页查询
  697. *
  698. * @return
  699. */
  700. public PageInfo<TestUsecase> list(Tablepar tablepar, TestUsecase model, DateTrans dt) {
  701. PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());
  702. List<TestUsecase> list = modelMapper.selectByExample(getCondition(model,dt));
  703. PageInfo<TestUsecase> pageInfo = new PageInfo<>(list);
  704. return pageInfo;
  705. }
  706. /**
  707. * 查询指定
  708. *
  709. * @return
  710. */
  711. public List<TestUsecase> listAll(TestUsecase model, DateTrans dt) {
  712. return modelMapper.selectByExample(getCondition(model,dt));
  713. }
  714. private TestUsecaseExample getCondition(TestUsecase model, DateTrans dt) {
  715. TestUsecaseExample ex = new TestUsecaseExample();
  716. ex.setOrderByClause("created_at asc");
  717. TestUsecaseExample.Criteria criteria = ex.createCriteria();
  718. if(StringUtils.isNotEmpty(model.getUsecaseTitle())){
  719. criteria.andUsecaseTitleLike("%"+model.getUsecaseTitle()+"%");
  720. }
  721. if(model.getIdPro()!=null){
  722. criteria.andIdProEqualTo(model.getIdPro());
  723. }
  724. if(dt != null){
  725. if(StringUtils.isNotEmpty(dt.getDate_from_1())){
  726. criteria.andCreatedAtGreaterThanOrEqualTo(DateUtils.string2Date(dt.getDate_from_1()));
  727. }
  728. if(StringUtils.isNotEmpty(dt.getDate_to_1())){
  729. criteria.andCreatedAtLessThanOrEqualTo(DateUtils.string2Date(dt.getDate_to_1()));
  730. }
  731. }
  732. return ex;
  733. }
  734. @Override
  735. public int deleteByPrimaryKey(String ids) {
  736. List<String> lista = Convert.toListStrArray(ids);
  737. TestUsecaseExample example = new TestUsecaseExample();
  738. example.createCriteria().andIdIn(lista);
  739. return modelMapper.deleteByExample(example);
  740. }
  741. @Override
  742. public TestUsecase selectByPrimaryKey(String id) {
  743. return modelMapper.selectByPrimaryKey(id);
  744. }
  745. @Override
  746. public int updateByPrimaryKeySelective(TestUsecase record) {
  747. return modelMapper.updateByPrimaryKeySelective(record);
  748. }
  749. @Override
  750. public int updateByExampleSelective(TestUsecase record, TestUsecaseExample example) {
  751. return modelMapper.updateByExampleSelective(record, example);
  752. }
  753. @Override
  754. public int updateByExample(TestUsecase record, TestUsecaseExample example) {
  755. return modelMapper.updateByExample(record, example);
  756. }
  757. @Override
  758. public List<TestUsecase> selectByExample(TestUsecaseExample example) {
  759. return modelMapper.selectByExample(example);
  760. }
  761. @Override
  762. public long countByExample(TestUsecaseExample example) {
  763. return modelMapper.countByExample(example);
  764. }
  765. public long countByExample(TestUsecase model, DateTrans dt) {
  766. return modelMapper.countByExample(getCondition(model,dt));
  767. }
  768. @Override
  769. public int deleteByExample(TestUsecaseExample example) {
  770. return modelMapper.deleteByExample(example);
  771. }
  772. public int insert(TestUsecase record){
  773. // record.setCreatedAt(new Date());
  774. // record.setUpdatedAt(record.getCreatedAt());
  775. // record.setCreatedBy(ShiroUtils.getUser().getId());
  776. // record.setUpdatedBy(record.getCreatedBy());
  777. // record.setStatus(0);
  778. record.setId(SnowflakeIdWorker.getUUID());
  779. return insertWithoutId(record);
  780. }
  781. public String insertReturnId(TestUsecase record){
  782. record.setId(SnowflakeIdWorker.getUUID());
  783. int i = insertWithoutId(record);
  784. if (i>0){
  785. return record.getId();
  786. }else{
  787. return null;
  788. }
  789. }
  790. public int insertWithoutId(TestUsecase record){
  791. // record.setCreatedAt(new Date());
  792. return modelMapper.insert(record);
  793. }
  794. @Override
  795. public int insertSelective(TestUsecase record) {
  796. record.setId(SnowflakeIdWorker.getUUID());
  797. record.setCreatedAt(new Date());
  798. return modelMapper.insertSelective(record);
  799. }
  800. public PageInfo<TestUsecaseIn> listVo(Tablepar tablepar, TestUsecaseIn model, DateTrans dt) {
  801. PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());
  802. List<TestUsecaseIn> list = testUsecaseExtendMapper.selectMoreByInfo(model,dt);
  803. PageInfo<TestUsecaseIn> pageInfo = new PageInfo<>(list);
  804. return pageInfo;
  805. }
  806. public TestUsecaseIn getVoById(String id) {
  807. return testUsecaseExtendMapper.getVoById(id);
  808. }
  809. /**
  810. * 导出用例时获取所有数据
  811. * @param model
  812. * @param dt
  813. * @return
  814. */
  815. public List<Map<String, Object>> findAllByInfo(TestUsecaseIn model, DateTrans dt) {
  816. // System.out.println(model);
  817. List<String> ids=null;
  818. if (model.getIdList() != null) {
  819. ids = JSONArray.parseArray(model.getIdList(), String.class);
  820. // ids = Convert.toListStrArray(model.getIdList());
  821. // for (String id : ids) {
  822. // System.out.println("获取数据:"+id);
  823. // }
  824. }
  825. return testUsecaseExtendMapper.findAllByInfo(model,ids, dt);
  826. }
  827. public PageInfo<TestUsecaseIn> listVoWithHasSelect(Tablepar tablepar, TestUsecaseIn model, DateTrans dt) {
  828. PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());
  829. List<TestUsecaseIn> list = testUsecaseExtendMapper.listVoWithHasSelect(model,dt);
  830. PageInfo<TestUsecaseIn> pageInfo = new PageInfo<>(list);
  831. return pageInfo;
  832. }
  833. }
  834. package com.idea.oa.testPlan.mapper;
  835. import com.idea.oa.testPlan.model.TestPlan;
  836. import com.idea.oa.testPlan.model.TestPlanExample;
  837. import java.util.List;
  838. import org.apache.ibatis.annotations.Param;
  839. import org.springframework.stereotype.Component;
  840. @Component
  841. public interface TestPlanMapper {
  842. long countByExample(TestPlanExample example);
  843. int deleteByExample(TestPlanExample example);
  844. int deleteByPrimaryKey(String id);
  845. int insert(TestPlan record);
  846. int insertSelective(TestPlan record);
  847. List<TestPlan> selectByExample(TestPlanExample example);
  848. TestPlan selectByPrimaryKey(String id);
  849. int updateByExampleSelective(@Param("record") TestPlan record, @Param("example") TestPlanExample example);
  850. int updateByExample(@Param("record") TestPlan record, @Param("example") TestPlanExample example);
  851. int updateByPrimaryKeySelective(TestPlan record);
  852. int updateByPrimaryKey(TestPlan record);
  853. }
  854. package com.idea.oa.testPlan.mapper;
  855. import com.idea.oa.testPlan.model.TestUsecase;
  856. import com.idea.oa.testPlan.model.TestUsecaseExample;
  857. import java.util.List;
  858. import org.apache.ibatis.annotations.Param;
  859. import org.springframework.stereotype.Component;
  860. @Component
  861. public interface TestUsecaseMapper {
  862. long countByExample(TestUsecaseExample example);
  863. int deleteByExample(TestUsecaseExample example);
  864. int deleteByPrimaryKey(String id);
  865. int insert(TestUsecase record);
  866. int insertSelective(TestUsecase record);
  867. List<TestUsecase> selectByExample(TestUsecaseExample example);
  868. TestUsecase selectByPrimaryKey(String id);
  869. int updateByExampleSelective(@Param("record") TestUsecase record, @Param("example") TestUsecaseExample example);
  870. int updateByExample(@Param("record") TestUsecase record, @Param("example") TestUsecaseExample example);
  871. int updateByPrimaryKeySelective(TestUsecase record);
  872. int updateByPrimaryKey(TestUsecase record);
  873. }
  874. package com.idea.oa.testPlan.controller;
  875. import com.github.pagehelper.PageInfo;
  876. import com.idea.oa.testPlan.model.TestPlanCommander;
  877. import com.idea.oa.testPlan.service.TestPlanCommanderService;
  878. import com.rockstar.common.base.BaseController;
  879. import com.rockstar.common.domain.AjaxResult;
  880. import com.rockstar.frame.model.extend.DateTrans;
  881. import com.rockstar.frame.model.extend.TableSplitResult;
  882. import com.rockstar.frame.model.extend.Tablepar;
  883. import io.swagger.annotations.Api;
  884. import org.springframework.beans.factory.annotation.Autowired;
  885. import org.springframework.stereotype.Controller;
  886. import org.springframework.web.bind.annotation.PathVariable;
  887. import org.springframework.web.bind.annotation.PostMapping;
  888. import org.springframework.web.bind.annotation.RequestMapping;
  889. import org.springframework.web.bind.annotation.ResponseBody;
  890. import java.util.Date;
  891. /**
  892. * Created by pengyq on 2020.
  893. */
  894. @Controller
  895. @RequestMapping(value = "TestPlanCommanderController")
  896. @Api(value="测试管理/测试计划/负责人关联表")
  897. public class TestPlanCommanderController extends BaseController {
  898. //主表
  899. @Autowired
  900. private TestPlanCommanderService modelService;
  901. @PostMapping(value = "list",produces = {"application/json;charset=UTF-8"})
  902. @ResponseBody
  903. public Object list(Tablepar tablepar, TestPlanCommander model, DateTrans dt){
  904. PageInfo<TestPlanCommander> page= modelService.list(tablepar,model,dt);
  905. TableSplitResult<TestPlanCommander> result=new TableSplitResult<TestPlanCommander>(page.getPageNum(), page.getTotal(), page.getList());
  906. return result;
  907. }
  908. @PostMapping(value = "listAll",produces = {"application/json;charset=UTF-8"})
  909. @ResponseBody
  910. public Object listAll(TestPlanCommander model, DateTrans dt){
  911. return modelService.listAll(model,dt);
  912. }
  913. @PostMapping(value = "add",produces = {"application/json;charset=UTF-8"})
  914. @ResponseBody
  915. public AjaxResult add(TestPlanCommander record){
  916. record.setCreatedAt(new Date());
  917. int result = modelService.insert(record);
  918. return result(result);
  919. }
  920. @PostMapping(value = "remove/{id}",produces = {"application/json;charset=UTF-8"})
  921. @ResponseBody
  922. public AjaxResult remove(@PathVariable("id") String id){
  923. int result = modelService.deleteByPrimaryKey(id);
  924. return result(result);
  925. }
  926. @PostMapping(value = "edit",produces = {"application/json;charset=UTF-8"})
  927. @ResponseBody
  928. public AjaxResult editSave(TestPlanCommander model){
  929. int result = modelService.updateByPrimaryKeySelective(model);
  930. return result(result);
  931. }
  932. @PostMapping(value = "getById",produces = {"application/json;charset=UTF-8"})
  933. @ResponseBody
  934. public TestPlanCommander getById(String id) {
  935. return modelService.selectByPrimaryKey(id);
  936. }
  937. }
  938. package com.idea.oa.testPlan.service;
  939. import com.github.pagehelper.PageHelper;
  940. import com.github.pagehelper.PageInfo;
  941. import com.idea.oa.testPlan.mapper.TestPlanCommanderMapper;
  942. import com.idea.oa.testPlan.model.TestPlanCommander;
  943. import com.idea.oa.testPlan.model.TestPlanCommanderExample;
  944. import com.rockstar.common.base.BaseService;
  945. import com.rockstar.common.support.Convert;
  946. import com.rockstar.frame.model.extend.DateTrans;
  947. import com.rockstar.frame.model.extend.Tablepar;
  948. import com.rockstar.util.DateUtils;
  949. import com.rockstar.util.SnowflakeIdWorker;
  950. import com.rockstar.util.StringUtils;
  951. import org.springframework.beans.factory.annotation.Autowired;
  952. import org.springframework.stereotype.Service;
  953. import java.util.Date;
  954. import java.util.List;
  955. @Service
  956. public class TestPlanCommanderService implements BaseService<TestPlanCommander, TestPlanCommanderExample> {
  957. //文件mapper
  958. @Autowired
  959. private TestPlanCommanderMapper modelMapper;
  960. /**
  961. * 分页查询
  962. *
  963. * @return
  964. */
  965. public PageInfo<TestPlanCommander> list(Tablepar tablepar, TestPlanCommander model, DateTrans dt) {
  966. PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());
  967. List<TestPlanCommander> list = modelMapper.selectByExample(getCondition(model,dt));
  968. PageInfo<TestPlanCommander> pageInfo = new PageInfo<>(list);
  969. return pageInfo;
  970. }
  971. /**
  972. * 查询指定
  973. *
  974. * @return
  975. */
  976. public List<TestPlanCommander> listAll(TestPlanCommander model, DateTrans dt) {
  977. return modelMapper.selectByExample(getCondition(model,dt));
  978. }
  979. private TestPlanCommanderExample getCondition(TestPlanCommander model, DateTrans dt) {
  980. TestPlanCommanderExample ex = new TestPlanCommanderExample();
  981. ex.setOrderByClause("created_at asc");
  982. TestPlanCommanderExample.Criteria criteria = ex.createCriteria();
  983. // if(StringUtils.isNotEmpty(model.getPlanName())){
  984. // criteria.andPlanNameLike("%"+model.getPlanName()+"%");
  985. // }
  986. // if(StringUtils.isNotEmpty(model.getProId())){
  987. // criteria.andProIdEqualTo(model.getProId());
  988. // }
  989. if(StringUtils.isNotEmpty(model.getPlanId())){
  990. criteria.andPlanIdEqualTo(model.getPlanId());
  991. }
  992. if(dt != null){
  993. if(StringUtils.isNotEmpty(dt.getDate_from_1())){
  994. criteria.andCreatedAtGreaterThanOrEqualTo(DateUtils.string2Date(dt.getDate_from_1()));
  995. }
  996. if(StringUtils.isNotEmpty(dt.getDate_to_1())){
  997. criteria.andCreatedAtLessThanOrEqualTo(DateUtils.string2Date(dt.getDate_to_1()));
  998. }
  999. }
  1000. return ex;
  1001. }
  1002. @Override
  1003. public int deleteByPrimaryKey(String ids) {
  1004. List<String> lista = Convert.toListStrArray(ids);
  1005. TestPlanCommanderExample example = new TestPlanCommanderExample();
  1006. example.createCriteria().andIdIn(lista);
  1007. return modelMapper.deleteByExample(example);
  1008. }
  1009. @Override
  1010. public TestPlanCommander selectByPrimaryKey(String id) {
  1011. return modelMapper.selectByPrimaryKey(id);
  1012. }
  1013. @Override
  1014. public int updateByPrimaryKeySelective(TestPlanCommander record) {
  1015. return modelMapper.updateByPrimaryKeySelective(record);
  1016. }
  1017. @Override
  1018. public int updateByExampleSelective(TestPlanCommander record, TestPlanCommanderExample example) {
  1019. return modelMapper.updateByExampleSelective(record, example);
  1020. }
  1021. @Override
  1022. public int updateByExample(TestPlanCommander record, TestPlanCommanderExample example) {
  1023. return modelMapper.updateByExample(record, example);
  1024. }
  1025. @Override
  1026. public List<TestPlanCommander> selectByExample(TestPlanCommanderExample example) {
  1027. return modelMapper.selectByExample(example);
  1028. }
  1029. @Override
  1030. public long countByExample(TestPlanCommanderExample example) {
  1031. return modelMapper.countByExample(example);
  1032. }
  1033. public long countByExample(TestPlanCommander model, DateTrans dt) {
  1034. return modelMapper.countByExample(getCondition(model,dt));
  1035. }
  1036. @Override
  1037. public int deleteByExample(TestPlanCommanderExample example) {
  1038. return modelMapper.deleteByExample(example);
  1039. }
  1040. public int insert(TestPlanCommander record){
  1041. record.setId(SnowflakeIdWorker.getUUID());
  1042. return insertWithoutId(record);
  1043. }
  1044. public int insertWithoutId(TestPlanCommander record){
  1045. record.setCreatedAt(new Date());
  1046. return modelMapper.insert(record);
  1047. }
  1048. @Override
  1049. public int insertSelective(TestPlanCommander record) {
  1050. record.setId(SnowflakeIdWorker.getUUID());
  1051. record.setCreatedAt(new Date());
  1052. return modelMapper.insertSelective(record);
  1053. }
  1054. }
  1055. package com.idea.oa.testPlan.mapper;
  1056. import com.idea.oa.testPlan.model.TestPlanCommander;
  1057. import com.idea.oa.testPlan.model.TestPlanCommanderExample;
  1058. import java.util.List;
  1059. import org.apache.ibatis.annotations.Param;
  1060. import org.springframework.stereotype.Component;
  1061. @Component
  1062. public interface TestPlanCommanderMapper {
  1063. long countByExample(TestPlanCommanderExample example);
  1064. int deleteByExample(TestPlanCommanderExample example);
  1065. int deleteByPrimaryKey(String id);
  1066. int insert(TestPlanCommander record);
  1067. int insertSelective(TestPlanCommander record);
  1068. List<TestPlanCommander> selectByExample(TestPlanCommanderExample example);
  1069. TestPlanCommander selectByPrimaryKey(String id);
  1070. int updateByExampleSelective(@Param("record") TestPlanCommander record, @Param("example") TestPlanCommanderExample example);
  1071. int updateByExample(@Param("record") TestPlanCommander record, @Param("example") TestPlanCommanderExample example);
  1072. int updateByPrimaryKeySelective(TestPlanCommander record);
  1073. int updateByPrimaryKey(TestPlanCommander record);
  1074. }
  1075. package com.idea.oa.testPlan.controller;
  1076. import com.github.pagehelper.PageInfo;
  1077. import com.idea.oa.testPlan.model.TestUsecaseStep;
  1078. import com.idea.oa.testPlan.service.TestUsecaseStepService;
  1079. import com.rockstar.common.base.BaseController;
  1080. import com.rockstar.common.domain.AjaxResult;
  1081. import com.rockstar.frame.model.extend.DateTrans;
  1082. import com.rockstar.frame.model.extend.TableSplitResult;
  1083. import com.rockstar.frame.model.extend.Tablepar;
  1084. import io.swagger.annotations.Api;
  1085. import org.springframework.beans.factory.annotation.Autowired;
  1086. import org.springframework.stereotype.Controller;
  1087. import org.springframework.web.bind.annotation.PathVariable;
  1088. import org.springframework.web.bind.annotation.PostMapping;
  1089. import org.springframework.web.bind.annotation.RequestMapping;
  1090. import org.springframework.web.bind.annotation.ResponseBody;
  1091. import java.util.Date;
  1092. import java.util.List;
  1093. /**
  1094. * Created by pengyq on 2020.
  1095. */
  1096. @Controller
  1097. @RequestMapping(value = "TestUsecaseStepController")
  1098. @Api(value="测试管理/用例库/用例步骤详细关联表")
  1099. public class TestUsecaseStepController extends BaseController {
  1100. //主表
  1101. @Autowired
  1102. private TestUsecaseStepService modelService;
  1103. @PostMapping(value = "list",produces = {"application/json;charset=UTF-8"})
  1104. @ResponseBody
  1105. public Object list(Tablepar tablepar, TestUsecaseStep model, DateTrans dt){
  1106. PageInfo<TestUsecaseStep> page= modelService.list(tablepar,model,dt);
  1107. TableSplitResult<TestUsecaseStep> result=new TableSplitResult<TestUsecaseStep>(page.getPageNum(), page.getTotal(), page.getList());
  1108. return result;
  1109. }
  1110. @PostMapping(value = "listAll",produces = {"application/json;charset=UTF-8"})
  1111. @ResponseBody
  1112. public Object listAll(TestUsecaseStep model, DateTrans dt){
  1113. return modelService.listAll(model,dt);
  1114. }
  1115. /**
  1116. * 通过usecaseid来获取所有的步骤
  1117. * @param model
  1118. * @return
  1119. */
  1120. @PostMapping(value = "/findListByUsecaseId",produces = {"application/json;charset=UTF-8"})
  1121. @ResponseBody
  1122. public List<TestUsecaseStep> findListByUsecaseId(TestUsecaseStep model){
  1123. return modelService.findListByUsecaseId(model);
  1124. }
  1125. @PostMapping(value = "add",produces = {"application/json;charset=UTF-8"})
  1126. @ResponseBody
  1127. public AjaxResult add(TestUsecaseStep record){
  1128. record.setCreatedAt(new Date());
  1129. int result = modelService.insert(record);
  1130. return result(result);
  1131. }
  1132. @PostMapping(value = "remove/{id}",produces = {"application/json;charset=UTF-8"})
  1133. @ResponseBody
  1134. public AjaxResult remove(@PathVariable("id") String id){
  1135. int result = modelService.deleteByPrimaryKey(id);
  1136. return result(result);
  1137. }
  1138. @PostMapping(value = "edit",produces = {"application/json;charset=UTF-8"})
  1139. @ResponseBody
  1140. public AjaxResult editSave(TestUsecaseStep model){
  1141. int result = modelService.updateByPrimaryKeySelective(model);
  1142. return result(result);
  1143. }
  1144. @PostMapping(value = "getById",produces = {"application/json;charset=UTF-8"})
  1145. @ResponseBody
  1146. public TestUsecaseStep getById(String id) {
  1147. return modelService.selectByPrimaryKey(id);
  1148. }
  1149. }
  1150. package com.idea.oa.testPlan.service;
  1151. import com.github.pagehelper.PageHelper;
  1152. import com.github.pagehelper.PageInfo;
  1153. import com.idea.oa.testPlan.mapper.TestUsecaseStepMapper;
  1154. import com.idea.oa.testPlan.model.TestUsecaseStep;
  1155. import com.idea.oa.testPlan.model.TestUsecaseStepExample;
  1156. import com.rockstar.common.base.BaseService;
  1157. import com.rockstar.common.support.Convert;
  1158. import com.rockstar.frame.model.extend.DateTrans;
  1159. import com.rockstar.frame.model.extend.Tablepar;
  1160. import com.rockstar.util.DateUtils;
  1161. import com.rockstar.util.SnowflakeIdWorker;
  1162. import com.rockstar.util.StringUtils;
  1163. import org.springframework.beans.factory.annotation.Autowired;
  1164. import org.springframework.stereotype.Service;
  1165. import java.util.Date;
  1166. import java.util.List;
  1167. @Service
  1168. public class TestUsecaseStepService implements BaseService<TestUsecaseStep, TestUsecaseStepExample> {
  1169. //文件mapper
  1170. @Autowired
  1171. private TestUsecaseStepMapper modelMapper;
  1172. /**
  1173. * 分页查询
  1174. *
  1175. * @return
  1176. */
  1177. public PageInfo<TestUsecaseStep> list(Tablepar tablepar, TestUsecaseStep model, DateTrans dt) {
  1178. PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());
  1179. List<TestUsecaseStep> list = modelMapper.selectByExample(getCondition(model,dt));
  1180. PageInfo<TestUsecaseStep> pageInfo = new PageInfo<>(list);
  1181. return pageInfo;
  1182. }
  1183. /**
  1184. * 查询指定
  1185. *
  1186. * @return
  1187. */
  1188. public List<TestUsecaseStep> listAll(TestUsecaseStep model, DateTrans dt) {
  1189. return modelMapper.selectByExample(getCondition(model,dt));
  1190. }
  1191. private TestUsecaseStepExample getCondition(TestUsecaseStep model, DateTrans dt) {
  1192. TestUsecaseStepExample ex = new TestUsecaseStepExample();
  1193. ex.setOrderByClause("created_at asc");
  1194. TestUsecaseStepExample.Criteria criteria = ex.createCriteria();
  1195. // if(StringUtils.isNotEmpty(model.getPlanName())){
  1196. // criteria.andPlanNameLike("%"+model.getPlanName()+"%");
  1197. // }
  1198. if(StringUtils.isNotEmpty(model.getUsecaseId())){
  1199. criteria.andUsecaseIdEqualTo(model.getUsecaseId());
  1200. }
  1201. // if(StringUtils.isNotEmpty(model.getTaskNo())){
  1202. // criteria.andTaskNoEqualTo(model.getTaskNo());
  1203. // }
  1204. if(dt != null){
  1205. if(StringUtils.isNotEmpty(dt.getDate_from_1())){
  1206. criteria.andCreatedAtGreaterThanOrEqualTo(DateUtils.string2Date(dt.getDate_from_1()));
  1207. }
  1208. if(StringUtils.isNotEmpty(dt.getDate_to_1())){
  1209. criteria.andCreatedAtLessThanOrEqualTo(DateUtils.string2Date(dt.getDate_to_1()));
  1210. }
  1211. }
  1212. return ex;
  1213. }
  1214. @Override
  1215. public int deleteByPrimaryKey(String ids) {
  1216. List<String> lista = Convert.toListStrArray(ids);
  1217. TestUsecaseStepExample example = new TestUsecaseStepExample();
  1218. example.createCriteria().andIdIn(lista);
  1219. return modelMapper.deleteByExample(example);
  1220. }
  1221. @Override
  1222. public TestUsecaseStep selectByPrimaryKey(String id) {
  1223. return modelMapper.selectByPrimaryKey(id);
  1224. }
  1225. @Override
  1226. public int updateByPrimaryKeySelective(TestUsecaseStep record) {
  1227. return modelMapper.updateByPrimaryKeySelective(record);
  1228. }
  1229. @Override
  1230. public int updateByExampleSelective(TestUsecaseStep record, TestUsecaseStepExample example) {
  1231. return modelMapper.updateByExampleSelective(record, example);
  1232. }
  1233. @Override
  1234. public int updateByExample(TestUsecaseStep record, TestUsecaseStepExample example) {
  1235. return modelMapper.updateByExample(record, example);
  1236. }
  1237. @Override
  1238. public List<TestUsecaseStep> selectByExample(TestUsecaseStepExample example) {
  1239. return modelMapper.selectByExample(example);
  1240. }
  1241. @Override
  1242. public long countByExample(TestUsecaseStepExample example) {
  1243. return modelMapper.countByExample(example);
  1244. }
  1245. public long countByExample(TestUsecaseStep model, DateTrans dt) {
  1246. return modelMapper.countByExample(getCondition(model,dt));
  1247. }
  1248. @Override
  1249. public int deleteByExample(TestUsecaseStepExample example) {
  1250. return modelMapper.deleteByExample(example);
  1251. }
  1252. public int insert(TestUsecaseStep record){
  1253. record.setId(SnowflakeIdWorker.getUUID());
  1254. return insertWithoutId(record);
  1255. }
  1256. public String insertReturnId(TestUsecaseStep record){
  1257. record.setId(SnowflakeIdWorker.getUUID());
  1258. int i = insertWithoutId(record);
  1259. if (i>0){
  1260. return record.getId();
  1261. }else{
  1262. return null;
  1263. }
  1264. }
  1265. public int insertWithoutId(TestUsecaseStep record){
  1266. // record.setCreatedAt(new Date());
  1267. return modelMapper.insert(record);
  1268. }
  1269. @Override
  1270. public int insertSelective(TestUsecaseStep record) {
  1271. record.setId(SnowflakeIdWorker.getUUID());
  1272. record.setCreatedAt(new Date());
  1273. return modelMapper.insertSelective(record);
  1274. }
  1275. public List<TestUsecaseStep> findListByUsecaseId(TestUsecaseStep model) {
  1276. TestUsecaseStepExample ex = new TestUsecaseStepExample();
  1277. ex.setOrderByClause("step_number asc");
  1278. TestUsecaseStepExample.Criteria criteria = ex.createCriteria();
  1279. // if(StringUtils.isNotEmpty(model.getUsecaseId())){
  1280. criteria.andUsecaseIdEqualTo(model.getUsecaseId());
  1281. // }
  1282. criteria.andStatusEqualTo(0);
  1283. return modelMapper.selectByExample(ex);
  1284. }
  1285. }
  1286. package com.idea.oa.testPlan.mapper;
  1287. import com.idea.oa.testPlan.model.TestUsecaseStep;
  1288. import com.idea.oa.testPlan.model.TestUsecaseStepExample;
  1289. import java.util.List;
  1290. import org.apache.ibatis.annotations.Param;
  1291. public interface TestUsecaseStepMapper {
  1292. long countByExample(TestUsecaseStepExample example);
  1293. int deleteByExample(TestUsecaseStepExample example);
  1294. int deleteByPrimaryKey(String id);
  1295. int insert(TestUsecaseStep record);
  1296. int insertSelective(TestUsecaseStep record);
  1297. List<TestUsecaseStep> selectByExample(TestUsecaseStepExample example);
  1298. TestUsecaseStep selectByPrimaryKey(String id);
  1299. int updateByExampleSelective(@Param("record") TestUsecaseStep record, @Param("example") TestUsecaseStepExample example);
  1300. int updateByExample(@Param("record") TestUsecaseStep record, @Param("example") TestUsecaseStepExample example);
  1301. int updateByPrimaryKeySelective(TestUsecaseStep record);
  1302. int updateByPrimaryKey(TestUsecaseStep record);
  1303. }