新增返回下一个要处理的recordId

This commit is contained in:
wulin 2020-12-21 15:50:35 +08:00
parent a51a6251f0
commit 2e373106da
9 changed files with 491 additions and 266 deletions

View File

@ -22,6 +22,7 @@ import com.lz.modules.app.service.DepartmentsService;
import com.lz.modules.app.service.DepartmentsStaffRelateService;
import com.lz.modules.app.service.StaffOccupationService;
import com.lz.modules.app.service.StaffService;
import com.lz.modules.flow.dao.FlowRecordMapper;
import com.lz.modules.flow.entity.*;
import com.lz.modules.flow.model.*;
import com.lz.modules.flow.req.ResultDetailReq;
@ -30,6 +31,7 @@ import com.lz.modules.job.business.DingtalkBusiness;
import com.lz.modules.performance.dto.ResultTaskDto;
import com.lz.modules.performance.dto.StaffTypeDto;
import com.lz.modules.performance.dto.TaskListDto;
import com.lz.modules.performance.req.ResultUpdateTaskReq;
import com.lz.modules.performance.entity.ResultTask;
@ -141,11 +143,16 @@ public class ResultRecordController extends AbstractController {
@Autowired
private FlowStartService flowStartService;
@Autowired
private ResultTaskService resultTaskService;
@Autowired
private StaffOccupationService staffOccupationService;
@Autowired
private FlowRecordMapper flowRecordMapper;
@Autowired
private ResultTaskService resultTaskService;
private final static String TYPE = "H5_URL";
@ -821,277 +828,28 @@ public class ResultRecordController extends AbstractController {
@ApiOperation("保存绩效详情-吴林")
public R saveDetail(@RequestBody @ApiParam ResultRecordDetailDto dto) {
Long userId = getUserId();
R r = resultRecordService.saveDetail(userId, dto);
//ResultRecord resultRecord = new ResultRecord();
ResultRecord resultRecord = resultRecordService.selectResultRecordById(dto.getId());
resultRecord.setAllScore(resultRecord.getLastScore());
List<ResultDetail> inserts = new ArrayList<>();
List<ResultDetail> updates = new ArrayList<>();
List<ResultScore> insertScores = new ArrayList<>();
List<ResultScore> updateScores = new ArrayList<>();
List<ResultDetail> resultDetails = resultDetailService.selectByRecordId(dto.getId());
Map<Long, ResultDetail> mapDetails =
resultDetails.stream().collect(Collectors.toMap(ResultDetail::getId, Function.identity(), (e, r) -> e));
List<ResultDetail> updateResultDetails = new ArrayList<>();
List<ResultDetail> editResultDetails = new ArrayList<>();//涉及到修改的指标保存方便后面生成修改记录
//获取当前绩效的节点
boolean isSetKeyResult = false;
List<FlowRecord> flowRecords = flowRecordService.selectFlowRecordByRecordIdStatus(dto.getId(), 2);
if(flowRecords.size() > 0){
if(flowRecords.get(0).getFlowProcess().intValue() < 1){
log.info("制定目标中");
isSetKeyResult = true;
}
}
for (ResultRecortModelDto model:dto.getRecortModelDtos()
) {
int index = 0;
BigDecimal weight = BigDecimal.ZERO;
/*if(model.getMaxCount() != null && model.getDetailDtos().size() > model.getMaxCount().intValue()){
return R.error(model.getName() + "维度指标数量不能超过" + model.getMaxCount());
}*/
for (ResultDetailDto detailDto:model.getDetailDtos()
) {//排序
ResultDetail resultDetail = new ResultDetail();
BeanUtils.copyProperties(detailDto, resultDetail);
if(!isSetKeyResult){
if(resultDetail.getIsDelete() != null && resultDetail.getIsDelete().intValue() == 1){//被删除了
log.info("指标被删除了");
resultDetail.setIsBack(2);
resultDetail.setBackId(resultDetail.getId());
updateResultDetails.add(resultDetail);
editResultDetails.add(resultDetail);
}else if(resultDetail.getId() == null){
resultDetail.setIsBack(3);//新增
editResultDetails.add(resultDetail);//插入数据库之后会生成id
log.info("新增指标");
}else {
if(resultDetail.getId() != null && mapDetails.containsKey(resultDetail.getId())){
//这里判断是否有更新或者删除
boolean isUp = false;
ResultDetail resultDetail1 = null;
resultDetail1 = mapDetails.get(resultDetail.getId());
if(!resultDetail.getTarget().equals(resultDetail1.getTarget())){
//打上标识
log.info("修改名称");
isUp = true;
}
if(!resultDetail.getKeyResult().equals(resultDetail1.getKeyResult())){
//打上标识
log.info("修改关键结果");
isUp = true;
}
if(!resultDetail.getCheckWeight().equals(resultDetail1.getCheckWeight())){
//打上标识
log.info("修改权重");
isUp = true;
}
if(isUp){
resultDetail1.setId(null);
resultDetail1.setIsBack(2);
resultDetail1.setBackId(resultDetail.getId());
inserts.add(resultDetail1);
editResultDetails.add(resultDetail1);//插入数据库之后会生成id
}
}
}
}
resultDetail.setPriority(index);
index++;
if(resultDetail.getId() != null){
updates.add(resultDetail);
}else{
resultDetail.setStaffId(resultRecord.getStaffId());
resultDetail.setRecordId(resultRecord.getId());
resultDetail.setType(model.getType());
resultDetail.setModelId(model.getId());
resultDetailService.insertResultDetail(resultDetail);
//inserts.add(resultDetail);
}
if(resultDetail.getIsDelete() != null && resultDetail.getIsDelete().intValue() == 1){
//删除任务
resultTaskService.deleteResultTasksByDetailId(resultDetail.getId());
}else{
//更新任务
if(getUserId().longValue() == resultRecord.getStaffId().longValue() &&
detailDto.getTaskDtos() != null && detailDto.getTaskDtos().size() > 0){//本人编辑任务才允许提交
log.info("任务个数{}", detailDto.getTaskDtos().size());
int orderBy = 0;
for (ResultTaskDto taskDto:detailDto.getTaskDtos()
) {
if(taskDto.getId() != null && taskDto.getIsDelete() != null && taskDto.getIsDelete().intValue() == 1){
//删除
resultTaskService.deleteTask(taskDto.getId(),userId);
}else{
ResultUpdateTaskReq taskReq = new ResultUpdateTaskReq();
taskReq.setDetailId(resultDetail.getId());
taskReq.setTaskId(taskDto.getId());
taskReq.setName(taskDto.getName());
taskReq.setOrderBy(orderBy);
taskReq.setProcessRate(BigDecimal.valueOf(taskDto.getProcessRate()));
R r = resultTaskService.saveOrUpdateResultTask(taskReq,userId);
if((int)r.get("code") != 200){
throw new RRException((String)r.get("msg"));
}
orderBy++;
}
}
}
// }
//if(resultDetail.getIsDelete() == null || resultDetail.getIsDelete().intValue() == 0){
BigDecimal score = BigDecimal.ZERO;
if(detailDto.getScoreDtos() != null){
for (ResultScoreDto scoreDto:detailDto.getScoreDtos()
) {
//计算得分
ResultScore resultScore = new ResultScore();
BeanUtils.copyProperties(scoreDto, resultScore);
if(scoreDto.getAcquireScore() != null){
score = score.add(scoreDto.getAcquireScore().multiply(scoreDto.getWeight()));
}
if(resultScore.getId() == null){
insertScores.add(resultScore);
}else{
updateScores.add(resultScore);
}
resultScore.setDetailId(detailDto.getId());
}
resultDetail.setAcquireScore(score);
weight = weight.add(resultDetail.getCheckWeight());
if((int)r.get("code") == 200){
//这里查询是否有下一条待办实现
Long nextRecordId = null;
int freeTime = 3;
List<TaskListDto> taskListDtos = flowRecordMapper.selectTodoTasksByApprovalStaffId(userId, null);
if (taskListDtos.size() > 0) {
for (TaskListDto task:taskListDtos
) {
if(task.getRecordId().longValue() != dto.getId().longValue()){
nextRecordId = task.getRecordId();
break;
}
}
}
return r.put("recordId", nextRecordId)//跳转下一个要处理的绩效
.put("time", freeTime);//多少秒之后跳转
}
//下面更新指标记录
if(inserts.size() > 0){
resultDetailService.saveBatch(inserts);
}
if(updates.size() > 0){
resultDetailService.updateBatchById(updates);
}
return r;
//下面更新评分记录
if(insertScores.size() > 0){
resultScoreService.saveBatch(insertScores);
}
if(updateScores.size() > 0){
resultScoreService.updateBatchById(updateScores);
}
resultRecordService.updateResultRecordById(resultRecord);
String commentId = null;
if(dto.getSave() == null){//非暂存
//修改评论信息
log.info("修改了多少个指标{}", editResultDetails.size());
editResultDetails.addAll(resultDetailService.selectNotNoticeResultDetailByRecordId(dto.getId())) ;
log.info("可能需要写入评论的内容条数{}", editResultDetails.size());
//去重
mapDetails = editResultDetails.stream().collect(Collectors.toMap(ResultDetail::getId, Function.identity(), (e, r) -> e));
editResultDetails = mapDetails.values().stream().collect(Collectors.toList());
if(!isSetKeyResult){
log.info("实际需要写入评论的内容条数{}", editResultDetails.size());
if(editResultDetails.size() > 0){
updates.addAll(inserts);
mapDetails = updates.stream().collect(Collectors.toMap(ResultDetail::getId, Function.identity(), (e, r) -> e));
String commandValue = "";
int commandIndex = 1;
for (ResultDetail resultDetail1:editResultDetails
) {
log.info("修改的对象为{}", resultDetail1);
if(resultDetail1.getIsDelete() != null && resultDetail1.getIsDelete().intValue() == 1){
commandValue += (commandIndex + "(删除) 指标" + resultDetail1.getTarget() + "\n");
commandIndex++;
resultDetail1.setIsBack(1);
}else if(resultDetail1.getIsBack().intValue() == 3){
commandValue += (commandIndex + "(新增) 指标" + resultDetail1.getTarget() + "\n");
commandIndex++;
resultDetail1.setIsBack(0);
}else{
ResultDetail resultDetail = mapDetails.get(resultDetail1.getBackId());
if(resultDetail != null){
log.info("修改后的对象为{}", resultDetail1);
boolean isUp = false;
String value = "";
String heard = "";
if(!resultDetail.getTarget().equals(resultDetail1.getTarget())){
//打上标识
value += ("(修改) 名称:" +
resultDetail1.getTarget()+ " \n(为)\n" + resultDetail.getTarget() + "\n");
isUp = true;
}else{
heard = "指标:" + resultDetail1.getTarget() + "\n";
}
if(!resultDetail.getKeyResult().equals(resultDetail1.getKeyResult())){
//打上标识
value += ("(修改) 考核标准:" +
resultDetail1.getKeyResult() + "\n(为)\n" + resultDetail.getKeyResult() + "\n");
isUp = true;
}
if(!resultDetail.getCheckWeight().equals(resultDetail1.getCheckWeight())){
//打上标识
value += ("(修改) 权重:" +
resultDetail1.getCheckWeight().multiply(new BigDecimal(100)).intValue() + "%\n(为)\n"
+ resultDetail.getCheckWeight().multiply(new BigDecimal(100)).intValue() +
"%\n");
isUp = true;
}
if(isUp){
commandValue += (commandIndex + "" + heard + value);
commandIndex++;
resultDetail1.setIsBack(1);
}
}
}
}
if(commandValue.length() > 0){
log.info("需要写入评论,具体呢容为{}", commandValue);
ResultComment resultComment = new ResultComment();//resultCommentService.selectResultCommentById(dto.getCommentId());
log.info("resultComment的值{}", resultComment);
resultComment.setOptDesc("修改了目标");
resultComment.setComment(commandValue);
resultCommentService.insertResultComment(resultComment);//.updateResultCommentCommentById(dto.getCommentId(), commandValue);
commentId = resultComment.getId().toString();
}
}
}else{
for (ResultDetail resultDetail1:editResultDetails
) {
if(resultDetail1.getIsBack().intValue() == 3){
resultDetail1.setIsBack(0);
}else{
resultDetail1.setIsBack(1);
}
}
}
resultDetailService.updateBatchById(editResultDetails);
}
return R.ok().put("commentId", commentId);
}
/**

View File

@ -14,6 +14,7 @@ import com.lz.modules.app.resp.OwnResultResp;
import com.lz.modules.app.utils.t.TwoTuple;
import com.lz.modules.flow.entity.Flow;
import com.lz.modules.flow.entity.FlowApprovalRole;
import com.lz.modules.flow.model.ResultRecordDetailDto;
import com.lz.modules.flow.model.StaffRoleDto;
import com.lz.modules.performance.req.AssessDetailReq;
import com.lz.modules.performance.req.OwnResultReq;
@ -136,4 +137,5 @@ public interface ResultRecordService extends IService<ResultRecord> {
List<Long> selectStaffIdsByFlowProcess(List<Integer> flowProcess);
R saveDetail(Long userId, ResultRecordDetailDto dto);
}

View File

@ -30,8 +30,11 @@ import com.lz.modules.flow.enums.FlowRecordEnum;
import com.lz.modules.flow.model.*;
import com.lz.modules.flow.service.*;
import com.lz.modules.job.business.DingtalkBusiness;
import com.lz.modules.performance.dto.ResultTaskDto;
import com.lz.modules.performance.req.OwnResultReq;
import com.lz.modules.performance.req.ResultUpdateTaskReq;
import com.lz.modules.performance.res.ChartStatistical;
import com.lz.modules.performance.service.ResultTaskService;
import com.lz.modules.sys.dao.app.ResultRecordMapper;
import com.lz.modules.sys.entity.SysUserEntity;
import com.lz.modules.sys.entity.app.ResultComment;
@ -51,6 +54,7 @@ import java.math.BigDecimal;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
@ -143,6 +147,9 @@ public class ResultRecordServiceImpl extends ServiceImpl<ResultRecordMapper, Res
@Autowired
private ResultScoreService resultScoreService;
@Autowired
private ResultTaskService resultTaskService;
@Override
public ResultRecord selectResultRecordById(Long id) {
@ -1548,4 +1555,277 @@ public class ResultRecordServiceImpl extends ServiceImpl<ResultRecordMapper, Res
public List<Long> selectStaffIdsByFlowProcess(List<Integer> flowProcess) {
return resultRecordMapper.selectStaffIdsByFlowProcess(flowProcess);
}
@Override
public R saveDetail(Long userId,ResultRecordDetailDto dto){
ResultRecord resultRecord = resultRecordService.selectResultRecordById(dto.getId());
resultRecord.setAllScore(resultRecord.getLastScore());
List<ResultDetail> inserts = new ArrayList<>();
List<ResultDetail> updates = new ArrayList<>();
List<ResultScore> insertScores = new ArrayList<>();
List<ResultScore> updateScores = new ArrayList<>();
List<ResultDetail> resultDetails = resultDetailService.selectByRecordId(dto.getId());
Map<Long, ResultDetail> mapDetails =
resultDetails.stream().collect(Collectors.toMap(ResultDetail::getId, Function.identity(), (e, r) -> e));
List<ResultDetail> updateResultDetails = new ArrayList<>();
List<ResultDetail> editResultDetails = new ArrayList<>();//涉及到修改的指标保存方便后面生成修改记录
//获取当前绩效的节点
boolean isSetKeyResult = false;
List<FlowRecord> flowRecords = flowRecordService.selectFlowRecordByRecordIdStatus(dto.getId(), 2);
if(flowRecords.size() > 0){
if(flowRecords.get(0).getFlowProcess().intValue() < 1){
log.info("制定目标中");
isSetKeyResult = true;
}
}
for (ResultRecortModelDto model:dto.getRecortModelDtos()
) {
int index = 0;
BigDecimal weight = BigDecimal.ZERO;
/*if(model.getMaxCount() != null && model.getDetailDtos().size() > model.getMaxCount().intValue()){
return R.error(model.getName() + "维度指标数量不能超过" + model.getMaxCount());
}*/
for (ResultDetailDto detailDto:model.getDetailDtos()
) {//排序
ResultDetail resultDetail = new ResultDetail();
BeanUtils.copyProperties(detailDto, resultDetail);
if(!isSetKeyResult){
if(resultDetail.getIsDelete() != null && resultDetail.getIsDelete().intValue() == 1){//被删除了
log.info("指标被删除了");
resultDetail.setIsBack(2);
resultDetail.setBackId(resultDetail.getId());
updateResultDetails.add(resultDetail);
editResultDetails.add(resultDetail);
}else if(resultDetail.getId() == null){
resultDetail.setIsBack(3);//新增
editResultDetails.add(resultDetail);//插入数据库之后会生成id
log.info("新增指标");
}else {
if(resultDetail.getId() != null && mapDetails.containsKey(resultDetail.getId())){
//这里判断是否有更新或者删除
boolean isUp = false;
ResultDetail resultDetail1 = null;
resultDetail1 = mapDetails.get(resultDetail.getId());
if(!resultDetail.getTarget().equals(resultDetail1.getTarget())){
//打上标识
log.info("修改名称");
isUp = true;
}
if(!resultDetail.getKeyResult().equals(resultDetail1.getKeyResult())){
//打上标识
log.info("修改关键结果");
isUp = true;
}
if(!resultDetail.getCheckWeight().equals(resultDetail1.getCheckWeight())){
//打上标识
log.info("修改权重");
isUp = true;
}
if(isUp){
resultDetail1.setId(null);
resultDetail1.setIsBack(2);
resultDetail1.setBackId(resultDetail.getId());
inserts.add(resultDetail1);
editResultDetails.add(resultDetail1);//插入数据库之后会生成id
}
}
}
}
resultDetail.setPriority(index);
index++;
if(resultDetail.getId() != null){
updates.add(resultDetail);
}else{
resultDetail.setStaffId(resultRecord.getStaffId());
resultDetail.setRecordId(resultRecord.getId());
resultDetail.setType(model.getType());
resultDetail.setModelId(model.getId());
resultDetailService.insertResultDetail(resultDetail);
//inserts.add(resultDetail);
}
if(resultDetail.getIsDelete() != null && resultDetail.getIsDelete().intValue() == 1){
//删除任务
resultTaskService.deleteResultTasksByDetailId(resultDetail.getId());
}else{
//更新任务
if(userId.longValue() == resultRecord.getStaffId().longValue() &&
detailDto.getTaskDtos() != null && detailDto.getTaskDtos().size() > 0){//本人编辑任务才允许提交
log.info("任务个数{}", detailDto.getTaskDtos().size());
int orderBy = 0;
for (ResultTaskDto taskDto:detailDto.getTaskDtos()
) {
if(taskDto.getId() != null && taskDto.getIsDelete() != null && taskDto.getIsDelete().intValue() == 1){
//删除
resultTaskService.deleteTask(taskDto.getId(),userId);
}else{
ResultUpdateTaskReq taskReq = new ResultUpdateTaskReq();
taskReq.setDetailId(resultDetail.getId());
taskReq.setTaskId(taskDto.getId());
taskReq.setName(taskDto.getName());
taskReq.setOrderBy(orderBy);
taskReq.setProcessRate(BigDecimal.valueOf(taskDto.getProcessRate()));
R r = resultTaskService.saveOrUpdateResultTask(taskReq,userId);
if((int)r.get("code") != 200){
throw new RRException((String)r.get("msg"));
}
orderBy++;
}
}
}
// }
//if(resultDetail.getIsDelete() == null || resultDetail.getIsDelete().intValue() == 0){
BigDecimal score = BigDecimal.ZERO;
if(detailDto.getScoreDtos() != null){
for (ResultScoreDto scoreDto:detailDto.getScoreDtos()
) {
//计算得分
ResultScore resultScore = new ResultScore();
BeanUtils.copyProperties(scoreDto, resultScore);
if(scoreDto.getAcquireScore() != null){
score = score.add(scoreDto.getAcquireScore().multiply(scoreDto.getWeight()));
}
if(resultScore.getId() == null){
insertScores.add(resultScore);
}else{
updateScores.add(resultScore);
}
resultScore.setDetailId(detailDto.getId());
}
resultDetail.setAcquireScore(score);
weight = weight.add(resultDetail.getCheckWeight());
}
}
}
}
//下面更新指标记录
if(inserts.size() > 0){
resultDetailService.saveBatch(inserts);
}
if(updates.size() > 0){
resultDetailService.updateBatchById(updates);
}
//下面更新评分记录
if(insertScores.size() > 0){
resultScoreService.saveBatch(insertScores);
}
if(updateScores.size() > 0){
resultScoreService.updateBatchById(updateScores);
}
resultRecordService.updateResultRecordById(resultRecord);
String commentId = null;
if(dto.getSave() == null){//非暂存
//修改评论信息
log.info("修改了多少个指标{}", editResultDetails.size());
editResultDetails.addAll(resultDetailService.selectNotNoticeResultDetailByRecordId(dto.getId())) ;
log.info("可能需要写入评论的内容条数{}", editResultDetails.size());
//去重
mapDetails = editResultDetails.stream().collect(Collectors.toMap(ResultDetail::getId, Function.identity(), (e, r) -> e));
editResultDetails = mapDetails.values().stream().collect(Collectors.toList());
if(!isSetKeyResult){
log.info("实际需要写入评论的内容条数{}", editResultDetails.size());
if(editResultDetails.size() > 0){
updates.addAll(inserts);
mapDetails = updates.stream().collect(Collectors.toMap(ResultDetail::getId, Function.identity(), (e, r) -> e));
String commandValue = "";
int commandIndex = 1;
for (ResultDetail resultDetail1:editResultDetails
) {
log.info("修改的对象为{}", resultDetail1);
if(resultDetail1.getIsDelete() != null && resultDetail1.getIsDelete().intValue() == 1){
commandValue += (commandIndex + "(删除) 指标" + resultDetail1.getTarget() + "\n");
commandIndex++;
resultDetail1.setIsBack(1);
}else if(resultDetail1.getIsBack().intValue() == 3){
commandValue += (commandIndex + "(新增) 指标" + resultDetail1.getTarget() + "\n");
commandIndex++;
resultDetail1.setIsBack(0);
}else{
ResultDetail resultDetail = mapDetails.get(resultDetail1.getBackId());
if(resultDetail != null){
log.info("修改后的对象为{}", resultDetail1);
boolean isUp = false;
String value = "";
String heard = "";
if(!resultDetail.getTarget().equals(resultDetail1.getTarget())){
//打上标识
value += ("(修改) 名称:" +
resultDetail1.getTarget()+ " \n(为)\n" + resultDetail.getTarget() + "\n");
isUp = true;
}else{
heard = "指标:" + resultDetail1.getTarget() + "\n";
}
if(!resultDetail.getKeyResult().equals(resultDetail1.getKeyResult())){
//打上标识
value += ("(修改) 考核标准:" +
resultDetail1.getKeyResult() + "\n(为)\n" + resultDetail.getKeyResult() + "\n");
isUp = true;
}
if(!resultDetail.getCheckWeight().equals(resultDetail1.getCheckWeight())){
//打上标识
value += ("(修改) 权重:" +
resultDetail1.getCheckWeight().multiply(new BigDecimal(100)).intValue() + "%\n(为)\n"
+ resultDetail.getCheckWeight().multiply(new BigDecimal(100)).intValue() +
"%\n");
isUp = true;
}
if(isUp){
commandValue += (commandIndex + "" + heard + value);
commandIndex++;
resultDetail1.setIsBack(1);
}
}
}
}
if(commandValue.length() > 0){
log.info("需要写入评论,具体呢容为{}", commandValue);
ResultComment resultComment = new ResultComment();//resultCommentService.selectResultCommentById(dto.getCommentId());
log.info("resultComment的值{}", resultComment);
resultComment.setOptDesc("修改了目标");
resultComment.setComment(commandValue);
resultCommentService.insertResultComment(resultComment);//.updateResultCommentCommentById(dto.getCommentId(), commandValue);
commentId = resultComment.getId().toString();
}
}
}else{
for (ResultDetail resultDetail1:editResultDetails
) {
if(resultDetail1.getIsBack().intValue() == 3){
resultDetail1.setIsBack(0);
}else{
resultDetail1.setIsBack(1);
}
}
}
resultDetailService.updateBatchById(editResultDetails);
}
return R.ok().put("commentId", commentId);
}
}

View File

@ -0,0 +1,4 @@
package com.lz.mysql;
public class AttributeDes extends Describer{
}

View File

@ -1,7 +1,155 @@
package com.lz.mysql;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
public class ControlScanner {
private String filePath;//文件地址
static final String[] notesSym = {"/*", "*/", "//", "\\n"};//注释符号成对出现偶数为起始符号奇数为结束符号
private String packageName;//包名
private String name;//类名
List<String> importList = new ArrayList<>();//引入的包名
List<FunctionDes> functionDesList = new ArrayList<>();//方法对象集合
List<AttributeDes> attributeDesList = new ArrayList<>();//属性对象集合
public void startScanner(String filePath){
File file = new File(filePath);
if(file.exists()){
//
try {
BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
String strLine = null;
int lineCount = 0;
while(null != (strLine = bufferedReader.readLine())){
strLine = pretreatment(strLine);
CheckType checkType = checkLineStart(strLine);
strLine = strLine.substring(checkType.getStart());
checkLineEnd(checkType, strLine);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
//文件异常
} catch (IOException e) {
e.printStackTrace();
//读取文件失败
}
}
}
private String pretreatment(String strLine){
strLine = strLine.replace("\t", " ");
strLine = removeMoreSpace(strLine);
strLine = strLine.replace("\r\n", "\n");
return strLine;
}
private String removeMoreSpace(String strLine){
int start = 0;
while(strLine.charAt(start) == ' '){
start++;
}
if(start > 0){
strLine = strLine.substring(start);
}
String newLine;
return strLine;
}
private CheckType checkLineStart(String strLine){
CheckType checkType = new CheckType();
switch (strLine.charAt(0)){
case '/':// /* //
if(strLine.charAt(1) == '/'){
checkType.setType(0);
//checkType.setEnd(true);
}else if(strLine.charAt(1) == '*'){
checkType.setType(1);
/*if(strLine.length() > 3 &&
strLine.charAt(strLine.length() - 1) == '/' &&
strLine.charAt(strLine.length() - 2) == '*'){
checkType.setEnd(true);
}*/
}
checkType.setStart(2);
break;
case 'i'://import
if(strLine.startsWith("import ")){
checkType.setType(2);
checkType.setStart(7);
}
break;
case 'p':// public private proteced package
if(strLine.startsWith("public ")){
checkType.setType(3);
checkType.setStart(7);
}else if(strLine.startsWith("private ")){
checkType.setType(4);
checkType.setStart(8);
}else if(strLine.startsWith("proteced ")){
checkType.setType(5);
checkType.setStart(9);
}else if(strLine.startsWith("package ")){
checkType.setType(6);
checkType.setStart(8);
}
break;
default:
checkType.setType(50);
checkType.setStart(0);
break;
}
/*if((type == 0 || type > 2)
&& strLine.charAt(strLine.length() - 1) == ';'){
checkType.setEnd(true);
}*/
return checkType;
}
private CheckType checkLineEnd(CheckType checkType, String strLine){
if(checkType.getType() > 1){//处理非注释代码中的多余的空格替换成一个引号内的不处理
}
return checkType;
}
public class CheckType{
//1// 2/* 3import 4public 5private 6proteced 7package 50未找到关键字
private int type;
private int start;
private boolean isEnd;//一行代码是否读取完毕
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public int getStart() {
return start;
}
public void setStart(int start) {
this.start = start;
}
public boolean isEnd() {
return isEnd;
}
public void setEnd(boolean end) {
isEnd = end;
}
}
}

View File

@ -0,0 +1,11 @@
package com.lz.mysql;
public class Describer {
protected String auther;//作者
protected String describe;//描述说明
protected String remark;//备注
protected String name;//方法名称或者属性名称
protected String date;//日期
protected int viewType;//0 public 1 protected 2 private;
protected JavaType javaType;//类型属性的类型方法返回的类型
}

View File

@ -0,0 +1,9 @@
package com.lz.mysql;
import java.util.ArrayList;
import java.util.List;
public class FunctionDes extends Describer{
private List<ReqParamDes> params = new ArrayList<>();//参数
}

View File

@ -0,0 +1,7 @@
package com.lz.mysql;
public class JavaType {
private String name;//type名称
private String packageName;//包名路径
private int custom;//0自定义 1sdk自带
}

View File

@ -0,0 +1,6 @@
package com.lz.mysql;
public class ReqParamDes extends AttributeDes{
private int reqType;//参数请求类型0 get 1 post
private int mustReq;//0非必传1必传
}