package ${basePackage}.${packageName}.controller.web;
|
|
import cn.huge.base.common.utils.ReturnFailUtils;
|
import cn.huge.base.common.utils.ReturnSucUtils;
|
import ${basePackage}.${packageName}.domain.po.${className};
|
import ${basePackage}.${packageName}.service.${className}Service;
|
import com.google.common.collect.Maps;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.PageRequest;
|
import org.springframework.data.domain.Sort;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.servlet.http.HttpServletRequest;
|
import java.util.Map;
|
import java.util.stream.Collectors;
|
import java.util.stream.Stream;
|
|
/**
|
* @title: ${tableComments}接口api-web端
|
* @description: ${tableComments}接口api-web端
|
* @company: hugeinfo
|
* @author: ${author}
|
* @time: ${createTime}
|
* @version: ${version}
|
*/
|
@Slf4j
|
@RestController
|
@RequestMapping("/api/web<#if classPath??>/${classPath}</#if>")
|
public class ${className}WebController {
|
|
@Autowired(required = false)
|
private HttpServletRequest request;
|
|
@Autowired
|
private ${className}Service service;
|
|
/**
|
* 获取请求URL参数
|
* @return Map<String, Object>
|
*/
|
private Map<String, Object> getParameter(){
|
Map<String, Object> terms = Maps.newHashMap();
|
<#list cols as col>
|
<#if (col.name!="create_time" && col.name!="update_time")>
|
// ${col.comments}
|
String ${col.fieldName} = request.getParameter("${col.fieldName}");
|
if (StringUtils.isNotBlank(${col.fieldName})){
|
terms.put("${col.fieldName}", ${col.fieldName});
|
}
|
</#if>
|
</#list>
|
// 创建时间区间
|
String createStart = request.getParameter("createStart");
|
String createEnd = request.getParameter("createEnd");
|
if(StringUtils.isNotBlank(createStart) && StringUtils.isNotBlank(createEnd)) {
|
terms.put("createStart", createStart);
|
terms.put("createEnd", createEnd);
|
}
|
// 更新时间区间
|
String updateStart = request.getParameter("updateStart");
|
String updateEnd = request.getParameter("updateEnd");
|
if(StringUtils.isNotBlank(updateStart) && StringUtils.isNotBlank(updateEnd)) {
|
terms.put("updateStart", updateStart);
|
terms.put("updateEnd", updateEnd);
|
}
|
return terms;
|
}
|
|
/**
|
* 条件查询多个
|
* @url {ctx}/api/web<#if classPath??>/${classPath}</#if>/listQuery
|
* @return Object
|
*/
|
@GetMapping("/listQuery")
|
public Object listQuery() {
|
try {
|
Map<String, Object> terms = getParameter();
|
return ReturnSucUtils.getRepInfo(service.listTerms(terms));
|
} catch (Exception e) {
|
return ReturnFailUtils.getRepInfo();
|
}
|
}
|
|
/**
|
* 条件分页查询
|
* @url {ctx}/api/web<#if classPath??>/${classPath}</#if>/pageQuery
|
* @param page 页码
|
* @param size 每页数量
|
* @return Object
|
*/
|
@GetMapping("/pageQuery")
|
public Object pageQuery(@RequestParam(value = "page") int page, @RequestParam(value = "size") int size) {
|
try {
|
Map<String, Object> terms = getParameter();
|
Sort sort = Sort.by(Sort.Direction.DESC, "create_time");
|
PageRequest pageRequest = PageRequest.of(page-1, size, sort);
|
Page<${className}> ${lowerName}Page = service.pageQuery(pageRequest, terms);
|
return ReturnSucUtils.getRepInfo( "处理成功", ${lowerName}Page);
|
} catch (Exception e) {
|
return ReturnFailUtils.getRepInfo();
|
}
|
}
|
|
/**
|
* 根据编号查询单个
|
* @url {ctx}/api/web<#if classPath??>/${classPath}</#if>/getById
|
* @param id 主键编号
|
* @return Object
|
*/
|
@GetMapping("/getById")
|
public Object getById(@RequestParam(value = "id") String id) {
|
try {
|
return ReturnSucUtils.getRepInfo(service.getById(id));
|
} catch (Exception e) {
|
return ReturnFailUtils.getRepInfo();
|
}
|
}
|
|
/**
|
* 根据主键单个
|
* @url {ctx}/api/web<#if classPath??>/${classPath}</#if>/deleteById
|
* @param id 主键编号
|
* @return Object
|
*/
|
@GetMapping("/deleteById")
|
public Object deleteById(@RequestParam(value = "id") String id) {
|
try {
|
service.removeById(id);
|
return ReturnSucUtils.getRepInfo();
|
} catch (Exception e) {
|
return ReturnFailUtils.getRepInfo();
|
}
|
}
|
|
/**
|
* 新增或更新对象
|
* @url {ctx}/api/web<#if classPath??>/${classPath}</#if>/save${className}
|
* @param ${lowerName} 实体对象
|
* @return Object
|
*/
|
@PostMapping("/save${className}")
|
public Object save${className}(@RequestBody ${className} ${lowerName}) {
|
try {
|
service.save${className}(${lowerName});
|
return ReturnSucUtils.getRepInfo();
|
} catch (Exception e) {
|
return ReturnFailUtils.getRepInfo();
|
}
|
}
|
|
}
|