421 lines
12 KiB
Plaintext
421 lines
12 KiB
Plaintext
package com.nationalelectric.greenH5.bizc;
|
||
|
||
import java.io.File;
|
||
import java.io.InputStream;
|
||
import java.io.Serializable;
|
||
import java.io.UnsupportedEncodingException;
|
||
import java.net.URLDecoder;
|
||
import java.text.SimpleDateFormat;
|
||
import java.util.Date;
|
||
import java.util.List;
|
||
import java.util.Map;
|
||
|
||
import javax.annotation.Resource;
|
||
import javax.servlet.http.HttpServletRequest;
|
||
|
||
import org.springframework.beans.factory.annotation.Autowired;
|
||
import org.springframework.stereotype.Service;
|
||
|
||
import com.nationalelectric.greenH5.po.GreenImageInfo;
|
||
import com.nationalelectric.greenH5.utils.Base64Utils;
|
||
import com.sgcc.uap.persistence.IHibernateDao;
|
||
|
||
@Service("baseService")
|
||
public class BaseServiceImpl implements Serializable {
|
||
|
||
/**
|
||
* HibernateDao逻辑构件
|
||
*/
|
||
@Autowired
|
||
IHibernateDao hibernateDao;
|
||
|
||
@Resource
|
||
private IGreenImageInfoBizc greenimageinfoBizc;
|
||
|
||
private String appImageUrl;
|
||
|
||
private String appImgDir;
|
||
|
||
private String webImgDir;
|
||
|
||
private String webImageUrl;
|
||
|
||
@SuppressWarnings("unchecked")
|
||
public List<Map<String, String>> getDictionaryInfo(String dataType, String dataCode) {
|
||
String sql = "SELECT di.data_value FROM GREEN_DICTIONARY_INFO di WHERE di.is_deleted = 'N' AND di.data_type = ? AND di.data_code = ? ORDER BY di.data_sort";
|
||
return hibernateDao.queryForListWithSql(sql, new Object[] { dataType, dataCode });
|
||
}
|
||
|
||
public void initImage(){
|
||
this.appImgDir = null;
|
||
this.appImageUrl = null;
|
||
}
|
||
/**
|
||
* 查询app访问的url
|
||
*
|
||
* @return
|
||
*/
|
||
public String getAppImgUrl() {
|
||
if(appImageUrl != null){
|
||
return appImageUrl;
|
||
}
|
||
List<Map<String, String>> list = getDictionaryInfo("appImgUrl", "001");
|
||
if (list.size() == 0) {
|
||
return null;
|
||
}
|
||
Map<String, String> map = list.get(0);
|
||
appImageUrl = map.get("data_value");
|
||
return appImageUrl;
|
||
}
|
||
public String getWebImgUrl() {
|
||
if(webImageUrl != null){
|
||
return webImageUrl;
|
||
}
|
||
List<Map<String, String>> list = getDictionaryInfo("webImgUrl", "001");
|
||
if (list.size() == 0) {
|
||
return null;
|
||
}
|
||
Map<String, String> map = list.get(0);
|
||
webImageUrl = map.get("data_value");
|
||
return webImageUrl;
|
||
}
|
||
|
||
/**
|
||
* 查询app存储的dir
|
||
*
|
||
* @return
|
||
*/
|
||
public String getAppImgDir() {
|
||
if(appImgDir != null){
|
||
return appImgDir;
|
||
}
|
||
List<Map<String, String>> list = getDictionaryInfo("appImgDir", "001");
|
||
if (list.size() == 0) {
|
||
return null;
|
||
}
|
||
Map<String, String> map = list.get(0);
|
||
appImgDir = map.get("data_value");
|
||
return appImgDir;
|
||
}
|
||
|
||
public String getWebImgDir() {
|
||
if(webImgDir != null){
|
||
return webImgDir;
|
||
}
|
||
List<Map<String, String>> list = getDictionaryInfo("webImgDir", "001");
|
||
if (list.size() == 0) {
|
||
return null;
|
||
}
|
||
Map<String, String> map = list.get(0);
|
||
webImgDir = map.get("data_value");
|
||
return webImgDir;
|
||
}
|
||
|
||
private String getBase64Image(String id) {
|
||
/*
|
||
* String sqlString =
|
||
* "select image_content from GREEN_IMAGE_INFO where id = ?"; List<Map>
|
||
* list = hibernateDao.queryForListWithSql(sqlString, new Object[] { id
|
||
* }); if (list.size() == 0) { System.out.println("====== 没找到图片");
|
||
* return null; } Map infoMap = list.get(0); String ss =
|
||
* String.valueOf(infoMap.get("image_content"));
|
||
*/
|
||
if (id == null || id.equals("")) {
|
||
return null;
|
||
}
|
||
/**
|
||
* GreenImageInfo info = greenimageinfoBizc.get(id); if (info == null) {
|
||
* return null; } try { InputStream is =
|
||
* info.getImageContentBlob().getBinaryStream(); StringBuffer
|
||
* stringBuffer = new StringBuffer(); byte[] byt = new byte[4096]; for
|
||
* (int i; (i = is.read(byt)) != -1;) { stringBuffer.append(new
|
||
* String(byt, 0, i)); } ss = stringBuffer.toString(); } catch
|
||
* (Exception e) { e.printStackTrace(); }
|
||
**/
|
||
String sql = "select image_content_blob from green_image_info where id = ?";
|
||
List<Map> list = hibernateDao.queryForListWithSql(sql, new Object[] { id });
|
||
if (list.size() == 0) {
|
||
return null;
|
||
}
|
||
Map map = list.get(0);
|
||
byte[] imgbytes = (byte[]) map.get("image_content_blob");
|
||
return new String(imgbytes);
|
||
}
|
||
|
||
/**
|
||
* 访客预约
|
||
*
|
||
* @param id
|
||
* @return
|
||
*/
|
||
public String saveVisitorImg(Long id) {
|
||
String sqlString = "select * from GREEN_VISITOR_INFO where id = ? and img_status = 0";
|
||
List<Map> list = hibernateDao.queryForListWithSql(sqlString, new Object[] { id });
|
||
if (list.size() > 0) {
|
||
System.out.println("------- into saveVisitorImg ----------- ");
|
||
Map info = list.get(0);
|
||
Object p1 = info.get("IDcard_pic1_data");
|
||
Object p2 = info.get("IDcard_pic2_data");
|
||
|
||
String f1 = String.valueOf(p1);
|
||
String f2 = String.valueOf(p2);
|
||
|
||
// ----pic1
|
||
String s1 = getBase64Image(f1);
|
||
if (s1 != null) {
|
||
s1 = s1.substring(s1.indexOf(",") + 1);
|
||
// System.out.println(s1);
|
||
String d1 = getAppImgDir() + f1 + ".jpg";
|
||
Boolean b = Base64Utils.Base64ToImage(s1, d1);
|
||
System.out.println("------- into saveVisitorImg save 1 result :" + b);
|
||
}
|
||
|
||
// ----pic2
|
||
String s2 = getBase64Image(f2);
|
||
if (s2 != null) {
|
||
s2 = s2.substring(s2.indexOf(",") + 1);
|
||
String d2 = getAppImgDir() + f2 + ".jpg";
|
||
boolean b2 = Base64Utils.Base64ToImage(s2, d2);
|
||
System.out.println("------- into saveVisitorImg save 2 result :" + b2);
|
||
}
|
||
|
||
sqlString = "update GREEN_VISITOR_INFO set IDcard_pic1 = ? , IDcard_pic2 = ?, img_status = 1 where id = ? ";
|
||
hibernateDao.updateWithSql(sqlString, new Object[] { f1 + ".jpg", f2 + ".jpg", id });
|
||
|
||
System.out.println("------- into saveVisitorImg ok update ");
|
||
|
||
// --------随访人员
|
||
String v_sql = "select id, IDcard_pic1_data p1, IDcard_pic2_data p2 from GREEN_RETINUE_INFO where visitor_id = ?";
|
||
List<Map> v_list = hibernateDao.queryForListWithSql(v_sql, new Object[] { id });
|
||
for (Map map : v_list) {
|
||
String picId = String.valueOf(map.get("id"));
|
||
// ------pc1
|
||
String v1 = String.valueOf(map.get("p1"));
|
||
String c1 = getBase64Image(v1);
|
||
if (c1 != null) {
|
||
c1 = c1.substring(c1.indexOf(",") + 1);
|
||
String dv1 = getAppImgDir() + v1 + ".jpg";
|
||
Base64Utils.Base64ToImage(c1, dv1);
|
||
}
|
||
// ------pc2
|
||
String v2 = String.valueOf(map.get("p2"));
|
||
String c2 = getBase64Image(v2);
|
||
if (c2 != null) {
|
||
c2 = c2.substring(c2.indexOf(",") + 1);
|
||
String dv2 = getAppImgDir() + v2 + ".jpg";
|
||
Base64Utils.Base64ToImage(c2, dv2);
|
||
}
|
||
|
||
sqlString = "update GREEN_RETINUE_INFO set IDcard_pic1 = ? , IDcard_pic2 = ? where id = ? ";
|
||
hibernateDao.updateWithSql(sqlString, new Object[] { v1 + ".jpg", v2 + ".jpg", picId });
|
||
}
|
||
|
||
}
|
||
return null;
|
||
}
|
||
// public boolean saveImgToIO(String fileName, String base64) {
|
||
// return Base64Utils.Base64ToImage(base64.substring(base64.indexOf(",") + 1), getAppImgDir() + fileName);
|
||
// }
|
||
|
||
public boolean saveImgToIO(String fileName, String base64) {
|
||
// URLEncoder.encode(content, "UTF-8");
|
||
// try {
|
||
// base64 = URLDecoder.decode(base64, "UTF-8");
|
||
// } catch (UnsupportedEncodingException e) {
|
||
// e.printStackTrace();
|
||
// }
|
||
String path = getAppImgDir();//"D:/ystp/";//
|
||
File filemulu =new File(path + fileName.substring(0, fileName.lastIndexOf("/")+1)); //如果文件夹不存在则创建
|
||
if (!filemulu.exists()) {
|
||
filemulu.mkdir();
|
||
}
|
||
return Base64Utils.Base64ToImage(base64.substring(base64.indexOf(",") + 1), path + fileName);
|
||
|
||
}
|
||
|
||
/**
|
||
* 用图片名称,取BASE64后的图片数据
|
||
*
|
||
* @param imgName
|
||
* @return
|
||
*/
|
||
public String getImageBase64(String imgName) {
|
||
if (imgName == null || imgName.equals("")) {
|
||
return null;
|
||
}
|
||
// String dir = getAppImgDir();
|
||
// String fileName = dir + imgName;
|
||
// StringBuffer stringBuffer = new StringBuffer();
|
||
// stringBuffer.append("data:image/jpeg;base64,");
|
||
// String ss = Base64Utils.ImageToBase64ByLocal(fileName);
|
||
// stringBuffer.append(ss);
|
||
// return stringBuffer.toString();
|
||
|
||
String appImageUrl = getAppImgUrl();
|
||
return appImageUrl + imgName;
|
||
}
|
||
public String getImageBase64ForWeek(String imgName) {
|
||
if (imgName == null || imgName.equals("")) {
|
||
return null;
|
||
}
|
||
// String dir = getAppImgDir();
|
||
// String fileName = dir + imgName;
|
||
// StringBuffer stringBuffer = new StringBuffer();
|
||
// stringBuffer.append("data:image/jpeg;base64,");
|
||
// String ss = Base64Utils.ImageToBase64ByLocal(fileName);
|
||
// stringBuffer.append(ss);
|
||
// return stringBuffer.toString();
|
||
|
||
String appImageUrl = getWebImgUrl();
|
||
return appImageUrl + imgName;
|
||
}
|
||
|
||
/**
|
||
* 施工申请
|
||
*
|
||
* @param id
|
||
* @return
|
||
*/
|
||
public String saveConstructImage(Long id) {
|
||
String sqlString = "select * from GREEN_CONSTRUCT_INFO where id = ? and img_status = 0";
|
||
List<Map> list = hibernateDao.queryForListWithSql(sqlString, new Object[] { id });
|
||
if (list.size() == 0) {
|
||
return null;
|
||
|
||
}
|
||
|
||
Map info = list.get(0);
|
||
Object p1 = info.get("implement_plan_data");
|
||
Object p2 = info.get("implement_initiate_file_data");
|
||
|
||
String f1 = String.valueOf(p1);
|
||
String f2 = String.valueOf(p2);
|
||
// ----pic1
|
||
String s1 = getBase64Image(f1);
|
||
if (s1 != null) {
|
||
s1 = s1.substring(s1.indexOf(",") + 1);
|
||
// System.out.println(s1);
|
||
String d1 = getAppImgDir() + f1 + ".jpg";
|
||
boolean b = Base64Utils.Base64ToImage(s1, d1);
|
||
}
|
||
|
||
// ----pic2
|
||
String s2 = getBase64Image(f2);
|
||
if (s2 != null) {
|
||
s2 = s2.substring(s2.indexOf(",") + 1);
|
||
String d2 = getAppImgDir() + f2 + ".jpg";
|
||
boolean b2 = Base64Utils.Base64ToImage(s2, d2);
|
||
}
|
||
|
||
sqlString = "update GREEN_CONSTRUCT_INFO set implement_plan = ? , implement_initiate_file = ? , img_status = 1 where id = ? ";
|
||
hibernateDao.updateWithSql(sqlString, new Object[] { f1 + ".jpg", f2 + ".jpg", id });
|
||
return null;
|
||
}
|
||
|
||
/**
|
||
* 暂时未用到的代码
|
||
*
|
||
* @param id
|
||
* @return
|
||
*/
|
||
public String savFaultRepairImage(Long id) {
|
||
String sqlString = "select * from GREEN_FAULT_REPAIR_INFO where id = ?";
|
||
List<Map> list = hibernateDao.queryForListWithSql(sqlString, new Object[] { id });
|
||
if (list.size() == 0) {
|
||
return null;
|
||
}
|
||
|
||
Map info = list.get(0);
|
||
Object p1 = info.get("fault_pic1_data");
|
||
Object p2 = info.get("fault_pic2_data");
|
||
Object p3 = info.get("fault_pic3_data");
|
||
|
||
String f1 = String.valueOf(p1);
|
||
String f2 = String.valueOf(p2);
|
||
String f3 = String.valueOf(p3);
|
||
|
||
// ----pic1
|
||
String s1 = getBase64Image(f1);
|
||
if (s1 != null) {
|
||
s1 = s1.substring(s1.indexOf(",") + 1);
|
||
// System.out.println(s1);
|
||
String d1 = getAppImgDir() + f1 + ".jpg";
|
||
boolean b = Base64Utils.Base64ToImage(s1, d1);
|
||
}
|
||
|
||
// ----pic2
|
||
String s2 = getBase64Image(f2);
|
||
if (s2 != null) {
|
||
s2 = s2.substring(s2.indexOf(",") + 1);
|
||
String d2 = getAppImgDir() + f2 + ".jpg";
|
||
boolean b2 = Base64Utils.Base64ToImage(s2, d2);
|
||
}
|
||
// ----pic3
|
||
String s3 = getBase64Image(f3);
|
||
if (s3 != null) {
|
||
s3 = s3.substring(s3.indexOf(",") + 1);
|
||
String d3 = getAppImgDir() + f3 + ".jpg";
|
||
boolean b3 = Base64Utils.Base64ToImage(s3, d3);
|
||
}
|
||
|
||
sqlString = "update GREEN_CONSTRUCT_INFO set fault_pic1 = ? , fault_pic1 = ? , fault_pic1 = ? where id = ? ";
|
||
hibernateDao.updateWithSql(sqlString, new Object[] { f1 + ".jpg", f2 + ".jpg", f3 + ".jpg", id });
|
||
return null;
|
||
}
|
||
|
||
public String saveStaffCardImage(Long id) {
|
||
String sqlString = "select * from GREEN_STAFF_CARD_INFO where id = ?";
|
||
List<Map> list = hibernateDao.queryForListWithSql(sqlString, new Object[] { id });
|
||
if (list.size() == 0) {
|
||
return null;
|
||
}
|
||
|
||
Map info = list.get(0);
|
||
Object p1 = info.get("entry_order_pic_data");
|
||
|
||
String f1 = String.valueOf(p1);
|
||
|
||
// ----pic1
|
||
String s1 = getBase64Image(f1);
|
||
s1 = s1.substring(s1.indexOf(",") + 1);
|
||
// System.out.println(s1);
|
||
String d1 = getAppImgDir() + f1 + ".jpg";
|
||
boolean b = Base64Utils.Base64ToImage(s1, d1);
|
||
if (!b) {
|
||
return null;
|
||
}
|
||
sqlString = "update GREEN_STAFF_CARD_INFO set entry_order_pic = ? where id = ? ";
|
||
hibernateDao.updateWithSql(sqlString, new Object[] { f1 + ".jpg", id });
|
||
return null;
|
||
}
|
||
|
||
public boolean saveFoodImage(Long foodId, String imageId) {
|
||
|
||
// ----pic1
|
||
String s1 = getBase64Image(imageId);
|
||
if (s1 == null) {
|
||
return false;
|
||
}
|
||
s1 = s1.substring(s1.indexOf(",") + 1);
|
||
// System.out.println(s1);
|
||
String d1 = getAppImgDir() + imageId + ".jpg";
|
||
boolean b = Base64Utils.Base64ToImage(s1, d1);
|
||
if (!b) {
|
||
return b;
|
||
}
|
||
String sqlString = "update GREEN_FOODS_KINDS set picture = ? , img_status = 1 where id = ? ";
|
||
hibernateDao.updateWithSql(sqlString, new Object[] { imageId + ".jpg", foodId });
|
||
return b;
|
||
|
||
}
|
||
|
||
public String getProperty(String dataType, String dataCode) {
|
||
List<Map<String, String>> list = getDictionaryInfo(dataType, dataCode);
|
||
if (list.size() == 0) {
|
||
return null;
|
||
}
|
||
Map<String, String> map = list.get(0);
|
||
return map.get("data_value");
|
||
}
|
||
}
|