Переглянути джерело

Merge branch 'dev' of http://192.168.1.220:10080/chenweida/jw2.0 into dev

Conflicts:
	svr-lib-parent-pom/pom.xml
	svr/svr-base/pom.xml
chenyongxing 8 роки тому
батько
коміт
b75cc56325

+ 58 - 0
svr/svr-base/src/main/java/com/yihu/jw/wx/controller/WxAccessTokenController.java

@ -0,0 +1,58 @@
package com.yihu.jw.wx.controller;
import com.yihu.jw.restmodel.base.BaseContants;
import com.yihu.jw.restmodel.common.Envelop;
import com.yihu.jw.restmodel.common.EnvelopRestController;
import com.yihu.jw.restmodel.exception.ApiException;
import com.yihu.jw.wx.model.WxAccessToken;
import com.yihu.jw.wx.service.WxAccessTokenService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
/**
 * Created by chenweida on 2017/5/11.
 */
@RestController
@RequestMapping(BaseContants.WxAccessToken.api_common)
@Api(value = "微信token模块", description = "微信token模块接口管理")
public class WxAccessTokenController extends EnvelopRestController {
    private WxAccessTokenService wxAccessTokenService;
    /**
     * 根据wechatCode获取WxAccessToken
     * @param wechatCode
     * @return MWxAccessToken
     * @throws Exception
     */
    @RequestMapping(value = BaseContants.WxAccessToken.api_get, method = RequestMethod.GET)
    @ApiOperation(value = "根据wechatCode获取最新的WxAccessToken")
    public Envelop getWxAccessToken(
            @ApiParam(name = "wechatCode", value = "wechatCode")
            @PathVariable(value = "wechatCode") String wechatCode) throws Exception {
        try {
            WxAccessToken wxAccessToken = wxAccessTokenService.getWxAccessTokenByCode(wechatCode);
            return Envelop.getSuccess(BaseContants.WxAccessToken.message_success_get, wxAccessToken);
        }catch (ApiException e) {
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        }
    }
    @PostMapping(value = BaseContants.WxAccessToken.api_create, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "创建WxAccessToken")
    public Envelop createWxAccessToken(
            @ApiParam(name = "wxAccessToken", value = "对象JSON结构体", allowMultiple = true)
            @RequestBody String wxAccessTokenJson) throws Exception {
        try {
            WxAccessToken wxAccessToken = toEntity(wxAccessTokenJson, WxAccessToken.class);
            wxAccessToken = wxAccessTokenService.createWxAccessToken(wxAccessToken);
            return Envelop.getSuccess(BaseContants.WxAccessToken.message_success_create, wxAccessToken);
        }catch (ApiException e) {
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        }
    }
}

+ 77 - 0
svr/svr-base/src/main/java/com/yihu/jw/wx/controller/WxMenuController.java

@ -0,0 +1,77 @@
package com.yihu.jw.wx.controller;
import com.yihu.jw.restmodel.base.BaseContants;
import com.yihu.jw.restmodel.common.Envelop;
import com.yihu.jw.restmodel.common.EnvelopRestController;
import com.yihu.jw.restmodel.exception.ApiException;
import com.yihu.jw.wx.model.WxMenu;
import com.yihu.jw.wx.service.WxMenuService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
/**
 * Created by Administrator on 2017/5/19 0019.
 */
public class WxMenuController extends EnvelopRestController {
    @Autowired
    private WxMenuService wxMenuService;
    @PostMapping(value = BaseContants.WxMenu.api_create, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "创建微信菜单", notes = "创建微信菜单")
    public Envelop createWxMenu(
            @ApiParam(name = "json_data", value = "", defaultValue = "")
            @RequestBody String jsonData) {
        try {
            WxMenu wxMenu = toEntity(jsonData, WxMenu.class);
            return Envelop.getSuccess(BaseContants.Function.message_success_create, wxMenuService.createWxMenu(wxMenu));
        } catch (ApiException e) {
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        }
    }
    @PutMapping(value = BaseContants.WxMenu.api_update, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "修改微信菜单", notes = "修改微信菜单")
    public Envelop updateWxMenu(
            @ApiParam(name = "json_data", value = "", defaultValue = "")
            @RequestBody String jsonData) {
        try {
            WxMenu wxMenu = toEntity(jsonData, WxMenu.class);
            return Envelop.getSuccess(BaseContants.WxMenu.message_success_update, wxMenuService.updateWxMenu(wxMenu));
        } catch (ApiException e) {
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        }
    }
    @DeleteMapping(value = BaseContants.WxMenu.api_delete, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "删除微信菜单", notes = "删除微信菜单")
    public Envelop deleteWxMenu(
            @ApiParam(name = "id", value = "id")
            @RequestParam(value = "id", required = true) Integer id) {
        try {
            wxMenuService.deleteWxMenu(id);
            return Envelop.getSuccess(BaseContants.WxMenu.message_success_delete );
        } catch (ApiException e) {
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        }
    }
    @GetMapping(value = BaseContants.WxMenu.api_getById, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "根据id查找微信菜单", notes = "根据id查找微信菜单")
    public Envelop findById(
            @ApiParam(name = "id", value = "id")
            @RequestParam(value = "id", required = true) Integer id
    ) {
        try {
            return Envelop.getSuccess(BaseContants.WxMenu.message_success_find, wxMenuService.findById(id));
        } catch (ApiException e) {
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        }
    }
}

