package cn.appinfodb.controller.developer;
import cn.appinfodb.entity.*;
import cn.appinfodb.service.DevUser.DevUserService;
import cn.appinfodb.service.appCategory.AppCategoryService;
import cn.appinfodb.service.appinfo.AppInfoService;
import cn.appinfodb.service.dataDictionary.DataDictionaryService;
import cn.appinfodb.service.version.AppVersionService;
import cn.appinfodb.util.Constants;
import cn.appinfodb.util.PageSupport;
import com.alibaba.fastjson.JSONArray;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang.math.RandomUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Controller
@RequestMapping("/appInfo")
public class AppInfoController {
@Autowired
private AppInfoService appInfoService;
/* @Autowired
private DevUserService devUserService;*/
@Autowired
private DataDictionaryService dataDictionaryService;
@Autowired
private AppCategoryService appCategoryService;
@Autowired
private AppVersionService appVersionService;
@RequestMapping("list")
public String getAppInfoList(String querySoftwareName,
Integer queryStatus,
Integer queryCategoryLevel1,
Integer queryCategoryLevel2,
Integer queryCategoryLevel3,
Integer queryFlatformId,
@RequestParam(defaultValue = "1")Integer pageIndex,
HttpSession session, Model model) throws Exception {
AppInfo appInfo = new AppInfo();
appInfo.setCategoryLevel1(queryCategoryLevel1);
if (queryCategoryLevel1!=null){
appInfo.setCategoryLevel2(queryCategoryLevel2);
}
if (queryCategoryLevel1!=null&&queryCategoryLevel2!=null){
appInfo.setCategoryLevel3(queryCategoryLevel3);
}
List<AppInfo> appInfoList = appInfoService.selectAppInfoList(querySoftwareName, queryStatus, appInfo, queryFlatformId, pageIndex, Constants.pageSize);
//总数量(表)
int totalCount = appInfoService.selectAppInfoCount(querySoftwareName, queryStatus, appInfo, queryFlatformId);
//总页数
PageSupport support = new PageSupport();
support.setCurrentPageNo(pageIndex);
support.setPageSize(Constants.pageSize);
support.setTotalCount(totalCount);
//将关于页面的信息封装到map里
Map<String, Integer> pages = new HashMap<>();
pages.put("totalCount",totalCount);//info数量
pages.put("currentPageNo",pageIndex);//当前页码
pages.put("totalPageCount",support.getTotalPageCount());//总页数
List<DataDictionary> statusList = dataDictionaryService.selectDataDictionaryList("APP_STATUS");
List<DataDictionary> flatFormList = dataDictionaryService.selectDataDictionaryList("APP_FLATFORM");
List<AppCategory> categoryLevel1List = appCategoryService.selectAppCategoryListByParentId(null);
model.addAttribute("appInfoList", appInfoList);
model.addAttribute("statusList", statusList);
model.addAttribute("flatFormList", flatFormList);
model.addAttribute("categoryLevel1List", categoryLevel1List);
model.addAttribute("pages", pages);
//参数回显
model.addAttribute("queryStatus", queryStatus);
model.addAttribute("querySoftwareName", querySoftwareName);
model.addAttribute("queryCategoryLevel1", queryCategoryLevel1);
model.addAttribute("queryCategoryLevel2", queryCategoryLevel2);
model.addAttribute("queryCategoryLevel3", queryCategoryLevel3);
model.addAttribute("queryFlatformId", queryFlatformId);
return "developer/appinfolist";
}
@RequestMapping("getDataDictionaryList")
@ResponseBody
public List<DataDictionary> getDataDictionaryList(String typeCode){
List<DataDictionary> dataDictionaryList = null;
try {
dataDictionaryList = dataDictionaryService.selectDataDictionaryList(typeCode);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return dataDictionaryList;
}
/**
* 分类
* @param pid
* @return
*/
@RequestMapping("getCategoryList")
@ResponseBody
public List<AppCategory> getCategoryList (Integer pid){
return appCategoryService.selectAppCategoryListByParentId(pid);
}
/**
* 增加app信息(跳转到新增appinfo页面)
* @param appInfo
* @return
*/
@RequestMapping("addappinfo")
public String toadd(@ModelAttribute("appInfo") AppInfo appInfo,Model model){
setAddModel(model);
return "developer/appinfoadd";
}
private void setAddModel(Model model) {
//获取所有所属平台信息
List<DataDictionary> flatFormList = dataDictionaryService.selectDataDictionaryList("APP_FLATFORM");
//获取一级菜单信息
List<AppCategory> categoryLevel1List = appCategoryService.selectAppCategoryListByParentId(null);
model.addAttribute("categoryLevel1List",categoryLevel1List);
model.addAttribute("flatFormList",flatFormList);
}
/**
* 查询AKPName是否存在
* @param APKName
* @return
*/
@RequestMapping("apkexist")
@ResponseBody
public String apkexist(String APKName){
if (APKName==null||APKName.equals("")){
return "empty";
}
if (appInfoService.selectInfoByAKPName(APKName)){
return "exist";
}else {
return "noexist";
}
}
@RequestMapping(value = "/addapp",method=RequestMethod.POST)
public String add(AppInfo appInfo, HttpSession session, HttpServletRequest request,Model model,
@RequestParam(value="a_logoPicPath",required= false) MultipartFile attach){
//保存路径
String logoPicPath = null;
//判断文件是否为空
if(!attach.isEmpty()){
String path = request.getSession().getServletContext().getRealPath("statics"+ File.separator+"uploadfiles");
String oldFileName = attach.getOriginalFilename();//原文件名
String prefix= FilenameUtils.getExtension(oldFileName);//原文件后缀
int filesize = 500000;
if(attach.getSize() > filesize){//上传大小不得超过 500k
request.setAttribute("fileUploadError", " * 上传大小不得超过 500k");
setAddModel(model);
return "developer/appinfoadd";
}else if(prefix.equalsIgnoreCase("jpg") || prefix.equalsIgnoreCase("png")
|| prefix.equalsIgnoreCase("jpeg") || prefix.equalsIgnoreCase("pneg")){//上传图片格式不正确
String fileName = System.currentTimeMillis()+ RandomUtils.nextInt(1000000)+"_Personal.jpg";
/* logger.debug("new fileName======== " + attach.getName());*/
File targetFile = new File(path, fileName);
if(!targetFile.exists()){
targetFile.mkdirs();
}
//保存
try {
attach.transferTo(targetFile);
} catch (Exception e) {
e.printStackTrace();
评论0