package com.yb.controller; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import com.yb.dao.THistoryDao; import com.yb.service.ThistoriesServices; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import com.yb.entity.THistoryEntity; import com.yb.service.THistoryService; import com.yb.config.PageUtils; import com.yb.config.R; /** * ${comments} * * @author yw * @email leutu@qq.com * @date 2024-09-14 16:35:15 */ @RestController @RequestMapping("/api/thistory") public class THistoryController { @Autowired private THistoryService tHistoryService; @Autowired private THistoryDao tHistoryDao; @Autowired private ThistoriesServices thistoriesServices; /** * 列表 */ @GetMapping("/list") @ApiOperation(value = "list", notes = "参数 : page,limit") public R list(@RequestParam Map params) { PageUtils page = tHistoryService.queryPage(params); return R.ok().put("page", page); } /** * 列表 */ @GetMapping("/query") @ApiOperation(value = "query", notes = "") public R query(@RequestParam Map params) { PageUtils page = tHistoryService.query(params); return R.ok().put("page", page); } /** * 列表 */ @PostMapping("/listAll") @ApiOperation(value = "listAll", notes = "") public R listAll() { PageUtils page = tHistoryService.queryPage(new HashMap()); return R.ok().put("page", page); } /** * 信息 */ @PostMapping("/info/{id}") @ApiOperation(value = "info", notes = "") public R info(@PathVariable("id") Integer id) { THistoryEntity tHistory = tHistoryService.getById(id); return R.ok().put("tHistory", tHistory); } /** * 保存 */ @PostMapping("/save") @ApiOperation(value = "save", notes = "") public R save(@RequestBody THistoryEntity tHistory) { int id = tHistoryDao.insert(tHistory); // tHistory.getId().toString() HashMap hashMap = new HashMap<>(); hashMap.put("id", tHistory.getId().toString()); return R.ok(hashMap); } /** * 修改 */ @PostMapping("/update") @ApiOperation(value = "update", notes = "") public R update(@RequestBody THistoryEntity tHistory) { tHistoryService.updateById(tHistory); return R.ok(); } /** * 删除 */ @PostMapping("/delete") @ApiOperation(value = "delete", notes = "") public R delete(@RequestBody Integer[] ids) { tHistoryService.removeByIds(Arrays.asList(ids)); return R.ok(); } /** * 修改 */ @PostMapping("/getTableMeta") @ApiOperation(value = "getTableMeta", notes = "") public R getTableMeta() { ArrayList> list = new ArrayList>(); Field[] fields = THistoryEntity.class.getDeclaredFields(); for (Field field : fields) { Map map = new HashMap<>(); System.out.println("属性名:" + field.getName()); System.out.println("类型:" + field.getType().getName()); map.put("name", field.getName()); map.put("type", field.getType().getName()); map.put("cname", field.getName()); list.add(map); } return R.ok(list); } @GetMapping("/getSessionById") @ApiOperation(value = "getSessionById", notes = "") public R getSessionById(@RequestParam(name = "sessionid", defaultValue = " ") String sessionid) { List list = thistoriesServices.getSessionId(sessionid); List> sList = new ArrayList<>(); for (int i = 0; i < list.size(); i++) { THistoryEntity th = list.get(i); HashMap hashMap = new HashMap<>(); hashMap.put("id", th.getId()); hashMap.put("human", th.getHuman()); hashMap.put("ai", th.getAi()); sList.add(hashMap); } PageUtils page = new PageUtils(sList,0,0,0); return R.ok() .put("page", page); } }