|
- package com.iformall.controller;
-
- import com.alibaba.fastjson.JSON;
- import com.github.pagehelper.PageInfo;
- import com.iformall.common.ErrorCode;
- import com.iformall.common.ResultData;
- import com.iformall.controller.base.BaseController;
- import com.iformall.domain.po.BaseEntity;
- import com.iformall.domain.po.TtMerchantPoi;
- import com.iformall.domain.po.WxAppinfo;
- import com.iformall.enums.EnumMeterialType;
- import com.iformall.service.TtMerchantPoiService;
- import com.iformall.service.WxAppinfoService;
- import com.iformall.service.toutiao.FmTtOpenService;
- import com.iformall.service.toutiao.api.TtOpenMaService;
- import io.swagger.annotations.ApiImplicitParam;
- import io.swagger.annotations.ApiImplicitParams;
- import io.swagger.annotations.ApiOperation;
- import org.apache.commons.lang3.StringUtils;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.*;
- import org.springframework.web.multipart.MultipartFile;
-
- import java.util.Map;
-
- /**
- * @author gongbiao
- */
- @RestController
- @RequestMapping("merchantPoi")
- public class TtMerchantPoiController extends BaseController {
- private final Logger logger = LoggerFactory.getLogger(this.getClass());
-
- @Autowired
- private TtMerchantPoiService ttMerchantPoiService;
-
- private WxAppinfoService appinfoService;
-
- @Autowired
- protected FmTtOpenService openService;
-
- @ApiOperation("分页列表接口")
- @GetMapping("list")
- @ApiImplicitParams({
- @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true),
- @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)})
- public ResultData list(@ModelAttribute TtMerchantPoi record, Integer pageNum, Integer pageSize) {
- logger.debug("[" + getIpAddr() + "] TtMerchantPoiController::list");
- if (null == record || StringUtils.isBlank(record.getTenantId())){
- return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL);
- }
- record.setSortColumns(BaseEntity.SortField.UpdateDate_DESC);
- final PageInfo<TtMerchantPoi> page = ttMerchantPoiService.listAsPage(record, pageNum, pageSize);
- return new ResultData(page);
- }
-
- @ApiOperation("根据id查询接口")
- @GetMapping("/findById")
- @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true)
- public ResultData findById(Long id) {
- logger.debug("[" + getIpAddr() + "] TtMerchantPoiController::findById");
- if(id == null){
- return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL);
- }
- TtMerchantPoi record = ttMerchantPoiService.getById(id);
- return new ResultData(record);
- }
-
- /**
- * 代授权小程序上传资源
- * 1 小程序图标 修改小程序图标接口 小于等于 2MB jpeg、jpg、png 像素为 200 * 200
- * 2 小程序服务类目资质材料 增加服务类目接口
- * 补充服务类目资质信息接口 小于等于 2MB jpeg、jpg、png
- * 3 小程序名称审核材料 修改小程序名称接口 小于等于 2MB jpeg、jpg、png
- * 4 小程序落地页截图 申请「短视频挂载」能力接口 小于等于 2MB jpeg、jpg、png
- * 5 场景示例图 申请「获取用户手机号」能力接口 小于等于 5MB jpeg、jpg、png
- * 6 小程序分享模板图片 新增分享模板接口
- * 修改分享模板接口 小于等于 1MB jpeg、jpg、png 像素为 500 * 400
- * 7 商铺营业执照、行业资质材料 提交商铺资质材料接口 小于等于 4MB jpeg、jpg、png
- * 8 服务商和商家的合作协议 提交商铺资质材料接口 小于等于 4MB pdf
- *
- * @param multiReq
- * @return
- * @throws Exception
- */
- @PostMapping(value = "/upload_material", consumes = "multipart/*", headers = "content-type=multipart/form-data")
- @ApiOperation("上传图片")
- public ResultData uploadMaterial(@RequestParam("file") MultipartFile multiReq
- ,@RequestParam Map<String, String> param) {
- logger.info("[" + getIpAddr() + "] TtMerchantPoiController::upload_material");
- String appId = param.get("appId");
- if(StringUtils.isBlank(appId)){
- return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL);
- }
- String materialTypeStr = param.get("materialType");
- Integer materialType = null;
- if(StringUtils.isNotBlank(materialTypeStr)){
- try{
- materialType = Integer.parseInt(materialTypeStr);
- }catch (Exception e){ }
- }
- if(materialType == null){
- return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL);
- }
-
- EnumMeterialType enumMeterialType = EnumMeterialType.getByCode(materialType);
- if(enumMeterialType == null){
- return new ResultData(ErrorCode.SYS_PARAMETER_ERROR);
- }
-
- long size = multiReq.getSize();
- final long length = enumMeterialType.getSize();
- if (size > length) {
- return new ResultData(ErrorCode.PICTURE_SIZE_EXCEED);
- }
-
- String fileFormat = "";
- try {
- int dot = multiReq.getOriginalFilename().lastIndexOf('.');
- if (dot >= 0) {
- fileFormat = multiReq.getOriginalFilename().substring(dot, multiReq.getOriginalFilename().length());
- }
-
- TtOpenMaService openMaService = openService.getTtOpenComponentService().getTtMaServiceByAppid(appId);
- String res = openMaService.mediaUpload(materialType, fileFormat, multiReq.getInputStream());
- if(StringUtils.isNotBlank(res)){
- return new ResultData(res);
- }
- return new ResultData(ErrorCode.SYS_SERVER_ERROR);
- } catch (Exception e) {
- logger.error("解析图片",e);
- return new ResultData(ErrorCode.PICTURE_ANALYZING_ERROR);
- }
- }
-
- /**
- * @param
- * @return
- * @throws Exception
- */
- @PostMapping(value = "/add_shop_material")
- @ApiOperation("提交商铺资质材料")
- public ResultData addShopMaterial(@RequestBody Map<String, String> param) {
- logger.info("[" + getIpAddr() + "] TtMerchantPoiController::add_shop_material");
- String appId = param.get("appId");
- if(StringUtils.isBlank(appId)){
- return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"appId为空");
- }
- WxAppinfo appinfo = appinfoService.getByAppId(appId);
- if(appinfo == null){
- return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"找不到小程序信息");
- }
-
- String supplierExtId = param.get("supplierExtId");
- if(StringUtils.isBlank(supplierExtId)){
- return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"商户ID为空");
- }
-
- TtMerchantPoi merchantPoi = ttMerchantPoiService.getById(Long.parseLong(supplierExtId));
- if(merchantPoi == null){
- return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"查询不到商户");
- }
-
- String bizLicencePath = param.get("bizLicencePath");
- if(StringUtils.isBlank(bizLicencePath)){
- return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"商铺营业执照为空");
- }
- merchantPoi.setBizLicencePath(bizLicencePath);
-
- String contractPath = param.get("contract_path");
- if(StringUtils.isBlank(contractPath)){
- return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"授权函为空");
- }
- merchantPoi.setContractPath(contractPath);
-
- String expireTime = param.get("expire_time");
- if(StringUtils.isBlank(expireTime)){
- return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"过期时间为空");
- }
- String regex = "(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29)(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29) ";
- if(!expireTime.matches(regex)){
- return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"过期时间格式 YYYY-MM-DD");
- }
- merchantPoi.setExpireTime(expireTime);
- String qualMaterial = param.get("qual_material");
- if(StringUtils.isNotBlank(qualMaterial)){
- try{
- JSON.parse(qualMaterial);
- merchantPoi.setQualMaterial(qualMaterial);
- }catch(Exception e){
- return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"商铺行业资质材料信息格式不正确");
- }
- }
- String additionalQual = param.get("additional_qual");
- if(StringUtils.isNotBlank(additionalQual)){
- try{
- JSON.parse(additionalQual);
- merchantPoi.setAdditionalQual(additionalQual);
- }catch(Exception e){
- return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"其他补充资质信息格式不正确");
- }
- }
-
- boolean b = ttMerchantPoiService.addShopMaterial(appinfo,merchantPoi);
-
- return new ResultData(b);
- }
-
- /**
- * @param
- * @return
- * @throws Exception
- */
- @PostMapping(value = "/add_shop_material_v1")
- @ApiOperation("提交商铺资质材料")
- public ResultData addShopMaterialV1(@RequestBody Map<String, String> param) {
- logger.info("[" + getIpAddr() + "] TtMerchantPoiController::add_shop_material");
- String appId = param.get("appId");
- if(StringUtils.isBlank(appId)){
- return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"appId为空");
- }
- WxAppinfo appinfo = appinfoService.getByAppId(appId);
- if(appinfo == null){
- return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"找不到小程序信息");
- }
-
- String supplierExtId = param.get("supplierExtId");
- if(StringUtils.isBlank(supplierExtId)){
- return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"商户ID为空");
- }
-
- TtMerchantPoi merchantPoi = ttMerchantPoiService.getById(Long.parseLong(supplierExtId));
- if(merchantPoi == null){
- return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"查询不到商户");
- }
-
- if(StringUtils.isBlank(merchantPoi.getBizLicencePath())){
- return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"商铺营业执照为空");
- }
-
- if(StringUtils.isBlank(merchantPoi.getContractPath())){
- return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"授权函为空");
- }
-
- if(StringUtils.isBlank(merchantPoi.getExpireTime())){
- return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"过期时间为空");
- }
- String regex = "(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29)(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29) ";
- if(!merchantPoi.getExpireTime().matches(regex)){
- return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"过期时间格式 YYYY-MM-DD");
- }
-
- if(StringUtils.isNotBlank(merchantPoi.getQualMaterial())){
- try{
- JSON.parse(merchantPoi.getQualMaterial());
- }catch(Exception e){
- return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"商铺行业资质材料信息格式不正确");
- }
- }
- if(StringUtils.isNotBlank(merchantPoi.getAdditionalQual())){
- try{
- JSON.parse(merchantPoi.getAdditionalQual());
- }catch(Exception e){
- return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"其他补充资质信息格式不正确");
- }
- }
-
- boolean b = ttMerchantPoiService.addShopMaterial(appinfo,merchantPoi);
-
- return new ResultData(b);
- }
-
-
- @ApiOperation("查询商铺资质材料状态")
- @GetMapping("/query_shop_meaterial")
- @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true)
- public ResultData queryShopMeaterial(String appId,Long id) {
- logger.debug("[" + getIpAddr() + "] TtMerchantPoiController::findById");
- if(StringUtils.isBlank(appId)){
- return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"appId为空");
- }
- WxAppinfo appinfo = appinfoService.getByAppId(appId);
-
- if(appinfo == null){
- return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"找不到小程序信息");
- }
- if(id == null){
- return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL);
- }
-
- TtMerchantPoi record = ttMerchantPoiService.getById(id);
- if(record == null){
- return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"查询不到商户");
- }
- try{
- TtOpenMaService openMaService = openService.getTtOpenComponentService().getTtMaServiceByAppid(appId);
- String res = openMaService.queryShopMeaterial(record.getSupplierExtId());
- return new ResultData(res);
- }catch(Exception e){
- logger.error("查询商铺资质材料状态 error"+ e.getMessage());
- }
- return new ResultData(ErrorCode.SYS_SERVER_ERROR);
-
- }
-
- }
|