Commit c8c89bc8 by chenweisong

更新

parent 3f59594c
package com.keymobile.rest.common.bean;
import com.keymobile.rest.common.constant.ApiConstant;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import java.io.Serializable;
@Data
@Builder
@AllArgsConstructor
public class ApiResponse<T> implements Serializable {
private int code;
private String msg;
private T data;
public static ApiResponse ok() {
return ApiResponse.builder().code(ApiConstant.SUCCEED_CODE).msg(ApiConstant.SUCCEED).build();
}
public static <T> ApiResponse ok(T data) {
return ApiResponse.builder().code(ApiConstant.SUCCEED_CODE).msg(ApiConstant.SUCCEED).data(data).build();
}
public static ApiResponse fail() {
return ApiResponse.builder().code(ApiConstant.FAILED_CODE).msg(ApiConstant.FAILED).build();
}
public static ApiResponse fail(int code, String msg) {
return ApiResponse.builder().code(code).msg(msg).build();
}
}
package com.keymobile.rest.conf;
package com.keymobile.rest.common.conf;
import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Value;
......
package com.keymobile.rest.common.constant;
public interface ApiConstant {
int SUCCEED_CODE = 200;
int FAILED_CODE = 500;
String SUCCEED = "成功";
String FAILED = "失败";
String ERROR = "系统错误";
String UNAUTHORIZED = "未授权";
String PARAM_ERROR = "参数错误";
}
......@@ -2,18 +2,18 @@ package com.keymobile.rest.ctrl;
import com.google.common.collect.ImmutableMap;
import com.keymobile.activiti.service.formService.FormExcelFileService;
import com.keymobile.activiti.utils.DateUtil;
import com.keymobile.rest.common.bean.ApiResponse;
import com.keymobile.rest.model.Excel;
import com.keymobile.rest.model.RecordInfo;
import com.keymobile.rest.model.Task;
import com.keymobile.rest.model.Job;
import com.keymobile.rest.model.User;
import com.keymobile.rest.service.*;
import com.keymobile.rest.service.TaskService;
import com.keymobile.rest.vo.DataVo;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import com.keymobile.rest.vo.ExcelForm;
import com.keymobile.rest.vo.RecordDataForm;
import com.keymobile.rest.vo.JobForm;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.activiti.engine.*;
import org.activiti.engine.TaskService;
import org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.repository.ProcessDefinition;
......@@ -21,12 +21,8 @@ import org.activiti.engine.runtime.ProcessInstance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.sql.Timestamp;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
......@@ -37,7 +33,7 @@ import java.util.stream.Collectors;
public class IndexCtrl {
@Autowired
private TaskService taskService;
private JobService jobService;
@Autowired
private ExcelService excelService;
@Autowired
......@@ -46,13 +42,12 @@ public class IndexCtrl {
private RecordInfoService recordInfoService;
@Autowired
private UserService userService;
@Autowired
private RepositoryService repositoryService;
@Autowired
private RuntimeService runtimeService;
@Autowired
private org.activiti.engine.TaskService engineTaskService;
private TaskService taskService;
@Autowired
private HistoryService historyService;
@Autowired
......@@ -65,81 +60,55 @@ public class IndexCtrl {
@ApiOperation(value = "获取首页收数列表")
@PostMapping(value = "/task/list")
public Map getTaskList(@RequestParam Integer pageNo, @RequestParam Integer pageSize, @RequestParam(required = false) String name) {
Page<Task> taskList;
public ApiResponse getTaskList(@RequestParam Integer pageNo, @RequestParam Integer pageSize, @RequestParam(required = false) @ApiParam(name = "name", value = "收数名称") String name) {
Page<Job> taskList;
String orderBy = "descending"; //
String propBy = "id"; // groupBy
if (name != null) {
taskList = taskService.findAllByName(name, pageNo, pageSize, orderBy, propBy);
taskList = jobService.findAllByName(name, pageNo, pageSize, orderBy, propBy);
} else {
taskList = taskService.findAll(pageNo, pageSize, orderBy, propBy);
taskList = jobService.findAll(pageNo, pageSize, orderBy, propBy);
}
return ImmutableMap.of("code", 200, "data", ImmutableMap.of("list", taskList.getContent(), "total", taskList.getTotalElements()));
return ApiResponse.ok(ImmutableMap.of("list", taskList.getContent(), "total", taskList.getTotalElements()));
}
@ApiOperation(value = "查看收数")
@PostMapping(value = "/task/get")
public Map get(@RequestParam int id) {
Task task = taskService.get(id);
return ImmutableMap.of("code", 200, "data", task);
public ApiResponse get(@RequestParam @ApiParam(name = "id", value = "收数id") long id) {
Job job = jobService.get(id);
return ApiResponse.ok(job);
}
@ApiOperation(value = "新建收数")
@ApiImplicitParams({
@ApiImplicitParam(name = "name", value = "收数名称", dataType = "String", required = true, paramType = "query"),
@ApiImplicitParam(name = "type", value = "收数类型 1为手动发起 2为自动发起", dataType = "Integer", required = true, paramType = "query"),
@ApiImplicitParam(name = "startAt", value = "自动发起需要提写的时间", dataType = "String", paramType = "query"),
@ApiImplicitParam(name = "userIds", value = "补录人员ids 用逗号隔开", dataType = "String", paramType = "query"),
@ApiImplicitParam(name = "excelIds", value = "新建的模板ids 用逗号隔开", dataType = "String", paramType = "query"),
})
@PostMapping(value = "/task/create")
public Map createTask(@RequestParam String name, @RequestParam Integer type,
@RequestParam(required = false) String startAt, @RequestParam(required = false) String userIds, @RequestParam(required = false) String excelIds) {
Task task = new Task();
Timestamp now = Timestamp.valueOf(DateUtil.getDateTime());
task.setCreateAt(now);
task.setStatus(Task.STATUS_UNRELEASED);
task.setJudge(Task.JUDGE_NEED);
task.setName(name);
task.setType(type);
if (type == Task.TYPE_AUTO) {
task.setStartAt(Timestamp.valueOf(startAt));
}
task.setUser(userService.getManager());
long id = taskService.save(task);
public ApiResponse createTask(@RequestBody JobForm form) {
Job job = jobService.save(form);
// 新建excel实例
if (excelIds != null) {
String[] excelIdArr = excelIds.split(",");
List<Long> ids = Arrays.asList(excelIdArr).stream().map(Long::parseLong).collect(Collectors.toList());
List<Excel> excelList = excelService.findAllByIdIn(ids);
if (form.getExcelIds() != null) {
String[] excelIds = form.getExcelIds().split(",");
List<Long> excelIdList = Arrays.asList(excelIds).stream().map(Long::parseLong).collect(Collectors.toList());
List<Excel> excelList = excelService.findAllByIdIn(excelIdList);
excelList.forEach(excel -> {
excel.setTask(task);
excel.setJob(job);
// 新建补录人员任务关联
if (userIds != null) {
String[] userStrIdArr = userIds.split(",");
List<Long> userIdList = Arrays.asList(userStrIdArr).stream().map(Long::parseLong).collect(Collectors.toList());
if (form.getUserIds() != null) {
String[] userIds = form.getUserIds().split(",");
List<Long> userIdList = Arrays.asList(userIds).stream().map(Long::parseLong).collect(Collectors.toList());
List<User> userList = userService.findAllByIdIn(userIdList);
userList.forEach(user -> {
RecordInfo info = new RecordInfo();
info.setUser(user);
info.setExcel(excel);
info.setCreateAt(now);
recordInfoService.save(info);
recordInfoService.save(user, excel);
});
}
});
excelService.saveAll(excelList);
}
return ImmutableMap.of("code", 200, "data", id);
return ApiResponse.ok();
}
@ApiOperation(value = "手动发起收数")
@PostMapping(value = "/task/start")
public Map startTask(@RequestParam int id) {
Task task = taskService.get(id);
public ApiResponse startTask(@RequestParam long id) {
Job job = jobService.get(id);
// 启动流程
// 获取流的引擎
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
......@@ -161,57 +130,50 @@ public class IndexCtrl {
//审批任务
processEngine.getTaskService().complete(resultTask.getId());
return ImmutableMap.of("code", 200);
return ApiResponse.ok();
}
@ApiOperation(value = "审核通过收数")
@PostMapping(value = "/task/pass")
public Map passTask(@RequestParam int id) {
return ImmutableMap.of("code", 200);
public ApiResponse passTask(@RequestParam long id) {
return ApiResponse.ok();
}
@ApiOperation(value = "审核驳回收数")
@PostMapping(value = "/task/reject")
public Map rejectTask(@RequestParam int id) {
return ImmutableMap.of("code", 200);
public ApiResponse rejectTask(@RequestParam long id) {
return ApiResponse.ok();
}
@ApiOperation(value = "查看当前收数进度")
@PostMapping(value = "/task/saveData")
public Map viewTaskProcess(@RequestParam int id) {
return ImmutableMap.of("code", 200);
public ApiResponse viewTaskProcess(@RequestParam long id) {
return ApiResponse.ok();
}
@ApiOperation(value = "获取补录人员列表")
@PostMapping(value = "/user/list")
public Map getUserList() {
public ApiResponse getUserList() {
List<User> userList = userService.findAllByRole(User.ROLE_NORMAL);
return ImmutableMap.of("code", 200, "data", userList);
return ApiResponse.ok(userList);
}
@ApiOperation(value = "新建模板")
@PostMapping(value = "/excel/create")
public Map saveExcel(@RequestParam String config, @RequestParam(required = false) String desc) {
Excel excel = new Excel();
excel.setConfig(config);
excel.setDesc(config);
long id = excelService.save(excel);
return ImmutableMap.of("code", 200, "data", id);
public ApiResponse saveExcel(@RequestBody ExcelForm form) {
Excel excel = excelService.save(form);
return ApiResponse.ok();
}
@ApiOperation(value = "填写补录数据")
@PostMapping(value = "/excel/saveData")
public Map saveRecordData(DataVo vo) {
// Excel excel = new Excel();
// excel.setConfig(config);
// excel.setDesc(config);
// long id = excelService.save(excel);
// recordDataService.save(vo);
return ImmutableMap.of("code", 200);
public ApiResponse saveRecordData(RecordDataForm form) {
return ApiResponse.ok();
}
......
package com.keymobile.rest.dao;
import com.keymobile.rest.model.Task;
import com.keymobile.rest.model.Job;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
public interface TaskDao extends JpaRepository<Task, Long> {
public interface JobDao extends JpaRepository<Job, Long> {
Page<Task> findAll(Pageable pageable);
Page<Job> findAll(Pageable pageable);
Page<Task> findAllByNameLike(String valueOf, Pageable pageable);
Page<Job> findAllByNameLike(String valueOf, Pageable pageable);
}
......@@ -36,7 +36,7 @@ public class Excel implements Serializable {
// 级别游离关联, 当加载的时候急加载这个对象
@ManyToOne(cascade = CascadeType.DETACH, fetch = FetchType.EAGER)
private Task task;
private Job job;
@OneToMany
@JsonIgnore
......
......@@ -20,7 +20,8 @@ import java.util.List;
@AllArgsConstructor // 自动生成全参数构造函数。
@Data
@Entity
public class Task implements Serializable {
@Table(name = "task")
public class Job implements Serializable {
public static int TYPE_AUTO = 2;
public static int TYPE_MANUAL = 1;
......
......@@ -13,7 +13,6 @@ import java.io.Serializable;
@Entity
public class User implements Serializable {
public static int ROLE_NORMAL = 1;
public static int ROLE_JUDGE = 2;
public static int ROLE_MANAGER = 3;
......
......@@ -2,7 +2,7 @@ package com.keymobile.rest.service;
import com.keymobile.rest.dao.*;
import com.keymobile.rest.model.Excel;
import com.keymobile.rest.vo.ExcelVO;
import com.keymobile.rest.vo.ExcelForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -12,17 +12,14 @@ import java.util.List;
public class ExcelService {
@Autowired
private TaskDao taskDao;
@Autowired
private UserDao userDao;
@Autowired
private ExcelDao excelDao;
@Autowired
private RecordInfoDao recordInfoDao;
public long save(Excel excel) {
public Excel save(ExcelForm form) {
Excel excel = new Excel();
excel.setConfig(form.getConfig());
excel.setDesc(form.getDesc());
excelDao.save(excel);
return excel.getId();
return excel;
}
public List<Excel> findAllByIdIn(List<Long> ids) {
......
package com.keymobile.rest.service;
import com.keymobile.rest.dao.TaskDao;
import com.keymobile.rest.model.Task;
import com.keymobile.activiti.utils.DateUtil;
import com.keymobile.rest.dao.JobDao;
import com.keymobile.rest.model.Job;
import com.keymobile.rest.vo.JobForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
......@@ -9,39 +11,52 @@ import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
@Service("ApiTaskService")
public class TaskService {
import java.sql.Timestamp;
@Service
public class JobService {
@Autowired
private TaskDao taskDao;
private JobDao jobDao;
public Task get(long id) {
return taskDao.getOne(id);
public Job get(long id) {
return jobDao.getOne(id);
}
public long save(Task task) {
taskDao.save(task);
return task.getId();
public Job save(JobForm form) {
Job job = new Job();
Timestamp now = Timestamp.valueOf(DateUtil.getDateTime());
job.setCreateAt(now);
job.setStatus(Job.STATUS_UNRELEASED);
job.setJudge(Job.JUDGE_NEED);
job.setName(form.getName());
job.setType(form.getType());
if (form.getType() == Job.TYPE_AUTO) {
job.setStartAt(Timestamp.valueOf(form.getStartAt()));
}
job.setUser(form.getUser());
jobDao.save(job);
return job;
}
public Page<Task> findAll(int pageNo, int pageSize) {
public Page<Job> findAll(int pageNo, int pageSize) {
Pageable pageable = convert(pageNo, pageSize);
return taskDao.findAll(pageable);
return jobDao.findAll(pageable);
}
public Page<Task> findAllByName(String name, int pageNo, int pageSize) {
public Page<Job> findAllByName(String name, int pageNo, int pageSize) {
Pageable pageable = convert(pageNo, pageSize);
return taskDao.findAllByNameLike(("%" + name + "%"), pageable);
return jobDao.findAllByNameLike(("%" + name + "%"), pageable);
}
public Page<Task> findAll(int pageNo, int pageSize, String orderBy, String propBy) {
public Page<Job> findAll(int pageNo, int pageSize, String orderBy, String propBy) {
Pageable pageable = convert(pageNo, pageSize, orderBy, propBy);
return taskDao.findAll(pageable);
return jobDao.findAll(pageable);
}
public Page<Task> findAllByName(String name, int pageNo, int pageSize, String orderBy, String propBy) {
public Page<Job> findAllByName(String name, int pageNo, int pageSize, String orderBy, String propBy) {
Pageable pageable = convert(pageNo, pageSize, orderBy, propBy);
return taskDao.findAllByNameLike(("%" + name + "%"), pageable);
return jobDao.findAllByNameLike(("%" + name + "%"), pageable);
}
private Pageable convert(int pageNo, int pageSize, String orderBy, String propBy) {
......
......@@ -2,17 +2,19 @@ package com.keymobile.rest.service;
import com.keymobile.rest.dao.*;
import com.keymobile.rest.model.RecordData;
import com.keymobile.rest.vo.DataVo;
import com.keymobile.rest.vo.ExcelVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class RecordDataService {
@Autowired
private RecordDataDao recordDataDao;
public long save(RecordData recordData) {
recordDataDao.save(recordData);
return recordData.getId();
public RecordData save() {
RecordData data = new RecordData();
recordDataDao.save(data);
return data;
}
}
package com.keymobile.rest.service;
import com.keymobile.activiti.utils.DateUtil;
import com.keymobile.rest.dao.*;
import com.keymobile.rest.model.RecordData;
import com.keymobile.rest.model.Excel;
import com.keymobile.rest.model.RecordInfo;
import com.keymobile.rest.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.sql.Timestamp;
@Service
public class RecordInfoService {
@Autowired
private RecordInfoDao recordInfoDao;
public long save(RecordInfo recordInfo) {
recordInfoDao.save(recordInfo);
return recordInfo.getId();
public RecordInfo save(User user, Excel excel) {
RecordInfo info = new RecordInfo();
info.setExcel(excel);
info.setUser(user);
Timestamp now = Timestamp.valueOf(DateUtil.getDateTime());
info.setCreateAt(now);
recordInfoDao.save(info);
return info;
}
}
package com.keymobile.rest.vo;
public class DataVo {
}
package com.keymobile.rest.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.persistence.Column;
......@@ -9,11 +11,13 @@ import javax.persistence.Id;
import java.sql.Timestamp;
@Data
public class ExcelVO {
private long id;
@ApiModel
public class ExcelForm {
@ApiModelProperty(name = "config", value = "表格配置", required = true)
private String config;
@ApiModelProperty(name = "desc", value = "表格描述")
private String desc;
}
package com.keymobile.rest.vo;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.keymobile.rest.model.User;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
@ApiModel
public class JobForm {
@ApiModelProperty(required = true, name = "name", value = "收数名称")
private String name;
@ApiModelProperty(required = true, name = "type", value = "收数类型 1手动 2自动")
private int type;
@ApiModelProperty(name = "startAt", value = "自动发起需要提写的时间")
private String startAt;
@ApiModelProperty(name = "excelIds", value = "新建的模板ids, 用逗号隔开")
private String excelIds;
@ApiModelProperty(name = "excelIds", value = "补录人员ids, 用逗号隔开")
private String userIds;
@JsonIgnore
private User user;
}
package com.keymobile.rest.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@ApiModel
@Data
public class RecordDataForm {
}
package com.keymobile.rest.vo;
import lombok.Data;
import java.sql.Timestamp;
@Data
public class TaskVO {
private long id;
private String name;
private int type;
private int status;
private int judge;
private Timestamp startAt;
private long userId;
/*
新建文件id, 逗号隔开
*/
private String excelIds;
/*
补录人员id, 逗号隔开
*/
private String userIds;
}
......@@ -52,8 +52,8 @@ app:
active-process: RecordProcess.bpmn
swagger2:
# host: localhost:8110
host: 47.105.236.43/activiti
host: localhost:8110
# host: 47.105.236.43/activiti
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment