Commit 04a5afbe authored by 黄毅's avatar 黄毅

1

parent 20ccd90c
/**
*
*/
package com.egolm.admin.controller;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.egolm.admin.pojo.TIcon;
import com.egolm.admin.pojo.TIconGroup;
import com.egolm.admin.service.IconManageService;
import com.egolm.admin.service.LinkListService;
import com.egolm.admin.util.AdminContstrant;
import com.egolm.admin.util.I18NUtils;
import com.egolm.common.GsonUtil;
import com.egolm.common.StringUtil;
import com.egolm.common.bean.Rjx;
import com.egolm.common.jdbc.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
/**
*
* @author huang.yi
* @date 2018年8月7日
* @Description IconManageController
*
*/
@Api(tags={"图标资源管理"})
@RestController
@RequestMapping("icon")
public class IconManageController {
@Autowired
private IconManageService iconService;
@ApiOperation("查询")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", name = "queryParam", dataType = "String", required = false, value = "组编号/组名称/说明", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "LangID", dataType = "String", required = true, value = "语言", defaultValue = "936"),
@ApiImplicitParam(paramType = "query", name = "index", dataType = "int", required = true, value = "页码", defaultValue = "1"),
@ApiImplicitParam(paramType = "query", name = "limit", dataType = "int", required = true, value = "每页显示数", defaultValue = "10"),
})
@RequestMapping(value = "/query",method=RequestMethod.GET)
public String query(HttpServletRequest request) {
String params = request.getParameter("queryParam");
String langId = request.getParameter("LangID");
String index = request.getParameter("index");
String limit = request.getParameter("limit");
if(!StringUtil.isNotEmpty(limit,index)) {
return Rjx.json().setCode(-1).setMessage(I18NUtils.getMessage(langId, "Msg_Parameter_empty")).toJson();
}
Map<String, Object> paramMap = new HashMap<String, Object>();
paramMap.put("queryParam", params);
paramMap.put("LangID", langId);
Page page = new Page();
page.setIndex(Long.valueOf(index));
page.setLimit(Long.valueOf(limit));
page.setLimitKey(" lastUpdateTime desc ");
List<Map<String, Object>> detailList = iconService.query(paramMap, page);
return Rjx.jsonOk().set("list", detailList).setPage(page).toString();
}
@ApiOperation("详情")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", name = "groupNO", dataType = "String", required = false, value = "组编号", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "LangID", dataType = "String", required = true, value = "语言", defaultValue = "936"),
})
@RequestMapping(value = "/showDetail",method=RequestMethod.GET)
public String showDetail(HttpServletRequest request) {
String groupNO = request.getParameter("groupNO");
String langId = request.getParameter("LangID");
if(!StringUtil.isNotEmpty(groupNO)) {
return Rjx.json().setCode(-1).setMessage(I18NUtils.getMessage(langId, "Msg_Parameter_empty")).toJson();
}
Map<String, Object> params = new HashMap<String, Object>();
params.put("groupNO", groupNO);
params.put("LangID", langId);
Map<String, Object> allDetail = new HashMap<String, Object>();
Map<String, Object> dataList_0 = iconService.showGroupDetail(params);
List<Map<String, Object>> dataList_1 = iconService.showDetail(params);
allDetail.put("dataList_0", dataList_0);
allDetail.put("dataList_1", dataList_1);
return Rjx.jsonOk().set("detail", allDetail).toString();
}
@ApiOperation("新增")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", name = "groupNO", dataType = "String", required = true, value = "组编号", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "groupName", dataType = "String", required = true, value = "组名称", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "caption", dataType = "String", required = false, value = "说明", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "LangID", dataType = "String", required = true, value = "语言", defaultValue = "936"),
@ApiImplicitParam(paramType = "query", name = "tag", dataType = "String", required = true, value = "状态 0为正常 2为不可用", defaultValue = "0"),
@ApiImplicitParam(paramType = "query", name = "dataList_1", dataType = "String", required = false, value = "图标资源管理数组", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "createUser", dataType = "String", required = true, value = "创建者", defaultValue = ""),
})
@RequestMapping(value = "/iconAdd",method=RequestMethod.POST)
public String iconAdd(HttpServletRequest request) {
String groupNO = request.getParameter("groupNO");
String groupName = request.getParameter("groupName");
String caption = request.getParameter("caption");
String tag = request.getParameter("tag");
String createUser = request.getParameter("createUser");
String langId = request.getParameter("LangID");
String dataList_1 = request.getParameter("dataList_1");
if(!StringUtil.isNotEmpty(groupNO,groupName,tag,langId,createUser,dataList_1)) {
return Rjx.json().setCode(-1).setMessage(I18NUtils.getMessage(langId, "Msg_Parameter_empty")).toJson();
}
TIconGroup iconGroup = new TIconGroup();
iconGroup.setsGroupNO(groupNO);
iconGroup.setsGroupName(groupName);
iconGroup.setsCaption(caption != null ? caption : "");
iconGroup.setsCreateUser(createUser);
iconGroup.setsUpdateUser(createUser);
iconGroup.setnTag(Integer.valueOf(tag));
List<TIcon> iconList = new ArrayList<TIcon>();
List<Map<String, Object>> dataMap = (List<Map<String, Object>>) GsonUtil.toList(dataList_1);
for(Map<String, Object> map : dataMap) {
TIcon icon = new TIcon();
icon.setsGroupNO(((String) map.get("groupNO")).trim());
icon.setsIconNO(((String) map.get("iconNO")).trim());
icon.setsIconPath(((String) map.get("iconPath")).trim());
icon.setsDefaultTxt(((String) map.get("defaultTxt")).trim());
icon.setsDefaultLinkType(((String) map.get("defaultLinkType")).trim());
icon.setsDefaultLink(((String) map.get("defaultLink")).trim());
iconList.add(icon);
}
Rjx rjx = iconService.saveGroup(iconGroup, iconList);
System.out.println(iconService.saveGroup(iconGroup, iconList));
Rjx result = Rjx.json();
result.setCode(rjx.getCode());
result.setMessage(I18NUtils.getMessage(langId, rjx.get(AdminContstrant.I18n_KEY)+""));
return result.toJson();
}
@ApiOperation("修改")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", name = "groupNO", dataType = "String", required = true, value = "组编号", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "groupName", dataType = "String", required = true, value = "组名称", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "caption", dataType = "String", required = false, value = "说明", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "LangID", dataType = "String", required = true, value = "语言", defaultValue = "936"),
@ApiImplicitParam(paramType = "query", name = "tag", dataType = "String", required = true, value = "状态 0为正常 2为不可用", defaultValue = "0"),
@ApiImplicitParam(paramType = "query", name = "dataList_1", dataType = "String", required = false, value = "图标资源管理数组", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "updateUser", dataType = "String", required = true, value = "修改者", defaultValue = ""),
})
@RequestMapping(value = "/iconModify",method=RequestMethod.POST)
public String iconModify(HttpServletRequest request) throws ParseException {
String groupNO = request.getParameter("groupNO");
String groupName = request.getParameter("groupName");
String caption = request.getParameter("caption");
String tag = request.getParameter("tag");
String langId = request.getParameter("LangID");
String dataList_1 = request.getParameter("dataList_1");
String updateUser = request.getParameter("updateUser");
String lastUpdateTime = request.getParameter("lastUpdateTime");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = sdf.parse(lastUpdateTime);
if(!StringUtil.isNotEmpty(groupNO,groupName,tag,langId,dataList_1,updateUser,lastUpdateTime)) {
return Rjx.json().setCode(-1).setMessage(I18NUtils.getMessage(langId, "Msg_Parameter_empty")).toJson();
}
TIconGroup iconGroup = iconService.getIconGroup(groupNO);
iconGroup.setsGroupNO(groupNO);
iconGroup.setsGroupName(groupName);
iconGroup.setsCaption(caption != null ? caption : "");
iconGroup.setsUpdateUser(updateUser);
iconGroup.setnTag(Integer.valueOf(tag));
List<TIcon> iconList = new ArrayList<TIcon>();
List<Map<String, Object>> dataMap = (List<Map<String, Object>>) GsonUtil.toList(dataList_1);
for(Map<String, Object> map : dataMap) {
TIcon icon = new TIcon();
icon.setsGroupNO(checkNull(((String) map.get("groupNO")).trim()));
icon.setsIconNO(checkNull(((String) map.get("iconNO")).trim()));
icon.setsIconPath(checkNull(((String) map.get("iconPath")).trim()));
icon.setsDefaultTxt(checkNull(((String) map.get("defaultTxt")).trim()));
icon.setsDefaultLinkType(checkNull(((String) map.get("defaultLinkType")).trim()));
icon.setsDefaultLink(checkNull(((String) map.get("defaultLink")).trim()));
iconList.add(icon);
}
Rjx rjx = iconService.updateGroup(iconGroup, iconList);
System.out.println(iconService.updateGroup(iconGroup, iconList));
Rjx result = Rjx.json();
result.setCode(rjx.getCode());
result.setMessage(I18NUtils.getMessage(langId, rjx.get(AdminContstrant.I18n_KEY)+""));
return result.toJson();
}
public String checkNull(String str) {
if(null == str) {
str = "";
}
return str;
}
}
/**
*
*/
package com.egolm.admin.service;
import java.util.List;
import java.util.Map;
import com.egolm.admin.pojo.TIcon;
import com.egolm.admin.pojo.TIconGroup;
import com.egolm.common.bean.Rjx;
import com.egolm.common.jdbc.Page;
/**
*
* @author huang.yi
* @date 2018年8月7日
* @Description IconManageService
*
*/
public interface IconManageService {
public List<Map<String, Object>> query(Map<String, Object> params, Page page);
public Map<String, Object> showGroupDetail(Map<String, Object> params);
public List<Map<String, Object>> showDetail(Map<String, Object> params);
public Rjx saveGroup(TIconGroup iconGroup, List<TIcon> iconList);
public Rjx save(List<TIcon> iconList);
public TIconGroup checkGroupNO(String groupNO);
public Rjx updateGroup(TIconGroup iconGroup, List<TIcon> iconList);
public TIconGroup getIconGroup(String groupNO);
public Rjx update(List<TIcon> iconList);
}
/**
*
*/
package com.egolm.admin.service.impl;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import com.egolm.admin.config.XException;
import com.egolm.admin.pojo.TIcon;
import com.egolm.admin.pojo.TIconGroup;
import com.egolm.admin.pojo.TLinkList;
import com.egolm.admin.service.IconManageService;
import com.egolm.admin.util.AdminContstrant;
import com.egolm.admin.util.I18NUtils;
import com.egolm.common.StringUtil;
import com.egolm.common.bean.Rjx;
import com.egolm.common.jdbc.JdbcTemplate;
import com.egolm.common.jdbc.Page;
/**
*
* @author huang.yi
* @date 2018年8月7日
* @Description IconManageImpl
*
*/
@Service
public class IconManageImpl implements IconManageService {
private static final Log logger = LogFactory.getLog(IconManageImpl.class);
@Autowired
private JdbcTemplate jdbcTemplate;
/**
* 首页查询
*/
@Override
public List<Map<String, Object>> query(Map<String, Object> params, Page page){
String searchParam = (String) params.get("queryParam");
String langId = (String) params.get("LangID");
String sql = "select a.sGroupNO groupNO, a.sGroupName groupName, count(b.sIconNO) IconCount , a.sCaption caption,a.nTag tag, "
+ " a.sCreateUser createUser,a.sUpdateUser updateUser ,a.dLastUpdateTime lastUpdateTime from tIconGroup a left join tIcon b on a.sGroupNO = b.sGroupNO where a.nTag&1 =0";
if(!StringUtil.isEmpty(searchParam)) {
sql += " and (a.sGroupNO like '%"+searchParam+"%' or a.sGroupName like '%"+searchParam+"%' or a.sCaption like '%"+searchParam+"%') ";
}
sql += " GROUP BY a.sGroupNO, a.sGroupName, a.sCaption, a.nTag, a.sCreateUser, a.sUpdateUser, a.dLastUpdateTime";
return jdbcTemplate.limit(sql, page);
}
/**
* 详情查询dataList-0
*/
@Override
public Map<String, Object> showGroupDetail(Map<String, Object> params){
String groupNO = (String) params.get("groupNO");
String langId = (String) params.get("LangID");
String sql = "select sGroupNO groupNO, sGroupName groupName, sCaption caption, nTag tag from tIconGroup where sGroupNO = ?";
return jdbcTemplate.queryForMap(sql, groupNO);
}
/**
* 详情查询dataList-1
*/
@Override
public List<Map<String, Object>> showDetail(Map<String, Object> params){
String groupNO = (String) params.get("groupNO");
String langId = (String) params.get("LangID");
String sql = "select sGroupNO groupNO, sIconNO iconNO, sIconPath iconPath, sDefaultTxt defaultTxt, sDefaultLinkType defaultLinkType, sDefaultLink defaultLink from tIcon where sGroupNO = ?" ;
return jdbcTemplate.queryForList(sql, groupNO);
}
/**
* 保存数据到tIconGroup表
*/
@Override
public Rjx saveGroup(TIconGroup iconGroup, List<TIcon> iconList) {
iconGroup.setdCreateDate(new Date());
iconGroup.setdLastUpdateTime(new Date());
iconGroup.setdUpdateDate(new Date());
TIconGroup iconG = checkGroupNO(iconGroup.getsGroupNO());
if (iconG != null) {
return Rjx.jsonErr().set(AdminContstrant.I18n_KEY, "Msg_GroupNO_exists"); // .setMessage("图标组编号已存在");
}
int i = jdbcTemplate.save(iconGroup);
if(i > 0) {
Rjx result = save(iconList);
System.out.println("result" + result);
if(result.getCode() == 200) {
return Rjx.jsonOk().set(AdminContstrant.I18n_KEY,"Msg_Save_Success"); //.setMessage("保存成功");
}else {
return Rjx.jsonErr().set(AdminContstrant.I18n_KEY,"Msg_Save_Error"); //.setMessage("保存失败");
}
}else {
return Rjx.jsonErr().set(AdminContstrant.I18n_KEY,"Msg_Save_Error"); //.setMessage("保存失败");
}
}
/**
* 保存数据到tIcon表
*/
@Override
public Rjx save(List<TIcon> iconList) {
try {
jdbcTemplate.batchSave(iconList);
return Rjx.json().setCode(200);
}catch(Exception e){
new XException(I18NUtils.getMessage(AdminContstrant.I18n_KEY, "Msg_Update_Success"), e);//新增失败
}
return Rjx.jsonErr().set(AdminContstrant.I18n_KEY,"Msg_Update_Error");
}
/**
* 修改tIconGroup表
*/
@Override
public Rjx updateGroup(TIconGroup iconGroup, List<TIcon> iconList) {
iconGroup.setdUpdateDate(new Date());
iconGroup.setdLastUpdateTime(new Date());
int i = jdbcTemplate.update(iconGroup);
if(i > 0) {
Rjx result = update(iconList);
System.out.println("result" + result);
if(result.getCode() == 200) {
return Rjx.jsonOk().set(AdminContstrant.I18n_KEY,"Msg_Update_Success"); //.setMessage("更新成功");
}else {
return Rjx.jsonErr().set(AdminContstrant.I18n_KEY,"Msg_Update_Error"); //.setMessage("更新失败");
}
}else {
return Rjx.jsonErr().set(AdminContstrant.I18n_KEY,"Msg_Update_Error"); //.setMessage("更新失败");
}
}
/**
* 修改tIconGroup表
*/
@Override
public Rjx update(List<TIcon> iconList) {
try {
for(TIcon icon : iconList) {
jdbcTemplate.update(icon);
}
return Rjx.json().setCode(200);
}catch(Exception e){
new XException(I18NUtils.getMessage(AdminContstrant.I18n_KEY, "Msg_Save_Error"), e);//更新失败
}
return Rjx.jsonErr().set(AdminContstrant.I18n_KEY,"Msg_Save_Error");
}
/**
* 获取单个icongroup
*/
@Override
public TIconGroup getIconGroup(String groupNO) {
try {
String sql = "SELECT * FROM tIconGroup WHERE sGroupNO = ? AND nTag&1=0";
return jdbcTemplate.queryForBean(sql, TIconGroup.class, groupNO);
} catch (Exception e) {
logger.info("组编号不存在 groupNO:"+groupNO);
}
return null;
}
/**
* 检查编号是否已存在
*/
@Override
public TIconGroup checkGroupNO(String groupNO) {
try {
String sql = "SELECT * FROM tIconGroup WHERE sGroupNO = ? AND nTag&1=0";
return jdbcTemplate.queryForBean(sql, TIconGroup.class, groupNO);
} catch (Exception e) {
logger.info("重复的 groupNO:"+groupNO);
}
return null;
}
}
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