+ 19 - 0
svr/svr-base/src/main/java/com/yihu/jw/wx/dao/WxAccessTokenDao.java

@ -0,0 +1,19 @@
package com.yihu.jw.wx.dao;
import com.yihu.jw.base.model.Function;
import com.yihu.jw.wx.model.WxAccessToken;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.Date;
import java.util.List;
/**
 * Created by Administrator on 2017/5/18 0018.
 */
public interface WxAccessTokenDao extends PagingAndSortingRepository<WxAccessToken, Long>, JpaSpecificationExecutor<WxAccessToken> {
    @Query("from WxAccessToken w where w.wechatCode =?1 order by w.addTimestamp desc")
    List<WxAccessToken> getWxAccessTokenByCode(String wechatCode);
}

+ 46 - 0
svr/svr-base/src/main/java/com/yihu/jw/wx/service/WxAccessTokenService.java

@ -0,0 +1,46 @@
package com.yihu.jw.wx.service;
import com.yihu.jw.restmodel.base.BaseContants;
import com.yihu.jw.restmodel.common.CommonContants;
import com.yihu.jw.restmodel.exception.ApiException;
import com.yihu.jw.wx.dao.WxAccessTokenDao;
import com.yihu.jw.wx.model.WxAccessToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import java.util.Date;
import java.util.List;
/**
 * Created by Administrator on 2017/5/18 0018.
 */
public class WxAccessTokenService {
    @Autowired
    private WxAccessTokenDao wxAccessTokenDao;
    /**
     * 根据wechatCode查找最新一条
     * @param wechatCode
     * @return
     */
    public WxAccessToken getWxAccessTokenByCode(String wechatCode) {
        List<WxAccessToken> wxAccessTokens =  wxAccessTokenDao.getWxAccessTokenByCode(wechatCode);
        if(wxAccessTokens!=null){
            return wxAccessTokens.get(0);
        }
        return null;
    }
    @Transactional
    public WxAccessToken createWxAccessToken(WxAccessToken wxAccessToken) {
        if (StringUtils.isEmpty(wxAccessToken.getWechatCode())) {
            throw new ApiException(BaseContants.WxAccessToken.message_fail_wechatCode_is_null, CommonContants.common_error_params_code);
        }
        if ("".equals(wxAccessToken.getAddTimestamp())){
            wxAccessToken.setAddTimestamp(new Date().getTime());
        }
        return wxAccessTokenDao.save(wxAccessToken);
    }
}

+ 58 - 0
svr/svr-base/src/main/java/com/yihu/jw/wx/service/WxMenuService.java

@ -0,0 +1,58 @@
package com.yihu.jw.wx.service;
import com.yihu.jw.restmodel.base.BaseContants;
import com.yihu.jw.restmodel.common.CommonContants;
import com.yihu.jw.restmodel.exception.ApiException;
import com.yihu.jw.wx.dao.WxMenuDao;
import com.yihu.jw.wx.model.WxMenu;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import javax.persistence.Transient;
/**
 * Created by Administrator on 2017/5/19 0019.
 */
public class WxMenuService {
    @Autowired
    private WxMenuDao wxMenuDao;
    public WxMenu createWxMenu(WxMenu wxMenu) {
        if (StringUtils.isEmpty(wxMenu.getWechatCode())) {
            throw new ApiException(BaseContants.WxMenu.message_fail_wechatCode_is_null, CommonContants.common_error_params_code);
        }
        if (StringUtils.isEmpty(wxMenu.getName())) {
            throw new ApiException(BaseContants.WxMenu.message_fail_wxMenuName_is_null, CommonContants.common_error_params_code);
        }
        return wxMenuDao.save(wxMenu);
    }
    @Transient
    public WxMenu updateWxMenu(WxMenu wxMenu) {
        if (StringUtils.isEmpty(wxMenu.getWechatCode())) {
            throw new ApiException(BaseContants.WxMenu.message_fail_code_is_null, CommonContants.common_error_params_code);
        }
        if (StringUtils.isEmpty(wxMenu.getName())) {
            throw new ApiException(BaseContants.WxMenu.message_fail_name_is_null, CommonContants.common_error_params_code);
        }
        if (StringUtils.isEmpty(wxMenu.getId())) {
            throw new ApiException(BaseContants.WxMenu.message_fail_id_is_null, CommonContants.common_error_params_code);
        }
        return wxMenuDao.save(wxMenu);
    }
    @Transient
    public void deleteWxMenu(Integer id) {
        WxMenu wxMenu = wxMenuDao.findById(id);
        if (wxMenu == null) {
            throw new ApiException(BaseContants.WxMenu.message_fail_id_no_exist, CommonContants.common_error_params_code);
        }
        wxMenu.setStatus(-1);
        wxMenuDao.save(wxMenu);
    }
    public Object findById(Integer id) {
        return wxMenuDao.findById(id);
    }
}