2015 5 月18
@At
public String test5(@Param("taskId") String taskId) {
Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
if (task == null)
return "null";
ProcessDefinitionEntity def = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService).getDeployedProcessDefinition(task.getProcessDefinitionId());
List activitiList = def.getActivities();
System.out.println("getTaskDefinitionKey:::" + task.getTaskDefinitionKey());
NutMap map = new NutMap();
int type = 0;
getTaskActivitys(task.getTaskDefinitionKey(), activitiList, type, map);
return Json.toJson(map);
}
public static List getTaskActivitys(String activityId, List activityList, int type, NutMap map) {
List activitiyIds = new ArrayList();
for (ActivityImpl activityImpl : activityList) {
String id = activityImpl.getId();
if (activityId.equals(id)) {
List outgoingTransitions = activityImpl.getOutgoingTransitions();//获取某节点所有线路
List list = new ArrayList();
for (PvmTransition tr : outgoingTransitions) {
NutMap map1 = new NutMap();
PvmActivity ac = tr.getDestination();//获取线路的终点节点
if (ac.getProperty("type").equals("userTask")) {
map.setv("type", type++);
map1.setv("id", ac.getId());
map1.setv("name", ac.getProperty("name"));
String conditionText=Strings.sNull(tr.getProperty("conditionText"));
if(!Strings.isEmpty(conditionText)){
map1.setv("conditionText",conditionText );
}
list.add(map1);
} else if (ac.getProperty("type").equals("exclusiveGateway")) {
getTaskActivitys(ac.getId(), activityList, type, map);
} else {
map.setv("type", type++);
break;
}
}
if (list.size() > 0)
map.addv("list", list);
break;
}
}
return activitiyIds;
}
2015 5 月12
通过配置文件实现(这个支持CXF spring注解)点这里
pom.xml
org.apache.cxf
cxf-api
2.7.15
org.apache.cxf
cxf-rt-frontend-jaxws
2.7.15
org.apache.cxf
cxf-rt-bindings-soap
2.7.15
org.apache.cxf
cxf-rt-transports-http
2.7.15
org.apache.cxf
cxf-rt-ws-security
2.7.15
web.xml
CXFServlet
com.auto.webservice.servlet.CXFServlet
1
CXFServlet
/webservice/*
CXFServlet.java:
package com.auto.webservice.servlet;
import org.apache.cxf.Bus;
import org.apache.cxf.BusFactory;
import org.apache.cxf.frontend.ServerFactoryBean;
import org.apache.cxf.transport.servlet.CXFNonSpringServlet;
import org.nutz.ioc.Ioc;
import org.nutz.lang.Strings;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.nutz.mvc.Mvcs;
import javax.jws.WebService;
import javax.servlet.ServletConfig;
import javax.xml.namespace.QName;
/**
* Created by wizzer on 15-4-10.
*/
@SuppressWarnings("serial")
public class CXFServlet extends CXFNonSpringServlet {
private final Log log = Logs.get();
@Override
protected void loadBus(ServletConfig sc) {
super.loadBus(sc);
//全局配置
Bus bus = getBus();
//添加白名单过滤器
bus.getInInterceptors().add(new IpAddressInInterceptor());
//使用全局配置
BusFactory.setDefaultBus(bus);
Ioc ioc = Mvcs.ctx().getDefaultIoc();
for (String name : ioc.getNames()) {
try {
Object obj = ioc.get(null, name);
if (!obj.getClass().getPackage().getName().equals("com.auto.webservice.server")) {
continue;
}
if (obj.getClass().getAnnotation(WebService.class) == null)
continue;
Class face = Class.forName(obj.getClass().getPackage().getName() + "." + Strings.upperFirst(name));
ServerFactoryBean serverFactoryBean = new ServerFactoryBean();
// 设置服务接口类
serverFactoryBean.setServiceClass(face);
// 服务请求路径
serverFactoryBean.setAddress("/" + name.substring(0, name.indexOf("Service")));
// 设置服务实现类
serverFactoryBean.setServiceBean(obj);
serverFactoryBean.setBindingId("http://schemas.xmlsoap.org/wsdl/soap12/");
serverFactoryBean.create();
} catch (Throwable e) {
}
}
}
}
接口类
WorkflowService.java
package com.auto.webservice.server;
import org.nutz.json.Json;
import javax.jws.WebService;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created by wizzer on 15-4-13.
*/
@WebService
public interface WorkflowService {
String start(String flowKey, String userId);//启动流程
}
实现类
WorkflowServiceImpl.java
package com.auto.webservice.server;
import org.activiti.engine.*;
import org.activiti.engine.form.FormProperty;
import org.activiti.engine.form.StartFormData;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.activiti.engine.task.TaskQuery;
import org.nutz.dao.Dao;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.json.Json;
import org.nutz.json.JsonFormat;
import org.nutz.lang.Strings;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.nutz.mvc.Mvcs;
import javax.jws.WebService;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created by wizzer on 15-4-13.
*/
@IocBean(name = "workflowService")
@WebService
public class WorkflowServiceImpl implements WorkflowService {
private final Log log = Logs.get();
@Inject
Dao dao;
@Inject
FormService formService;
@Inject
IdentityService identityService;
@Inject
RepositoryService repositoryService;
@Inject
RuntimeService runtimeService;
@Inject
TaskService taskService;
/**
* 启动一个流程
*
* @param flowKey 流程模型key
* @param userId 用户ID
* @return
*/
public String start(String flowKey, String userId) {
Map map = new HashMap();
try {
if (!Strings.isEmpty(userId)) {
identityService.setAuthenticatedUserId(userId);
}
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(flowKey);
map.put("errcode", 0);
map.put("errmsg", "");
map.put("processInstanceId", processInstance.getId());
} catch (Exception e) {
log.error("WebServcice启动流程出错", e);
map.put("errcode", 1);
map.put("errmsg", e.getMessage());
} finally {
identityService.setAuthenticatedUserId(null);
}
return Json.toJson(map, JsonFormat.compact());
}
}
2015 5 月7
在nutz filter作用域内才能Mvcs.getIoc()
其他情况:
Mvcs.ctx().getDefaultIoc().get(xxx.class)
2015 4 月27
首先值得一提的是,taskService.createTaskQuery().taskCandidateOrAssigned(userId) 方法有bug,不会调用重写的工厂类,请使用taskService.createTaskQuery().taskCandidateUser(userId)方法。
CustomGroupEntityManager
/**
* 分组工厂类
* Created by wizzer on 15-4-27.
*/
@IocBean
public class CustomGroupEntityManager extends GroupEntityManager {
Dao dao= Mvcs.getIoc().get(Dao.class);
private final Log log = Logs.get();
@Override
public List findGroupsByUser(String userId) {
Sql sql = Sqls.create("SELECT a.* FROM sys_role a,sys_user_role b WHERE a.id=b.roleid AND b.userid=@c");
sql.params().set("c", userId);
sql.setCallback(Sqls.callback.maps());
dao.execute(sql);
List list=sql.getList(Map.class);
List groupList=new ArrayList();
for (Map m:list){
GroupEntity group=new GroupEntity();
group.setId(Strings.sNull(m.get("id")));
group.setName(Strings.sNull(m.get("name")));
group.setType("assignment");
group.setRevision(1);
groupList.add(group);
}
return groupList;
}
}
CustomGroupEntityManagerFactory
/**
* 分组接口类
* Created by wizzer on 15-4-27.
*/
@IocBean
public class CustomGroupEntityManagerFactory implements SessionFactory {
private GroupEntityManager groupEntityManager;
public void setGroupEntityManager(GroupEntityManager groupEntityManager) {
this.groupEntityManager = groupEntityManager;
}
@Override
public Class getSessionType() {
return GroupIdentityManager.class;
}
@Override
public Session openSession() {
return groupEntityManager;
}
}
CustomUserEntityManager
/**
* 用户工厂类
* Created by wizzer on 15-4-24.
*/
@IocBean
public class CustomUserEntityManager extends UserEntityManager {
Dao dao= Mvcs.getIoc().get(Dao.class);
private final Log log = Logs.get();
@Override
public User findUserById(String userId) {
log.info("findUserById:::::::::::::::::::::::::::::::"+userId);
UserEntity userEntity = new UserEntity();
Sys_user sysUser = dao.fetch(Sys_user.class, Cnd.where("uid", "=", userId));
userEntity.setId(userId);
userEntity.setFirstName(sysUser.getRealname());
userEntity.setEmail(sysUser.getEmail());
userEntity.setRevision(1);
return userEntity;
}
@Override
public List findGroupsByUser(String userId) {
// TODO Auto-generated method stub
log.info("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
Sql sql = Sqls.create("SELECT a.* FROM sys_role a,sys_user_role b WHERE a.id=b.roleid AND b.userid=@c");
sql.params().set("c", userId);
sql.setCallback(Sqls.callback.maps());
dao.execute(sql);
List list=sql.getList(Map.class);
List groupList=new ArrayList();
for (Map m:list){
GroupEntity group=new GroupEntity();
group.setId(Strings.sNull(m.get("id")));
group.setName(Strings.sNull(m.get("name")));
group.setType("assignment");
group.setRevision(1);
groupList.add(group);
}
return groupList;
}
}
CustomUserEntityManagerFactory
/**
* 用户接口类
* Created by wizzer on 15-4-24.
*/
@IocBean
public class CustomUserEntityManagerFactory implements SessionFactory {
private UserEntityManager userEntityManager;
public void setUserEntityManager(UserEntityManager userEntityManager) {
this.userEntityManager = userEntityManager;
}
@Override
public Class getSessionType() {
return UserIdentityManager.class;
}
@Override
public Session openSession() {
return userEntityManager;
}
}
在初始化activiti时追加代码:
List list=new ArrayList();
CustomGroupEntityManagerFactory customGroupManagerFactory=new CustomGroupEntityManagerFactory();
customGroupManagerFactory.setGroupEntityManager(new CustomGroupEntityManager());
CustomUserEntityManagerFactory customUserEntityManagerFactory=new CustomUserEntityManagerFactory();
customUserEntityManagerFactory.setUserEntityManager(new CustomUserEntityManager());
list.add(customGroupManagerFactory);
list.add(customUserEntityManagerFactory);
processEngineConfiguration.setCustomSessionFactories(list);
2015 4 月27
@SetupBy(value=StartSetup.class)
public class MainModule {
}
private void activitiInit(NutConfig config) {
log.info("Activiti Init Start...");
ProcessEngineConfigurationImpl processEngineConfiguration = (ProcessEngineConfigurationImpl) ProcessEngineConfiguration
.createStandaloneProcessEngineConfiguration();
processEngineConfiguration.setDataSource(config.getIoc().get(DataSource.class));
processEngineConfiguration.setDatabaseSchemaUpdate("false");
processEngineConfiguration.setJobExecutorActivate(false);
processEngineConfiguration.setActivityFontName("宋体");
processEngineConfiguration.setLabelFontName("宋体");
processEngineConfiguration.setXmlEncoding("utf-8");
ProcessEngine processEngine = processEngineConfiguration.buildProcessEngine();
((Ioc2) config.getIoc()).getIocContext().save("app", "processEngine", new ObjectProxy(processEngine));
((Ioc2) config.getIoc()).getIocContext().save("app", "repositoryService", new ObjectProxy(processEngine.getProcessEngineConfiguration().getRepositoryService()));
((Ioc2) config.getIoc()).getIocContext().save("app", "runtimeService", new ObjectProxy(processEngine.getProcessEngineConfiguration().getRuntimeService()));
((Ioc2) config.getIoc()).getIocContext().save("app", "taskService", new ObjectProxy(processEngine.getProcessEngineConfiguration().getTaskService()));
((Ioc2) config.getIoc()).getIocContext().save("app", "formService", new ObjectProxy(processEngine.getProcessEngineConfiguration().getFormService()));
((Ioc2) config.getIoc()).getIocContext().save("app", "historyService", new ObjectProxy(processEngine.getProcessEngineConfiguration().getHistoryService()));
((Ioc2) config.getIoc()).getIocContext().save("app", "managementService", new ObjectProxy(processEngine.getProcessEngineConfiguration().getManagementService()));
((Ioc2) config.getIoc()).getIocContext().save("app", "identityService", new ObjectProxy(processEngine.getProcessEngineConfiguration().getIdentityService()));
log.info("Activiti Init End.");
}
2015 4 月24
public String getTemplateStr(String template, Map para) {
StringWriter writer = new StringWriter();
try {
RuntimeServices runtimeServices = RuntimeSingleton.getRuntimeServices();
StringReader reader = new StringReader(template);
SimpleNode node = runtimeServices.parse(reader, "Template name");
Template t = new Template();
t.setRuntimeServices(runtimeServices);
t.setData(node);
t.initDocument();
VelocityContext context = new VelocityContext();
if (para.size() > 0) {
for (String key : para.keySet()) {
context.put(key, para.get(key));
}
}
t.merge(context, writer);
} catch (Exception e) {
throw new RuntimeException("Error commiting transaction! cause:"+ e.getMessage());
}
return writer.toString();
}
@At("/form")
@Ok("vm:template.private.test")
public void form(HttpServletRequest req, HttpServletResponse resp) {
Map formParams = new HashMap();
formParams.put("formKey", "form/waizhibiaodan/01/01.form");
int timeout = 60 * 1000;
String str = Http.post("http://127.0.0.1/test/getFormKey", formParams, timeout);
NutMap map = Json.fromJson(NutMap.class, str);
String formData = map.getString("data");
Map params = new HashMap();
params.put("startDate", "2015-04-21");
params.put("endDate", "2015-04-25");
req.setAttribute("formData", getTemplateStr(formData, params));
}
2015 4 月21
mvn package -Dmaven.test.skip=true
2015 4 月16
processEngineConfiguration.setActivityFontName(“宋体”);
processEngineConfiguration.setLabelFontName(“宋体”);
windows环境变量:
JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF-8
2015 3 月10
刚才给一位顾客剪完发,他对着镜子照了一番,脸上露出一丝笑意:“明天我叫我的兄弟一起过来!” 我很高兴,正要谢他,他却拍了拍我的肩膀:“你也叫点人吧,到时别说我人多欺负你!”
2015 2 月3
Wirank.cn
提供自助的微信文章阅读数查询功能,以及回溯公众号历史文章功能,并提供API接口供调用。
2015 1 月28
效果图:
源码不解释:
private void ResultToJpg(List list, String title, HttpServletResponse response) {
BufferedImage image;
int totalrow = list.size();
int totalcol = 7;
int imageWidth = 640;
int rowheight = 40;
int imageHeight = totalrow * rowheight + 105;
int startHeight = 20;
int startWidth = 10;
int colwidth = (int) ((imageWidth - 20) / totalcol);
int colwidth2 = (int) ((imageWidth - 20) / (totalcol + 1));
image = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_RGB);
Graphics2D graphics = (Graphics2D) image.getGraphics();
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
graphics.setColor(Color.WHITE);
graphics.fillRect(0, 0, imageWidth, imageHeight);
Font font = new Font("微软雅黑", Font.BOLD, 20);
graphics.setFont(font);
graphics.setColor(new Color(112, 48, 158));
graphics.drawString(Strings.sNull(title), startWidth, startHeight + 10);
font = new Font("微软雅黑", Font.PLAIN, 13);
graphics.setColor(new Color(99, 99, 99));
graphics.setFont(font);
String subtitle1 = "欢迎访问";
graphics.drawString(subtitle1, startWidth, startHeight + 30);
font = new Font("Arial, Helvetica, sans-serif", Font.BOLD, 13);
graphics.setColor(new Color(112, 48, 158));
graphics.setFont(font);
String subtitle2 = "inm.xuetang.cn";
graphics.drawString(subtitle2, startWidth + 60, startHeight + 30);
font = new Font("微软雅黑", Font.PLAIN, 13);
graphics.setColor(new Color(99, 99, 99));
graphics.setFont(font);
String subtitle3 = "冲榜、制榜!";
graphics.drawString(subtitle3, startWidth + 165, startHeight + 30);
//画首行
graphics.setColor(new Color(112, 48, 158));
graphics.fillRect(startWidth, startHeight + rowheight, imageWidth - 20, rowheight);
font = new Font("微软雅黑", Font.PLAIN, 12);
graphics.setColor(Color.WHITE);
graphics.setFont(font);
graphics.drawString("#", startWidth + 10, startHeight + rowheight * 2 - 15);
graphics.drawString("公众号", startWidth + colwidth - 10, startHeight + rowheight * 2 - 15);
//画表头
String[] headCells = {"发布", "总阅读数", " 头条", " 平均 ", "总点赞数", " WCI"};
for (int m = 0; m < headCells.length; m++) {
graphics.drawString(headCells[m].toString(), startWidth + colwidth2 * m + colwidth * 2, startHeight + rowheight * 2 - 15);
}
//画行
for (int j = 0; j 0) {
String readnum_all = Strings.sNull(map.get("readnum_all"));
int t = NumberUtils.toInt(readnum_all.substring(readnum_all.length() - 4, readnum_all.length() - 3));
if (t > 0) {
readnum_all = readnum_all.substring(0, readnum_all.length() - 4) + "." + String.valueOf(t);
} else {
readnum_all = readnum_all.substring(0, readnum_all.length() - 4);
}
graphics.drawString(readnum_all + "万+", startWidth + colwidth2 + colwidth * 2 + 5, startHeight + (j + 3) * rowheight - 15);
} else {
graphics.drawString(Strings.sNull(map.get("readnum_all")), startWidth + colwidth2 + colwidth * 2 + 5, startHeight + (j + 3) * rowheight - 15);
}
if (NumberUtils.toInt(Strings.sNull(map.get("url_times_readnum"))) > 100000) {
String url_times_readnum = Strings.sNull(map.get("url_times_readnum"));
int t = NumberUtils.toInt(url_times_readnum.substring(url_times_readnum.length() - 4, url_times_readnum.length() - 3));
if (t > 0) {
url_times_readnum = url_times_readnum.substring(0, url_times_readnum.length() - 4) + "." + String.valueOf(t);
} else {
url_times_readnum = url_times_readnum.substring(0, url_times_readnum.length() - 4);
}
graphics.drawString(url_times_readnum+"万+", startWidth + colwidth2 + colwidth * 3 - 5, startHeight + (j + 3) * rowheight - 15);
} else {
graphics.drawString(Strings.sNull(map.get("url_times_readnum")), startWidth + colwidth2 + colwidth * 3 - 5, startHeight + (j + 3) * rowheight - 15);
}
if (NumberUtils.toInt(Strings.sNull(map.get("readnum_av"))) > 100000) {
String readnum_av = Strings.sNull(map.get("readnum_av"));
int t = NumberUtils.toInt(readnum_av.substring(readnum_av.length() - 4, readnum_av.length() - 3));
if (t > 0) {
readnum_av = readnum_av.substring(0, readnum_av.length() - 4) + "." + String.valueOf(t);
} else {
readnum_av = readnum_av.substring(0, readnum_av.length() - 4);
}
graphics.drawString(readnum_av+"万+", startWidth + colwidth2 + colwidth * 4 - 15, startHeight + (j + 3) * rowheight - 15);
} else {
graphics.drawString(Strings.sNull(map.get("readnum_av")), startWidth + colwidth2 + colwidth * 4 - 15, startHeight + (j + 3) * rowheight - 15);
}
graphics.drawString(Strings.sNull(map.get("likenum_all")), startWidth + colwidth2 + colwidth * 5 - 20, startHeight + (j + 3) * rowheight - 15);
graphics.drawString(Strings.sNull(map.get("wci")), startWidth + colwidth2 + colwidth * 6 - 40, startHeight + (j + 3) * rowheight - 15);
}
//末行
graphics.setColor(Color.WHITE);
graphics.fillRect(startWidth, startHeight + (totalrow + 1) * rowheight + 40, imageWidth - 20, startHeight + (totalrow + 1) * rowheight);
try {
response.setContentType("image/png");
OutputStream out = response.getOutputStream();
ImageIO.write(image, "png", out);
} catch (Exception e) {
e.printStackTrace();
}
}
2015 1 月3
关注微信,发送弹幕到电影院大屏幕,后台有审核和黑名单功能。
弹幕字体随机、颜色随机、大小随机、位置随机,都可以设置。
测试效果和当天影院现场图片:
2014 11 月14
String str = String.format(“%010d”, 1212);
2014 11 月10
ComboIocLoader loader = new ComboIocLoader(
new String[]{
“org.nutz.ioc.loader.json.JsonLoader”, “ioc/”,
“ org.nutz.ioc.loader.annotation.AnnotationIocLoader”, “cn.xuetang”}
);
ioc = new NutIoc(loader);
dao = ioc.get(Dao.class);
2014 11 月10
SELECT SUBSTRING_INDEX(SUBSTRING(url,LOCATE(“sn=”,url)+3),’&’,1),url FROM wx_kw_url_1111
2014 10 月24
adb shell
su
chmod 777 /data/local/tcpdump
/data/local/tcpdump -p -vv -s 0 -w /sdcard/capture.pcap
2014 9 月29
select a.*
from wx_nickname a
left join (select distinct nickname_id from wx_group_nickname )b on
a.id = b.nickname_id
where b.nickname_id is null
2014 9 月23
NutzWk
https://github.com/Wizzercn/NutzWk
基于Nutz的开源企业级开发框架。
文件编码全部为UTF-8,可以导入Eclispe、IDEA中,jdk7,tomcat 6/7.
创建空的数据库,首次启动项目会自动初始化数据.
本框架已成功应用于XX省交通厅网络问政平台、XX省交通厅CMS内容管理系统、XX公司舆情监测管理中心等项目。
使用条款:
1、个人开源,可以任意修改使用;
2、商业使用,必须更改后台菜单布局、CSS样式、界面颜色等元素(既:不可使用原始界面用于商业项目)。