package com.yeshi.fanli.controller.admin;
|
|
import java.io.InputStream;
|
import java.io.PrintWriter;
|
import java.util.ArrayList;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.UUID;
|
|
import javax.annotation.Resource;
|
|
import net.sf.json.JSONObject;
|
|
import org.springframework.stereotype.Controller;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.multipart.commons.CommonsMultipartFile;
|
import org.yeshi.utils.JsonUtil;
|
import org.yeshi.utils.tencentcloud.COSManager;
|
|
import com.google.gson.Gson;
|
import com.google.gson.GsonBuilder;
|
import com.google.gson.reflect.TypeToken;
|
import com.yeshi.fanli.entity.admin.InviteGetMoney;
|
import com.yeshi.fanli.entity.bus.invite.SpreadImg;
|
import com.yeshi.fanli.service.AdminUserService;
|
import com.yeshi.fanli.service.inter.config.InviteGetMoneyService;
|
import com.yeshi.fanli.service.inter.goods.TaoBaoGoodsBriefService;
|
import com.yeshi.fanli.tag.PageEntity;
|
import com.yeshi.fanli.util.Constant;
|
import com.yeshi.fanli.util.GsonUtil;
|
import com.yeshi.fanli.util.StringUtil;
|
|
@Controller
|
@RequestMapping("admin/new/api/v1/inviteGetMoney")
|
public class InviteGetMoneyAdminController {
|
|
@Resource
|
private InviteGetMoneyService inviteGetMoneyService;
|
|
|
|
@Resource
|
private TaoBaoGoodsBriefService taoBaoGoodsBriefService;
|
|
@Resource
|
private AdminUserService adminUserService;
|
|
|
|
/**
|
*
|
* 方法说明: 查询邀请榜单列表
|
* @author mawurui
|
* createTime 2018年3月30日 上午11:32:02
|
* @param pageIndex
|
* @param key
|
* @param out
|
*/
|
@RequestMapping(value="/inviteGetMoneyList",method=RequestMethod.POST)
|
public void inviteGetMoneyList(int pageIndex, String key,PrintWriter out){
|
//查询商品总数
|
Integer totalCount = inviteGetMoneyService.getCount();
|
int totalPage = totalCount % Constant.PAGE_SIZE == 0 ? totalCount
|
/ Constant.PAGE_SIZE : totalCount / Constant.PAGE_SIZE + 1;
|
PageEntity pageEntity = new PageEntity(pageIndex, Constant.PAGE_SIZE, totalCount,
|
totalPage);
|
Map<String, String> map = new HashMap<String, String>();
|
map.put("key", key);
|
pageEntity.setParams(map);
|
//分页查询所有榜单用户
|
List<InviteGetMoney> inviteGetMoneyList = inviteGetMoneyService.inviteGetMoneyList(pageIndex-1, key);
|
|
JSONObject data=new JSONObject();
|
data.put("pageEntity", JsonUtil.getSimpleGsonWithDate().toJson(pageEntity));
|
data.put("inviteGetMoneyList", JsonUtil.getSimpleGsonWithDate().toJson(inviteGetMoneyList));
|
out.print(JsonUtil.loadTrue(0, JsonUtil.getSimpleGson().toJson(data), "成功"));
|
}
|
|
/**
|
*
|
* 方法说明: 删除榜单成员
|
* @author mawurui
|
* createTime 2018年3月30日 下午12:00:38
|
* @param ids
|
* @param out
|
*/
|
@RequestMapping(value="/deleteInviteGetMoney", method=RequestMethod.POST)
|
public void deleteInviteGetMoney(long[] ids, PrintWriter out){
|
for (long id : ids) {
|
inviteGetMoneyService.deleteInviteGetMoney(id);
|
}
|
out.print(JsonUtil.loadTrueResult("删除成功"));
|
}
|
|
/***
|
*
|
* 方法说明: 修改榜单信息
|
* @author mawurui
|
* createTime 2018年3月30日 上午9:29:46
|
* @param id
|
* @param out
|
*/
|
@RequestMapping(value="/updateInviteGetMoney", method=RequestMethod.POST)
|
public void updateInviteGetMoney(InviteGetMoney InviteGetMoney , PrintWriter out) {
|
inviteGetMoneyService.updateInviteGetMoney(InviteGetMoney);
|
out.print(JsonUtil.loadTrueResult("修改成功"));
|
}
|
|
/**
|
*
|
* 方法说明: 查询每日任务详情(页面反显)
|
* @author mawurui
|
* createTime 2018年3月30日 上午9:32:52
|
* @param id
|
* @return
|
*/
|
@RequestMapping(value="/getInviteGetMoney", method=RequestMethod.POST)
|
public void getInviteGetMoney(long id, PrintWriter out) {
|
InviteGetMoney inviteGetMoney = inviteGetMoneyService.getInviteGetMoney(id);
|
JSONObject data = new JSONObject();
|
data.put("inviteGetMoney", GsonUtil.toDFJson(inviteGetMoney));
|
out.print(JsonUtil.loadTrueResult(0, data));
|
}
|
|
|
/**
|
*
|
* 方法说明: 添加邀请好友图片
|
* @author mawurui
|
* createTime 2018年4月3日 下午2:54:19
|
* @param spreadImgPrintWriter
|
*/
|
@RequestMapping(value="/addInviteFriendImg", method=RequestMethod.POST)
|
public void addInviteFriendImg(SpreadImg spreadImg, String url, PrintWriter out) {
|
if(url == null || url.equals("")) {
|
out.print(JsonUtil.loadTrueResult("请输入url"));
|
return;
|
}
|
inviteGetMoneyService.addInviteFriendImg(spreadImg, url);
|
out.print(JsonUtil.loadTrueResult("添加成功"));
|
}
|
|
/**
|
*
|
* 方法说明: 分页查询 邀请图片
|
* @author mawurui
|
* createTime 2018年4月3日 上午11:32:17
|
* @param pageIndex
|
* @return
|
*/
|
@RequestMapping(value="/inviteFriendImgList", method=RequestMethod.POST)
|
public void inviteFriendImgList(int pageIndex, String key, PrintWriter out) {
|
Integer totalCount = inviteGetMoneyService.spreadImgCount();
|
int totalPage = totalCount % Constant.PAGE_SIZE == 0 ? totalCount
|
/ Constant.PAGE_SIZE : totalCount / Constant.PAGE_SIZE + 1;
|
PageEntity pageEntity = new PageEntity(pageIndex, Constant.PAGE_SIZE, totalCount,
|
totalPage);
|
|
List<SpreadImg> spreadImgList = inviteGetMoneyService.spreadImgList(pageIndex-1, "");
|
|
JSONObject data=new JSONObject();
|
data.put("pageEntity", JsonUtil.getSimpleGsonWithDate().toJson(pageEntity));
|
data.put("spreadImgList", JsonUtil.getSimpleGsonWithDate().toJson(spreadImgList));
|
out.print(JsonUtil.loadTrue(0, JsonUtil.getSimpleGson().toJson(data), "成功"));
|
}
|
|
/**
|
*
|
* 方法说明: 删除邀请好友图片
|
* @author mawurui
|
* createTime 2018年3月30日 下午12:00:38
|
* @param ids
|
* @param out
|
*/
|
@RequestMapping(value="/deleteInviteFriendImg", method=RequestMethod.POST)
|
public void deleteInviteFriendImg(long[] ids, PrintWriter out){
|
for (long id : ids) {
|
inviteGetMoneyService.deleteInviteFriendImg(id);
|
}
|
out.print(JsonUtil.loadTrueResult("删除成功"));
|
}
|
|
/**
|
*
|
* 方法说明: 查询邀请好友图片详情(页面反显)
|
* @author mawurui
|
* createTime 2018年3月30日 上午9:32:52
|
* @param id
|
* @return
|
*/
|
@RequestMapping(value="/getInviteSpreadImg", method=RequestMethod.POST)
|
public void getInviteSpreadImg(long id, PrintWriter out) {
|
SpreadImg spreadImg = inviteGetMoneyService.getInviteSpreadImg(id);
|
JSONObject data = new JSONObject();
|
data.put("spreadImg", GsonUtil.toDFJson(spreadImg));
|
out.print(JsonUtil.loadTrueResult(0, data));
|
}
|
|
/**
|
*
|
* 方法说明: 修改邀请好友图片
|
* @author mawurui
|
* createTime 2018年4月3日 下午2:45:47
|
* @param everyDayTask
|
* @param out
|
*/
|
@RequestMapping(value="/updateInviteSpreadImg", method=RequestMethod.POST)
|
public void updateInviteSpreadImg(SpreadImg spreadImg , PrintWriter out) {
|
inviteGetMoneyService.updateInviteSpreadImg(spreadImg);
|
out.print(JsonUtil.loadTrueResult("修改成功"));
|
}
|
|
/**
|
*
|
* 方法说明: 查询活动规则
|
* @author mawurui
|
* createTime 2018年5月16日 下午3:28:01
|
*/
|
@RequestMapping(value="/getActivityRules", method=RequestMethod.POST)
|
public void getActivityRules(PrintWriter out) {
|
String key = "activityRules";
|
String activityRules = inviteGetMoneyService.getActivityRules(key);
|
JSONObject data = new JSONObject();
|
data.put("activityRules", activityRules);
|
out.print(JsonUtil.loadTrueResult(data));
|
}
|
|
/**
|
*
|
* 方法说明: 编辑活动规则
|
* @author mawurui
|
* createTime 2018年5月16日 下午3:45:24
|
* @param out
|
*/
|
@RequestMapping(value="/editActivityRules", method=RequestMethod.POST)
|
public void editActivityRules(String value, PrintWriter out) {
|
String key = "activityRules";
|
inviteGetMoneyService.editActivityRules(value, key);
|
out.print(JsonUtil.loadTrueResult("修改成功"));
|
}
|
|
|
/**
|
* 专题图片上传
|
* @param file
|
* @param uid
|
* @param id
|
* @param request
|
* @param response
|
* @param out
|
*/
|
@RequestMapping(value = "saveAdd")
|
public void saveAdd(@RequestParam("file") CommonsMultipartFile file, Long id, PrintWriter out) {
|
|
if (file == null) {
|
out.print(JsonUtil.loadFalseResult("上传文件为空"));
|
return;
|
}
|
|
try {
|
InputStream inputStream = file.getInputStream();
|
String contentType = file.getContentType();
|
String type = contentType.substring(contentType.indexOf("/") + 1);
|
// 上传文件相对位置
|
String fileUrl="/img/invite/"+UUID.randomUUID().toString().replace("-", "") + "." + type;
|
|
String uploadFilePath = COSManager.getInstance().uploadFile(inputStream, fileUrl).getUrl();
|
if (StringUtil.isNullOrEmpty(uploadFilePath)) {
|
out.print(JsonUtil.loadFalseResult("图片上传失败"));
|
return;
|
}
|
|
SpreadImg spreadImg = new SpreadImg();
|
inviteGetMoneyService.addInviteFriendImg(spreadImg, uploadFilePath);
|
|
out.print(JsonUtil.loadTrueResult("上传成功"));
|
|
} catch (Exception e) {
|
out.print(JsonUtil.loadFalseResult("操作失败"));
|
e.printStackTrace();
|
}
|
}
|
|
/**
|
* 查询
|
* @param callback
|
* @param pageIndex
|
* @param pageSize
|
* @param key 模糊查询:说明、标识
|
* @param out
|
*/
|
@RequestMapping(value = "query")
|
public void query(String callback, Integer pageIndex, Integer pageSize, String key,
|
Integer sort, PrintWriter out) {
|
|
if (pageIndex == null || pageIndex < 1) {
|
pageIndex = 1;
|
}
|
|
if (pageSize == null || pageSize < 1) {
|
pageSize = Constant.PAGE_SIZE;
|
}
|
|
try {
|
List<SpreadImg> list = inviteGetMoneyService.listQuery((pageIndex - 1) * pageSize, pageSize, key);
|
|
if (list == null || list.size() == 0) {
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("暂无数据"));
|
return;
|
}
|
|
long count = inviteGetMoneyService.countQuery(key);
|
|
int totalPage = (int) (count % pageSize == 0 ? count / pageSize : count / pageSize + 1);
|
PageEntity pe = new PageEntity(pageIndex, pageSize, count, totalPage);
|
|
GsonBuilder gsonBuilder = new GsonBuilder();
|
gsonBuilder.serializeNulls();
|
Gson gson = gsonBuilder.setDateFormat("yyyy/MM/dd HH:mm:ss").create();
|
|
JSONObject data = new JSONObject();
|
data.put("pe", pe);
|
data.put("result_list", gson.toJson(list));
|
|
JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
|
|
} catch (Exception e) {
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作异常"));
|
e.printStackTrace();
|
}
|
}
|
|
/**
|
* 删除
|
* @param callback
|
* @param idArray
|
* @param out
|
*/
|
@RequestMapping(value = "delete")
|
public void delete(String callback, String idArray, PrintWriter out) {
|
|
try {
|
if (StringUtil.isNullOrEmpty(idArray)) {
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("请选择操作的数据"));
|
return;
|
}
|
|
Gson gson = new Gson();
|
List<Long> list = gson.fromJson(idArray, new TypeToken<ArrayList<Long>>() {}.getType());
|
|
if (list == null || list.size() == 0) {
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("未检测到删除的数据"));
|
return;
|
}
|
|
for (Long id: list) {
|
SpreadImg spreadImg = inviteGetMoneyService.getInviteSpreadImg(id);
|
String url = spreadImg.getUrl();
|
if (!StringUtil.isNullOrEmpty(url)) {
|
COSManager.getInstance().deleteFile(url);
|
}
|
inviteGetMoneyService.deleteInviteFriendImg(id);
|
}
|
|
JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("删除成功"));
|
|
} catch (Exception e) {
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("删除失败"));
|
e.printStackTrace();
|
}
|
}
|
|
}
|