Commit a240198c by chenweisong

更新

parent 367302b4
......@@ -34,7 +34,7 @@ public class IndexCtrl {
@Autowired
private RecordDataService recordDataService;
@Autowired
private RecordInfoService recordInfoService;
private JobInfoService jobInfoService;
@Autowired
private UserService userService;
@Autowired
......@@ -100,8 +100,7 @@ public class IndexCtrl {
public ApiResponse createTask(@RequestBody JobForm form) {
TwinkleValidator.notEmpty(form.getName(), "名称不能为空");
TwinkleValidator.notNull(form.getType(), "类型不能为空");
TwinkleValidator.notLessThan(form.getExcels().size(), 1, "补录模板不能为空");
TwinkleValidator.notEmpty(form.getUserIds(), "补录人不能为空");
TwinkleValidator.isFalse((form.getExcels() == null || form.getExcels().size() == 0), "补录模板不能为空");
// 创建人
User manager = userService.getManager();
form.setUser(manager);
......@@ -109,15 +108,16 @@ public class IndexCtrl {
// 新建excel实例
List<ExcelForm> excelFormList = form.getExcels();
excelFormList.forEach(excelForm -> {
TwinkleValidator.notEmpty(excelForm.getUserIds(), "补录人不能为空");
excelForm.setJob(job);
Excel excel = excelService.save(excelForm);
// 新建补录人员任务关联
String[] userIds = form.getUserIds().split(",");
String[] userIds = excelForm.getUserIds().split(",");
List<Long> userIdList = Arrays.asList(userIds).stream().map(Long::parseLong).collect(Collectors.toList());
List<User> userList = userService.findAllByIdIn(userIdList);
TwinkleValidator.notLessThan(userList.size(), 1, "补录人员不存在");
userList.forEach(user -> {
recordInfoService.save(user, excel);
jobInfoService.save(user, excel);
});
});
return ApiResponse.ok(job.getId());
......@@ -126,12 +126,14 @@ public class IndexCtrl {
@ApiOperation(value = "修改收数")
@PostMapping(value = "/task/update")
public ApiResponse updateTask(@RequestBody JobForm form) {
TwinkleValidator.notEmpty(form.getName(), "名称不能为空");
TwinkleValidator.notNull(form.getType(), "类型不能为空");
TwinkleValidator.notLessThan(form.getExcels().size(), 1, "补录模板不能为空");
TwinkleValidator.notNull(form.getId(), "收数id不能为空");
TwinkleValidator.isFalse((form.getId() == null && form.getId() <= 0), "收数id不能为空");
Job job = jobService.get(form.getId());
TwinkleValidator.notNull(job, "收数不存在");
int status = job.getStatus();
TwinkleValidator.isFalse(status != Job.STATUS_UNRELEASED, "收数已经发起");
TwinkleValidator.notEmpty(form.getName(), "名称不能为空");
TwinkleValidator.notNull(form.getType(), "类型不能为空");
TwinkleValidator.isFalse((form.getExcels() == null || form.getExcels().size() == 0), "补录模板不能为空");
job.setType(form.getType());
job.setRemark(form.getRemark());
job.setName(form.getName());
......@@ -145,7 +147,7 @@ public class IndexCtrl {
excel.setConfig(excelForm.getConfig());
excel.setRemark(excelForm.getRemark());
excel.setDataAt(excelForm.getDataAt());
recordInfoService.deleteAllByExcelId(excel.getId());
excelService.update(excel);
});
return ApiResponse.ok(job.getId());
}
......@@ -171,18 +173,18 @@ public class IndexCtrl {
//启动流程
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(processDefinition.getKey(), variables);
job.setProcessId(processInstance.getId());
jobService.update(job);
// 发起人把流程发送到下一个人
Task resultTask = taskService.createTaskQuery().processInstanceId(processInstance.getId()).
taskInvolvedUser(inputUser).singleResult();
// 根据收数查找需要填写的人 目前只支持一人
List<Excel> excelList = excelService.findAllByJobId(taskId);
List<Excel> excelList = job.getExcelList();
TwinkleValidator.notLessThan(excelList.size(), 1, "补录模板不存在");
Excel excel = excelList.get(0);
List<RecordInfo> recordInfoList = recordInfoService.findAllByExcelId(excel.getId());
TwinkleValidator.notLessThan(recordInfoList.size(), 1, "补录人员不存在");
taskService.complete(resultTask.getId(), ImmutableMap.of("userId", recordInfoList.get(0).getUser().getUsername()));
List<JobInfo> jobInfoList = jobInfoService.findAllByExcelId(excel.getId());
TwinkleValidator.notLessThan(jobInfoList.size(), 1, "补录人员不存在");
taskService.complete(resultTask.getId(), ImmutableMap.of("userId", jobInfoList.get(0).getUser().getUsername()));
return ApiResponse.ok();
}
......
package com.keymobile.rest.dao;
import com.keymobile.rest.model.RecordInfo;
import com.keymobile.rest.model.JobInfo;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
public interface RecordInfoDao extends JpaRepository<RecordInfo, Long> {
public interface JobInfoDao extends JpaRepository<JobInfo, Long> {
List<RecordInfo> findAllByExcelId(long eid);
List<JobInfo> findAllByExcelId(long eid);
List<RecordInfo> findAllByUserId(long uid);
List<JobInfo> findAllByUserId(long uid);
void deleteAllByExcelId(long eid);
......
......@@ -42,12 +42,7 @@ public class Excel implements Serializable {
@CreationTimestamp
private Timestamp createAt;
// 级别游离关联, 当加载的时候急加载这个对象
@ManyToOne(cascade = CascadeType.DETACH, fetch = FetchType.EAGER)
@ManyToOne(fetch = FetchType.LAZY)
@JsonIgnore
private Job job;
@OneToMany
@JsonIgnore
private List<RecordInfo> recordInfoList;
}
......@@ -30,9 +30,8 @@ public class Job implements Serializable {
public static int STATUS_UNRELEASED = 1;
public static int STATUS_COMPLETED = 3;
public static int JUDGE_NEED = 2;
public static int JUDGE_NO_NEED = 1;
public static int AUDIT_NEED = 1;
public static int AUDIT_NO_NEED = 2;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
......@@ -41,19 +40,18 @@ public class Job implements Serializable {
@Column(nullable = false)
private String name;
@Column
@Column(nullable = false)
private int type = 1;
@Column
@Column(nullable = false)
private int status = 1;
@Column
private int judge = 2;
@Column(nullable = false)
private int audit = 1;
@Column
private String remark;
@Column(name = "process_id")
private String processId;
......@@ -65,8 +63,8 @@ public class Job implements Serializable {
@CreationTimestamp
private Timestamp createAt;
@OneToMany(fetch = FetchType.EAGER)
@JoinTable(name = "excel", joinColumns = {@JoinColumn(name = "job_id")}, inverseJoinColumns = {@JoinColumn(name = "id")})
@OneToMany(fetch = FetchType.EAGER, mappedBy = "job")
private List<Excel> excelList;
@ManyToOne
......
......@@ -20,25 +20,23 @@ import java.util.List;
@AllArgsConstructor
@Data
@Entity
public class RecordInfo implements Serializable {
public class JobInfo implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column(name = "create_at", nullable = false, columnDefinition = "DATETIME COMMENT '创建时间'")
@CreationTimestamp
private Timestamp createAt;
@OneToMany
@JsonIgnore
List<RecordData> recordDataList;
@ManyToOne
@OneToOne
private Excel excel;
@OneToOne
private User user;
@OneToMany(mappedBy = "jobInfo", fetch = FetchType.EAGER)
List<RecordData> recordDataList;
}
package com.keymobile.rest.model;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.AllArgsConstructor;
import lombok.Data;
......@@ -24,12 +25,11 @@ public class RecordData implements Serializable {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column(name = "create_at", nullable = false, columnDefinition = "DATETIME COMMENT '创建时间'")
@Column(name = "create_at", nullable = false)
@CreationTimestamp
private Timestamp createAt;
@ManyToOne
private RecordInfo recordInfo;
@ManyToOne(fetch = FetchType.LAZY)
@JsonIgnore
private JobInfo jobInfo;
}
......@@ -33,6 +33,10 @@ public class ExcelService {
return excelDao.getOne(id);
}
public void update(Excel excel) {
excelDao.save(excel);
}
public List<Excel> findAllByIdIn(List<Long> ids) {
return excelDao.findAllByIdIn(ids);
}
......
......@@ -3,7 +3,7 @@ package com.keymobile.rest.service;
import com.keymobile.activiti.utils.DateUtil;
import com.keymobile.rest.dao.*;
import com.keymobile.rest.model.Excel;
import com.keymobile.rest.model.RecordInfo;
import com.keymobile.rest.model.JobInfo;
import com.keymobile.rest.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -12,30 +12,30 @@ import java.sql.Timestamp;
import java.util.List;
@Service
public class RecordInfoService {
public class JobInfoService {
@Autowired
private RecordInfoDao recordInfoDao;
private JobInfoDao jobInfoDao;
public RecordInfo save(User user, Excel excel) {
RecordInfo info = new RecordInfo();
public JobInfo save(User user, Excel excel) {
JobInfo info = new JobInfo();
info.setExcel(excel);
info.setUser(user);
Timestamp now = Timestamp.valueOf(DateUtil.getDateTime());
info.setCreateAt(now);
info = recordInfoDao.save(info);
info = jobInfoDao.save(info);
return info;
}
public List<RecordInfo> findAllByExcelId(long eid) {
return recordInfoDao.findAllByExcelId(eid);
public List<JobInfo> findAllByExcelId(long eid) {
return jobInfoDao.findAllByExcelId(eid);
}
public List<RecordInfo> findByUserId(long uid) {
return recordInfoDao.findAllByUserId(uid);
public List<JobInfo> findByUserId(long uid) {
return jobInfoDao.findAllByUserId(uid);
}
public void deleteAllByExcelId(long eid) {
recordInfoDao.deleteAllByExcelId(eid);
jobInfoDao.deleteAllByExcelId(eid);
}
}
......@@ -32,7 +32,7 @@ public class JobService {
Timestamp now = Timestamp.valueOf(DateUtil.getDateTime());
job.setCreateAt(now);
job.setStatus(Job.STATUS_UNRELEASED);
job.setJudge(Job.JUDGE_NEED);
job.setAudit(Job.AUDIT_NEED);
job.setName(form.getName());
job.setType(form.getType());
if (form.getType() == Job.TYPE_AUTO) {
......
......@@ -19,6 +19,9 @@ public class ExcelForm {
@ApiModelProperty(name = "id", value = "表格id,修改的时候需要用到")
private Long id;
@ApiModelProperty(required = true, name = "userIds", value = "补录人员ids, 用逗号隔开")
private String userIds;
@ApiModelProperty(name = "remark", value = "表格名称", required = true)
private String name;
......@@ -28,7 +31,7 @@ public class ExcelForm {
@ApiModelProperty(name = "remark", value = "表格描述")
private String remark;
@ApiModelProperty(name = "dataAt", value = "数据开始", required = true)
@ApiModelProperty(name = "dataAt", value = "数据开始", required = true, example = "1")
private Integer dataAt;
@JsonIgnore
......
......@@ -6,6 +6,7 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
@Data
......@@ -22,8 +23,8 @@ public class JobForm {
@ApiModelProperty(name = "remark", value = "收数描述")
private String remark;
@ApiModelProperty(required = true, name = "type", value = "收数类型 1手动 2自动")
private int type = 1;
@ApiModelProperty(required = true, name = "type", value = "收数类型 1手动 2自动", example = "1")
private Integer type;
// @ApiModelProperty(name = "startAt", value = "自动发起需要提写的时间")
@JsonIgnore
......@@ -32,9 +33,6 @@ public class JobForm {
@ApiModelProperty(required = true, name = "excels", value = "新建的模板配置数组")
private List<ExcelForm> excels;
@ApiModelProperty(required = true, name = "userIds", value = "补录人员ids, 用逗号隔开")
private String userIds;
@JsonIgnore
private User user;
}
......@@ -11,8 +11,8 @@ spring:
jpa:
show-sql: true
database-platform: org.hibernate.dialect.MySQL5Dialect
hibernate:
ddl-auto: update
# hibernate:
# ddl-auto: update
datasource:
url: jdbc:mysql://47.105.193.165:3306/test?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&serverTimezone=GMT%2B8
username: root
......@@ -52,7 +52,7 @@ app:
active-process: RecordStandardProcess.bpmn
swagger2:
host: localhost:8110
# host: localhost:8110
host: 47.105.236.43/activiti
......
......@@ -51,7 +51,7 @@ public class ProcessTest {
// .complete("32502");
}
@Test
// @Test
public void zhuguan() {
// try {
......
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