diff --git b/.gitignore a/.gitignore new file mode 100644 index 0000000..beed7ee --- /dev/null +++ a/.gitignore @@ -0,0 +1,32 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/** +!**/src/test/** + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ + +### VS Code ### +.vscode/ +/recommendationLogs/ diff --git b/pom.xml a/pom.xml new file mode 100644 index 0000000..5182cf4 --- /dev/null +++ a/pom.xml @@ -0,0 +1,137 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.3.8.RELEASE + + + com.qiwu + inference-game + 2.0.0 + jar + inference-game-2.0.0 + inference-game-2.0.0 + + + 1.8 + + + + org.springframework.boot + spring-boot-autoconfigure + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-logging + + + + + + com.baomidou + mybatis-plus-boot-starter + 3.5.2 + + + + com.baomidou + mybatis-plus-generator + 3.5.2 + + + + org.apache.velocity + velocity-engine-core + 2.3 + + + + io.springfox + springfox-boot-starter + 3.0.0 + + + org.springframework.boot + spring-boot-starter-log4j2 + + + mysql + mysql-connector-java + runtime + + + org.redisson + redisson + 3.17.4 + + + com.alibaba + druid + 1.2.11 + + + com.alibaba + fastjson + 1.2.70 + + + com.alibaba + easyexcel + 3.1.1 + + + org.projectlombok + lombok + compile + + + + cn.hutool + hutool-all + 5.8.8 + + + commons-fileupload + commons-fileupload + 1.4 + + + + + com.github.junrar + junrar + 7.5.4 + + + net.lingala + zip4j + 1.3.3 + + + + + inference-game + + + org.springframework.boot + spring-boot-maven-plugin + 2.1.7.RELEASE + + + + repackage + + + + + + + + diff --git b/src/main/java/com/qiwu/inference/FileImport.java a/src/main/java/com/qiwu/inference/FileImport.java new file mode 100644 index 0000000..6a8fef1 --- /dev/null +++ a/src/main/java/com/qiwu/inference/FileImport.java @@ -0,0 +1,178 @@ +package com.qiwu.inference; + +import com.alibaba.excel.EasyExcel; +import com.alibaba.excel.read.listener.PageReadListener; +import com.qiwu.inference.pojo.*; +import com.qiwu.inference.service.*; +import com.qiwu.inference.util.FileUtil; +import com.qiwu.inference.util.SpringContextUtil; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.ApplicationContext; + +import java.io.File; + +@SpringBootApplication +public class FileImport { + + private static EndGoalService endGoalService; + private static KeyClueService keyClueService; + private static IdentityService identityService; + private static PersonService personService; + private static LocationService locationService; + private static DispositionService dispositionService; + private static DispositionTypeService dispositionTypeService; + private static BehaviourService behaviourService; + private static RelationService relationService; + private static RelationTypeService relationTypeService; + private static DemandTaskService demandTaskService; + private static TaskConditionService taskConditionService; + private static ItemService itemService; + + private static ClueService clueService; + + + + public static void main(String[] args) { + + SpringApplication.run(FileImport.class,args); + ApplicationContext applicationContext = SpringContextUtil.getApplicationContext(); + + //1. 结局目标 + endGoalService = applicationContext.getBean(EndGoalService.class); + String fileName = FileUtil.getPath() + "file" + File.separator + "end_goal.xlsx"; + // 这里 需要指定读用哪个class去读,然后读取第一个sheet 文件流会自动关闭 + // 这里每次会读取100条数据 然后返回过来 直接调用使用数据就行 + EasyExcel.read(fileName, EndGoal.class, new PageReadListener(dataList -> { + endGoalService.saveBatch(dataList); + })).sheet().doRead(); + + //2. 关键线索 + keyClueService = applicationContext.getBean(KeyClueService.class); + fileName = FileUtil.getPath() + "file" + File.separator + "key_clue.xlsx"; + // 这里 需要指定读用哪个class去读,然后读取第一个sheet 文件流会自动关闭 + // 这里每次会读取100条数据 然后返回过来 直接调用使用数据就行 + EasyExcel.read(fileName, KeyClue.class, new PageReadListener(dataList -> { + keyClueService.saveBatch(dataList); + })).sheet().doRead(); + + + //3. 身份 + identityService = applicationContext.getBean(IdentityService.class); + fileName = FileUtil.getPath() + "file" + File.separator + "identity.xlsx"; + // 这里 需要指定读用哪个class去读,然后读取第一个sheet 文件流会自动关闭 + // 这里每次会读取100条数据 然后返回过来 直接调用使用数据就行 + EasyExcel.read(fileName, Identity.class, new PageReadListener(dataList -> { + identityService.saveBatch(dataList); + })).sheet().doRead(); + + + //4. 场所 + locationService = applicationContext.getBean(LocationService.class); + fileName = FileUtil.getPath() + "file" + File.separator + "location.xlsx"; + // 这里 需要指定读用哪个class去读,然后读取第一个sheet 文件流会自动关闭 + // 这里每次会读取100条数据 然后返回过来 直接调用使用数据就行 + EasyExcel.read(fileName, Location.class, new PageReadListener(dataList -> { + locationService.saveBatch(dataList); + })).sheet().doRead(); + + + //5. 性格喜好 + dispositionService = applicationContext.getBean(DispositionService.class); + fileName = FileUtil.getPath() + "file" + File.separator + "disposition.xlsx"; + // 这里 需要指定读用哪个class去读,然后读取第一个sheet 文件流会自动关闭 + // 这里每次会读取100条数据 然后返回过来 直接调用使用数据就行 + EasyExcel.read(fileName, Disposition.class, new PageReadListener(dataList -> { + dispositionService.saveBatch(dataList); + })).sheet().doRead(); + + + //6. 行为 + behaviourService = applicationContext.getBean(BehaviourService.class); + fileName = FileUtil.getPath() + "file" + File.separator + "behaviour.xlsx"; + // 这里 需要指定读用哪个class去读,然后读取第一个sheet 文件流会自动关闭 + // 这里每次会读取100条数据 然后返回过来 直接调用使用数据就行 + EasyExcel.read(fileName, Behaviour.class, new PageReadListener(dataList -> { + behaviourService.saveBatch(dataList); + })).sheet().doRead(); + + + //7. 关系 + relationService = applicationContext.getBean(RelationService.class); + fileName = FileUtil.getPath() + "file" + File.separator + "relation.xlsx"; + // 这里 需要指定读用哪个class去读,然后读取第一个sheet 文件流会自动关闭 + // 这里每次会读取100条数据 然后返回过来 直接调用使用数据就行 + EasyExcel.read(fileName, Relation.class, new PageReadListener(dataList -> { + relationService.saveBatch(dataList); + })).sheet().doRead(); + + + //8. 关系类型 + relationTypeService = applicationContext.getBean(RelationTypeService.class); + fileName = FileUtil.getPath() + "file" + File.separator + "relation_type.xlsx"; + // 这里 需要指定读用哪个class去读,然后读取第一个sheet 文件流会自动关闭 + // 这里每次会读取100条数据 然后返回过来 直接调用使用数据就行 + EasyExcel.read(fileName, RelationType.class, new PageReadListener(dataList -> { + relationTypeService.saveBatch(dataList); + })).sheet().doRead(); + + + //9. 需求任物 + demandTaskService = applicationContext.getBean(DemandTaskService.class); + fileName = FileUtil.getPath() + "file" + File.separator + "demand_task.xlsx"; + // 这里 需要指定读用哪个class去读,然后读取第一个sheet 文件流会自动关闭 + // 这里每次会读取100条数据 然后返回过来 直接调用使用数据就行 + EasyExcel.read(fileName, DemandTask.class, new PageReadListener(dataList -> { + demandTaskService.saveBatch(dataList); + })).sheet().doRead(); + + //10. 任物条件 + taskConditionService = applicationContext.getBean(TaskConditionService.class); + fileName = FileUtil.getPath() + "file" + File.separator + "task_condition.xlsx"; + // 这里 需要指定读用哪个class去读,然后读取第一个sheet 文件流会自动关闭 + // 这里每次会读取100条数据 然后返回过来 直接调用使用数据就行 + EasyExcel.read(fileName, TaskCondition.class, new PageReadListener(dataList -> { + taskConditionService.saveBatch(dataList); + })).sheet().doRead(); + + + //11. 人物表 + personService = applicationContext.getBean(PersonService.class); + fileName = FileUtil.getPath() + "file" + File.separator + "person.xlsx"; + // 这里 需要指定读用哪个class去读,然后读取第一个sheet 文件流会自动关闭 + // 这里每次会读取100条数据 然后返回过来 直接调用使用数据就行 + EasyExcel.read(fileName, Person.class, new PageReadListener(dataList -> { + personService.saveBatch(dataList); + })).sheet().doRead(); + + + //12. 物品表 + itemService = applicationContext.getBean(ItemService.class); + fileName = FileUtil.getPath() + "file" + File.separator + "item.xlsx"; + // 这里 需要指定读用哪个class去读,然后读取第一个sheet 文件流会自动关闭 + // 这里每次会读取100条数据 然后返回过来 直接调用使用数据就行 + EasyExcel.read(fileName, Item.class, new PageReadListener(dataList -> { + itemService.saveBatch(dataList); + })).sheet().doRead(); + + //13. 性格类型 + dispositionTypeService = applicationContext.getBean(DispositionTypeService.class); + fileName = FileUtil.getPath() + "file" + File.separator + "disposition_type.xlsx"; + // 这里 需要指定读用哪个class去读,然后读取第一个sheet 文件流会自动关闭 + // 这里每次会读取100条数据 然后返回过来 直接调用使用数据就行 + EasyExcel.read(fileName, DispositionType.class, new PageReadListener(dataList -> { + dispositionTypeService.saveBatch(dataList); + })).sheet().doRead(); + + + //14. 线索 + clueService = applicationContext.getBean(ClueService.class); + fileName = FileUtil.getPath() + "file" + File.separator + "clue.xlsx"; + // 这里 需要指定读用哪个class去读,然后读取第一个sheet 文件流会自动关闭 + // 这里每次会读取100条数据 然后返回过来 直接调用使用数据就行 + EasyExcel.read(fileName, Clue.class, new PageReadListener(dataList -> { + clueService.saveBatch(dataList); + })).sheet().doRead(); + + } +} diff --git b/src/main/java/com/qiwu/inference/InferenceGameApplication.java a/src/main/java/com/qiwu/inference/InferenceGameApplication.java new file mode 100644 index 0000000..97bcc1f --- /dev/null +++ a/src/main/java/com/qiwu/inference/InferenceGameApplication.java @@ -0,0 +1,13 @@ +package com.qiwu.inference; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ComponentScan; + +@SpringBootApplication +public class InferenceGameApplication { + + public static void main(String[] args) { + SpringApplication.run(InferenceGameApplication.class, args); + } +} diff --git b/src/main/java/com/qiwu/inference/auto/BFS.java a/src/main/java/com/qiwu/inference/auto/BFS.java new file mode 100644 index 0000000..423bb75 --- /dev/null +++ a/src/main/java/com/qiwu/inference/auto/BFS.java @@ -0,0 +1,556 @@ +package com.qiwu.inference.auto; + +import cn.hutool.core.util.ObjectUtil; +import com.qiwu.inference.auto.enums.ConditionMethod; +import com.qiwu.inference.auto.pojo.*; +import com.qiwu.inference.auto.service.PlayerServiceImpl; +import com.qiwu.inference.common.api.CommonData; +import com.qiwu.inference.common.api.CommonResult; +import com.qiwu.inference.util.FastJsonUtil; +import com.qiwu.inference.util.FileUtil; +import org.springframework.util.StringUtils; + +import java.io.File; +import java.text.SimpleDateFormat; +import java.util.*; + +public class BFS { + + private static PlayerServiceImpl playerService; + + public static List list = new ArrayList<>(); + + private static boolean endFlag = true; + private static int count = 0; + public static int steps = 30; + private static double minScore = 0; + + public static void main(String[] args) throws Exception { +// String key = "4a2410ec-a131-4a43-bb4b-13b0ce5ea30a"; + Player player; + player = new Player(); +// if (!RedissonUtil.checkKey(key)) { +// player = new Player(); +// RedissonUtil.setStr(player.getGateNo(), FastJsonUtil.obj2json(player)); +// } else { +// String playerStr = RedissonUtil.getStr(key); +// player = FastJsonUtil.json2obj(playerStr, Player.class); +// } + playerService = new PlayerServiceImpl(); + for (Integer personId : player.getPersonMap().keySet()) { + findTasks(personId, player); + } + minScore = 0; + player.setIndex(0); + player.aStarScore(); + aStar(player); + String filePath = FileUtil.getPath() + "file" + File.separator + "results_log.txt"; + FileUtil.writeLog(list, filePath); + System.exit(0); + } + + + /** + * 查询符合条件的任务 + */ + private static void findTasks(int personId, Player player) { + List demandTaskList = player.getPersonMap().get(personId).getDemandTasks(); + for (DemandTask demandTask : demandTaskList) { + if (demandTask.getType() == 6) { + if (demandTask.getSubject() == personId && demandTask.getClueSwitch() == 0) { + if (!player.getDemandTaskHashSet().contains(demandTask)) { + demandTask.setStatus(2); + demandTask.setLockStatus(1); + demandTask.setClueProb(1.0); + demandTask.setThresholdStatus(1); + demandTask.setThresholdProb(1.0); + player.getDemandTaskQueue().add(demandTask); + player.getDemandTaskHashSet().add(demandTask); + } + } + } + } + } + + /** + * 查询符合条件的任务 + */ + private static void findTasks(String postTask, int personId, Player player) { + if (personId == 0) { + return; + } + List demandTaskList = player.getPersonMap().get(personId).getDemandTasks(); + for (DemandTask demandTask : demandTaskList) { + if (demandTask.getType() == 6) { + String[] postTasks = postTask.split("\\|"); + for (String taskId : postTasks) { + if (demandTask.getSubject() == personId && demandTask.getDemandTaskId() == Integer.parseInt(taskId)) { + if (!player.getDemandTaskHashSet().contains(demandTask)) { + demandTask.setStatus(2); + demandTask.setLockStatus(1); + player.getDemandTaskQueue().add(demandTask); + player.getDemandTaskHashSet().add(demandTask); + } + } + } + } + } + } + + + /** + * 执行询问操作 + * @param player 玩家信息 + */ + private static void performAsk(Player player) { + Map personMap = player.getPersonMap(); + //List askMethodId = Arrays.asList("1007"); + List askMethodId = Arrays.asList("1002", "1007", "1009", "1010", "1015", "1016", "1017", "1018", "1019", "1020", "1021", "1022", "1023", "1029", "1024", "1025", "1026", "1027", "1028"); + //List askMethodId = Arrays.asList("1002","1007","1009","1010","1023","1029","1024","1025","1026","1027","1028"); + + for (Integer subjectId : personMap.keySet()) { + player.setPersonId(subjectId); + //System.out.println("当前询问人物的编号:"+subjectId); + for (Integer objectId : personMap.keySet()) { + if (!Objects.equals(subjectId, objectId)) { + for (String methodId : askMethodId) { + askOperate(personMap.get(objectId), null, methodId, player); + } + } + } + } + + } + + /** + * 询问操作 + * + * @param subject 主体对象 + * @param object 客体对象 + * @param methodId 方法id + * @param player 玩家信息 + */ + private static void askOperate(Person subject, Person object, String methodId, Player player) { + Map request = new HashMap<>(); + request.put("subjectName", subject.getName()); + if ("1003".equals(methodId) || "1004".equals(methodId) || "1008".equals(methodId) || "1011".equals(methodId)) { + request.put("objectName", object.getName()); + } + + CommonResult result = null; + if ("1001".equals(methodId) || "1002".equals(methodId)) { + request.put("type", "1"); + request.put("dispositionName", subject.getDispositions().get(0).getName()); + result = playerService.askDisposition(methodId, player, request); + if (result.getCode() == 200) { + if ("1".equals(result.getData().getStatus())) { + List demandTaskList = result.getData().getDemandTaskList(); + if (demandTaskList.size() > 0) { + String res = "向" + player.getPersonMap().get(player.getPersonId()).getName() + "询问,执行" + methodId + "(" + result.getData().getName() + ")操作,向" + subject.getName() + "询问性格," + "反馈结果为:" + result.getData().getText(); + printLog(res, player); + saveTask(demandTaskList, player); + } + } + } + } else if ("1003".equals(methodId) || "1004".equals(methodId) || "1005".equals(methodId) || "1006".equals(methodId)) { + if ("1003".equals(methodId)) { + result = playerService.askRelation(methodId, player, request); + if (result.getCode() == 200) { + if ("1".equals(result.getData().getStatus())) { +// String res ="向"+player.getPersonMap().get(player.getPersonId()).getName()+"询问,执行"+methodId+"("+result.getData().getName()+")操作,询问"+subject.getName()+"和"+object.getName()+"的关系,"+"反馈结果为:"+result.getData().getText(); + } + } + } else { + Set relations = new HashSet<>(); + for (Person person : player.getPersonMap().values()) { + for (Relation relation : person.getRelations()) { + relations.add(relation.getName()); + } + } + + //String[] relations = new String[]{"面缘","认识","友好","亲密","厌恶","仇恨","儿子","女儿","父亲","母亲","妻子","丈夫","前妻","前夫","孙子","孙女","爷爷","奶奶","外公","外婆","亲戚","远房亲戚","邻居","朋友","被绑架","绑架","被买","被卖","买人","卖人","盗窃","被盗"}; + for (String relation : relations) { + request.put("relationName", relation); + result = playerService.askRelation(methodId, player, request); + if (result.getCode() == 200) { + if ("1".equals(result.getData().getStatus())) { + if ("1004".equals(methodId)) { +// String res ="向"+player.getPersonMap().get(player.getPersonId()).getName()+"询问,执行"+methodId+"("+result.getData().getName()+")操作,询问"+subject.getName()+"和"+object.getName()+"之间是否是"+relation+"的关系,"+"反馈结果为:"+result.getData().getText(); + } else { +// String res ="向"+player.getPersonMap().get(player.getPersonId()).getName()+"询问,执行"+methodId+"("+result.getData().getName()+")操作,询问"+subject.getName()+"和谁之间是否是"+relation+"的关系,"+"反馈结果为:"+result.getData().getText(); + } + } + } + } + } + + } else if ("1007".equals(methodId) || "1008".equals(methodId) || "1009".equals(methodId) || "1010".equals(methodId) || "1011".equals(methodId)) { + if ("1007".equals(methodId)) { + result = playerService.askBehaviour(methodId, player, request); + if (result.getCode() == 200) { + if ("1".equals(result.getData().getStatus())) { + List demandTaskList = result.getData().getDemandTaskList(); + if (demandTaskList.size() > 0) { + String res = "向" + player.getPersonMap().get(player.getPersonId()).getName() + "询问,执行" + methodId + "(" + result.getData().getName() + ")操作,询问" + subject.getName() + "有什么样的行为," + "反馈结果为:" + result.getData().getText(); + printLog(res, player); + saveTask(demandTaskList, player); + } + } + } + } else if ("1008".equals(methodId)) { + result = playerService.askBehaviour(methodId, player, request); + if (result.getCode() == 200) { + if ("1".equals(result.getData().getStatus())) { +// String res ="向"+player.getPersonMap().get(player.getPersonId()).getName()+"询问,执行"+methodId+"("+result.getData().getName()+")操作,询问"+subject.getName()+"和"+object.getName()+"之间有什么样的行为,"+"反馈结果为:"+result.getData().getText(); + } + } + } else { + Set behaviours = new HashSet<>(); + for (Person person : player.getPersonMap().values()) { + for (Behaviour behaviour : person.getBehaviours()) { + behaviours.add(behaviour.getName()); + } + } +// String[] behaviours = new String[]{"斗殴","殴伤","重伤","绑架","偷盗金钱","偷盗物品","被绑架","贪污金钱","贪污财宝","暗探","在逃", "越狱", "通缉", "通奸", "诈骗", "欺骗", "威胁", "挑拨", "诱拐", "欠债", "欠债不还", "辱骂", "造谣", "强奸", "背叛感情", "背叛上级", "背叛同伴", "出卖感情", "出卖上司", "出卖同伴", "帮助", "贿赂", "受贿", "讨好", "路边看到", "关怀备至", "学习武艺", "杀人", "帮买米", "买东西", "卖东西", +// "偷听", "闲聊", "密谈", "拜访", "取笑", "送礼", "追求", "求学", "传授武艺", "传授学问", "救火", "被打伤", "被打重伤", "被盗", "被贪污", "被通缉", "被诈骗", "被欺骗", "被威胁", "被挑拨", "被诱拐", "被欠债", "被欠债不还", "被辱骂", "被造谣", "被强奸", "被背叛感情", "被背叛", "被出卖感情", "被出卖", "被帮助", "被讨好", "被关怀", "被拜访", "被取笑", "被送礼", "被追求", "丢失钗子", "捡到钗子", "盗窃钗子"}; + for (String behaviour : behaviours) { + request.put("behaviourName", behaviour); + result = playerService.askBehaviour(methodId, player, request); + if (result.getCode() == 200) { + if ("1".equals(result.getData().getStatus())) { + if ("1011".equals(methodId)) { +// String res ="向"+player.getPersonMap().get(player.getPersonId()).getName()+"询问,执行"+methodId+"("+result.getData().getName()+")操作,询问"+subject.getName()+"和"+object.getName()+"之间是否有"+behaviour+"的行为,"+"反馈结果为:"+result.getData().getText(); + } else { + List demandTaskList = result.getData().getDemandTaskList(); + if (demandTaskList.size() > 0) { + String res = "向" + player.getPersonMap().get(player.getPersonId()).getName() + "询问,执行" + methodId + "(" + result.getData().getName() + ")操作,询问" + subject.getName() + "和谁有" + behaviour + "的行为," + "反馈结果为:" + result.getData().getText(); + printLog(res, player); + saveTask(demandTaskList, player); + } + } + } + } + } + } + } else if ("1015".equals(methodId) || "1016".equals(methodId) || "1017".equals(methodId) || "1018".equals(methodId) || "1019".equals(methodId) || "1020".equals(methodId) || "1021".equals(methodId) || "1022".equals(methodId)) { + if ("1017".equals(methodId) || "1018".equals(methodId) || "1021".equals(methodId) || "1022".equals(methodId)) { + Set tasks = new HashSet<>(); + for (Person person : player.getPersonMap().values()) { + for (DemandTask demandTask : person.getDemandTasks()) { + tasks.add(demandTask.getName()); + } + } + //String[] tasks = new String[]{"饮酒", "开怀畅饮", "打招呼", "喜欢古董", "(后)卖古董", "(后)卖古董低价", "需要金疮药", "(后)买金疮药", "(后)获赠金疮药", "揍人报仇", "(后)挨揍", "请吃饭", "小费", "帮忙挑水", "帮找大夫", "(后)大夫出诊", "一起钓鱼", "需要人送货", "想要茶具", "(后)卖出茶具", "喜欢钓鱼", "送钱(高)", "送钱(中)", "送钱(低)", "寻找钗子", "(后)买回钗子", "(后)抢回钗子", "追查私吞", "(后)追回私吞款", "打探肥羊", "(后)探听身家", "(后)送货"}; + for (String task : tasks) { + request.put("taskName", task); + result = playerService.askTask(methodId, player, request); + if (result.getCode() == 200) { + if ("1".equals(result.getData().getStatus())) { + List demandTaskList = result.getData().getDemandTaskList(); + if (demandTaskList.size() > 0) { + String res = "向" + player.getPersonMap().get(player.getPersonId()).getName() + "询问,执行" + methodId + "(" + result.getData().getName() + ")操作,询问" + subject.getName() + "是否有" + task + "的任务," + "反馈结果为:" + result.getData().getText(); + printLog(res, player); + saveTask(demandTaskList, player); + } + } + } + } + } else { + result = playerService.askTask(methodId, player, request); + if (result.getCode() == 200) { + if ("1".equals(result.getData().getStatus())) { + List demandTaskList = result.getData().getDemandTaskList(); + if (demandTaskList.size() > 0) { + String res = "向" + player.getPersonMap().get(player.getPersonId()).getName() + "询问,执行" + methodId + "(" + result.getData().getName() + ")操作,询问" + subject.getName() + "是否有可以提升或者降低信任度或者威慑度的任务," + "反馈结果为:" + result.getData().getText(); + printLog(res, player); + saveTask(demandTaskList, player); + } + } + } + } + } else if ("1023".equals(methodId) || "1024".equals(methodId)) { + if ("1023".equals(methodId)) { + result = playerService.askIdentity(methodId, player, request); + if (result.getCode() == 200) { + if ("1".equals(result.getData().getStatus())) { + List demandTaskList = result.getData().getDemandTaskList(); + if (demandTaskList.size() > 0) { + String res = "向" + player.getPersonMap().get(player.getPersonId()).getName() + "询问,执行" + methodId + "(" + result.getData().getName() + ")操作,询问" + subject.getName() + "的身份," + "反馈结果为:" + result.getData().getText(); + printLog(res, player); + saveTask(demandTaskList, player); + } + } + } + } else { + Set identitys = new HashSet<>(); + for (Person person : player.getPersonMap().values()) { + identitys.add(person.getIdentityName()); + } + //String[] identitys = new String[]{"大夫", "酒馆掌柜", "店小二", "土匪", "流民", "混混", "老妇人", "美女", "杂货店掌柜", "赌徒"}; + for (String identity : identitys) { + request.put("identityName", identity); + result = playerService.askIdentity(methodId, player, request); + if (result.getCode() == 200) { + if ("1".equals(result.getData().getStatus())) { + List demandTaskList = result.getData().getDemandTaskList(); + if (demandTaskList.size() > 0) { + String res = "向" + player.getPersonMap().get(player.getPersonId()).getName() + "询问,执行" + methodId + "(" + result.getData().getName() + ")操作,询问" + subject.getName() + "的身份是否为" + identity + "," + "反馈结果为:" + result.getData().getText(); + printLog(res, player); + saveTask(demandTaskList, player); + } + } + } + } + } + + } else if ("1025".equals(methodId) || "1026".equals(methodId)) { + if ("1025".equals(methodId)) { + result = playerService.askLocation(methodId, player, request); + if (result.getCode() == 200) { + if ("1".equals(result.getData().getStatus())) { + List demandTaskList = result.getData().getDemandTaskList(); + if (demandTaskList.size() > 0) { + String res = "向" + player.getPersonMap().get(player.getPersonId()).getName() + "询问,执行" + methodId + "(" + result.getData().getName() + ")操作,询问" + subject.getName() + "的位置," + "反馈结果为:" + result.getData().getText(); + printLog(res, player); + saveTask(demandTaskList, player); + } + } + } + } else { + String[] locations = new String[]{"公司", "商场", "物业"}; + //String[] locations = new String[]{"酒馆", "客栈", "民居", "广场", "小巷", "街道", "后山", "郊外", "赌场", "肉铺", "村舍", "民房", "私塾", "县衙", "青楼", "杂货店", "裁缝店", "县衙后院", "青楼门口", "寺庙"}; + for (String location : locations) { + request.put("locationName", location); + result = playerService.askLocation(methodId, player, request); + if (result.getCode() == 200) { + if ("1".equals(result.getData().getStatus())) { + List demandTaskList = result.getData().getDemandTaskList(); + if (demandTaskList.size() > 0) { + String res = "向" + player.getPersonMap().get(player.getPersonId()).getName() + "询问,执行" + methodId + "(" + result.getData().getName() + ")操作,询问" + subject.getName() + "的位置是否在" + location + "," + "反馈结果为:" + result.getData().getText(); + printLog(res, player); + saveTask(demandTaskList, player); + } + } + } + } + } + } else if ("1027".equals(methodId)) { + result = playerService.askPrompt(methodId, player, request); + if (result.getCode() == 200) { + if ("1".equals(result.getData().getStatus())) { + List demandTaskList = result.getData().getDemandTaskList(); + if (demandTaskList.size() > 0) { + String res = "向" + player.getPersonMap().get(player.getPersonId()).getName() + "询问,执行" + methodId + "(" + result.getData().getName() + ")操作,询问" + subject.getName() + "给个提示," + "反馈结果为:" + result.getData().getText(); + printLog(res, player); + saveTask(demandTaskList, player); + } + } + } + } + } + + private static void printLog(String line, Player player) { + list.add(line); + //set.add(line); + player.getLogList().add(line); + //System.out.println(line); + } + + /** + * 设置前置任务的 postTaskStatus 为 1 + */ + private static void setPostTaskStatus(DemandTask demandTask, Player player) { + Set demandTaskSet = new HashSet<>(); + + for (Person person : player.getPersonMap().values()) { + demandTaskSet.addAll(person.getDemandTasks()); + } + + for (DemandTask temp : demandTaskSet) { + if (!StringUtils.isEmpty(temp.getPostTask()) && temp.getPostTask().contains(String.valueOf(demandTask.getDemandTaskId())) && demandTask.getSubject() == temp.getObject()) { + temp.setPostTaskStatus(1); + break; + } + } + } + + /** + * 执行任务 + * + * @param demandTask 任务 + * @param player 玩家信息 + */ + private static boolean performTask(DemandTask demandTask, Player player) throws Exception { + String[] condition1 = demandTask.getCondition1().split("\\|"); + Person subject = player.getPersonMap().get(demandTask.getSubject()); + String methodId = ConditionMethod.get(condition1[0]).getMethodId(); + + CommonResult result = playerService.performTask(demandTask, player); + + if (result.getCode() == 200) { + if ("1".equals(result.getData().getStatus())) { + demandTask.setStatus(3); + setPostTaskStatus(demandTask, player); + String res = "执行" + methodId + "(" + result.getData().getName() + ")操作,向" + subject.getName() + "执行任务操作,反馈结果为:" + result.getData().getText(); + printLog(res, player); + if (demandTask.getTaskLabel() == 3) { + endFlag = false; + System.out.println("------最终成功结果---------"); + player.getFinalLogList().addAll(player.getAskLogList()); + player.getFinalLogList().addAll(player.getLogList()); + + player.getFinalTaskList().add(demandTask); + + for (int i = 0; i < player.getFinalLogList().size(); i++) { + System.out.println(player.getFinalLogList().get(i)); + } + String filePath = FileUtil.getPath() + "file" + File.separator + "results_final.txt"; + FileUtil.writeLog(player.getFinalLogList(), filePath); + + String fileJsonPath = FileUtil.getPath() + "file" + File.separator + "results_final_task.json"; + FastJsonUtil.createJsonFile(player.getFinalTaskList(), fileJsonPath); + + System.out.println("------最终成功结果---------"); + } + return true; + } + } + if(player.getStep()>steps){ + endFlag = false; + System.out.println("------超过最大步数退出---------"); + } + return false; + } + + /** + * A*找最短路径 + * + * @param startPlayer + */ + private static void aStar(Player startPlayer) throws Exception { + List queue = new ArrayList<>(); + int index = 0; + queue.add(startPlayer); + startPlayer.setIndex(0); + while (index >= 0) { + Player currentPlayer = queue.get(index); + count++; + Date date = new Date(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SS"); +// for (String val:currentPlayer.getFinalLogList()){ +// System.out.println(val); +// } + DemandTask keyTask = currentPlayer.findKeyTask_(); + // postTaskStatus 0 表示后置任务没有执行 1 表示后置任务已经执行 + // clueProb 线索解锁的概率占比 + // thresholdProb 任务解锁的概率占比 + String playerStatus = "[" + keyTask.getPostTaskStatus() + "/" + keyTask.getClueProb() + "/" + keyTask.getThresholdProb() + "]"; + //String playerStatus = "["+keyTask.getPostTaskStatus()+"/"+((double)Math.round(keyTask.getCluePro()*10000)/10000)+"/"+((double)Math.round(keyTask.getThresholdPro()*10000)/10000)+"]"; + System.out.println("---" + count + "/" + queue.size() + playerStatus + currentPlayer.getScore() + "---" + currentPlayer.getPath() + "---" + sdf.format(date)); + + currentPlayer.getLogList().clear(); + performAsk(currentPlayer); + currentPlayer.setAskLogList(ObjectUtil.cloneByStream(currentPlayer.getLogList())); + Object[] currentTaskList = currentPlayer.getDemandTaskQueue().toArray(); + //根据评估排序 + if (currentPlayer.getStep() < steps) { + for (int i = 0; i < currentTaskList.length; i++) { + Player player = ObjectUtil.cloneByStream(currentPlayer); + player.setStep(player.getStep() + 1); + Object[] taskList = player.getDemandTaskQueue().toArray(); + DemandTask demandTask = (DemandTask) taskList[i]; + + player.getLogList().clear(); + boolean flag = performTask(demandTask, player); + player.getFinalLogList().addAll(player.getAskLogList()); + player.getFinalLogList().addAll(player.getLogList()); + //System.out.println("任务["+i+"/"+currentTaskList.length+"]:"+demandTask.getName()+"|"+ flag); + //System.out.println("current:"+currentPlayer.getPath()); + //System.out.println("thistep:"+player.getPath()); + + player.setIndex(queue.size()); + player.aStarScore(); + if (flag && player.getScore() > currentPlayer.getScore()) { + player.getFinalTaskList().add(demandTask); + minScore = player.getScore(); + //finalLogList 写入文件 + String filePath = FileUtil.getPath() + "file" + File.separator + "final_log" + File.separator + "final_log_" + player.getIndex() + ".txt"; + FileUtil.writeLog(player.getFinalLogList(), filePath); + + queue.add(player); + player.setPath(player.getPath() + "-" + player.getStep() + "[" + i + "/" + taskList.length + "/" + player.getIndex() + "/" + (double) Math.round(player.getScore() * 10000) / 10000 + "]"); + player.setFather(index); + player.setPrevious(-1); + player.setNext(-1); + /* + if (player.getStep()>=steps){ + player.setScore(0); + } else { + player.setScore(player.getScore()*(steps-player.getStep())); + } + */ + Player node = queue.get(index); + int next = node.getNext(); + //System.out.println("next="+next); + if (next < 0) { + node.setNext(player.getIndex()); + player.setPrevious(node.getIndex()); + //System.out.println(node.getIndex()+"=>"+player.getIndex()); + } else { + while (next >= 0) { + //System.out.println("next1="+next); + Player nextPlayer = queue.get(next); + if (player.getScore() > nextPlayer.getScore()) { + node.setNext(player.getIndex()); + player.setPrevious(node.getIndex()); + player.setNext(next); + nextPlayer.setPrevious(player.getIndex()); + break; + } + node = nextPlayer; + next = node.getNext(); + } + if (next < 0) { + node.setNext(player.getIndex()); + player.setPrevious(node.getIndex()); + } + } + //System.out.println("end task"); + } + if (!endFlag) { + break; + } + //System.out.println("i="+i); + } + } + if (!endFlag) { + break; + } + index = currentPlayer.getNext(); + //System.out.println("index="+index); + } + } + + /** + * 保存任务 + * + * @param demandTaskList 任务列表 + * @param player 玩家 + */ + private static void saveTask(List demandTaskList, Player player) { + for (int i = 0; i < demandTaskList.size(); i++) { + DemandTask demandTask = demandTaskList.get(i); + if (!player.getDemandTaskHashSet().contains(demandTask)) { + demandTask.setStatus(2); + demandTask.setLockStatus(1); + //加入任务队列 + player.getDemandTaskQueue().add(demandTask); + player.getDemandTaskHashSet().add(demandTask); + } + if (!StringUtils.isEmpty(demandTask.getPostTask())) { + findTasks(demandTask.getPostTask(), demandTask.getObject(), player); + } + } + } + +} diff --git b/src/main/java/com/qiwu/inference/auto/enums/ConditionMethod.java a/src/main/java/com/qiwu/inference/auto/enums/ConditionMethod.java new file mode 100644 index 0000000..d4e26c3 --- /dev/null +++ a/src/main/java/com/qiwu/inference/auto/enums/ConditionMethod.java @@ -0,0 +1,112 @@ +package com.qiwu.inference.auto.enums; + +import java.util.Arrays; + +public enum ConditionMethod { + + Task_Condition_1("70001", "2001","下达请喝酒的指令"), + Task_Condition_3("70003", "2999","<确认已完成后置任务>"), + Task_Condition_4("70004", "2002","向NPC打招呼"), + Task_Condition_5("70005", "2003","给钱买古董"), + Task_Condition_6("70006", "2004","给钱买东西(药)"), + Task_Condition_7("70007", "2005","确认获赠金疮药"), + Task_Condition_8("70008", "2006","确认揍了某人"), + Task_Condition_9("70009", "2007","请吃饭的指令"), + Task_Condition_10("70010", "2008","给好处费的指令"), + Task_Condition_11("70011", "2009","挑水指令"), + Task_Condition_12("70012", "2010","钓鱼指令"), + Task_Condition_13("70013", "2011","送货指令"), + Task_Condition_14("70014", "2012","给钱指令"), + Task_Condition_15("70015", "2013","请医生"), + Task_Condition_16("70016", "2014","给钱买茶具"), + Task_Condition_17("70017", "2015","花大价钱喝个痛快"), + Task_Condition_18("70018", "2016","花钱买回钗子"), + Task_Condition_19("70019", "2017","用暴力抢回钗子"), + Task_Condition_20("70020", "2018","追回私吞的款项"), + Task_Condition_21("70021", "2019","探听某人的身家"), + Task_Condition_22("70022", "2020","解救被绑女孩"), + Task_Condition_23("70023", "2021","审问罪犯供出老巢"), + Task_Condition_24("70024", "2022","交出藏宝图"), + Task_Condition_25("70025", "2023","抓捕人犯"), + Task_Condition_26("70026", "2024","购买犯人信息"), + Task_Condition_27("70027", "2025","购买物品完成"), + Task_Condition_28("70028", "2026","大夫出诊完成"), + Task_Condition_29("70029", "2027","寻回物品完成"), + Task_Condition_30("70030", "2028","打探肥羊完成"), + Task_Condition_31("70031", "2029","催账完成"), + Task_Condition_32("70032", "2030","催账"), + Task_Condition_33("70033", "2031","砸场子完成"), + Task_Condition_34("70034", "2032","砸场子"), + Task_Condition_35("70035", "2033","探听隐私完成"), + Task_Condition_36("70036", "2034","探听隐私"), + Task_Condition_37("70037", "2035","试药"), + Task_Condition_38("70038", "2036","证据账本完成"), + Task_Condition_39("70039", "2037","证据账本"), + Task_Condition_40("70040", "2038","证据账本类型2完成"), + Task_Condition_41("70041", "2039","栽赃陷害完成"), + Task_Condition_42("70042", "2040","栽赃陷害类型2完成"), + Task_Condition_43("70043", "2041","帮忙做事完成(通用)"), + Task_Condition_44("70044", "2042","求婚"), + Task_Condition_45("70045", "2043","赌场作弊"), + Task_Condition_46("70046", "2044","展示信物"), + Task_Condition_47("70047", "2045","救人"), + Task_Condition_48("71000", "2098","自动完成任务"), + Task_Condition_49("70501", "2051","谴责乱扔垃圾"), + Task_Condition_50("70502", "2052","谴责抽烟"), + Task_Condition_51("70503", "2053","谴责邋遢"), + Task_Condition_52("70504", "2054","谴责颜值"), + Task_Condition_53("70505", "2055","谴责骂人"), + Task_Condition_54("70506", "2056","谴责完成"), + Task_Condition_55("70507", "2057","打探"), + Task_Condition_56("70508", "2058","打探完成"), + Task_Condition_57("70509", "2059","质问打小报告"), + Task_Condition_58("70510", "2060","质问甩锅"), + Task_Condition_59("70511", "2061","质问完成"), + Task_Condition_60("70512", "2062","买高档耳机"), + Task_Condition_61("70513", "2063","买运动手环"), + Task_Condition_62("70514", "2064","买巧克力"), + Task_Condition_63("70515", "2065","买茶叶"), + Task_Condition_64("70516", "2066","买化妆品"), + Task_Condition_65("70517", "2067","买玩偶"), + Task_Condition_66("70518", "2068","买精致餐具"), + Task_Condition_67("70519", "2069","买感冒药"), + Task_Condition_68("70520", "2070","买红糖"), + Task_Condition_69("70521", "2071","买烟"), + Task_Condition_70("70522", "2072","购买礼品完成"), + Task_Condition_71("70523", "2073","恭维"), + Task_Condition_72("70524", "2074","把柄(偷窃)"), + Task_Condition_73("70525", "2075","把柄(打游戏)"), + Task_Condition_74("70526", "2076","把柄(做兼职)"), + Task_Condition_75("70527", "2077","把柄(泄密)"), + Task_Condition_76("70528", "2078","把柄(早退)"), + Task_Condition_77("70529", "2079","举报"), + Task_Condition_78("70530", "2080","澄清"), + Task_Condition_79("70531", "2081","找到间谍"); + + + private final String id; + private final String methodId; + private final String description; + + ConditionMethod(String id, String methodId, String description){ + this.id =id; + this.methodId = methodId; + this.description = description; + + } + + public static ConditionMethod get(String id) { + return Arrays.stream(values()) + .filter(r -> r.id.equals(id)) + .findFirst().get(); + } + + + public String getMethodId(){ + return this.methodId; + } + + public static void main(String[] args) { + System.out.println(ConditionMethod.get("70001").methodId); + } +} diff --git b/src/main/java/com/qiwu/inference/auto/enums/LevelRange.java a/src/main/java/com/qiwu/inference/auto/enums/LevelRange.java new file mode 100644 index 0000000..bdec6ed --- /dev/null +++ a/src/main/java/com/qiwu/inference/auto/enums/LevelRange.java @@ -0,0 +1,43 @@ +package com.qiwu.inference.auto.enums; + +import java.util.Arrays; + +public enum LevelRange { + + LEVEL_1(0, 10,-5), + LEVEL_2(11, 20,-4), + LEVEL_3(21, 30,-3), + LEVEL_4(31, 30,-2), + LEVEL_5(41, 45,-1), + LEVEL_6(46, 50,0), + LEVEL_7(51, 60,1), + LEVEL_8(61, 70,2), + LEVEL_9(71, 80,3), + LEVEL_10(81, 90,4), + LEVEL_11(91, 100,5); + + private final int min; + private final int max; + private final int val; + + private LevelRange(int min, int max, int val) { + this.min = min; + this.max = max; + this.val = val; + } + + public String getRangeLevel() { + return String.format("%d,%d", min, max); + } + + public static LevelRange get(int val) { + return Arrays.stream(values()) + .filter(r -> val >= r.min && val <= r.max) + .findFirst() + .orElse(null); + } + + public static void main(String[] args) { + System.out.println(LevelRange.get(90).val); + } +} \ No newline at end of file diff --git b/src/main/java/com/qiwu/inference/auto/enums/Operate.java a/src/main/java/com/qiwu/inference/auto/enums/Operate.java new file mode 100644 index 0000000..e1b9046 --- /dev/null +++ a/src/main/java/com/qiwu/inference/auto/enums/Operate.java @@ -0,0 +1,344 @@ +package com.qiwu.inference.auto.enums; + +import java.util.Arrays; + +public enum Operate { + + /** + * 1001 askDisposition + * 请求参数: + * subjectName 人物编号 1 + * type 性格类型 1、2、 3 + * 返回数据: + * 符合阈值要求 反馈ID 反馈文本 + * 100101 线索文本 + * 不符合阈值要求 反馈ID 反馈文本 + * 100102 “我又不认识你,为什么要告诉你?” + * 人物没有这条线索 反馈ID 反馈文本 + * 100103 “不好意思,我不知道” + */ + OPERATE_1("1001", "询问A的性格","askDisposition"), + /** + * 1002 askDisposition + * 请求参数 + * subjectName 人物名称 张三 + * dispositionName 性格名称 随和 + * + * 返回数据: + * + */ + OPERATE_2("1002", "询问A是否是某个性格","askDisposition"), + + /** + * 1003 askRelation + * 请求参数 + * subjectName A人物名称 张三 + * objectName B人物名称 李四 + */ + OPERATE_3("1003", "询问A和B是什么关系","askRelation"), + /** + * 1004 askRelation + * 请求参数 + * subjectName A人物名称 张三 + * objectName B人物名称 李四 + * relationName 关系名称 面缘 + */ + OPERATE_4("1004", "询问A和B是不是某个关系","askRelation"), + /** + * 1005 askRelation + * 请求参数 + * subjectName 人物名称 张三 + * relationName 关系名称 面缘 + */ + OPERATE_5("1005", "询问和A有某个关系的人是谁","askRelation"), + /** + * 1006 askRelation + * 请求参数 + * relationName 关系名称 面缘 + */ + OPERATE_6("1006", "询问谁和谁有某个关系","askRelation"), + /** + * 1007 askBehaviour + * 请求参数 + * subjectName 人物名称 张三 + */ + OPERATE_7("1007", "询问A有过什么行为","askBehaviour"), + /** + * 1008 askBehaviour + * 请求参数 + * subjectName A人物名称 张三 + * objectName B人物名称 李四 + */ + OPERATE_8("1008", "询问A和B有什么行为","askBehaviour"), + /** + * 1009 askBehaviour + * 请求参数 + * subjectName 人物名称 张三 (可以为主体或者客体) + * behaviourName 行为名称 斗殴 + */ + OPERATE_9("1009", "询问A和谁有了某个行为","askBehaviour"), + /** + * 1010 askBehaviour + * 请求参数 + * subjectName 人物名称 张三 (可以为主体或者客体) + * behaviourName 行为名称 斗殴 + */ + OPERATE_10("1010", "询问A有没有发生过某个行为","askBehaviour"), + /** + * 1011 askBehaviour + * 请求参数 + * subjectName A人物名称 张三 + * objectName B人物名称 李四 + * behaviourName 行为名称 斗殴 + */ + OPERATE_11("1011", "询问A和B有没有发生过某个行为","askBehaviour"), + OPERATE_12("1012", "询问A知道/看见了B和C的什么行为",""), + OPERATE_13("1013", "询问A有没有看到B和C发生了某个行为",""), + OPERATE_14("1014", "询问A知道什么行为事件",""), + /** + * 1015 askTask + * 请求参数 + * subjectName 人物名称 张三 + */ + OPERATE_15("1015", "询问A的提升信任度任务","askTask"), + /** + * 1016 askTask + * 请求参数 + * subjectName 人物名称 张三 + */ + OPERATE_16("1016", "询问A的提升威慑度任务","askTask"), + /** + * 1017 askTask + * 请求参数 + * subjectName 人物名称 张三 + * taskName 任务名称 打招呼 + */ + OPERATE_17("1017", "询问A是否有某个提升信任度的任务","askTask"), + /** + * 1018 askTask + * 请求参数 + * subjectName 人物名称 张三 + * taskName 任务名称 打招呼 + */ + OPERATE_18("1018", "询问A是否有某个提升威慑度的任务","askTask"), + /** + * 1019 askTask + * 请求参数 + * subjectName 人物名称 张三 + */ + OPERATE_19("1019", "询问A降低信任度的任务","askTask"), + /** + * 1020 askTask + * 请求参数 + * subjectName 人物名称 张三 + */ + OPERATE_20("1020", "询问A降低威慑度的任务","askTask"), + /** + * 1021 askTask + * 请求参数 + * subjectName 人物名称 张三、 + */ + OPERATE_21("1021", "询问A是否有某个降低信任度的任务","askTask"), + /** + * 1022 askTask + * 请求参数 + * subjectName 人物名称 张三、 + */ + OPERATE_22("1022", "询问A是否有某个降低威慑度的任务","askTask"), + /** + * 1023 askIdentity + * 请求参数 + * subjectName 人物名称 张三 + */ + OPERATE_23("1023", "询问A是什么身份","askIdentity"), + /** + * 1024 askIdentity + * 请求参数 + * subjectName 人物名称 张三 + * identityName 身份名称 张三 + */ + OPERATE_24("1024", "询问A是不是某个身份","askIdentity"), + /** + * 1025 askLocation + * 请求参数 + * subjectName 人物名称 张三 + */ + OPERATE_25("1025", "询问A在哪个场所","askLocation"), + /** + * 1026 askLocation + * 请求参数 + * subjectName 人物名称 张三 + * locationName 场所名称 酒馆 + */ + OPERATE_26("1026", "询问A是不是在某个场所","askLocation"), + + /** + * 1027 askPrompt + * 请求参数 + * subjectName 人物名称 张三 + */ + OPERATE_27("1027", "询问提示","askPrompt"), + /** + * 2001 performTask + * 请求参数 + * subjectName 人物名称 李四 + * taskConditionId 任务条件ID 70001 + */ + OPERATE_28("2001", "饮酒","performTask"), + /** + * 2002 performTask + * 请求参数 + * subjectName 人物名称 李四 + * taskConditionId 任务条件ID 70004 + */ + OPERATE_29("2002", "打招呼","performTask"), + /** + * 2003 performTask + * 请求参数 + * subjectName A人物名称 李四 + * taskConditionId 任务条件ID 70004 + */ + OPERATE_30("2003", "买古董","performTask"), + /** + * 2004 performTask + * 请求参数 + * subjectName A人物名称 李四 + * taskConditionId 任务条件ID 70005 + */ + OPERATE_31("2004", "买药","performTask"), + /** + * 2005 performTask + * 请求参数 + * subjectName 人物名称 李四 + * taskConditionId 任务条件ID 70006 + */ + OPERATE_32("2005", "获赠金疮药","performTask"), + /** + * 2006 performTask + * 请求参数 + * subjectName 人物名称 李四 + * taskConditionId 任务条件ID 70007 + */ + OPERATE_33("2006", "揍人","performTask"), + /** + * 2007 performTask + * 请求参数 + * subjectName 人物名称 李四 + * taskConditionId 任务条件ID 70008 + */ + OPERATE_34("2007", "请吃饭","performTask"), + /** + * 2008 performTask + * 请求参数 + * subjectName 人物名称 李四 + * taskConditionId 任务条件ID 70009 + */ + OPERATE_35("2008", "好处费","performTask"), + /** + * 2009 performTask + * 请求参数 + * subjectName A人物名称 李四 + * taskConditionId 任务条件ID 70010 + */ + OPERATE_36("2009", "帮挑水","performTask"), + /** + * 2010 performTask + * 请求参数 + * subjectName A人物名称 李四 + * taskConditionId 任务条件ID 70011 + */ + OPERATE_37("2010", "一起钓鱼","performTask"), + /** + * 2011 performTask + * 请求参数 + * subjectName A人物名称 李四 + * taskConditionId 任务条件ID 70012 + */ + OPERATE_38("2011", "送货","performTask"), + /** + * 2012 performTask + * 请求参数 + * subjectName A人物名称 李四 + * taskConditionId 任务条件ID 70013 + */ + OPERATE_39("2012", "给钱","performTask"), + /** + * 2013 performTask + * 请求参数 + * subjectName A人物名称 李四 + * taskConditionId 任务条件ID 70014 + */ + OPERATE_40("2013", "邀请医生","performTask"), + /** + * 2014 performTask + * 请求参数 + * subjectName A人物名称 李四 + * taskConditionId 任务条件ID 70015 + */ + OPERATE_41("2014", "给钱买药","performTask"), + /** + * 2015 performTask + * 请求参数 + * subjectName A人物名称 李四 + * taskConditionId 任务条件ID 70016 + */ + OPERATE_42("2015", "开怀畅饮","performTask"), + /** + * 2016 performTask + * 请求参数 + * subjectName A人物名称 李四 + * taskConditionId 任务条件ID 70017 + */ + OPERATE_43("2016", "买回钗子","performTask"), + /** + * 2017 performTask + * 请求参数 + * subjectName A人物名称 李四 + * taskConditionId 任务条件ID 70018 + */ + OPERATE_44("2017", "抢回钗子","performTask"), + /** + * 2018 performTask + * 请求参数 + * subjectName A人物名称 李四 + * taskConditionId 任务条件ID 70019 + */ + OPERATE_45("2018", "追回私吞款项","performTask"), + /** + * 2019 performTask + * 请求参数 + * subjectName 人物名称 李四 + * taskConditionId 任务条件ID 70020 + */ + OPERATE_46("2019", "探听身家","performTask"), + + /** + * 2999 performTask + * 请求参数 + * subjectName 人物名称 李四 + * taskConditionId 任务条件ID 70003 + */ + OPERATE_47("2999", "触发后置任务","performTask"); + + private final String id; + private final String operateName; + private final String operate; + + private Operate(String id,String operateName,String operate){ + this.id =id; + this.operateName = operateName; + this.operate = operate; + + } + + public static Operate get(String id) { + return Arrays.stream(values()) + .filter(r -> r.id.equals(id)) + .findFirst().get(); + } + + + public static void main(String[] args) { + System.out.println(Operate.get("1002").operate); + } +} diff --git b/src/main/java/com/qiwu/inference/auto/enums/TaskCondition.java a/src/main/java/com/qiwu/inference/auto/enums/TaskCondition.java new file mode 100644 index 0000000..4fe07c8 --- /dev/null +++ a/src/main/java/com/qiwu/inference/auto/enums/TaskCondition.java @@ -0,0 +1,51 @@ +package com.qiwu.inference.auto.enums; + +import java.util.Arrays; + +public enum TaskCondition { + + Task_Condition_1("70001", "饮酒","下达请喝酒的指令"), + Task_Condition_2("70002", "买药(备用)","下达买药指令并完成"), + Task_Condition_3("70003", "后置任务","<确认已完成后置任务>"), + Task_Condition_4("70004", "打招呼","向NPC打招呼"), + Task_Condition_5("70005", "买古董","给钱买古董"), + Task_Condition_6("70006", "给钱买药","给钱买东西(药)"), + Task_Condition_7("70007", "获赠金疮药","确认获赠金疮药"), + Task_Condition_8("70008", "揍人","确认揍了某人"), + Task_Condition_9("70009", "请吃饭","请吃饭的指令"), + Task_Condition_10("70010", "好处费","给好处费的指令"), + Task_Condition_11("70011", "帮挑水","挑水指令"), + Task_Condition_12("70012", "一起钓鱼","钓鱼指令"), + Task_Condition_13("70013", "送货","送货指令"), + Task_Condition_14("70014", "给钱","给钱指令"), + Task_Condition_15("70015", "邀请医生","请医生"), + Task_Condition_16("70016", "给钱买茶具","给钱买茶具"), + Task_Condition_17("70017", "开怀畅饮","花大价钱喝个痛快"), + Task_Condition_18("70018", "买回钗子","花钱买回钗子"), + Task_Condition_19("70019", "抢回钗子","用暴力抢回钗子"), + Task_Condition_20("70020", "追回私吞款项","追回私吞的款项"), + Task_Condition_21("70021", "探听身家","探听某人的身家"); + + + private final String id; + private final String taskName; + private final String description; + + private TaskCondition(String id, String taskName, String description){ + this.id =id; + this.taskName = taskName; + this.description = description; + + } + + public static TaskCondition get(String taskName) { + return Arrays.stream(values()) + .filter(r -> r.taskName.equals(taskName)) + .findFirst().get(); + } + + + public static void main(String[] args) { + System.out.println(TaskCondition.get("买药(备用)").id); + } +} diff --git b/src/main/java/com/qiwu/inference/auto/enums/TaskMethod.java a/src/main/java/com/qiwu/inference/auto/enums/TaskMethod.java new file mode 100644 index 0000000..1f61411 --- /dev/null +++ a/src/main/java/com/qiwu/inference/auto/enums/TaskMethod.java @@ -0,0 +1,53 @@ +package com.qiwu.inference.auto.enums; + +import java.util.Arrays; + +public enum TaskMethod { + + TASK_METHOD_1("2001", "饮酒","下达请喝酒的指令"), + TASK_METHOD_4("2002", "打招呼","向NPC打招呼"), + TASK_METHOD_5("2003", "买古董","给钱买古董"), + TASK_METHOD_6("2004", "买药","给钱买东西(药)"), + TASK_METHOD_7("2005", "获赠金疮药","确认获赠金疮药"), + TASK_METHOD_8("2006", "揍人","确认揍了某人"), + TASK_METHOD_9("2007", "请吃饭","请吃饭的指令"), + TASK_METHOD_10("2008", "好处费","给好处费的指令"), + TASK_METHOD_11("2009", "帮挑水","挑水指令"), + TASK_METHOD_12("2010", "一起钓鱼","钓鱼指令"), + TASK_METHOD_13("2011", "送货","送货指令"), + TASK_METHOD_14("2012", "给钱","给钱指令"), + TASK_METHOD_15("2013", "邀请医生","请医生"), + TASK_METHOD_16("2014", "给钱买茶具","给钱买茶具"), + TASK_METHOD_17("2015", "开怀畅饮","花大价钱喝个痛快"), + TASK_METHOD_18("2016", "买回钗子","花钱买回钗子"), + TASK_METHOD_19("2017", "抢回钗子","用暴力抢回钗子"), + TASK_METHOD_20("2018", "追回私吞款项","追回私吞的款项"), + TASK_METHOD_21("2019", "探听身家","探听某人的身家"); + + + private final String id; + private final String taskName; + private final String description; + + private TaskMethod(String id, String taskName, String description){ + this.id =id; + this.taskName = taskName; + this.description = description; + + } + + public String getId(){ + return this.id; + } + + public static TaskMethod get(String taskName) { + return Arrays.stream(values()) + .filter(r -> r.taskName.equals(taskName)) + .findFirst().get(); + } + + + public static void main(String[] args) { + System.out.println(TaskMethod.get("买药(备用)").id); + } +} diff --git b/src/main/java/com/qiwu/inference/auto/pojo/Behaviour.java a/src/main/java/com/qiwu/inference/auto/pojo/Behaviour.java new file mode 100644 index 0000000..84d0d4e --- /dev/null +++ a/src/main/java/com/qiwu/inference/auto/pojo/Behaviour.java @@ -0,0 +1,48 @@ +package com.qiwu.inference.auto.pojo; + +import lombok.Getter; +import lombok.Setter; + +import java.io.Serializable; + + +@Getter +@Setter +public class Behaviour implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * id + */ + private Integer id; + /** + * 行为名称 + */ + private String name; + /** + * 行为id + */ + private int behaviourId; + /** + * 行为描述 + */ + private String description; + /** + * 主体 + */ + private int subject; + /** + * 主体名称 + */ + private String subjectName; + /** + * 客体 + */ + private int object; + /** + * 客体名称 + */ + private String objectName; + +} diff --git b/src/main/java/com/qiwu/inference/auto/pojo/Clue.java a/src/main/java/com/qiwu/inference/auto/pojo/Clue.java new file mode 100644 index 0000000..416c5cd --- /dev/null +++ a/src/main/java/com/qiwu/inference/auto/pojo/Clue.java @@ -0,0 +1,91 @@ +package com.qiwu.inference.auto.pojo; + +import lombok.Getter; +import lombok.Setter; + +import java.io.Serializable; +import java.util.Objects; + + +@Getter +@Setter +public class Clue implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * id + */ + private Integer id; + + /** + * 线索id + */ + private int clueId; + + /** + * 线索名称 + */ + private String clueName; + + /** + * 主体 + */ + private int subject; + /** + * 客体 + */ + private int object; + /** + * 描述 + */ + private String description; + /** + * 类型: 1:身份 2:场所 3:性格爱好 4:行为 5:关系 6:任务 9: 关键线索 + */ + private int type; + /** + * 信息级别 + */ + private int infoLevel; + /** + * 关联人物 + */ + private int associatedPerson; + /** + * 线索模板 + */ + private String clueTemplate; + + /** + * 信任度 + */ + private int trustDegree=100; + + /** + * 威胁度 + */ + private int deterrenceDegree=100; + + /** + * 1 表示不满足阈值条件 2表示满足阈值 3表示可以解锁任务 + */ + private int status=1; + + + //private DemandTask demandTask; + + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Clue clue = (Clue) o; + return Objects.equals(id, clue.id) && clueId == clue.clueId && subject == clue.subject && clueName.equals(clue.clueName); + } + + @Override + public int hashCode() { + return Objects.hash(id, clueId, clueName, subject); + } +} diff --git b/src/main/java/com/qiwu/inference/auto/pojo/DemandTask.java a/src/main/java/com/qiwu/inference/auto/pojo/DemandTask.java new file mode 100644 index 0000000..f66f1a6 --- /dev/null +++ a/src/main/java/com/qiwu/inference/auto/pojo/DemandTask.java @@ -0,0 +1,186 @@ +package com.qiwu.inference.auto.pojo; + +import cn.hutool.core.clone.CloneSupport; +import lombok.Getter; +import lombok.Setter; + +import java.io.Serializable; +import java.util.Objects; + + +@Getter +@Setter +public class DemandTask extends CloneSupport implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * id + */ + private Integer id; + + /** + * demandTaskId + */ + private int demandTaskId; + + /** + * 名称 + */ + private String name; + + /** + * 任务组 + */ + private int taskGroup; + + /** + * 描述 + */ + private String description; + + /** + * 主体 + */ + private int subject; + + /** + * 客体 + */ + private int object; + + /** + * 开启条件信任度的开始 + */ + private int trustStart=100; + + /** + * 开启条件信任度的结束 + */ + private int trustEnd=100; + + /** + * 开启条件威胁度的开始 + */ + private int deterrenceStart=100; + + /** + * 开启条件威胁度的结束 + */ + private int deterrenceEnd=100; + + /** + * 后置任务 + */ + private String postTask; + + /** + * 条件1|次数 + */ + private String condition1; + + /** + * 条件2|次数 + */ + private String condition2; + + /** + * 信任度增减 + */ + private int trustDegree; + + /** + * 威慑度增减 + */ + private int deterrenceDegree; + + /** + * 完成奖励 + */ + private String completionReward; + + /** + * 声望增减 + */ + private int reputation; + + /** + * 有效次数 + */ + private int effectiveDegree; + + /** + * 类型: 1:身份 2:场所 3:性格爱好 4:行为 5:关系 6:任务 9:关键线索 + */ + private int type; + + /** + * 线索id + */ + private int clueId; + + /** + * 信息级别 + */ + private int infoLevel; + + /** + * 任务标签 1普通任务 2关键任务 3 目标任务 + */ + private int taskLabel; + + /** + * 线索开关 0 代表不需要线索就可执行,1 代表需要线索才能执行此任务 + */ + private int clueSwitch; + + /** + * 自动触发 + */ + private int isAuto; + + /** + * 1 表示没有解锁 2 表示解锁了未执行 3 表示满足阈值已经执行 + */ + private int status=1; + + /** + * 0 表示未解锁 1 表示已经解锁 + */ + private int lockStatus=0; + + /** + * 线索解锁的概率占比 + */ + private double clueProb=0.0; + + /** + * 0 表示不满足阈值 1 表示满足阈值 + */ + private int thresholdStatus=0; + + /** + * 任务解锁的概率占比 + */ + private double thresholdProb=0.0; + + /** + * 0 表示后置任务没有执行 1 表示后置任务已经执行 + */ + private int postTaskStatus=0; + + //private Clue clue; + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + DemandTask demandTask = (DemandTask) o; + return Objects.equals(id, demandTask.id) && demandTaskId == demandTask.demandTaskId && subject == demandTask.subject && type == demandTask.type && clueId == demandTask.clueId && name.equals(demandTask.name); + } + + @Override + public int hashCode() { + return Objects.hash(id, demandTaskId, name, subject, type, clueId); + } +} diff --git b/src/main/java/com/qiwu/inference/auto/pojo/Disposition.java a/src/main/java/com/qiwu/inference/auto/pojo/Disposition.java new file mode 100644 index 0000000..56368ef --- /dev/null +++ a/src/main/java/com/qiwu/inference/auto/pojo/Disposition.java @@ -0,0 +1,40 @@ +package com.qiwu.inference.auto.pojo; + +import lombok.Getter; +import lombok.Setter; + +import java.io.Serializable; + + +@Getter +@Setter +public class Disposition implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * id + */ + private Integer id; + /** + * 性格id + */ + private int dispositionId; + /** + * 人物id + */ + private int subject; + /** + * 性格名称 + */ + private String name; + /** + * 性格描述 + */ + private String description; + /** + * 类型 + */ + private String type; + +} diff --git b/src/main/java/com/qiwu/inference/auto/pojo/Person.java a/src/main/java/com/qiwu/inference/auto/pojo/Person.java new file mode 100644 index 0000000..cc89733 --- /dev/null +++ a/src/main/java/com/qiwu/inference/auto/pojo/Person.java @@ -0,0 +1,111 @@ +package com.qiwu.inference.auto.pojo; + +import cn.hutool.core.clone.CloneSupport; +import lombok.Getter; +import lombok.Setter; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + + +@Getter +@Setter +public class Person extends CloneSupport implements Serializable { + + /** + * 人物编号 + */ + private Integer id; + + /** + * 人物名称 + */ + private String name; + + /** + * 身份id + */ + private int identityId; + + /** + * 身份名称 + */ + private String identityName; + + /** + * 年龄 + */ + private int age; + + /** + * 是否为关键人物 1 关键人物 2 普通人物 + */ + private int isKey; + + /** + * 性别 + */ + private int gender; + + /** + * 所在地 + */ + private int location; + + /** + * 人物拥有的性格 + */ + private List dispositions; + + /** + * 人物拥有的关系 + */ + private List relations; + + /** + * 人物拥有的行为 + */ + private List behaviours; + + /** + * 人物掌握的线索集合 + */ + private List clues; + + /** + * 人物的需求任务集合 + */ + private List demandTasks; + + /** + * 信任度 + */ + private int trustDegree = 50; + + /** + * 威胁 + */ + private int deterrenceDegree = 50; + + /** + * 他指向的点的集合 + */ + private ArrayList nexts = new ArrayList<>(); + + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Person person = (Person) o; + return Objects.equals(id, person.id) && name.equals(person.name) && identityId==person.identityId && identityName.equals(person.identityName) && age==person.age && isKey==(person.isKey) && gender==person.gender && location==person.location; + } + + @Override + public int hashCode() { + return Objects.hash(id, name, identityId, identityName, age, isKey, gender, location); + } + +} diff --git b/src/main/java/com/qiwu/inference/auto/pojo/Player.java a/src/main/java/com/qiwu/inference/auto/pojo/Player.java new file mode 100644 index 0000000..6a1aedf --- /dev/null +++ a/src/main/java/com/qiwu/inference/auto/pojo/Player.java @@ -0,0 +1,512 @@ +package com.qiwu.inference.auto.pojo; + +import cn.hutool.core.clone.CloneSupport; +import com.qiwu.inference.util.FastJsonUtil; +import com.qiwu.inference.util.FileUtil; +import com.qiwu.inference.util.RandomUtil; +import lombok.Getter; +import lombok.Setter; +import org.springframework.util.StringUtils; + +import java.io.*; +import java.util.*; + +@Getter +@Setter +public class Player extends CloneSupport implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 关卡编号 + */ + private String gateNo; + /** + * 保存所有人物 + */ + Map personMap = new HashMap<>(); + + Map>> relationsMap = new HashMap<>(); + + Map name2IdMap = new HashMap<>(); + + + Queue demandTaskQueue = new LinkedList<>(); + HashSet demandTaskHashSet = new HashSet<>(); + + private List logList = new ArrayList<>(); + private List askLogList = new ArrayList<>(); + private List finalLogList = new ArrayList<>(); + private List treeLogList = new ArrayList<>(); + + private List finalTaskList = new ArrayList<>(); + + + /** + * 玩家当前对话的人物 + */ + private Integer personId; + + + /** + * 货币 + */ + private double currency = 1000.0; + + private Map> taskMap = new HashMap<>(); + + private int index = -1; + private int next = -1; + private int previous = -1; + private int father = -1; + private double score = 0; + private String path=""; + private int step = 0; + + /** + * 初始人物的阈值 + */ + Map> initMap = new HashMap<>(); + + public Player(){ + String filePath = FileUtil.getPath() + "file" + File.separator +"results.json"; + String jsonStr=readJson(filePath); + Map map = FastJsonUtil.parseJSON2Map(jsonStr); + List keys = new ArrayList(map.keySet()); + int index = RandomUtil.randomInt(keys.size()); + String personListStr = map.get(keys.get(index)); + this.setGateNo(keys.get(index)); + List personList = FastJsonUtil.json2List(personListStr, Person.class); + assert personList != null; + for (Person person:personList){ + this.getPersonMap().put(person.getId(),person); + List temp = new ArrayList<>(); + temp.add(person.getTrustDegree()); + temp.add(person.getDeterrenceDegree()); + this.initMap.put(person.getId(),temp); + this.getName2IdMap().put(person.getName(),person.getId()); + this.getTaskMap().put(person.getId(),new HashMap<>()); + } + for(Person person:this.getPersonMap().values()){ + for (Relation relation:person.getRelations()){ + if(this.getRelationsMap().containsKey(relation.getSubject())){ + Map> relationsMap=this.getRelationsMap().get(relation.getSubject()); + if(relationsMap.containsKey(relation.getRelationId())){ + List list = relationsMap.get(relation.getRelationId()); + list.add(relation.getObject()); + relationsMap.put(relation.getRelationId(),list); + }else{ + List list = new ArrayList<>(); + list.add(relation.getObject()); + relationsMap.put(relation.getRelationId(),list); + } + this.getRelationsMap().put(relation.getSubject(),relationsMap); + }else{ + Map> relationsMap = new HashMap<>(); + List list = new ArrayList<>(); + list.add(relation.getObject()); + relationsMap.put(relation.getRelationId(),list); + this.getRelationsMap().put(relation.getSubject(),relationsMap); + } + if(!Objects.equals(person.getId(), relation.getObject())){ + if(!person.getNexts().contains(this.getPersonMap().get(relation.getObject()))){ + person.getNexts().add(this.getPersonMap().get(relation.getObject())); + } + } + } + + + //线索查找相关的任务 +// for (Clue clue :person.getClues()){ +// DemandTask demandTask = findTask(person.getDemandTasks(),clue); +// if(!StringUtils.isEmpty(demandTask)){ +// clue.setDemandTask(demandTask); +// } +// } + //任务查找相关的线索 +// for (DemandTask demandTask :person.getDemandTasks()){ +// Clue clue = findClue(person.getClues(),demandTask); +// if(!StringUtils.isEmpty(clue)){ +// demandTask.setClue(clue); +// } +// } + + } + } + + /** + * 根据任务查询符合条件的线索 + */ + private Clue findClue(List clueList,DemandTask demandTask){ + for (Clue clue : clueList) { + if (clue.getType() == demandTask.getType() && clue.getClueId() == demandTask.getClueId() && clue.getSubject() == demandTask.getSubject()) { + return clue; + } + } + return null; + } + + /** + * 根据线索查询符合条件的任务 + * @param demandTaskList 任务列表 + * @param clue 线索 + * @return 任务 + */ + private DemandTask findTask(List demandTaskList ,Clue clue){ + DemandTask result = null; + for (DemandTask demandTask : demandTaskList) { + if (demandTask.getClueId() == clue.getClueId() && demandTask.getType() == clue.getType()) { + result = demandTask; + break; + } + } + if(!StringUtils.isEmpty(result)){ + for (DemandTask demandTask:demandTaskList){ + if(demandTask.getDemandTaskId()==result.getDemandTaskId()&&demandTask.getType()==6&&result.getSubject()==demandTask.getSubject()){ + return demandTask; + } + } + } + return null; + } + + public double aStarScore() throws Exception{ + score = 0; + List demandTaskSet = new ArrayList<>(); + int depth=1; + DemandTask demandTask = this.findKeyTask_(); + demandTaskSet.add(demandTask); +// if (demandTask.getStatus()==3){ +// //System.out.print("*"); +// } + //System.out.println(demandTask.getName()+"("+getPersonMap().get(demandTask.getSubject()).getName()+")"+"="+1+"/"+this.score); + //计算每个任务和每条线索的概率 + getTaskAndCluePro(); + //Tree 结构写入文件 之前的文件内容要清空 + String filePath = FileUtil.getPath() + "file" + File.separator+"tree_log"+File.separator+"tree_log_"+this.getIndex()+".txt"; + treeLogList.clear(); + this.dfs(demandTask,demandTaskSet,depth,1); + if(treeLogList.size()>0){ + FileUtil.writeLog(treeLogList,filePath); + } + /* + if (this.getStep()>= DFS.steps){ + this.setScore(0); + } else { + this.setScore(this.getScore()*(DFS.steps-this.getStep())/DFS.steps); + } + + */ + return score; + } + + public void getTaskAndCluePro(){ + Set demandTaskSet = new HashSet<>(); + for (Person person:this.personMap.values()){ + demandTaskSet.addAll(person.getDemandTasks()); + } + double temp= 0.0; + for (DemandTask demandTask:demandTaskSet){ + if(demandTask.getType()==6){ + //查询任务对应的线索 + Set clueSet=this.findClue(demandTask); + double cluePro = 0.0; + for (Clue clue:clueSet){ + //查询线索相关的人物 + List personList=this.getPerson(clue); + for (Person person:personList){ + int initTrustDegree=this.getInitMap().get(person.getId()).get(0); + int initDeterrenceDegree=this.getInitMap().get(person.getId()).get(1); + double tempTrustDegreeProb=0.0; + if((clue.getTrustDegree()-initTrustDegree) > 0){ + tempTrustDegreeProb=(double)(person.getTrustDegree()-initTrustDegree)/(double)(clue.getTrustDegree()-initTrustDegree); + }else if(person.getTrustDegree()>=clue.getTrustDegree()){ + tempTrustDegreeProb=1.0; + } + double tempDeterrenceDegreeProb=0.0; + if((clue.getDeterrenceDegree()-initDeterrenceDegree) > 0){ + tempDeterrenceDegreeProb=(double)(person.getDeterrenceDegree()-initDeterrenceDegree)/(double)(clue.getDeterrenceDegree()-initDeterrenceDegree); + }else if(person.getDeterrenceDegree()>=clue.getDeterrenceDegree()){ + tempDeterrenceDegreeProb=1.0; + } + temp=Math.max(tempTrustDegreeProb,tempDeterrenceDegreeProb); + cluePro = Math.max(cluePro,temp); + } + } + cluePro = Math.min(cluePro, 1.0); + demandTask.setClueProb(cluePro); + + Person person = this.getPersonMap().get(demandTask.getSubject()); + if(demandTask.getTrustStart()<= person.getTrustDegree()||demandTask.getDeterrenceStart()<=person.getDeterrenceDegree()){ + demandTask.setThresholdStatus(1); + } + + int initTrustDegree=this.getInitMap().get(person.getId()).get(0); + int initDeterrenceDegree=this.getInitMap().get(person.getId()).get(1); + double tempTrustDegreeProb=0.0; + if (demandTask.getTrustStart()>=100){ + + } else if((demandTask.getTrustStart()-initTrustDegree) > 0){ + tempTrustDegreeProb=(double)(person.getTrustDegree()-initTrustDegree)/(double)(demandTask.getTrustStart()-initTrustDegree); + } else if (person.getTrustDegree()>=demandTask.getTrustStart()){ + tempTrustDegreeProb = 1.0; + } + double tempDeterrenceDegreeProb=0.0; + if (demandTask.getDeterrenceStart()>=100){ + + } else if((demandTask.getDeterrenceStart()-initDeterrenceDegree) > 0){ + tempDeterrenceDegreeProb=(double)(person.getDeterrenceDegree()-initDeterrenceDegree)/(double)(demandTask.getDeterrenceStart()-initDeterrenceDegree); + } else if (person.getDeterrenceDegree()>=demandTask.getDeterrenceStart()){ + tempDeterrenceDegreeProb = 1.0; + } + temp = Math.max(tempTrustDegreeProb,tempDeterrenceDegreeProb); + demandTask.setThresholdProb(Math.min(temp, 1.0)); + } + } + } + + /** + * 查找关键任务 + * @return 任务 + */ + public DemandTask findKeyTask_(){ + Set demandTaskSet = new HashSet<>(); + for (Person person:this.personMap.values()){ + demandTaskSet.addAll(person.getDemandTasks()); + } + Object[] demandTasks = demandTaskSet.toArray(); + for (Object task : demandTasks) { + DemandTask demandTask = (DemandTask) task; + if (demandTask.getTaskLabel() == 3 && demandTask.getType() == 6) {//关键任务 + return demandTask; + } + } + return null; + } + + /** + * 查找后置任务 + * @return 任务 + */ + public DemandTask findPostTask(DemandTask demandTask){ + Set demandTaskSet = new HashSet<>(); + for (Person person:this.personMap.values()){ + if(demandTask.getType()==6){ + demandTaskSet.addAll(person.getDemandTasks()); + } + } + Object[] demandTasks = demandTaskSet.toArray(); + + for (Object task : demandTasks) { + DemandTask temp = (DemandTask) task; + String[] postTasks = demandTask.getPostTask().split("\\|"); + for (String postTask : postTasks) { + if (temp.getDemandTaskId() == Integer.parseInt(postTask) && temp.getSubject() == demandTask.getObject()) { + return temp; + } + } + + } + return null; + } + + /** + * 查询任务对应的线索 + * @param demandTask + * @return + */ + public Set findClue(DemandTask demandTask){ + Set clueSet = new HashSet<>(); + for (Person person:personMap.values()){ + if(person.getId()!=demandTask.getSubject()){ + for (Clue clue:person.getClues()){ + if(clue.getClueId()==demandTask.getClueId()){ + clueSet.add(clue); + } + } + } + } + return clueSet; + } + + + public void dfs(DemandTask root,List demandTaskSet,int depth,double weight) throws Exception{ + if(root==null){ + //System.out.println("深度优先回溯"); + return; + } + + if (root.getStatus()==3){ + this.score+=weight; + return; + } +// if(root.getLockStatus()==1&&root.getThresholdStatus()==1&&root.getPostTaskStatus()==1&&weight==1){ +// //System.out.print(""); +// } + if(demandTaskSet.contains(root)){ + //demandTaskSet.add(root); + + //查询关键任务相对应的线索 +// for (Clue clue:findClue(root)){ +//// if(!clueSet.contains(clue)){ +//// clueSet.add(clue); +//// } +// } + + List demandTaskNextSet = new ArrayList(); + demandTaskNextSet.addAll(demandTaskSet); + double taskWeight = 0; + //查询可以提升自己阈值的任务 + Person person = personMap.get(root.getSubject()); + List demandTaskBaseList = person.getDemandTasks(); + List demandTaskList = new ArrayList<>(); + + if (root.getThresholdStatus()==0){ + taskWeight+=0.3*(1-root.getThresholdProb()); + this.score+=weight*0.3*root.getThresholdProb(); + for (DemandTask demandTask:demandTaskBaseList){ + if (demandTask.getType()==6&&!demandTaskNextSet.contains(demandTask)){ + if ((demandTask.getTrustStart() relatedPersons=getPerson(clue); + for (Person relatedPerson:relatedPersons){ + List relatedTaskBaseList = relatedPerson.getDemandTasks(); +// List relatedTaskList = new ArrayList(); + for (DemandTask relatedTask:relatedTaskBaseList){ + if (relatedTask.getType()==6&&!demandTaskNextSet.contains(relatedTask)){ + if ((relatedTask.getTrustStart()0||root.getDeterrenceDegree()>0){ + String temp=""; + for (int j=0;j0||root.getDeterrenceDegree()>0){ + String temp=""; + for (int j=0;j getPerson(Clue clue){ + List personList = new ArrayList<>(); + for(Integer key:personMap.keySet()){ + if(clue.getSubject()!=key){ + Person person = personMap.get(key); + for(Clue c:person.getClues()){ + if(c.equals(clue)){ + personList.add(person); + } + } + } + } + return personList; + } + + /** + * 读取json文件数据 + * @param jsonPath json文件路径 + * @return 字符串 + */ + private static String readJson(String jsonPath) { + File jsonFile = new File(jsonPath); + try { + FileReader fileReader = new FileReader(jsonFile); + BufferedReader reader = new BufferedReader(fileReader); + StringBuilder sb = new StringBuilder(); + while (true) { + int ch = reader.read(); + if (ch != -1) { + sb.append((char) ch); + } else { + break; + } + } + fileReader.close(); + reader.close(); + return sb.toString(); + } catch (IOException e) { + return ""; + } + } +} diff --git b/src/main/java/com/qiwu/inference/auto/pojo/Player_bak.java a/src/main/java/com/qiwu/inference/auto/pojo/Player_bak.java new file mode 100644 index 0000000..7f7715b --- /dev/null +++ a/src/main/java/com/qiwu/inference/auto/pojo/Player_bak.java @@ -0,0 +1,304 @@ +package com.qiwu.inference.auto.pojo; + +import cn.hutool.core.clone.CloneSupport; +import com.qiwu.inference.util.FastJsonUtil; +import com.qiwu.inference.util.FileUtil; +import com.qiwu.inference.util.RandomUtil; +import lombok.Getter; +import lombok.Setter; +import org.springframework.util.StringUtils; + +import java.io.*; +import java.util.*; + +@Getter +@Setter +public class Player_bak extends CloneSupport implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 关卡编号 + */ + private String gateNo; + /** + * 保存所有人物 + */ + Map personMap = new HashMap<>(); + + Map>> relationsMap = new HashMap<>(); + + Map name2IdMap = new HashMap<>(); + + Queue demandTaskQueue = new LinkedList<>(); + HashSet demandTaskHashSet = new HashSet<>(); + + private List logList = new ArrayList<>(); + private List askLogList = new ArrayList<>(); + private List finalLogList = new ArrayList<>(); + /** + * 玩家当前对话的人物 + */ + private Integer personId; + + + /** + * 货币 + */ + private Double currency = 1000.0; + + private Map> taskMap = new HashMap<>(); + + private int index = -1; + private int next = -1; + private int previous = -1; + private int father = -1; + private int score = 0; + private String path=""; + private int step = 0; + + /** + * 初始人物的阈值 + */ + Map> initMap = new HashMap<>(); + + public Player_bak(){ + String filePath = FileUtil.getPath() + "file" + File.separator +"results.json"; + String jsonStr=readJson(filePath); + Map map = FastJsonUtil.parseJSON2Map(jsonStr); + List keys = new ArrayList(map.keySet()); + int index = RandomUtil.randomInt(keys.size()); + String personListStr = map.get(keys.get(index)); + this.setGateNo(keys.get(index)); + List personList = FastJsonUtil.json2List(personListStr, Person.class); + for (Person person:personList){ + this.getPersonMap().put(person.getId(),person); + List temp = new ArrayList<>(); + temp.add(person.getTrustDegree()); + temp.add(person.getDeterrenceDegree()); + this.initMap.put(person.getId(),temp); + this.getName2IdMap().put(person.getName(),person.getId()); + this.getTaskMap().put(person.getId(),new HashMap<>()); + } + for(Person person:this.getPersonMap().values()){ + for (Relation relation:person.getRelations()){ + if(this.getRelationsMap().containsKey(relation.getSubject())){ + Map> relationsMap=this.getRelationsMap().get(relation.getSubject()); + if(relationsMap.containsKey(relation.getRelationId())){ + List list = relationsMap.get(relation.getRelationId()); + list.add(relation.getObject()); + relationsMap.put(relation.getRelationId(),list); + }else{ + List list = new ArrayList<>(); + list.add(relation.getObject()); + relationsMap.put(relation.getRelationId(),list); + } + this.getRelationsMap().put(relation.getSubject(),relationsMap); + }else{ + Map> relationsMap = new HashMap<>(); + List list = new ArrayList<>(); + list.add(relation.getObject()); + relationsMap.put(relation.getRelationId(),list); + this.getRelationsMap().put(relation.getSubject(),relationsMap); + } + if(!Objects.equals(person.getId(), relation.getObject())){ + if(!person.getNexts().contains(this.getPersonMap().get(relation.getObject()))){ + person.getNexts().add(this.getPersonMap().get(relation.getObject())); + } + } + } + } + } + + /** + * A*评估函数 + */ + public int aStarScore(){ + score = 0; + //为每个人打分 + Set demandTasksSet = findKeyTask(); + Map weightMap = new HashMap<>(); + getPersonScore(weightMap,65536,demandTasksSet); + //完成度 + Map clueMap=getProb(); + for (Integer key:weightMap.keySet()){ + int characterScore =(int)(clueMap.get(key)*weightMap.get(key)); + score+=characterScore; + //System.out.println("score["+personMap.get(key).getName()+"]=("+(clueMap.get(key))+")*"+weightMap.get(key)+"="+characterScore); + } + //System.out.println("score="+score); + if (score>=1024){ + //System.out.println("---"); + } + return score; + } + + /** + * 查找关键任务 + * @return + */ + public Set findKeyTask(){ + Set result = new HashSet<>(); + Set demandTaskSet = new HashSet<>(); + for (Person person:this.personMap.values()){ + demandTaskSet.addAll(person.getDemandTasks()); + } + Object[] demandTasks = demandTaskSet.toArray(); + for (int i=0;i getProb(){ + Map result = new HashMap<>(); + for (Integer key:personMap.keySet()){ + Person person = personMap.get(key); + int trustDegreeNumerator =0; + int trustDegreeDenominator =0; + int deterrenceDegreeNumerator =0; + int deterrenceDegreeDenominator =0; + + List clueList = personMap.get(key).getClues(); + for (Clue clue:clueList){ + if(person.getTrustDegree()<=clue.getTrustDegree()){ + trustDegreeNumerator+=person.getTrustDegree()-initMap.get(key).get(0); + }else + { + trustDegreeNumerator+=clue.getTrustDegree()-initMap.get(key).get(0); + } + + if(person.getDeterrenceDegree()<=clue.getDeterrenceDegree()){ + deterrenceDegreeNumerator+=person.getDeterrenceDegree()-initMap.get(key).get(1); + }else{ + deterrenceDegreeNumerator+=clue.getDeterrenceDegree()-initMap.get(key).get(1); + } + trustDegreeDenominator+=clue.getTrustDegree()-initMap.get(key).get(0); + deterrenceDegreeDenominator+=clue.getDeterrenceDegree()-initMap.get(key).get(1); + } + + List demandTaskList = personMap.get(key).getDemandTasks(); + for (DemandTask demandTask:demandTaskList){ + if(demandTask.getTrustStart()>0){ + if(person.getTrustDegree()<=demandTask.getTrustStart()){ + trustDegreeNumerator+=person.getTrustDegree()-initMap.get(key).get(0); + }else{ + trustDegreeNumerator+=demandTask.getTrustStart()-initMap.get(key).get(0); + } + trustDegreeDenominator+=demandTask.getTrustStart()-initMap.get(key).get(0); + } + if(demandTask.getDeterrenceStart()>0){ + if(person.getTrustDegree()<=demandTask.getDeterrenceStart()){ + deterrenceDegreeNumerator+=person.getTrustDegree()-initMap.get(key).get(0); + }else{ + deterrenceDegreeNumerator+=demandTask.getDeterrenceStart()-initMap.get(key).get(1); + } + deterrenceDegreeNumerator+=demandTask.getDeterrenceStart()-initMap.get(key).get(1); + } + } + + result.put(key,Math.max((double)trustDegreeNumerator/trustDegreeDenominator,(double)deterrenceDegreeNumerator/deterrenceDegreeDenominator)); + } + return result; + } + + + + /** + * 对每个人物进行打分 + * @param weightMap + * @param weight + * @param demandTasksSet + * @return + */ + public void getPersonScore(Map weightMap,int weight,Set demandTasksSet){ + if(weightMap.size()==personMap.size()){ +// System.out.println("深度优先回溯"); + return; + } + Set demandTasks= new HashSet<>(); + for (DemandTask demandTask:demandTasksSet){ + if(!weightMap.containsKey(demandTask.getSubject())){ + weightMap.put(demandTask.getSubject(),weight); + Person person = personMap.get(demandTask.getSubject()); + demandTasks.addAll(person.getDemandTasks()); + } + } + Set result= new HashSet<>(); + for (DemandTask demandTask:demandTasks){ + for (Person person:personMap.values()){ + if(person.getId()!=demandTask.getSubject()){ + for(Clue clue:person.getClues()){ + if(clue.getClueId()==demandTask.getClueId()){ + result.addAll(person.getDemandTasks()); + } + } + } + } + } + + if(result.size()>0){ + this.getPersonScore(weightMap,weight/8,result); + } + } + + + + + + /** + * 读取json文件数据 + * @param jsonPath json文件路径 + * @return 字符串 + */ + private static String readJson(String jsonPath) { + File jsonFile = new File(jsonPath); + try { + FileReader fileReader = new FileReader(jsonFile); + BufferedReader reader = new BufferedReader(fileReader); + StringBuilder sb = new StringBuilder(); + while (true) { + int ch = reader.read(); + if (ch != -1) { + sb.append((char) ch); + } else { + break; + } + } + fileReader.close(); + reader.close(); + return sb.toString(); + } catch (IOException e) { + return ""; + } + } +} diff --git b/src/main/java/com/qiwu/inference/auto/pojo/Relation.java a/src/main/java/com/qiwu/inference/auto/pojo/Relation.java new file mode 100644 index 0000000..ceee330 --- /dev/null +++ a/src/main/java/com/qiwu/inference/auto/pojo/Relation.java @@ -0,0 +1,65 @@ +package com.qiwu.inference.auto.pojo; + +import lombok.Getter; +import lombok.Setter; + +import java.io.Serializable; + + +@Getter +@Setter +public class Relation implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * id + */ + private Integer id; + + /** + * 关系名称 + */ + private String name; + + /** + * 关系描述 + */ + private String description; + + /** + * 类型 + */ + private int type; + + /** + * 关系id + */ + private int relationId; + + /** + * 关系的主体 + */ + private int subject; + + /** + * 主体名称 + */ + private String subjectName; + + /** + * 关系客体 + */ + private int object; + + /** + * 客体名称 + */ + private String objectName; + + /** + * 掌握信息级别 + */ + private int masterInfoLevel; + +} diff --git b/src/main/java/com/qiwu/inference/auto/service/PlayerServiceImpl.java a/src/main/java/com/qiwu/inference/auto/service/PlayerServiceImpl.java new file mode 100644 index 0000000..d3e74ca --- /dev/null +++ a/src/main/java/com/qiwu/inference/auto/service/PlayerServiceImpl.java @@ -0,0 +1,2084 @@ +package com.qiwu.inference.auto.service; + +import com.qiwu.inference.auto.enums.ConditionMethod; +import com.qiwu.inference.auto.pojo.Clue; +import com.qiwu.inference.auto.pojo.DemandTask; +import com.qiwu.inference.auto.pojo.Person; +import com.qiwu.inference.auto.pojo.Player; +import com.qiwu.inference.common.api.CommonData; +import com.qiwu.inference.common.api.CommonResult; +import com.qiwu.inference.util.RandomUtil; +import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; + +import java.util.*; + +@Service +public class PlayerServiceImpl { + /** + * 询问性格 + * @param methodId 方法编号 + * @param player 玩家 + * @param request 请求对象 + * @return 通用信息 + */ + public CommonResult askDisposition(String methodId,Player player, Map request){ + CommonData commonData = new CommonData(); + if("1001".equals(methodId)){ + String subjectName = request.get("subjectName"); + String type = request.get("type"); + if(StringUtils.isEmpty(subjectName)){ + return CommonResult.failed("用户名称不能为空!"); + } + if(StringUtils.isEmpty(type)){ + return CommonResult.failed("性格类型不能为空!"); + } + //当前对话的人物 + Person current = player.getPersonMap().get(player.getPersonId()); + + Integer personId = player.getName2IdMap().get(subjectName); + Person subject =player.getPersonMap().get(personId); + + //查找符合条件的线索 + List clueList=findClues(current,subject,3); + if(clueList.size()==0){ + commonData.setId(100103); + commonData.setStatus("0"); + commonData.setText("不好意思,我不知道"); + }else{ + //检查是否符合阈值要求 + clueList=checkThreshold(current,clueList); + if(clueList.size()==0){ + commonData.setId(100102); + commonData.setStatus("0"); + commonData.setText("我又不认识你,为什么要告诉你?"); + }else{ + commonData.setId(100101); + commonData.setStatus("1"); + commonData.setText(clueList.get(0).getClueTemplate()); + commonData.setDemandTaskList(new ArrayList<>()); + + } + } + return CommonResult.success(commonData); + }else if("1002".equals(methodId)){ + String subjectName = request.get("subjectName"); + String dispositionName = request.get("dispositionName"); + if(StringUtils.isEmpty(subjectName)){ + return CommonResult.failed("用户名称不能为空!"); + } + if(StringUtils.isEmpty(dispositionName)){ + return CommonResult.failed("性格名称不能为空!"); + } + //当前对话的人物 + Person current = player.getPersonMap().get(player.getPersonId()); + Integer personId = player.getName2IdMap().get(subjectName); + Person subject =player.getPersonMap().get(personId); + //查找符合条件的线索 + List clueList=findClues(current,subject,3); + if(clueList.size()==0){ + commonData.setId(100204); + commonData.setStatus("0"); + commonData.setText("不好意思,我不知道"); + }else{ + //检查是否符合阈值要求 + clueList=checkThreshold(current,clueList); + if(clueList.size()==0){ + commonData.setId(100203); + commonData.setStatus("0"); + commonData.setText("我又不认识你,为什么要告诉你?"); + }else{ + //查找符合条件的线索 + clueList=findClues(clueList,dispositionName); + if(clueList.size()==0){ + commonData.setId(100202); + commonData.setStatus("0"); + commonData.setText("不是,"+dispositionName); + }else{ + commonData.setId(100201); + commonData.setStatus("1"); + commonData.setName("询问A是否是某个性格"); + StringBuilder text = new StringBuilder(); + List demandTaskList = new ArrayList<>(); + for (Clue clue : clueList) { + DemandTask demandTask = findTasks(subject.getDemandTasks(), clue); + if (!StringUtils.isEmpty(demandTask)) { + if (demandTask.getClueSwitch() == 1 || demandTask.getClueSwitch() == -1) { + clue.setStatus(3); + text.append(clue.getClueTemplate() + ":可以解锁" + player.getPersonMap().get(subject.getId()).getName() + "的" + demandTask.getName() + "任务, "); + demandTaskList.add(demandTask); + } + } else { + clue.setStatus(2); + text.append(clue.getClueTemplate()); + } + } + if(demandTaskList.size()>0){ + commonData.setDemandTaskList(demandTaskList); + }else{ + commonData.setDemandTaskList(new ArrayList<>()); + } + commonData.setText(text.toString()); + } + } + } + return CommonResult.success(commonData); + } + return CommonResult.failed("询问性格失败!"); + } + + /** + * 询问关系 + * @param methodId + * @param player + * @param request + * @return + */ + public CommonResult askRelation(String methodId,Player player, Map request){ + CommonData commonData = new CommonData(); + if("1003".equals(methodId)){ + String subjectName = request.get("subjectName"); + String objectName = request.get("objectName"); + if(StringUtils.isEmpty(subjectName)||StringUtils.isEmpty(objectName)){ + return CommonResult.failed("用户名称不能为空!"); + } + //当前对话的人物 + Person current = player.getPersonMap().get(player.getPersonId()); + Integer subjectId = player.getName2IdMap().get(subjectName); + Integer objectId = player.getName2IdMap().get(objectName); + Person subject =player.getPersonMap().get(subjectId); + Person object =player.getPersonMap().get(objectId); + + //查找符合条件的线索 + List clueList=findClues(current,subject,object,5); + if(clueList.size()==0){ + commonData.setId(100303); + commonData.setStatus("0"); + commonData.setText("不好意思,我不知道"); + }else{ + //检查是否符合阈值要求 + clueList=checkThreshold(current,clueList); + if(clueList.size()==0){ + commonData.setId(100302); + commonData.setStatus("0"); + commonData.setText("我又不认识你,为什么要告诉你?"); + }else{ + StringBuilder builder = new StringBuilder(); + for (Clue clue : clueList) { + clue.setStatus(2); + builder.append(clue.getClueTemplate()); + } + commonData.setId(100301); + commonData.setName("询问A和B是什么关系"); + commonData.setStatus("1"); + commonData.setText(builder.toString()); + } + + } + return CommonResult.success(commonData); + }else if("1004".equals(methodId)){ + String subjectName = request.get("subjectName"); + String objectName = request.get("objectName"); + String relationName = request.get("relationName"); + if(StringUtils.isEmpty(subjectName)||StringUtils.isEmpty(objectName)){ + return CommonResult.failed("用户名称不能为空!"); + } + + if(StringUtils.isEmpty(relationName)){ + return CommonResult.failed("关系名称不能为空!"); + } + //当前对话的人物 + Person current = player.getPersonMap().get(player.getPersonId()); + Integer subjectId = player.getName2IdMap().get(subjectName); + Integer objectId = player.getName2IdMap().get(objectName); + Person subject =player.getPersonMap().get(subjectId); + Person object =player.getPersonMap().get(objectId); + //查找符合条件的线索 + List clueList=findClues(current,subject,object,5); + if(clueList.size()==0){ + commonData.setId(100404); + commonData.setStatus("0"); + commonData.setText("不好意思,我不知道"); + }else{ + //检查是否符合阈值要求 + clueList=checkThreshold(current,clueList); + if(clueList.size()==0){ + commonData.setId(100403); + commonData.setStatus("0"); + commonData.setText("我又不认识你,为什么要告诉你?"); + }else{ + //查找符合条件的线索 + clueList=findClues(clueList,relationName); + if(clueList.size()==0){ + commonData.setId(100402); + commonData.setStatus("0"); + commonData.setText("不是,"+relationName); + }else{ + commonData.setId(100401); + commonData.setStatus("1"); + commonData.setName("询问A和B是不是某个关系"); + StringBuilder text = new StringBuilder(); + List demandTaskList = new ArrayList<>(); + for (Clue clue : clueList) { + DemandTask demandTask = findTasks(subject.getDemandTasks(), clue); + if (!StringUtils.isEmpty(demandTask)) { + if (demandTask.getClueSwitch() == 1 || demandTask.getClueSwitch() == -1) { + clue.setStatus(3); + text.append(clue.getClueTemplate() + ",可以解锁" + player.getPersonMap().get(subject.getId()).getName() + "的" + demandTask.getName() + "任务, "); + demandTaskList.add(demandTask); + } + } else { + clue.setStatus(2); + text.append(clue.getClueTemplate()); + } + } + if(demandTaskList.size()>0){ + commonData.setDemandTaskList(demandTaskList); + }else{ + commonData.setDemandTaskList(new ArrayList<>()); + } + commonData.setText(text.toString()); + } + } + } + return CommonResult.success(commonData); + }else if("1005".equals(methodId)){ + String subjectName = request.get("subjectName"); + String relationName = request.get("relationName"); + if(StringUtils.isEmpty(subjectName)){ + return CommonResult.failed("用户名称不能为空!"); + } + + if(StringUtils.isEmpty(relationName)){ + return CommonResult.failed("关系名称不能为空!"); + } + //当前对话的人物 + Person current = player.getPersonMap().get(player.getPersonId()); + Integer subjectId = player.getName2IdMap().get(subjectName); + Person subject =player.getPersonMap().get(subjectId); + + //查找符合条件的线索 + List clueList=findClues(current,5); + if(clueList.size()==0){ + commonData.setId(100503); + commonData.setStatus("0"); + commonData.setText("不好意思,我不知道"); + }else{ + //检查是否符合阈值要求 + clueList=checkThreshold(current,clueList); + if(clueList.size()==0){ + commonData.setId(100502); + commonData.setStatus("0"); + commonData.setText("我又不认识你,为什么要告诉你?"); + }else{ + //查找符合条件的线索 + clueList=findClues(clueList,relationName); + if(clueList.size()==0){ + commonData.setId(100503); + commonData.setStatus("0"); + commonData.setText("不好意思,我不知道"); + }else{ + StringBuilder builder = new StringBuilder(); + for (Clue clue : clueList) { + if (!StringUtils.isEmpty(clue.getObject())) { + clue.setStatus(2); + builder.append(player.getPersonMap().get(clue.getObject()).getName() + "跟" + subjectName + "有" + clue.getClueName() + "关系。"); + } + } + if(!StringUtils.isEmpty(builder.toString())){ + commonData.setId(100501); + commonData.setStatus("1"); + commonData.setName("询问和A有某个关系的人是谁"); + commonData.setText(builder.toString()); + }else{ + commonData.setId(100503); + commonData.setStatus("0"); + commonData.setText("不好意思,我不知道"); + } + } + } + } + return CommonResult.success(commonData); + }else if("1006".equals(methodId)){ + String relationName = request.get("relationName"); + if(StringUtils.isEmpty(relationName)){ + return CommonResult.failed("关系名称不能为空!"); + } + //当前对话的人物 + Person current = player.getPersonMap().get(player.getPersonId()); + + StringBuilder builder = new StringBuilder(); + List clueList = new ArrayList<>(); + for(Integer key:player.getPersonMap().keySet()){ + Person subject = player.getPersonMap().get(key); + clueList.addAll(findClues(current,subject,5)); + } + if(clueList.size()==0){ + commonData.setId(100603); + commonData.setStatus("0"); + commonData.setText("不好意思,我不知道"); + }else{ + //检查是否符合阈值要求 + clueList=checkThreshold(current,clueList); + if(clueList.size()==0){ + commonData.setId(100602); + commonData.setStatus("0"); + commonData.setText("我又不认识你,为什么要告诉你?"); + }else{ + //查找符合条件的线索 + clueList=findClues(clueList,relationName); + if(clueList.size()==0){ + commonData.setId(100603); + commonData.setStatus("0"); + commonData.setText("不好意思,我不知道"); + }else{ + for (Clue clue : clueList) { + clue.setStatus(2); + builder.append(clue.getClueTemplate()); + } + commonData.setId(100601); + commonData.setStatus("1"); + commonData.setName("询问谁和谁有某个关系"); + commonData.setText(builder.toString()); + } + } + } + return CommonResult.success(commonData); + } + return CommonResult.failed("询问关系失败!"); + } + + /** + * 询问行为 + * @param methodId + * @param player + * @param request + * @return + */ + public CommonResult askBehaviour(String methodId,Player player, Map request){ + CommonData commonData = new CommonData(); + if("1007".equals(methodId)){ + String subjectName = request.get("subjectName"); + if(StringUtils.isEmpty(subjectName)){ + return CommonResult.failed("用户名称不能为空!"); + } + //当前对话的人物 + Person current = player.getPersonMap().get(player.getPersonId()); + Integer subjectId = player.getName2IdMap().get(subjectName); + Person subject =player.getPersonMap().get(subjectId); + //查找符合条件的线索 + List clueList=findClues(current,subject,4); + if(clueList.size()==0){ + commonData.setId(100703); + commonData.setStatus("0"); + commonData.setText("不好意思,我不知道"); + }else{ + //检查是否符合阈值要求 + clueList=checkThreshold(current,clueList); + if(clueList.size()==0){ + commonData.setId(100702); + commonData.setStatus("0"); + commonData.setText("我又不认识你,为什么要告诉你?"); + }else{ + StringBuilder text = new StringBuilder(); + List demandTaskList = new ArrayList<>(); + for (Clue clue : clueList) { + if (subjectId == clue.getSubject()) { + DemandTask demandTask = findTasks(subject.getDemandTasks(), clue); + if (!StringUtils.isEmpty(demandTask)) { + if (demandTask.getClueSwitch() == 1 || demandTask.getClueSwitch() == -1) { + clue.setStatus(3); + text.append(clue.getClueTemplate() + ",可以解锁" + player.getPersonMap().get(subject.getId()).getName() + "的" + demandTask.getName() + "任务, "); + demandTaskList.add(demandTask); + } + } else { + clue.setStatus(2); + text.append(clue.getClueTemplate()); + } + } + } + if(!StringUtils.isEmpty(text.toString())){ + commonData.setId(100701); + commonData.setStatus("1"); + commonData.setName("询问A有过什么行为"); + + if(demandTaskList.size()>0){ + commonData.setDemandTaskList(demandTaskList); + }else{ + commonData.setDemandTaskList(new ArrayList<>()); + } + commonData.setText(text.toString()); + }else{ + commonData.setId(100703); + commonData.setStatus("0"); + commonData.setText("不好意思,我不知道"); + } + } + return CommonResult.success(commonData); + } + }else if("1008".equals(methodId)){ + String subjectName = request.get("subjectName"); + String objectName = request.get("objectName"); + if(StringUtils.isEmpty(subjectName)||StringUtils.isEmpty(objectName)){ + return CommonResult.failed("用户名称不能为空!"); + } + //当前对话的人物 + Person current = player.getPersonMap().get(player.getPersonId()); + Integer subjectId = player.getName2IdMap().get(subjectName); + Integer objectId = player.getName2IdMap().get(objectName); + Person subject =player.getPersonMap().get(subjectId); + Person object =player.getPersonMap().get(objectId); + + //查找符合条件的线索 + List clueList=findClues(current,subject,object,4); + if(clueList.size()==0){ + commonData.setId(100803); + commonData.setStatus("0"); + commonData.setText("不好意思,我不知道"); + }else{ + //检查是否符合阈值要求 + clueList=checkThreshold(current,clueList); + if(clueList.size()==0){ + commonData.setId(100802); + commonData.setStatus("0"); + commonData.setText("我又不认识你,为什么要告诉你?"); + }else{ + StringBuilder text = new StringBuilder(); + List demandTaskList = new ArrayList<>(); + for (Clue clue : clueList) { + DemandTask demandTask = findTasks(subject.getDemandTasks(), clue); + if (!StringUtils.isEmpty(demandTask)) { + if (demandTask.getClueSwitch() == 1 || demandTask.getClueSwitch() == -1) { + clue.setStatus(3); + text.append(clue.getClueTemplate() + ",可以解锁" + player.getPersonMap().get(subject.getId()).getName() + "的" + demandTask.getName() + "任务, "); + demandTaskList.add(demandTask); + } + } else { + clue.setStatus(2); + text.append(clue.getClueTemplate()); + } + } + commonData.setId(100801); + commonData.setStatus("1"); + commonData.setName("询问A和B有什么行为"); + if(demandTaskList.size()>0){ + commonData.setDemandTaskList(demandTaskList); + }else{ + commonData.setDemandTaskList(new ArrayList<>()); + } + commonData.setText(text.toString()); + } + } + return CommonResult.success(commonData); + }else if("1009".equals(methodId)){ + String subjectName = request.get("subjectName"); + String behaviourName = request.get("behaviourName"); + + if(StringUtils.isEmpty(subjectName)){ + return CommonResult.failed("人物名称不能为空!"); + } + + if(StringUtils.isEmpty(behaviourName)){ + return CommonResult.failed("行为名称不能为空!"); + } + //当前对话的人物 + Person current = player.getPersonMap().get(player.getPersonId()); + Integer subjectId = player.getName2IdMap().get(subjectName); + Person subject =player.getPersonMap().get(subjectId); + List clueList = findClues(current,subject,4); + if(clueList.size()==0){ + commonData.setId(100903); + commonData.setStatus("0"); + commonData.setText("不好意思,我不知道"); + }else{ + //检查是否符合阈值要求 + clueList=checkThreshold(current,clueList); + if(clueList.size()==0){ + commonData.setId(100902); + commonData.setStatus("0"); + commonData.setText("我又不认识你,为什么要告诉你?"); + }else{ + clueList=findClues(clueList,behaviourName); + if(clueList.size()==0){ + commonData.setId(100903); + commonData.setStatus("0"); + commonData.setText("不好意思,我不知道"); + }else{ + StringBuilder text = new StringBuilder(); + List demandTaskList = new ArrayList<>(); + for (Clue clue : clueList) { + if (clue.getSubject() == subjectId || clue.getObject() == subjectId) { + DemandTask demandTask = findTasks(subject.getDemandTasks(), clue); + if (!StringUtils.isEmpty(demandTask)) { + if (demandTask.getClueSwitch() == 1 || demandTask.getClueSwitch() == -1) { + clue.setStatus(3); + text.append(clue.getClueTemplate() + ",可以解锁" + player.getPersonMap().get(subject.getId()).getName() + "的" + demandTask.getName() + "任务, "); + demandTaskList.add(demandTask); + } + } else { + clue.setStatus(2); + text.append(clue.getClueTemplate()); + } + } + } + if(!StringUtils.isEmpty(text.toString())){ + commonData.setId(100901); + commonData.setStatus("1"); + commonData.setName("询问A和谁有了某个行为"); + if(demandTaskList.size()>0){ + commonData.setDemandTaskList(demandTaskList); + }else{ + commonData.setDemandTaskList(new ArrayList<>()); + } + commonData.setText(text.toString()); + }else{ + commonData.setId(100903); + commonData.setStatus("0"); + commonData.setText("不好意思,我不知道"); + } + } + } + } + return CommonResult.success(commonData); + }else if("1010".equals(methodId)){ + String subjectName = request.get("subjectName"); + String behaviourName = request.get("behaviourName"); + if(StringUtils.isEmpty(subjectName)){ + return CommonResult.failed("人物名称不能为空!"); + } + if(StringUtils.isEmpty(behaviourName)){ + return CommonResult.failed("行为名称不能为空!"); + } + //当前对话的人物 + Person current = player.getPersonMap().get(player.getPersonId()); + Integer subjectId = player.getName2IdMap().get(subjectName); + Person subject =player.getPersonMap().get(subjectId); + List clueList = findClues(current,subject,4); + if(clueList.size()==0){ + commonData.setId(101003); + commonData.setStatus("0"); + commonData.setText("不好意思,我不知道"); + }else{ + //查找符合条件的线索 + clueList=findClues(clueList,behaviourName); + if(clueList.size()==0){ + commonData.setId(101003); + commonData.setStatus("0"); + commonData.setText("不好意思,我不知道"); + }else{ + //检查是否符合阈值要求 + clueList=checkThreshold(current,clueList); + if(clueList.size()==0){ + commonData.setId(101002); + commonData.setStatus("0"); + commonData.setText("我又不认识你,为什么要告诉你?"); + }else{ + StringBuilder text = new StringBuilder(); + List demandTaskList = new ArrayList<>(); + for (Clue clue : clueList) { + if (subjectId == clue.getSubject() || subjectId == clue.getObject()) { + DemandTask demandTask = findTasks(subject.getDemandTasks(), clue); + if (!StringUtils.isEmpty(demandTask)) { + if (demandTask.getClueSwitch() == 1 || demandTask.getClueSwitch() == -1) { + clue.setStatus(3); + text.append(clue.getClueTemplate() + ",可以解锁" + player.getPersonMap().get(subject.getId()).getName() + "的" + demandTask.getName() + "任务, "); + demandTaskList.add(demandTask); + } + } else { + clue.setStatus(2); + text.append(clue.getClueTemplate()); + } + } + } + + if(!StringUtils.isEmpty(text.toString())){ + commonData.setId(101001); + commonData.setStatus("1"); + commonData.setName("询问A有没有发生过某个行为"); + if(demandTaskList.size()>0){ + commonData.setDemandTaskList(demandTaskList); + }else{ + commonData.setDemandTaskList(new ArrayList<>()); + } + commonData.setText(text.toString()); + }else{ + commonData.setId(101002); + commonData.setStatus("0"); + commonData.setText("不是,"+behaviourName); + } + } + } + } + return CommonResult.success(commonData); + }else if("1011".equals(methodId)){ + String subjectName = request.get("subjectName"); + String objectName = request.get("objectName"); + String behaviourName = request.get("behaviourName"); + if(StringUtils.isEmpty(subjectName)||StringUtils.isEmpty(objectName)){ + return CommonResult.failed("人物名称不能为空!"); + } + if(StringUtils.isEmpty(behaviourName)){ + return CommonResult.failed("行为名称不能为空!"); + } + //当前对话的人物 + Person current = player.getPersonMap().get(player.getPersonId()); + Integer subjectId = player.getName2IdMap().get(subjectName); + Integer objectId = player.getName2IdMap().get(objectName); + Person subject =player.getPersonMap().get(subjectId); + Person object =player.getPersonMap().get(objectId); + + //查找符合条件的线索 + List clueList=findClues(current,subject,object,4); + if(clueList.size()==0){ + commonData.setId(101104); + commonData.setStatus("0"); + commonData.setText("不好意思,我不知道"); + }else{ + //检查是否符合阈值要求 + clueList=checkThreshold(current,clueList); + if(clueList.size()==0){ + commonData.setId(101103); + commonData.setStatus("0"); + commonData.setText("我又不认识你,为什么要告诉你?"); + }else{ + //查找符合条件的线索 + clueList=findClues(clueList,behaviourName); + if(clueList.size()==0){ + commonData.setId(101102); + commonData.setStatus("0"); + commonData.setText("不是,"+behaviourName); + }else{ + StringBuilder text = new StringBuilder(); + List demandTaskList = new ArrayList<>(); + for (Clue clue : clueList) { + DemandTask demandTask = findTasks(subject.getDemandTasks(), clue); + if (!StringUtils.isEmpty(demandTask)) { + if (demandTask.getClueSwitch() == 1 || demandTask.getClueSwitch() == -1) { + clue.setStatus(3); + text.append(clue.getClueTemplate() + ",可以解锁" + player.getPersonMap().get(subject.getId()).getName() + "的" + demandTask.getName() + "任务, "); + demandTaskList.add(demandTask); + } + } else { + clue.setStatus(2); + text.append(clue.getClueTemplate()); + } + } + commonData.setId(101101); + commonData.setStatus("1"); + commonData.setName("询问A和B有没有发生过某个行为"); + commonData.setText(text.toString()); + if(demandTaskList.size()>0){ + commonData.setDemandTaskList(demandTaskList); + }else{ + commonData.setDemandTaskList(new ArrayList<>()); + } + } + } + } + return CommonResult.success(commonData); + }else if("1028".equals(methodId)){ + String subjectName = request.get("subjectName"); + String behaviourName = request.get("behaviourName"); + + if(StringUtils.isEmpty(subjectName)){ + return CommonResult.failed("人物名称不能为空!"); + } + + if(StringUtils.isEmpty(behaviourName)){ + return CommonResult.failed("行为名称不能为空!"); + } + //当前对话的人物 + Person current = player.getPersonMap().get(player.getPersonId()); + Integer subjectId = player.getName2IdMap().get(subjectName); + Person subject =player.getPersonMap().get(subjectId); + + List clueList =findClues(current,subject,6); + if(clueList.size()==0){ + commonData.setId(102803); + commonData.setStatus("0"); + commonData.setText("不好意思,我不知道"); + }else{ + //检查是否符合阈值要求 + clueList=checkThreshold(current,clueList); + if(clueList.size()==0){ + commonData.setId(102802); + commonData.setStatus("0"); + commonData.setText("我又不认识你,为什么要告诉你?"); + }else{ + clueList=findClues(clueList,behaviourName); + if(clueList.size()==0){ + commonData.setId(102803); + commonData.setStatus("0"); + commonData.setText("不好意思,我不知道"); + }else{ + StringBuilder text = new StringBuilder(); + List demandTaskList = new ArrayList<>(); + for (Clue clue : clueList) { + if (clue.getSubject() == subjectId || clue.getObject() == subjectId) { + DemandTask demandTask = findTasks(subject.getDemandTasks(), clue); + if (!StringUtils.isEmpty(demandTask)) { + if (demandTask.getClueSwitch() == 1 || demandTask.getClueSwitch() == -1) { + clue.setStatus(3); + text.append(clue.getClueTemplate() + ",可以解锁" + player.getPersonMap().get(subject.getId()).getName() + "的" + demandTask.getName() + "任务, "); + demandTaskList.add(demandTask); + } + } else { + clue.setStatus(2); + text.append(clue.getClueTemplate()); + } + } + } + if(!StringUtils.isEmpty(text.toString())){ + commonData.setId(102801); + commonData.setStatus("1"); + commonData.setName("询问A是否有某个行为"); + if(demandTaskList.size()>0){ + commonData.setDemandTaskList(demandTaskList); + }else{ + commonData.setDemandTaskList(new ArrayList<>()); + } + commonData.setText(text.toString()); + }else{ + commonData.setId(102803); + commonData.setStatus("0"); + commonData.setText("不好意思,我不知道"); + } + } + } + } + return CommonResult.success(commonData); + } + return CommonResult.failed("询问行为失败!"); + } + /** + * 询问任务对应的相关线索 + * @param methodId + * @param player + * @param request + * @return + */ + public CommonResult askTask(String methodId,Player player, Map request){ + CommonData commonData = new CommonData(); + String subjectName = request.get("subjectName"); + if(StringUtils.isEmpty(subjectName)){ + return CommonResult.failed("用户名称不能为空!"); + } + //当前对话的人物 + Person current = player.getPersonMap().get(player.getPersonId()); + Integer subjectId = player.getName2IdMap().get(subjectName); + Person subject =player.getPersonMap().get(subjectId); + + if("1015".equals(methodId)){ + //查找符合条件的任务 + List demandTaskList = findTasks(subject,1); + List clueList = findClues(demandTaskList,current); + if(clueList.size()==0){ + commonData.setId(101503); + commonData.setStatus("0"); + commonData.setText("不好意思,我不知道"); + }else{ + //检查任务是否符合阈值要求 + clueList =checkThreshold(current,clueList); + if(clueList.size()==0){ + commonData.setId(101502); + commonData.setStatus("0"); + commonData.setText("我又不认识你,为什么要告诉你?"); + }else{ + StringBuilder text = new StringBuilder(); + demandTaskList = new ArrayList<>(); + for (Clue clue : clueList) { + if (clue.getSubject() == subjectId || clue.getObject() == subjectId) { + DemandTask demandTask = findTasks(subject.getDemandTasks(), clue); + if (!StringUtils.isEmpty(demandTask)) { + if (demandTask.getClueSwitch() == 1 || demandTask.getClueSwitch() == -1) { + clue.setStatus(3); + text.append(clue.getClueTemplate() + ",可以解锁" + player.getPersonMap().get(subject.getId()).getName() + "的" + demandTask.getName() + "任务, "); + demandTaskList.add(demandTask); + } + } else { + clue.setStatus(2); + text.append(clue.getClueTemplate()); + } + } + } + if(!StringUtils.isEmpty(text.toString())){ + commonData.setId(101501); + commonData.setStatus("1"); + commonData.setName("询问A的提升信任度任务"); + if(demandTaskList.size()>0){ + commonData.setDemandTaskList(demandTaskList); + }else{ + commonData.setDemandTaskList(new ArrayList<>()); + } + commonData.setText(text.toString()); + }else{ + commonData.setId(101503); + commonData.setStatus("0"); + commonData.setText("不好意思,我不知道"); + } + } + } + return CommonResult.success(commonData); + }else if("1016".equals(methodId)){ + //查找符合条件的任务 + List demandTaskList = findTasks(subject,3); + List clueList = findClues(demandTaskList,current); + if(clueList.size()==0){ + commonData.setId(101603); + commonData.setStatus("0"); + commonData.setText("不好意思,我不知道"); + }else{ + //检查任务是否符合阈值要求 + clueList =checkThreshold(current,clueList); + if(clueList.size()==0){ + commonData.setId(101602); + commonData.setStatus("0"); + commonData.setText("我又不认识你,为什么要告诉你?"); + }else{ + StringBuilder text = new StringBuilder(); + demandTaskList = new ArrayList<>(); + for (Clue clue : clueList) { + if (clue.getSubject() == subjectId || clue.getObject() == subjectId) { + DemandTask demandTask = findTasks(subject.getDemandTasks(), clue); + if (!StringUtils.isEmpty(demandTask)) { + if (demandTask.getClueSwitch() == 1 || demandTask.getClueSwitch() == -1) { + clue.setStatus(3); + text.append(clue.getClueTemplate() + ",可以解锁" + player.getPersonMap().get(subject.getId()).getName() + "的" + demandTask.getName() + "任务, "); + demandTaskList.add(demandTask); + } + } else { + clue.setStatus(2); + text.append(clue.getClueTemplate()); + } + } + } + if(!StringUtils.isEmpty(text.toString())){ + commonData.setId(101601); + commonData.setStatus("1"); + commonData.setName("询问A的提升威慑度任务"); + if(demandTaskList.size()>0){ + commonData.setDemandTaskList(demandTaskList); + }else{ + commonData.setDemandTaskList(new ArrayList<>()); + } + commonData.setText(text.toString()); + }else{ + commonData.setId(101603); + commonData.setStatus("0"); + commonData.setText("不好意思,我不知道"); + } + + } + } + return CommonResult.success(commonData); + }else if("1017".equals(methodId)){ + String taskName = request.get("taskName"); + if(StringUtils.isEmpty(subjectName)){ + return CommonResult.failed("任务名称不能为空!"); + } + //查找符合条件的任务 + List demandTaskList = findTasks(subject,taskName); + //List demandTaskList = findTasks(subject,1); + //demandTaskList = findTasks(demandTaskList,taskName); + List clueList = findClues(demandTaskList,current); + if(clueList.size()==0){ + commonData.setId(101704); + commonData.setStatus("0"); + commonData.setText("不好意思,我不知道"); + }else{ + //检查任务是否符合阈值要求 + clueList =checkThreshold(current,clueList); + if(clueList.size()==0){ + commonData.setId(101703); + commonData.setStatus("0"); + commonData.setText("我又不认识你,为什么要告诉你?"); + }else{ + StringBuilder text = new StringBuilder(); + demandTaskList = new ArrayList<>(); + for (Clue clue : clueList) { + if (clue.getSubject() == subjectId || clue.getObject() == subjectId) { + DemandTask demandTask = findTasks(subject.getDemandTasks(), clue); + if (!StringUtils.isEmpty(demandTask)) { + if (demandTask.getClueSwitch() == 1 || demandTask.getClueSwitch() == -1) { + clue.setStatus(3); + text.append(clue.getClueTemplate() + ",可以解锁" + player.getPersonMap().get(subject.getId()).getName() + "的" + demandTask.getName() + "任务, "); + demandTaskList.add(demandTask); + } + } else { + clue.setStatus(2); + text.append(clue.getClueTemplate()); + } + } + } + if(!StringUtils.isEmpty(text.toString())){ + commonData.setId(101701); + commonData.setStatus("1"); + commonData.setName("询问A是否有某个提升信任度的任务"); + if(demandTaskList.size()>0){ + commonData.setDemandTaskList(demandTaskList); + }else{ + commonData.setDemandTaskList(new ArrayList<>()); + } + commonData.setText(text.toString()); + }else{ + commonData.setId(101704); + commonData.setStatus("0"); + commonData.setText("不好意思,我不知道"); + } + } + } + return CommonResult.success(commonData); + }else if("1018".equals(methodId)){ + String taskName = request.get("taskName"); + if(StringUtils.isEmpty(subjectName)){ + return CommonResult.failed("任务名称不能为空!"); + } + + //查找符合条件的任务 + List demandTaskList = findTasks(subject,taskName); + //List demandTaskList = findTasks(subject,3); + //demandTaskList = findTasks(demandTaskList,taskName); + List clueList = findClues(demandTaskList,current); + if(clueList.size()==0){ + commonData.setId(101804); + commonData.setStatus("0"); + commonData.setText("不好意思,我不知道"); + }else{ + //检查任务是否符合阈值要求 + clueList =checkThreshold(current,clueList); + if(clueList.size()==0){ + commonData.setId(101803); + commonData.setStatus("0"); + commonData.setText("我又不认识你,为什么要告诉你?"); + }else{ + StringBuilder text = new StringBuilder(); + demandTaskList = new ArrayList<>(); + for (Clue clue : clueList) { + if (clue.getSubject() == subjectId || clue.getObject() == subjectId) { + DemandTask demandTask = findTasks(subject.getDemandTasks(), clue); + if (!StringUtils.isEmpty(demandTask)) { + if (demandTask.getClueSwitch() == 1 || demandTask.getClueSwitch() == -1) { + clue.setStatus(3); + text.append(clue.getClueTemplate() + ",可以解锁" + player.getPersonMap().get(subject.getId()).getName() + "的" + demandTask.getName() + "任务, "); + demandTaskList.add(demandTask); + } + } else { + clue.setStatus(2); + text.append(clue.getClueTemplate()); + } + } + } + if(!StringUtils.isEmpty(text.toString())){ + commonData.setId(101801); + commonData.setStatus("1"); + commonData.setName("询问A是否有某个提升威慑度的任务"); + if(demandTaskList.size()>0){ + commonData.setDemandTaskList(demandTaskList); + }else{ + commonData.setDemandTaskList(new ArrayList<>()); + } + commonData.setText(text.toString()); + }else{ + commonData.setId(101804); + commonData.setStatus("0"); + commonData.setText("不好意思,我不知道"); + } + } + } + return CommonResult.success(commonData); + }else if("1019".equals(methodId)){ + //查找符合条件的任务 + List demandTaskList = findTasks(subject,2); + List clueList = findClues(demandTaskList,current); + if(clueList.size()==0){ + commonData.setId(101903); + commonData.setStatus("0"); + commonData.setText("不好意思,我不知道"); + }else{ + //检查任务是否符合阈值要求 + clueList =checkThreshold(current,clueList); + if(clueList.size()==0){ + commonData.setId(101902); + commonData.setStatus("0"); + commonData.setText("我又不认识你,为什么要告诉你?"); + }else{ + StringBuilder text = new StringBuilder(); + demandTaskList = new ArrayList<>(); + for (Clue clue : clueList) { + if (clue.getSubject() == subjectId || clue.getObject() == subjectId) { + DemandTask demandTask = findTasks(subject.getDemandTasks(), clue); + if (!StringUtils.isEmpty(demandTask)) { + if (demandTask.getClueSwitch() == 1 || demandTask.getClueSwitch() == -1) { + clue.setStatus(3); + text.append(clue.getClueTemplate() + ",可以解锁" + player.getPersonMap().get(subject.getId()).getName() + "的" + demandTask.getName() + "任务, "); + demandTaskList.add(demandTask); + } + } else { + clue.setStatus(2); + text.append(clue.getClueTemplate()); + } + } + } + if(!StringUtils.isEmpty(text.toString())){ + commonData.setId(101901); + commonData.setStatus("1"); + commonData.setName("询问A降低信任度的任务"); + if(demandTaskList.size()>0){ + commonData.setDemandTaskList(demandTaskList); + }else{ + commonData.setDemandTaskList(new ArrayList<>()); + } + commonData.setText(text.toString()); + }else{ + commonData.setId(101903); + commonData.setStatus("0"); + commonData.setText("不好意思,我不知道"); + } + } + } + return CommonResult.success(commonData); + }else if("1020".equals(methodId)){ + //查找符合条件的任务 + List demandTaskList = findTasks(subject,4); + List clueList = findClues(demandTaskList,current); + if(clueList.size()==0){ + commonData.setId(102003); + commonData.setStatus("0"); + commonData.setText("不好意思,我不知道"); + }else{ + //检查任务是否符合阈值要求 + clueList =checkThreshold(current,clueList); + if(clueList.size()==0){ + commonData.setId(102002); + commonData.setStatus("0"); + commonData.setText("我又不认识你,为什么要告诉你?"); + }else{ + StringBuilder text = new StringBuilder(); + demandTaskList = new ArrayList<>(); + for (Clue clue : clueList) { + if (clue.getSubject() == subjectId || clue.getObject() == subjectId) { + DemandTask demandTask = findTasks(subject.getDemandTasks(), clue); + if (!StringUtils.isEmpty(demandTask)) { + if (demandTask.getClueSwitch() == 1 || demandTask.getClueSwitch() == -1) { + clue.setStatus(3); + text.append(clue.getClueTemplate() + ",可以解锁" + player.getPersonMap().get(subject.getId()).getName() + "的" + demandTask.getName() + "任务, "); + demandTaskList.add(demandTask); + } + } else { + clue.setStatus(2); + text.append(clue.getClueTemplate()); + } + } + } + if(!StringUtils.isEmpty(text.toString())){ + commonData.setId(102001); + commonData.setStatus("1"); + commonData.setName("询问A降低威慑度的任务"); + if(demandTaskList.size()>0){ + commonData.setDemandTaskList(demandTaskList); + }else{ + commonData.setDemandTaskList(new ArrayList<>()); + } + commonData.setText(text.toString()); + }else{ + commonData.setId(101903); + commonData.setStatus("0"); + commonData.setText("不好意思,我不知道"); + } + } + } + return CommonResult.success(commonData); + }else if("1021".equals(methodId)){ + String taskName = request.get("taskName"); + if(StringUtils.isEmpty(subjectName)){ + return CommonResult.failed("任务名称不能为空!"); + } + //查找符合条件的任务 + List demandTaskList = findTasks(subject,2); + demandTaskList = findTasks(demandTaskList,taskName); + List clueList = findClues(demandTaskList,current); + if(clueList.size()==0){ + commonData.setId(102104); + commonData.setStatus("0"); + commonData.setText("不好意思,我不知道"); + }else{ + //检查任务是否符合阈值要求 + clueList =checkThreshold(current,clueList); + if(clueList.size()==0){ + commonData.setId(102103); + commonData.setStatus("0"); + commonData.setText("我又不认识你,为什么要告诉你?"); + }else{ + StringBuilder text = new StringBuilder(); + demandTaskList = new ArrayList<>(); + for (Clue clue : clueList) { + if (clue.getSubject() == subjectId || clue.getObject() == subjectId) { + DemandTask demandTask = findTasks(subject.getDemandTasks(), clue); + if (!StringUtils.isEmpty(demandTask)) { + if (demandTask.getClueSwitch() == 1 || demandTask.getClueSwitch() == -1) { + clue.setStatus(3); + text.append(clue.getClueTemplate() + ",可以解锁" + player.getPersonMap().get(subject.getId()).getName() + "的" + demandTask.getName() + "任务, "); + demandTaskList.add(demandTask); + } + } else { + clue.setStatus(2); + text.append(clue.getClueTemplate()); + } + } + } + if(!StringUtils.isEmpty(text.toString())){ + commonData.setId(102101); + commonData.setStatus("1"); + commonData.setName("询问A是否有某个降低信任度的任务"); + if(demandTaskList.size()>0){ + commonData.setDemandTaskList(demandTaskList); + }else{ + commonData.setDemandTaskList(new ArrayList<>()); + } + commonData.setText(text.toString()); + }else{ + commonData.setId(102104); + commonData.setStatus("0"); + commonData.setText("不好意思,我不知道"); + } + } + } + return CommonResult.success(commonData); + }else if("1022".equals(methodId)){ + String taskName = request.get("taskName"); + if(StringUtils.isEmpty(subjectName)){ + return CommonResult.failed("任务名称不能为空!"); + } + //查找符合条件的任务 + List demandTaskList = findTasks(subject,4); + demandTaskList = findTasks(demandTaskList,taskName); + List clueList = findClues(demandTaskList,current); + if(clueList.size()==0){ + commonData.setId(102204); + commonData.setStatus("0"); + commonData.setText("不好意思,我不知道"); + }else{ + //检查任务是否符合阈值要求 + clueList =checkThreshold(current,clueList); + if(clueList.size()==0){ + commonData.setId(102203); + commonData.setStatus("0"); + commonData.setText("我又不认识你,为什么要告诉你?"); + }else{ + StringBuilder text = new StringBuilder(); + demandTaskList = new ArrayList<>(); + for (Clue clue : clueList) { + if (clue.getSubject() == subjectId || clue.getObject() == subjectId) { + DemandTask demandTask = findTasks(subject.getDemandTasks(), clue); + if (!StringUtils.isEmpty(demandTask)) { + if (demandTask.getClueSwitch() == 1 || demandTask.getClueSwitch() == -1) { + clue.setStatus(3); + text.append(clue.getClueTemplate() + ",可以解锁" + player.getPersonMap().get(subject.getId()).getName() + "的" + demandTask.getName() + "任务, "); + demandTaskList.add(demandTask); + } + } else { + clue.setStatus(2); + text.append(clue.getClueTemplate()); + } + } + } + if(!StringUtils.isEmpty(text.toString())){ + commonData.setId(102201); + commonData.setStatus("1"); + commonData.setName("询问A是否有某个降低威慑度的任务"); + if(demandTaskList.size()>0){ + commonData.setDemandTaskList(demandTaskList); + }else{ + commonData.setDemandTaskList(new ArrayList<>()); + } + commonData.setText(text.toString()); + }else{ + commonData.setId(102204); + commonData.setStatus("0"); + commonData.setText("不好意思,我不知道"); + } + } + } + return CommonResult.success(commonData); + } + return CommonResult.failed("询问任务失败!"); + } + + /** + * 询问身份 + * @param methodId 方法编号 + * @param player 玩家 + * @param request 请求 + * @return + */ + public CommonResult askIdentity(String methodId,Player player, Map request){ + CommonData commonData = new CommonData(); + if("1023".equals(methodId)){ + String subjectName = request.get("subjectName"); + if(StringUtils.isEmpty(subjectName)){ + return CommonResult.failed("用户名称不能为空!"); + } + //当前对话的人物 + Person current = player.getPersonMap().get(player.getPersonId()); + Integer subjectId = player.getName2IdMap().get(subjectName); + Person subject =player.getPersonMap().get(subjectId); + //查找符合条件的线索 + List clueList=findClues(current,subject,1); + if(clueList.size()==0){ + commonData.setId(102303); + commonData.setStatus("0"); + commonData.setText("不好意思,我不知道"); + }else{ + //检查是否符合阈值要求 + clueList=checkThreshold(current,clueList); + if(clueList.size()==0){ + commonData.setId(102302); + commonData.setStatus("0"); + commonData.setText("我又不认识你,为什么要告诉你?"); + }else{ + StringBuilder text = new StringBuilder(); + List demandTaskList = new ArrayList<>(); + for (Clue clue : clueList) { + DemandTask demandTask = findTasks(subject.getDemandTasks(), clue); + if (!StringUtils.isEmpty(demandTask)) { + if (demandTask.getClueSwitch() == 1 || demandTask.getClueSwitch() == -1) { + clue.setStatus(3); + text.append(clue.getClueTemplate() + ",可以解锁" + player.getPersonMap().get(subject.getId()).getName() + "的" + demandTask.getName() + "任务, "); + demandTaskList.add(demandTask); + } + } else { + clue.setStatus(2); + text.append(clue.getClueTemplate()); + } + } + commonData.setId(102301); + commonData.setStatus("1"); + commonData.setName("询问A是什么身份"); + if(demandTaskList.size()>0){ + commonData.setDemandTaskList(demandTaskList); + }else{ + commonData.setDemandTaskList(new ArrayList<>()); + } + commonData.setText(text.toString()); + } + } + return CommonResult.success(commonData); + }else if("1024".equals(methodId)){ + String subjectName = request.get("subjectName"); + String identityName = request.get("identityName"); + if(StringUtils.isEmpty(subjectName)){ + return CommonResult.failed("用户名称不能为空!"); + } + if(StringUtils.isEmpty(identityName)){ + return CommonResult.failed("身份名称不能为空!"); + } + //当前对话的人物 + Person current = player.getPersonMap().get(player.getPersonId()); + Integer subjectId = player.getName2IdMap().get(subjectName); + Person subject =player.getPersonMap().get(subjectId); + //查找符合条件的线索 + List clueList=findClues(current,subject,1); + if(clueList.size()==0){ + commonData.setId(102404); + commonData.setStatus("0"); + commonData.setText("不好意思,我不知道"); + }else{ + //检查是否符合阈值要求 + clueList=checkThreshold(current,clueList); + if(clueList.size()==0){ + commonData.setId(102403); + commonData.setStatus("0"); + commonData.setText("我又不认识你,为什么要告诉你?"); + }else{ + //查找符合条件的线索 + clueList=findClues(clueList,identityName); + if(clueList.size()==0){ + commonData.setId(102402); + commonData.setStatus("0"); + commonData.setText("不是,"+identityName); + }else{ + StringBuilder text = new StringBuilder(); + List demandTaskList = new ArrayList<>(); + for (Clue clue : clueList) { + DemandTask demandTask = findTasks(subject.getDemandTasks(), clue); + if (!StringUtils.isEmpty(demandTask)) { + if (demandTask.getClueSwitch() == 1 || demandTask.getClueSwitch() == -1) { + clue.setStatus(3); + text.append(clue.getClueTemplate() + ",可以解锁" + player.getPersonMap().get(subject.getId()).getName() + "的" + demandTask.getName() + "任务, "); + demandTaskList.add(demandTask); + } + } else { + clue.setStatus(2); + text.append(clue.getClueTemplate()); + } + } + commonData.setId(102401); + commonData.setStatus("1"); + commonData.setName("询问A是不是某个身份"); + if(demandTaskList.size()>0){ + commonData.setDemandTaskList(demandTaskList); + }else{ + commonData.setDemandTaskList(new ArrayList<>()); + } + commonData.setText(text.toString()); + } + } + } + return CommonResult.success(commonData); + } + return CommonResult.failed("询问身份失败!"); + } + + + /** + * 询问场所 + * @param methodId 方法id + * @param player 玩家 + * @param request 请求数据 + * @return 通用结果 + */ + public CommonResult askLocation(String methodId,Player player, Map request){ + CommonData commonData = new CommonData(); + if("1025".equals(methodId)){ + String subjectName = request.get("subjectName"); + if(StringUtils.isEmpty(subjectName)){ + return CommonResult.failed("用户名称不能为空!"); + } + //当前对话的人物 + Person current = player.getPersonMap().get(player.getPersonId()); + Integer subjectId = player.getName2IdMap().get(subjectName); + Person subject =player.getPersonMap().get(subjectId); + //查找符合条件的线索 + List clueList=findClues(current,subject,2); + if(clueList.size()==0){ + commonData.setId(102503); + commonData.setStatus("0"); + commonData.setText("不好意思,我不知道"); + }else{ + //检查是否符合阈值要求 + clueList=checkThreshold(current,clueList); + if(clueList.size()==0){ + commonData.setId(102502); + commonData.setStatus("0"); + commonData.setText("我又不认识你,为什么要告诉你?"); + }else{ + StringBuilder text = new StringBuilder(); + List demandTaskList = new ArrayList<>(); + for (Clue clue : clueList) { + DemandTask demandTask = findTasks(subject.getDemandTasks(), clue); + if (!StringUtils.isEmpty(demandTask)) { + if (demandTask.getClueSwitch() == 1 || demandTask.getClueSwitch() == -1) { + clue.setStatus(3); + text.append(clue.getClueTemplate() + ",可以解锁" + player.getPersonMap().get(subject.getId()).getName() + "的" + demandTask.getName() + "任务, "); + demandTaskList.add(demandTask); + } + } else { + clue.setStatus(2); + text.append(clue.getClueTemplate()); + } + } + commonData.setId(102501); + commonData.setStatus("1"); + commonData.setName("询问A在哪个场所"); + if(demandTaskList.size()>0){ + commonData.setDemandTaskList(demandTaskList); + }else{ + commonData.setDemandTaskList(new ArrayList<>()); + } + commonData.setText(text.toString()); + } + } + return CommonResult.success(commonData); + }else if("1026".equals(methodId)){ + String subjectName = request.get("subjectName"); + String locationName = request.get("locationName"); + if(StringUtils.isEmpty(subjectName)){ + return CommonResult.failed("用户名称不能为空!"); + } + if(StringUtils.isEmpty(locationName)){ + return CommonResult.failed("场所名称不能为空!"); + } + //当前对话的人物 + Person current = player.getPersonMap().get(player.getPersonId()); + Integer subjectId = player.getName2IdMap().get(subjectName); + Person subject =player.getPersonMap().get(subjectId); + + //查找符合条件的线索 + List clueList=findClues(current,subject,2); + if(clueList.size()==0){ + commonData.setId(102604); + commonData.setStatus("0"); + commonData.setText("不好意思,我不知道"); + }else{ + //检查是否符合阈值要求 + clueList=checkThreshold(current,clueList); + if(clueList.size()==0){ + commonData.setId(102603); + commonData.setStatus("0"); + commonData.setText("我又不认识你,为什么要告诉你?"); + }else{ + //查找符合条件的线索 + clueList=findClues(clueList,locationName); + if(clueList.size()==0){ + commonData.setId(102602); + commonData.setStatus("0"); + commonData.setText("不是,"+locationName); + }else{ + StringBuilder text = new StringBuilder(); + List demandTaskList = new ArrayList<>(); + for (Clue clue : clueList) { + DemandTask demandTask = findTasks(subject.getDemandTasks(), clue); + if (!StringUtils.isEmpty(demandTask)) { + if (demandTask.getClueSwitch() == 1 || demandTask.getClueSwitch() == -1) { + clue.setStatus(3); + text.append(clue.getClueTemplate() + ",可以解锁" + player.getPersonMap().get(subject.getId()).getName() + "的" + demandTask.getName() + "任务, "); + demandTaskList.add(demandTask); + } + } else { + clue.setStatus(2); + text.append(clue.getClueTemplate()); + } + } + commonData.setId(102601); + commonData.setStatus("1"); + commonData.setName("询问A是不是在某个场所"); + if(demandTaskList.size()>0){ + commonData.setDemandTaskList(demandTaskList); + }else{ + commonData.setDemandTaskList(new ArrayList<>()); + } + commonData.setText(text.toString()); + } + } + } + return CommonResult.success(commonData); + } + return CommonResult.failed("询问场所失败!"); + } + + + /** + * 询问提示 + * @param methodId + * @param player + * @param request + * @return + */ + public CommonResult askPrompt(String methodId,Player player, Map request){ + CommonData commonData = new CommonData(); + if("1027".equals(methodId)){ + String subjectName = request.get("subjectName"); + if(StringUtils.isEmpty(subjectName)){ + return CommonResult.failed("用户名称不能为空!"); + } + //当前对话的人物 + Person current = player.getPersonMap().get(player.getPersonId()); + Integer subjectId = player.getName2IdMap().get(subjectName); + Person subject =player.getPersonMap().get(subjectId); + //查找符合条件的线索 + List clueList=findClues(current,subject,5); + //检查是否符合阈值要求 + clueList= checkThreshold(current,clueList); + if(clueList.size()==0){ + commonData.setId(102702); + commonData.setStatus("0"); + commonData.setText("抱歉,爱莫能助"); + }else{ + int index = RandomUtil.randomInt(clueList.size()); + commonData.setId(102701); + commonData.setStatus("1"); + commonData.setName("询问提示"); + subject =player.getPersonMap().get(clueList.get(index).getSubject()); + commonData.setText("你可以去问问"+subject.getName()+",他可能知道点什么。"); + commonData.setDemandTaskList(new ArrayList<>()); + } + return CommonResult.success(commonData); + } + return CommonResult.failed("询问提示失败!"); + } + + + + + /** + * 执行任务 + * @param demandTask 任务 + * @param player 玩家 + * @return 通用信息 + */ + public CommonResult performTask(DemandTask demandTask,Player player){ + CommonData commonData = new CommonData(); + Person subject = player.getPersonMap().get(demandTask.getSubject()); + String taskConditionId =demandTask.getCondition1().split("\\|")[0]; + String methodId = ConditionMethod.get(taskConditionId).getMethodId(); + + /** + * 不涉及后置任务的方法 + */ + List list_1 = Arrays.asList("2001","2002","2003","2004","2005","2006","2007","2008","2009","2010","2011","2012","2013","2014","2015","2016","2017","2018","2019","2020","2021","2022","2023","2024","2030","2032","2034","2035","2037","2043","2044","2051","2052","2053","2054","2055","2057","2059","2060","2062","2063","2064","2065","2066","2067","2068","2069","2070","2071","2073","2074","2075","2076","2077","2078","2080"); + + /** + * 涉及含有后置任务的方法 + */ + List list_2 = Arrays.asList("2025","2026","2027","2028","2029","2031","2033","2036","2038","2039","2040","2041","2042","2056","2058","2061","2072","2079","2080","2081"); + + /** + * 自动完成任务的方法 + */ + List list_3 = Arrays.asList("2098"); + + if(list_1.contains(methodId)){ + //条件判断 + // 1. 判断是否满足货币消费条件 + String condition2 = demandTask.getCondition2(); + double value = 0.0; + if(!StringUtils.isEmpty(condition2)){ + value = Double.parseDouble(condition2); + if(player.getCurrency() < value){ + commonData.setId(Integer.valueOf(methodId+"03")); + commonData.setStatus("0"); + commonData.setName(demandTask.getName()); + return CommonResult.success(commonData); + } + } + + // 2. 判断是否符合阈值需求 + boolean flag = checkThreshold(demandTask,subject); + if(!flag){ + //不符合阈值需求 + commonData.setId(Integer.valueOf(methodId+"04")); + commonData.setStatus("0"); + commonData.setName(demandTask.getName()); + return CommonResult.success(commonData); + }else{ + //2.符合阈值需求,判断是否已达次数上限 + Map> taskMap= player.getTaskMap(); + if(taskMap.containsKey(subject.getId())){ + Map map =taskMap.get(subject.getId()); + if(map.containsKey(demandTask.getDemandTaskId())){ + int num = map.get(demandTask.getDemandTaskId()); + if(num >= demandTask.getEffectiveDegree()){ + //符合阈值需求,已达次数上限 + commonData.setId(Integer.valueOf(methodId+"02")); + commonData.setStatus("0"); + commonData.setName(demandTask.getName()); + }else{ + // 3.信任阈值提升 + map.put(demandTask.getDemandTaskId(),num+1); + int trustDegree = subject.getTrustDegree(); + int deterrenceDegree = subject.getDeterrenceDegree(); + double currency = player.getCurrency(); + addThreshold(subject,demandTask); + if(value>0){ + player.setCurrency(currency-value); + } + if(!StringUtils.isEmpty(demandTask.getCompletionReward())){ + player.setCurrency(player.getCurrency()+Double.parseDouble(demandTask.getCompletionReward())); + } + commonData.setId(Integer.valueOf(methodId+"01")); + commonData.setStatus("1"); + commonData.setName(demandTask.getName()); + commonData.setText("信任值由原来的:"+trustDegree+"变为"+subject.getTrustDegree()+",货币由原来的"+currency+"变为"+player.getCurrency()+",威慑度由原来的"+deterrenceDegree+"变为"+subject.getDeterrenceDegree()); + } + }else{ + // 3.信任阈值提升 + map.put(demandTask.getDemandTaskId(),1); + int trustDegree = subject.getTrustDegree(); + int deterrenceDegree = subject.getDeterrenceDegree(); + double currency = player.getCurrency(); + addThreshold(subject,demandTask); + if(value > 0){ + player.setCurrency(currency-value); + } + if(!StringUtils.isEmpty(demandTask.getCompletionReward())){ + player.setCurrency(player.getCurrency()+Double.parseDouble(demandTask.getCompletionReward())); + } + commonData.setId(Integer.valueOf(methodId+"01")); + commonData.setStatus("1"); + commonData.setName(demandTask.getName()); + commonData.setText("信任值由原来的:"+trustDegree+"变为"+subject.getTrustDegree()+",货币由原来的"+currency+"变为"+player.getCurrency()+",威慑度由原来的"+deterrenceDegree+"变为"+subject.getDeterrenceDegree()); + } + return CommonResult.success(commonData); + } + } + }else if(list_2.contains(methodId)){ + //条件判断 + // 1. 判断是否符合阈值需求 + boolean flag = checkThreshold(demandTask,subject); + if(!flag){ + //不符合阈值需求 + commonData.setId(Integer.valueOf(methodId+"04")); + commonData.setStatus("0"); + commonData.setName(demandTask.getName()); + return CommonResult.success(commonData); + }else{ + Map> taskMap= player.getTaskMap(); + //2.符合阈值需求,判断是否完成后置任务 + if(taskMap.containsKey(subject.getId())){ + Map subjectMap =taskMap.get(subject.getId()); + if(subjectMap.containsKey(demandTask.getDemandTaskId())){ + int num = subjectMap.get(demandTask.getDemandTaskId()); + if(num >= demandTask.getEffectiveDegree()){ + //符合阈值需求,已达次数上限 + commonData.setId(Integer.valueOf(methodId+"02")); + commonData.setStatus("0"); + commonData.setName(demandTask.getName()); + }else{ + String[] postTasks = demandTask.getPostTask().split("\\|"); + Integer objectId = demandTask.getObject(); + Map objectMap =taskMap.get(objectId); + for(String postTask:postTasks){ + if(objectMap.containsKey(Integer.valueOf(postTask))){ + subjectMap.put(demandTask.getDemandTaskId(),num+1); + int trustDegree = subject.getTrustDegree(); + int deterrenceDegree = subject.getDeterrenceDegree(); + double currency = player.getCurrency(); + addThreshold(subject,demandTask); + if(!StringUtils.isEmpty(demandTask.getCompletionReward())){ + player.setCurrency(player.getCurrency()+Double.parseDouble(demandTask.getCompletionReward())); + } + commonData.setId(Integer.valueOf(methodId+"01")); + commonData.setStatus("1"); + commonData.setName(demandTask.getName()); + commonData.setText("信任值由原来的:"+trustDegree+"变为"+subject.getTrustDegree()+",货币由原来的"+currency+"变为"+player.getCurrency()+",威慑度由原来的"+deterrenceDegree+"变为"+subject.getDeterrenceDegree()); + return CommonResult.success(commonData); + } + } + //符合阈值需求,后置任务没有完成 + commonData.setId(Integer.valueOf(methodId+"03")); + commonData.setStatus("0"); + commonData.setName(demandTask.getName()); + } + }else{ + String[] postTasks = demandTask.getPostTask().split("\\|"); + Integer objectId = demandTask.getObject(); + Map objectMap =taskMap.get(objectId); + for(String postTask:postTasks){ + if(objectMap.containsKey(Integer.valueOf(postTask))){ + subjectMap.put(demandTask.getDemandTaskId(),1); + int trustDegree = subject.getTrustDegree(); + int deterrenceDegree = subject.getDeterrenceDegree(); + double currency = player.getCurrency(); + addThreshold(subject,demandTask); + if(!StringUtils.isEmpty(demandTask.getCompletionReward())){ + player.setCurrency(player.getCurrency()+Double.parseDouble(demandTask.getCompletionReward())); + } + commonData.setId(Integer.valueOf(methodId+"01")); + commonData.setStatus("1"); + commonData.setName(demandTask.getName()); + commonData.setText("信任值由原来的:"+trustDegree+"变为"+subject.getTrustDegree()+",货币由原来的"+currency+"变为"+player.getCurrency()+",威慑度由原来的"+deterrenceDegree+"变为"+subject.getDeterrenceDegree()); + return CommonResult.success(commonData); + } + } + //符合阈值需求,后置任务没有完成 + commonData.setId(Integer.valueOf(methodId+"03")); + commonData.setStatus("0"); + commonData.setName(demandTask.getName()); + } + return CommonResult.success(commonData); + } + } + }else if (list_3.contains(methodId)){ + if(StringUtils.isEmpty(demandTask.getPostTask())){ + //条件判断 + // 1. 判断是否满足货币消费条件 + String condition2 = demandTask.getCondition2(); + double value = 0.0; + if(!StringUtils.isEmpty(condition2)){ + value = Double.parseDouble(condition2); + if(player.getCurrency() < value){ + commonData.setId(Integer.valueOf(methodId+"04")); + commonData.setStatus("0"); + commonData.setName(demandTask.getName()); + return CommonResult.success(commonData); + } + } + + // 2. 判断是否符合阈值需求 + boolean flag = checkThreshold(demandTask,subject); + if(!flag){ + //不符合阈值需求 + commonData.setId(Integer.valueOf(methodId+"03")); + commonData.setStatus("0"); + commonData.setName(demandTask.getName()); + return CommonResult.success(commonData); + }else{ + //2.符合阈值需求,判断是否已达次数上限 + Map> taskMap= player.getTaskMap(); + if(taskMap.containsKey(subject.getId())){ + Map map =taskMap.get(subject.getId()); + if(map.containsKey(demandTask.getDemandTaskId())){ + int num = map.get(demandTask.getDemandTaskId()); + if(num >= demandTask.getEffectiveDegree()){ + //符合阈值需求,已达次数上限 + commonData.setId(Integer.valueOf(methodId+"02")); + commonData.setStatus("0"); + commonData.setName(demandTask.getName()); + }else{ + // 3.阈值改变 + map.put(demandTask.getDemandTaskId(),num+1); + int trustDegree = subject.getTrustDegree(); + int deterrenceDegree = subject.getDeterrenceDegree(); + double currency = player.getCurrency(); + addThreshold(subject,demandTask); + if(value>0){ + player.setCurrency(currency-value); + } + if(!StringUtils.isEmpty(demandTask.getCompletionReward())){ + player.setCurrency(player.getCurrency()+Double.parseDouble(demandTask.getCompletionReward())); + } + commonData.setId(Integer.valueOf(methodId+"01")); + commonData.setStatus("1"); + commonData.setName(demandTask.getName()); + commonData.setText("信任值由原来的:"+trustDegree+"变为"+subject.getTrustDegree()+",货币由原来的"+currency+"变为"+player.getCurrency()+",威慑度由原来的"+deterrenceDegree+"变为"+subject.getDeterrenceDegree()); + } + }else{ + // 3.阈值改变 + map.put(demandTask.getDemandTaskId(),1); + int trustDegree = subject.getTrustDegree(); + int deterrenceDegree = subject.getDeterrenceDegree(); + double currency = player.getCurrency(); + addThreshold(subject,demandTask); + if(value>0){ + player.setCurrency(currency-value); + } + if(!StringUtils.isEmpty(demandTask.getCompletionReward())){ + player.setCurrency(player.getCurrency()+Double.parseDouble(demandTask.getCompletionReward())); + } + commonData.setId(Integer.valueOf(methodId+"01")); + commonData.setStatus("1"); + commonData.setName(demandTask.getName()); + commonData.setText("信任值由原来的:"+trustDegree+"变为"+subject.getTrustDegree()+",货币由原来的"+currency+"变为"+player.getCurrency()+",威慑度由原来的"+deterrenceDegree+"变为"+subject.getDeterrenceDegree()); + } + return CommonResult.success(commonData); + } + } + }else{ + //条件判断 + // 1. 判断是否符合阈值需求 + boolean flag = checkThreshold(demandTask,subject); + if(!flag){ + //不符合阈值需求 + commonData.setId(Integer.parseInt(methodId+"04")); + commonData.setStatus("0"); + commonData.setName(demandTask.getName()); + return CommonResult.success(commonData); + }else{ + Map> taskMap= player.getTaskMap(); + //2.符合阈值需求,判断是否完成后置任务 + if(taskMap.containsKey(subject.getId())){ + Map subjectMap =taskMap.get(subject.getId()); + if(subjectMap.containsKey(demandTask.getDemandTaskId())){ + int num = subjectMap.get(demandTask.getDemandTaskId()); + if(num >= demandTask.getEffectiveDegree()){ + //符合阈值需求,已达次数上限 + commonData.setId(Integer.valueOf(methodId+"02")); + commonData.setStatus("0"); + commonData.setName(demandTask.getName()); + }else{ + Map objectMap =taskMap.get(demandTask.getObject()); + if(objectMap.containsKey(Integer.valueOf(demandTask.getPostTask()))){ + subjectMap.put(demandTask.getDemandTaskId(),num+1); + int trustDegree = subject.getTrustDegree(); + int deterrenceDegree = subject.getDeterrenceDegree(); + double currency = player.getCurrency(); + addThreshold(subject,demandTask); + if(!StringUtils.isEmpty(demandTask.getCompletionReward())){ + player.setCurrency(player.getCurrency()+Double.parseDouble(demandTask.getCompletionReward())); + } + commonData.setId(Integer.valueOf(methodId+"01")); + commonData.setStatus("1"); + commonData.setName(demandTask.getName()); + commonData.setText("信任值由原来的:"+trustDegree+"变为"+subject.getTrustDegree()+",货币由原来的"+currency+"变为"+player.getCurrency()+",威慑度由原来的"+deterrenceDegree+"变为"+subject.getDeterrenceDegree()); + }else{ + //符合阈值需求,后置任务没有完成 + commonData.setId(Integer.valueOf(methodId+"03")); + commonData.setStatus("0"); + commonData.setName(demandTask.getName()); + } + } + }else{ + Map objectMap =taskMap.get(demandTask.getObject()); + if(objectMap.containsKey(Integer.valueOf(demandTask.getPostTask()))){ + subjectMap.put(demandTask.getDemandTaskId(),1); + int trustDegree = subject.getTrustDegree(); + int deterrenceDegree = subject.getDeterrenceDegree(); + double currency = player.getCurrency(); + addThreshold(subject,demandTask); + if(!StringUtils.isEmpty(demandTask.getCompletionReward())){ + player.setCurrency(player.getCurrency()+Double.parseDouble(demandTask.getCompletionReward())); + } + commonData.setId(Integer.valueOf(methodId+"01")); + commonData.setStatus("1"); + commonData.setName(demandTask.getName()); + commonData.setText("信任值由原来的:"+trustDegree+"变为"+subject.getTrustDegree()+",货币由原来的"+currency+"变为"+player.getCurrency()+",威慑度由原来的"+deterrenceDegree+"变为"+subject.getDeterrenceDegree()); + }else{ + //符合阈值需求,后置任务没有完成 + commonData.setId(Integer.valueOf(methodId+"03")); + commonData.setStatus("0"); + commonData.setName(demandTask.getName()); + } + } + return CommonResult.success(commonData); + } + } + } + } + return CommonResult.failed("任务执行失败!"+taskConditionId); + } + + + /** + * 查询符合条件的任务 + * @param person 人物 + * @param taskName 任务名称 + * @return 任务列表 + */ + private List findTasks(Person person,String taskName){ + List result = new ArrayList<>(); + if(!StringUtils.isEmpty(person)){ + for (DemandTask demandTask : person.getDemandTasks()) { + if (demandTask.getType() == 6 && taskName.equals(demandTask.getName())) { + result.add(demandTask); + } + } + } + return result; + } + + + /** + * 查询符合条件的任务 + * @param person 人物 + * @param type 1 信任度提升 2 信任度降低 3 威慑度提升 4 威慑度降低 + * @return 任务列表 + */ + private List findTasks(Person person,Integer type){ + List result = new ArrayList<>(); + if(!StringUtils.isEmpty(person)){ + for (DemandTask demandTask : person.getDemandTasks()) { + if (demandTask.getType() == 6 && demandTask.getSubject() == person.getId()) { + if (type == 1) { + int trustDegree = demandTask.getTrustDegree(); + if (trustDegree > 0) { + result.add(demandTask); + } + } else if (type == 2) { + int trustDegree = demandTask.getTrustDegree(); + if (trustDegree < 0) { + result.add(demandTask); + } + } else if (type == 3) { + int deterrenceDegree = demandTask.getDeterrenceDegree(); + if (deterrenceDegree > 0) { + result.add(demandTask); + } + } else if (type == 4) { + int deterrenceDegree = demandTask.getDeterrenceDegree(); + if (deterrenceDegree < 0) { + result.add(demandTask); + } + } + } + } + } + return result; + } + + + /** + * 查询符合条件的任务 + * @param demandTaskList 任务列表 + * @param taskName 任务名称 + * @return 任务列表 + */ + private List findTasks(List demandTaskList ,String taskName){ + List result = new ArrayList<>(); + for (DemandTask demandTask : demandTaskList) { + if (Objects.equals(demandTask.getName(), taskName)) { + result.add(demandTask); + } + } + return result; + } + + /** + * 查询符合条件的任务 + * @param demandTaskList 任务列表 + * @param clue 线索 + * @return 任务 + */ + private DemandTask findTasks(List demandTaskList ,Clue clue){ + DemandTask result = null; + for (DemandTask demandTask : demandTaskList) { + if (demandTask.getClueId() == clue.getClueId() && demandTask.getType() == clue.getType()) { + result = demandTask; + break; + } + } + if(!StringUtils.isEmpty(result)){ + for (DemandTask demandTask:demandTaskList){ + if(demandTask.getDemandTaskId()==result.getDemandTaskId()&&demandTask.getType()==6&&result.getSubject()==demandTask.getSubject()){ + return demandTask; + } + } + } + return null; + } + + + /** + * 根据任务查询符合条件的线索 + * @param current 当前的人物 + * @return List 线索列表 + */ + private List findClues(List demandTaskList,Person current){ + List result = new ArrayList<>(); + if(!StringUtils.isEmpty(current)){ + List clueList =findClues(current,6); + for (Clue clue : clueList) { + for (DemandTask demandTask : demandTaskList) { + if (clue.getType() == 6 && clue.getClueId() == demandTask.getClueId() && clue.getSubject() == demandTask.getSubject()) { + result.add(clue); + } + } + } + } + return result; + } + + /** + * 查询符合条件的线索 + * @param current 当前对话人物 + * @param type 线索类型 + * @return List 线索列表 + */ + private List findClues(Person current,int type){ + List result = new ArrayList<>(); + if(!StringUtils.isEmpty(current)){ + for (Clue clue : current.getClues()) { + if (clue.getType() == type) { + result.add(clue); + } + } + } + return result; + } + + + /** + * 查询符合条件的线索 + * @param current 当前对话人物 + * @param subject 人物 + * @param type 线索类型 + * @return List 线索列表 + */ + private List findClues(Person current,Person subject,int type){ + List result = new ArrayList<>(); + if(!StringUtils.isEmpty(current)){ + for (Clue clue : current.getClues()) { + if (clue.getType() == type && clue.getSubject() == subject.getId()) { + result.add(clue); + } + } + } + return result; + } + + + /** + * 查询符合条件的线索 + * @param subject 主体人物 + * @param object 客体人物 + * @param type 线索类型 + * @return List 线索列表 + */ + private List findClues(Person current,Person subject,Person object,int type){ + List result = new ArrayList<>(); + if(!StringUtils.isEmpty(subject)&&!StringUtils.isEmpty(object)){ + for (Clue clue : current.getClues()) { + if (clue.getType() == type) { + if (subject.getId() == clue.getSubject() && object.getId() == clue.getObject()) { + result.add(clue); + } + } + } + } + return result; + } + + /** + * 查询符合条件的线索 + * @param clueName 线索名称 + * @return List 线索列表 + */ + private List findClues(List clueList,String clueName){ + List result = new ArrayList<>(); + if (!StringUtils.isEmpty(clueName)) { + for (Clue clue : clueList) { + if (!clueName.equals(clue.getClueName())) { + continue; + } + result.add(clue); + } + } + return result; + } + + /** + * 线索判断是否符合阈值需求 + * @param person 人物 + * @param clueList 线索列表 + * @return List 线索列表 + */ + private List checkThreshold(Person person, List clueList){ + List result = new ArrayList<>(); + for (Clue clue : clueList) { + //符合阈值要求 + if (person.getTrustDegree() >= clue.getTrustDegree() || person.getDeterrenceDegree() >= clue.getDeterrenceDegree()) { + result.add(clue); + } + } + return result; + } + + /** + * 任务判断是否符合阈值需求 + * @param demandTask 任务 + * @param subject 人物 + * @return 布尔值 + */ + private boolean checkThreshold(DemandTask demandTask,Person subject){ + boolean flag = false; + if(demandTask.getTrustStart() >= 0 && demandTask.getTrustEnd() > 0){ + if(demandTask.getTrustStart()<=subject.getTrustDegree()&&subject.getTrustDegree()<=demandTask.getTrustEnd()){ + flag = true; + } + } + + if(demandTask.getDeterrenceStart() >= 0 && demandTask.getDeterrenceEnd() > 0){ + if(demandTask.getDeterrenceStart() <= subject.getDeterrenceDegree() && subject.getDeterrenceDegree() <= demandTask.getDeterrenceEnd()){ + flag = true; + } + } + return flag; + } + + /** + * 新增阈值 + * @param subject 人物 + * @param demandTask 任务 + */ + private void addThreshold(Person subject,DemandTask demandTask){ + if(demandTask.getTrustDegree()!=0){ + if(subject.getTrustDegree() < 100) { + subject.setTrustDegree(Math.max(Math.min((subject.getTrustDegree() + demandTask.getTrustDegree()), 100),0)); + } + } + if(demandTask.getDeterrenceDegree()!=0){ + if(subject.getDeterrenceDegree() < 100) { + subject.setDeterrenceDegree(Math.max(Math.min((subject.getDeterrenceDegree() + demandTask.getDeterrenceDegree()), 100),0)); + } + } + } +} \ No newline at end of file diff --git b/src/main/java/com/qiwu/inference/common/api/CommonData.java a/src/main/java/com/qiwu/inference/common/api/CommonData.java new file mode 100644 index 0000000..6af6b29 --- /dev/null +++ a/src/main/java/com/qiwu/inference/common/api/CommonData.java @@ -0,0 +1,39 @@ +package com.qiwu.inference.common.api; + +import com.qiwu.inference.auto.pojo.Clue; +import com.qiwu.inference.auto.pojo.DemandTask; +import lombok.Getter; +import lombok.Setter; + +import java.util.List; + +@Getter +@Setter +public class CommonData { + private Integer id; + + private String name; + + private Integer type; + + private Integer subject; + + private String status; + private String aside; + private String text; + + private List demandTaskList; + + private List clueList; + + + public CommonData(){ + + } + public CommonData(Integer id,String text,String aside){ + this.id = id; + this.aside = aside; + this.text = text; + } + +} diff --git b/src/main/java/com/qiwu/inference/common/api/CommonPage.java a/src/main/java/com/qiwu/inference/common/api/CommonPage.java new file mode 100644 index 0000000..3b97209 --- /dev/null +++ a/src/main/java/com/qiwu/inference/common/api/CommonPage.java @@ -0,0 +1,34 @@ +package com.qiwu.inference.common.api; + +import cn.hutool.core.convert.Convert; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import lombok.Getter; +import lombok.Setter; + +import java.util.List; + +/** + * 分页数据封装类 + */ +@Getter +@Setter +public class CommonPage { + private Integer pageNum; + private Integer pageSize; + private Integer totalPage; + private Long total; + private List list; + + /** + * 将MyBatis Plus 分页结果转化为通用结果 + */ + public static CommonPage restPage(Page pageResult) { + CommonPage result = new CommonPage<>(); + result.setPageNum(Convert.toInt(pageResult.getCurrent())); + result.setPageSize(Convert.toInt(pageResult.getSize())); + result.setTotal(pageResult.getTotal()); + result.setTotalPage(Convert.toInt(pageResult.getTotal()/pageResult.getSize()+1)); + result.setList(pageResult.getRecords()); + return result; + } +} diff --git b/src/main/java/com/qiwu/inference/common/api/CommonResult.java a/src/main/java/com/qiwu/inference/common/api/CommonResult.java new file mode 100644 index 0000000..53494c5 --- /dev/null +++ a/src/main/java/com/qiwu/inference/common/api/CommonResult.java @@ -0,0 +1,106 @@ +package com.qiwu.inference.common.api; + +import lombok.Getter; +import lombok.Setter; + +/** + * 通用返回对象 + */ + +@Getter +@Setter +public class CommonResult { + private long code; + private String message; + private T data; + + protected CommonResult() { + } + + protected CommonResult(long code, String message, T data) { + this.code = code; + this.message = message; + this.data = data; + } + + /** + * 成功返回结果 + * + * @param data 获取的数据 + */ + public static CommonResult success(T data) { + return new CommonResult(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(), data); + } + + /** + * 成功返回结果 + * + * @param data 获取的数据 + * @param message 提示信息 + */ + public static CommonResult success(T data, String message) { + return new CommonResult(ResultCode.SUCCESS.getCode(), message, data); + } + + /** + * 失败返回结果 + * @param errorCode 错误码 + */ + public static CommonResult failed(IErrorCode errorCode) { + return new CommonResult(errorCode.getCode(), errorCode.getMessage(), null); + } + + /** + * 失败返回结果 + * @param errorCode 错误码 + * @param message 错误信息 + */ + public static CommonResult failed(IErrorCode errorCode,String message) { + return new CommonResult(errorCode.getCode(), message, null); + } + + /** + * 失败返回结果 + * @param message 提示信息 + */ + public static CommonResult failed(String message) { + return new CommonResult(ResultCode.FAILED.getCode(), message, null); + } + + /** + * 失败返回结果 + */ + public static CommonResult failed() { + return failed(ResultCode.FAILED); + } + + /** + * 参数验证失败返回结果 + */ + public static CommonResult validateFailed() { + return failed(ResultCode.VALIDATE_FAILED); + } + + /** + * 参数验证失败返回结果 + * @param message 提示信息 + */ + public static CommonResult validateFailed(String message) { + return new CommonResult(ResultCode.VALIDATE_FAILED.getCode(), message, null); + } + + /** + * 未登录返回结果 + */ + public static CommonResult unauthorized(T data) { + return new CommonResult(ResultCode.UNAUTHORIZED.getCode(), ResultCode.UNAUTHORIZED.getMessage(), data); + } + + /** + * 未授权返回结果 + */ + public static CommonResult forbidden(T data) { + return new CommonResult(ResultCode.FORBIDDEN.getCode(), ResultCode.FORBIDDEN.getMessage(), data); + } + +} diff --git b/src/main/java/com/qiwu/inference/common/api/IErrorCode.java a/src/main/java/com/qiwu/inference/common/api/IErrorCode.java new file mode 100644 index 0000000..45cb45d --- /dev/null +++ a/src/main/java/com/qiwu/inference/common/api/IErrorCode.java @@ -0,0 +1,10 @@ +package com.qiwu.inference.common.api; + +/** + * 封装API的错误码 + */ +public interface IErrorCode { + long getCode(); + + String getMessage(); +} diff --git b/src/main/java/com/qiwu/inference/common/api/ResultCode.java a/src/main/java/com/qiwu/inference/common/api/ResultCode.java new file mode 100644 index 0000000..4c7f979 --- /dev/null +++ a/src/main/java/com/qiwu/inference/common/api/ResultCode.java @@ -0,0 +1,29 @@ +package com.qiwu.inference.common.api; + + +/** + * 枚举了一些常用API操作码 + */ + +public enum ResultCode implements IErrorCode { + SUCCESS(200, "操作成功"), + FAILED(500, "操作失败"), + VALIDATE_FAILED(404, "参数检验失败"), + UNAUTHORIZED(401, "暂未登录或token已经过期"), + FORBIDDEN(403, "没有相关权限"); + private long code; + private String message; + + private ResultCode(long code, String message) { + this.code = code; + this.message = message; + } + + public long getCode() { + return code; + } + + public String getMessage() { + return message; + } +} diff --git b/src/main/java/com/qiwu/inference/common/config/BaseSwaggerConfig.java a/src/main/java/com/qiwu/inference/common/config/BaseSwaggerConfig.java new file mode 100644 index 0000000..259d135 --- /dev/null +++ a/src/main/java/com/qiwu/inference/common/config/BaseSwaggerConfig.java @@ -0,0 +1,80 @@ +package com.qiwu.inference.common.config; + +import com.qiwu.inference.common.domain.SwaggerProperties; +import org.springframework.context.annotation.Bean; +import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.service.*; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spi.service.contexts.SecurityContext; +import springfox.documentation.spring.web.plugins.Docket; + +import java.util.ArrayList; +import java.util.List; + +/** + * Swagger基础配置 + */ +public abstract class BaseSwaggerConfig { + + @Bean + public Docket createRestApi() { + SwaggerProperties swaggerProperties = swaggerProperties(); + Docket docket = new Docket(DocumentationType.SWAGGER_2) + .apiInfo(apiInfo(swaggerProperties)) + .select() + .apis(RequestHandlerSelectors.basePackage(swaggerProperties.getApiBasePackage())) + .paths(PathSelectors.any()) + .build(); + if (swaggerProperties.isEnableSecurity()) { + docket.securitySchemes(securitySchemes()).securityContexts(securityContexts()); + } + return docket; + } + + private ApiInfo apiInfo(SwaggerProperties swaggerProperties) { + return new ApiInfoBuilder() + .title(swaggerProperties.getTitle()) + .description(swaggerProperties.getDescription()) + .contact(new Contact(swaggerProperties.getContactName(), swaggerProperties.getContactUrl(), swaggerProperties.getContactEmail())) + .version(swaggerProperties.getVersion()) + .build(); + } + + private List securitySchemes() { + //设置请求头信息 + List result = new ArrayList<>(); + ApiKey apiKey = new ApiKey("Authorization", "Authorization", "header"); + result.add(apiKey); + return result; + } + + private List securityContexts() { + //设置需要登录认证的路径 + List result = new ArrayList<>(); + result.add(getContextByPath("/*/.*")); + return result; + } + + private SecurityContext getContextByPath(String pathRegex) { + return SecurityContext.builder() + .securityReferences(defaultAuth()) + .forPaths(PathSelectors.regex(pathRegex)) + .build(); + } + + private List defaultAuth() { + List result = new ArrayList<>(); + AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything"); + AuthorizationScope[] authorizationScopes = new AuthorizationScope[1]; + authorizationScopes[0] = authorizationScope; + result.add(new SecurityReference("Authorization", authorizationScopes)); + return result; + } + + /** + * 自定义Swagger配置 + */ + public abstract SwaggerProperties swaggerProperties(); +} diff --git b/src/main/java/com/qiwu/inference/common/domain/SwaggerProperties.java a/src/main/java/com/qiwu/inference/common/domain/SwaggerProperties.java new file mode 100644 index 0000000..3c1a07d --- /dev/null +++ a/src/main/java/com/qiwu/inference/common/domain/SwaggerProperties.java @@ -0,0 +1,46 @@ +package com.qiwu.inference.common.domain; + +import lombok.Builder; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * Swagger自定义配置 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@Builder +public class SwaggerProperties { + /** + * API文档生成基础路径 + */ + private String apiBasePackage; + /** + * 是否要启用登录认证 + */ + private boolean enableSecurity; + /** + * 文档标题 + */ + private String title; + /** + * 文档描述 + */ + private String description; + /** + * 文档版本 + */ + private String version; + /** + * 文档联系人姓名 + */ + private String contactName; + /** + * 文档联系人网址 + */ + private String contactUrl; + /** + * 文档联系人邮箱 + */ + private String contactEmail; +} diff --git b/src/main/java/com/qiwu/inference/common/exception/ApiException.java a/src/main/java/com/qiwu/inference/common/exception/ApiException.java new file mode 100644 index 0000000..809d777 --- /dev/null +++ a/src/main/java/com/qiwu/inference/common/exception/ApiException.java @@ -0,0 +1,33 @@ +package com.qiwu.inference.common.exception; + + +import com.qiwu.inference.common.api.IErrorCode; +import lombok.Getter; +import lombok.Setter; + +/** + * 自定义API异常 + */ +@Getter +@Setter +public class ApiException extends RuntimeException { + private IErrorCode errorCode; + + public ApiException(IErrorCode errorCode) { + super(errorCode.getMessage()); + this.errorCode = errorCode; + } + + public ApiException(String message) { + super(message); + } + + public ApiException(Throwable cause) { + super(cause); + } + + public ApiException(String message, Throwable cause) { + super(message, cause); + } + +} diff --git b/src/main/java/com/qiwu/inference/common/exception/Asserts.java a/src/main/java/com/qiwu/inference/common/exception/Asserts.java new file mode 100644 index 0000000..1263894 --- /dev/null +++ a/src/main/java/com/qiwu/inference/common/exception/Asserts.java @@ -0,0 +1,17 @@ +package com.qiwu.inference.common.exception; + + +import com.qiwu.inference.common.api.IErrorCode; + +/** + * 断言处理类,用于抛出各种API异常 + */ +public class Asserts { + public static void fail(String message) { + throw new ApiException(message); + } + + public static void fail(IErrorCode errorCode) { + throw new ApiException(errorCode); + } +} diff --git b/src/main/java/com/qiwu/inference/common/exception/GlobalExceptionHandler.java a/src/main/java/com/qiwu/inference/common/exception/GlobalExceptionHandler.java new file mode 100644 index 0000000..cabc24b --- /dev/null +++ a/src/main/java/com/qiwu/inference/common/exception/GlobalExceptionHandler.java @@ -0,0 +1,54 @@ +package com.qiwu.inference.common.exception; + +import com.qiwu.inference.common.api.CommonResult; +import org.springframework.validation.BindException; +import org.springframework.validation.BindingResult; +import org.springframework.validation.FieldError; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseBody; + +/** + * 全局异常处理 + */ +@ControllerAdvice +public class GlobalExceptionHandler { + + @ResponseBody + @ExceptionHandler(value = ApiException.class) + public CommonResult handle(ApiException e) { + if (e.getErrorCode() != null) { + return CommonResult.failed(e.getErrorCode()); + } + return CommonResult.failed(e.getMessage()); + } + + @ResponseBody + @ExceptionHandler(value = MethodArgumentNotValidException.class) + public CommonResult handleValidException(MethodArgumentNotValidException e) { + BindingResult bindingResult = e.getBindingResult(); + String message = null; + if (bindingResult.hasErrors()) { + FieldError fieldError = bindingResult.getFieldError(); + if (fieldError != null) { + message = fieldError.getField()+fieldError.getDefaultMessage(); + } + } + return CommonResult.validateFailed(message); + } + + @ResponseBody + @ExceptionHandler(value = BindException.class) + public CommonResult handleValidException(BindException e) { + BindingResult bindingResult = e.getBindingResult(); + String message = null; + if (bindingResult.hasErrors()) { + FieldError fieldError = bindingResult.getFieldError(); + if (fieldError != null) { + message = fieldError.getField()+fieldError.getDefaultMessage(); + } + } + return CommonResult.validateFailed(message); + } +} diff --git b/src/main/java/com/qiwu/inference/config/MyBatisConfig.java a/src/main/java/com/qiwu/inference/config/MyBatisConfig.java new file mode 100644 index 0000000..973f016 --- /dev/null +++ a/src/main/java/com/qiwu/inference/config/MyBatisConfig.java @@ -0,0 +1,26 @@ +package com.qiwu.inference.config; + +import com.baomidou.mybatisplus.annotation.DbType; +import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; +import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +/** + * MyBatis配置类 + */ +@Configuration +@EnableTransactionManagement +@MapperScan({"com.qiwu.inference.dao"}) +public class MyBatisConfig { + + @Bean + public MybatisPlusInterceptor mybatisPlusInterceptor() { + MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); + interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); + return interceptor; + } + +} diff --git b/src/main/java/com/qiwu/inference/controller/PersonRecordController.java a/src/main/java/com/qiwu/inference/controller/PersonRecordController.java new file mode 100644 index 0000000..1971c59 --- /dev/null +++ a/src/main/java/com/qiwu/inference/controller/PersonRecordController.java @@ -0,0 +1,1659 @@ +package com.qiwu.inference.controller; + +import cn.hutool.core.lang.UUID; +import cn.hutool.core.util.NumberUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.ReUtil; +import com.qiwu.inference.common.api.CommonResult; +import com.qiwu.inference.pojo.*; +import com.qiwu.inference.service.*; +import com.qiwu.inference.util.*; +import org.apache.commons.io.FileUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.util.StringUtils; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import java.io.File; +import java.io.IOException; +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.util.*; + +/** + *

+ * 前端控制器 + *

+ * + * @author xingxing.ye + * @since 2022-11-02 + */ +@RestController +@RequestMapping("/api/personRecord") +public class PersonRecordController { + + @Autowired + public EndGoalService endGoalService; + + @Autowired + public KeyClueService keyClueService; + + @Autowired + public IdentityService identityService; + + @Autowired + public PersonService personService; + + @Autowired + public PersonRecordService personRecordService; + + @Autowired + public RelationService relationService; + + @Autowired + public DispositionService dispositionService; + + @Autowired + public DispositionTypeService dispositionTypeService; + + @Autowired + public RelationRecordService relationRecordService; + + @Autowired + public RelationTypeService relationTypeService; + @Autowired + public BehaviourService behaviourService; + @Autowired + public BehaviourRecordService behaviourRecordService; + + @Autowired + public ClueRecordService clueRecordService; + + @Autowired + public LocationService locationService; + + @Autowired + public DemandTaskService demandTaskService; + + @Autowired + public DemandTaskRecordService demandTaskRecordService; + + @Autowired + public DispositionRecordService dispositionRecordService; + + @Autowired + public ClueService clueService; + + private final static String ZIP_FILE = "application/zip"; + private final static String RAR_FILE = "application/vnd.rar"; + + @PostMapping("/import") + public CommonResult importZipFile(@RequestBody MultipartFile uploadFile) { + boolean isZipPack = true; + // 解压目录 + String packageFileStr = FileUtil.getPath() + "file" + File.separator + "zip"; + + //不存在则创建 + File packFile = new File(packageFileStr); + if (!packFile.exists()) { + boolean mkdirs = packFile.mkdirs(); + if (!mkdirs) { + throw new RuntimeException("文件夹创建失败!"); + } + } + if (uploadFile == null) { + throw new RuntimeException("请上传文件!"); + } + String contentType = uploadFile.getContentType(); + String filename = uploadFile.getOriginalFilename(); + //将压缩包保存在指定路径 + String packageFilePath = packageFileStr + File.separator + filename; + if (ZIP_FILE.equals(contentType)) { + //zip解压缩处理 + } else if (RAR_FILE.equals(contentType)) { + //rar解压缩处理 + isZipPack = false; + } else { + throw new RuntimeException("上传的压缩包格式不正确,仅支持rar和zip压缩文件!"); + } + File file = new File(packageFilePath); + try { + uploadFile.transferTo(file); + } catch (IOException e) { + e.printStackTrace(); + throw new RuntimeException("压缩文件到:" + packageFileStr + " 失败!"); + } + if (isZipPack) { + //zip压缩包 + UnPackageUtil.unPackageZip(file, null, packageFileStr); + } else { + //rar压缩包 + UnPackageUtil.unPackageRar(file, packageFileStr); + } + file.delete(); + //获取压缩包名称 + assert filename != null; + filename = filename.substring(0, filename.lastIndexOf(".")); + System.out.println("解压成功,解压目录:" + packageFilePath); + //可以根据解压路径、压缩包名称、文件名称,取出对应文件进行操作 + return CommonResult.success(filename); + } + + @RequestMapping(value = "/view_all", method = RequestMethod.POST) + @ResponseBody + public CommonResult>> view_all() throws Exception { + List gateNoList = personRecordService.getGateNo(); + Map> map = new HashMap<>(); + + String filePath = FileUtil.getPath() + "file" + File.separator + "results.txt"; + + for (String gateNo : gateNoList) { + List personRecordList = personRecordService.getPersonRecords(gateNo); + List personList = new ArrayList<>(); + for (PersonRecord p : personRecordList) { + com.qiwu.inference.auto.pojo.Person person = new com.qiwu.inference.auto.pojo.Person(); + BeanUtil.copyProperties(p, person); + + List list = new ArrayList<>(); + //人物的基本情况 + list.add(String.format("姓名:%s,(%s)", p.getName(), p.getIsKey() == 1 ? "关键人物" : "普通人物")); + list.add(String.format("身份:%s", p.getIdentityName())); + if (p.getGender() == 1) { + list.add(String.format("性别:%s", "男")); + } else { + list.add(String.format("性别:%s", "女")); + } + list.add(String.format("年龄:%s", p.getAge())); + //查询性格 + list.add(String.format("性格:%s", p.getDisposition())); + //查询关系 + list.add(String.format("正向关系:\n %s", convertRelation(p.getId()))); + list.add(String.format("反向关系:\n %s", convertInverseRelation(p.getId()))); + //查询行为 + list.add(String.format("行为:\n %s", convertBehaviour(p.getId()))); + //查询线索记录 + list.add(String.format("线索:\n %s", convertClue(p.getId()))); + + Map result = allocationClueMerge(p.getId()); + + list.add(String.format("分配的线索:\n %s", result.get("1"))); + list.add(String.format("需求任务("+p.getName()+"):\n %s", convertDemandTask(p.getId()))); + list.add("-------------------------------------------------------"); + FileUtils.writeLines(new File(filePath), "utf-8", list, true); + + + //人物拥有的性格 + List dispositionRecordList = dispositionRecordService.getDispositionRecords(person.getId()); + List dispositionList = new ArrayList<>(); + for (DispositionRecord dispositionRecord : dispositionRecordList) { + com.qiwu.inference.auto.pojo.Disposition disposition = new com.qiwu.inference.auto.pojo.Disposition(); + BeanUtil.copyProperties(dispositionRecord, disposition); + dispositionList.add(disposition); + } + person.setDispositions(dispositionList); + + //人物拥有的关系 + List relationRecordList = relationRecordService.getRelationRecords(person.getId()); + List relationList = new ArrayList<>(); + for (RelationRecord relationRecord : relationRecordList) { + com.qiwu.inference.auto.pojo.Relation relation = new com.qiwu.inference.auto.pojo.Relation(); + BeanUtil.copyProperties(relationRecord, relation); + relationList.add(relation); + } + person.setRelations(relationList); + + //人物拥有的行为 + List behaviourRecordList = behaviourRecordService.getBehaviourRecords(person.getId()); + List behaviourList = new ArrayList<>(); + for (BehaviourRecord behaviourRecord : behaviourRecordList) { + com.qiwu.inference.auto.pojo.Behaviour behaviour = new com.qiwu.inference.auto.pojo.Behaviour(); + BeanUtil.copyProperties(behaviourRecord, behaviour); + behaviourList.add(behaviour); + } + person.setBehaviours(behaviourList); + + //人物掌握的线索集合 + List clueRecordList = clueRecordService.getClueRecords(person.getId()); + List clueList = new ArrayList<>(); + //人物分配的线索 + clueRecordList.addAll((List) result.get("2")); + + for (ClueRecord clueRecord : clueRecordList) { + com.qiwu.inference.auto.pojo.Clue clue = new com.qiwu.inference.auto.pojo.Clue(); + BeanUtil.copyProperties(clueRecord, clue); + clueList.add(clue); + } + + person.setClues(clueList); + + //人物的需求任务集合 + List demandTaskRecordList = demandTaskRecordService.getDemandTaskRecords(person.getId()); + List demandTaskList_1 = demandTaskService.list(); + List demandTaskList = new ArrayList<>(); + for (DemandTaskRecord demandTaskRecord : demandTaskRecordList) { + com.qiwu.inference.auto.pojo.DemandTask demandTask = new com.qiwu.inference.auto.pojo.DemandTask(); + BeanUtil.copyProperties(demandTaskRecord, demandTask); + for (DemandTask demandTask_1 : demandTaskList_1) { + if (Objects.equals(demandTask.getDemandTaskId(), demandTask_1.getId())) { + if (!StringUtils.isEmpty(demandTask_1.getTrustCondition())) { + String[] trustCondition = demandTask_1.getTrustCondition().split("\\|"); + demandTask.setTrustStart(Integer.parseInt(trustCondition[0])); + demandTask.setTrustEnd(Integer.parseInt(trustCondition[1])); + } + + if (!StringUtils.isEmpty(demandTask_1.getDeterrenceCondition())) { + String[] deterrenceCondition = demandTask_1.getDeterrenceCondition().split("\\|"); + demandTask.setDeterrenceStart(Integer.parseInt(deterrenceCondition[0])); + demandTask.setDeterrenceEnd(Integer.parseInt(deterrenceCondition[1])); + } + demandTask.setPostTask(demandTask_1.getPostTask()); + demandTask.setCondition1(demandTask_1.getCondition1()); + demandTask.setCondition2(demandTask_1.getCondition2()); + demandTask.setTrustDegree(demandTask_1.getTrustDegree()); + demandTask.setDeterrenceDegree(demandTask_1.getDeterrenceDegree()); + demandTask.setCompletionReward(demandTask_1.getCompletionReward()); + demandTask.setEffectiveDegree(demandTask_1.getEffectiveDegree()); + } + } + demandTaskList.add(demandTask); + } + person.setDemandTasks(demandTaskList); + personList.add(person); + } + map.put(gateNo, personList); + } + String fileJsonPath = FileUtil.getPath() + "file" + File.separator + "results.json"; + FastJsonUtil.createJsonFile(map, fileJsonPath); + return CommonResult.success(map); + } + + + @RequestMapping(value = "/generate", method = RequestMethod.GET) + @ResponseBody + public CommonResult> generate() throws Exception { + //删除之前生成的关卡 + String filePath = FileUtil.getPath() + "file"+File.separator; + FileUtil.delFilesByPath(filePath,"results"); + + String gateNo = UUID.fastUUID().toString(); + + //1.结局目标 在结局目标表中使用同等概率随机选中一个结局目标 + List endGoalList = endGoalService.list(); + //随机产生一个索引下标 + int index = RandomUtil.randomInt(endGoalList.size()); + EndGoal endGoal = endGoalList.get(index); + + //2.关键线索 + String clueGroup = endGoal.getClueGroup(); + String[] clueGroups = clueGroup.split("\\|"); + //随机产生一个索引下标 + index = RandomUtil.randomInt(clueGroups.length); + clueGroup = clueGroups[index]; + List keyClueList = keyClueService.getKeyClues(clueGroup); + + //3.人物数量 5至10人之间随机 + //int num = RandomUtil.randomInt(5,7); + int num = 8; + Map map = new HashMap<>(); + Map keyClueMap = new HashMap<>(); + Map kinshipMap = new HashMap<>(); + Map identityMap = new HashMap<>(); + + List personRecordList = new ArrayList<>(); + + //4.关键人物 + for (int i = 0; i < keyClueList.size(); i++) { + KeyClue keyClue = keyClueList.get(i); + //随机选取一个主体的身份 + Person person = null; + PersonRecord subject = null; + PersonRecord object = null; + String identityId = keyClue.getSubjectIdentity(); + + if (!StringUtils.isEmpty(identityId)) { + if (!map.containsKey(keyClue.getSubjectLabel())) { + String[] identityIds = identityId.split("\\|"); + index = RandomUtil.randomInt(identityIds.length); + identityId = identityIds[index]; + if (identityMap.containsKey(Integer.parseInt(identityId))) { + identityMap.put(Integer.parseInt(identityId), identityMap.get(Integer.parseInt(identityId)) + 1); + } else { + identityMap.put(Integer.parseInt(identityId), 1); + } + List personList = personService.getPersons(Integer.parseInt(identityId)); + index = RandomUtil.randomInt(personList.size()); + person = personList.get(index); + while (kinshipMap.containsKey(person.getId())) { + index = RandomUtil.randomInt(personList.size()); + person = personList.get(index); + } + kinshipMap.put(person.getId(), person.getKinship()); + subject = generatePerson(person, true, gateNo); + personRecordList.add(subject); + map.put(keyClue.getSubjectLabel(), subject); + //关键线索 + keyClueMap.put(subject.getId(), keyClue); + //generateClueRecord(subject.getId(),keyClue.getDescription(),5,null); + num--; + } else { + subject = map.get(keyClue.getSubjectLabel()); + } + } + //随机选取一个客体的身份 + identityId = keyClue.getObjectIdentity(); + if (!StringUtils.isEmpty(identityId)) { + if (!map.containsKey(keyClue.getObjectLabel())) { + String[] identityIds = identityId.split("\\|"); + index = RandomUtil.randomInt(identityIds.length); + identityId = identityIds[index]; + if (identityMap.containsKey(Integer.parseInt(identityId))) { + identityMap.put(Integer.parseInt(identityId), identityMap.get(Integer.parseInt(identityId)) + 1); + } else { + identityMap.put(Integer.parseInt(identityId), 1); + } + List personList = personService.getPersons(Integer.parseInt(identityId)); + index = RandomUtil.randomInt(personList.size()); + person = personList.get(index); + while (kinshipMap.containsKey(person.getId())) { + index = RandomUtil.randomInt(personList.size()); + person = personList.get(index); + } + kinshipMap.put(person.getId(), person.getKinship()); + object = generatePerson(person, true, gateNo); + personRecordList.add(object); + map.put(keyClue.getObjectLabel(), object); + //关键线索 + keyClueMap.put(object.getId(), keyClue); + //generateClueRecord(object.getId(),keyClue.getDescription(),5,null); + num--; + } else { + object = map.get(keyClue.getObjectLabel()); + } + } + //同时不为空,才去判断他们之间的关系 + if (!StringUtils.isEmpty(subject) && !StringUtils.isEmpty(object)) { + String relationId = keyClue.getRelation(); + if (!StringUtils.isEmpty(relationId)) { + String[] relations = relationId.split("\\|"); + index = RandomUtil.randomInt(relations.length); + relationId = relations[index]; + Relation relation = relationService.getById(Integer.parseInt(relationId)); + List list = new ArrayList<>(); + list.add(relation); + judgeRelation(subject, object, list, true); + } + } + } + + for (Integer key : keyClueMap.keySet()) { + KeyClue keyClue = keyClueMap.get(key); + String description = keyClue.getDescription(); + if(!StringUtils.isEmpty(description)){ + description = replaceText(map, description); + } + Clue clue = clueService.getClue(9, keyClue.getId()); + //生成关键线索 + if (!StringUtils.isEmpty(clue)) { + clue.setClueTemplate(description); + if(!StringUtils.isEmpty(description)){ + int num_ = Integer.parseInt(ReUtil.findAllGroup0("^*【\\d+】", keyClue.getDescription()).get(0).replace("【", "").replace("】", "")); + generateClueRecord(num_, key, clue); + } + } + //生成关键任务 + if (!StringUtils.isEmpty(keyClue.getAssociatedTask())) { + for (String associatedTask : keyClue.getAssociatedTask().split(";")) { + String[] associatedTasks = associatedTask.split("\\|"); + DemandTask demandTask = demandTaskService.getById(associatedTasks[0]); + clue = clueService.getClue(6, demandTask.getId()); + if (associatedTasks.length > 2) { + generateDemandTaskRecord(demandTask, clue, map.get(Integer.parseInt(associatedTasks[1])).getId(), map.get(Integer.parseInt(associatedTasks[2])).getId()); + //生成任务的线索 + generateClueRecord(map.get(Integer.parseInt(associatedTasks[1])).getId(), map.get(Integer.parseInt(associatedTasks[2])).getId(), clue); + } else { + generateDemandTaskRecord(demandTask, clue, map.get(Integer.parseInt(associatedTasks[1])).getId(), 0); + //生成任务的线索 + generateClueRecord(map.get(Integer.parseInt(associatedTasks[1])).getId(), 0, clue); + } + } + } + } + + //5.随机人物 + if (num > 0) { + //List identityList=identityService.getIdentitys("0"); + List identityList = identityService.list(); + for (int i = 1; i <= num; i++) { + index = RandomUtil.randomInt(identityList.size()); + Identity identity = identityList.get(index); + + while (identity.getMaxNum() == 0 || (identityMap.containsKey(identity.getId()) + && identityMap.get(identity.getId()) >= identity.getMaxNum())) { + index = RandomUtil.randomInt(identityList.size()); + identity = identityList.get(index); + } + + if (identityMap.containsKey(identity.getId())) { + identityMap.put(identity.getId(), identityMap.get(identity.getId()) + 1); + } else { + identityMap.put(identity.getId(), 1); + } + + List personList = personService.getPersons(identity.getId()); + index = RandomUtil.randomInt(personList.size()); + Person person = personList.get(index); + while (kinshipMap.containsKey(person.getId())) { + index = RandomUtil.randomInt(personList.size()); + person = personList.get(index); + } + kinshipMap.put(person.getId(), person.getKinship()); + PersonRecord p = generatePerson(person, false, gateNo); + personRecordList.add(p); + } + } + + //6.判断人物之间的亲缘关系 + for (Integer key : kinshipMap.keySet()) { + String kinship = kinshipMap.get(key); + if (!StringUtils.isEmpty(kinship)) { + String[] kinships = kinship.split(";"); + for (String obj : kinships) { + String[] objs = obj.split("\\|"); + if (kinshipMap.containsKey(Integer.parseInt(objs[0]))) { + //要优化的地方 + PersonRecord subject = personRecordService.getPersonRecords(key, gateNo); + PersonRecord object = personRecordService.getPersonRecords(Integer.parseInt(objs[0]), gateNo); + Relation relation = relationService.getById(Integer.parseInt(objs[1])); + generateRelation(subject, object, relation, true); + Clue clue = clueService.getClue(5, relation.getId()); + //生成关系线索 + if (!StringUtils.isEmpty(clue)) { + generateClueRecord(subject.getId(), object.getId(), clue); + } + } + } + + } + } + + //7.判断随机人物间关系 + generateRandomRelation(personRecordList); + //8.行为事件 + generateRandomBehaviour(personRecordList); + //9.任务 + generateRandomDemandTask(personRecordList); + + return CommonResult.success(null); + } + + /** + * 正向关系进行转换 + * + * @param subject 人物 + * @return String + */ + public String convertRelation(Integer subject) { + List relationRecordList = relationRecordService.getRelationRecords(subject); + StringBuilder builder = new StringBuilder(); + for (int i = 0; i < relationRecordList.size(); i++) { + RelationRecord relationRecord = relationRecordList.get(i); + builder.append(String.format(" 与%s有%s(%s)的关系 \n ", relationRecord.getObjectName(), relationRecord.getName(), relationRecord.getRelationId())); + } + return ("".equals(builder.toString())) ? "无" : builder.toString(); + } + + + /** + * 反向关系进行转换 + * + * @param object 人物 + * @return String + */ + public String convertInverseRelation(Integer object) { + List relationRecordList = relationRecordService.getInverseRelationRecords(object); + StringBuilder builder = new StringBuilder(); + for (int i = 0; i < relationRecordList.size(); i++) { + RelationRecord relationRecord = relationRecordList.get(i); + builder.append(String.format(" %s与我有%s(%s)的关系 \n ", relationRecord.getSubjectName(), relationRecord.getName(), relationRecord.getRelationId())); + } + return ("".equals(builder.toString())) ? "无" : builder.toString(); + } + + + /** + * 行为进行转换 + * + * @param subject + * @return + */ + public String convertBehaviour(Integer subject) { + List behaviourRecordList = behaviourRecordService.getBehaviourRecords(subject); + StringBuilder builder = new StringBuilder(); + for (BehaviourRecord behaviourRecord : behaviourRecordList) { + if (behaviourRecord.getObject() == 0) { + builder.append(String.format(" 有%s(%s)的行为 \n ", behaviourRecord.getName(), behaviourRecord.getBehaviourId())); + } else { + builder.append(String.format(" 与%s有%s(%s)的行为 \n ", behaviourRecord.getObjectName(), behaviourRecord.getName(), behaviourRecord.getBehaviourId())); + } + } + return ("".equals(builder.toString())) ? "无" : builder.toString(); + } + + /** + * 文字替换 + * + * @param map + * @return + */ + public String replaceText(Map map, String description) { + String regExp = "^*【\\d+】"; + String regExp_gender = "^*【\\d+第三人称】"; + if (!(ReUtil.findAllGroup0(regExp, description).size() > 0)) { + return description; + } + int num = Integer.parseInt(ReUtil.findAllGroup0(regExp, description).get(0).replace("【", "").replace("】", "")); + description = description.replaceAll("【" + num + "】", map.get(num).getName()); + if (ReUtil.findAllGroup0(regExp, description).size() > 0) { + num = Integer.parseInt(ReUtil.findAllGroup0(regExp, description).get(0).replace("【", "").replace("】", "")); + if (!StringUtils.isEmpty(map.get(num))) { + description = description.replaceAll("【" + num + "】", map.get(num).getName()); + } + if (ReUtil.findAllGroup0(regExp_gender, description).size() > 0) { + num = Integer.parseInt(ReUtil.findAllGroup0(regExp_gender, description).get(0).replace("【", "").replace("第三人称】", "")); + String gender = map.get(num).getGender() == 1 ? "他" : "她"; + description = description.replaceAll("【" + num + "第三人称】", gender); + return description; + } else { + return description; + } + } else { + if (ReUtil.findAllGroup0(regExp_gender, description).size() > 0) { + num = Integer.parseInt(ReUtil.findAllGroup0(regExp_gender, description).get(0).replace("【", "").replace("第三人称】", "")); + String gender = map.get(num).getGender() == 1 ? "他" : "她"; + description = description.replaceAll("【" + num + "第三人称】", gender); + return description; + } else { + return description; + } + } + } + + /** + * 线索进行转换 + * + * @param subject + * @return + */ + public String convertClue(Integer subject) { + List clueRecordList = clueRecordService.getClueRecords(subject); + + StringBuilder builder = new StringBuilder(); + for (ClueRecord clueRecord : clueRecordList) { + if (!StringUtils.isEmpty(clueRecord.getClueTemplate())) { + if (clueRecord.getType() == 9) { + builder.append(String.format(" %s (%s|%s)\n", clueRecord.getClueTemplate() + "(关键线索)", clueRecord.getTrustDegree(), clueRecord.getDeterrenceDegree())); + } else { + builder.append(String.format(" %s (%s|%s)\n", clueRecord.getClueTemplate(), clueRecord.getTrustDegree(), clueRecord.getDeterrenceDegree())); + } + } + } + return ("".equals(builder.toString())) ? "无" : builder.toString(); + } + + /** + * 需求任务进行转换 + * + * @param subject 人物 + * @return String + */ + public String convertDemandTask(Integer subject) { + List demandTaskRecordList = demandTaskRecordService.getDemandTaskRecords(subject); + StringBuilder builder = new StringBuilder(); + for (DemandTaskRecord demandTaskRecord : demandTaskRecordList) { + if (demandTaskRecord.getType() == 6) { + DemandTask demandTask = demandTaskService.getById(demandTaskRecord.getDemandTaskId()); + builder.append(String.format(" %s (信任值开启条件)%s (威慑度开启条件)%s \n ", demandTaskRecord.getName(), demandTask.getTrustCondition(), demandTask.getDeterrenceCondition())); + } + } + return ("".equals(builder.toString())) ? "无" : builder.toString(); + } + + + /** + * 分配的线索 + * + * @param subject + * @return + */ + public String convertAllocationClue(Integer subject) { + //List clueRecordList=clueRecordService.getClueRecords(subject); + + List relationRecordList = relationRecordService.getRelationRecords(subject); + Map map = new HashMap<>(); + for (RelationRecord relationRecord : relationRecordList) { + if (!map.containsKey(relationRecord.getObject())) { + map.put(relationRecord.getObject(), relationRecord.getMasterInfoLevel()); + } else { + if (map.get(relationRecord.getObject()) < relationRecord.getMasterInfoLevel()) { + map.put(relationRecord.getObject(), relationRecord.getMasterInfoLevel()); + } + } + } + List clueRecordList = new ArrayList<>(); + for (Integer key : map.keySet()) { + clueRecordList.addAll(clueRecordService.getClueRecords(key, map.get(key))); + } + Set obj = new HashSet<>(); + for (ClueRecord clueRecord : clueRecordList) { + Clue clue = clueService.getById(clueRecord.getClueId()); + double prob = RandomUtil.randomDouble(2, RoundingMode.HALF_UP); + if (prob < Double.parseDouble(clue.getProb())) { + if (!StringUtils.isEmpty(clueRecord.getClueTemplate())) { + obj.add(clueRecord.getClueTemplate()); + } + } + + } + StringBuilder builder = new StringBuilder(); + for (String description : obj) { + builder.append(String.format(" %s \n ", description)); + } + return ("".equals(builder.toString())) ? "无" : builder.toString(); + } + + + /** + * 分配的线索 + * + * @param subject 人物 + * @return Map + */ + public Map allocationClueMerge(Integer subject) { + //List clueRecordList=clueRecordService.getClueRecords(subject); + Map result = new HashMap<>(); + List relationRecordList = relationRecordService.getRelationRecords(subject); + Map map = new HashMap<>(); + for (RelationRecord relationRecord : relationRecordList) { + if (!map.containsKey(relationRecord.getObject())) { + map.put(relationRecord.getObject(), relationRecord.getMasterInfoLevel()); + } else { + if (map.get(relationRecord.getObject()) < relationRecord.getMasterInfoLevel()) { + map.put(relationRecord.getObject(), relationRecord.getMasterInfoLevel()); + } + } + } + List clueRecordList = new ArrayList<>(); + for (Integer key : map.keySet()) { + clueRecordList.addAll(clueRecordService.getClueRecords(key, map.get(key))); + } + Set obj = new HashSet<>(); + List cueRecordResult = new ArrayList<>(); + + + for (ClueRecord clueRecord : clueRecordList) { + Clue clue = clueService.getById(clueRecord.getClueId()); + double prob = RandomUtil.randomDouble(2, RoundingMode.HALF_UP); + if (prob < Double.parseDouble(clue.getProb())) { + if (!StringUtils.isEmpty(clueRecord.getClueTemplate())) { + obj.add(clueRecord.getClueTemplate() + "(" + clue.getTrustDegree() + "|" + clue.getDeterrenceDegree() + ")"); + clueRecord.setTrustDegree(clue.getTrustDegree()); + clueRecord.setDeterrenceDegree(clue.getDeterrenceDegree()); + cueRecordResult.add(clueRecord); + } + } + } + StringBuilder builder = new StringBuilder(); + for (String description : obj) { + builder.append(String.format(" %s \n ", description)); + } + result.put("1", ("".equals(builder.toString())) ? "无" : builder.toString()); + result.put("2", cueRecordResult); + return result; + } + + + public List allocationClue(Integer subject) { + List relationRecordList = relationRecordService.getRelationRecords(subject); + Map map = new HashMap<>(); + for (RelationRecord relationRecord : relationRecordList) { + if (!map.containsKey(relationRecord.getObject())) { + map.put(relationRecord.getObject(), relationRecord.getMasterInfoLevel()); + } else { + if (map.get(relationRecord.getObject()) < relationRecord.getMasterInfoLevel()) { + map.put(relationRecord.getObject(), relationRecord.getMasterInfoLevel()); + } + } + } + + List clueRecordList = new ArrayList<>(); + for (Integer key : map.keySet()) { + clueRecordList.addAll(clueRecordService.getClueRecords(key, map.get(key))); + } + + List result = new ArrayList<>(); + + for (ClueRecord clueRecord : clueRecordList) { + Clue clue = clueService.getById(clueRecord.getClueId()); + double prob = RandomUtil.randomDouble(2, RoundingMode.HALF_UP); + if (prob < Double.parseDouble(clue.getProb())) { + clueRecord.setTrustDegree(clue.getTrustDegree()); + clueRecord.setDeterrenceDegree(clue.getDeterrenceDegree()); + result.add(clueRecord); + } + + } + return result; + } + + + /** + * 根据身份生成一个人物 + * + * @param person 人物 + * @return 人物 + */ + public PersonRecord generatePerson(Person person, boolean isKey, String gateNo) { + PersonRecord personRecord = new PersonRecord(); + if (isKey) { + personRecord.setIsKey(1); + } else { + personRecord.setIsKey(2); + } + personRecord.setGateNo(gateNo); + personRecord.setIdentityId(person.getIdentityId()); + personRecord.setIdentityName(identityService.getById(person.getIdentityId()).getName()); + personRecord.setAge(generateAge(person.getAge())); + personRecord.setGender(person.getGender()); + personRecord.setLocation(person.getLocation()); + personRecord.setName(person.getName()); + personRecord.setPersonId(person.getId()); + personRecord.setFriendly(person.getFriendly()); + personRecordService.save(personRecord); + + Map map = new HashMap<>(); + + //生成特定的性格 + if (!StringUtils.isEmpty(person.getSpecialDisposition())) { + String[] specialDispositions =person.getSpecialDisposition().split("\\|"); + for (String specialDisposition:specialDispositions){ + Disposition disposition = dispositionService.getById(Integer.parseInt(specialDisposition)); + DispositionRecord dispositionRecord = new DispositionRecord(); + dispositionRecord.setDispositionId(disposition.getId()); + dispositionRecord.setSubject(personRecord.getId()); + dispositionRecord.setName(disposition.getName()); + dispositionRecord.setDescription(disposition.getDescription()); + dispositionRecord.setType(disposition.getType()); + dispositionRecordService.save(dispositionRecord); + map.put(disposition.getId(), disposition.getName()); + Clue clue = clueService.getClue(3, disposition.getId()); + //生成性格线索 + if (!StringUtils.isEmpty(clue)) { + generateClueRecord(personRecord.getId(), 0, clue); + } + } + } + + //判断人物的性格 + generateDisposition(personRecord, map); + //生成场所线索 + Clue clue = null; + if (person.getLocation() != 0) { + clue = clueService.getClue(2, person.getLocation()); + } else { + List locationList = locationService.list(); + int index = RandomUtil.randomInt(locationList.size()); + clue = clueService.getClue(2, locationList.get(index).getId()); + personRecord.setLocation(locationList.get(index).getId()); + } + //生成位置线索 + if (!StringUtils.isEmpty(clue)) { + generateClueRecord(personRecord.getId(), 0, clue); + } + clue = null; + //生成身份线索 + clue = clueService.getClue(1, person.getId()); + if (!StringUtils.isEmpty(clue)) { + generateClueRecord(personRecord.getId(), 0, clue); + } + + personRecordService.updateById(personRecord); + return personRecord; + } + + + /** + * 根据年龄的规则生成一个随机的年龄 + * + * @param ageCondition 年龄条件 + * @return 年龄 + */ + public Integer generateAge(String ageCondition) { + String[] ageConditions = ageCondition.split("\\|"); + int age = RandomUtil.randomInt(Integer.parseInt(ageConditions[0]), Integer.parseInt(ageConditions[1]) + 1); + return age; + } + + + /** + * 随机生成人物的性格关系 + * + * @param personRecord 人物 + */ + public void generateDisposition(PersonRecord personRecord, Map map) { + List dispositionTypeList = dispositionTypeService.list(); + double prob = 0.0; + for (DispositionType dispositionType : dispositionTypeList) { + //随机一个概率 + prob = RandomUtil.randomDouble(2, RoundingMode.HALF_UP); + if (0 < prob && prob <= Double.parseDouble(dispositionType.getProbability())) { + List dispositionList = dispositionService.getDispositions(dispositionType.getId()); + judgeDisposition(personRecord, dispositionList, map); + } + } + personRecord.setDisposition(FastJsonUtil.obj2json(map)); + } + + /** + * 随机生成一个关系 + * + * @param subject + * @param object + * @param relation + * @param inverse 是否是正向关系 + */ + public void generateRelation(PersonRecord subject, PersonRecord object, Relation relation, boolean inverse) { + //关系人排除身份 + if (!StringUtils.isEmpty(relation.getExclusionIdentity())) { + String[] exclusionIdentitys = relation.getExclusionIdentity().split("\\|"); + if (exclusionIdentitys[exclusionIdentitys.length - 1].equals("-1")) { //身份排除 + for (int i = 0; i < exclusionIdentitys.length - 1; i++) { + if (Objects.equals(Integer.parseInt(exclusionIdentitys[i]), subject.getIdentityId())) { + return; + } + } + } else { + boolean flag = false; + for (int i = 0; i < exclusionIdentitys.length - 1; i++) { + if (Objects.equals(Integer.parseInt(exclusionIdentitys[i]), subject.getIdentityId())) { + flag = true; + } + } + if (!flag) { + return; + } + } + } + + //互斥关系 + if (!StringUtils.isEmpty(relation.getExclusionRelation())) { + boolean flag = relationService.isExists(relation.getExclusionRelation().split("\\|")); + if (flag) { + return; + } + } + if (!relationRecordService.isExists(subject.getId(), object.getId(), relation.getId())) { + RelationRecord relationRecord = new RelationRecord(); + relationRecord.setName(relation.getName()); + relationRecord.setDescription(relation.getDescription()); + relationRecord.setType(relation.getType()); + relationRecord.setRelationId(relation.getId()); + relationRecord.setSubject(subject.getId()); + relationRecord.setSubjectName(subject.getName()); + relationRecord.setObject(object.getId()); + relationRecord.setObjectName(object.getName()); + relationRecord.setMasterInfoLevel(relation.getMasterInfoLevel()); + relationRecordService.save(relationRecord); + + //反向关系 + if (!StringUtils.isEmpty(relation.getInverseRelation()) && inverse) { + judgeRelation(object, subject, relationService.getRelations(relation.getInverseRelation().split("\\|")), false); + } + } + } + + /** + * 随机生成一个线索记录 + * + * @param subject + * @param object + * @param clue + */ + public void generateClueRecord(int subject, int object, Clue clue) { + ClueRecord clueRecord = new ClueRecord(); + clueRecord.setClueId(clue.getId()); + clueRecord.setClueName(clue.getName()); + + clueRecord.setDescription(clue.getDescription()); + + if (clue.getType() != 9) { + String clueTemplate = clue.getClueTemplate(); + PersonRecord p = personRecordService.getById(subject); + clueTemplate = clueTemplate.replaceAll("【A】", p.getName()); + if (!StringUtils.isEmpty(object)) { + if (ReUtil.findAllGroup0("^*【B】", clueTemplate).size() > 0) { + p = personRecordService.getById(object); + if (!StringUtils.isEmpty(p)) { + clueTemplate = clueTemplate.replaceAll("【B】", p.getName()); + } + } + } + clueRecord.setClueTemplate(clueTemplate); + clueRecord.setSubject(subject); + clueRecord.setObject(object); + clueRecord.setAssociatedPerson(subject); + } else { + clueRecord.setClueTemplate(clue.getClueTemplate()); + clueRecord.setSubject(subject); + clueRecord.setAssociatedPerson(object); + } + clueRecord.setType(clue.getType()); + clueRecord.setInfoLevel(clue.getInfoLevel()); +// clueRecord.setTrustDegree(clue.getTrustDegree()); +// clueRecord.setThreaten(clue.getThreaten()); + clueRecord.setTrustDegree(clue.getMyTrustDegree()); + clueRecord.setDeterrenceDegree(clue.getMyDeterrenceDegree()); + + if (!clueRecordService.isExists(clueRecord)) { + clueRecordService.save(clueRecord); + } + } + + /** + * 生成人物的随机关系 + * + * @param personRecordList 人物记录列表 + * @return void + */ + public void generateRandomRelation(List personRecordList) { + int size = personRecordList.size(); + for (int i = 0; i < size; i++) { + for (int j = 0; j < size; j++) { + if (i != j) { + PersonRecord subject = personRecordList.get(i); + PersonRecord object = personRecordList.get(j); + + List relationTypeList = relationTypeService.list(2); + double prob = 0.0; + for (int k = 0; k < relationTypeList.size(); k++) { + RelationType relationType = relationTypeList.get(k); + //随机一个概率 + prob = RandomUtil.randomDouble(2, RoundingMode.HALF_UP); + if (0 < prob && prob <= Double.parseDouble(relationType.getProbability())) { + List relationList = relationService.getRelations(relationType.getId()); + judgeRelation(subject, object, relationList, true); + } + } + } + } + } + } + + /** + * 判断人物之间的关系 + * + * @param subject 主体人物 + * @param object 客体人物 + * @param list + */ + public void judgeRelation(PersonRecord subject, PersonRecord object, List list, boolean inverse) { + int sumWeight = 0; + for (int i = 0; i < list.size(); i++) { + Relation relation = list.get(i); + int weight = relation.getWeight(); + String genderWeight = relation.getGenderWeight(); + //性别影响权重增减 + if (!StringUtils.isEmpty(genderWeight)) { + String[] genderWeights = genderWeight.split(";"); + for (String s : genderWeights) { + String[] obj = s.split("\\|"); + if (obj.length == 2) { + if (obj[0].equals(String.valueOf(subject.getGender()))) { + weight += Integer.parseInt(obj[1]); + } + } else if (obj.length == 3) { + if (obj[0].equals(String.valueOf(subject.getGender())) && obj[1].equals(String.valueOf(object.getGender()))) { + weight += Integer.parseInt(obj[2]); + } + } + } + } + + String ageWeight = relation.getAgeWeight(); + //年龄影响权重增减 + if (!StringUtils.isEmpty(ageWeight)) { + String[] ageWeights = ageWeight.split(";"); + for (int j = 0; j < ageWeights.length; j++) { + ageWeight = ageWeights[j]; + String[] ageWeights_1 = ageWeight.split("\\|"); + if (NumberUtil.isIn(BigDecimal.valueOf(subject.getAge()), BigDecimal.valueOf(Integer.parseInt(ageWeights_1[0])), BigDecimal.valueOf(Integer.parseInt(ageWeights_1[1])))) { + weight += Integer.parseInt(ageWeights_1[2]); + } + } + } + //年龄差影响权重增减 + + //身份影响概率增减 + String identityWeight = relation.getIdentityWeight(); + if (!StringUtils.isEmpty(identityWeight)) { + String[] identityWeights = identityWeight.split("\\|"); + if (identityWeight.contains(String.valueOf(subject.getIdentityId()))) { + weight += Integer.parseInt(identityWeights[identityWeights.length - 1]); + } + } + //性格/喜好影响权重增减 + weight = Math.max(weight, 0); + sumWeight += weight; + relation.setWeight(weight); + list.set(i, relation); + } + double start = 0.0; + double end = 0.0; + //随机一个概率 + double prob = RandomUtil.randomDouble(2, RoundingMode.HALF_UP); + for (int i = 0; i < list.size(); i++) { + Relation relation = list.get(i); + if (!relationRecordService.isExistsRelationTypes(subject.getId(), object.getId(), relation.getType())) { + if (relation.getWeight() != 0) { + end += NumberUtil.div(Double.valueOf(relation.getWeight()), Double.valueOf(sumWeight), 2); + if (NumberUtil.isIn(BigDecimal.valueOf(prob), BigDecimal.valueOf(start), BigDecimal.valueOf(end))) { + generateRelation(subject, object, relation, inverse); + Clue clue = clueService.getClue(5, relation.getId()); + //生成关系线索 + if (!StringUtils.isEmpty(clue)) { + generateClueRecord(subject.getId(), object.getId(), clue); + } + break; + } + start = end; + } + } else { + return; + } + } + } + + /** + * 判断人物之间的性格 + * + * @param personRecord 人物 + * @param list 列表 + */ + public void judgeDisposition(PersonRecord personRecord, List list, Map map) { + int sumWeight = 0; + for (int i = 0; i < list.size(); i++) { + Disposition disposition = list.get(i); + int weight = disposition.getWeight(); + weight = Math.max(weight, 0); + sumWeight += weight; + disposition.setWeight(weight); + list.set(i, disposition); + } + double start = 0.0; + double end = 0.0; + //随机一个概率 + double prob = RandomUtil.randomDouble(2, RoundingMode.HALF_UP); + for (Disposition disposition : list) { + if (disposition.getWeight() != 0) { + end += NumberUtil.div(Double.valueOf(disposition.getWeight()), Double.valueOf(sumWeight), 2); + if (NumberUtil.isIn(BigDecimal.valueOf(prob), BigDecimal.valueOf(start), BigDecimal.valueOf(end))) { + DispositionRecord dispositionRecord = new DispositionRecord(); + dispositionRecord.setDispositionId(disposition.getId()); + dispositionRecord.setSubject(personRecord.getId()); + dispositionRecord.setName(disposition.getName()); + dispositionRecord.setDescription(disposition.getDescription()); + dispositionRecord.setType(disposition.getType()); + dispositionRecordService.save(dispositionRecord); + map.put(disposition.getId(), disposition.getName()); + Clue clue = clueService.getClue(3, disposition.getId()); + //生成性格线索 + if (!StringUtils.isEmpty(clue)) { + generateClueRecord(personRecord.getId(), 0, clue); + } + break; + } + start = end; + } + } + } + + /** + * 生成人物的随机行为 + * + * @param personRecordList 人物 + * @return void + */ + public void generateRandomBehaviour(List personRecordList) { + int size = personRecordList.size(); + for (int i = 0; i < size; i++) { + for (int j = 0; j < size; j++) { + if (i != j) { + PersonRecord subject = personRecordList.get(i); + PersonRecord object = personRecordList.get(j); + List behaviourList = behaviourService.list(0); + double prob = 0.0; + for (Behaviour behaviour : behaviourList) { + //互斥行为 + if (!StringUtils.isEmpty(behaviour.getExclusionBehaviour())) { + String[] exclusionBehaviours = behaviour.getExclusionBehaviour().split("\\|"); + boolean flag = true; + for (String exclusionBehaviour : exclusionBehaviours) { + //判断是不是单人行为 + if (behaviour.getSingleLabel() == 1) { + if (behaviourRecordService.isExists(subject.getId(), behaviour.getId()) || behaviourRecordService.isExists(subject.getId(), Integer.parseInt(exclusionBehaviour))) { + flag = false; + } + } else { + if (behaviourRecordService.isExists(subject.getId(), object.getId(), behaviour.getId()) || behaviourRecordService.isExists(subject.getId(), object.getId(), Integer.parseInt(exclusionBehaviour))) { + flag = false; + } + } + } + if (!flag) { + continue; + } + } + double generationProbability = behaviour.getGenerationProbability(); + + //行为人性格喜好|概率增减 + String subjectDisposition = behaviour.getSubjectDisposition(); + if (!StringUtils.isEmpty(subjectDisposition)) { + String[] subjectDispositions = subjectDisposition.split(";"); + for (String disposition : subjectDispositions) { + Map map = FastJsonUtil.parseJSON2Map(subject.getDisposition()); + for (String key : map.keySet()) { + if (disposition.contains(key)) { + String[] obj = disposition.split("\\|"); + generationProbability += Double.parseDouble(obj[obj.length - 1]); + } + } + } + } + + //行为人身份|概率增减 + String subjectIdentityProbability = behaviour.getSubjectIdentityProbability(); + if (!StringUtils.isEmpty(subjectIdentityProbability)) { + if (behaviour.getSubjectIdentityProbability().contains(String.valueOf(subject.getIdentityId()))) { + String[] obj = subjectIdentityProbability.split("\\|"); + generationProbability += Double.parseDouble(obj[obj.length - 1]); + } + } + + //行为对象身份|概率增减(B) + String objectIdentityProbability = behaviour.getObjectIdentityProbability(); + if (!StringUtils.isEmpty(objectIdentityProbability)) { + if (behaviour.getObjectIdentityProbability().contains(String.valueOf(object.getIdentityId()))) { + String[] obj = objectIdentityProbability.split("\\|"); + generationProbability += Double.parseDouble(obj[obj.length - 1]); + } + } + //与行为对象关系|概率影响(A与B)" + String objectRelationProbability = behaviour.getObjectRelationProbability(); + + //行为对象性格喜好|概率影响(B) + String objectDispositionProbability = behaviour.getObjectDispositionProbability(); + if (!StringUtils.isEmpty(objectDispositionProbability)) { + String[] objectDispositionProbabilitys = objectDispositionProbability.split(";"); + for (String dispositionProbability : objectDispositionProbabilitys) { + Map map = FastJsonUtil.parseJSON2Map(object.getDisposition()); + for (String key : map.keySet()) { + if (dispositionProbability.contains(key)) { + String[] obj = dispositionProbability.split("\\|"); + generationProbability += Double.parseDouble(obj[obj.length - 1]); + } + } + } + } + + //行为人性别|行为对象性别|概率影响 + String genderProbability = behaviour.getGenderProbability(); + if (!StringUtils.isEmpty(genderProbability)) { + String[] genderProbabilitys = genderProbability.split(";"); + for (String probability : genderProbabilitys) { + String[] obj = probability.split("\\|"); + if (obj[0].equals(String.valueOf(subject.getGender())) && obj[1].equals(String.valueOf(object.getGender()))) { + generationProbability += Double.parseDouble(obj[2]); + } + } + } + //随机一个概率 + prob = RandomUtil.randomDouble(2, RoundingMode.HALF_UP); + if (0 < prob && prob <= generationProbability) { + //单人行为 + if (behaviour.getSingleLabel() == 1) { + generateRandomBehaviour(subject, null, behaviour); + } else { + generateRandomBehaviour(subject, object, behaviour); + } + //反向行为 + if (!StringUtils.isEmpty(behaviour.getInverseBehaviour()) && behaviour.getInverseLabel() == 0) { + String[] inverseBehaviours = behaviour.getInverseBehaviour().split("\\|"); + int index = RandomUtil.randomInt(inverseBehaviours.length); + behaviour = behaviourService.getById(Integer.parseInt(inverseBehaviours[index])); + //单人行为 + if (behaviour.getSingleLabel() == 1) { + generateRandomBehaviour(object, null, behaviour); + } else { + generateRandomBehaviour(object, subject, behaviour); + } + } + } + } + } + } + } + } + + + /** + * 生成人物的随机需求任务 + * + * @param personRecordList 人物列表 + * @return void + */ + public void generateRandomDemandTask(List personRecordList) { + for (int i = 0; i < personRecordList.size(); i++) { + PersonRecord subject = personRecordList.get(i); + int taskGroupSize = demandTaskService.getTaskGroupSize(); + + for (int j = 1; j < taskGroupSize; j++) { + List demandTaskList = demandTaskService.list(j, 0, 1); + Collections.shuffle(demandTaskList); + for (DemandTask demandTask : demandTaskList) { + //根据友好人物 剔除负面任务 + if(subject.getFriendly()==1&&demandTask.getNegativeTask()==1){ + continue; + } + + //主体判断身份 + if (!StringUtils.isEmpty(demandTask.getSubjectNeedIdentity())) { + if (!demandTask.getSubjectNeedIdentity().contains(String.valueOf(subject.getIdentityId()))) { + continue; + } + } + //主体判断性别 + if (!StringUtils.isEmpty(demandTask.getSubjectNeedGender())) { + if (!demandTask.getSubjectNeedGender().equals(String.valueOf(subject.getGender()))) { + continue; + } + } + + boolean flag = false; + Integer objectId = null; + + if (!StringUtils.isEmpty(demandTask.getPostTask())) { + String[] postTasks = demandTask.getPostTask().split("\\|"); + int index = RandomUtil.randomInt(postTasks.length); + DemandTask postDemandTask = demandTaskService.getById(postTasks[index]); + Map res = generatePostDemandTask(postDemandTask, subject.getId()); + if (res.size() > 0) { + PersonRecord object = personRecordService.getById(res.get("object")); + + //根据友好人物 剔除负面任务 + if(object.getFriendly()==1&&postDemandTask.getNegativeTask()==1){ + continue; + } + + //判断客体的必要身份 + if (!StringUtils.isEmpty(demandTask.getObjectNeedIdentity())) { + if (!demandTask.getObjectNeedIdentity().contains(String.valueOf(object.getIdentityId()))) { + continue; + } + } + //判断客体的必要性别 + if (!StringUtils.isEmpty(demandTask.getObjectNeedGender())) { + if (!demandTask.getObjectNeedGender().equals(String.valueOf(object.getGender()))) { + continue; + } + } + + flag = generateDemandTask(demandTask, subject.getId(), res.get("object")); + if (flag) { + Clue clue = clueService.getClue(6, postDemandTask.getId()); + boolean flag_ = generateDemandTaskRecord(postDemandTask, clue, res.get("object"), 0); + if (!flag_) { + //删除前置任务相关线索 + List list_ = demandTaskRecordService.getDemandTaskRecords(demandTask.getId(), subject.getId(), res.get("object")); + for (DemandTaskRecord demandTaskRecord : list_) { + clueRecordService.delete(demandTaskRecord.getClueId(), subject.getId(), res.get("object")); + } + //删除前置任务 + demandTaskRecordService.delete(demandTask.getId(), subject.getId(), res.get("object")); + } + } + } else {//后置任务 如果四个条件都没有命中 随机选取一个人物 + index = RandomUtil.randomInt(personRecordList.size()); + objectId = personRecordList.get(index).getId(); + while (Objects.equals(personRecordList.get(index).getId(), subject.getId())) { + index = RandomUtil.randomInt(personRecordList.size()); + objectId = personRecordList.get(index).getId(); + } + + PersonRecord object = personRecordService.getById(objectId); + + //根据友好人物 剔除负面任务 + if(object.getFriendly()==1&&postDemandTask.getNegativeTask()==1){ + continue; + } + + //判断客体的必要身份 + if (!StringUtils.isEmpty(demandTask.getObjectNeedIdentity())) { + if (!demandTask.getObjectNeedIdentity().contains(String.valueOf(object.getIdentityId()))) { + continue; + } + } + //判断客体的必要性别 + if (!StringUtils.isEmpty(demandTask.getObjectNeedGender())) { + if (!demandTask.getObjectNeedGender().equals(String.valueOf(object.getGender()))) { + continue; + } + } + flag = generateDemandTask(demandTask, subject.getId(), objectId); + if (flag) { + Clue clue = clueService.getClue(6, postDemandTask.getId()); + boolean flag_ = generateDemandTaskRecord(postDemandTask, clue, objectId, 0); + if (!flag_) { + //删除前置任务相关线索 + List list_ = demandTaskRecordService.getDemandTaskRecords(demandTask.getId(), subject.getId(), objectId); + for (DemandTaskRecord demandTaskRecord : list_) { + clueRecordService.delete(demandTaskRecord.getClueId(), subject.getId(), objectId); + } + //删除前置任务 + demandTaskRecordService.delete(demandTask.getId(), subject.getId(), objectId); + } + } + } + } else { + flag = generateDemandTask(demandTask, subject.getId(), 0); + } + if (flag) { + break; + } + } + } + } + } + + + public boolean generateDemandTask(DemandTask demandTask, int subjectId, int objectId) { + double prob = 0.0; + PersonRecord subject = personRecordService.getById(subjectId); + boolean flag = false; + List clueList = new ArrayList<>(); + Clue clue = null; + + if (demandTaskRecordService.isExistsTaskGroup(subjectId, demandTask.getTaskGroup())) { + return flag; + } + + //性格喜好关联 + if (!StringUtils.isEmpty(demandTask.getAssociatedDisposition())) { + String disposition = subject.getDisposition(); + Map dispositionMap = FastJsonUtil.parseJSON2Map(disposition); + for (String key : dispositionMap.keySet()) { + if (demandTask.getAssociatedDisposition().contains(key)) { + prob = RandomUtil.randomDouble(2, RoundingMode.HALF_UP); + String[] obj = demandTask.getAssociatedDisposition().split("\\|"); + if (0 < prob && prob <= Double.parseDouble(obj[obj.length - 1])) { + flag = true; + clue = clueService.getClue(3, Integer.parseInt(obj[0])); + clueList.add(ObjectUtil.clone(clue)); + //generateDemandTaskRecord(demandTask,clue,subject.getId(),objectId); + break; + } else { + flag = false; + return flag; + } + } + } + } + //身份关联 + if (!StringUtils.isEmpty(demandTask.getAssociatedIdentity())) { + if (demandTask.getAssociatedIdentity().contains(String.valueOf(subject.getIdentityId()))) { + prob = RandomUtil.randomDouble(2, RoundingMode.HALF_UP); + String[] obj = demandTask.getAssociatedIdentity().split("\\|"); + if (0 < prob && prob <= Double.parseDouble(obj[obj.length - 1])) { + flag = true; + clue = clueService.getClue(1, Integer.parseInt(obj[0])); + clueList.add(ObjectUtil.clone(clue)); + //generateDemandTaskRecord(demandTask,clue,subject.getId(),objectId); + } else { + flag = false; + return flag; + } + } + } + //行为关联 + if (!StringUtils.isEmpty(demandTask.getAssociatedBehaviour())) { + List behaviourRecordList = behaviourRecordService.getBehaviourRecords(subject.getId()); + for (BehaviourRecord behaviourRecord : behaviourRecordList) { + if (demandTask.getAssociatedBehaviour().contains(String.valueOf(behaviourRecord.getBehaviourId()))) { + prob = RandomUtil.randomDouble(2, RoundingMode.HALF_UP); + String[] obj = demandTask.getAssociatedBehaviour().split("\\|"); + if (0 < prob && prob <= Double.parseDouble(obj[obj.length - 1])) { + flag = true; + clue = clueService.getClue(4, Integer.parseInt(obj[0])); + clueList.add(ObjectUtil.clone(clue)); + //generateDemandTaskRecord(demandTask,clue,subject.getId(),objectId); + break; + } else { + flag = false; + return flag; + } + } + } + } + //关系关联 + if (!StringUtils.isEmpty(demandTask.getAssociatedRelation())) { + List relationRecordList = relationRecordService.getRelationRecords(subject.getId()); + for (RelationRecord relationRecord : relationRecordList) { + if (demandTask.getAssociatedRelation().contains(String.valueOf(relationRecord.getRelationId()))) { + prob = RandomUtil.randomDouble(2, RoundingMode.HALF_UP); + String[] obj = demandTask.getAssociatedRelation().split("\\|"); + if (0 < prob && prob <= Double.parseDouble(obj[obj.length - 1])) { + flag = true; + clue = clueService.getClue(5, Integer.parseInt(obj[0])); + clueList.add(ObjectUtil.clone(clue)); + //generateDemandTaskRecord(demandTask,clue,subject.getId(),objectId); + break; + } else { + flag = false; + return flag; + } + } + } + } + if(flag){ + flag = generateDemandTaskRecord(demandTask, null, subject.getId(), objectId); + if(flag){ + for (Clue key : clueList) { + generateDemandTaskRecord(demandTask, key, subject.getId(), objectId); + } + } + return flag; + } else {//四个关联都没有命中,直接插入一条数据 + if (StringUtils.isEmpty(demandTask.getAssociatedDisposition()) && + StringUtils.isEmpty(demandTask.getAssociatedBehaviour()) && + StringUtils.isEmpty(demandTask.getAssociatedIdentity()) && + StringUtils.isEmpty(demandTask.getAssociatedRelation())) { + generateDemandTaskRecord(demandTask, null, subject.getId(), objectId); + return true; + }else{ + return flag; + } + } + } + + + public Map generatePostDemandTask(DemandTask demandTask, Integer subjectId) { + double prob = 0.0; + Integer objectId = null; + Map result = new HashMap<>(); + //性格喜好关联 + if (!StringUtils.isEmpty(demandTask.getAssociatedDisposition())) { + prob = RandomUtil.randomDouble(2, RoundingMode.HALF_UP); + String[] obj = demandTask.getAssociatedDisposition().split("\\|"); + if (0 < prob && prob <= Double.parseDouble(obj[obj.length - 1])) { + for (int i = 0; i < obj.length - 1; i++) { + List dispositionRecordList = dispositionRecordService.getDispositionRecordsNoSubject(subjectId, Integer.parseInt(obj[i])); + if (dispositionRecordList.size() > 0) { + int index = RandomUtil.randomInt(dispositionRecordList.size()); + //generateDemandTask(demandTask,dispositionRecordList.get(index).getSubject(),null); + objectId = dispositionRecordList.get(index).getSubject(); + result.put("object", objectId); + return result; + } + } + } + } + //身份关联 + if (!StringUtils.isEmpty(demandTask.getAssociatedIdentity())) { + prob = RandomUtil.randomDouble(2, RoundingMode.HALF_UP); + String[] obj = demandTask.getAssociatedIdentity().split("\\|"); + if (0 < prob && prob <= Double.parseDouble(obj[obj.length - 1])) { + for (int i = 0; i < obj.length - 1; i++) { + List personRecordList = personRecordService.getPersonRecordsNoSubject(subjectId, Integer.parseInt(obj[i])); + if (personRecordList.size() > 0) { + int index = RandomUtil.randomInt(personRecordList.size()); + //generateDemandTask(demandTask,personRecordList.get(index).getId(),null); + objectId = personRecordList.get(index).getId(); + result.put("object", objectId); + return result; + } + } + } + } + //行为关联 + if (!StringUtils.isEmpty(demandTask.getAssociatedBehaviour())) { + prob = RandomUtil.randomDouble(2, RoundingMode.HALF_UP); + String[] obj = demandTask.getAssociatedBehaviour().split("\\|"); + if (0 < prob && prob <= Double.parseDouble(obj[obj.length - 1])) { + for (int i = 0; i < obj.length - 1; i++) { + Behaviour behaviour = behaviourService.getById(Integer.parseInt(obj[i])); + List behaviourRecordList; + if (behaviour.getSingleLabel() == 1) {//单人行为标签 + behaviourRecordList = behaviourRecordService.getBehaviourRecordsNoSubject(subjectId, Integer.parseInt(obj[i])); + } else { + behaviourRecordList = behaviourRecordService.getBehaviourRecords(subjectId, Integer.parseInt(obj[i])); + } + if (behaviourRecordList.size() > 0) { + int index = RandomUtil.randomInt(behaviourRecordList.size()); + //generateDemandTask(demandTask, behaviourRecordList.get(index).getSubject(), null); + objectId = behaviourRecordList.get(index).getSubject(); + result.put("object", objectId); + return result; + } + } + } + } + //关系关联 + if (!StringUtils.isEmpty(demandTask.getAssociatedRelation())) { + prob = RandomUtil.randomDouble(2, RoundingMode.HALF_UP); + String[] obj = demandTask.getAssociatedRelation().split("\\|"); + if (0 < prob && prob <= Double.parseDouble(obj[obj.length - 1])) { + for (int i = 0; i < obj.length - 1; i++) { + List relationRecordList = relationRecordService.getRelationRecordsNoSubject(subjectId, Integer.parseInt(obj[i])); + if (relationRecordList.size() > 0) { + int index = RandomUtil.randomInt(relationRecordList.size()); + //generateDemandTask(demandTask,relationRecordList.get(index).getSubject(),null); + objectId = relationRecordList.get(index).getSubject(); + result.put("object", objectId); + return result; + } + } + } + } + return result; + } + + public boolean generateDemandTaskRecord(DemandTask demandTask, Clue clue, int subject, int object) { + boolean flag = true; + + //判断互斥任务 + if (!StringUtils.isEmpty(demandTask.getExclusiveTask())) { + String exclusiveTask = demandTask.getExclusiveTask(); + String[] exclusiveTasks = exclusiveTask.split("\\|"); + for (String task : exclusiveTasks) { + if (demandTaskRecordService.isExists(subject, Integer.parseInt(task))) { + flag = false; + break; + } + } + } + + if (flag) { + if (StringUtils.isEmpty(clue)) { + if (demandTask.getTaskLabel() == 1) { + clue = clueService.getClue(6, demandTask.getId()); + } else { + clue = clueService.getClue(9, demandTask.getId()); + } + } + DemandTaskRecord demandTaskRecord = new DemandTaskRecord(); + demandTaskRecord.setDemandTaskId(demandTask.getId()); + demandTaskRecord.setName(demandTask.getName()); + demandTaskRecord.setTaskGroup(demandTask.getTaskGroup()); + demandTaskRecord.setDescription(demandTask.getDescription()); + demandTaskRecord.setSubject(subject); + demandTaskRecord.setObject(object); + demandTaskRecord.setType(clue.getType()); + demandTaskRecord.setClueId(clue.getId()); + demandTaskRecord.setInfoLevel(demandTask.getInfoLevel()); + demandTaskRecord.setTaskLabel(demandTask.getTaskLabel()); + demandTaskRecord.setClueSwitch(demandTask.getClueSwitch()); + demandTaskRecord.setIsAuto(demandTask.getIsAuto()); + if (!demandTaskRecordService.isExists(demandTaskRecord)) { + demandTaskRecordService.save(demandTaskRecord); + if (clue.getType() == 6 || demandTask.getTaskLabel() == 2) { + //生成任务线索 + generateClueRecord(subject, object, clue); + } + } else { + return false; + } + } + return flag; + } + + /** + * 随机生成一个行为 + * + * @param subject 主体人物 + * @param object 客体人物 + * @param behaviour 行为 + */ + public void generateRandomBehaviour(PersonRecord subject, PersonRecord object, Behaviour behaviour) { + boolean flag = false; + + BehaviourRecord behaviourRecord = new BehaviourRecord(); + behaviourRecord.setName(behaviour.getName()); + behaviourRecord.setDescription(behaviour.getDescription()); + behaviourRecord.setBehaviourId(behaviour.getId()); + behaviourRecord.setSubject(subject.getId()); + behaviourRecord.setSubjectName(subject.getName()); + if (!StringUtils.isEmpty(object)) { + behaviourRecord.setObject(object.getId()); + behaviourRecord.setObjectName(object.getName()); + if(!behaviourRecordService.isExists(subject.getId(), object.getId(), behaviour.getId())) { + behaviourRecordService.save(behaviourRecord); + flag = true; + } + }else{ + if (!behaviourRecordService.isExists(subject.getId(), behaviour.getId())) { + behaviourRecordService.save(behaviourRecord); + flag = true; + } + } + + if (flag) { + Clue clue = clueService.getClue(4, behaviour.getId()); + if (!StringUtils.isEmpty(clue)) { + //生成行为线索 + if (!StringUtils.isEmpty(object)) { + generateClueRecord(subject.getId(), object.getId(), clue); + } else { + generateClueRecord(subject.getId(), 0, clue); + } + } + } + } +} diff --git b/src/main/java/com/qiwu/inference/dao/BehaviourMapper.java a/src/main/java/com/qiwu/inference/dao/BehaviourMapper.java new file mode 100644 index 0000000..e028e66 --- /dev/null +++ a/src/main/java/com/qiwu/inference/dao/BehaviourMapper.java @@ -0,0 +1,16 @@ +package com.qiwu.inference.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.qiwu.inference.pojo.Behaviour; + +/** + *

+ * Mapper 接口 + *

+ * + * @author xingxing.ye + * @since 2022-11-02 + */ +public interface BehaviourMapper extends BaseMapper { + +} diff --git b/src/main/java/com/qiwu/inference/dao/BehaviourRecordMapper.java a/src/main/java/com/qiwu/inference/dao/BehaviourRecordMapper.java new file mode 100644 index 0000000..21678ab --- /dev/null +++ a/src/main/java/com/qiwu/inference/dao/BehaviourRecordMapper.java @@ -0,0 +1,16 @@ +package com.qiwu.inference.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.qiwu.inference.pojo.BehaviourRecord; + +/** + *

+ * Mapper 接口 + *

+ * + * @author xingxing.ye + * @since 2022-11-02 + */ +public interface BehaviourRecordMapper extends BaseMapper { + +} diff --git b/src/main/java/com/qiwu/inference/dao/ClueMapper.java a/src/main/java/com/qiwu/inference/dao/ClueMapper.java new file mode 100644 index 0000000..26c1c06 --- /dev/null +++ a/src/main/java/com/qiwu/inference/dao/ClueMapper.java @@ -0,0 +1,16 @@ +package com.qiwu.inference.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.qiwu.inference.pojo.Clue; + +/** + *

+ * Mapper 接口 + *

+ * + * @author xingxing.ye + * @since 2022-11-07 + */ +public interface ClueMapper extends BaseMapper { + +} diff --git b/src/main/java/com/qiwu/inference/dao/ClueRecordMapper.java a/src/main/java/com/qiwu/inference/dao/ClueRecordMapper.java new file mode 100644 index 0000000..6ece70c --- /dev/null +++ a/src/main/java/com/qiwu/inference/dao/ClueRecordMapper.java @@ -0,0 +1,16 @@ +package com.qiwu.inference.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.qiwu.inference.pojo.ClueRecord; + +/** + *

+ * Mapper 接口 + *

+ * + * @author xingxing.ye + * @since 2022-11-02 + */ +public interface ClueRecordMapper extends BaseMapper { + +} diff --git b/src/main/java/com/qiwu/inference/dao/DemandTaskMapper.java a/src/main/java/com/qiwu/inference/dao/DemandTaskMapper.java new file mode 100644 index 0000000..1eefccf --- /dev/null +++ a/src/main/java/com/qiwu/inference/dao/DemandTaskMapper.java @@ -0,0 +1,16 @@ +package com.qiwu.inference.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.qiwu.inference.pojo.DemandTask; + +/** + *

+ * Mapper 接口 + *

+ * + * @author xingxing.ye + * @since 2022-11-07 + */ +public interface DemandTaskMapper extends BaseMapper { + +} diff --git b/src/main/java/com/qiwu/inference/dao/DemandTaskRecordMapper.java a/src/main/java/com/qiwu/inference/dao/DemandTaskRecordMapper.java new file mode 100644 index 0000000..23cfd00 --- /dev/null +++ a/src/main/java/com/qiwu/inference/dao/DemandTaskRecordMapper.java @@ -0,0 +1,16 @@ +package com.qiwu.inference.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.qiwu.inference.pojo.DemandTaskRecord; + +/** + *

+ * Mapper 接口 + *

+ * + * @author xingxing.ye + * @since 2022-11-07 + */ +public interface DemandTaskRecordMapper extends BaseMapper { + +} diff --git b/src/main/java/com/qiwu/inference/dao/DispositionMapper.java a/src/main/java/com/qiwu/inference/dao/DispositionMapper.java new file mode 100644 index 0000000..c04d369 --- /dev/null +++ a/src/main/java/com/qiwu/inference/dao/DispositionMapper.java @@ -0,0 +1,16 @@ +package com.qiwu.inference.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.qiwu.inference.pojo.Disposition; + +/** + *

+ * Mapper 接口 + *

+ * + * @author xingxing.ye + * @since 2022-11-02 + */ +public interface DispositionMapper extends BaseMapper { + +} diff --git b/src/main/java/com/qiwu/inference/dao/DispositionRecordMapper.java a/src/main/java/com/qiwu/inference/dao/DispositionRecordMapper.java new file mode 100644 index 0000000..1451fbc --- /dev/null +++ a/src/main/java/com/qiwu/inference/dao/DispositionRecordMapper.java @@ -0,0 +1,16 @@ +package com.qiwu.inference.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.qiwu.inference.pojo.DispositionRecord; + +/** + *

+ * Mapper 接口 + *

+ * + * @author xingxing.ye + * @since 2022-11-02 + */ +public interface DispositionRecordMapper extends BaseMapper { + +} diff --git b/src/main/java/com/qiwu/inference/dao/DispositionTypeMapper.java a/src/main/java/com/qiwu/inference/dao/DispositionTypeMapper.java new file mode 100644 index 0000000..d693ba1 --- /dev/null +++ a/src/main/java/com/qiwu/inference/dao/DispositionTypeMapper.java @@ -0,0 +1,16 @@ +package com.qiwu.inference.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.qiwu.inference.pojo.DispositionType; + +/** + *

+ * Mapper 接口 + *

+ * + * @author xingxing.ye + * @since 2022-11-04 + */ +public interface DispositionTypeMapper extends BaseMapper { + +} diff --git b/src/main/java/com/qiwu/inference/dao/EndGoalMapper.java a/src/main/java/com/qiwu/inference/dao/EndGoalMapper.java new file mode 100644 index 0000000..ea13e90 --- /dev/null +++ a/src/main/java/com/qiwu/inference/dao/EndGoalMapper.java @@ -0,0 +1,16 @@ +package com.qiwu.inference.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.qiwu.inference.pojo.EndGoal; + +/** + *

+ * Mapper 接口 + *

+ * + * @author xingxing.ye + * @since 2022-11-02 + */ +public interface EndGoalMapper extends BaseMapper { + +} diff --git b/src/main/java/com/qiwu/inference/dao/IdentityMapper.java a/src/main/java/com/qiwu/inference/dao/IdentityMapper.java new file mode 100644 index 0000000..c6c5369 --- /dev/null +++ a/src/main/java/com/qiwu/inference/dao/IdentityMapper.java @@ -0,0 +1,17 @@ +package com.qiwu.inference.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.qiwu.inference.pojo.Identity; +import com.qiwu.inference.pojo.Person; + +/** + *

+ * Mapper 接口 + *

+ * + * @author xingxing.ye + * @since 2022-11-02 + */ +public interface IdentityMapper extends BaseMapper { + +} diff --git b/src/main/java/com/qiwu/inference/dao/ItemMapper.java a/src/main/java/com/qiwu/inference/dao/ItemMapper.java new file mode 100644 index 0000000..e3577bf --- /dev/null +++ a/src/main/java/com/qiwu/inference/dao/ItemMapper.java @@ -0,0 +1,16 @@ +package com.qiwu.inference.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.qiwu.inference.pojo.Item; + +/** + *

+ * Mapper 接口 + *

+ * + * @author xingxing.ye + * @since 2022-11-02 + */ +public interface ItemMapper extends BaseMapper { + +} diff --git b/src/main/java/com/qiwu/inference/dao/KeyClueMapper.java a/src/main/java/com/qiwu/inference/dao/KeyClueMapper.java new file mode 100644 index 0000000..2335668 --- /dev/null +++ a/src/main/java/com/qiwu/inference/dao/KeyClueMapper.java @@ -0,0 +1,16 @@ +package com.qiwu.inference.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.qiwu.inference.pojo.KeyClue; + +/** + *

+ * Mapper 接口 + *

+ * + * @author xingxing.ye + * @since 2022-11-02 + */ +public interface KeyClueMapper extends BaseMapper { + +} diff --git b/src/main/java/com/qiwu/inference/dao/LocationMapper.java a/src/main/java/com/qiwu/inference/dao/LocationMapper.java new file mode 100644 index 0000000..ceb6a7a --- /dev/null +++ a/src/main/java/com/qiwu/inference/dao/LocationMapper.java @@ -0,0 +1,16 @@ +package com.qiwu.inference.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.qiwu.inference.pojo.Location; + +/** + *

+ * Mapper 接口 + *

+ * + * @author xingxing.ye + * @since 2022-11-02 + */ +public interface LocationMapper extends BaseMapper { + +} diff --git b/src/main/java/com/qiwu/inference/dao/PersonMapper.java a/src/main/java/com/qiwu/inference/dao/PersonMapper.java new file mode 100644 index 0000000..8fc10ea --- /dev/null +++ a/src/main/java/com/qiwu/inference/dao/PersonMapper.java @@ -0,0 +1,16 @@ +package com.qiwu.inference.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.qiwu.inference.pojo.Person; + +/** + *

+ * Mapper 接口 + *

+ * + * @author xingxing.ye + * @since 2022-11-02 + */ +public interface PersonMapper extends BaseMapper { + +} diff --git b/src/main/java/com/qiwu/inference/dao/PersonRecordMapper.java a/src/main/java/com/qiwu/inference/dao/PersonRecordMapper.java new file mode 100644 index 0000000..7665cb8 --- /dev/null +++ a/src/main/java/com/qiwu/inference/dao/PersonRecordMapper.java @@ -0,0 +1,18 @@ +package com.qiwu.inference.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.qiwu.inference.pojo.PersonRecord; + +import java.util.List; + +/** + *

+ * Mapper 接口 + *

+ * + * @author xingxing.ye + * @since 2022-11-02 + */ +public interface PersonRecordMapper extends BaseMapper { + List getGateNo(); +} diff --git b/src/main/java/com/qiwu/inference/dao/RelationMapper.java a/src/main/java/com/qiwu/inference/dao/RelationMapper.java new file mode 100644 index 0000000..2a75e33 --- /dev/null +++ a/src/main/java/com/qiwu/inference/dao/RelationMapper.java @@ -0,0 +1,16 @@ +package com.qiwu.inference.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.qiwu.inference.pojo.Relation; + +/** + *

+ * Mapper 接口 + *

+ * + * @author xingxing.ye + * @since 2022-11-03 + */ +public interface RelationMapper extends BaseMapper { + +} diff --git b/src/main/java/com/qiwu/inference/dao/RelationRecordMapper.java a/src/main/java/com/qiwu/inference/dao/RelationRecordMapper.java new file mode 100644 index 0000000..a320372 --- /dev/null +++ a/src/main/java/com/qiwu/inference/dao/RelationRecordMapper.java @@ -0,0 +1,16 @@ +package com.qiwu.inference.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.qiwu.inference.pojo.RelationRecord; + +/** + *

+ * Mapper 接口 + *

+ * + * @author xingxing.ye + * @since 2022-11-02 + */ +public interface RelationRecordMapper extends BaseMapper { + +} diff --git b/src/main/java/com/qiwu/inference/dao/RelationTypeMapper.java a/src/main/java/com/qiwu/inference/dao/RelationTypeMapper.java new file mode 100644 index 0000000..bb5d384 --- /dev/null +++ a/src/main/java/com/qiwu/inference/dao/RelationTypeMapper.java @@ -0,0 +1,16 @@ +package com.qiwu.inference.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.qiwu.inference.pojo.RelationType; + +/** + *

+ * Mapper 接口 + *

+ * + * @author xingxing.ye + * @since 2022-11-03 + */ +public interface RelationTypeMapper extends BaseMapper { + +} diff --git b/src/main/java/com/qiwu/inference/dao/TaskConditionMapper.java a/src/main/java/com/qiwu/inference/dao/TaskConditionMapper.java new file mode 100644 index 0000000..de0c00a --- /dev/null +++ a/src/main/java/com/qiwu/inference/dao/TaskConditionMapper.java @@ -0,0 +1,16 @@ +package com.qiwu.inference.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.qiwu.inference.pojo.TaskCondition; + +/** + *

+ * Mapper 接口 + *

+ * + * @author xingxing.ye + * @since 2022-11-02 + */ +public interface TaskConditionMapper extends BaseMapper { + +} diff --git b/src/main/java/com/qiwu/inference/generator/MyBatisPlusGenerator.java a/src/main/java/com/qiwu/inference/generator/MyBatisPlusGenerator.java new file mode 100644 index 0000000..30b7496 --- /dev/null +++ a/src/main/java/com/qiwu/inference/generator/MyBatisPlusGenerator.java @@ -0,0 +1,137 @@ +package com.qiwu.inference.generator; + +import cn.hutool.core.util.StrUtil; +import cn.hutool.setting.dialect.Props; +import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException; +import com.baomidou.mybatisplus.generator.AutoGenerator; +import com.baomidou.mybatisplus.generator.config.*; +import com.baomidou.mybatisplus.generator.config.po.LikeTable; +import com.baomidou.mybatisplus.generator.config.querys.MySqlQuery; +import com.baomidou.mybatisplus.generator.config.rules.DateType; +import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy; +import com.baomidou.mybatisplus.generator.engine.VelocityTemplateEngine; + +import java.util.Collections; +import java.util.Scanner; + +/** + * MyBatisPlus代码生成器 + */ +public class MyBatisPlusGenerator { + + public static void main(String[] args) { + String projectPath = System.getProperty("user.dir"); + String moduleName = scanner("模块名"); + String[] tableNames = scanner("表名,多个英文逗号分割").split(","); + // 代码生成器 + AutoGenerator autoGenerator = new AutoGenerator(initDataSourceConfig()); + autoGenerator.global(initGlobalConfig(projectPath)); + autoGenerator.packageInfo(initPackageConfig(projectPath,moduleName)); + autoGenerator.injection(initInjectionConfig(projectPath, moduleName)); + autoGenerator.template(initTemplateConfig()); + autoGenerator.strategy(initStrategyConfig(tableNames)); + autoGenerator.execute(new VelocityTemplateEngine()); + } + + /** + * 读取控制台内容信息 + */ + private static String scanner(String tip) { + Scanner scanner = new Scanner(System.in); + System.out.println(("请输入" + tip + ":")); + if (scanner.hasNext()) { + String next = scanner.next(); + if (StrUtil.isNotEmpty(next)) { + return next; + } + } + throw new MybatisPlusException("请输入正确的" + tip + "!"); + } + + /** + * 初始化全局配置 + */ + private static GlobalConfig initGlobalConfig(String projectPath) { + return new GlobalConfig.Builder() + .outputDir(projectPath + "/src/main/java") + .author("xingxing.ye") + .disableOpenDir() + .enableSwagger() + .dateType(DateType.ONLY_DATE) + .build(); + } + + /** + * 初始化数据源配置 + */ + private static DataSourceConfig initDataSourceConfig() { + Props props = new Props("generator.properties"); + String url = props.getStr("dataSource.url"); + String username = props.getStr("dataSource.username"); + String password = props.getStr("dataSource.password"); + return new DataSourceConfig.Builder(url,username,password) + .dbQuery(new MySqlQuery()) + .build(); + } + + /** + * 初始化包配置 + */ + private static PackageConfig initPackageConfig(String projectPath,String moduleName) { + Props props = new Props("generator.properties"); + return new PackageConfig.Builder() + .moduleName(moduleName) + .parent(props.getStr("package.base")) + .entity("model") + .pathInfo(Collections.singletonMap(OutputFile.xml, projectPath + "/src/main/resources/com/qiwu/api/dao/" + moduleName)) + .build(); + } + + /** + * 初始化模板配置 + */ + private static TemplateConfig initTemplateConfig() { + //可以对controller、service、entity模板进行配置 + return new TemplateConfig.Builder().build(); + } + + /** + * 初始化策略配置 + */ + private static StrategyConfig initStrategyConfig(String[] tableNames) { + StrategyConfig.Builder builder = new StrategyConfig.Builder(); + builder.entityBuilder() + .naming(NamingStrategy.underline_to_camel) + .columnNaming(NamingStrategy.underline_to_camel) + .enableLombok() + .formatFileName("%s") + .mapperBuilder() + .enableBaseResultMap() + .formatMapperFileName("%sMapper") + .formatXmlFileName("%sMapper") + .serviceBuilder() + .formatServiceFileName("%sService") + .formatServiceImplFileName("%sServiceImpl") + .controllerBuilder() + .enableRestStyle() + .formatFileName("%sController"); + //当表名中带*号时可以启用通配符模式 + if (tableNames.length == 1 && tableNames[0].contains("*")) { + String[] likeStr = tableNames[0].split("_"); + String likePrefix = likeStr[0] + "_"; + builder.likeTable(new LikeTable(likePrefix)); + } else { + builder.addInclude(tableNames); + } + return builder.build(); + } + + /** + * 初始化自定义配置 + */ + private static InjectionConfig initInjectionConfig(String projectPath, String moduleName) { + // 自定义配置 + return new InjectionConfig.Builder().build(); + } + +} \ No newline at end of file diff --git b/src/main/java/com/qiwu/inference/pojo/Behaviour.java a/src/main/java/com/qiwu/inference/pojo/Behaviour.java new file mode 100644 index 0000000..701e37b --- /dev/null +++ a/src/main/java/com/qiwu/inference/pojo/Behaviour.java @@ -0,0 +1,84 @@ +package com.qiwu.inference.pojo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.Setter; + +import java.io.Serializable; +import java.util.Date; + +/** + *

+ * + *

+ * + * @author xingxing.ye + * @since 2022-11-02 + */ +@Getter +@Setter +@ApiModel(value = "Behaviour对象", description = "") +public class Behaviour implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty("行为id") + private Integer id; + + @ApiModelProperty("行为名称") + private String name; + + @ApiModelProperty("行为描述") + private String description; + + @ApiModelProperty("发生的概率") + private double generationProbability; + + @ApiModelProperty("行为对象身份(B)") + private String objectIdentity; + + @ApiModelProperty("关联对象id") + private String associatedId; + + @ApiModelProperty("行为人性格喜好|概率增减(A)") + private String subjectDisposition; + + @ApiModelProperty("行为人身份|概率增减(A)") + private String subjectIdentityProbability; + + @ApiModelProperty("行为对象身份|概率增减(B)") + private String objectIdentityProbability; + + @ApiModelProperty("与行为对象关系|概率影响(A与B)") + private String objectRelationProbability; + + @ApiModelProperty("行为对象性格喜好|概率影响(B)") + private String objectDispositionProbability; + + @ApiModelProperty("行为人性别|行为对象性别|概率影响(A)") + private String genderProbability; + + @ApiModelProperty("互斥行为") + private String exclusionBehaviour; + + @ApiModelProperty("反向行为") + private String inverseBehaviour; + + @ApiModelProperty("反向行为标签:0为非反向行为,1为反向行为") + private int inverseLabel; + + @ApiModelProperty("单人行为标签:0为双人行为,1为单人行为") + private int singleLabel; + + @ApiModelProperty("信息级别") + private int infoLevel; + + @ApiModelProperty("创建时间") + private Date createTime; + + @ApiModelProperty("更新时间") + private Date updateTime; + + +} diff --git b/src/main/java/com/qiwu/inference/pojo/BehaviourRecord.java a/src/main/java/com/qiwu/inference/pojo/BehaviourRecord.java new file mode 100644 index 0000000..4d6c099 --- /dev/null +++ a/src/main/java/com/qiwu/inference/pojo/BehaviourRecord.java @@ -0,0 +1,62 @@ +package com.qiwu.inference.pojo; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.Setter; + +import java.io.Serializable; +import java.util.Date; + +/** + *

+ * + *

+ * + * @author xingxing.ye + * @since 2022-11-02 + */ +@Getter +@Setter +@TableName("behaviour_record") +@ApiModel(value = "BehaviourRecord对象", description = "") +public class BehaviourRecord implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty("行为记录id") + @TableId(value = "id", type = IdType.AUTO) + private Integer id; + + @ApiModelProperty("行为名称") + private String name; + + @ApiModelProperty("行为id") + private int behaviourId; + + @ApiModelProperty("行为描述") + private String description; + + @ApiModelProperty("主体:1") + private int subject; + + @ApiModelProperty("主体名称:老王") + private String subjectName; + + @ApiModelProperty("客体:2") + private int object; + + @ApiModelProperty("客体名称:小美") + private String objectName; + + @ApiModelProperty("创建时间") + private Date createTime; + + @ApiModelProperty("更新时间") + private Date updateTime; + + +} diff --git b/src/main/java/com/qiwu/inference/pojo/Clue.java a/src/main/java/com/qiwu/inference/pojo/Clue.java new file mode 100644 index 0000000..9a63421 --- /dev/null +++ a/src/main/java/com/qiwu/inference/pojo/Clue.java @@ -0,0 +1,75 @@ +package com.qiwu.inference.pojo; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.Setter; + +import java.io.Serializable; +import java.util.Date; + +/** + *

+ * + *

+ * + * @author xingxing.ye + * @since 2022-11-07 + */ +@Getter +@Setter +@ApiModel(value = "Clue对象", description = "") +public class Clue implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty("id") + @TableId(value = "id", type = IdType.AUTO) + private Integer id; + + @ApiModelProperty("线索名称") + private String name; + + @ApiModelProperty("描述") + private String description; + + @ApiModelProperty("类型: 1:身份 2:场所 3:性格爱好 4:行为 5:关系 6:任务") + private int type; + + @ApiModelProperty("对应的Id") + private int associatedId; + + @ApiModelProperty("线索模板") + private String clueTemplate; + + @ApiModelProperty("信息级别") + private int infoLevel; + + @ApiModelProperty("信任度") + private int trustDegree; + + @ApiModelProperty("威胁度") + private int deterrenceDegree; + + @ApiModelProperty("概率") + private String prob; + + @ApiModelProperty("自己的信任度") + private int myTrustDegree; + + @ApiModelProperty("自己的威胁度") + private int myDeterrenceDegree; + + @ApiModelProperty("积分") + private int score; + + @ApiModelProperty("创建时间") + private Date createTime; + + @ApiModelProperty("更新时间") + private Date updateTime; + + +} diff --git b/src/main/java/com/qiwu/inference/pojo/ClueRecord.java a/src/main/java/com/qiwu/inference/pojo/ClueRecord.java new file mode 100644 index 0000000..dfae6e4 --- /dev/null +++ a/src/main/java/com/qiwu/inference/pojo/ClueRecord.java @@ -0,0 +1,71 @@ +package com.qiwu.inference.pojo; + +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.Setter; + +import java.io.Serializable; +import java.util.Date; + +/** + *

+ * + *

+ * + * @author xingxing.ye + * @since 2022-11-02 + */ +@Getter +@Setter +@TableName("clue_record") +@ApiModel(value = "ClueRecord对象", description = "") +public class ClueRecord implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty("id") + private Integer id; + + @ApiModelProperty("线索id") + private int clueId; + + @ApiModelProperty("线索名称") + private String clueName; + + @ApiModelProperty("主体") + private int subject; + + @ApiModelProperty("客体") + private int object; + + @ApiModelProperty("描述") + private String description; + + @ApiModelProperty("类型: 1:身份 2:场所 3:性格爱好 4:行为 5:关系 6:任务 9:关键线索 ") + private int type; + + @ApiModelProperty("信息级别") + private int infoLevel; + + @ApiModelProperty("关联人物") + private int associatedPerson; + + @ApiModelProperty("线索模板") + private String clueTemplate; + + @ApiModelProperty("信任度") + private int trustDegree; + + @ApiModelProperty("威胁") + private int deterrenceDegree; + + @ApiModelProperty("创建时间") + private Date createTime; + + @ApiModelProperty("更新时间") + private Date updateTime; + + +} diff --git b/src/main/java/com/qiwu/inference/pojo/DemandTask.java a/src/main/java/com/qiwu/inference/pojo/DemandTask.java new file mode 100644 index 0000000..238fb72 --- /dev/null +++ a/src/main/java/com/qiwu/inference/pojo/DemandTask.java @@ -0,0 +1,121 @@ +package com.qiwu.inference.pojo; + +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.Setter; + +import java.io.Serializable; +import java.util.Date; + +/** + *

+ * + *

+ * + * @author xingxing.ye + * @since 2022-11-07 + */ +@Getter +@Setter +@TableName("demand_task") +@ApiModel(value = "DemandTask对象", description = "") +public class DemandTask implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty("id") + private Integer id; + + @ApiModelProperty("名称") + private String name; + + @ApiModelProperty("任务组") + private int taskGroup; + + @ApiModelProperty("描述") + private String description; + + @ApiModelProperty("主体必要身份") + private String subjectNeedIdentity; + + @ApiModelProperty("客体必要身份") + private String objectNeedIdentity; + + @ApiModelProperty("主体必要性别") + private String subjectNeedGender; + + @ApiModelProperty("客体必要性别") + private String objectNeedGender; + + @ApiModelProperty("开启条件信任度") + private String trustCondition; + + @ApiModelProperty("开启条件威慑度") + private String deterrenceCondition; + + @ApiModelProperty("后置任务") + private String postTask; + + @ApiModelProperty("条件1|次数") + private String condition1; + + @ApiModelProperty("条件2|次数") + private String condition2; + + @ApiModelProperty("关联喜好") + private String associatedDisposition; + + @ApiModelProperty("关联身份") + private String associatedIdentity; + + @ApiModelProperty("关联行为") + private String associatedBehaviour; + + @ApiModelProperty("关联关系") + private String associatedRelation; + + @ApiModelProperty("互斥关系") + private String exclusiveTask; + + @ApiModelProperty("信任度增减") + private int trustDegree; + + @ApiModelProperty("威慑度增减") + private int deterrenceDegree; + + @ApiModelProperty("完成奖励") + private String completionReward; + + @ApiModelProperty("声望增减") + private int reputation; + + @ApiModelProperty("有效次数") + private int effectiveDegree; + + @ApiModelProperty("特殊任务 0 主动任务 1 被动任务") + private int specialTask; + + @ApiModelProperty("信息级别") + private int infoLevel; + + @ApiModelProperty("任务标签 1普通任务 2关键任务 3目标任务") + private int taskLabel; + + @ApiModelProperty("线索开关 0代表不需要线索就可执行,1代表需要线索才能执行此任务") + private int clueSwitch; + + @ApiModelProperty("自动触发") + private int isAuto; + + @ApiModelProperty("负面任务") + private int negativeTask; + + @ApiModelProperty("创建时间") + private Date createTime; + + @ApiModelProperty("更新时间") + private Date updateTime; + +} diff --git b/src/main/java/com/qiwu/inference/pojo/DemandTaskRecord.java a/src/main/java/com/qiwu/inference/pojo/DemandTaskRecord.java new file mode 100644 index 0000000..dbc7f03 --- /dev/null +++ a/src/main/java/com/qiwu/inference/pojo/DemandTaskRecord.java @@ -0,0 +1,74 @@ +package com.qiwu.inference.pojo; + +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.Setter; + +import java.io.Serializable; +import java.util.Date; + +/** + *

+ * + *

+ * + * @author xingxing.ye + * @since 2022-11-07 + */ +@Getter +@Setter +@TableName("demand_task_record") +@ApiModel(value = "DemandTaskRecord对象", description = "") +public class DemandTaskRecord implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty("id") + private Integer id; + + @ApiModelProperty("demandTaskId") + private int demandTaskId; + + @ApiModelProperty("名称") + private String name; + + @ApiModelProperty("任务组") + private int taskGroup; + + @ApiModelProperty("描述") + private String description; + + @ApiModelProperty("主体") + private int subject; + + @ApiModelProperty("客体") + private int object; + + @ApiModelProperty("类型: 1:身份 2:场所 3:性格爱好 4:行为 5:关系 6:任务 9:关键线索") + private int type; + + @ApiModelProperty("线索id") + private int clueId; + + @ApiModelProperty("信息级别") + private int infoLevel; + + @ApiModelProperty("任务标签 1普通任务 2关键任务 3目标任") + private int taskLabel; + + @ApiModelProperty("线索开关 0代表不需要线索就可执行,1代表需要线索才能执行此任务") + private int clueSwitch; + + @ApiModelProperty("自动触发") + private int isAuto; + + @ApiModelProperty("创建时间") + private Date createTime; + + @ApiModelProperty("更新时间") + private Date updateTime; + + +} diff --git b/src/main/java/com/qiwu/inference/pojo/Disposition.java a/src/main/java/com/qiwu/inference/pojo/Disposition.java new file mode 100644 index 0000000..e593836 --- /dev/null +++ a/src/main/java/com/qiwu/inference/pojo/Disposition.java @@ -0,0 +1,78 @@ +package com.qiwu.inference.pojo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.Setter; + +import java.io.Serializable; +import java.util.Date; + +/** + *

+ * + *

+ * + * @author xingxing.ye + * @since 2022-11-02 + */ +@Getter +@Setter +@ApiModel(value = "Disposition对象", description = "") +public class Disposition implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty("性格id") + private Integer id; + + @ApiModelProperty("性格名称") + private String name; + + @ApiModelProperty("性格描述") + private String description; + + @ApiModelProperty("类型") + private int type; + + @ApiModelProperty("基础权重") + private int weight; + + @ApiModelProperty("身份影响权重:") + private String identityWeight; + + @ApiModelProperty("性别影响概率:") + private String genderWeight; + + @ApiModelProperty("年龄影响权重:") + private String ageWeight; + + @ApiModelProperty("信任度初始值") + private String trustDegree; + + @ApiModelProperty("威胁度初始值") + private String deterrenceDegree; + + @ApiModelProperty("弱点条件:") + private String weaknessCondition; + + @ApiModelProperty("对应物品|好感度增减:") + private String itemFavorDegree; + + @ApiModelProperty("对应身份|好感度增减:") + private String identityFavorDegree; + + @ApiModelProperty("互斥性格|喜好:") + private String exclusionDisposition; + + @ApiModelProperty("信息重要级别") + private int infoLevel; + + @ApiModelProperty("创建时间") + private Date createTime; + + @ApiModelProperty("更新时间") + private Date updateTime; + + +} diff --git b/src/main/java/com/qiwu/inference/pojo/DispositionRecord.java a/src/main/java/com/qiwu/inference/pojo/DispositionRecord.java new file mode 100644 index 0000000..992602d --- /dev/null +++ a/src/main/java/com/qiwu/inference/pojo/DispositionRecord.java @@ -0,0 +1,52 @@ +package com.qiwu.inference.pojo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.Setter; + +import java.io.Serializable; +import java.util.Date; + +/** + *

+ * + *

+ * + * @author xingxing.ye + * @since 2022-11-02 + */ +@Getter +@Setter +@ApiModel(value = "DispositionRecord对象", description = "") +public class DispositionRecord implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty("id") + private Integer id; + + @ApiModelProperty("性格id") + private int dispositionId; + + @ApiModelProperty("人物id") + private int subject; + + @ApiModelProperty("性格名称") + private String name; + + @ApiModelProperty("性格描述") + private String description; + + @ApiModelProperty("类型") + private int type; + + + @ApiModelProperty("创建时间") + private Date createTime; + + @ApiModelProperty("更新时间") + private Date updateTime; + + +} diff --git b/src/main/java/com/qiwu/inference/pojo/DispositionType.java a/src/main/java/com/qiwu/inference/pojo/DispositionType.java new file mode 100644 index 0000000..34bf390 --- /dev/null +++ a/src/main/java/com/qiwu/inference/pojo/DispositionType.java @@ -0,0 +1,48 @@ +package com.qiwu.inference.pojo; + +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.Setter; + +import java.io.Serializable; +import java.util.Date; + +/** + *

+ * + *

+ * + * @author xingxing.ye + * @since 2022-11-04 + */ +@Getter +@Setter +@TableName("disposition_type") +@ApiModel(value = "DispositionType对象", description = "") +public class DispositionType implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty("关系类型id") + private Integer id; + + @ApiModelProperty("名称") + private String name; + + @ApiModelProperty("描述") + private String description; + + @ApiModelProperty("概率") + private String probability; + + + @ApiModelProperty("创建时间") + private Date createTime; + + @ApiModelProperty("更新时间") + private Date updateTime; + + +} diff --git b/src/main/java/com/qiwu/inference/pojo/EndGoal.java a/src/main/java/com/qiwu/inference/pojo/EndGoal.java new file mode 100644 index 0000000..6386fb7 --- /dev/null +++ a/src/main/java/com/qiwu/inference/pojo/EndGoal.java @@ -0,0 +1,47 @@ +package com.qiwu.inference.pojo; + +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.Setter; + +import java.io.Serializable; +import java.util.Date; + +/** + *

+ * + *

+ * + * @author xingxing.ye + * @since 2022-11-02 + */ +@Getter +@Setter +@TableName("end_goal") +@ApiModel(value = "EndGoal对象", description = "") +public class EndGoal implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty("结局目标id") + private Integer id; + + @ApiModelProperty("目标名称") + private String name; + + @ApiModelProperty("目标描述") + private String description; + + @ApiModelProperty("组合表:1|2|3|4|5") + private String clueGroup; + + @ApiModelProperty("创建时间") + private Date createTime; + + @ApiModelProperty("更新时间") + private Date updateTime; + + +} diff --git b/src/main/java/com/qiwu/inference/pojo/Identity.java a/src/main/java/com/qiwu/inference/pojo/Identity.java new file mode 100644 index 0000000..c8d2ae0 --- /dev/null +++ a/src/main/java/com/qiwu/inference/pojo/Identity.java @@ -0,0 +1,54 @@ +package com.qiwu.inference.pojo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.Setter; + +import java.io.Serializable; +import java.util.Date; + +/** + *

+ * + *

+ * + * @author xingxing.ye + * @since 2022-11-02 + */ +@Getter +@Setter +@ApiModel(value = "Identity对象", description = "") +public class Identity implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty("id") + private Integer id; + + @ApiModelProperty("身份名称") + private String name; + + @ApiModelProperty("描述") + private String description; + + @ApiModelProperty("关键身份") + private int keyIdentity; + + @ApiModelProperty("对应性别") + private int gender; + + @ApiModelProperty("最大人数") + private int maxNum; + + @ApiModelProperty("信息级别") + private int infoLevel; + + @ApiModelProperty("创建时间") + private Date createTime; + + @ApiModelProperty("更新时间") + private Date updateTime; + + +} diff --git b/src/main/java/com/qiwu/inference/pojo/Item.java a/src/main/java/com/qiwu/inference/pojo/Item.java new file mode 100644 index 0000000..ea8541b --- /dev/null +++ a/src/main/java/com/qiwu/inference/pojo/Item.java @@ -0,0 +1,45 @@ +package com.qiwu.inference.pojo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.Setter; + +import java.io.Serializable; +import java.util.Date; + +/** + *

+ * + *

+ * + * @author xingxing.ye + * @since 2022-11-02 + */ +@Getter +@Setter +@ApiModel(value = "Item对象", description = "") +public class Item implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty("id") + private Integer id; + + @ApiModelProperty("名称") + private String name; + + @ApiModelProperty("描述") + private String description; + + @ApiModelProperty("价格") + private String price; + + @ApiModelProperty("创建时间") + private Date createTime; + + @ApiModelProperty("更新时间") + private Date updateTime; + + +} diff --git b/src/main/java/com/qiwu/inference/pojo/KeyClue.java a/src/main/java/com/qiwu/inference/pojo/KeyClue.java new file mode 100644 index 0000000..1bafdff --- /dev/null +++ a/src/main/java/com/qiwu/inference/pojo/KeyClue.java @@ -0,0 +1,74 @@ +package com.qiwu.inference.pojo; + +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.Setter; + +import java.io.Serializable; +import java.util.Date; + +/** + *

+ * + *

+ * + * @author xingxing.ye + * @since 2022-11-03 + */ +@Getter +@Setter +@TableName("key_clue") +@ApiModel(value = "KeyClue对象", description = "") +public class KeyClue implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty("关键线索id") + private Integer id; + + @ApiModelProperty("名称") + private String name; + + @ApiModelProperty("描述") + private String description; + + @ApiModelProperty("关键人物身份(甲)") + private String subjectIdentity; + + @ApiModelProperty("人物标签(甲)") + private int subjectLabel; + + @ApiModelProperty("掌握线索人物身份(乙)") + private String objectIdentity; + + @ApiModelProperty("人物标签(乙)") + private int objectLabel; + + @ApiModelProperty("关系(留空为自己)") + private String relation; + + @ApiModelProperty("前置线索:90002|90003") + private String precue; + + @ApiModelProperty("线索组合") + private int clueGroup; + + @ApiModelProperty("对应目标") + private int target; + + @ApiModelProperty("对应任务") + private String associatedTask; + + @ApiModelProperty("信息等级") + private int infoLevel; + + @ApiModelProperty("创建时间") + private Date createTime; + + @ApiModelProperty("更新时间") + private Date updateTime; + + +} diff --git b/src/main/java/com/qiwu/inference/pojo/Location.java a/src/main/java/com/qiwu/inference/pojo/Location.java new file mode 100644 index 0000000..33e7077 --- /dev/null +++ a/src/main/java/com/qiwu/inference/pojo/Location.java @@ -0,0 +1,48 @@ +package com.qiwu.inference.pojo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.Setter; + +import java.io.Serializable; +import java.util.Date; + +/** + *

+ * + *

+ * + * @author xingxing.ye + * @since 2022-11-02 + */ +@Getter +@Setter +@ApiModel(value = "Location对象", description = "") +public class Location implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty("场所id") + private Integer id; + + @ApiModelProperty("场所名称") + private String name; + + @ApiModelProperty("描述") + private String description; + + @ApiModelProperty("关键场所") + private String keyLocation; + + @ApiModelProperty("是否隐藏") + private int isHidden; + + @ApiModelProperty("创建时间") + private Date createTime; + + @ApiModelProperty("更新时间") + private Date updateTime; + + +} diff --git b/src/main/java/com/qiwu/inference/pojo/Person.java a/src/main/java/com/qiwu/inference/pojo/Person.java new file mode 100644 index 0000000..7458d57 --- /dev/null +++ a/src/main/java/com/qiwu/inference/pojo/Person.java @@ -0,0 +1,66 @@ +package com.qiwu.inference.pojo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.Setter; + +import java.io.Serializable; +import java.util.Date; + +/** + *

+ * + *

+ * + * @author xingxing.ye + * @since 2022-11-02 + */ +@Getter +@Setter +@ApiModel(value = "Person对象", description = "") +public class Person implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty("id") + private Integer id; + + @ApiModelProperty("人物名称") + private String name; + + @ApiModelProperty("身份名称") + private String identityName; + + @ApiModelProperty("身份id") + private int identityId; + + @ApiModelProperty("对应年龄") + private String age; + + @ApiModelProperty("对应场所") + private int location; + + @ApiModelProperty("对应性别") + private int gender; + + @ApiModelProperty("特定性格") + private String specialDisposition; + + @ApiModelProperty("亲缘关系") + private String kinship; + + @ApiModelProperty("信息重要级别") + private int infoLevel; + + @ApiModelProperty("友好人物") + private int friendly; + + @ApiModelProperty("创建时间") + private Date createTime; + + @ApiModelProperty("更新时间") + private Date updateTime; + + +} diff --git b/src/main/java/com/qiwu/inference/pojo/PersonRecord.java a/src/main/java/com/qiwu/inference/pojo/PersonRecord.java new file mode 100644 index 0000000..a4b24b2 --- /dev/null +++ a/src/main/java/com/qiwu/inference/pojo/PersonRecord.java @@ -0,0 +1,88 @@ +package com.qiwu.inference.pojo; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.Setter; + +import java.io.Serializable; +import java.util.Date; +import java.util.List; + +/** + *

+ * + *

+ * + * @author xingxing.ye + * @since 2022-11-02 + */ +@Getter +@Setter +@TableName("person_record") +@ApiModel(value = "PersonRecord对象", description = "") +public class PersonRecord implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty("人物id") + @TableId(value = "id", type = IdType.AUTO) + private Integer id; + + @ApiModelProperty("关卡编号") + private String gateNo; + + @ApiModelProperty("人物名称") + private String name; + + @ApiModelProperty("人物id") + private int personId; + + @ApiModelProperty("身份id") + private int identityId; + + @ApiModelProperty("身份名称") + private String identityName; + + @ApiModelProperty("年龄") + private int age; + + @ApiModelProperty("是否为关键人物 1 关键人物 2 普通人物") + private int isKey; + + @ApiModelProperty("性别") + private int gender; + + @ApiModelProperty("所在地") + private int location; + + @ApiModelProperty("性格") + private String disposition; + + @ApiModelProperty("友好人物") + private int friendly; + + @ApiModelProperty("人物拥有的关系") + @TableField(exist = false) + private List relations; + + @ApiModelProperty("人物拥有的行为") + @TableField(exist = false) + private List behaviours; + + @ApiModelProperty("人物掌握的线索集合") + @TableField(exist = false) + private List clues; + + @ApiModelProperty("创建时间") + private Date createTime; + + @ApiModelProperty("更新时间") + private Date updateTime; + + +} diff --git b/src/main/java/com/qiwu/inference/pojo/Relation.java a/src/main/java/com/qiwu/inference/pojo/Relation.java new file mode 100644 index 0000000..ed617cf --- /dev/null +++ a/src/main/java/com/qiwu/inference/pojo/Relation.java @@ -0,0 +1,78 @@ +package com.qiwu.inference.pojo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.Setter; + +import java.io.Serializable; +import java.util.Date; + +/** + *

+ * + *

+ * + * @author xingxing.ye + * @since 2022-11-03 + */ +@Getter +@Setter +@ApiModel(value = "Relation对象", description = "") +public class Relation implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty("关系id") + private Integer id; + + @ApiModelProperty("关系名称") + private String name; + + @ApiModelProperty("关系描述") + private String description; + + @ApiModelProperty("关系类型") + private int type; + + @ApiModelProperty("权重") + private int weight; + + @ApiModelProperty("自身|关系人性别影响权重") + private String genderWeight; + + @ApiModelProperty("年龄影响概率增减") + private String ageWeight; + + @ApiModelProperty("年龄差影响概率增减") + private String ageGapsWeight; + + @ApiModelProperty("身份影响概率增减") + private String identityWeight; + + @ApiModelProperty("性格/喜好影响概率增减") + private String dispositionWeight; + + @ApiModelProperty("关系人排除身份") + private String exclusionIdentity; + + @ApiModelProperty("互斥关系") + private String exclusionRelation; + + @ApiModelProperty("反向关系") + private String inverseRelation; + + @ApiModelProperty("信息重要级别") + private int infoLevel; + + @ApiModelProperty("掌握信息级别") + private int masterInfoLevel; + + @ApiModelProperty("创建时间") + private Date createTime; + + @ApiModelProperty("更新时间") + private Date updateTime; + + +} diff --git b/src/main/java/com/qiwu/inference/pojo/RelationRecord.java a/src/main/java/com/qiwu/inference/pojo/RelationRecord.java new file mode 100644 index 0000000..86f40fe --- /dev/null +++ a/src/main/java/com/qiwu/inference/pojo/RelationRecord.java @@ -0,0 +1,68 @@ +package com.qiwu.inference.pojo; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.Setter; + +import java.io.Serializable; +import java.util.Date; + +/** + *

+ * + *

+ * + * @author xingxing.ye + * @since 2022-11-02 + */ +@Getter +@Setter +@TableName("relation_record") +@ApiModel(value = "RelationRecord对象", description = "") +public class RelationRecord implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty("id") + @TableId(value = "id", type = IdType.AUTO) + private Integer id; + + @ApiModelProperty("关系名称") + private String name; + + @ApiModelProperty("关系描述") + private String description; + + @ApiModelProperty("类型") + private int type; + + @ApiModelProperty("关系id") + private int relationId; + + @ApiModelProperty("关系的主体") + private int subject; + + @ApiModelProperty("主体名称:老王") + private String subjectName; + + @ApiModelProperty("关系客体") + private int object; + + @ApiModelProperty("客体名称:老王") + private String objectName; + + @ApiModelProperty("掌握信息级别") + private int masterInfoLevel; + + @ApiModelProperty("创建时间") + private Date createTime; + + @ApiModelProperty("更新时间") + private Date updateTime; + + +} diff --git b/src/main/java/com/qiwu/inference/pojo/RelationType.java a/src/main/java/com/qiwu/inference/pojo/RelationType.java new file mode 100644 index 0000000..7e5fa16 --- /dev/null +++ a/src/main/java/com/qiwu/inference/pojo/RelationType.java @@ -0,0 +1,53 @@ +package com.qiwu.inference.pojo; + +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.Setter; + +import java.io.Serializable; +import java.util.Date; + +/** + *

+ * + *

+ * + * @author xingxing.ye + * @since 2022-11-03 + */ +@Getter +@Setter +@TableName("relation_type") +@ApiModel(value = "RelationType对象", description = "") +public class RelationType implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty("关系类型id") + private Integer id; + + @ApiModelProperty("名称") + private String name; + + @ApiModelProperty("描述") + private String description; + + @ApiModelProperty("概率") + private String probability; + + @ApiModelProperty("身份影响概率增减") + private String identityProbability; + + @ApiModelProperty("性格/喜好影响概率增减") + private String dispositionProbability; + + @ApiModelProperty("创建时间") + private Date createTime; + + @ApiModelProperty("更新时间") + private Date updateTime; + + +} diff --git b/src/main/java/com/qiwu/inference/pojo/TaskCondition.java a/src/main/java/com/qiwu/inference/pojo/TaskCondition.java new file mode 100644 index 0000000..1027936 --- /dev/null +++ a/src/main/java/com/qiwu/inference/pojo/TaskCondition.java @@ -0,0 +1,44 @@ +package com.qiwu.inference.pojo; + +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.Setter; + +import java.io.Serializable; +import java.util.Date; + +/** + *

+ * 任务条件 + *

+ * + * @author xingxing.ye + * @since 2022-11-02 + */ +@Getter +@Setter +@TableName("task_condition") +@ApiModel(value = "TaskCondition对象", description = "") +public class TaskCondition implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty("id") + private Integer id; + + @ApiModelProperty("名称") + private String name; + + @ApiModelProperty("描述") + private String description; + + @ApiModelProperty("创建时间") + private Date createTime; + + @ApiModelProperty("更新时间") + private Date updateTime; + + +} diff --git b/src/main/java/com/qiwu/inference/service/BehaviourRecordService.java a/src/main/java/com/qiwu/inference/service/BehaviourRecordService.java new file mode 100644 index 0000000..19c07aa --- /dev/null +++ a/src/main/java/com/qiwu/inference/service/BehaviourRecordService.java @@ -0,0 +1,23 @@ +package com.qiwu.inference.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.qiwu.inference.pojo.BehaviourRecord; + +import java.util.List; + +/** + *

+ * 服务类 + *

+ * + * @author xingxing.ye + * @since 2022-11-02 + */ +public interface BehaviourRecordService extends IService { + + List getBehaviourRecords(Integer subject); + List getBehaviourRecords(Integer object, Integer behaviourId); + List getBehaviourRecordsNoSubject(Integer subject, Integer behaviourId); + Boolean isExists(Integer subject, Integer behaviourId); + Boolean isExists(Integer subject,Integer object, Integer behaviourId); +} diff --git b/src/main/java/com/qiwu/inference/service/BehaviourService.java a/src/main/java/com/qiwu/inference/service/BehaviourService.java new file mode 100644 index 0000000..fb95060 --- /dev/null +++ a/src/main/java/com/qiwu/inference/service/BehaviourService.java @@ -0,0 +1,19 @@ +package com.qiwu.inference.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.qiwu.inference.pojo.Behaviour; +import com.qiwu.inference.pojo.DemandTask; + +import java.util.List; + +/** + *

+ * 服务类 + *

+ * + * @author xingxing.ye + * @since 2022-11-02 + */ +public interface BehaviourService extends IService { + List list(Integer inverseLabel); +} diff --git b/src/main/java/com/qiwu/inference/service/ClueRecordService.java a/src/main/java/com/qiwu/inference/service/ClueRecordService.java new file mode 100644 index 0000000..c3f61f1 --- /dev/null +++ a/src/main/java/com/qiwu/inference/service/ClueRecordService.java @@ -0,0 +1,23 @@ +package com.qiwu.inference.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.qiwu.inference.pojo.ClueRecord; + +import java.util.List; + +/** + *

+ * 服务类 + *

+ * + * @author xingxing.ye + * @since 2022-11-02 + */ +public interface ClueRecordService extends IService { + + List getClueRecords(Integer subject); + List getClueRecords(Integer subject,Integer infoLevel); + Boolean isExists(ClueRecord clueRecord); + + void delete(Integer clueId,Integer subjectId,Integer objectId); +} diff --git b/src/main/java/com/qiwu/inference/service/ClueService.java a/src/main/java/com/qiwu/inference/service/ClueService.java new file mode 100644 index 0000000..1b78756 --- /dev/null +++ a/src/main/java/com/qiwu/inference/service/ClueService.java @@ -0,0 +1,19 @@ +package com.qiwu.inference.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.qiwu.inference.pojo.Clue; +import io.swagger.v3.oas.models.security.SecurityScheme; + +/** + *

+ * 服务类 + *

+ * + * @author xingxing.ye + * @since 2022-11-07 + */ +public interface ClueService extends IService { + + Clue getClue(Integer type,Integer associatedId); + +} diff --git b/src/main/java/com/qiwu/inference/service/DemandTaskRecordService.java a/src/main/java/com/qiwu/inference/service/DemandTaskRecordService.java new file mode 100644 index 0000000..1156ddc --- /dev/null +++ a/src/main/java/com/qiwu/inference/service/DemandTaskRecordService.java @@ -0,0 +1,29 @@ +package com.qiwu.inference.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.qiwu.inference.pojo.Clue; +import com.qiwu.inference.pojo.DemandTaskRecord; +import com.qiwu.inference.pojo.KeyClue; + +import java.util.List; + +/** + *

+ * 服务类 + *

+ * + * @author xingxing.ye + * @since 2022-11-07 + */ +public interface DemandTaskRecordService extends IService { + List getDemandTaskRecords(Integer subject); + Boolean isExists(Integer subjectId,Integer demandTaskId); + + Boolean isExistsTaskGroup(Integer subjectId,Integer taskGroup); + + Boolean isExists(DemandTaskRecord demandTaskRecord); + + void delete(Integer demandTaskId,Integer subjectId,Integer objectId); + + List getDemandTaskRecords(Integer demandTaskId,Integer subjectId,Integer objectId); +} diff --git b/src/main/java/com/qiwu/inference/service/DemandTaskService.java a/src/main/java/com/qiwu/inference/service/DemandTaskService.java new file mode 100644 index 0000000..b517313 --- /dev/null +++ a/src/main/java/com/qiwu/inference/service/DemandTaskService.java @@ -0,0 +1,23 @@ +package com.qiwu.inference.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.qiwu.inference.pojo.DemandTask; +import com.qiwu.inference.pojo.DemandTaskRecord; + +import java.util.List; + +/** + *

+ * 服务类 + *

+ * + * @author xingxing.ye + * @since 2022-11-07 + */ +public interface DemandTaskService extends IService { + List list(Integer specialTask,Integer taskLabel); + + List list(Integer taskGroup,Integer specialTask,Integer taskLabel); + + int getTaskGroupSize(); +} diff --git b/src/main/java/com/qiwu/inference/service/DispositionRecordService.java a/src/main/java/com/qiwu/inference/service/DispositionRecordService.java new file mode 100644 index 0000000..bb2a77f --- /dev/null +++ a/src/main/java/com/qiwu/inference/service/DispositionRecordService.java @@ -0,0 +1,21 @@ +package com.qiwu.inference.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.qiwu.inference.pojo.DispositionRecord; + +import java.util.List; + +/** + *

+ * 服务类 + *

+ * + * @author xingxing.ye + * @since 2022-11-02 + */ +public interface DispositionRecordService extends IService { + List getDispositionRecords(Integer subject ,Integer dispositionId); + List getDispositionRecords(Integer subject ); + + List getDispositionRecordsNoSubject(Integer subject ,Integer dispositionId); +} diff --git b/src/main/java/com/qiwu/inference/service/DispositionService.java a/src/main/java/com/qiwu/inference/service/DispositionService.java new file mode 100644 index 0000000..7c8a08e --- /dev/null +++ a/src/main/java/com/qiwu/inference/service/DispositionService.java @@ -0,0 +1,18 @@ +package com.qiwu.inference.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.qiwu.inference.pojo.Disposition; + +import java.util.List; + +/** + *

+ * 服务类 + *

+ * + * @author xingxing.ye + * @since 2022-11-02 + */ +public interface DispositionService extends IService { + List getDispositions(Integer type); +} diff --git b/src/main/java/com/qiwu/inference/service/DispositionTypeService.java a/src/main/java/com/qiwu/inference/service/DispositionTypeService.java new file mode 100644 index 0000000..5437b7d --- /dev/null +++ a/src/main/java/com/qiwu/inference/service/DispositionTypeService.java @@ -0,0 +1,16 @@ +package com.qiwu.inference.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.qiwu.inference.pojo.DispositionType; + +/** + *

+ * 服务类 + *

+ * + * @author xingxing.ye + * @since 2022-11-04 + */ +public interface DispositionTypeService extends IService { + +} diff --git b/src/main/java/com/qiwu/inference/service/EndGoalService.java a/src/main/java/com/qiwu/inference/service/EndGoalService.java new file mode 100644 index 0000000..c4670a6 --- /dev/null +++ a/src/main/java/com/qiwu/inference/service/EndGoalService.java @@ -0,0 +1,16 @@ +package com.qiwu.inference.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.qiwu.inference.pojo.EndGoal; + +/** + *

+ * 服务类 + *

+ * + * @author xingxing.ye + * @since 2022-11-02 + */ +public interface EndGoalService extends IService { + +} diff --git b/src/main/java/com/qiwu/inference/service/IdentityService.java a/src/main/java/com/qiwu/inference/service/IdentityService.java new file mode 100644 index 0000000..5c4a81e --- /dev/null +++ a/src/main/java/com/qiwu/inference/service/IdentityService.java @@ -0,0 +1,19 @@ +package com.qiwu.inference.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.qiwu.inference.pojo.Identity; +import com.qiwu.inference.pojo.Person; + +import java.util.List; + +/** + *

+ * 服务类 + *

+ * + * @author xingxing.ye + * @since 2022-11-02 + */ +public interface IdentityService extends IService { + List getIdentitys(String keyIdentity); +} diff --git b/src/main/java/com/qiwu/inference/service/ItemService.java a/src/main/java/com/qiwu/inference/service/ItemService.java new file mode 100644 index 0000000..dbf8426 --- /dev/null +++ a/src/main/java/com/qiwu/inference/service/ItemService.java @@ -0,0 +1,16 @@ +package com.qiwu.inference.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.qiwu.inference.pojo.Item; + +/** + *

+ * 服务类 + *

+ * + * @author xingxing.ye + * @since 2022-11-02 + */ +public interface ItemService extends IService { + +} diff --git b/src/main/java/com/qiwu/inference/service/KeyClueService.java a/src/main/java/com/qiwu/inference/service/KeyClueService.java new file mode 100644 index 0000000..4eb3276 --- /dev/null +++ a/src/main/java/com/qiwu/inference/service/KeyClueService.java @@ -0,0 +1,18 @@ +package com.qiwu.inference.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.qiwu.inference.pojo.KeyClue; + +import java.util.List; + +/** + *

+ * 服务类 + *

+ * + * @author xingxing.ye + * @since 2022-11-02 + */ +public interface KeyClueService extends IService { + List getKeyClues(String clueGroup); +} diff --git b/src/main/java/com/qiwu/inference/service/LocationService.java a/src/main/java/com/qiwu/inference/service/LocationService.java new file mode 100644 index 0000000..524ed7e --- /dev/null +++ a/src/main/java/com/qiwu/inference/service/LocationService.java @@ -0,0 +1,16 @@ +package com.qiwu.inference.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.qiwu.inference.pojo.Location; + +/** + *

+ * 服务类 + *

+ * + * @author xingxing.ye + * @since 2022-11-02 + */ +public interface LocationService extends IService { + +} diff --git b/src/main/java/com/qiwu/inference/service/PersonRecordService.java a/src/main/java/com/qiwu/inference/service/PersonRecordService.java new file mode 100644 index 0000000..bf56a2e --- /dev/null +++ a/src/main/java/com/qiwu/inference/service/PersonRecordService.java @@ -0,0 +1,26 @@ +package com.qiwu.inference.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.qiwu.inference.pojo.PersonRecord; + +import java.util.List; + +/** + *

+ * 服务类 + *

+ * + * @author xingxing.ye + * @since 2022-11-02 + */ +public interface PersonRecordService extends IService { + + List getPersonRecords(String gateNo); + + PersonRecord getPersonRecords(Integer personId,String gateNo); + + List getPersonRecordsNoSubject(Integer subject,Integer identityId); + + List getGateNo(); + +} diff --git b/src/main/java/com/qiwu/inference/service/PersonService.java a/src/main/java/com/qiwu/inference/service/PersonService.java new file mode 100644 index 0000000..5c561c5 --- /dev/null +++ a/src/main/java/com/qiwu/inference/service/PersonService.java @@ -0,0 +1,19 @@ +package com.qiwu.inference.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.qiwu.inference.pojo.Person; + +import java.util.List; + +/** + *

+ * 服务类 + *

+ * + * @author xingxing.ye + * @since 2022-11-02 + */ +public interface PersonService extends IService { + + List getPersons(Integer indentityId); +} diff --git b/src/main/java/com/qiwu/inference/service/RelationRecordService.java a/src/main/java/com/qiwu/inference/service/RelationRecordService.java new file mode 100644 index 0000000..ec875c0 --- /dev/null +++ a/src/main/java/com/qiwu/inference/service/RelationRecordService.java @@ -0,0 +1,23 @@ +package com.qiwu.inference.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.qiwu.inference.pojo.RelationRecord; + +import java.util.List; + +/** + *

+ * 服务类 + *

+ * + * @author xingxing.ye + * @since 2022-11-02 + */ +public interface RelationRecordService extends IService { + + List getRelationRecords(Integer subject); + List getRelationRecordsNoSubject(Integer subject,Integer relationId); + Boolean isExistsRelationTypes(Integer subject,Integer object,Integer type); + List getInverseRelationRecords(Integer object); + Boolean isExists(Integer subjectId,Integer objectId,Integer relationId); +} diff --git b/src/main/java/com/qiwu/inference/service/RelationService.java a/src/main/java/com/qiwu/inference/service/RelationService.java new file mode 100644 index 0000000..14559b3 --- /dev/null +++ a/src/main/java/com/qiwu/inference/service/RelationService.java @@ -0,0 +1,20 @@ +package com.qiwu.inference.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.qiwu.inference.pojo.Relation; + +import java.util.List; + +/** + *

+ * 服务类 + *

+ * + * @author xingxing.ye + * @since 2022-11-03 + */ +public interface RelationService extends IService { + List getRelations(Integer type); + Boolean isExists(String[] relationIds); + List getRelations(String[] relationIds); +} diff --git b/src/main/java/com/qiwu/inference/service/RelationTypeService.java a/src/main/java/com/qiwu/inference/service/RelationTypeService.java new file mode 100644 index 0000000..40d4f09 --- /dev/null +++ a/src/main/java/com/qiwu/inference/service/RelationTypeService.java @@ -0,0 +1,18 @@ +package com.qiwu.inference.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.qiwu.inference.pojo.RelationType; + +import java.util.List; + +/** + *

+ * 服务类 + *

+ * + * @author xingxing.ye + * @since 2022-11-03 + */ +public interface RelationTypeService extends IService { + List list(Integer type); +} diff --git b/src/main/java/com/qiwu/inference/service/TaskConditionService.java a/src/main/java/com/qiwu/inference/service/TaskConditionService.java new file mode 100644 index 0000000..674fe2a --- /dev/null +++ a/src/main/java/com/qiwu/inference/service/TaskConditionService.java @@ -0,0 +1,16 @@ +package com.qiwu.inference.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.qiwu.inference.pojo.TaskCondition; + +/** + *

+ * 服务类 + *

+ * + * @author xingxing.ye + * @since 2022-11-02 + */ +public interface TaskConditionService extends IService { + +} diff --git b/src/main/java/com/qiwu/inference/service/impl/BehaviourRecordServiceImpl.java a/src/main/java/com/qiwu/inference/service/impl/BehaviourRecordServiceImpl.java new file mode 100644 index 0000000..721a109 --- /dev/null +++ a/src/main/java/com/qiwu/inference/service/impl/BehaviourRecordServiceImpl.java @@ -0,0 +1,65 @@ +package com.qiwu.inference.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.qiwu.inference.dao.BehaviourRecordMapper; +import com.qiwu.inference.pojo.BehaviourRecord; +import com.qiwu.inference.service.BehaviourRecordService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + *

+ * 服务实现类 + *

+ * + * @author xingxing.ye + * @since 2022-11-02 + */ +@Service +public class BehaviourRecordServiceImpl extends ServiceImpl implements BehaviourRecordService { + + @Autowired + private BehaviourRecordMapper behaviourRecordMapper; + @Override + public List getBehaviourRecords(Integer subject) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.lambda().eq(BehaviourRecord::getSubject,subject); + return list(wrapper); + } + + @Override + public List getBehaviourRecords(Integer object, Integer behaviourId) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.lambda().eq(BehaviourRecord::getObject,object); + wrapper.lambda().eq(BehaviourRecord::getBehaviourId,behaviourId); + return list(wrapper); + } + + @Override + public List getBehaviourRecordsNoSubject(Integer subject, Integer behaviourId) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.lambda().eq(BehaviourRecord::getBehaviourId,behaviourId); + wrapper.lambda().and(temp ->temp.ne(BehaviourRecord::getSubject, subject).or().ne(BehaviourRecord::getObject, subject)); + return list(wrapper); + } + + @Override + public Boolean isExists(Integer subject, Integer behaviourId) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.lambda().eq(BehaviourRecord::getSubject,subject); + wrapper.lambda().eq(BehaviourRecord::getBehaviourId,behaviourId); + return behaviourRecordMapper.exists(wrapper); + } + + @Override + public Boolean isExists(Integer subject, Integer object, Integer behaviourId) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.lambda().eq(BehaviourRecord::getSubject,subject); + wrapper.lambda().eq(BehaviourRecord::getObject,object); + wrapper.lambda().eq(BehaviourRecord::getBehaviourId,behaviourId); + return behaviourRecordMapper.exists(wrapper); + } +} diff --git b/src/main/java/com/qiwu/inference/service/impl/BehaviourServiceImpl.java a/src/main/java/com/qiwu/inference/service/impl/BehaviourServiceImpl.java new file mode 100644 index 0000000..57984ff --- /dev/null +++ a/src/main/java/com/qiwu/inference/service/impl/BehaviourServiceImpl.java @@ -0,0 +1,30 @@ +package com.qiwu.inference.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.qiwu.inference.dao.BehaviourMapper; +import com.qiwu.inference.pojo.Behaviour; +import com.qiwu.inference.pojo.DemandTask; +import com.qiwu.inference.service.BehaviourService; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + *

+ * 服务实现类 + *

+ * + * @author xingxing.ye + * @since 2022-11-02 + */ +@Service +public class BehaviourServiceImpl extends ServiceImpl implements BehaviourService { + + @Override + public List list(Integer inverseLabel) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.lambda().eq(Behaviour::getInverseLabel,inverseLabel); + return list(wrapper); + } +} diff --git b/src/main/java/com/qiwu/inference/service/impl/ClueRecordServiceImpl.java a/src/main/java/com/qiwu/inference/service/impl/ClueRecordServiceImpl.java new file mode 100644 index 0000000..06f2752 --- /dev/null +++ a/src/main/java/com/qiwu/inference/service/impl/ClueRecordServiceImpl.java @@ -0,0 +1,73 @@ +package com.qiwu.inference.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.qiwu.inference.dao.ClueRecordMapper; +import com.qiwu.inference.pojo.ClueRecord; +import com.qiwu.inference.service.ClueRecordService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; + +import java.util.List; + +/** + *

+ * 服务实现类 + *

+ * + * @author xingxing.ye + * @since 2022-11-02 + */ +@Service +public class ClueRecordServiceImpl extends ServiceImpl implements ClueRecordService { + @Autowired + private ClueRecordMapper clueRecordMapper; + @Override + public List getClueRecords(Integer subject) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.lambda().eq(ClueRecord::getAssociatedPerson,subject); + return list(wrapper); + } + + @Override + public List getClueRecords(Integer subject, Integer infoLevel) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.lambda().eq(ClueRecord::getAssociatedPerson,subject); + wrapper.lambda().le(ClueRecord::getInfoLevel,infoLevel); + return list(wrapper); + } + + @Override + public Boolean isExists(ClueRecord clueRecord) { + QueryWrapper wrapper = new QueryWrapper<>(); + if(clueRecord.getClueId()!=0){ + wrapper.eq("clue_id",clueRecord.getClueId()); + } + if(!StringUtils.isEmpty(clueRecord.getClueName())){ + wrapper.eq("clue_name",clueRecord.getClueName()); + } + if(clueRecord.getSubject()!=0){ + wrapper.eq("subject",clueRecord.getSubject()); + } + if(!StringUtils.isEmpty(clueRecord.getClueTemplate())){ + wrapper.eq("clue_template",clueRecord.getClueTemplate()); + } + if(clueRecord.getAssociatedPerson()!=0){ + wrapper.eq("associated_person",clueRecord.getAssociatedPerson()); + } + if(clueRecord.getType()!=0){ + wrapper.eq("type",clueRecord.getType()); + } + return clueRecordMapper.exists(wrapper); + } + + @Override + public void delete(Integer clueId, Integer subjectId, Integer objectId) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("clue_id",clueId); + wrapper.eq("subject",subjectId); + wrapper.eq("object",objectId); + clueRecordMapper.delete(wrapper); + } +} diff --git b/src/main/java/com/qiwu/inference/service/impl/ClueServiceImpl.java a/src/main/java/com/qiwu/inference/service/impl/ClueServiceImpl.java new file mode 100644 index 0000000..e80a863 --- /dev/null +++ a/src/main/java/com/qiwu/inference/service/impl/ClueServiceImpl.java @@ -0,0 +1,28 @@ +package com.qiwu.inference.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.qiwu.inference.dao.ClueMapper; +import com.qiwu.inference.pojo.Clue; +import com.qiwu.inference.service.ClueService; +import org.springframework.stereotype.Service; + +/** + *

+ * 服务实现类 + *

+ * + * @author xingxing.ye + * @since 2022-11-07 + */ +@Service +public class ClueServiceImpl extends ServiceImpl implements ClueService { + + @Override + public Clue getClue(Integer type, Integer associatedId) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.lambda().eq(Clue::getType,type); + wrapper.lambda().eq(Clue::getAssociatedId,associatedId); + return getOne(wrapper); + } +} diff --git b/src/main/java/com/qiwu/inference/service/impl/DemandTaskRecordServiceImpl.java a/src/main/java/com/qiwu/inference/service/impl/DemandTaskRecordServiceImpl.java new file mode 100644 index 0000000..1d5dc36 --- /dev/null +++ a/src/main/java/com/qiwu/inference/service/impl/DemandTaskRecordServiceImpl.java @@ -0,0 +1,103 @@ +package com.qiwu.inference.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.qiwu.inference.dao.DemandTaskRecordMapper; +import com.qiwu.inference.pojo.DemandTaskRecord; +import com.qiwu.inference.service.DemandTaskRecordService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; + +import java.util.List; + +/** + *

+ * 服务实现类 + *

+ * + * @author xingxing.ye + * @since 2022-11-07 + */ +@Service +public class DemandTaskRecordServiceImpl extends ServiceImpl implements DemandTaskRecordService { + + @Autowired + private DemandTaskRecordMapper demandTaskRecordMapper; + + @Override + public List getDemandTaskRecords(Integer subject) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.lambda().eq(DemandTaskRecord::getSubject,subject); + return list(wrapper); + } + + @Override + public Boolean isExists(Integer subjectId, Integer demandTaskId) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("subject",subjectId); + wrapper.eq("demand_task_id",demandTaskId); + return demandTaskRecordMapper.exists(wrapper); + } + + @Override + public Boolean isExistsTaskGroup(Integer subjectId, Integer taskGroup) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("subject",subjectId); + wrapper.eq("task_group",taskGroup); + return demandTaskRecordMapper.exists(wrapper); + } + + @Override + public Boolean isExists(DemandTaskRecord demandTaskRecord) { + QueryWrapper wrapper = new QueryWrapper<>(); + if(demandTaskRecord.getDemandTaskId()!=0){ + wrapper.eq("demand_task_id",demandTaskRecord.getDemandTaskId()); + } + if(!StringUtils.isEmpty(demandTaskRecord.getName())){ + wrapper.eq("name",demandTaskRecord.getName()); + } + + if(demandTaskRecord.getSubject()!=0){ + wrapper.eq("subject",demandTaskRecord.getSubject()); + } + + if(demandTaskRecord.getObject()!=0){ + wrapper.eq("object",demandTaskRecord.getObject()); + } + + if(demandTaskRecord.getType()!=0){ + wrapper.eq("type",demandTaskRecord.getType()); + } + + if(demandTaskRecord.getClueId()!=0){ + wrapper.eq("clue_id",demandTaskRecord.getClueId()); + } + + if(demandTaskRecord.getInfoLevel()!=0){ + wrapper.eq("info_level",demandTaskRecord.getInfoLevel()); + } + if(demandTaskRecord.getTaskLabel()!=0){ + wrapper.eq("task_label",demandTaskRecord.getTaskLabel()); + } + return demandTaskRecordMapper.exists(wrapper); + } + + @Override + public void delete(Integer demandTaskId, Integer subjectId, Integer objectId) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("demand_task_id",demandTaskId); + wrapper.eq("subject",subjectId); + wrapper.eq("object",objectId); + demandTaskRecordMapper.delete(wrapper); + } + + @Override + public List getDemandTaskRecords(Integer demandTaskId, Integer subjectId, Integer objectId) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("demand_task_id",demandTaskId); + wrapper.eq("subject",subjectId); + wrapper.eq("object",objectId); + return list(wrapper); + } +} diff --git b/src/main/java/com/qiwu/inference/service/impl/DemandTaskServiceImpl.java a/src/main/java/com/qiwu/inference/service/impl/DemandTaskServiceImpl.java new file mode 100644 index 0000000..81e7d8c --- /dev/null +++ a/src/main/java/com/qiwu/inference/service/impl/DemandTaskServiceImpl.java @@ -0,0 +1,46 @@ +package com.qiwu.inference.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.qiwu.inference.dao.DemandTaskMapper; +import com.qiwu.inference.pojo.DemandTask; +import com.qiwu.inference.service.DemandTaskService; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + *

+ * 服务实现类 + *

+ * + * @author xingxing.ye + * @since 2022-11-07 + */ +@Service +public class DemandTaskServiceImpl extends ServiceImpl implements DemandTaskService { + + @Override + public List list(Integer specialTask,Integer taskLabel) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.lambda().eq(DemandTask::getSpecialTask,specialTask); + wrapper.lambda().eq(DemandTask::getTaskLabel,taskLabel); + return list(wrapper); + } + + @Override + public List list(Integer taskGroup, Integer specialTask, Integer taskLabel) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.lambda().eq(DemandTask::getTaskGroup,taskGroup); + wrapper.lambda().eq(DemandTask::getSpecialTask,specialTask); + wrapper.lambda().eq(DemandTask::getTaskLabel,taskLabel); + return list(wrapper); + } + + @Override + public int getTaskGroupSize() { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.select("task_group"); + return list(wrapper).size(); + } +} diff --git b/src/main/java/com/qiwu/inference/service/impl/DispositionRecordServiceImpl.java a/src/main/java/com/qiwu/inference/service/impl/DispositionRecordServiceImpl.java new file mode 100644 index 0000000..0357f97 --- /dev/null +++ a/src/main/java/com/qiwu/inference/service/impl/DispositionRecordServiceImpl.java @@ -0,0 +1,47 @@ +package com.qiwu.inference.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.qiwu.inference.dao.DispositionRecordMapper; +import com.qiwu.inference.pojo.DispositionRecord; +import com.qiwu.inference.pojo.KeyClue; +import com.qiwu.inference.service.DispositionRecordService; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + *

+ * 服务实现类 + *

+ * + * @author xingxing.ye + * @since 2022-11-02 + */ +@Service +public class DispositionRecordServiceImpl extends ServiceImpl implements DispositionRecordService { + + + @Override + public List getDispositionRecords(Integer subject, Integer dispositionId) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.lambda().eq(DispositionRecord::getSubject,subject); + wrapper.lambda().eq(DispositionRecord::getDispositionId,dispositionId); + return list(wrapper); + } + + @Override + public List getDispositionRecords(Integer subject) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.lambda().eq(DispositionRecord::getSubject,subject); + return list(wrapper); + } + + @Override + public List getDispositionRecordsNoSubject(Integer subject, Integer dispositionId) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.lambda().eq(DispositionRecord::getDispositionId,dispositionId); + wrapper.lambda().ne(DispositionRecord::getSubject,subject); + return list(wrapper); + } +} diff --git b/src/main/java/com/qiwu/inference/service/impl/DispositionServiceImpl.java a/src/main/java/com/qiwu/inference/service/impl/DispositionServiceImpl.java new file mode 100644 index 0000000..a37760a --- /dev/null +++ a/src/main/java/com/qiwu/inference/service/impl/DispositionServiceImpl.java @@ -0,0 +1,31 @@ +package com.qiwu.inference.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.qiwu.inference.dao.DispositionMapper; +import com.qiwu.inference.pojo.Disposition; +import com.qiwu.inference.pojo.DispositionRecord; +import com.qiwu.inference.service.DispositionService; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + *

+ * 服务实现类 + *

+ * + * @author xingxing.ye + * @since 2022-11-02 + */ +@Service +public class DispositionServiceImpl extends ServiceImpl implements DispositionService { + + + @Override + public List getDispositions(Integer type) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.lambda().eq(Disposition::getType,type); + return list(wrapper); + } +} diff --git b/src/main/java/com/qiwu/inference/service/impl/DispositionTypeServiceImpl.java a/src/main/java/com/qiwu/inference/service/impl/DispositionTypeServiceImpl.java new file mode 100644 index 0000000..ea03472 --- /dev/null +++ a/src/main/java/com/qiwu/inference/service/impl/DispositionTypeServiceImpl.java @@ -0,0 +1,20 @@ +package com.qiwu.inference.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.qiwu.inference.dao.DispositionTypeMapper; +import com.qiwu.inference.pojo.DispositionType; +import com.qiwu.inference.service.DispositionTypeService; +import org.springframework.stereotype.Service; + +/** + *

+ * 服务实现类 + *

+ * + * @author xingxing.ye + * @since 2022-11-04 + */ +@Service +public class DispositionTypeServiceImpl extends ServiceImpl implements DispositionTypeService { + +} diff --git b/src/main/java/com/qiwu/inference/service/impl/EndGoalServiceImpl.java a/src/main/java/com/qiwu/inference/service/impl/EndGoalServiceImpl.java new file mode 100644 index 0000000..f76ef93 --- /dev/null +++ a/src/main/java/com/qiwu/inference/service/impl/EndGoalServiceImpl.java @@ -0,0 +1,20 @@ +package com.qiwu.inference.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.qiwu.inference.dao.EndGoalMapper; +import com.qiwu.inference.pojo.EndGoal; +import com.qiwu.inference.service.EndGoalService; +import org.springframework.stereotype.Service; + +/** + *

+ * 服务实现类 + *

+ * + * @author xingxing.ye + * @since 2022-11-02 + */ +@Service +public class EndGoalServiceImpl extends ServiceImpl implements EndGoalService { + +} diff --git b/src/main/java/com/qiwu/inference/service/impl/IdentityServiceImpl.java a/src/main/java/com/qiwu/inference/service/impl/IdentityServiceImpl.java new file mode 100644 index 0000000..a812354 --- /dev/null +++ a/src/main/java/com/qiwu/inference/service/impl/IdentityServiceImpl.java @@ -0,0 +1,30 @@ +package com.qiwu.inference.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.qiwu.inference.dao.IdentityMapper; +import com.qiwu.inference.pojo.Identity; +import com.qiwu.inference.pojo.Person; +import com.qiwu.inference.service.IdentityService; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + *

+ * 服务实现类 + *

+ * + * @author xingxing.ye + * @since 2022-11-02 + */ +@Service +public class IdentityServiceImpl extends ServiceImpl implements IdentityService { + + @Override + public List getIdentitys(String keyIdentity) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.lambda().eq(Identity::getKeyIdentity,keyIdentity); + return list(wrapper); + } +} diff --git b/src/main/java/com/qiwu/inference/service/impl/ItemServiceImpl.java a/src/main/java/com/qiwu/inference/service/impl/ItemServiceImpl.java new file mode 100644 index 0000000..6dceefb --- /dev/null +++ a/src/main/java/com/qiwu/inference/service/impl/ItemServiceImpl.java @@ -0,0 +1,20 @@ +package com.qiwu.inference.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.qiwu.inference.dao.ItemMapper; +import com.qiwu.inference.pojo.Item; +import com.qiwu.inference.service.ItemService; +import org.springframework.stereotype.Service; + +/** + *

+ * 服务实现类 + *

+ * + * @author xingxing.ye + * @since 2022-11-02 + */ +@Service +public class ItemServiceImpl extends ServiceImpl implements ItemService { + +} diff --git b/src/main/java/com/qiwu/inference/service/impl/KeyClueServiceImpl.java a/src/main/java/com/qiwu/inference/service/impl/KeyClueServiceImpl.java new file mode 100644 index 0000000..9e644b9 --- /dev/null +++ a/src/main/java/com/qiwu/inference/service/impl/KeyClueServiceImpl.java @@ -0,0 +1,29 @@ +package com.qiwu.inference.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.qiwu.inference.dao.KeyClueMapper; +import com.qiwu.inference.pojo.KeyClue; +import com.qiwu.inference.service.KeyClueService; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + *

+ * 服务实现类 + *

+ * + * @author xingxing.ye + * @since 2022-11-02 + */ +@Service +public class KeyClueServiceImpl extends ServiceImpl implements KeyClueService { + + @Override + public List getKeyClues(String clueGroup) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.lambda().eq(KeyClue::getClueGroup,clueGroup); + return list(wrapper); + } +} diff --git b/src/main/java/com/qiwu/inference/service/impl/LocationServiceImpl.java a/src/main/java/com/qiwu/inference/service/impl/LocationServiceImpl.java new file mode 100644 index 0000000..5a1dece --- /dev/null +++ a/src/main/java/com/qiwu/inference/service/impl/LocationServiceImpl.java @@ -0,0 +1,20 @@ +package com.qiwu.inference.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.qiwu.inference.dao.LocationMapper; +import com.qiwu.inference.pojo.Location; +import com.qiwu.inference.service.LocationService; +import org.springframework.stereotype.Service; + +/** + *

+ * 服务实现类 + *

+ * + * @author xingxing.ye + * @since 2022-11-02 + */ +@Service +public class LocationServiceImpl extends ServiceImpl implements LocationService { + +} diff --git b/src/main/java/com/qiwu/inference/service/impl/PersonRecordServiceImpl.java a/src/main/java/com/qiwu/inference/service/impl/PersonRecordServiceImpl.java new file mode 100644 index 0000000..213e6f5 --- /dev/null +++ a/src/main/java/com/qiwu/inference/service/impl/PersonRecordServiceImpl.java @@ -0,0 +1,57 @@ +package com.qiwu.inference.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.qiwu.inference.dao.PersonRecordMapper; +import com.qiwu.inference.pojo.BehaviourRecord; +import com.qiwu.inference.pojo.ClueRecord; +import com.qiwu.inference.pojo.DispositionRecord; +import com.qiwu.inference.pojo.PersonRecord; +import com.qiwu.inference.service.PersonRecordService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + *

+ * 服务实现类 + *

+ * + * @author xingxing.ye + * @since 2022-11-02 + */ +@Service +public class PersonRecordServiceImpl extends ServiceImpl implements PersonRecordService { + + @Autowired + PersonRecordMapper personRecordMapper; + @Override + public List getPersonRecords(String gateNo) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.lambda().eq(PersonRecord::getGateNo,gateNo); + return list(wrapper); + } + + @Override + public PersonRecord getPersonRecords(Integer personId,String gateNo) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.lambda().eq(PersonRecord::getPersonId,personId); + wrapper.lambda().eq(PersonRecord::getGateNo,gateNo); + return getOne(wrapper); + } + + + @Override + public List getPersonRecordsNoSubject(Integer subject, Integer identityId) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.lambda().eq(PersonRecord::getIdentityId,identityId); + wrapper.lambda().ne(PersonRecord::getId,subject); + return list(wrapper); + } + + @Override + public List getGateNo() { + return personRecordMapper.getGateNo(); + } +} diff --git b/src/main/java/com/qiwu/inference/service/impl/PersonServiceImpl.java a/src/main/java/com/qiwu/inference/service/impl/PersonServiceImpl.java new file mode 100644 index 0000000..3417936 --- /dev/null +++ a/src/main/java/com/qiwu/inference/service/impl/PersonServiceImpl.java @@ -0,0 +1,30 @@ +package com.qiwu.inference.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.qiwu.inference.dao.PersonMapper; +import com.qiwu.inference.pojo.Behaviour; +import com.qiwu.inference.pojo.Person; +import com.qiwu.inference.service.PersonService; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + *

+ * 服务实现类 + *

+ * + * @author xingxing.ye + * @since 2022-11-02 + */ +@Service +public class PersonServiceImpl extends ServiceImpl implements PersonService { + + @Override + public List getPersons(Integer identityId) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.lambda().eq(Person::getIdentityId,identityId); + return list(wrapper); + } +} diff --git b/src/main/java/com/qiwu/inference/service/impl/RelationRecordServiceImpl.java a/src/main/java/com/qiwu/inference/service/impl/RelationRecordServiceImpl.java new file mode 100644 index 0000000..29863d6 --- /dev/null +++ a/src/main/java/com/qiwu/inference/service/impl/RelationRecordServiceImpl.java @@ -0,0 +1,67 @@ +package com.qiwu.inference.service.impl; + + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.qiwu.inference.dao.RelationMapper; +import com.qiwu.inference.dao.RelationRecordMapper; +import com.qiwu.inference.pojo.BehaviourRecord; +import com.qiwu.inference.pojo.KeyClue; +import com.qiwu.inference.pojo.Relation; +import com.qiwu.inference.pojo.RelationRecord; +import com.qiwu.inference.service.RelationRecordService; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + *

+ * 服务实现类 + *

+ * + * @author xingxing.ye + * @since 2022-11-02 + */ +@Service +public class RelationRecordServiceImpl extends ServiceImpl implements RelationRecordService{ + + @Override + public List getRelationRecords(Integer subject) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.lambda().eq(RelationRecord::getSubject,subject); + return list(wrapper); + } + + @Override + public List getRelationRecordsNoSubject(Integer subject, Integer relationId) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.lambda().eq(RelationRecord::getRelationId,relationId); + wrapper.lambda().and(tmp ->tmp.ne(RelationRecord::getSubject, subject).or().ne(RelationRecord::getObject, subject)); + return list(wrapper); + } + + @Override + public Boolean isExistsRelationTypes(Integer subject, Integer object,Integer type) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("subject",subject); + wrapper.eq("object",object); + wrapper.eq("type",type); + return list(wrapper).size() > 0; + } + + @Override + public List getInverseRelationRecords(Integer object) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.lambda().eq(RelationRecord::getObject,object); + return list(wrapper); + } + + @Override + public Boolean isExists(Integer subject, Integer object, Integer relationId) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("subject",subject); + wrapper.eq("object",object); + wrapper.eq("relation_id",relationId); + return list(wrapper).size() > 0; + } +} diff --git b/src/main/java/com/qiwu/inference/service/impl/RelationServiceImpl.java a/src/main/java/com/qiwu/inference/service/impl/RelationServiceImpl.java new file mode 100644 index 0000000..716f1eb --- /dev/null +++ a/src/main/java/com/qiwu/inference/service/impl/RelationServiceImpl.java @@ -0,0 +1,45 @@ +package com.qiwu.inference.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.qiwu.inference.dao.RelationMapper; +import com.qiwu.inference.pojo.KeyClue; +import com.qiwu.inference.pojo.Relation; +import com.qiwu.inference.service.RelationService; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + *

+ * 服务实现类 + *

+ * + * @author xingxing.ye + * @since 2022-11-03 + */ +@Service +public class RelationServiceImpl extends ServiceImpl implements RelationService { + + @Override + public List getRelations(Integer type) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.lambda().eq(Relation::getType,type); + return list(wrapper); + } + + @Override + public Boolean isExists(String[] relationIds) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.in("id",relationIds); + return list(wrapper).size() > 0; + } + + + @Override + public List getRelations(String[] relationIds) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.in("id",relationIds); + return list(wrapper); + } +} diff --git b/src/main/java/com/qiwu/inference/service/impl/RelationTypeServiceImpl.java a/src/main/java/com/qiwu/inference/service/impl/RelationTypeServiceImpl.java new file mode 100644 index 0000000..d9c4465 --- /dev/null +++ a/src/main/java/com/qiwu/inference/service/impl/RelationTypeServiceImpl.java @@ -0,0 +1,31 @@ +package com.qiwu.inference.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.qiwu.inference.dao.RelationTypeMapper; +import com.qiwu.inference.pojo.PersonRecord; +import com.qiwu.inference.pojo.RelationType; +import com.qiwu.inference.service.RelationTypeService; +import org.springframework.stereotype.Service; + +import java.lang.reflect.Type; +import java.util.List; + +/** + *

+ * 服务实现类 + *

+ * + * @author xingxing.ye + * @since 2022-11-03 + */ +@Service +public class RelationTypeServiceImpl extends ServiceImpl implements RelationTypeService { + + @Override + public List list(Integer type) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.lambda().ne(RelationType::getId, type); + return list(wrapper); + } +} diff --git b/src/main/java/com/qiwu/inference/service/impl/TaskConditionServiceImpl.java a/src/main/java/com/qiwu/inference/service/impl/TaskConditionServiceImpl.java new file mode 100644 index 0000000..19a8c72 --- /dev/null +++ a/src/main/java/com/qiwu/inference/service/impl/TaskConditionServiceImpl.java @@ -0,0 +1,20 @@ +package com.qiwu.inference.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.qiwu.inference.dao.TaskConditionMapper; +import com.qiwu.inference.pojo.TaskCondition; +import com.qiwu.inference.service.TaskConditionService; +import org.springframework.stereotype.Service; + +/** + *

+ * 服务实现类 + *

+ * + * @author xingxing.ye + * @since 2022-11-02 + */ +@Service +public class TaskConditionServiceImpl extends ServiceImpl implements TaskConditionService { + +} diff --git b/src/main/java/com/qiwu/inference/util/BeanUtil.java a/src/main/java/com/qiwu/inference/util/BeanUtil.java new file mode 100644 index 0000000..506496a --- /dev/null +++ a/src/main/java/com/qiwu/inference/util/BeanUtil.java @@ -0,0 +1,68 @@ +package com.qiwu.inference.util; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.springframework.beans.BeanUtils; +import org.springframework.beans.BeanWrapper; +import org.springframework.beans.BeanWrapperImpl; +import org.springframework.util.StringUtils; + +public class BeanUtil { + /** + * 拷贝bean中的属性 + * @param source + * @param target + * @param ignores + */ + public static void copyProperties(Object source, Object target, String... ignores){ + BeanUtils.copyProperties(source, target, ignores); + } + /** + * 拷贝bean中的属性 忽略掉空值属性和ID属性 + * @param source + * @param target + */ + public static void copyPropertiesIgnoreNullValueAndId(Object source, Object target){ + copyProperties(source, target, getNullPropertyNamesAndIgnoreNames(source, "id")); + } + /** + * 拷贝bean中的属性 忽略掉空值属性 + * @param source + * @param target + */ + public static void copyPropertiesIgnoreNullValue(Object source, Object target){ + copyProperties(source, target, getNullPropertyNamesAndIgnoreNames(source)); + } + /** + * 获取空值属性名称或者忽略 + * @param source + * @param ignores + * @return + */ + public static String[] getNullPropertyNamesAndIgnoreNames (Object source, String... ignores ) { + final BeanWrapper src = new BeanWrapperImpl(source); + java.beans.PropertyDescriptor[] pds = src.getPropertyDescriptors(); + + Set emptyNames = new HashSet(); + if (ignores != null && ignores.length > 0){ + emptyNames.addAll(Arrays.asList(ignores)); + } + for(java.beans.PropertyDescriptor pd : pds) { + Object srcValue = src.getPropertyValue(pd.getName()); + if (srcValue == null) emptyNames.add(pd.getName()); + } + String[] result = new String[emptyNames.size()]; + return emptyNames.toArray(result); + } + + public static String[] convertStringToArray(String ids){ + if (StringUtils.isEmpty(ids)){ + return null; + } + return ids.split(","); + } +} diff --git b/src/main/java/com/qiwu/inference/util/DateUtil.java a/src/main/java/com/qiwu/inference/util/DateUtil.java new file mode 100644 index 0000000..d27f817 --- /dev/null +++ a/src/main/java/com/qiwu/inference/util/DateUtil.java @@ -0,0 +1,504 @@ +package com.qiwu.inference.util; + +import java.text.DecimalFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; +import org.apache.commons.lang3.time.DateFormatUtils; +import org.apache.commons.lang3.time.DateUtils; + +public class DateUtil { + + /** + * 仅显示年月日,例如 2015-08-11. + */ + public static final String DATE_FORMAT = "yyyy-MM-dd"; + /** + * 显示年月日时分秒,例如 2015-08-11 09:51:53. + */ + public static final String DATETIME_FORMAT = "yyyy-MM-dd HH:mm:ss"; + + /** + * 仅显示时分秒,例如 09:51:53. + */ + public static final String TIME_FORMAT = "HH:mm:ss"; + + /** + * 每天的毫秒数 8640000. + */ + public static final long MILLISECONDS_PER_DAY = 86400000L; + + /** + * 每周的天数. + */ + public static final long DAYS_PER_WEEK = 7L; + + /** + * 每小时毫秒数. + */ + public static final long MILLISECONDS_PER_HOUR = 3600000L; + + /** + * 每分钟秒数. + */ + public static final long SECONDS_PER_MINUTE = 60L; + + /** + * 每小时秒数. + */ + public static final long SECONDS_PER_HOUR = 3600L; + + /** + * 每天秒数. + */ + public static final long SECONDS_PER_DAY = 86400L; + + /** + * 每个月秒数,默认每月30天. + */ + public static final long SECONDS_PER_MONTH = 2592000L; + + /** + * 每年秒数,默认每年365天. + */ + public static final long SECONDS_PER_YEAR = 31536000L; + + /** + * 常用的时间格式. + */ + private static String[] parsePatterns = { "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy/MM/dd", + "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm" }; + + /** + * 得到当前日期字符串. + * @return String 日期字符串,例如2015-08-11 + * @since 1.0 + */ + public static String getDate() { + return getDate(DateUtil.DATE_FORMAT); + } + + /** + * 得到当前时间字符串. + * @return String 时间字符串,例如 09:51:53 + * @since 1.0 + */ + public static String getTime() { + return formatDate(new Date(), DateUtil.TIME_FORMAT); + } + + /** + * 得到当前日期和时间字符串. + * @return String 日期和时间字符串,例如 2015-08-11 09:51:53 + * @since 1.0 + */ + public static String getDateTime() { + return formatDate(new Date(), DateUtil.DATETIME_FORMAT); + } + + /** + * 获取当前时间指定格式下的字符串. + * @param pattern + * 转化后时间展示的格式,例如"yyyy-MM-dd","yyyy-MM-dd HH:mm:ss"等 + * @return String 格式转换之后的时间字符串. + * @since 1.0 + */ + public static String getDate(String pattern) { + return DateFormatUtils.format(new Date(), pattern); + } + + /** + * 获取指定日期的字符串格式. + * @param date 需要格式化的时间,不能为空 + * @param pattern 时间格式,例如"yyyy-MM-dd","yyyy-MM-dd HH:mm:ss"等 + * @return String 格式转换之后的时间字符串. + * @since 1.0 + */ + public static String getDate(Date date, String pattern) { + return DateFormatUtils.format(date, pattern); + } + + /** + * 获取日期时间字符串,默认格式为(yyyy-MM-dd). + * @param date 需要转化的日期时间 + * @param pattern 时间格式,例如"yyyy-MM-dd" "HH:mm:ss" "E"等 + * @return String 格式转换后的时间字符串 + * @since 1.0 + */ + public static String formatDate(Date date, Object... pattern) { + String formatDate = null; + if (pattern != null && pattern.length > 0) { + formatDate = DateFormatUtils.format(date, pattern[0].toString()); + } else { + formatDate = DateFormatUtils.format(date, DateUtil.DATE_FORMAT); + } + return formatDate; + } + + /** + * 获取当前年份字符串. + * @return String 当前年份字符串,例如 2015 + * @since 1.0 + */ + public static String getYear() { + return formatDate(new Date(), "yyyy"); + } + + /** + * 获取当前月份字符串. + * @return String 当前月份字符串,例如 08 + * @since 1.0 + */ + public static String getMonth() { + return formatDate(new Date(), "MM"); + } + + /** + * 获取当前天数字符串. + * @return String 当前天数字符串,例如 11 + * @since 1.0 + */ + public static String getDay() { + return formatDate(new Date(), "dd"); + } + + /** + * 获取当前星期字符串. + * @return String 当前星期字符串,例如星期二 + * @since 1.0 + */ + public static String getWeek() { + return formatDate(new Date(), "E"); + } + + /** + * 将日期型字符串转换为日期格式. + * 支持的日期字符串格式包括"yyyy-MM-dd","yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", + * "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm" + * @param str + * @return Date + * @since 1.0 + */ + public static Date parseDate(Object str) { + if (str == null) { + return null; + } + try { + return DateUtils.parseDate(str.toString(), parsePatterns); + } catch (ParseException e) { + return null; + } + } + + /** + * 获取当前日期与指定日期相隔的天数. + * @param date 给定的日期 + * @return long 日期间隔天数,正数表示给定日期在当前日期之前,负数表示在当前日期之后 + * @since 1.0 + */ + public static long pastDays(Date date) { + // 将指定日期转换为yyyy-MM-dd格式 + date = DateUtil.parseDate(DateUtil.formatDate(date, DateUtil.DATE_FORMAT)); + // 当前日期转换为yyyy-MM-dd格式 + Date currentDate = DateUtil.parseDate(DateUtil.formatDate(new Date(), DateUtil.DATE_FORMAT)); + long t=0; + if(date!=null&¤tDate!=null){ + t = (currentDate.getTime() - date.getTime()) / DateUtil.MILLISECONDS_PER_DAY; + } + return t; + } + + /** + * 获取当前日期指定天数之后的日期. + * @param num 相隔天数 + * @return Date 日期 + * @since 1.0 + */ + public static Date nextDay(int num) { + Calendar curr = Calendar.getInstance(); + curr.set(Calendar.DAY_OF_MONTH, curr.get(Calendar.DAY_OF_MONTH) + num); + return curr.getTime(); + } + + /** + * 获取当前日期指定月数之后的日期. + * @param num 间隔月数 + * @return Date 日期 + * @since 1.0 + */ + public static Date nextMonth(int num) { + Calendar curr = Calendar.getInstance(); + curr.set(Calendar.MONTH, curr.get(Calendar.MONTH) + num); + return curr.getTime(); + } + + /** + * 获取当前日期指定年数之后的日期. + * @param num 间隔年数 + * @return Date 日期 + * @since 1.0 + */ + public static Date nextYear(int num) { + Calendar curr = Calendar.getInstance(); + curr.set(Calendar.YEAR, curr.get(Calendar.YEAR) + num); + return curr.getTime(); + } + + /** + * 将 Date 日期转化为 Calendar 类型日期. + * @param date 给定的时间,若为null,则默认为当前时间 + * @return Calendar Calendar对象 + * @since 1.0 + */ + public static Calendar getCalendar(Date date) { + Calendar calendar = Calendar.getInstance(); + // calendar.setFirstDayOfWeek(Calendar.SUNDAY);//每周从周日开始 + // calendar.setMinimalDaysInFirstWeek(1); // 设置每周最少为1天 + if (date != null) { + calendar.setTime(date); + } + return calendar; + } + + /** + * 计算两个日期之间相差天数. + * @param start 计算开始日期 + * @param end 计算结束日期 + * @return long 相隔天数 + * @since 1.0 + */ + public static long getDaysBetween(Date start, Date end) { + // 将指定日期转换为yyyy-MM-dd格式 + start = DateUtil.parseDate(DateUtil.formatDate(start, DateUtil.DATE_FORMAT)); + // 当前日期转换为yyyy-MM-dd格式 + end = DateUtil.parseDate(DateUtil.formatDate(end, DateUtil.DATE_FORMAT)); + + long diff=0; + if(start!=null&&end!=null) { + diff = (end.getTime() - start.getTime()) / DateUtil.MILLISECONDS_PER_DAY; + } + return diff; + } + + /** + * 计算两个日期之前相隔多少周. + * @param start 计算开始时间 + * @param end 计算结束时间 + * @return long 相隔周数,向下取整 + * @since 1.0 + */ + public static long getWeeksBetween(Date start, Date end) { + return getDaysBetween(start, end) / DateUtil.DAYS_PER_WEEK; + } + + /** + * 获取与指定日期间隔给定天数的日期. + * @param specifiedDay 给定的字符串格式日期,支持的日期字符串格式包括"yyyy-MM-dd","yyyy-MM-dd HH:mm:ss", + * "yyyy-MM-dd HH:mm", "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", + * "yyyy/MM/dd HH:mm" + * @param num 间隔天数 + * @return String 间隔指定天数之后的日期 + * @since 1.0 + */ + public static String getSpecifiedDayAfter(String specifiedDay, int num) { + Date specifiedDate = parseDate(specifiedDay); + Calendar c = Calendar.getInstance(); + c.setTime(specifiedDate); + int day = c.get(Calendar.DATE); + c.set(Calendar.DATE, day + num); + String dayAfter = formatDate(c.getTime(), DateUtil.DATE_FORMAT); + return dayAfter; + } + + /** + * 计算两个日期之前间隔的小时数. + * + * @param date1 + * 结束时间 + * @param date2 + * 开始时间 + * @return String 相差的小时数,保留一位小数 + * @since 1.0 + */ + public static String dateMinus(Date date1, Date date2) { + if (date1 == null || date2 == null) { + return "0"; + } + Long r = date1.getTime() - date2.getTime(); + DecimalFormat df = new DecimalFormat("#.0"); + double result = r * 1.0 / DateUtil.MILLISECONDS_PER_HOUR; + return df.format(result); + } + + /** + * 获取当前季度 . + * + * @return Integer 当前季度数 + * @since 1.0 + */ + public static Integer getCurrentSeason() { + Calendar calendar = Calendar.getInstance(); + Integer month = calendar.get(Calendar.MONTH) + 1; + int season = 0; + if (month >= 1 && month <= 3) { + season = 1; + } else if (month >= 4 && month <= 6) { + season = 2; + } else if (month >= 7 && month <= 9) { + season = 3; + } else if (month >= 10 && month <= 12) { + season = 4; + } + return season; + } + + /** + * 将以秒为单位的时间转换为其他单位. + * + * @param seconds + * 秒数 + * @return String 例如 16分钟前、2小时前、3天前、4月前、5年前等 + * @since 1.0 + */ + public static String getIntervalBySeconds(long seconds) { + StringBuffer buffer = new StringBuffer(); + if (seconds < SECONDS_PER_MINUTE) { + buffer.append(seconds).append("秒前"); + } else if (seconds < SECONDS_PER_HOUR) { + buffer.append(seconds / SECONDS_PER_MINUTE).append("分钟前"); + } else if (seconds < SECONDS_PER_DAY) { + buffer.append(seconds / SECONDS_PER_HOUR).append("小时前"); + } else if (seconds < SECONDS_PER_MONTH) { + buffer.append(seconds / SECONDS_PER_DAY).append("天前"); + } else if (seconds < SECONDS_PER_YEAR) { + buffer.append(seconds / SECONDS_PER_MONTH).append("月前"); + } else { + buffer.append(seconds / DateUtil.SECONDS_PER_YEAR).append("年前"); + } + return buffer.toString(); + } + + /** + * + * getNowTimeBefore(记录时间相当于目前多久之前) + * + * @param seconds + * 秒 + * @return + * @exception @since + * 1.0 + * @author rlliu + */ + public static String getNowTimeBefore(long seconds) { + StringBuffer buffer = new StringBuffer(); + buffer.append("上传于"); + if (seconds < 3600) { + buffer.append((long) Math.floor(seconds / 60.0)).append("分钟前"); + } else if (seconds < 86400) { + buffer.append((long) Math.floor(seconds / 3600.0)).append("小时前"); + } else if (seconds < 604800) { + buffer.append((long) Math.floor(seconds / 86400.0)).append("天前"); + } else if (seconds < 2592000) { + buffer.append((long) Math.floor(seconds / 604800.0)).append("周前"); + } else if (seconds < 31104000) { + buffer.append((long) Math.floor(seconds / 2592000.0)).append("月前"); + } else { + buffer.append((long) Math.floor(seconds / 31104000.0)).append("年前"); + } + return buffer.toString(); + } + + /** + * + * getMonthsBetween(查询两个日期相隔的月份) + * + * @param startDate 开始日期1 (格式yyyy-MM-dd) + * @param endDate 截止日期2 (格式yyyy-MM-dd) + * @return + */ + public static int getMonthsBetween(String startDate, String endDate) { + Calendar c1 = Calendar.getInstance(); + Calendar c2 = Calendar.getInstance(); + c1.setTime(DateUtil.parseDate(startDate)); + c2.setTime(DateUtil.parseDate(endDate)); + int year = c2.get(Calendar.YEAR) - c1.get(Calendar.YEAR); + int month = c2.get(Calendar.MONTH) - c1.get(Calendar.MONTH); + return Math.abs(year * 12 + month); + } + + /** + * + * getDayOfWeek(获取当前日期是星期几) + * + * @param dateStr 日期 + * @return 星期几 + */ + public static String getDayOfWeek(String dateStr) { + String[] weekOfDays = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" }; + Date date = parseDate(dateStr); + Calendar calendar = Calendar.getInstance(); + calendar.setTime(date); + int num = calendar.get(Calendar.DAY_OF_WEEK) - 1; + return weekOfDays[num]; + } + + /** + * sns 格式 如几秒前,几分钟前,几小时前,几天前,几个月前,几年后, ... 精细,类如某个明星几秒钟之前发表了一篇微博 + * + * @param createTime + * @return + */ + public static String snsFormat(long createTime) { + long now = System.currentTimeMillis() / 1000; + long differ = now - createTime / 1000; + String dateStr = ""; + if (differ <= 60) { + dateStr = "刚刚"; + } else if (differ <= 3600) { + dateStr = (differ / 60) + "分钟前"; + } else if (differ <= 3600 * 24) { + dateStr = (differ / 3600) + "小时前"; + } else if (differ <= 3600 * 24 * 30) { + dateStr = (differ / (3600 * 24)) + "天前"; + } else { + Date date = new Date(createTime); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + dateStr = sdf.format(date); + } + return dateStr; + } + + /** + * 得到UTC时间,类型为字符串,格式为"yyyy-MM-dd HH:mm" + * 如果获取失败,返回null + * @return + */ + public static String getUTCTimeStr() { + StringBuffer UTCTimeBuffer = new StringBuffer(); + // 1、取得本地时间: + Calendar cal = Calendar.getInstance() ; + // 2、取得时间偏移量: + int zoneOffset = cal.get(java.util.Calendar.ZONE_OFFSET); + // 3、取得夏令时差: + int dstOffset = cal.get(java.util.Calendar.DST_OFFSET); + // 4、从本地时间里扣除这些差量,即可以取得UTC时间: + cal.add(java.util.Calendar.MILLISECOND, -(zoneOffset + dstOffset)); + int year = cal.get(Calendar.YEAR); + int month = cal.get(Calendar.MONTH)+1; + int day = cal.get(Calendar.DAY_OF_MONTH); + int hour = cal.get(Calendar.HOUR_OF_DAY); + int minute = cal.get(Calendar.MINUTE); + UTCTimeBuffer.append(year).append("-").append(month).append("-").append(day) ; + UTCTimeBuffer.append(" ").append(hour).append(":").append(minute) ; + try{ + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); + sdf.parse(UTCTimeBuffer.toString()) ; + return UTCTimeBuffer.toString() ; + }catch(ParseException e) + { + e.printStackTrace() ; + } + return null ; + } +} diff --git b/src/main/java/com/qiwu/inference/util/DoubleUtil.java a/src/main/java/com/qiwu/inference/util/DoubleUtil.java new file mode 100644 index 0000000..f015953 --- /dev/null +++ a/src/main/java/com/qiwu/inference/util/DoubleUtil.java @@ -0,0 +1,105 @@ +package com.qiwu.inference.util; + +import java.math.BigDecimal; + +/** + * 提供精确的浮点数运算工具类 + * @author xingxing.ye.ye + * + */ +public class DoubleUtil { + + // 除法运算默认精度,下面自定义方法可修改 + private static final int DEF_DIV_SCALE = 10; + + private DoubleUtil() { + + } + + /** + * 精确加法 + */ + public static double add(double firValue, double sedValue) { + BigDecimal firBD = BigDecimal.valueOf(firValue); + BigDecimal sedBD = BigDecimal.valueOf(sedValue); + return firBD.add(sedBD).doubleValue(); + } + + /** + * 精确减法 + */ + public static double sub(double firValue, double sedValue) { + BigDecimal firBD = BigDecimal.valueOf(firValue); + BigDecimal sedBD = BigDecimal.valueOf(sedValue); + return firBD.subtract(sedBD).doubleValue(); + } + + /** + * 精确乘法 + */ + public static double mul(double firValue, double sedValue) { + BigDecimal firBD = BigDecimal.valueOf(firValue); + BigDecimal sedBD = BigDecimal.valueOf(sedValue); + return firBD.multiply(sedBD).doubleValue(); + } + + /** + * 精确除法 使用默认精度 + */ + public static double div(double firValue, double sedValue) { + double num = 0; + try { + num = div(firValue, sedValue, DEF_DIV_SCALE); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + return num; + } + + /** + * 精确除法 + * + * @param scale 精度 + * @throws IllegalAccessException + */ + public static double div(double firValue, double sedValue, int scale) throws IllegalAccessException { + if (scale < 0) { + throw new IllegalAccessException("精确度不能小于0"); + } + BigDecimal b1 = BigDecimal.valueOf(firValue); + BigDecimal b2 = BigDecimal.valueOf(sedValue); + return b1.divide(b2, scale, BigDecimal.ROUND_HALF_UP).doubleValue(); + } + + /** + * 四舍五入 + * + * @param scale 小数点后保留几位 + */ + public static double round(double value, int scale) { + double num = 0; + try { + num = div(value, 1, scale); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + return num; + } + + /** + * 比较两数是否相等 + */ + public static boolean equalTo(BigDecimal firBD, BigDecimal sedBD) { + if (firBD == null || sedBD == null) { + return false; + } + return 0 == firBD.compareTo(sedBD); + } + + /** + * 百分号的数转化为小数 + */ + public static double convert(String str) { + return Double.parseDouble(str.replace("%",""))*0.01; + } +} \ No newline at end of file diff --git b/src/main/java/com/qiwu/inference/util/FastJsonUtil.java a/src/main/java/com/qiwu/inference/util/FastJsonUtil.java new file mode 100644 index 0000000..fd02d33 --- /dev/null +++ a/src/main/java/com/qiwu/inference/util/FastJsonUtil.java @@ -0,0 +1,231 @@ +package com.qiwu.inference.util; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.serializer.SerializerFeature; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.OutputStreamWriter; +import java.io.Writer; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author: xingxing.ye + * @describe: fastjson 工具 + */ +public final class FastJsonUtil { + private FastJsonUtil() { + + } + + /** + * 将对象转换为json + * null ->list =[] + * 输出null 值 + * @param value 对象 + * @return + */ + public static String obj2json(Object value) { + try { + return JSON.toJSONString(value,SerializerFeature.WriteMapNullValue,SerializerFeature.WriteNullListAsEmpty); + } catch (Exception e) { + try { + return obj2json3(value); + } catch (Exception e1) { + e.printStackTrace(); + return null; + } + } + } + + public static String obj2jsonPretty(Object value) { + try { + return JSON.toJSONString(value, SerializerFeature.PrettyFormat); + } catch (Exception e) { + try { + return obj2json2(value); + } catch (Exception e1) { + e.printStackTrace(); + return null; + } + } + } + + public static String obj2jsonDateFormat(Object value) { + try { + return JSON.toJSONStringWithDateFormat(value, "yyyy-MM-dd HH:mm:ss", + SerializerFeature.WriteDateUseDateFormat,SerializerFeature.DisableCircularReferenceDetect); + } catch (Exception e) { + try { + return obj2json2(value); + } catch (Exception e1) { + e.printStackTrace(); + return null; + } + } + } + + public static String obj2jsonDateFormat(Object value, String format) { + try { +// return JSON.toJSONString(value, SerializerFeature.PrettyFormat); + return JSON.toJSONStringWithDateFormat(value, format, + SerializerFeature.WriteDateUseDateFormat); + } catch (Exception e) { + try { + return obj2json2(value); + } catch (Exception e1) { + e.printStackTrace(); + return null; + } + } + } + + @SuppressWarnings("deprecation") + public static String obj2json2(Object value) { + try { + return JSON.toJSONString(value, SerializerFeature.WriteTabAsSpecial, SerializerFeature.WriteSlashAsSpecial); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + @SuppressWarnings("deprecation") + public static String obj2json3(Object value) { + try { + return JSON.toJSONString(value, SerializerFeature.WriteTabAsSpecial, SerializerFeature.WriteSlashAsSpecial, + SerializerFeature.BrowserCompatible); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + /** + * 将json转换为对象 + * + * @param 转换的类型 + * @param json json数据 + * @param clazz 被转化对象的class + * @return + */ + public static T json2obj(String json, Class clazz) { + try { + return JSON.parseObject(json, clazz); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + /** + * 将json转换为对象数组 + * + * @param 转换的类型 + * @param json json数据 + * @param clazz 被转化对象的class + * @return + */ + public static List json2List(String json, Class clazz) { + try { + return JSON.parseArray(json, clazz); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + /** + * jsonStr to Map + * + * @param jsonStr jsonStr + * @return + */ + public static Map parseJSON2Map(String jsonStr) { + + // 参数di + Map map = new HashMap(); + JSONObject json = null; + + // 最外层解析 + try { + json = JSONObject.parseObject(jsonStr); + for (String k : json.keySet()) { + Object v = json.get(k); + if (null != v) { + map.put(k.toString(), v.toString()); + } + } + } catch (Exception e) { + e.printStackTrace(); + return null; + } + return map; + } + + /** + * jsonStr to Map + * + * @param jsonStr jsonStr + * @return + */ + public static Map parseJSON2Map2(String jsonStr) { + + // 参数di + Map map = new HashMap(); + JSONObject json = null; + + // 最外层解析 + try { + json = JSONObject.parseObject(jsonStr); + for (String k : json.keySet()) { + Object v = json.get(k); + if (null != v) { + map.put(k.toString(), v.toString()); + } + } + } catch (Exception e) { + e.printStackTrace(); + return null; + } + return map; + } + + /** + * 保存json数据到指定的文件路径 + * @param jsonData json数据 + * @param filePath 文件路径 + * @return + */ + public static boolean createJsonFile(Object jsonData, String filePath) { + String content = JSON.toJSONString(jsonData, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue, + SerializerFeature.WriteDateUseDateFormat); + try { + File file = new File(filePath); + // 创建上级目录 + if (!file.getParentFile().exists()) { + file.getParentFile().mkdirs(); + } + // 如果文件存在,则删除文件 + if (file.exists()) { + file.delete(); + } + // 创建文件 + file.createNewFile(); + // 写入文件 + Writer write = new OutputStreamWriter(Files.newOutputStream(file.toPath()), StandardCharsets.UTF_8); + write.write(content); + write.flush(); + write.close(); + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } +} \ No newline at end of file diff --git b/src/main/java/com/qiwu/inference/util/FileUtil.java a/src/main/java/com/qiwu/inference/util/FileUtil.java new file mode 100644 index 0000000..5c9a010 --- /dev/null +++ a/src/main/java/com/qiwu/inference/util/FileUtil.java @@ -0,0 +1,84 @@ +package com.qiwu.inference.util; + +import org.apache.commons.io.FileUtils; + +import java.io.File; +import java.io.InputStream; +import java.util.List; + +public class FileUtil { + + + public static InputStream getResourcesFileInputStream(String fileName) { + return Thread.currentThread().getContextClassLoader().getResourceAsStream("" + fileName); + } + + public static String getPath() { + return FileUtil.class.getResource("/").getPath(); + } + + public static File createNewFile(String pathName) { + File file = new File(getPath() + pathName); + if (file.exists()) { + file.delete(); + } else { + if (!file.getParentFile().exists()) { + file.getParentFile().mkdirs(); + } + } + return file; + } + + public static void writeLog(List list, String filePath)throws Exception{ + FileUtils.writeLines(new File(filePath), "utf-8", list,false); + } + + public static File readFile(String pathName) { + return new File(getPath() + pathName); + } + + public static File readUserHomeFile(String pathName) { + return new File(System.getProperty("user.home") + File.separator + pathName); + } + + /** + * 用以模糊删除头部为str的文件 + * @param path 要删除的文件的文件夹的路径 + * @param str 匹配的字符串的头 + * @return boolean + */ + public static boolean delFilesByPath(String path,String str){ + boolean flag=false; + File file = new File(path); + File[] tempFile = file.listFiles(); + for (File value : tempFile) { + if (value.getName().startsWith(str) || value.getName().endsWith(str)) { + System.out.println("将被删除的文件名:" + value.getName()); + boolean del = deleteFile(path + value.getName()); + if (del) { + System.out.println("文件" + value.getName() + "删除成功!"); + flag = true; + } else { + System.out.println("文件" + value.getName() + "删除失败!"); + } + } + } + return flag; + } + + /** + * 用以删除文件 + * @param path 要删除的文件的路径 + * @return boolean + */ + private static boolean deleteFile(String path){ + System.out.println(path); + boolean del=false; + File file=new File(path); + if(file.isFile()){ + file.delete(); + del=true; + } + return del; + } +} diff --git b/src/main/java/com/qiwu/inference/util/NumberUtil.java a/src/main/java/com/qiwu/inference/util/NumberUtil.java new file mode 100644 index 0000000..08708f1 --- /dev/null +++ a/src/main/java/com/qiwu/inference/util/NumberUtil.java @@ -0,0 +1,66 @@ +package com.qiwu.inference.util; + +import java.util.Arrays; +import java.util.List; +import java.util.Objects; +import java.util.regex.Pattern; +import java.util.stream.Collectors; + +public class NumberUtil { + /** + * 开闭区间正则表达式 + */ + private static final Pattern NUM_RANGE_PATTERN = Pattern.compile("[\\[|\\(]\\s?\\d+\\s?,\\s?\\d+\\s?[\\)|\\]]"); + /** + * 左半区间正则表达式 + */ + private static final Pattern LEFT_NUM_RANGE_PATTERN = Pattern.compile("[\\[|\\(]\\s?\\d+\\s?,\\s?[\\)|\\]]"); + /** + * 右半区间正则表达式 + */ + private static final Pattern RIGHT_NUM_RANGE_PATTERN = Pattern.compile("[\\[|\\(],\\s?\\d+\\s?[\\)|\\]]"); + /** + * 判断是否为有效的数字区间范围 + * @param numRange 数字区间 + * @return boolean + */ + public static boolean isValidNumRange(String numRange) { + return NUM_RANGE_PATTERN.matcher(numRange).matches() + || LEFT_NUM_RANGE_PATTERN.matcher(numRange).matches() + || RIGHT_NUM_RANGE_PATTERN.matcher(numRange).matches(); + } + + /** + * 判断数值是否在区间范围内 + * @param number 数值 + * @param numRange 开闭区间 + * @return boolean + */ + public static boolean inNumRange(int number, String numRange) { + Objects.requireNonNull(numRange); + + if (!isValidNumRange(numRange)) { + return false; + } + + String[] pairs = numRange.split(","); + + // 获取开闭区间的最小值和最大值 + List rangeNums = Arrays.stream(pairs).map(str -> str.replaceAll("[(|)|\\[|\\]]", "").trim()).collect(Collectors.toList()); + Integer minValue = "".equals(rangeNums.get(0)) ? null : Integer.valueOf(rangeNums.get(0)); + Integer maxValue = "".equals(rangeNums.get(1)) ? null : Integer.valueOf(rangeNums.get(1)); + + // 判定数值是否大于最小值 + boolean minMatched = (minValue == null) || (pairs[0].startsWith("[") ? number >= minValue : number > minValue); + // 判定数值是否小于最大值 + boolean maxMatched = (maxValue == null) || (pairs[1].endsWith("]") ? number <= maxValue : number < maxValue); + + return minMatched && maxMatched; + } + + public static void main(String[] args) { + System.out.println(inNumRange(1, "[15, 29]")); + } + + +} diff --git b/src/main/java/com/qiwu/inference/util/RandomUtil.java a/src/main/java/com/qiwu/inference/util/RandomUtil.java new file mode 100644 index 0000000..63946fc --- /dev/null +++ a/src/main/java/com/qiwu/inference/util/RandomUtil.java @@ -0,0 +1,510 @@ +package com.qiwu.inference.util; + +import java.awt.Color; +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; +import java.util.*; +import java.util.concurrent.ThreadLocalRandom; + +import cn.hutool.core.date.DateTime; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.exceptions.UtilException; +import cn.hutool.core.lang.UUID; +import cn.hutool.core.lang.WeightRandom; +import cn.hutool.core.lang.WeightRandom.WeightObj; +import cn.hutool.core.util.NumberUtil; + +/** + * 随机工具类 + * + */ +public class RandomUtil { + + /** 用于随机选的数字 */ + public static final String BASE_NUMBER = "0123456789"; + /** 用于随机选的字符 */ + public static final String BASE_CHAR = "abcdefghijklmnopqrstuvwxyz"; + /** 用于随机选的字符和数字 */ + public static final String BASE_CHAR_NUMBER = BASE_CHAR + BASE_NUMBER; + + /** + * 获取随机数生成器对象
+ * ThreadLocalRandom是JDK 7之后提供并发产生随机数,能够解决多个线程发生的竞争争夺。 + * + * @return {@link ThreadLocalRandom} + * @since 3.1.2 + */ + public static ThreadLocalRandom getRandom() { + return ThreadLocalRandom.current(); + } + + /** + * 获取{@link SecureRandom},类提供加密的强随机数生成器 (RNG) + * + * @return {@link SecureRandom} + * @since 3.1.2 + */ + public static SecureRandom getSecureRandom() { + try { + return SecureRandom.getInstance("SHA1PRNG"); + } catch (NoSuchAlgorithmException e) { + throw new UtilException(e); + } + } + + /** + * 获取随机数产生器 + * + * @param isSecure 是否为强随机数生成器 (RNG) + * @return {@link Random} + * @since 4.1.15 + * @see #getSecureRandom() + * @see #getRandom() + */ + public static Random getRandom(boolean isSecure) { + return isSecure ? getSecureRandom() : getRandom(); + } + + /** + * 获得指定范围内的随机数 + * + * @param min 最小数(包含) + * @param max 最大数(不包含) + * @return 随机数 + */ + public static int randomInt(int min, int max) { + return getRandom().nextInt(min, max); + } + + /** + * 获得随机数[0, 2^32) + * + * @return 随机数 + */ + public static int randomInt() { + return getRandom().nextInt(); + } + + /** + * 获得指定范围内的随机数 [0,limit) + * + * @param limit 限制随机数的范围,不包括这个数 + * @return 随机数 + */ + public static int randomInt(int limit) { + return getRandom().nextInt(limit); + } + + /** + * 获得指定范围内的随机数[min, max) + * + * @param min 最小数(包含) + * @param max 最大数(不包含) + * @return 随机数 + * @since 3.3.0 + */ + public static long randomLong(long min, long max) { + return getRandom().nextLong(min, max); + } + + /** + * 获得随机数 + * + * @return 随机数 + * @since 3.3.0 + */ + public static long randomLong() { + return getRandom().nextLong(); + } + + /** + * 获得指定范围内的随机数 [0,limit) + * + * @param limit 限制随机数的范围,不包括这个数 + * @return 随机数 + */ + public static long randomLong(long limit) { + return getRandom().nextLong(limit); + } + + /** + * 获得指定范围内的随机数 + * + * @param min 最小数(包含) + * @param max 最大数(不包含) + * @return 随机数 + * @since 3.3.0 + */ + public static double randomDouble(double min, double max) { + return getRandom().nextDouble(min, max); + } + + /** + * 获得指定范围内的随机数 + * + * @param min 最小数(包含) + * @param max 最大数(不包含) + * @param scale 保留小数位数 + * @param roundingMode 保留小数的模式 {@link RoundingMode} + * @return 随机数 + * @since 4.0.8 + */ + public static double randomDouble(double min, double max, int scale, RoundingMode roundingMode) { + return NumberUtil.round(randomDouble(min, max), scale, roundingMode).doubleValue(); + } + + /** + * 获得随机数[0, 1) + * + * @return 随机数 + * @since 3.3.0 + */ + public static double randomDouble() { + return getRandom().nextDouble(); + } + + /** + * 获得指定范围内的随机数 + * + * @param scale 保留小数位数 + * @param roundingMode 保留小数的模式 {@link RoundingMode} + * @return 随机数 + * @since 4.0.8 + */ + public static double randomDouble(int scale, RoundingMode roundingMode) { + return NumberUtil.round(randomDouble(), scale, roundingMode).doubleValue(); + } + + /** + * 获得指定范围内的随机数 [0,limit) + * + * @param limit 限制随机数的范围,不包括这个数 + * @return 随机数 + * @since 3.3.0 + */ + public static double randomDouble(double limit) { + return getRandom().nextDouble(limit); + } + + /** + * 获得指定范围内的随机数 + * + * @param limit 限制随机数的范围,不包括这个数 + * @param scale 保留小数位数 + * @param roundingMode 保留小数的模式 {@link RoundingMode} + * @return 随机数 + * @since 4.0.8 + */ + public static double randomDouble(double limit, int scale, RoundingMode roundingMode) { + return NumberUtil.round(randomDouble(limit), scale, roundingMode).doubleValue(); + } + + /** + * 获得指定范围内的随机数[0, 1) + * + * @return 随机数 + * @since 4.0.9 + */ + public static BigDecimal randomBigDecimal() { + return NumberUtil.toBigDecimal(getRandom().nextDouble()); + } + + /** + * 获得指定范围内的随机数 [0,limit) + * + * @param limit 最大数(不包含) + * @return 随机数 + * @since 4.0.9 + */ + public static BigDecimal randomBigDecimal(BigDecimal limit) { + return NumberUtil.toBigDecimal(getRandom().nextDouble(limit.doubleValue())); + } + + /** + * 获得指定范围内的随机数 + * + * @param min 最小数(包含) + * @param max 最大数(不包含) + * @return 随机数 + * @since 4.0.9 + */ + public static BigDecimal randomBigDecimal(BigDecimal min, BigDecimal max) { + return NumberUtil.toBigDecimal(getRandom().nextDouble(min.doubleValue(), max.doubleValue())); + } + + /** + * 随机bytes + * + * @param length 长度 + * @return bytes + */ + public static byte[] randomBytes(int length) { + byte[] bytes = new byte[length]; + getRandom().nextBytes(bytes); + return bytes; + } + + /** + * 随机获得列表中的元素 + * + * @param 元素类型 + * @param list 列表 + * @return 随机元素 + */ + public static T randomEle(List list) { + return randomEle(list, list.size()); + } + + /** + * 随机获得列表中的元素 + * + * @param 元素类型 + * @param list 列表 + * @param limit 限制列表的前N项 + * @return 随机元素 + */ + public static T randomEle(List list, int limit) { + return list.get(randomInt(limit)); + } + + /** + * 随机获得数组中的元素 + * + * @param 元素类型 + * @param array 列表 + * @return 随机元素 + * @since 3.3.0 + */ + public static T randomEle(T[] array) { + return randomEle(array, array.length); + } + + /** + * 随机获得数组中的元素 + * + * @param 元素类型 + * @param array 列表 + * @param limit 限制列表的前N项 + * @return 随机元素 + * @since 3.3.0 + */ + public static T randomEle(T[] array, int limit) { + return array[randomInt(limit)]; + } + + /** + * 随机获得列表中的一定量元素 + * + * @param 元素类型 + * @param list 列表 + * @param count 随机取出的个数 + * @return 随机元素 + */ + public static List randomEles(List list, int count) { + final List result = new ArrayList(count); + int limit = list.size(); + while (result.size() < count) { + result.add(randomEle(list, limit)); + } + + return result; + } + + /** + * 随机获得列表中的一定量的不重复元素,返回Set + * + * @param 元素类型 + * @param collection 列表 + * @param count 随机取出的个数 + * @return 随机元素 + * @throws IllegalArgumentException 需要的长度大于给定集合非重复总数 + */ + public static Set randomEleSet(Collection collection, int count) { + ArrayList source = new ArrayList<>(new HashSet<>(collection)); + if (count > source.size()) { + throw new IllegalArgumentException("Count is larger than collection distinct size !"); + } + + final HashSet result = new HashSet(count); + int limit = collection.size(); + while (result.size() < count) { + result.add(randomEle(source, limit)); + } + + return result; + } + + /** + * 获得一个随机的字符串(只包含数字和字符) + * + * @param length 字符串的长度 + * @return 随机字符串 + */ + public static String randomString(int length) { + return randomString(BASE_CHAR_NUMBER, length); + } + + /** + * 获得一个随机的字符串(只包含数字和大写字符) + * + * @param length 字符串的长度 + * @return 随机字符串 + * @since 4.0.13 + */ + public static String randomStringUpper(int length) { + return randomString(BASE_CHAR_NUMBER, length).toUpperCase(); + } + + /** + * 获得一个只包含数字的字符串 + * + * @param length 字符串的长度 + * @return 随机字符串 + */ + public static String randomNumbers(int length) { + return randomString(BASE_NUMBER, length); + } + + /** + * 获得一个随机的字符串 + * + * @param baseString 随机字符选取的样本 + * @param length 字符串的长度 + * @return 随机字符串 + */ + public static String randomString(String baseString, int length) { + final StringBuilder sb = new StringBuilder(); + + if (length < 1) { + length = 1; + } + int baseLength = baseString.length(); + for (int i = 0; i < length; i++) { + int number = getRandom().nextInt(baseLength); + sb.append(baseString.charAt(number)); + } + return sb.toString(); + } + + /** + * 随机数字,数字为0~9单个数字 + * + * @return 随机数字字符 + * @since 3.1.2 + */ + public static int randomNumber() { + return randomChar(BASE_NUMBER); + } + + /** + * 随机字母或数字,小写 + * + * @return 随机字符 + * @since 3.1.2 + */ + public static char randomChar() { + return randomChar(BASE_CHAR_NUMBER); + } + + /** + * 随机字符 + * + * @param baseString 随机字符选取的样本 + * @return 随机字符 + * @since 3.1.2 + */ + public static char randomChar(String baseString) { + return baseString.charAt(getRandom().nextInt(baseString.length())); + } + + /** + * 生成随机颜色 + * + * @return 随机颜色 + * @since 4.1.5 + */ + public static Color randomColor() { + final Random random = getRandom(); + return new Color(random.nextInt(255), random.nextInt(255), random.nextInt(255)); + } + + /** + * 带有权重的随机生成器 + * + * @param weightObjs 带有权重的对象列表 + * @return {@link WeightRandom} + * @since 4.0.3 + */ + public static WeightRandom weightRandom(WeightObj[] weightObjs) { + return new WeightRandom<>(weightObjs); + } + + /** + * 带有权重的随机生成器 + * + * @param weightObjs 带有权重的对象列表 + * @return {@link WeightRandom} + * @since 4.0.3 + */ + public static WeightRandom weightRandom(Iterable> weightObjs) { + return new WeightRandom<>(weightObjs); + } + + // ------------------------------------------------------------------- UUID + /** + * @return 随机UUID + * @deprecated 请使用{@link IdUtil#randomUUID()} + */ + @Deprecated + public static String randomUUID() { + return UUID.randomUUID().toString(); + } + + /** + * 简化的UUID,去掉了横线 + * + * @return 简化的UUID,去掉了横线 + * @since 3.2.2 + * @deprecated 请使用{@link IdUtil#simpleUUID()} + */ + @Deprecated + public static String simpleUUID() { + return UUID.randomUUID().toString(true); + } + + /** + * 以当天为基准,随机产生一个日期 + * + * @param min 偏移最小天,可以为负数表示过去的时间 + * @param max 偏移最大天,可以为负数表示过去的时间 + * @return 随机日期(随机天,其它时间不变) + * @since 4.0.8 + */ + public static DateTime randomDay(int min, int max) { + return DateUtil.offsetDay(DateUtil.date(), randomInt(min, max)); + } + + public static void main(String[] args) { + double num = randomDouble(2,RoundingMode.UP); + Map map = new HashMap<>(); + map.put("0","0.0"); + map.put("1","0.35"); //0.35 + map.put("2","0.27"); //0.62 + map.put("3","0.37"); //0.99 + double start =0.0; + double end =0.0; + int level =0 ; + for(int i=0;i<4;i++){ + end +=Double.parseDouble(map.get(String.valueOf(i))); + if(num >= start && num <=end){ + level = i; + } + start = end; + } + System.out.println(num); + System.out.println(level); + } +} + diff --git b/src/main/java/com/qiwu/inference/util/RedissonUtil.java a/src/main/java/com/qiwu/inference/util/RedissonUtil.java new file mode 100644 index 0000000..a0722ec --- /dev/null +++ a/src/main/java/com/qiwu/inference/util/RedissonUtil.java @@ -0,0 +1,126 @@ +package com.qiwu.inference.util; + +import org.redisson.Redisson; +import org.redisson.api.RedissonClient; +import org.redisson.config.Config; + +import java.util.Collection; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.TimeUnit; + + +/** + * 基于Redisson实现Redis数据的操作 + */ +public class RedissonUtil { + + private static RedissonClient client; + + static { + Config config = new Config(); + config.setThreads(1000); + config.useSingleServer().setAddress("redis://127.0.0.1:6379"); // 单机 + + client = Redisson.create(config); + } + + // 新增 + public static void setStr(String key,String val){ + client.getBucket(key).set(val); + } + + public static void setStr(String key,String val,long seconds){ + client.getBucket(key).set(val,seconds, TimeUnit.SECONDS); + } + + public static void setSet(String key,String val){ + client.getSet(key).add(val); + } + + public static void setSet(String key, Set vals){ + client.getSet(key).addAll(vals); + } + + public static void setSet(String key,double score,String val){ + client.getScoredSortedSet(key).add(score,val); + } + + public static void setSet(String key, Map vals){ + client.getScoredSortedSet(key).addAll(vals); + } + + public static void setHash(String key,String val,Object file){ + client.getMap(key).put(val,file); + } + + public static void serHashAll(String key,Map map){ + client.getMap(key).putAll(map); + } + + // 查询 + public static String getStr(String key){ + return client.getBucket(key).get().toString(); + } + public static Set getSet(String key){ + return client.getSet(key).readAll(); + } + public static Collection getzSet(String key){ + return client.getScoredSortedSet(key).readAll(); + } + public static boolean checkSet(String key,Object val){ + return client.getSet(key).contains(val); + } + public static boolean checkzSet(String key,Object val){ + return client.getScoredSortedSet(key).contains(val); + } + public static boolean checkKey(String key){ + return client.getKeys().countExists(key) > 0; + } + public static boolean checkField(String key,String file){ + return client.getMap(key).containsKey(file); + } + public static Object getHash(String key,String file){ + return client.getMap(key).get(file); + } + + // 设置有效期 + public static void setTime(String key,long time,TimeUnit timeUnit){ + client.getKeys().expire(key, time, timeUnit); + } + + // 移除元素 + public static boolean delZet(String key,Object val){ + return client.getScoredSortedSet(key).remove(val); + } + // 删除key + public static void delKey(String... key){ + client.getKeys().delete(key); + } + + public static void delHash(String key,Object val){ + client.getMap(key).remove(val); + } + + // 分布式锁 Redis = (Setnx + Java中的LOCK) + // 加锁 + public static void lock(String key){ + client.getLock(key).lock(); + } + // 加锁设置有效期 超出有效期自动释放 + public static void lock(String key,long seconds){ + client.getLock(key).lock(seconds,TimeUnit.SECONDS); + } + // 释放锁 + public static void unlock(String key){ + client.getLock(key).unlock(); + } + + public static Iterable getKeys(String key){ + return client.getKeys().getKeysByPattern(key); + } + + public static void main(String[] args) { + System.out.println(RedissonUtil.getSet("2ba767cf-62e8-41a2-9f9f-d0581a0c9fa5")); + } +} diff --git b/src/main/java/com/qiwu/inference/util/SpringContextUtil.java a/src/main/java/com/qiwu/inference/util/SpringContextUtil.java new file mode 100644 index 0000000..81e20f9 --- /dev/null +++ a/src/main/java/com/qiwu/inference/util/SpringContextUtil.java @@ -0,0 +1,35 @@ +package com.qiwu.inference.util; + +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.stereotype.Component; + +@Component +public class SpringContextUtil implements ApplicationContextAware { + private static ApplicationContext applicationContext = null; + + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + if (SpringContextUtil.applicationContext == null) { + SpringContextUtil.applicationContext = applicationContext; + } + } + + public static ApplicationContext getApplicationContext() { + return applicationContext; + } + + public static Object getBean(String name) { + return getApplicationContext().getBean(name); + } + + public static T getBean(Class clazz) { + return getApplicationContext().getBean(clazz); + } + + public static T getBean(String name, Class clazz) { + return getApplicationContext().getBean(name, clazz); + } + +} \ No newline at end of file diff --git b/src/main/java/com/qiwu/inference/util/ThreadLocalUtil.java a/src/main/java/com/qiwu/inference/util/ThreadLocalUtil.java new file mode 100644 index 0000000..2e965c8 --- /dev/null +++ a/src/main/java/com/qiwu/inference/util/ThreadLocalUtil.java @@ -0,0 +1,148 @@ +package com.qiwu.inference.util; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + *
+ * ThreadLocal을 사용하여 스레드 간 객체를 전파하기 위한 유틸리리 클래스
+ * 
+ */ +public class ThreadLocalUtil { + + private static final Logger LOGGER = LoggerFactory.getLogger(ThreadLocalUtil.class); + + // 스레드 간 공유 객체를 저장하기 위한 ThreadLocal + private static ThreadLocal> threadLocal = new ThreadLocal>(); + + /** + *
+     * ThreadLocal 用于在线程之间传播对象的实用程序类
+     * 
+ * @return + */ + private static Map getThreadLocal() { + if (threadLocal.get() == null) { + Map sharedObject = new HashMap(); + threadLocal.set(sharedObject); + } + + return threadLocal.get(); + }//end of getThreadLocal() + + /** + *
+     * 以在线程间共享对象中指定的键的名称存储对象
+     * 
+ * @param key + * @param object + */ + public static void add(String key, Object object) { // NOPMD + getThreadLocal().put(key, object); + }//end of add() + + /** + *
+     * 从线程之间的共享对象导入与指定键相对应的对象
+     * 
+ * @param key + * @return + */ + public static Object get(String key) { // NOPMD + return getThreadLocal().get(key); + }//end of get() + + /** + *
+     * 调查是否存在与线程间共享对象上指定的键相对应的对象
+     * 
+ * @param key + * @return + */ + public static boolean isExist(String key) { + Object object = getThreadLocal().get(key); + if (object != null) { + return true; + } else { + return false; + } + }//end of isExist() + + /** + *
+     * 初始化线程之间的共享对象
+     * 
+ */ + public static void clearSharedObject() { + getThreadLocal().clear(); + threadLocal.set(null); + }//end of clearSharedObject() + + /** + *
+     * 
+ * @return + */ + public static String[] getThreadLocalKeys() { + String[] arrKeys = new String[getThreadLocal().size()]; + Iterator keyIter = getThreadLocal().keySet().iterator(); + + int i = 0; + while (keyIter.hasNext()) { + arrKeys[i] = keyIter.next(); + i++; + } + + return arrKeys; + }//end of getThreadLocalKeys() + + /** + *
+     * 
+ * @return + */ + public static int size() { + return getThreadLocal().size(); + }//end of size() + + /** + *
+     * 
+ * @return + */ + public static Object[] getThreadLocalValues() { + int size = size(); + + String[] arrKeys = getThreadLocalKeys(); + Object[] values = new Object[size]; + + for (int i = 0; i < size; i++) { + values[i] = getThreadLocal().get(arrKeys[i]); + } + + return values; + }//end of getThreadLocalValues() + + /** + *
+     * 
+ */ + public static void toPrintString() { + int size = size(); + + StringBuffer str = new StringBuffer(); + String[] keys = getThreadLocalKeys(); + Object[] values = getThreadLocalValues(); + + for (int i = 0; i < size; i++) { + str.append(" " + keys[i] + " = " + values[i] + " \n"); + } + + LOGGER.info("{}", str.toString()); + }//end of toPringString() + +}// end of ThreadLocalUtil.java \ No newline at end of file diff --git b/src/main/java/com/qiwu/inference/util/UnPackageUtil.java a/src/main/java/com/qiwu/inference/util/UnPackageUtil.java new file mode 100644 index 0000000..0e153aa --- /dev/null +++ a/src/main/java/com/qiwu/inference/util/UnPackageUtil.java @@ -0,0 +1,82 @@ +package com.qiwu.inference.util; + +import com.github.junrar.Archive; +import com.github.junrar.rarfile.FileHeader; +import net.lingala.zip4j.core.ZipFile; +import org.slf4j.LoggerFactory; +import org.slf4j.Logger; + +import java.io.File; +import java.io.FileOutputStream; + +public class UnPackageUtil { + + private static final Logger logger = LoggerFactory.getLogger(UnPackageUtil.class); + + /** + * zip文件解压 + * + * @param destPath 解压文件路径 + * @param zipFile 压缩文件 + * @param password 解压密码(如果有) + */ + public static void unPackageZip(File zipFile, String password, String destPath) { + try { + ZipFile zip = new ZipFile(zipFile); + /*zip4j默认用GBK编码去解压,这里设置编码为GBK的*/ + zip.setFileNameCharset("GBK"); + logger.info("begin unpack zip file...."); + zip.extractAll(destPath); + // 如果解压需要密码 + if (password != null) { + if (zip.isEncrypted()) { + zip.setPassword(password); + } + } + + } catch (Exception e) { + logger.error("解压失败:", e.getMessage(), e); + } + } + + /** + * rar文件解压(不支持有密码的压缩包) + * + * @param rarFile rar压缩包 + * @param destPath 解压保存路径 + */ + public static void unPackageRar(File rarFile, String destPath) { + try (Archive archive = new Archive(rarFile)) { + if (null != archive) { + FileHeader fileHeader = archive.nextFileHeader(); + File file = null; + while (null != fileHeader) { + // 防止文件名中文乱码问题的处理 + String fileName = fileHeader.getFileNameW().isEmpty() ? fileHeader.getFileNameString() : fileHeader.getFileNameW(); + if (fileHeader.isDirectory()) { + //是文件夹 + file = new File(destPath + File.separator + fileName); + file.mkdirs(); + } else { + //不是文件夹 + file = new File(destPath + File.separator + fileName.trim()); + if (!file.exists()) { + if (!file.getParentFile().exists()) { + // 相对路径可能多级,可能需要创建父目录. + file.getParentFile().mkdirs(); + } + file.createNewFile(); + } + FileOutputStream os = new FileOutputStream(file); + archive.extractFile(fileHeader, os); + os.close(); + } + fileHeader = archive.nextFileHeader(); + } + } + } catch (Exception e) { + logger.error("解压失败:", e.getMessage(), e); + } + } +} + diff --git b/src/main/resources/application-dev.yml a/src/main/resources/application-dev.yml new file mode 100644 index 0000000..072e5dc --- /dev/null +++ a/src/main/resources/application-dev.yml @@ -0,0 +1,47 @@ +server: + port: 8082 + serlvet: + context-path:/inferenceGame + +#设置当前服务名 +spring: + application: + #注册到注册中心的服务名 + name: inference-game + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://localhost:3306/inference_game_1?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC + username: root + password: admin!@#$ + type: com.alibaba.druid.pool.DruidDataSource + druid: + initial-size: 5 + min-idle: 5 + max-active: 20 + max-wait: 60000 + #配置间隔多久才进行一次检测,检测需要关闭的空闲连接 + time-between-eviction-runs-millis: 20000 + #配置一个连接在池中最小生存的时间 + min-evictable-idle-time-millis: 300000 + servlet: + multipart: + max-file-size: 1GB #文件最大大小 + max-request-size: 1GB #文件请求大小 + #location: /tmp/pimport #文件存储路径 + +mybatis-plus: + mapper-locations: classpath:com.qiwu.inference.dao/*.xml + global-config: + db-config: + id-type: auto + configuration: + auto-mapping-behavior: partial + map-underscore-to-camel-case: true + log-impl: org.apache.ibatis.logging.stdout.StdOutImpl + + + +logging: + level: + root: info + com.qiwu.inference: debug \ No newline at end of file diff --git b/src/main/resources/application.yml a/src/main/resources/application.yml new file mode 100644 index 0000000..caf4dfc --- /dev/null +++ a/src/main/resources/application.yml @@ -0,0 +1,3 @@ +spring: + profiles: + active: dev \ No newline at end of file diff --git b/src/main/resources/com.qiwu.inference.dao/BehaviourMapper.xml a/src/main/resources/com.qiwu.inference.dao/BehaviourMapper.xml new file mode 100644 index 0000000..497aaa4 --- /dev/null +++ a/src/main/resources/com.qiwu.inference.dao/BehaviourMapper.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git b/src/main/resources/com.qiwu.inference.dao/BehaviourRecordMapper.xml a/src/main/resources/com.qiwu.inference.dao/BehaviourRecordMapper.xml new file mode 100644 index 0000000..914a1ce --- /dev/null +++ a/src/main/resources/com.qiwu.inference.dao/BehaviourRecordMapper.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git b/src/main/resources/com.qiwu.inference.dao/ClueMapper.xml a/src/main/resources/com.qiwu.inference.dao/ClueMapper.xml new file mode 100644 index 0000000..24eb386 --- /dev/null +++ a/src/main/resources/com.qiwu.inference.dao/ClueMapper.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git b/src/main/resources/com.qiwu.inference.dao/ClueRecordMapper.xml a/src/main/resources/com.qiwu.inference.dao/ClueRecordMapper.xml new file mode 100644 index 0000000..56c195f --- /dev/null +++ a/src/main/resources/com.qiwu.inference.dao/ClueRecordMapper.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git b/src/main/resources/com.qiwu.inference.dao/DemandTaskMapper.xml a/src/main/resources/com.qiwu.inference.dao/DemandTaskMapper.xml new file mode 100644 index 0000000..adbecf5 --- /dev/null +++ a/src/main/resources/com.qiwu.inference.dao/DemandTaskMapper.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git b/src/main/resources/com.qiwu.inference.dao/DemandTaskRecordMapper.xml a/src/main/resources/com.qiwu.inference.dao/DemandTaskRecordMapper.xml new file mode 100644 index 0000000..bdd3f9f --- /dev/null +++ a/src/main/resources/com.qiwu.inference.dao/DemandTaskRecordMapper.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git b/src/main/resources/com.qiwu.inference.dao/DispositionMapper.xml a/src/main/resources/com.qiwu.inference.dao/DispositionMapper.xml new file mode 100644 index 0000000..0ec79a4 --- /dev/null +++ a/src/main/resources/com.qiwu.inference.dao/DispositionMapper.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git b/src/main/resources/com.qiwu.inference.dao/DispositionMapperRecord.xml a/src/main/resources/com.qiwu.inference.dao/DispositionMapperRecord.xml new file mode 100644 index 0000000..127070c --- /dev/null +++ a/src/main/resources/com.qiwu.inference.dao/DispositionMapperRecord.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git b/src/main/resources/com.qiwu.inference.dao/DispositionTypeMapper.xml a/src/main/resources/com.qiwu.inference.dao/DispositionTypeMapper.xml new file mode 100644 index 0000000..7402592 --- /dev/null +++ a/src/main/resources/com.qiwu.inference.dao/DispositionTypeMapper.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git b/src/main/resources/com.qiwu.inference.dao/EndGoalMapper.xml a/src/main/resources/com.qiwu.inference.dao/EndGoalMapper.xml new file mode 100644 index 0000000..80e13df --- /dev/null +++ a/src/main/resources/com.qiwu.inference.dao/EndGoalMapper.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git b/src/main/resources/com.qiwu.inference.dao/IdentityMapper.xml a/src/main/resources/com.qiwu.inference.dao/IdentityMapper.xml new file mode 100644 index 0000000..c15e39b --- /dev/null +++ a/src/main/resources/com.qiwu.inference.dao/IdentityMapper.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git b/src/main/resources/com.qiwu.inference.dao/ItemMapper.xml a/src/main/resources/com.qiwu.inference.dao/ItemMapper.xml new file mode 100644 index 0000000..9825d75 --- /dev/null +++ a/src/main/resources/com.qiwu.inference.dao/ItemMapper.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git b/src/main/resources/com.qiwu.inference.dao/KeyClueMapper.xml a/src/main/resources/com.qiwu.inference.dao/KeyClueMapper.xml new file mode 100644 index 0000000..83973ee --- /dev/null +++ a/src/main/resources/com.qiwu.inference.dao/KeyClueMapper.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git b/src/main/resources/com.qiwu.inference.dao/LocationMapper.xml a/src/main/resources/com.qiwu.inference.dao/LocationMapper.xml new file mode 100644 index 0000000..a57e778 --- /dev/null +++ a/src/main/resources/com.qiwu.inference.dao/LocationMapper.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git b/src/main/resources/com.qiwu.inference.dao/PersonMapper.xml a/src/main/resources/com.qiwu.inference.dao/PersonMapper.xml new file mode 100644 index 0000000..d0094fd --- /dev/null +++ a/src/main/resources/com.qiwu.inference.dao/PersonMapper.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + diff --git b/src/main/resources/com.qiwu.inference.dao/PersonRecordMapper.xml a/src/main/resources/com.qiwu.inference.dao/PersonRecordMapper.xml new file mode 100644 index 0000000..c51b576 --- /dev/null +++ a/src/main/resources/com.qiwu.inference.dao/PersonRecordMapper.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git b/src/main/resources/com.qiwu.inference.dao/RelationMapper.xml a/src/main/resources/com.qiwu.inference.dao/RelationMapper.xml new file mode 100644 index 0000000..1dfa95a --- /dev/null +++ a/src/main/resources/com.qiwu.inference.dao/RelationMapper.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git b/src/main/resources/com.qiwu.inference.dao/RelationRecordMapper.xml a/src/main/resources/com.qiwu.inference.dao/RelationRecordMapper.xml new file mode 100644 index 0000000..c9d2217 --- /dev/null +++ a/src/main/resources/com.qiwu.inference.dao/RelationRecordMapper.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + diff --git b/src/main/resources/com.qiwu.inference.dao/RelationTypeMapper.xml a/src/main/resources/com.qiwu.inference.dao/RelationTypeMapper.xml new file mode 100644 index 0000000..6b348a5 --- /dev/null +++ a/src/main/resources/com.qiwu.inference.dao/RelationTypeMapper.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git b/src/main/resources/com.qiwu.inference.dao/TaskConditionMapper.xml a/src/main/resources/com.qiwu.inference.dao/TaskConditionMapper.xml new file mode 100644 index 0000000..be48844 --- /dev/null +++ a/src/main/resources/com.qiwu.inference.dao/TaskConditionMapper.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git b/src/main/resources/file/behaviour.xlsx a/src/main/resources/file/behaviour.xlsx new file mode 100644 index 0000000..fa7053b Binary files /dev/null and a/src/main/resources/file/behaviour.xlsx differ diff --git b/src/main/resources/file/clue.xlsx a/src/main/resources/file/clue.xlsx new file mode 100644 index 0000000..62f00ba Binary files /dev/null and a/src/main/resources/file/clue.xlsx differ diff --git b/src/main/resources/file/demand_task.xlsx a/src/main/resources/file/demand_task.xlsx new file mode 100644 index 0000000..1b1293b Binary files /dev/null and a/src/main/resources/file/demand_task.xlsx differ diff --git b/src/main/resources/file/disposition.xlsx a/src/main/resources/file/disposition.xlsx new file mode 100644 index 0000000..674dcac Binary files /dev/null and a/src/main/resources/file/disposition.xlsx differ diff --git b/src/main/resources/file/disposition_type.xlsx a/src/main/resources/file/disposition_type.xlsx new file mode 100644 index 0000000..81400ba Binary files /dev/null and a/src/main/resources/file/disposition_type.xlsx differ diff --git b/src/main/resources/file/end_goal.xlsx a/src/main/resources/file/end_goal.xlsx new file mode 100644 index 0000000..727009c Binary files /dev/null and a/src/main/resources/file/end_goal.xlsx differ diff --git b/src/main/resources/file/identity.xlsx a/src/main/resources/file/identity.xlsx new file mode 100644 index 0000000..f4f50d5 Binary files /dev/null and a/src/main/resources/file/identity.xlsx differ diff --git b/src/main/resources/file/item.xlsx a/src/main/resources/file/item.xlsx new file mode 100644 index 0000000..8d6f2c6 Binary files /dev/null and a/src/main/resources/file/item.xlsx differ diff --git b/src/main/resources/file/key_clue.xlsx a/src/main/resources/file/key_clue.xlsx new file mode 100644 index 0000000..31695a2 Binary files /dev/null and a/src/main/resources/file/key_clue.xlsx differ diff --git b/src/main/resources/file/location.xlsx a/src/main/resources/file/location.xlsx new file mode 100644 index 0000000..f0c536f Binary files /dev/null and a/src/main/resources/file/location.xlsx differ diff --git b/src/main/resources/file/person.xlsx a/src/main/resources/file/person.xlsx new file mode 100644 index 0000000..2549f82 Binary files /dev/null and a/src/main/resources/file/person.xlsx differ diff --git b/src/main/resources/file/relation.xlsx a/src/main/resources/file/relation.xlsx new file mode 100644 index 0000000..be43ba4 Binary files /dev/null and a/src/main/resources/file/relation.xlsx differ diff --git b/src/main/resources/file/relation_type.xlsx a/src/main/resources/file/relation_type.xlsx new file mode 100644 index 0000000..8549894 Binary files /dev/null and a/src/main/resources/file/relation_type.xlsx differ diff --git b/src/main/resources/file/task_condition.xlsx a/src/main/resources/file/task_condition.xlsx new file mode 100644 index 0000000..e9381db Binary files /dev/null and a/src/main/resources/file/task_condition.xlsx differ diff --git b/src/main/resources/generator.properties a/src/main/resources/generator.properties new file mode 100644 index 0000000..36d8d4a --- /dev/null +++ a/src/main/resources/generator.properties @@ -0,0 +1,5 @@ +dataSource.url=jdbc:mysql://localhost:3306/inference_game?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai +dataSource.driverName=com.mysql.cj.jdbc.Driver +dataSource.username=root +dataSource.password=admin!@#$ +package.base=com.qiwu.inference \ No newline at end of file diff --git b/src/main/resources/log4j2.xml a/src/main/resources/log4j2.xml new file mode 100644 index 0000000..948bf97 --- /dev/null +++ a/src/main/resources/log4j2.xml @@ -0,0 +1,84 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git b/src/main/resources/sql/drop_tb.sql a/src/main/resources/sql/drop_tb.sql new file mode 100644 index 0000000..65f67f0 --- /dev/null +++ a/src/main/resources/sql/drop_tb.sql @@ -0,0 +1,122 @@ +-- ---------------------------- +-- Table structure for person_record +-- ---------------------------- +DROP TABLE IF EXISTS `person_record`; +CREATE TABLE `person_record` ( + `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '人物id', + `gate_no` varchar(255) DEFAULT NULL COMMENT '关卡编号', + `name` varchar(255) DEFAULT NULL COMMENT '人物名称', + `person_id` int(20) DEFAULT NULL COMMENT '人物id', + `description` varchar(255) DEFAULT NULL COMMENT '人物描述', + `identity_id` int(20) DEFAULT NULL COMMENT '身份id', + `identity_name` varchar(255) DEFAULT NULL COMMENT '身份名称', + `age` int(2) DEFAULT NULL COMMENT '年龄', + `is_key` int(2) DEFAULT NULL COMMENT '是否为关键人物 1 关键人物 2 普通人物', + `gender` int(2) DEFAULT NULL COMMENT '性别', + `location` int(11) DEFAULT NULL COMMENT '所在地', + `disposition` text COMMENT '性格', + `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '创建时间', + `update_time` timestamp NULL DEFAULT NULL COMMENT '更新时间', + PRIMARY KEY (`id`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; + + +-- ---------------------------- +-- Table structure for relation_record +-- ---------------------------- +DROP TABLE IF EXISTS `relation_record`; +CREATE TABLE `relation_record` ( + `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'id', + `name` varchar(255) DEFAULT NULL COMMENT '关系名称', + `description` varchar(255) DEFAULT NULL COMMENT '关系描述', + `type` int(2) DEFAULT NULL COMMENT '关系类型', + `relation_id` int(11) DEFAULT NULL COMMENT '关系id', + `subject` int(11) DEFAULT NULL COMMENT '关系的主体', + `subject_name` varchar(255) DEFAULT NULL COMMENT '主体名称:老王', + `object` int(11) DEFAULT NULL COMMENT '关系客体', + `object_name` varchar(255) DEFAULT NULL COMMENT '主体名称:老王', + `master_info_level` int(2) DEFAULT NULL COMMENT '掌握信息级别', + `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '创建时间', + `update_time` timestamp NULL DEFAULT NULL COMMENT '更新时间', + PRIMARY KEY (`id`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; + + +-- ---------------------------- +-- Table structure for disposition_record +-- ---------------------------- +DROP TABLE IF EXISTS `disposition_record`; +CREATE TABLE `disposition_record` ( + `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'id', + `subject` int(11) DEFAULT NULL COMMENT '人物id', + `disposition_id` int(11) DEFAULT NULL COMMENT '性格id', + `name` varchar(255) DEFAULT NULL COMMENT '性格名称', + `description` varchar(255) DEFAULT NULL COMMENT '性格描述', + `type` varchar(255) DEFAULT NULL COMMENT '类型', + `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '创建时间', + `update_time` timestamp NULL DEFAULT NULL COMMENT '更新时间', + PRIMARY KEY (`id`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; + + +-- ---------------------------- +-- Table structure for demand_task_record +-- ---------------------------- +DROP TABLE IF EXISTS `demand_task_record`; +CREATE TABLE `demand_task_record` ( + `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'id', + `demand_task_id` varchar(255) DEFAULT NULL COMMENT '任务id', + `name` varchar(255) DEFAULT NULL COMMENT '名称', + `description` varchar(255) DEFAULT NULL COMMENT '描述', + `subject` int(11) DEFAULT NULL COMMENT '主体', + `object` int(11) DEFAULT NULL COMMENT '客体', + `type` int(2) DEFAULT NULL COMMENT '类型: 1:身份 2:场所 3:性格爱好 4:行为 5:关系 6:任务 9:关键线索', + `clue_id` int(11) DEFAULT NULL COMMENT '线索id', + `info_level` int(2) DEFAULT NULL COMMENT '信息级别', + `task_label` int(2) DEFAULT NULL COMMENT '任务标签 1普通任务 2关键任务 3目标任务', + `clue_switch` int(2) DEFAULT NULL COMMENT '线索开关 0代表不需要线索就可执行,1代表需要线索才能执行此任务', + `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '创建时间', + `update_time` timestamp NULL DEFAULT NULL COMMENT '更新时间', + PRIMARY KEY (`id`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; + + +-- ---------------------------- +-- Table structure for clue_record +-- ---------------------------- +DROP TABLE IF EXISTS `clue_record`; +CREATE TABLE `clue_record` ( +`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'id', +`clue_id` int(11) DEFAULT NULL COMMENT '线索id', +`clue_name` varchar(255) DEFAULT NULL COMMENT '线索名称', +`subject` int(11) DEFAULT NULL COMMENT '主体', +`object` int(11) DEFAULT NULL COMMENT '客体', +`description` varchar(255) DEFAULT NULL COMMENT '描述', +`type` int(2) DEFAULT NULL COMMENT '类型: 1:身份 2:场所 3:性格爱好 4:行为 5:关系 6:任务 9:关键线索 ', +`info_level` int(2) DEFAULT NULL COMMENT '信息级别', +`associated_person` int(11) DEFAULT NULL COMMENT '关联人物', +`clue_template` varchar(255) DEFAULT NULL COMMENT '线索模板', +`trust_degree` int(11) DEFAULT NULL COMMENT '信任度', +`deterrence_degree` int(11) DEFAULT NULL COMMENT '威胁', +`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '创建时间', +`update_time` timestamp NULL DEFAULT NULL COMMENT '更新时间', +PRIMARY KEY (`id`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; + +-- ---------------------------- +-- Table structure for behaviour_record +-- ---------------------------- +DROP TABLE IF EXISTS `behaviour_record`; +CREATE TABLE `behaviour_record` ( +`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '行为记录id', +`name` varchar(255) DEFAULT NULL COMMENT '行为名称', +`behaviour_id` int(11) DEFAULT NULL COMMENT '行为id', +`description` varchar(255) DEFAULT NULL COMMENT '行为描述', +`subject` int(11) DEFAULT NULL COMMENT '主体:1', +`subject_name` varchar(255) DEFAULT NULL COMMENT '主体名称:老王', +`object` int(11) DEFAULT NULL COMMENT '客体:2', +`object_name` varchar(255) DEFAULT NULL COMMENT '客体名称:小美', +`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '创建时间', +`update_time` timestamp NULL DEFAULT NULL COMMENT '更新时间', +PRIMARY KEY (`id`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; \ No newline at end of file diff --git b/src/main/resources/sql/inference_game.sql a/src/main/resources/sql/inference_game.sql new file mode 100644 index 0000000..7a8f245 --- /dev/null +++ a/src/main/resources/sql/inference_game.sql @@ -0,0 +1,428 @@ +/* + Navicat Premium Data Transfer + + Source Server : mysql + Source Server Type : MySQL + Source Server Version : 50733 + Source Host : 127.0.0.1:3306 + Source Schema : inference_game_1 + + Target Server Type : MySQL + Target Server Version : 50733 + File Encoding : 65001 + + Date: 02/02/2023 13:51:37 +*/ + +SET NAMES utf8mb4; +SET FOREIGN_KEY_CHECKS = 0; + +-- ---------------------------- +-- Table structure for behaviour +-- ---------------------------- +DROP TABLE IF EXISTS `behaviour`; +CREATE TABLE `behaviour` ( + `id` int(11) NOT NULL COMMENT '行为id', + `name` varchar(255) DEFAULT NULL COMMENT '行为名称', + `description` varchar(255) DEFAULT NULL COMMENT '行为描述', + `generation_probability` float(8,2) DEFAULT NULL COMMENT '发生的概率', + `object_identity` varchar(255) DEFAULT NULL COMMENT '行为对象身份(B)', + `associated_id` varchar(255) DEFAULT NULL COMMENT '关联对象id', + `subject_disposition` varchar(255) DEFAULT NULL COMMENT '行为人性格喜好|概率增减(A)', + `subject_identity_probability` varchar(255) DEFAULT NULL COMMENT '行为人身份|概率增减(A)', + `object_identity_probability` varchar(255) DEFAULT NULL COMMENT '行为对象身份|概率增减(B)', + `object_relation_probability` varchar(255) DEFAULT NULL COMMENT '与行为对象关系|概率影响(A与B)', + `object_disposition_probability` varchar(255) DEFAULT NULL COMMENT '行为对象性格喜好|概率影响(B)', + `gender_probability` varchar(255) DEFAULT NULL COMMENT '行为人性别|行为对象性别|概率影响(A)', + `exclusion_behaviour` varchar(255) DEFAULT NULL COMMENT '互斥行为', + `inverse_behaviour` varchar(255) DEFAULT NULL COMMENT '反向行为', + `inverse_label` int(2) DEFAULT NULL COMMENT '被动行为标签:0为主行为,1为被动行为', + `single_label` int(2) DEFAULT NULL COMMENT '单人行为标签:0为双人行为,1为单人行为', + `info_level` int(2) DEFAULT NULL COMMENT '信息重要级别', + `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '创建时间', + `update_time` timestamp NULL DEFAULT NULL COMMENT '更新时间', + PRIMARY KEY (`id`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; + +-- ---------------------------- +-- Table structure for behaviour_record +-- ---------------------------- +DROP TABLE IF EXISTS `behaviour_record`; +CREATE TABLE `behaviour_record` ( + `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '行为记录id', + `name` varchar(255) DEFAULT NULL COMMENT '行为名称', + `behaviour_id` int(11) DEFAULT NULL COMMENT '行为id', + `description` varchar(255) DEFAULT NULL COMMENT '行为描述', + `subject` int(11) DEFAULT NULL COMMENT '主体:1', + `subject_name` varchar(255) DEFAULT NULL COMMENT '主体名称:老王', + `object` int(11) DEFAULT NULL COMMENT '客体:2', + `object_name` varchar(255) DEFAULT NULL COMMENT '客体名称:小美', + `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '创建时间', + `update_time` timestamp NULL DEFAULT NULL COMMENT '更新时间', + PRIMARY KEY (`id`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; + +-- ---------------------------- +-- Table structure for clue +-- ---------------------------- +DROP TABLE IF EXISTS `clue`; +CREATE TABLE `clue` ( + `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'id', + `name` varchar(255) DEFAULT NULL COMMENT '线索名称', + `description` varchar(255) DEFAULT NULL COMMENT '描述', + `type` int(2) DEFAULT NULL COMMENT '类型: 1:身份 2:场所 3:性格爱好 4:行为 5:关系 6:任务', + `associated_id` int(11) DEFAULT NULL COMMENT '对应的Id', + `clue_template` varchar(255) DEFAULT NULL COMMENT '线索模板', + `info_level` varchar(255) DEFAULT NULL COMMENT '信息级别', + `trust_degree` int(11) DEFAULT NULL COMMENT '信任度', + `deterrence_degree` int(11) DEFAULT NULL COMMENT '威胁', + `prob` varchar(255) DEFAULT NULL COMMENT '概率', + `my_trust_degree` int(11) DEFAULT NULL COMMENT '自己的信任度', + `my_deterrence_degree` int(11) DEFAULT NULL COMMENT '自己的威胁度', + `score` int(11) DEFAULT NULL COMMENT '积分', + `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '创建时间', + `update_time` timestamp NULL DEFAULT NULL COMMENT '更新时间', + PRIMARY KEY (`id`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; + +-- ---------------------------- +-- Table structure for clue_record +-- ---------------------------- +DROP TABLE IF EXISTS `clue_record`; +CREATE TABLE `clue_record` ( + `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'id', + `clue_id` int(11) DEFAULT NULL COMMENT '线索id', + `clue_name` varchar(255) DEFAULT NULL COMMENT '线索名称', + `subject` int(11) DEFAULT NULL COMMENT '主体', + `object` int(11) DEFAULT NULL COMMENT '客体', + `description` varchar(255) DEFAULT NULL COMMENT '描述', + `type` int(2) DEFAULT NULL COMMENT '类型: 1:身份 2:场所 3:性格爱好 4:行为 5:关系 6:任务 9:关键线索 ', + `info_level` int(2) DEFAULT NULL COMMENT '信息级别', + `associated_person` int(11) DEFAULT NULL COMMENT '关联人物', + `clue_template` varchar(255) DEFAULT NULL COMMENT '线索模板', + `trust_degree` int(11) DEFAULT NULL COMMENT '信任度', + `deterrence_degree` int(11) DEFAULT NULL COMMENT '威胁度', + `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '创建时间', + `update_time` timestamp NULL DEFAULT NULL COMMENT '更新时间', + PRIMARY KEY (`id`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; + +-- ---------------------------- +-- Table structure for demand_task +-- ---------------------------- +DROP TABLE IF EXISTS `demand_task`; +CREATE TABLE `demand_task` ( + `id` int(11) NOT NULL COMMENT 'id', + `name` varchar(255) DEFAULT NULL COMMENT '名称', + `description` varchar(255) DEFAULT NULL COMMENT '描述', + `task_group` int(2) DEFAULT NULL COMMENT '任务组', + `subject_need_identity` varchar(255) DEFAULT NULL COMMENT '主体必要身份', + `object_need_identity` varchar(255) DEFAULT NULL COMMENT '客体必要身份', + `subject_need_gender` varchar(255) DEFAULT NULL COMMENT '主体必要的性别', + `object_need_gender` varchar(255) DEFAULT NULL COMMENT '客体必要的性别', + `trust_condition` varchar(255) DEFAULT NULL COMMENT '开启条件信任度', + `deterrence_condition` varchar(255) DEFAULT NULL COMMENT '开启条件威慑度', + `post_task` varchar(255) DEFAULT NULL COMMENT '后置任务', + `condition1` varchar(255) DEFAULT NULL COMMENT '条件1|次数', + `condition2` varchar(255) DEFAULT NULL COMMENT '条件2|次数', + `associated_disposition` varchar(255) DEFAULT NULL COMMENT '关联喜好', + `associated_identity` varchar(255) DEFAULT NULL COMMENT '关联身份', + `associated_behaviour` varchar(255) DEFAULT NULL COMMENT '关联行为', + `associated_relation` varchar(255) DEFAULT NULL COMMENT '关联关系', + `exclusive_task` varchar(255) DEFAULT NULL COMMENT '互斥任务', + `trust_degree` int(5) DEFAULT NULL COMMENT '信任度增减', + `deterrence_degree` int(5) DEFAULT NULL COMMENT '威慑度增减', + `completion_reward` varchar(255) DEFAULT NULL COMMENT '完成奖励', + `reputation` int(5) DEFAULT NULL COMMENT '声望增减', + `effective_degree` int(2) DEFAULT NULL COMMENT '有效次数', + `special_task` int(2) DEFAULT NULL COMMENT '特殊任务 0 主动任务 1 被动任务', + `info_level` int(2) DEFAULT NULL COMMENT '信息级别', + `task_label` int(2) DEFAULT NULL COMMENT '任务标签 1普通任务 2关键任务 3目标任务', + `clue_switch` int(2) DEFAULT NULL COMMENT '线索开关 0代表不需要线索就可执行,1代表需要线索才能执行此任务', + `is_auto` int(2) DEFAULT NULL COMMENT '自动触发', + `negative_task` int(2) DEFAULT NULL COMMENT '负面任务', + `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '创建时间', + `update_time` timestamp NULL DEFAULT NULL COMMENT '更新时间', + PRIMARY KEY (`id`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; + +-- ---------------------------- +-- Table structure for demand_task_record +-- ---------------------------- +DROP TABLE IF EXISTS `demand_task_record`; +CREATE TABLE `demand_task_record` ( + `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'id', + `demand_task_id` varchar(255) DEFAULT NULL COMMENT '任务id', + `name` varchar(255) DEFAULT NULL COMMENT '名称', + `task_group` int(2) DEFAULT NULL COMMENT '任务组', + `description` varchar(255) DEFAULT NULL COMMENT '描述', + `subject` int(11) DEFAULT NULL COMMENT '主体', + `object` int(11) DEFAULT NULL COMMENT '客体', + `type` int(2) DEFAULT NULL COMMENT '类型: 1:身份 2:场所 3:性格爱好 4:行为 5:关系 6:任务 9:关键线索', + `clue_id` int(11) DEFAULT NULL COMMENT '线索id', + `info_level` int(2) DEFAULT NULL COMMENT '信息级别', + `task_label` int(2) DEFAULT NULL COMMENT '任务标签 1普通任务 2关键任务 3目标任务', + `clue_switch` int(2) DEFAULT NULL COMMENT '线索开关 0代表不需要线索就可执行,1代表需要线索才能执行此任务', + `is_auto` int(2) DEFAULT NULL COMMENT '自动触发', + `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '创建时间', + `update_time` timestamp NULL DEFAULT NULL COMMENT '更新时间', + PRIMARY KEY (`id`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; + +-- ---------------------------- +-- Table structure for disposition +-- ---------------------------- +DROP TABLE IF EXISTS `disposition`; +CREATE TABLE `disposition` ( + `id` int(11) NOT NULL COMMENT '性格id', + `name` varchar(255) DEFAULT NULL COMMENT '性格名称', + `description` varchar(255) DEFAULT NULL COMMENT '性格描述', + `type` int(2) DEFAULT NULL COMMENT '类型', + `weight` int(10) DEFAULT NULL COMMENT '基础权重', + `identity_weight` varchar(255) DEFAULT NULL COMMENT '身份影响权重:', + `gender_weight` varchar(255) DEFAULT NULL COMMENT '性别影响权重:', + `age_weight` varchar(255) DEFAULT NULL COMMENT '年龄影响权重:', + `trust_degree` int(10) DEFAULT NULL COMMENT '信任度初始值', + `deterrence_degree` int(10) DEFAULT NULL COMMENT '威胁度初始值:', + `weakness_condition` varchar(255) DEFAULT NULL COMMENT '弱点条件:', + `item_favor_degree` varchar(255) DEFAULT NULL COMMENT '对应物品|好感度增减:', + `identity_favor_degree` varchar(255) DEFAULT NULL COMMENT '对应身份|好感度增减:', + `exclusion_disposition` varchar(255) DEFAULT NULL COMMENT '互斥性格|喜好:', + `info_level` varchar(255) DEFAULT NULL COMMENT '信息重要级别', + `clue_template` varchar(255) DEFAULT NULL COMMENT '对应线索模板:', + `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '创建时间', + `update_time` timestamp NULL DEFAULT NULL COMMENT '更新时间', + PRIMARY KEY (`id`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; + +-- ---------------------------- +-- Table structure for disposition_record +-- ---------------------------- +DROP TABLE IF EXISTS `disposition_record`; +CREATE TABLE `disposition_record` ( + `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'id', + `subject` int(11) DEFAULT NULL COMMENT '人物id', + `disposition_id` int(11) DEFAULT NULL COMMENT '性格id', + `name` varchar(255) DEFAULT NULL COMMENT '性格名称', + `description` varchar(255) DEFAULT NULL COMMENT '性格描述', + `type` int(2) DEFAULT NULL COMMENT '类型', + `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '创建时间', + `update_time` timestamp NULL DEFAULT NULL COMMENT '更新时间', + PRIMARY KEY (`id`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; + +-- ---------------------------- +-- Table structure for disposition_type +-- ---------------------------- +DROP TABLE IF EXISTS `disposition_type`; +CREATE TABLE `disposition_type` ( + `id` int(11) NOT NULL COMMENT '关系类型id', + `name` varchar(255) DEFAULT NULL COMMENT '名称', + `description` varchar(255) DEFAULT NULL COMMENT '描述', + `probability` varchar(255) DEFAULT NULL COMMENT '概率', + `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '创建时间', + `update_time` timestamp NULL DEFAULT NULL COMMENT '更新时间', + PRIMARY KEY (`id`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; + +-- ---------------------------- +-- Table structure for end_goal +-- ---------------------------- +DROP TABLE IF EXISTS `end_goal`; +CREATE TABLE `end_goal` ( + `id` int(11) NOT NULL COMMENT '结局目标id', + `name` varchar(255) DEFAULT NULL COMMENT '目标名称', + `description` varchar(255) DEFAULT NULL COMMENT '目标描述', + `clue_group` varchar(255) DEFAULT NULL COMMENT '组合表:1|2|3|4|5', + `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '创建时间', + `update_time` timestamp NULL DEFAULT NULL COMMENT '更新时间', + PRIMARY KEY (`id`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; + +-- ---------------------------- +-- Table structure for identity +-- ---------------------------- +DROP TABLE IF EXISTS `identity`; +CREATE TABLE `identity` ( + `id` int(11) NOT NULL COMMENT '身份id', + `name` varchar(255) DEFAULT NULL COMMENT '身份名称', + `description` varchar(255) DEFAULT NULL COMMENT '身份描述', + `key_identity` int(2) DEFAULT NULL COMMENT '关键身份', + `gender` int(2) DEFAULT NULL COMMENT '对应性别', + `max_num` int(2) DEFAULT NULL COMMENT '最大人数', + `info_level` int(2) DEFAULT NULL COMMENT '信息级别', + `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '创建时间', + `update_time` timestamp NULL DEFAULT NULL COMMENT '更新时间', + PRIMARY KEY (`id`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; + +-- ---------------------------- +-- Table structure for item +-- ---------------------------- +DROP TABLE IF EXISTS `item`; +CREATE TABLE `item` ( + `id` int(11) NOT NULL COMMENT 'id', + `name` varchar(255) DEFAULT NULL COMMENT '名称', + `description` varchar(255) DEFAULT NULL COMMENT '描述', + `price` varchar(255) DEFAULT NULL COMMENT '价格', + `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '创建时间', + `update_time` timestamp NULL DEFAULT NULL COMMENT '更新时间', + PRIMARY KEY (`id`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; + +-- ---------------------------- +-- Table structure for key_clue +-- ---------------------------- +DROP TABLE IF EXISTS `key_clue`; +CREATE TABLE `key_clue` ( + `id` int(11) NOT NULL COMMENT '关键线索id', + `name` varchar(255) DEFAULT NULL COMMENT '名称', + `description` varchar(255) DEFAULT NULL COMMENT '描述', + `subject_identity` varchar(255) DEFAULT NULL COMMENT '关键人物身份(甲)', + `subject_label` int(2) DEFAULT NULL COMMENT '人物标签(甲)', + `object_identity` varchar(255) DEFAULT NULL COMMENT '掌握线索人物身份(乙)', + `object_label` int(2) DEFAULT NULL COMMENT '人物标签(乙)', + `relation` varchar(255) DEFAULT NULL COMMENT '关系(留空为自己)', + `precue` varchar(255) DEFAULT NULL COMMENT '前置线索:90002|90003', + `clue_group` int(2) DEFAULT NULL COMMENT '线索组合:', + `target` int(11) DEFAULT NULL COMMENT '对应目标:', + `associated_task` varchar(255) DEFAULT NULL COMMENT '对应任务', + `info_level` int(2) DEFAULT NULL COMMENT '信息等级', + `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '创建时间', + `update_time` timestamp NULL DEFAULT NULL COMMENT '更新时间', + PRIMARY KEY (`id`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; + +-- ---------------------------- +-- Table structure for location +-- ---------------------------- +DROP TABLE IF EXISTS `location`; +CREATE TABLE `location` ( + `id` int(11) NOT NULL COMMENT '场所id', + `name` varchar(255) DEFAULT NULL COMMENT '场所名称', + `description` varchar(255) DEFAULT NULL COMMENT '描述', + `key_location` varchar(255) DEFAULT NULL COMMENT '关键场所', + `is_hidden` int(2) DEFAULT NULL COMMENT '是否隐藏', + `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '创建时间', + `update_time` timestamp NULL DEFAULT NULL COMMENT '更新时间', + PRIMARY KEY (`id`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; + +-- ---------------------------- +-- Table structure for person +-- ---------------------------- +DROP TABLE IF EXISTS `person`; +CREATE TABLE `person` ( + `id` int(11) NOT NULL COMMENT '身份id', + `name` varchar(255) DEFAULT NULL COMMENT '人物名称', + `identity_name` varchar(255) DEFAULT NULL COMMENT '身份名称', + `identity_id` int(2) DEFAULT NULL COMMENT '身份id', + `age` varchar(255) DEFAULT NULL COMMENT '对应年龄', + `location` int(11) DEFAULT NULL COMMENT '对应场所', + `gender` int(2) DEFAULT NULL COMMENT '对应性别', + `special_disposition` varchar(255) DEFAULT NULL COMMENT '特定性格', + `kinship` varchar(255) DEFAULT NULL COMMENT '亲缘关系', + `info_level` varchar(255) DEFAULT NULL COMMENT '信息重要级别', + `friendly` int(2) DEFAULT NULL COMMENT '友好人物', + `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '创建时间', + `update_time` timestamp NULL DEFAULT NULL COMMENT '更新时间', + PRIMARY KEY (`id`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; + +-- ---------------------------- +-- Table structure for person_record +-- ---------------------------- +DROP TABLE IF EXISTS `person_record`; +CREATE TABLE `person_record` ( + `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '人物id', + `gate_no` varchar(255) DEFAULT NULL COMMENT '关卡编号', + `name` varchar(255) DEFAULT NULL COMMENT '人物名称', + `person_id` int(20) DEFAULT NULL COMMENT '人物id', + `identity_id` int(20) DEFAULT NULL COMMENT '身份id', + `identity_name` varchar(255) DEFAULT NULL COMMENT '身份名称', + `age` int(2) DEFAULT NULL COMMENT '年龄', + `is_key` int(2) DEFAULT NULL COMMENT '是否为关键人物 1 关键人物 2 普通人物', + `gender` int(2) DEFAULT NULL COMMENT '性别', + `location` int(11) DEFAULT NULL COMMENT '所在地', + `disposition` text COMMENT '性格', + `friendly` int(2) DEFAULT NULL COMMENT '友好人物', + `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '创建时间', + `update_time` timestamp NULL DEFAULT NULL COMMENT '更新时间', + PRIMARY KEY (`id`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; + +-- ---------------------------- +-- Table structure for relation +-- ---------------------------- +DROP TABLE IF EXISTS `relation`; +CREATE TABLE `relation` ( + `id` int(11) NOT NULL COMMENT '关系id', + `name` varchar(255) DEFAULT NULL COMMENT '关系名称', + `description` varchar(255) DEFAULT NULL COMMENT '关系描述', + `type` int(2) DEFAULT NULL COMMENT '关系类型', + `weight` int(5) DEFAULT NULL COMMENT '权重', + `gender_weight` varchar(255) DEFAULT NULL COMMENT '性别影响概率增减', + `age_weight` varchar(255) DEFAULT NULL COMMENT '年龄影响概率增减', + `age_gaps_weight` varchar(255) DEFAULT NULL COMMENT '年龄差影响概率增减', + `identity_weight` varchar(255) DEFAULT NULL COMMENT '身份影响概率增减', + `disposition_weight` varchar(255) DEFAULT NULL COMMENT '性格/喜好影响概率增减', + `exclusion_identity` varchar(255) DEFAULT NULL COMMENT '关系人排除身份', + `exclusion_relation` varchar(255) DEFAULT NULL COMMENT '互斥关系', + `inverse_relation` varchar(255) DEFAULT NULL COMMENT '反向关系', + `info_level` int(2) DEFAULT NULL COMMENT '信息重要级别', + `master_info_level` int(2) DEFAULT NULL COMMENT '掌握信息级别', + `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '创建时间', + `update_time` timestamp NULL DEFAULT NULL COMMENT '更新时间', + PRIMARY KEY (`id`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; + +-- ---------------------------- +-- Table structure for relation_record +-- ---------------------------- +DROP TABLE IF EXISTS `relation_record`; +CREATE TABLE `relation_record` ( + `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'id', + `name` varchar(255) DEFAULT NULL COMMENT '关系名称', + `description` varchar(255) DEFAULT NULL COMMENT '关系描述', + `type` int(2) DEFAULT NULL COMMENT '关系类型', + `relation_id` int(11) DEFAULT NULL COMMENT '关系id', + `subject` int(11) DEFAULT NULL COMMENT '关系的主体', + `subject_name` varchar(255) DEFAULT NULL COMMENT '主体名称:老王', + `object` int(11) DEFAULT NULL COMMENT '关系客体', + `object_name` varchar(255) DEFAULT NULL COMMENT '主体名称:老王', + `master_info_level` int(2) DEFAULT NULL COMMENT '掌握信息级别', + `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '创建时间', + `update_time` timestamp NULL DEFAULT NULL COMMENT '更新时间', + PRIMARY KEY (`id`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; + +-- ---------------------------- +-- Table structure for relation_type +-- ---------------------------- +DROP TABLE IF EXISTS `relation_type`; +CREATE TABLE `relation_type` ( + `id` int(11) NOT NULL COMMENT '关系类型id', + `name` varchar(255) DEFAULT NULL COMMENT '名称', + `description` varchar(255) DEFAULT NULL COMMENT '描述', + `probability` varchar(255) DEFAULT NULL COMMENT '概率', + `identity_probability` varchar(255) DEFAULT NULL COMMENT '身份影响概率增减', + `disposition_probability` varchar(255) DEFAULT NULL COMMENT '性格/喜好影响概率增减', + `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '创建时间', + `update_time` timestamp NULL DEFAULT NULL COMMENT '更新时间', + PRIMARY KEY (`id`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; + +-- ---------------------------- +-- Table structure for task_condition +-- ---------------------------- +DROP TABLE IF EXISTS `task_condition`; +CREATE TABLE `task_condition` ( + `id` int(11) NOT NULL COMMENT 'id', + `name` varchar(255) DEFAULT NULL COMMENT '名称', + `description` varchar(255) DEFAULT NULL COMMENT '描述', + `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '创建时间', + `update_time` timestamp NULL DEFAULT NULL COMMENT '更新时间', + PRIMARY KEY (`id`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; + +SET FOREIGN_KEY_CHECKS = 1; diff --git "b/src/main/resources/sql/\347\240\264\350\247\243Navicat" "a/src/main/resources/sql/\347\240\264\350\247\243Navicat" new file mode 100644 index 0000000..1abb376 --- /dev/null +++ "a/src/main/resources/sql/\347\240\264\350\247\243Navicat" @@ -0,0 +1,2 @@ +rm -rf ~/.config/navicat +rm -rf ~/.config/dconf/user \ No newline at end of file