SystemConfigService.java 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  1. package com.jsh.erp.service;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.aliyun.oss.ClientException;
  5. import com.aliyun.oss.OSS;
  6. import com.aliyun.oss.OSSClientBuilder;
  7. import com.aliyun.oss.OSSException;
  8. import com.aliyun.oss.model.CopyObjectResult;
  9. import com.aliyun.oss.model.PutObjectRequest;
  10. import com.jsh.erp.constants.BusinessConstants;
  11. import com.jsh.erp.datasource.entities.SystemConfig;
  12. import com.jsh.erp.datasource.entities.SystemConfigExample;
  13. import com.jsh.erp.datasource.entities.User;
  14. import com.jsh.erp.datasource.mappers.SystemConfigMapper;
  15. import com.jsh.erp.datasource.mappers.SystemConfigMapperEx;
  16. import com.jsh.erp.exception.JshException;
  17. import com.jsh.erp.utils.*;
  18. import org.slf4j.Logger;
  19. import org.slf4j.LoggerFactory;
  20. import org.springframework.beans.factory.annotation.Value;
  21. import org.springframework.stereotype.Service;
  22. import org.springframework.transaction.annotation.Transactional;
  23. import org.springframework.util.FileCopyUtils;
  24. import org.springframework.web.context.request.RequestContextHolder;
  25. import org.springframework.web.context.request.ServletRequestAttributes;
  26. import org.springframework.web.multipart.MultipartFile;
  27. import javax.annotation.Resource;
  28. import javax.imageio.ImageIO;
  29. import javax.imageio.stream.ImageOutputStream;
  30. import javax.servlet.http.HttpServletRequest;
  31. import javax.servlet.http.HttpServletResponse;
  32. import java.awt.*;
  33. import java.awt.image.BufferedImage;
  34. import java.io.*;
  35. import java.net.HttpURLConnection;
  36. import java.net.URL;
  37. import java.nio.file.*;
  38. import java.util.ArrayList;
  39. import java.util.Date;
  40. import java.util.List;
  41. @Service
  42. public class SystemConfigService {
  43. private Logger logger = LoggerFactory.getLogger(SystemConfigService.class);
  44. @Resource
  45. private SystemConfigMapper systemConfigMapper;
  46. @Resource
  47. private SystemConfigMapperEx systemConfigMapperEx;
  48. @Resource
  49. private PlatformConfigService platformConfigService;
  50. @Resource
  51. private UserService userService;
  52. @Resource
  53. private LogService logService;
  54. @Value(value="${file.uploadType}")
  55. private Long fileUploadType;
  56. @Value(value="${file.path}")
  57. private String filePath;
  58. @Value(value="${aliyun.oss.endPoint}")
  59. private String endpoint;
  60. @Value(value="${aliyun.accessKeyId}")
  61. private String accessKeyId;
  62. @Value(value="${aliyun.secretAccessKey}")
  63. private String accessKeySecret;
  64. @Value(value="${aliyun.oss.bucketName}")
  65. private String bucketName;
  66. @Value(value="${aliyun.oss.linkUrl}")
  67. private String aliOssLinkUrl;
  68. private static String DELETED = "deleted";
  69. public SystemConfig getSystemConfig(long id)throws Exception {
  70. SystemConfig result=null;
  71. try{
  72. result=systemConfigMapper.selectByPrimaryKey(id);
  73. }catch(Exception e){
  74. JshException.readFail(logger, e);
  75. }
  76. return result;
  77. }
  78. public List<SystemConfig> getSystemConfig()throws Exception {
  79. SystemConfigExample example = new SystemConfigExample();
  80. example.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
  81. List<SystemConfig> list=null;
  82. try{
  83. list=systemConfigMapper.selectByExample(example);
  84. }catch(Exception e){
  85. JshException.readFail(logger, e);
  86. }
  87. return list;
  88. }
  89. public List<SystemConfig> select(String companyName)throws Exception {
  90. List<SystemConfig> list=null;
  91. try{
  92. PageUtils.startPage();
  93. list=systemConfigMapperEx.selectByConditionSystemConfig(companyName);
  94. }catch(Exception e){
  95. JshException.readFail(logger, e);
  96. }
  97. return list;
  98. }
  99. @Transactional(value = "transactionManager", rollbackFor = Exception.class)
  100. public int insertSystemConfig(JSONObject obj, HttpServletRequest request) throws Exception{
  101. SystemConfig systemConfig = JSONObject.parseObject(obj.toJSONString(), SystemConfig.class);
  102. int result=0;
  103. try{
  104. result=systemConfigMapper.insertSelective(systemConfig);
  105. String logInfo = StringUtil.isNotEmpty(systemConfig.getCompanyName())?systemConfig.getCompanyName():"配置信息";
  106. logService.insertLogWithUserId(userService.getCurrentUser().getId(), userService.getCurrentUser().getTenantId(), "系统配置",
  107. new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_ADD).append(logInfo).toString(), request);
  108. }catch(Exception e){
  109. JshException.writeFail(logger, e);
  110. }
  111. return result;
  112. }
  113. @Transactional(value = "transactionManager", rollbackFor = Exception.class)
  114. public int updateSystemConfig(JSONObject obj, HttpServletRequest request) throws Exception{
  115. SystemConfig systemConfig = JSONObject.parseObject(obj.toJSONString(), SystemConfig.class);
  116. int result=0;
  117. try{
  118. result = systemConfigMapper.updateByPrimaryKeySelective(systemConfig);
  119. String logInfo = StringUtil.isNotEmpty(systemConfig.getCompanyName())?systemConfig.getCompanyName():"配置信息";
  120. logService.insertLogWithUserId(userService.getCurrentUser().getId(), userService.getCurrentUser().getTenantId(), "系统配置",
  121. new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(logInfo).toString(), request);
  122. }catch(Exception e){
  123. JshException.writeFail(logger, e);
  124. }
  125. return result;
  126. }
  127. @Transactional(value = "transactionManager", rollbackFor = Exception.class)
  128. public int deleteSystemConfig(Long id, HttpServletRequest request)throws Exception {
  129. return batchDeleteSystemConfigByIds(id.toString());
  130. }
  131. @Transactional(value = "transactionManager", rollbackFor = Exception.class)
  132. public int batchDeleteSystemConfig(String ids, HttpServletRequest request)throws Exception {
  133. return batchDeleteSystemConfigByIds(ids);
  134. }
  135. @Transactional(value = "transactionManager", rollbackFor = Exception.class)
  136. public int batchDeleteSystemConfigByIds(String ids)throws Exception {
  137. logService.insertLog("系统配置",
  138. new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_DELETE).append(ids).toString(),
  139. ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
  140. User userInfo=userService.getCurrentUser();
  141. String [] idArray=ids.split(",");
  142. int result=0;
  143. try{
  144. result = systemConfigMapperEx.batchDeleteSystemConfigByIds(new Date(), userInfo == null ? null : userInfo.getId(), idArray);
  145. }catch(Exception e){
  146. JshException.writeFail(logger, e);
  147. }
  148. return result;
  149. }
  150. public int checkIsNameExist(Long id, String name) throws Exception{
  151. SystemConfigExample example = new SystemConfigExample();
  152. example.createCriteria().andIdNotEqualTo(id).andCompanyNameEqualTo(name).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
  153. List<SystemConfig> list =null;
  154. try{
  155. list=systemConfigMapper.selectByExample(example);
  156. }catch(Exception e){
  157. JshException.readFail(logger, e);
  158. }
  159. return list==null?0:list.size();
  160. }
  161. /**
  162. * 本地文件上传
  163. * @param mf 文件
  164. * @param bizPath 自定义路径
  165. * @return
  166. */
  167. public String uploadLocal(MultipartFile mf, String bizPath, HttpServletRequest request) throws Exception {
  168. try {
  169. if(StringUtil.isEmpty(bizPath)){
  170. bizPath = "";
  171. }
  172. // Validate bizPath to prevent directory traversal
  173. if (bizPath.contains("..") || bizPath.contains("/")) {
  174. throw new IllegalArgumentException("Invalid bizPath");
  175. }
  176. String token = request.getHeader("X-Access-Token");
  177. Long tenantId = Tools.getTenantIdByToken(token);
  178. bizPath = bizPath + File.separator + tenantId;
  179. String ctxPath = filePath;
  180. String fileName = null;
  181. File file = new File(ctxPath + File.separator + bizPath + File.separator );
  182. if (!file.exists()) {
  183. file.mkdirs();// 创建文件根目录
  184. }
  185. String orgName = mf.getOriginalFilename();// 获取文件名
  186. orgName = FileUtils.getFileName(orgName);
  187. // Validate file extension to allow only specific types
  188. String[] allowedExtensions = {".gif", ".jpg", ".jpeg", ".png", ".pdf", ".txt",".doc",".docx",".xls",".xlsx",
  189. ".ppt",".pptx",".zip",".rar",".mp3",".mp4",".avi",".apk"};
  190. boolean isValidExtension = false;
  191. for (String ext : allowedExtensions) {
  192. if (orgName.toLowerCase().endsWith(ext)) {
  193. isValidExtension = true;
  194. break;
  195. }
  196. }
  197. if (!isValidExtension) {
  198. throw new IllegalArgumentException("Invalid file type");
  199. }
  200. if(orgName.contains(".")){
  201. fileName = orgName.substring(0, orgName.lastIndexOf(".")) + "_" + System.currentTimeMillis() + orgName.substring(orgName.indexOf("."));
  202. }else{
  203. fileName = orgName+ "_" + System.currentTimeMillis();
  204. }
  205. String savePath = file.getPath() + File.separator + fileName;
  206. File savefile = new File(savePath);
  207. FileCopyUtils.copy(mf.getBytes(), savefile);
  208. // 返回路径
  209. String dbpath = null;
  210. if(StringUtil.isNotEmpty(bizPath)){
  211. dbpath = bizPath + File.separator + fileName;
  212. }else{
  213. dbpath = fileName;
  214. }
  215. if (dbpath.contains("\\")) {
  216. dbpath = dbpath.replace("\\", "/");
  217. }
  218. return dbpath;
  219. } catch (IOException e) {
  220. logger.error(e.getMessage(), e);
  221. }
  222. return "";
  223. }
  224. /**
  225. * 阿里Oss文件上传
  226. * @param mf 文件
  227. * @param bizPath 自定义路径
  228. * @return
  229. */
  230. public String uploadAliOss(MultipartFile mf, String bizPath, HttpServletRequest request) throws Exception {
  231. if(StringUtil.isEmpty(bizPath)){
  232. bizPath = "";
  233. }
  234. // Validate bizPath to prevent directory traversal
  235. if (bizPath.contains("..") || bizPath.contains("/")) {
  236. throw new IllegalArgumentException("Invalid bizPath");
  237. }
  238. String token = request.getHeader("X-Access-Token");
  239. Long tenantId = Tools.getTenantIdByToken(token);
  240. bizPath = bizPath + "/" + tenantId;
  241. // 填写Object完整路径,完整路径中不能包含Bucket名称,例如exampledir/exampleobject.txt。
  242. String fileName = "";
  243. String orgName = mf.getOriginalFilename();// 获取文件名
  244. orgName = FileUtils.getFileName(orgName);
  245. // Validate file extension to allow only specific types
  246. String[] allowedExtensions = {".gif", ".jpg", ".jpeg", ".png", ".pdf", ".txt",".doc",".docx",".xls",".xlsx",
  247. ".ppt",".pptx",".zip",".rar",".mp3",".mp4",".avi"};
  248. boolean isValidExtension = false;
  249. for (String ext : allowedExtensions) {
  250. if (orgName.toLowerCase().endsWith(ext)) {
  251. isValidExtension = true;
  252. break;
  253. }
  254. }
  255. if (!isValidExtension) {
  256. throw new IllegalArgumentException("Invalid file type");
  257. }
  258. if(orgName.contains(".")){
  259. fileName = orgName.substring(0, orgName.lastIndexOf(".")) + "_" + System.currentTimeMillis() + orgName.substring(orgName.indexOf("."));
  260. }else{
  261. fileName = orgName+ "_" + System.currentTimeMillis();
  262. }
  263. String filePathStr = StringUtil.isNotEmpty(filePath)? filePath.substring(1):"";
  264. String objectName = filePathStr + "/" + bizPath + "/" + fileName;
  265. String smallObjectName = filePathStr + "-small/" + bizPath + "/" + fileName;
  266. // 如果未指定本地路径,则默认从示例程序所属项目对应本地路径中上传文件流。
  267. byte [] byteArr = mf.getBytes();
  268. // 创建OSSClient实例。
  269. OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
  270. try {
  271. // 保存原文件
  272. InputStream inputStream = new ByteArrayInputStream(byteArr);
  273. PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, objectName, inputStream);
  274. ossClient.putObject(putObjectRequest);
  275. // 如果是图片-保存缩略图
  276. int index = fileName.lastIndexOf(".");
  277. String ext = fileName.substring(index + 1);
  278. if(ext.contains("gif") || ext.contains("jpg") || ext.contains("jpeg") || ext.contains("png")
  279. || ext.contains("GIF") || ext.contains("JPG") || ext.contains("JPEG") || ext.contains("PNG")) {
  280. String fileUrl = getFileUrlAliOss(bizPath + "/" + fileName);
  281. URL url = new URL(fileUrl);
  282. HttpURLConnection conn = (HttpURLConnection) url.openConnection();
  283. conn.setRequestMethod("GET");
  284. conn.setConnectTimeout(5 * 1000);
  285. InputStream imgInputStream = conn.getInputStream();// 通过输入流获取图片数据
  286. BufferedImage smallImage = getImageMini(imgInputStream, 80);
  287. ByteArrayOutputStream bs = new ByteArrayOutputStream();
  288. ImageOutputStream imOut = ImageIO.createImageOutputStream(bs);
  289. ImageIO.write(smallImage, ext, imOut);
  290. InputStream isImg = new ByteArrayInputStream(bs.toByteArray());
  291. PutObjectRequest putSmallObjectRequest = new PutObjectRequest(bucketName, smallObjectName, isImg);
  292. ossClient.putObject(putSmallObjectRequest);
  293. }
  294. // 返回路径
  295. return getFileUrlAliOss(bizPath + "/" + fileName);
  296. } catch (OSSException oe) {
  297. logger.error("Caught an OSSException, which means your request made it to OSS, "
  298. + "but was rejected with an error response for some reason.");
  299. logger.error("Error Message:" + oe.getErrorMessage());
  300. logger.error("Error Code:" + oe.getErrorCode());
  301. logger.error("Request ID:" + oe.getRequestId());
  302. logger.error("Host ID:" + oe.getHostId());
  303. } catch (ClientException ce) {
  304. logger.error("Caught an ClientException, which means the client encountered "
  305. + "a serious internal problem while trying to communicate with OSS, "
  306. + "such as not being able to access the network.");
  307. System.out.println("Error Message:" + ce.getMessage());
  308. } finally {
  309. if (ossClient != null) {
  310. ossClient.shutdown();
  311. }
  312. }
  313. return "";
  314. }
  315. public String getFileUrlLocal(String imgPath) {
  316. return filePath + File.separator + imgPath;
  317. }
  318. public String getFileUrlAliOss(String imgPath) throws Exception {
  319. String linkUrl = aliOssLinkUrl;
  320. return linkUrl + filePath + "/" + imgPath;
  321. }
  322. /**
  323. * 逻辑删除文件
  324. * @param pathList
  325. */
  326. public void deleteFileByPathList(List<String> pathList) throws Exception {
  327. if(fileUploadType == 1) {
  328. //本地
  329. for(String pathStr: pathList) {
  330. if(StringUtil.isNotEmpty(pathStr)) {
  331. String[] pathArr = pathStr.split(",");
  332. for (String path : pathArr) {
  333. // 提取文件的路径
  334. String pathDir = getDirByPath(path);
  335. if (StringUtil.isNotEmpty(pathDir)) {
  336. // 源文件路径
  337. Path sourcePath = Paths.get(filePath + File.separator + path);
  338. // 目标文件路径(注意这里是新文件的完整路径,包括文件名)
  339. Path targetPath = Paths.get(filePath + File.separator + DELETED + File.separator + path);
  340. try {
  341. File file = new File(filePath + File.separator + DELETED + File.separator + pathDir);
  342. if (!file.exists()) {
  343. file.mkdirs();// 创建文件根目录
  344. }
  345. // 复制文件,如果目标文件已存在则替换它
  346. Files.copy(sourcePath, targetPath, StandardCopyOption.REPLACE_EXISTING);
  347. // 删除源文件
  348. Files.delete(sourcePath);
  349. logger.info("File copied successfully.");
  350. } catch (NoSuchFileException e) {
  351. logger.error("Source file not found: " + e.getMessage());
  352. } catch (IOException e) {
  353. logger.error("An I/O error occurred: " + e.getMessage());
  354. } catch (SecurityException e) {
  355. logger.error("No permission to copy file: " + e.getMessage());
  356. }
  357. }
  358. }
  359. }
  360. }
  361. } else if(fileUploadType == 2) {
  362. //oss
  363. for(String pathStr: pathList) {
  364. if(StringUtil.isNotEmpty(pathStr)) {
  365. String[] pathArr = pathStr.split(",");
  366. for (String path : pathArr) {
  367. if(StringUtil.isNotEmpty(path)) {
  368. // 创建OSSClient实例。
  369. OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
  370. try {
  371. String filePathStr = StringUtil.isNotEmpty(filePath) ? filePath.substring(1) : "";
  372. String sourceObjectKey = filePathStr + "/" + path;
  373. String sourceSmallObjectKey = filePathStr + "-small/" + path;
  374. String destinationObjectKey = DELETED + "/list/" + sourceObjectKey;
  375. String destinationSmallObjectKey = DELETED + "/list/" + sourceSmallObjectKey;
  376. this.copySourceToDest(ossClient, bucketName, sourceObjectKey, destinationObjectKey);
  377. this.copySourceToDest(ossClient, bucketName, sourceSmallObjectKey, destinationSmallObjectKey);
  378. } catch (Exception e) {
  379. logger.error(e.getMessage());
  380. } finally {
  381. // 关闭OSSClient。
  382. if (ossClient != null) {
  383. ossClient.shutdown();
  384. }
  385. }
  386. }
  387. }
  388. }
  389. }
  390. }
  391. }
  392. /**
  393. *
  394. * @param ossClient
  395. * @param bucketName
  396. * @param sourceObjectKey 源文件路径,包括目录和文件名
  397. * @param destinationObjectKey 目标文件路径,包括新目录和文件名
  398. */
  399. public void copySourceToDest(OSS ossClient, String bucketName, String sourceObjectKey, String destinationObjectKey) {
  400. // 复制文件
  401. CopyObjectResult copyResult = ossClient.copyObject(bucketName, sourceObjectKey, bucketName, destinationObjectKey);
  402. // 确认复制成功
  403. if (copyResult != null && copyResult.getETag() != null) {
  404. logger.info("文件复制成功,ETag: " + copyResult.getETag());
  405. // 删除源文件
  406. ossClient.deleteObject(bucketName, sourceObjectKey);
  407. logger.info("源文件已删除:" + sourceObjectKey);
  408. } else {
  409. logger.info("文件复制失败");
  410. }
  411. }
  412. public String getDirByPath(String path) {
  413. if(path.lastIndexOf("/")>-1) {
  414. return path.substring(0, path.lastIndexOf("/"));
  415. } else {
  416. return null;
  417. }
  418. }
  419. public BufferedImage getImageMini(InputStream inputStream, int w) throws Exception {
  420. BufferedImage img = ImageIO.read(inputStream);
  421. //获取图片的长和宽
  422. int width = img.getWidth();
  423. int height = img.getHeight();
  424. int tempw = 0;
  425. int temph = 0;
  426. if(width>height){
  427. tempw = w;
  428. temph = height* w/width;
  429. }else{
  430. tempw = w*width/height;
  431. temph = w;
  432. }
  433. Image _img = img.getScaledInstance(tempw, temph, Image.SCALE_DEFAULT);
  434. BufferedImage image = new BufferedImage(tempw, temph, BufferedImage.TYPE_INT_RGB);
  435. Graphics2D graphics = image.createGraphics();
  436. graphics.drawImage(_img, 0, 0, null);
  437. graphics.dispose();
  438. return image;
  439. }
  440. /**
  441. * 获取仓库开关
  442. * @return
  443. * @throws Exception
  444. */
  445. public boolean getDepotFlag() throws Exception {
  446. boolean depotFlag = false;
  447. List<SystemConfig> list = getSystemConfig();
  448. if(list.size()>0) {
  449. String flag = list.get(0).getDepotFlag();
  450. if(("1").equals(flag)) {
  451. depotFlag = true;
  452. }
  453. }
  454. return depotFlag;
  455. }
  456. /**
  457. * 获取客户开关
  458. * @return
  459. * @throws Exception
  460. */
  461. public boolean getCustomerFlag() throws Exception {
  462. boolean customerFlag = false;
  463. List<SystemConfig> list = getSystemConfig();
  464. if(list.size()>0) {
  465. String flag = list.get(0).getCustomerFlag();
  466. if(("1").equals(flag)) {
  467. customerFlag = true;
  468. }
  469. }
  470. return customerFlag;
  471. }
  472. /**
  473. * 获取负库存开关
  474. * @return
  475. * @throws Exception
  476. */
  477. public boolean getMinusStockFlag() throws Exception {
  478. boolean minusStockFlag = false;
  479. List<SystemConfig> list = getSystemConfig();
  480. if(list.size()>0) {
  481. String flag = list.get(0).getMinusStockFlag();
  482. if(("1").equals(flag)) {
  483. minusStockFlag = true;
  484. }
  485. }
  486. return minusStockFlag;
  487. }
  488. /**
  489. * 获取更新单价开关
  490. * @return
  491. * @throws Exception
  492. */
  493. public boolean getUpdateUnitPriceFlag() throws Exception {
  494. boolean updateUnitPriceFlag = true;
  495. List<SystemConfig> list = getSystemConfig();
  496. if(list.size()>0) {
  497. String flag = list.get(0).getUpdateUnitPriceFlag();
  498. if(("0").equals(flag)) {
  499. updateUnitPriceFlag = false;
  500. }
  501. }
  502. return updateUnitPriceFlag;
  503. }
  504. /**
  505. * 获取超出关联单据开关
  506. * @return
  507. * @throws Exception
  508. */
  509. public boolean getOverLinkBillFlag() throws Exception {
  510. boolean overLinkBillFlag = false;
  511. List<SystemConfig> list = getSystemConfig();
  512. if(list.size()>0) {
  513. String flag = list.get(0).getOverLinkBillFlag();
  514. if(("1").equals(flag)) {
  515. overLinkBillFlag = true;
  516. }
  517. }
  518. return overLinkBillFlag;
  519. }
  520. /**
  521. * 获取强审核开关
  522. * @return
  523. * @throws Exception
  524. */
  525. public boolean getForceApprovalFlag() throws Exception {
  526. boolean forceApprovalFlag = false;
  527. List<SystemConfig> list = getSystemConfig();
  528. if(list.size()>0) {
  529. String flag = list.get(0).getForceApprovalFlag();
  530. if(("1").equals(flag)) {
  531. forceApprovalFlag = true;
  532. }
  533. }
  534. return forceApprovalFlag;
  535. }
  536. /**
  537. * 获取多级审核开关
  538. * @return
  539. * @throws Exception
  540. */
  541. public boolean getMultiLevelApprovalFlag() throws Exception {
  542. boolean multiLevelApprovalFlag = false;
  543. List<SystemConfig> list = getSystemConfig();
  544. if(list.size()>0) {
  545. String flag = list.get(0).getMultiLevelApprovalFlag();
  546. if(("1").equals(flag)) {
  547. multiLevelApprovalFlag = true;
  548. }
  549. }
  550. return multiLevelApprovalFlag;
  551. }
  552. /**
  553. * 获取出入库管理开关
  554. * @return
  555. * @throws Exception
  556. */
  557. public boolean getInOutManageFlag() throws Exception {
  558. boolean inOutManageFlag = false;
  559. List<SystemConfig> list = getSystemConfig();
  560. if(list.size()>0) {
  561. String flag = list.get(0).getInOutManageFlag();
  562. if(("1").equals(flag)) {
  563. inOutManageFlag = true;
  564. }
  565. }
  566. return inOutManageFlag;
  567. }
  568. /**
  569. * 获取移动平均价开关
  570. * @return
  571. * @throws Exception
  572. */
  573. public boolean getMoveAvgPriceFlag() throws Exception {
  574. boolean moveAvgPriceFlag = false;
  575. List<SystemConfig> list = getSystemConfig();
  576. if(list.size()>0) {
  577. String flag = list.get(0).getMoveAvgPriceFlag();
  578. if(("1").equals(flag)) {
  579. moveAvgPriceFlag = true;
  580. }
  581. }
  582. return moveAvgPriceFlag;
  583. }
  584. /**
  585. * Excel导出统一方法
  586. * @param title
  587. * @param head
  588. * @param tip
  589. * @param arr
  590. * @param response
  591. * @throws Exception
  592. */
  593. public void exportExcelByParam(String title, String head, String tip, JSONArray arr, HttpServletResponse response) throws Exception {
  594. List<String> nameList = StringUtil.strToStringList(head);
  595. String[] names = StringUtil.listToStringArray(nameList);
  596. List<String[]> objects = new ArrayList<>();
  597. if (null != arr) {
  598. for (Object object: arr) {
  599. List<Object> list = (List<Object>) object;
  600. String[] objs = new String[names.length];
  601. for (int i = 0; i < list.size(); i++) {
  602. if(null != list.get(i)) {
  603. objs[i] = list.get(i).toString();
  604. }
  605. }
  606. objects.add(objs);
  607. }
  608. }
  609. File file = ExcelUtils.exportObjectsOneSheet(title, tip, names, title, objects);
  610. ExcelUtils.downloadExcel(file, file.getName(), response);
  611. }
  612. }