package org.coody.reduce.controller;
import java.util.Date;
import java.util.List;
import org.coody.framework.core.annotation.AutoBuild;
import org.coody.framework.core.util.CommonUtil;
import org.coody.framework.core.util.reflex.PropertUtil;
import org.coody.framework.jdbc.entity.Pager;
import org.coody.framework.minicat.web.adapter.JsonMealAdapter;
import org.coody.framework.minicat.web.annotation.JsonOut;
import org.coody.framework.minicat.web.annotation.ParamsAdapt;
import org.coody.framework.minicat.web.annotation.PathBinding;
import org.coody.reduce.common.annotation.LoginCheck;
import org.coody.reduce.common.enm.ResultCode;
import org.coody.reduce.common.util.PECode;
import org.coody.reduce.controller.base.BaseController;
import org.coody.reduce.domain.AppInfo;
import org.coody.reduce.domain.ShortInfo;
import org.coody.reduce.dto.ShortInfoDTO;
import org.coody.reduce.service.AppService;
import org.coody.reduce.service.ShortService;
@PathBinding("/short")
@JsonOut
public class ShortController extends BaseController {
@AutoBuild
ShortService shortService;
@AutoBuild
AppService appService;
@PathBinding("/create")
public Object create(String unionId, String url) {
AppInfo app = appService.fromUnionId(unionId);
if (CommonUtil.isNullOrEmpty(app)) {
return ResultCode.E_1001_APP_EXISTS.toMsgEntity();
}
if (app.getStatus() != 1) {
return ResultCode.E_1002_APP_UNAVAILABLE.toMsgEntity();
}
ShortInfo info = new ShortInfo();
info.setUrl(url);
info.setCreateTime(new Date());
info.setUserId(app.getUserId());
info.setAppId(app.getId());
Long id = shortService.insert(info);
if (id < 1) {
return ResultCode.E_500_SYS_BUSY.toMsgEntity();
}
String shorter = request.getBasePath() + "/" + PECode.encode(id);
return ResultCode.E_200_SUCCESS.toMsgEntity(shorter);
}
@LoginCheck
@PathBinding("/info")
public Object save(Long id) {
ShortInfo shorter = shortService.fromId(id);
if (shorter == null) {
return ResultCode.E_403_NOT_EXISTS.toMsgEntity();
}
Integer userId = getCurrentUserId();
if (shorter.getUserId() != userId.intValue()) {
return ResultCode.E_403_NOT_EXISTS.toMsgEntity();
}
return ResultCode.E_200_SUCCESS.toMsgEntity(shorter);
}
@LoginCheck
@PathBinding("/save")
@ParamsAdapt(JsonMealAdapter.class)
public Object save(ShortInfo info) {
if (!CommonUtil.isNullOrEmpty(info.getId())) {
ShortInfo shorter = shortService.fromId(info.getId());
if (shorter == null) {
return ResultCode.E_403_NOT_EXISTS.toMsgEntity();
}
Integer userId = getCurrentUserId();
if (shorter.getUserId() != userId.intValue()) {
return ResultCode.E_403_NOT_EXISTS.toMsgEntity();
}
}
if (info.getAppId() == null) {
return ResultCode.E_1001_APP_EXISTS.toMsgEntity();
}
AppInfo app = appService.fromId(info.getAppId());
if (app == null) {
return ResultCode.E_1001_APP_EXISTS.toMsgEntity();
}
info.setUserId(getCurrentUserId());
Long code = shortService.save(info);
if (code < 1) {
return ResultCode.E_500_SYS_BUSY.toMsgEntity();
}
return ResultCode.E_200_SUCCESS.toMsgEntity();
}
@LoginCheck
@PathBinding("/del")
public Object del(Long id) {
ShortInfo shorter = shortService.fromId(id);
if (CommonUtil.isNullOrEmpty(shorter) || shorter.getUserId() != getCurrentUserId().intValue()) {
return ResultCode.E_403_NOT_EXISTS.toMsgEntity();
}
Long code = shortService.del(id);
if (code < 1) {
return ResultCode.E_500_SYS_BUSY.toMsgEntity();
}
return ResultCode.E_200_SUCCESS.toMsgEntity();
}
@LoginCheck
@PathBinding("/page")
@ParamsAdapt(JsonMealAdapter.class)
public Object page(Pager pager, ShortInfo shorter) {
if (shorter == null) {
shorter = new ShortInfo();
}
if (pager == null) {
pager = new Pager();
}
shorter.setUserId(getCurrentUserId());
pager = shortService.findPager(pager, shorter);
if (!CommonUtil.isNullOrEmpty(pager.getData())) {
List<ShortInfoDTO> dtos = PropertUtil.getNewList(pager.getData(), ShortInfoDTO.class);
for (ShortInfoDTO dto : dtos) {
String shortUrl = request.getBasePath() + "/" + PECode.encode(dto.getId());
dto.setShortUrl(shortUrl);
AppInfo app = appService.fromId(dto.getAppId());
dto.setAppName(app == null ? "" : app.getName());
}
pager.setData(dtos);
}
return ResultCode.E_200_SUCCESS.toMsgEntity(pager);
}
}
Java程序员-张凯
- 粉丝: 1w+
- 资源: 7527
最新资源
- springboot项目家乡特色推荐系统.zip
- 电源开关电源200W 12V 24V,0.95效率 集成PFC+LLC方案稳定,电路外围简单,工作稳定,多重保护,低纹波,低成本,超高效率,芯片好买 电源架构PFC+LLC+同步整流,高效率高功率
- springboot项目基于vue的地方美食分享网站.zip
- springboot项目基于web的智慧养老平台.zip
- springboot项目基于Web的社区医院管理服务系统.zip
- springboot项目基于Springboot的漫画网站.zip
- springboot项目基于vue的MOBA类游戏攻略分享平台.zip
- springboot项目基于SpringBoot的冬奥会科普平台.zip
- [Matlab Simulink] 电动汽车制动能量回收 刹车充电仿真 PMSM永磁同步电机转速SVPWM控制 双有源桥DAB移相控制 电动汽车充放电 个人搭建,确保运行
- springboot项目基于Java的超市进销存系统.zip
- springboot项目基于Spring Boot的在线考试系统.zip
- springboot项目基于SpringBoot的CSGO赛事管理系统.zip
- springboot项目广场舞团.zip
- springboot项目高校食堂移动预约点餐系统.zip
- springboot项目会员制医疗预约服务管理信息系统.zip
- springboot项目福聚苑社区团购.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