package controllers.data; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import models.Good; import models.GoodType; import com.et.mvc.JsonView; import com.et.mvc.View; import controllers.ApplicationController; public class GoodController extends ApplicationController{ public void index() throws Exception{ } public View getItems(int goodTypeId, String q, String code, String name, String spec, String model, String sort, String order, int rows, int page) throws Exception{ String orderBy = "id"; if (sort != null && order != null){ orderBy = sort + " " + order; } String cond = "1=1"; List<Object> tmpArgs = new ArrayList<Object>(); GoodType goodType = GoodType.find(GoodType.class, goodTypeId); if (goodType != null){ cond += " and goodTypeId in (" + goodType.findChildIds() + ")"; } if (q != null && !q.trim().equals("")){ cond += " and (code like ? or name like ? or help like ?)"; tmpArgs.add("%" + q.trim() + "%"); tmpArgs.add("%" + q.trim() + "%"); tmpArgs.add("%" + q.trim() + "%"); } if (code != null && !code.equals("")){ cond += " and (code like ?)"; tmpArgs.add("%"+code+"%"); } if (name != null && !name.equals("")){ cond += " and (name like ?)"; tmpArgs.add("%"+name+"%"); } if (spec != null && !spec.equals("")){ cond += " and (spec like ?)"; tmpArgs.add("%"+spec+"%"); } if (model != null && !model.equals("")){ cond += " and (model like ?)"; tmpArgs.add("%"+model+"%"); } Object[] args = tmpArgs.toArray(); Map<String,Object> result = new HashMap<String,Object>(); result.put("total", Good.count(Good.class, cond, args)); result.put("rows", Good.findAll(Good.class, cond, args, orderBy, rows, (page-1)*rows)); return new JsonView(result); } public View save(Good item) throws Exception{ item.save(); View view = new JsonView("success:true"); view.setContentType("text/plain;charset=utf-8"); return view; } public View update(int id, Map<String,Object> params) throws Exception{ Good item = Good.find(Good.class, id); item = Good.updateModel(item, params); item.save(); View view = new JsonView("success:true"); view.setContentType("text/plain;charset=utf-8"); return view; } }

hubugai1 LV11
4月25日
天涯过客JC LV1
4月15日
lhm789 LV6
2024年10月26日
233002037 LV3
2024年10月12日
educationAAA LV11
2024年5月17日
genyuan2014 LV6
2024年4月27日
wanglinddad LV55
2024年3月14日
erqiu2013 LV18
2023年12月27日
微笑刺客 LV21
2023年11月21日
Seaskye LV14
2023年11月4日

ES大兵 LV11
6月12日
暂无贡献等级
hubugai1 LV11
4月24日
付洋麟 LV5
4月23日
天涯过客JC LV1
4月15日
微信网友_6040315240812544 LV8
3月21日
weishenme1993 LV9
1月1日
sshiqi LV2
2024年12月11日
yimaoermao LV1
2024年11月28日
驱蚊器我
2024年11月18日
暂无贡献等级