package com.fgkj.controller;
|
|
import java.io.File;
|
import java.io.IOException;
|
import java.io.InputStream;
|
import java.io.OutputStream;
|
import java.sql.Blob;
|
import java.sql.SQLException;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
import com.fgkj.mapper.UinfDaoFactory;
|
import com.fgkj.dto.ServiceModel;
|
import com.fgkj.dto.User_Chart;
|
import com.fgkj.dto.User_inf;
|
import com.fgkj.dto.User_log;
|
import com.fgkj.services.User_ChartService;
|
import com.fgkj.services.User_logService;
|
import io.swagger.annotations.Api;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.*;
|
|
@RequestMapping("userChart")
|
@RestController
|
@Api
|
public class User_ChartController{
|
@Autowired
|
private User_ChartService service;
|
@Autowired
|
private User_logService uservice;
|
|
// private List<File> file;
|
// private List<String> fileFileName;
|
// private List<String> filetype;
|
|
// private User_Chart uc;
|
|
private static Map<String,String> fileUtil = new HashMap<String, String>(){
|
{
|
put("logo","logo.png");
|
put("normal","home_normal.gif");
|
put("behind","home_behind.gif");
|
put("timeout","home_timeout.gif");
|
put("warn","home_warn.gif");
|
//添加61850设备对应的kk --》文件名称
|
put("nuclear","home_warn.gif");
|
put("devalarm","home_warn.gif");
|
put("precharge","home_warn.gif");
|
put("onlinecharge","home_warn.gif");
|
}
|
};
|
|
//添加图标
|
@PostMapping("/")
|
public ServiceModel add(@RequestBody User_Chart uchart,@RequestBody List<File> file,List<String> filetype){
|
suitFiles(file,filetype,uchart);
|
ServiceModel model =service.add(uchart);
|
{
|
String msg="添加"+uchart.getChart_name()+"班组图表";
|
User_log ulog=UinfDaoFactory.CreateULog(UinfDaoFactory.Increase, msg);
|
uservice.add(ulog);//将用户的操作记录下来
|
}
|
|
return model;
|
}
|
|
|
//修改图标信息
|
@PutMapping("/")
|
public ServiceModel update(@RequestBody User_Chart uchart,@RequestBody List<File>file,@RequestBody List<String>filetype){
|
suitFiles(file,filetype,uchart); //设置对象的属性值
|
ServiceModel model =service.update(uchart);
|
{
|
String msg="修改"+uchart.getChart_name()+"班组图表";
|
User_log ulog=UinfDaoFactory.CreateULog(UinfDaoFactory.Alter, msg);
|
uservice.add(ulog);//将用户的操作记录下来
|
}
|
|
return model;
|
}
|
//删除图标
|
@DeleteMapping("/")
|
public ServiceModel del(@RequestBody User_Chart uchart){
|
ServiceModel model =service.del(uchart);
|
{
|
String msg="删除"+uchart.getChart_name()+"班组图表";
|
User_log ulog=UinfDaoFactory.CreateULog(UinfDaoFactory.Delete, msg);
|
uservice.add(ulog);//将用户的操作记录下来
|
}
|
|
return model;
|
}
|
|
//查询所有图标
|
@GetMapping("all")
|
public ServiceModel searchAll(){
|
ServiceModel model =service.searchAll();
|
|
return model;
|
}
|
|
//根据用户id查图表
|
@GetMapping("byCondition")
|
public ServiceModel serchByCondition(@RequestBody User_inf uinf){
|
ServiceModel model =service.serchByCondition(uinf);
|
|
return model;
|
}
|
|
//根据chartfile和列名查具体的图片
|
@GetMapping("byInfo")
|
public void serchByInfo(@RequestBody User_Chart uc){
|
//System.out.println(json);
|
InputStream is = null;
|
OutputStream os =null;
|
ServiceModel model = service.serchByInfo(uc);
|
if(model.code == 1){
|
List list = (List) model.getData();
|
Blob blob = (Blob) list.get(0);
|
try {
|
is = blob.getBinaryStream();
|
os = ActionUtil.getResponse().getOutputStream();
|
byte[] image = ActionUtil.IStoByteArr(is);
|
os.write(image);
|
os.flush();
|
} catch (SQLException e) {
|
e.printStackTrace();
|
} catch (IOException e) {
|
e.printStackTrace();
|
} finally{
|
if(os != null){
|
try {
|
os.close();
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
}
|
}
|
}
|
}
|
|
/**
|
* 将文件设置到指定的对象中去
|
* @param files
|
* @param ftype
|
* @param uc
|
*/
|
private void suitFiles(List<File> files,List<String> ftype,User_Chart uc){
|
for(int i=0;i<files.size() && i<ftype.size();i++){
|
if("logo".equals(ftype.get(i))){
|
uc.setChart_logo(files.get(i));
|
}else if("normal".equals(ftype.get(i))){
|
uc.setChart_normal(files.get(i));
|
}else if("behind".equals(ftype.get(i))){
|
uc.setChart_behind(files.get(i));
|
}else if("timeout".equals(ftype.get(i))){
|
uc.setChart_timeout(files.get(i));
|
}else if("warn".equals(ftype.get(i))){
|
uc.setChart_warn(files.get(i));
|
}else if("nuclear".equals(ftype.get(i))){
|
uc.setChart_nuclear_cap(files.get(i));
|
}else if("devalarm".equals(ftype.get(i))){
|
uc.setChart_dev_alarm(files.get(i));
|
}else if("precharge".equals(ftype.get(i))){
|
uc.setChart_pre_charge(files.get(i));
|
}else if("onlinecharge".equals(ftype.get(i))){
|
uc.setChart_online_charge(files.get(i));
|
}
|
|
}
|
}
|
|
}
|