3 changed files with 174 additions and 11 deletions
@ -0,0 +1,77 @@ |
|||||
|
package ${package}.controller; |
||||
|
|
||||
|
import ${main}.commons.tools.page.PageData; |
||||
|
import ${main}.commons.tools.utils.ExcelUtils; |
||||
|
import ${main}.commons.tools.utils.Result; |
||||
|
import ${main}.commons.tools.validator.AssertUtils; |
||||
|
import ${main}.commons.tools.validator.ValidatorUtils; |
||||
|
import ${main}.commons.tools.validator.group.AddGroup; |
||||
|
import ${main}.commons.tools.validator.group.UpdateGroup; |
||||
|
import ${main}.commons.tools.validator.group.DefaultGroup; |
||||
|
import ${package}.dto.${className}DTO; |
||||
|
import ${package}.excel.${className}Excel; |
||||
|
import ${package}.service.${className}Service; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.web.bind.annotation.*; |
||||
|
|
||||
|
import javax.servlet.http.HttpServletResponse; |
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* ${comments} |
||||
|
* |
||||
|
* @author ${author} ${email} |
||||
|
* @since ${version} ${date} |
||||
|
*/ |
||||
|
@RestController |
||||
|
@RequestMapping("${pathName}") |
||||
|
public class ${className}Controller { |
||||
|
|
||||
|
@Autowired |
||||
|
private ${className}Service ${classname}Service; |
||||
|
|
||||
|
@GetMapping("page") |
||||
|
public Result<PageData<${className}DTO>> page(@RequestParam Map<String, Object> params){ |
||||
|
PageData<${className}DTO> page = ${classname}Service.page(params); |
||||
|
return new Result<PageData<${className}DTO>>().ok(page); |
||||
|
} |
||||
|
|
||||
|
@GetMapping("{id}") |
||||
|
public Result<${className}DTO> get(@PathVariable("id") String id){ |
||||
|
${className}DTO data = ${classname}Service.get(id); |
||||
|
return new Result<${className}DTO>().ok(data); |
||||
|
} |
||||
|
|
||||
|
@PostMapping |
||||
|
public Result save(@RequestBody ${className}DTO dto){ |
||||
|
//效验数据 |
||||
|
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class); |
||||
|
${classname}Service.save(dto); |
||||
|
return new Result(); |
||||
|
} |
||||
|
|
||||
|
@PutMapping |
||||
|
public Result update(@RequestBody ${className}DTO dto){ |
||||
|
//效验数据 |
||||
|
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class); |
||||
|
${classname}Service.update(dto); |
||||
|
return new Result(); |
||||
|
} |
||||
|
|
||||
|
@DeleteMapping |
||||
|
public Result delete(@RequestBody String[] ids){ |
||||
|
//效验数据 |
||||
|
AssertUtils.isArrayEmpty(ids, "id"); |
||||
|
${classname}Service.delete(ids); |
||||
|
return new Result(); |
||||
|
} |
||||
|
|
||||
|
@GetMapping("export") |
||||
|
public void export(@RequestParam Map<String, Object> params, HttpServletResponse response) throws Exception { |
||||
|
List<${className}DTO> list = ${classname}Service.list(params); |
||||
|
ExcelUtils.exportExcelToTarget(response, null, list, ${className}Excel.class); |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,87 @@ |
|||||
|
package ${package}.service.impl; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||
|
import ${main}.commons.mybatis.service.impl.BaseServiceImpl; |
||||
|
import ${main}.commons.tools.page.PageData; |
||||
|
import ${main}.commons.tools.utils.ConvertUtils; |
||||
|
import ${package}.commons.tools.constant.FieldConstant; |
||||
|
import ${package}.dao.${className}Dao; |
||||
|
import ${package}.dto.${className}DTO; |
||||
|
import ${package}.entity.${className}Entity; |
||||
|
import ${package}.redis.${className}Redis; |
||||
|
import ${package}.service.${className}Service; |
||||
|
import org.apache.commons.lang3.StringUtils; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
import org.springframework.transaction.annotation.Transactional; |
||||
|
|
||||
|
import java.util.Arrays; |
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
/** |
||||
|
* ${comments} |
||||
|
* |
||||
|
* @author ${author} ${email} |
||||
|
* @since ${version} ${date} |
||||
|
*/ |
||||
|
@Service |
||||
|
public class ${className}ServiceImpl extends BaseServiceImpl<${className}Dao, ${className}Entity> implements ${className}Service { |
||||
|
|
||||
|
@Autowired |
||||
|
private ${className}Redis ${classname}Redis; |
||||
|
|
||||
|
@Override |
||||
|
public PageData<${className}DTO> page(Map<String, Object> params) { |
||||
|
IPage<${className}Entity> page = baseDao.selectPage( |
||||
|
getPage(params, FieldConstant.CREATED_TIME, false), |
||||
|
getWrapper(params) |
||||
|
); |
||||
|
return getPageData(page, ${className}DTO.class); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public List<${className}DTO> list(Map<String, Object> params) { |
||||
|
List<${className}Entity> entityList = baseDao.selectList(getWrapper(params)); |
||||
|
|
||||
|
return ConvertUtils.sourceToTarget(entityList, ${className}DTO.class); |
||||
|
} |
||||
|
|
||||
|
private QueryWrapper<${className}Entity> getWrapper(Map<String, Object> params){ |
||||
|
String id = (String)params.get(FieldConstant.ID_HUMP); |
||||
|
|
||||
|
QueryWrapper<${className}Entity> wrapper = new QueryWrapper<>(); |
||||
|
wrapper.eq(StringUtils.isNotBlank(id), FieldConstant.ID, id); |
||||
|
|
||||
|
return wrapper; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public ${className}DTO get(String id) { |
||||
|
${className}Entity entity = baseDao.selectById(id); |
||||
|
return ConvertUtils.sourceToTarget(entity, ${className}DTO.class); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
@Transactional(rollbackFor = Exception.class) |
||||
|
public void save(${className}DTO dto) { |
||||
|
${className}Entity entity = ConvertUtils.sourceToTarget(dto, ${className}Entity.class); |
||||
|
insert(entity); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
@Transactional(rollbackFor = Exception.class) |
||||
|
public void update(${className}DTO dto) { |
||||
|
${className}Entity entity = ConvertUtils.sourceToTarget(dto, ${className}Entity.class); |
||||
|
updateById(entity); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
@Transactional(rollbackFor = Exception.class) |
||||
|
public void delete(String[] ids) { |
||||
|
// 逻辑删除(@TableLogic 注解) |
||||
|
baseDao.deleteBatchIds(Arrays.asList(ids)); |
||||
|
} |
||||
|
|
||||
|
} |
Loading…
Reference in new issue