package com.ucap.jycypolicy.action;
import com.alibaba.fastjson.JSON;
import com.ucap.common.exception.InterfaceException;
import com.ucap.common.query.QueryObject;
import com.ucap.common.util.DataMaskUtil;
import com.ucap.common.util.LogUtil;
import com.ucap.common.util.PageBean;
import com.ucap.common.util.PageUtil;
import com.ucap.common.util.json.JSONUtil;
import com.ucap.jycypolicy.dao.CyjyLayerDao;
import com.ucap.jycypolicy.pojo.TCyjyLayer;
import com.ucap.mzty.service.DefineService;
import com.ucap.sys.action.AuthBaseAction;
import com.ucap.sys.pojo.MztyDefine;
import com.ucap.tyjr.pojo.JobFair;
import com.ucap.tyjr.pojo.JobFairFj;
import com.ucap.web.tools.WebTools;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import java.io.File;
import java.util.*;
/**
* 政策指引
* 测试环境 url : http://127.0.0.1:8080/gdstyjr/jycyLayer!toList.action?viewIndex=1&menuId=561
*
* @author haipeng
*/
@Controller
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@ParentPackage(value = "haslogin")
@Action(value = "jycyLayer")
@Results(value = {
@Result(name = "list", location = "/WEB-INF/jsp/jycypolicy/layer/layer_list.jsp"),
@Result(name = "edit", location = "/WEB-INF/jsp/mzty/layer/layer_edit.jsp"),
@Result(name = "view", location = "/WEB-INF/jsp/mzty/layer/layer_view.jsp")
})
public class LayerAction extends AuthBaseAction {
private String MODEL_CODE = "jycyLayer";
private String DESC_MODEL = "政策区域";
private Integer pageCurrent = 1;
private Integer pageSize = 10;
// private PageUtil<Map<String, Object>> pageUtil;
private PageUtil<TCyjyLayer> pageUtil;
// 前端请求入参
private Map<String, Object> params = new HashMap<>();
// private Map<String, Object> dataMap = new HashMap<>();
private Map<String, Object> dataMap = new HashMap<>();
private List<Map<String, Object>> dataListMap = new ArrayList<>();
public String toList() {
LogUtil.getLogger().info("====hello layer list()=====");
return "list";
}
public String readLayer() {
processRight();
// String xzqh = WebTools.getUser().getKglxzqhbm();
// String xzqhName = WebTools.getUser().getKglxzqhmc();
String layerId = MapUtils.getString(params, "id");
LogUtil.getLogger().info("获取到layerId=" + layerId);
// if (params.get("fair_id") != null) {
// fairId = params.get("fair_id") + "";
// }
if (StringUtils.isNotBlank(layerId)) {
// // 查询
// this.cyjyLayerDao.getHibernateTemplate().find()
// List<Map<String, Object>> dataList = fairService.selectListMapByParam(params);
// if (dataList != null && dataList.size() > 0) {
// dataMap = dataList.get(0);
// }
TCyjyLayer layerBean = new TCyjyLayer();
layerBean.setCode("1");
layerBean.setName("测试layer");
layerBean.setDesc("mock desc");
layerBean.setStatus("ON");
layerBean.setId(Long.parseLong(layerId));
dataMap = com.alibaba.fastjson.JSON.parseObject(com.alibaba.fastjson.JSON.toJSONString(layerBean), Map.class);
} else {
// Calendar date = Calendar.getInstance();
// String dateYear = String.valueOf(date.get(Calendar.YEAR));
// dataMap.put("fair_name", dateYear + xzqhName + "招聘会");
// dataMap.put("city_code", xzqh);
// dataMap.put("fair_id", UUID.randomUUID().toString().replaceAll("-", ""));
}
return "edit";
}
public String pageLayerJson() throws Exception {
LogUtil.getLogger().info("page layer json====》");
String xzqh = WebTools.getUser().getKglxzqhbm();
params.put("city_code", xzqh);
TCyjyLayer layerBean = new TCyjyLayer();
layerBean.setCode("1");
layerBean.setName("测试layer");
layerBean.setDesc("mock desc");
layerBean.setStatus("ON");
layerBean.setId(1L);
layerBean.setModifiedTime(new Date());
PageUtil<TCyjyLayer> page = new PageUtil<>();
page.setCurrent(1);
page.setSize(1);
page.setCount(1);
page.setList(Collections.singletonList(layerBean));
this.pageUtil = page;
String s = page4JsonArray(pageUtil);
LogUtil.getLogger().info("返回page数据:" + s);
getResponse().getWriter().write(s);
return NONE;
// getResponse().getWriter().write(jsonMsg(false, "列表数据为空"));
// pageUtil = fairService.selectPageMapByParam(pageCurrent-1,pageSize,params);
// if(pageUtil!=null) {
// //mapDataTm 数据脱敏 hotline_phone hotline_email
// pageUtil.setList(DataMaskUtil.mapDataTm(pageUtil.getList()));
// getResponse().getWriter().write(page4JsonArray(pageUtil));
//// }else {
// getResponse().getWriter().write(jsonMsg(false, "列表数据为空"));
// }
// String xzqh = WebTools.getUser().getKglxzqhbm();
// params.put("city_code",xzqh);
// if(this.pageUtil !=null) {
// //mapDataTm 数据脱敏 hotline_phone hotline_email
// this.pageUtil.setList(DataMaskUtil.mapDataTm(this.pageUtil.getList()));
// getResponse().getWriter().write(page4JsonArray(this.pageUtil));
// }else {
// getResponse().getWriter().write(jsonMsg(false, "列表数据为空"));
// }
// return NONE;
}
@Autowired
private CyjyLayerDao cyjyLayerDao;
//删除数据
public void del() throws Exception {
String id = getParamFromRequest("id");
LogUtil.getLogger().info("删除layer id=" + id);
}
protected String page4JsonArray(PageUtil<TCyjyLayer> pageUtil) {
List<TCyjyLayer> list = new ArrayList<>();
JSONObject datas = new JSONObject();
JSONArray jsonAttr = new JSONArray();
list = pageUtil.getList();
if (list != null && list.size() > 0) {
jsonAttr = JSONUtil.getJSONArray(list, null);
}
datas.put("total", list == null ? 0 : list.size());
datas.put("rows", jsonAttr);
datas.put("start", pageUtil.getCurrent());
datas.put("limit", pageUtil.getLimitNum());
datas.put("totalProperty", pageUtil.getCount());
return datas.toString();
}
public String getMODEL_CODE() {
return MODEL_CODE;
}
public void setMODEL_CODE(String MODEL_CODE) {
this.MODEL_CODE = MODEL_CODE;
}
public String getDESC_MODEL() {
return DESC_MODEL;
}
public void setDESC_MODEL(String DESC_MODEL) {
this.DESC_MODEL = DESC_MODEL;
}
public Integer getPageCurrent() {
return pageCurrent;
}
public void setPageCurrent(Integer pageCurrent) {
this.pageCurrent = pageCurrent;
}
public Integer getPageSize() {
return pageSize;
}
public void setPageSize(Integer pageSize) {
this.pageSize = pageSize;
}
public PageUtil<TCyjyLayer> getPageUtil() {
return pageUtil;
}
public void setPageUtil(PageUtil<TCyjyLayer> pageUtil) {
this.pageUtil = pageUtil;
}
// public PageUtil<Map<String, Object>> getPageUtil() {
// return pageUtil;
// }
//
// public void setPageUtil(PageUtil<Map<String, Object>> pageUtil) {
// this.pageUtil = pageUtil;
// }
public Map<String, Object> getParams() {
return params;
}
public void setParams(Map<String, Object> params) {
this.params = params;
}
public Map<String, Object> getDataMap() {
return dataMap;
}
public void setDataMap(Map<String, Object> dataMap) {
this.dataMap = dataMap;
}
public List<Map<String, Object>> getDataListMap() {
return dataListMap;
}
public void setDataListMap(List<Map<String, Object>> dataListMap) {
this.dataListMap = dataListMap;
}
}