Skip to content

Commit

Permalink
update method
Browse files Browse the repository at this point in the history
  • Loading branch information
leelance committed Jan 3, 2017
1 parent 79505d7 commit 44a4f23
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.lance.activiti.mapper.process;

import java.util.List;
import java.util.Map;

import com.lance.activiti.model.process.ProcessDefineInfo;

Expand All @@ -9,7 +10,7 @@ public interface ProcessDefineMapper {
* 查询所有流程
* @return
*/
List<ProcessDefineInfo> findAll();
List<ProcessDefineInfo> findAll(Map<String, Object> params);

/**
* 保存对象
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.io.Serializable;
import java.util.Date;

import com.alibaba.fastjson.annotation.JSONField;

/**
* 定义流程
* @author Administrator
Expand All @@ -23,6 +25,7 @@ public class ProcessDefineInfo implements Serializable{
private String processFile;

/**创建时间*/
@JSONField(format="yyyy-MM-dd HH:mm:ss")
private Date createTime;

public int getId() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.lance.activiti.service.process;

import java.util.List;
import java.util.Map;

import com.lance.activiti.model.process.ProcessDefineInfo;

Expand All @@ -10,5 +11,23 @@ public interface ProcessDefineService {
* 查询所有定义的流程
* @return
*/
List<ProcessDefineInfo>findAll();
List<ProcessDefineInfo>findAll(Map<String, Object> params);

/**
* 保存方法
* @param info
*/
void save(ProcessDefineInfo info);

/**
* 更新方法
* @param info
*/
void update(ProcessDefineInfo info);

/**
* 删除流程定义
* @param id
*/
void delete(int id);
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package com.lance.activiti.service.process;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lance.activiti.common.exception.ServiceException;
import com.lance.activiti.mapper.process.ProcessDefineMapper;
import com.lance.activiti.model.process.ProcessDefineInfo;

@Service
public class ProcessDefineServiceImpl implements ProcessDefineService{
private final String BPMN_XML = ".bpmn20.xml";
@Autowired
private ProcessDefineMapper processDefineMapper;

Expand All @@ -18,7 +22,46 @@ public class ProcessDefineServiceImpl implements ProcessDefineService{
* @return
*/
@Override
public List<ProcessDefineInfo> findAll() {
return processDefineMapper.findAll();
public List<ProcessDefineInfo> findAll(Map<String, Object> params) {
return processDefineMapper.findAll(params);
}

/**
* 保存方法
* @param info
*/
@Override
public void save(ProcessDefineInfo info) {
if(StringUtils.isAnyBlank(info.getProcessName(), info.getProcessFile())) {
throw new ServiceException("流程文件名称或流程文件不能为空");
}

if(!StringUtils.endsWith(info.getProcessFile(), BPMN_XML)) {
throw new ServiceException("流程文件格式错误,以.bpmn20.xml结尾");
}

String processKey = StringUtils.substringBefore(info.getProcessFile(), BPMN_XML);
info.setProcessKey(processKey);
processDefineMapper.save(info);
}

/**
* 更新方法
* @param info
*/
@Override
public void update(ProcessDefineInfo info) {
String processKey = StringUtils.substringBefore(info.getProcessFile(), BPMN_XML);
info.setProcessKey(processKey);
processDefineMapper.update(info);
}

/**
* 删除流程定义
* @param id
*/
@Override
public void delete(int id) {
processDefineMapper.delete(id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lance.activiti.common.exception.ServiceException;
import com.lance.activiti.common.page.PageInfo;
import com.lance.activiti.common.result.ResultInfo;
import com.lance.activiti.model.process.ProcessDefineInfo;
import com.lance.activiti.service.process.ProcessDefineService;
import com.lance.activiti.utils.FastJsonUtils;
Expand Down Expand Up @@ -42,11 +45,46 @@ public String list(){
@ResponseBody
@RequestMapping(value="list", method=RequestMethod.POST)
public String list(@RequestParam Map<String, Object> params){
List<ProcessDefineInfo> list = processDefineService.findAll();
List<ProcessDefineInfo> list = processDefineService.findAll(params);
String page = params.get("page")+"";

PageInfo<ProcessDefineInfo> pageInfo = new PageInfo<>(list.size(), Integer.valueOf(page));
pageInfo.setRows(list);
return FastJsonUtils.toJson(pageInfo);
}

/**
* 保存方法
* @param info
* @return
*/
@ResponseBody
@RequestMapping(value="save", method=RequestMethod.POST, produces = "application/json; charset=UTF-8")
public String save(ProcessDefineInfo info){
try {
if(info.getId() == 0) {
processDefineService.save(info);
}else{
processDefineService.update(info);
}
} catch (ServiceException e) {
return ResultInfo.error(-1, e.getMessage());
}
return ResultInfo.success();
}

/**
* 删除流程定义
* 2016年10月9日下午1:52:20
*/
@ResponseBody
@RequestMapping(value="delete/{id}", produces = "application/json; charset=UTF-8")
public String delete(@PathVariable int id){
try {
processDefineService.delete(id);
} catch (ServiceException e) {
return ResultInfo.error(-1, e.getMessage());
}
return ResultInfo.success();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
<mapper namespace="com.lance.activiti.mapper.process.ProcessDefineMapper">

<!-- findAll -->
<select id="findAll" resultType="ProcessDefineInfo">
<select id="findAll" resultType="ProcessDefineInfo" parameterType="Map">
select *from t_process_define
<where>
<if test="processName!=null and processName!=''">
and process_name=#{processName}
</if>
</where>
</select>

<!-- findOne -->
Expand Down

0 comments on commit 44a4f23

Please sign in to comment.