Commit a7d8bc98 authored by 廖旭伟's avatar 廖旭伟

統一項目和模板的接口格式

parent 2eb8e9b9
...@@ -14,4 +14,6 @@ import lombok.Data; ...@@ -14,4 +14,6 @@ import lombok.Data;
public class GoviewMasterplateVo extends BaseEntityLong { public class GoviewMasterplateVo extends BaseEntityLong {
/** 项目数据 */ /** 项目数据 */
private String content; private String content;
/*** 项目名称 */
private String projectName;
} }
\ No newline at end of file
package com.mortals.xhx.module.goview.service.impl; package com.mortals.xhx.module.goview.service.impl;
import com.mortals.framework.model.PageInfo;
import com.mortals.xhx.module.goview.model.*; import com.mortals.xhx.module.goview.model.*;
import com.mortals.xhx.module.goview.service.GoviewMasterplateDataService; import com.mortals.xhx.module.goview.service.GoviewMasterplateDataService;
import com.mortals.xhx.module.goview.service.GoviewProjectDataService; import com.mortals.xhx.module.goview.service.GoviewProjectDataService;
import com.mortals.xhx.module.goview.service.GoviewProjectService; import com.mortals.xhx.module.goview.service.GoviewProjectService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl; import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
...@@ -32,6 +34,21 @@ public class GoviewMasterplateServiceImpl extends AbstractCRUDServiceImpl<Goview ...@@ -32,6 +34,21 @@ public class GoviewMasterplateServiceImpl extends AbstractCRUDServiceImpl<Goview
@Autowired @Autowired
private GoviewMasterplateDataService goviewMasterplateDataService; private GoviewMasterplateDataService goviewMasterplateDataService;
@Override
protected void saveBefore(GoviewMasterplateEntity entity, Context context) throws AppException {
this.validData(entity, context);
entity.setState(-1);
}
@Override
protected void findAfter(GoviewMasterplateEntity params, PageInfo pageInfo, Context context, List<GoviewMasterplateEntity> list) throws AppException {
if(CollectionUtils.isNotEmpty(list)){
for(GoviewMasterplateEntity item:list){
item.setProjectName(item.getMasterplateName());
}
}
}
@Override @Override
protected void removeAfter(Long[] ids, Context context, int result) throws AppException { protected void removeAfter(Long[] ids, Context context, int result) throws AppException {
List<Long> masterplateIdList = new ArrayList<>(); List<Long> masterplateIdList = new ArrayList<>();
......
package com.mortals.xhx.module.goview.web;
import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.annotation.RepeatSubmit;
import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.framework.model.PageInfo;
import com.mortals.framework.model.Result;
import com.mortals.framework.service.IUser;
import com.mortals.framework.util.StringUtils;
import com.mortals.framework.web.BaseJsonBodyController;
import com.mortals.xhx.base.system.param.service.ParamService;
import com.mortals.xhx.common.key.Constant;
import com.mortals.xhx.module.goview.model.*;
import com.mortals.xhx.module.goview.service.GoviewMasterplateDataService;
import com.mortals.xhx.module.goview.service.GoviewMasterplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@RestController
@RequestMapping("api/goview/masterplate")
public class GoviewMasterplateApi extends BaseJsonBodyController {
@Autowired
private ParamService paramService;
@Autowired
private GoviewMasterplateService goviewMasterplateService;
@Autowired
private GoviewMasterplateDataService goviewMasterplateDataService;
protected void init(Map<String, Object> model, Context context) {
this.addDict(model, "state", paramService.getParamBySecondOrganize("GoviewMasterplate","state"));
//super.init(model, context);
}
protected PageInfo buildPageInfo(GoviewMasterplateEntity query) {
PageInfo pageInfo = new PageInfo();
if (!ObjectUtils.isEmpty(query) && !ObjectUtils.isEmpty(query.getPage())) {
pageInfo.setCurrPage(query.getPage());
}
if (!ObjectUtils.isEmpty(query) && !ObjectUtils.isEmpty(query.getSize())) {
pageInfo.setPrePageResult(query.getSize());
}
return pageInfo;
}
protected void parsePageInfo(Map<String, Object> model, PageInfo pageInfo) {
model.put("total", pageInfo.getTotalResult());
model.put("per_page", pageInfo.getPrePageResult());
model.put("current_page", pageInfo.getCurrPage());
model.put("last_page", pageInfo.getTotalPage());
model.put("pageInfo", pageInfo);
}
@RequestMapping(value = {"list"},method = {RequestMethod.GET})
public Rest<Object> list(Integer page, Integer limit) {
GoviewMasterplateEntity query = new GoviewMasterplateEntity();
query.setPage(page);
query.setSize(limit);
IUser user = this.getCurUser();
if (user != null && user.getUserType() == Constant.CUSTOMER_USER) {
query.setCustomerId(user.getId());
}
Rest<Object> ret = new Rest();
Map<String, Object> model = new HashMap();
Context context = this.getContext();
String busiDesc = "查询模板";
int code;
try {
PageInfo pageInfo = this.buildPageInfo(query);
// this.doListBefore(query, model, context);
Result<GoviewMasterplateEntity> result = goviewMasterplateService.find(query, pageInfo, context);
model.put("data", result.getList());
model.put("pageInfo", result.getPageInfo());
this.parsePageInfo(model, result.getPageInfo());
code = 1;
model.put("message_info", busiDesc + "成功");
this.recordSysLog(this.request, busiDesc + " 【成功】");
} catch (Exception var9) {
code = -1;
this.doException(this.request, busiDesc, model, var9);
}
this.init(model, context);
ret.setCode(code);
ret.setData(model);
ret.setDict(model.get("dict"));
ret.setMsg(model.get("message_info") == null ? "" : model.remove("message_info").toString());
return ret;
}
@PostMapping({"create"})
@RepeatSubmit
public String create(@RequestBody GoviewProjectEntity projectEntity) {
Map<String, Object> model = new HashMap();
Context context = this.getContext();
String busiDesc = "新增模板信息";
int code=1;
GoviewMasterplateEntity entity = new GoviewMasterplateEntity();
entity.setMasterplateName(projectEntity.getProjectName());
entity.setIndexImage(projectEntity.getIndexImage());
entity.setRemarks(projectEntity.getRemarks());
try {
IUser user;
entity.setCreateTime(new Date());
entity.setUpdateTime(entity.getCreateTime());
user = this.getCurUser();
if (user != null && user.getUserType() == Constant.CUSTOMER_USER) {
entity.setCreateUserId(user.getId());
entity.setCustomerId(user.getId());
}
goviewMasterplateService.save(entity, context);
model.put("id", entity.getId());
model.put("entity", entity);
model.put("message_info", busiDesc + "成功");
this.recordSysLog(this.request, busiDesc + " 【成功】 [id:" + entity.getId() + "]");
} catch (Exception var7) {
this.doException(this.request, busiDesc, model, var7);
model.put("entity", entity);
code = -1;
}
this.init(model, context);
JSONObject ret = new JSONObject();
ret.put("code", code);
ret.put("msg", model.remove("message_info"));
ret.put("data", model);
return ret.toJSONString();
}
@PostMapping({"edit"})
public String editNew(@RequestBody GoviewProjectEntity projectEntity) {
Map<String, Object> model = new HashMap();
Context context = this.getContext();
String busiDesc = "修改模板信息";
int code=1;
GoviewMasterplateEntity entity = new GoviewMasterplateEntity();
entity.setId(projectEntity.getId());
entity.setMasterplateName(projectEntity.getProjectName());
entity.setIndexImage(projectEntity.getIndexImage());
entity.setRemarks(projectEntity.getRemarks());
try {
if(entity.getId()==null){
throw new AppException("模板ID不能为空");
}
IUser user;
entity.setUpdateTime(new Date());
user = this.getCurUser();
if (user != null) {
entity.setUpdateUserId(user.getId());
}
goviewMasterplateService.update(entity, context);
model.put("id", entity.getId());
model.put("entity", entity);
model.put("message_info", busiDesc + "成功");
this.recordSysLog(this.request, busiDesc + " 【成功】 [id:" + entity.getId() + "]");
} catch (Exception var7) {
this.doException(this.request, busiDesc, model, var7);
model.put("entity", entity);
code = -1;
}
this.init(model, context);
JSONObject ret = new JSONObject();
ret.put("code", code);
ret.put("msg", model.remove("message_info"));
ret.put("data", model);
return ret.toJSONString();
}
@PostMapping({"rename"})
public String rename(@RequestBody GoviewProjectEntity projectEntity) {
Map<String, Object> model = new HashMap();
Context context = this.getContext();
String busiDesc = "修改模板信息";
int code=1;
GoviewMasterplateEntity entity = new GoviewMasterplateEntity();
entity.setId(projectEntity.getId());
entity.setMasterplateName(projectEntity.getProjectName());
entity.setIndexImage(projectEntity.getIndexImage());
entity.setRemarks(projectEntity.getRemarks());
try {
if(entity.getId()==null){
throw new AppException("模板ID不能为空");
}
if(StringUtils.isEmpty(entity.getMasterplateName())){
throw new AppException("模板名称不能为空");
}
GoviewMasterplateEntity update = new GoviewMasterplateEntity();
update.setId(entity.getId());
update.setMasterplateName(entity.getMasterplateName());
IUser user;
entity.setUpdateTime(new Date());
user = this.getCurUser();
if (user != null) {
update.setUpdateUserId(user.getId());
}
goviewMasterplateService.update(update, context);
model.put("id", entity.getId());
model.put("entity", entity);
model.put("message_info", busiDesc + "成功");
this.recordSysLog(this.request, busiDesc + " 【成功】 [id:" + entity.getId() + "]");
} catch (Exception var7) {
this.doException(this.request, busiDesc, model, var7);
model.put("entity", entity);
code = -1;
}
this.init(model, context);
JSONObject ret = new JSONObject();
ret.put("code", code);
ret.put("msg", model.remove("message_info"));
ret.put("data", model);
return ret.toJSONString();
}
/**
* 发布/取消模板状态
* @param entity
* @return
*/
@PostMapping({"publish"})
public String publish(@RequestBody GoviewMasterplateEntity entity) {
Map<String, Object> model = new HashMap();
Context context = this.getContext();
String busiDesc = "发布/取消模板状态";
int code=1;
try {
if(entity.getId()==null){
throw new AppException("模板ID不能为空");
}
if(entity.getState()==null){
throw new AppException("模板状态不能为空");
}
if(entity.getState()==-1||entity.getState()==1) {
GoviewMasterplateEntity update = new GoviewMasterplateEntity();
update.setId(entity.getId());
update.setState(entity.getState());
IUser user;
entity.setUpdateTime(new Date());
user = this.getCurUser();
if (user != null) {
update.setUpdateUserId(user.getId());
}
goviewMasterplateService.update(update, context);
model.put("id", entity.getId());
model.put("entity", entity);
model.put("message_info", busiDesc + "成功");
this.recordSysLog(this.request, busiDesc + " 【成功】 [id:" + entity.getId() + "]");
}else {
throw new AppException("模板状态值非法,只能为-1或1");
}
} catch (Exception var7) {
this.doException(this.request, busiDesc, model, var7);
model.put("entity", entity);
code = -1;
}
this.init(model, context);
JSONObject ret = new JSONObject();
ret.put("code", code);
ret.put("msg", model.remove("message_info"));
ret.put("data", model);
return ret.toJSONString();
}
@RequestMapping(value = {"getData"},method = {RequestMethod.GET})
public Rest<Object> getData(Long projectId, ModelMap map) {
Rest<Object> ret = new Rest();
Map<String, Object> model = new HashMap();
Context context = this.getContext();
String busiDesc = "查询模板关联数据";
int code;
try {
GoviewMasterplateEntity goviewMasterplateEntity = goviewMasterplateService.get(projectId);
GoviewMasterplateDataEntity goviewMasterplateDataEntity = this.goviewMasterplateDataService.selectOne(new GoviewMasterplateDataQuery().masterplateId(projectId));
if(goviewMasterplateEntity!=null && goviewMasterplateDataEntity!=null){
byte[] bs= goviewMasterplateDataEntity.getContent();
String str="二进制转换错误";
str = new String(bs);
goviewMasterplateEntity.setContent(str);
}
model.put("data", goviewMasterplateEntity);
code = 1;
model.put("message_info", busiDesc + "成功");
this.recordSysLog(this.request, busiDesc + " 【成功】");
} catch (Exception var9) {
code = -1;
this.doException(this.request, busiDesc, model, var9);
}
ret.setCode(code);
ret.setData(model.get("data"));
ret.setDict(model.get("dict"));
ret.setMsg(model.get("message_info") == null ? "" : model.remove("message_info").toString());
return ret;
}
@PostMapping({"save/data"})
public String saveData(GoviewProjectDataEntity projectDataEntity) {
Map<String, Object> model = new HashMap();
Context context = this.getContext();
String busiDesc = "保存模板数据";
int code=1;
GoviewMasterplateDataEntity entity = new GoviewMasterplateDataEntity();
entity.setMasterplateId(projectDataEntity.getProjectId());
entity.setContent(projectDataEntity.getContent());
try {
IUser user = this.getCurUser();
if(entity.getMasterplateId()==null){
throw new AppException("模板ID不能为空");
}
GoviewMasterplateDataEntity old = goviewMasterplateDataService.selectOne(new GoviewMasterplateDataQuery().masterplateId(entity.getMasterplateId()));
if(old==null){
entity.setCreateTime(new Date());
entity.setUpdateTime(entity.getCreateTime());
if (user != null) {
entity.setCreateUserId(user.getId());
}
this.goviewMasterplateDataService.save(entity, context);
}else {
entity.setId(old.getId());
entity.setUpdateTime(new Date());
this.goviewMasterplateDataService.update(entity, context);
}
model.put("id", entity.getId());
model.put("entity", entity);
model.put("message_info", busiDesc + "成功");
this.recordSysLog(this.request, busiDesc + " 【成功】 [id:" + entity.getId() + "]");
} catch (Exception var7) {
this.doException(this.request, busiDesc, model, var7);
model.put("entity", entity);
code = -1;
}
this.init(model, context);
JSONObject ret = new JSONObject();
ret.put("code", code);
ret.put("msg", model.remove("message_info"));
ret.put("data", model);
return ret.toJSONString();
}
/**
* 使用模板
* @param entity
* @return
*/
@PostMapping({"use"})
public String useMasterplate(@RequestBody GoviewMasterplateEntity entity) {
Map<String, Object> model = new HashMap();
Context context = this.getContext();
String busiDesc = "使用模板";
int code=1;
try {
if(entity.getId()==null){
throw new AppException("模板ID不能为空");
}
goviewMasterplateService.useMasterplate(entity.getId(), context);
model.put("id", entity.getId());
model.put("entity", entity);
model.put("message_info", busiDesc + "成功");
this.recordSysLog(this.request, busiDesc + " 【成功】 [id:" + entity.getId() + "]");
} catch (Exception var7) {
this.doException(this.request, busiDesc, model, var7);
model.put("entity", entity);
code = -1;
}
this.init(model, context);
JSONObject ret = new JSONObject();
ret.put("code", code);
ret.put("msg", model.remove("message_info"));
ret.put("data", model);
return ret.toJSONString();
}
@RequestMapping(
value = {"delete"},
method = {RequestMethod.POST, RequestMethod.GET}
)
public String delete(Long[] id) {
Context context = this.getContext();
if (id == null) {
return this.createFailJsonResp("请至少选择一条记录");
} else {
Map<String, Object> model = new HashMap();
int code = 1;
String busiDesc = "删除模板";
try {
int iRet = this.goviewMasterplateService.remove(id, context);
model.put("message_info", "模板信息删除成功!删除条数:" + iRet);
this.recordSysLog(this.request, busiDesc + " 【成功】 [id:" + StringUtils.converArray2Str(id) + "]");
} catch (Exception var7) {
code = -1;
this.doException(this.request, busiDesc, model, var7);
}
JSONObject ret = new JSONObject();
ret.put("code", Integer.valueOf(code));
ret.put("msg", model.remove("message_info"));
ret.put("data", model);
return ret.toJSONString();
}
}
}
...@@ -347,4 +347,68 @@ public class GoviewProjectAPi extends BaseJsonBodyController { ...@@ -347,4 +347,68 @@ public class GoviewProjectAPi extends BaseJsonBodyController {
ret.put("data", model); ret.put("data", model);
return ret.toJSONString(); return ret.toJSONString();
} }
/**
* 发布为模板
* @param entity
* @return
*/
@PostMapping({"publish/masterplate"})
public String publishMasterplate(@RequestBody GoviewProjectEntity entity) {
Map<String, Object> model = new HashMap();
Context context = this.getContext();
String busiDesc = "发布模板";
int code=1;
try {
if(entity.getId()==null){
throw new AppException("项目ID不能为空");
}
goviewProjectService.publishMasterplate(entity.getId(), context);
model.put("id", entity.getId());
model.put("entity", entity);
model.put("message_info", busiDesc + "成功");
this.recordSysLog(this.request, busiDesc + " 【成功】 [id:" + entity.getId() + "]");
} catch (Exception var7) {
this.doException(this.request, busiDesc, model, var7);
model.put("entity", entity);
code = -1;
}
this.init(model, context);
JSONObject ret = new JSONObject();
ret.put("code", code);
ret.put("msg", model.remove("message_info"));
ret.put("data", model);
return ret.toJSONString();
}
@RequestMapping(
value = {"delete"},
method = {RequestMethod.POST, RequestMethod.GET}
)
public String delete(Long[] id) {
Context context = this.getContext();
if (id == null) {
return this.createFailJsonResp("请至少选择一条记录");
} else {
Map<String, Object> model = new HashMap();
int code = 1;
String busiDesc = "删除項目";
try {
int iRet = this.goviewProjectService.remove(id, context);
model.put("message_info", "項目信息删除成功!删除条数:" + iRet);
this.recordSysLog(this.request, busiDesc + " 【成功】 [id:" + StringUtils.converArray2Str(id) + "]");
} catch (Exception var7) {
code = -1;
this.doException(this.request, busiDesc, model, var7);
}
JSONObject ret = new JSONObject();
ret.put("code", Integer.valueOf(code));
ret.put("msg", model.remove("message_info"));
ret.put("data", model);
return ret.toJSONString();
}
}
} }
\ No newline at end of file
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