PlatformConfigService.java 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. package com.jsh.erp.service;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.jsh.erp.constants.BusinessConstants;
  4. import com.jsh.erp.datasource.entities.PlatformConfig;
  5. import com.jsh.erp.datasource.entities.PlatformConfigExample;
  6. import com.jsh.erp.datasource.mappers.PlatformConfigMapper;
  7. import com.jsh.erp.datasource.mappers.PlatformConfigMapperEx;
  8. import com.jsh.erp.exception.JshException;
  9. import com.jsh.erp.utils.PageUtils;
  10. import com.jsh.erp.utils.StringUtil;
  11. import org.slf4j.Logger;
  12. import org.slf4j.LoggerFactory;
  13. import org.springframework.stereotype.Service;
  14. import org.springframework.transaction.annotation.Transactional;
  15. import javax.annotation.Resource;
  16. import javax.servlet.http.HttpServletRequest;
  17. import java.util.List;
  18. @Service
  19. public class PlatformConfigService {
  20. private Logger logger = LoggerFactory.getLogger(PlatformConfigService.class);
  21. @Resource
  22. private UserService userService;
  23. @Resource
  24. private PlatformConfigMapper platformConfigMapper;
  25. @Resource
  26. private PlatformConfigMapperEx platformConfigMapperEx;
  27. public PlatformConfig getPlatformConfig(long id)throws Exception {
  28. PlatformConfig result=null;
  29. try{
  30. if(BusinessConstants.DEFAULT_MANAGER.equals(userService.getCurrentUser().getLoginName())) {
  31. result = platformConfigMapper.selectByPrimaryKey(id);
  32. }
  33. }catch(Exception e){
  34. JshException.readFail(logger, e);
  35. }
  36. return result;
  37. }
  38. public List<PlatformConfig> getPlatformConfig()throws Exception {
  39. PlatformConfigExample example = new PlatformConfigExample();
  40. example.createCriteria();
  41. List<PlatformConfig> list=null;
  42. try{
  43. if(BusinessConstants.DEFAULT_MANAGER.equals(userService.getCurrentUser().getLoginName())) {
  44. list = platformConfigMapper.selectByExample(example);
  45. }
  46. }catch(Exception e){
  47. JshException.readFail(logger, e);
  48. }
  49. return list;
  50. }
  51. public List<PlatformConfig> select(String platformKey)throws Exception {
  52. List<PlatformConfig> list=null;
  53. try{
  54. if(BusinessConstants.DEFAULT_MANAGER.equals(userService.getCurrentUser().getLoginName())) {
  55. PageUtils.startPage();
  56. list = platformConfigMapperEx.selectByConditionPlatformConfig(platformKey);
  57. }
  58. }catch(Exception e){
  59. JshException.readFail(logger, e);
  60. }
  61. return list;
  62. }
  63. @Transactional(value = "transactionManager", rollbackFor = Exception.class)
  64. public int insertPlatformConfig(JSONObject obj, HttpServletRequest request) throws Exception{
  65. PlatformConfig platformConfig = JSONObject.parseObject(obj.toJSONString(), PlatformConfig.class);
  66. int result=0;
  67. try{
  68. if(BusinessConstants.DEFAULT_MANAGER.equals(userService.getCurrentUser().getLoginName())) {
  69. result = platformConfigMapper.insertSelective(platformConfig);
  70. }
  71. }catch(Exception e){
  72. JshException.writeFail(logger, e);
  73. }
  74. return result;
  75. }
  76. @Transactional(value = "transactionManager", rollbackFor = Exception.class)
  77. public int updatePlatformConfig(JSONObject obj, HttpServletRequest request) throws Exception{
  78. PlatformConfig platformConfig = JSONObject.parseObject(obj.toJSONString(), PlatformConfig.class);
  79. int result=0;
  80. try{
  81. if(BusinessConstants.DEFAULT_MANAGER.equals(userService.getCurrentUser().getLoginName())) {
  82. result = platformConfigMapper.updateByPrimaryKeySelective(platformConfig);
  83. }
  84. }catch(Exception e){
  85. JshException.writeFail(logger, e);
  86. }
  87. return result;
  88. }
  89. @Transactional(value = "transactionManager", rollbackFor = Exception.class)
  90. public int deletePlatformConfig(Long id, HttpServletRequest request)throws Exception {
  91. int result=0;
  92. try{
  93. if(BusinessConstants.DEFAULT_MANAGER.equals(userService.getCurrentUser().getLoginName())) {
  94. result = platformConfigMapper.deleteByPrimaryKey(id);
  95. }
  96. }catch(Exception e){
  97. JshException.writeFail(logger, e);
  98. }
  99. return result;
  100. }
  101. @Transactional(value = "transactionManager", rollbackFor = Exception.class)
  102. public int batchDeletePlatformConfig(String ids, HttpServletRequest request)throws Exception {
  103. List<Long> idList = StringUtil.strToLongList(ids);
  104. PlatformConfigExample example = new PlatformConfigExample();
  105. example.createCriteria().andIdIn(idList);
  106. int result=0;
  107. try{
  108. if(BusinessConstants.DEFAULT_MANAGER.equals(userService.getCurrentUser().getLoginName())) {
  109. result = platformConfigMapper.deleteByExample(example);
  110. }
  111. }catch(Exception e){
  112. JshException.writeFail(logger, e);
  113. }
  114. return result;
  115. }
  116. public int updatePlatformConfigByKey(String platformKey, String platformValue)throws Exception {
  117. int result=0;
  118. try{
  119. if(BusinessConstants.DEFAULT_MANAGER.equals(userService.getCurrentUser().getLoginName())) {
  120. PlatformConfig platformConfig = new PlatformConfig();
  121. platformConfig.setPlatformValue(platformValue);
  122. PlatformConfigExample example = new PlatformConfigExample();
  123. example.createCriteria().andPlatformKeyEqualTo(platformKey);
  124. result = platformConfigMapper.updateByExampleSelective(platformConfig, example);
  125. }
  126. }catch(Exception e){
  127. JshException.writeFail(logger, e);
  128. }
  129. return result;
  130. }
  131. public PlatformConfig getInfoByKey(String platformKey)throws Exception {
  132. PlatformConfig platformConfig = new PlatformConfig();
  133. try{
  134. if(platformKey.contains("aliOss") || platformKey.contains("weixin")) {
  135. platformConfig = null;
  136. } else {
  137. PlatformConfigExample example = new PlatformConfigExample();
  138. example.createCriteria().andPlatformKeyEqualTo(platformKey);
  139. List<PlatformConfig> list=platformConfigMapper.selectByExample(example);
  140. if(list!=null && list.size()>0){
  141. platformConfig = list.get(0);
  142. }
  143. }
  144. }catch(Exception e){
  145. JshException.readFail(logger, e);
  146. }
  147. return platformConfig;
  148. }
  149. /**
  150. * 根据key查询平台信息-内部专用方法
  151. * @param platformKey
  152. * @return
  153. * @throws Exception
  154. */
  155. public PlatformConfig getPlatformConfigByKey(String platformKey)throws Exception {
  156. PlatformConfig platformConfig = new PlatformConfig();
  157. try{
  158. PlatformConfigExample example = new PlatformConfigExample();
  159. example.createCriteria().andPlatformKeyEqualTo(platformKey);
  160. List<PlatformConfig> list=platformConfigMapper.selectByExample(example);
  161. if(list!=null && list.size()>0){
  162. platformConfig = list.get(0);
  163. }
  164. }catch(Exception e){
  165. JshException.readFail(logger, e);
  166. }
  167. return platformConfig;
  168. }
  169. }