123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- package com.jsh.erp.service;
- import com.alibaba.fastjson.JSONObject;
- import com.jsh.erp.constants.BusinessConstants;
- import com.jsh.erp.datasource.entities.PlatformConfig;
- import com.jsh.erp.datasource.entities.PlatformConfigExample;
- import com.jsh.erp.datasource.mappers.PlatformConfigMapper;
- import com.jsh.erp.datasource.mappers.PlatformConfigMapperEx;
- import com.jsh.erp.exception.JshException;
- import com.jsh.erp.utils.PageUtils;
- import com.jsh.erp.utils.StringUtil;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import javax.annotation.Resource;
- import javax.servlet.http.HttpServletRequest;
- import java.util.List;
- @Service
- public class PlatformConfigService {
- private Logger logger = LoggerFactory.getLogger(PlatformConfigService.class);
- @Resource
- private UserService userService;
- @Resource
- private PlatformConfigMapper platformConfigMapper;
- @Resource
- private PlatformConfigMapperEx platformConfigMapperEx;
- public PlatformConfig getPlatformConfig(long id)throws Exception {
- PlatformConfig result=null;
- try{
- if(BusinessConstants.DEFAULT_MANAGER.equals(userService.getCurrentUser().getLoginName())) {
- result = platformConfigMapper.selectByPrimaryKey(id);
- }
- }catch(Exception e){
- JshException.readFail(logger, e);
- }
- return result;
- }
- public List<PlatformConfig> getPlatformConfig()throws Exception {
- PlatformConfigExample example = new PlatformConfigExample();
- example.createCriteria();
- List<PlatformConfig> list=null;
- try{
- if(BusinessConstants.DEFAULT_MANAGER.equals(userService.getCurrentUser().getLoginName())) {
- list = platformConfigMapper.selectByExample(example);
- }
- }catch(Exception e){
- JshException.readFail(logger, e);
- }
- return list;
- }
- public List<PlatformConfig> select(String platformKey)throws Exception {
- List<PlatformConfig> list=null;
- try{
- if(BusinessConstants.DEFAULT_MANAGER.equals(userService.getCurrentUser().getLoginName())) {
- PageUtils.startPage();
- list = platformConfigMapperEx.selectByConditionPlatformConfig(platformKey);
- }
- }catch(Exception e){
- JshException.readFail(logger, e);
- }
- return list;
- }
- @Transactional(value = "transactionManager", rollbackFor = Exception.class)
- public int insertPlatformConfig(JSONObject obj, HttpServletRequest request) throws Exception{
- PlatformConfig platformConfig = JSONObject.parseObject(obj.toJSONString(), PlatformConfig.class);
- int result=0;
- try{
- if(BusinessConstants.DEFAULT_MANAGER.equals(userService.getCurrentUser().getLoginName())) {
- result = platformConfigMapper.insertSelective(platformConfig);
- }
- }catch(Exception e){
- JshException.writeFail(logger, e);
- }
- return result;
- }
- @Transactional(value = "transactionManager", rollbackFor = Exception.class)
- public int updatePlatformConfig(JSONObject obj, HttpServletRequest request) throws Exception{
- PlatformConfig platformConfig = JSONObject.parseObject(obj.toJSONString(), PlatformConfig.class);
- int result=0;
- try{
- if(BusinessConstants.DEFAULT_MANAGER.equals(userService.getCurrentUser().getLoginName())) {
- result = platformConfigMapper.updateByPrimaryKeySelective(platformConfig);
- }
- }catch(Exception e){
- JshException.writeFail(logger, e);
- }
- return result;
- }
- @Transactional(value = "transactionManager", rollbackFor = Exception.class)
- public int deletePlatformConfig(Long id, HttpServletRequest request)throws Exception {
- int result=0;
- try{
- if(BusinessConstants.DEFAULT_MANAGER.equals(userService.getCurrentUser().getLoginName())) {
- result = platformConfigMapper.deleteByPrimaryKey(id);
- }
- }catch(Exception e){
- JshException.writeFail(logger, e);
- }
- return result;
- }
- @Transactional(value = "transactionManager", rollbackFor = Exception.class)
- public int batchDeletePlatformConfig(String ids, HttpServletRequest request)throws Exception {
- List<Long> idList = StringUtil.strToLongList(ids);
- PlatformConfigExample example = new PlatformConfigExample();
- example.createCriteria().andIdIn(idList);
- int result=0;
- try{
- if(BusinessConstants.DEFAULT_MANAGER.equals(userService.getCurrentUser().getLoginName())) {
- result = platformConfigMapper.deleteByExample(example);
- }
- }catch(Exception e){
- JshException.writeFail(logger, e);
- }
- return result;
- }
- public int updatePlatformConfigByKey(String platformKey, String platformValue)throws Exception {
- int result=0;
- try{
- if(BusinessConstants.DEFAULT_MANAGER.equals(userService.getCurrentUser().getLoginName())) {
- PlatformConfig platformConfig = new PlatformConfig();
- platformConfig.setPlatformValue(platformValue);
- PlatformConfigExample example = new PlatformConfigExample();
- example.createCriteria().andPlatformKeyEqualTo(platformKey);
- result = platformConfigMapper.updateByExampleSelective(platformConfig, example);
- }
- }catch(Exception e){
- JshException.writeFail(logger, e);
- }
- return result;
- }
- public PlatformConfig getInfoByKey(String platformKey)throws Exception {
- PlatformConfig platformConfig = new PlatformConfig();
- try{
- if(platformKey.contains("aliOss") || platformKey.contains("weixin")) {
- platformConfig = null;
- } else {
- PlatformConfigExample example = new PlatformConfigExample();
- example.createCriteria().andPlatformKeyEqualTo(platformKey);
- List<PlatformConfig> list=platformConfigMapper.selectByExample(example);
- if(list!=null && list.size()>0){
- platformConfig = list.get(0);
- }
- }
- }catch(Exception e){
- JshException.readFail(logger, e);
- }
- return platformConfig;
- }
- /**
- * 根据key查询平台信息-内部专用方法
- * @param platformKey
- * @return
- * @throws Exception
- */
- public PlatformConfig getPlatformConfigByKey(String platformKey)throws Exception {
- PlatformConfig platformConfig = new PlatformConfig();
- try{
- PlatformConfigExample example = new PlatformConfigExample();
- example.createCriteria().andPlatformKeyEqualTo(platformKey);
- List<PlatformConfig> list=platformConfigMapper.selectByExample(example);
- if(list!=null && list.size()>0){
- platformConfig = list.get(0);
- }
- }catch(Exception e){
- JshException.readFail(logger, e);
- }
- return platformConfig;
- }
- }
|