Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

309 rindas
14 KiB

  1. package com.iformall.controller;
  2. import com.alibaba.fastjson.JSON;
  3. import com.github.pagehelper.PageInfo;
  4. import com.iformall.common.ErrorCode;
  5. import com.iformall.common.ResultData;
  6. import com.iformall.controller.base.BaseController;
  7. import com.iformall.domain.po.BaseEntity;
  8. import com.iformall.domain.po.TtMerchantPoi;
  9. import com.iformall.domain.po.WxAppinfo;
  10. import com.iformall.enums.EnumMeterialType;
  11. import com.iformall.service.TtMerchantPoiService;
  12. import com.iformall.service.WxAppinfoService;
  13. import com.iformall.service.toutiao.FmTtOpenService;
  14. import com.iformall.service.toutiao.api.TtOpenMaService;
  15. import io.swagger.annotations.ApiImplicitParam;
  16. import io.swagger.annotations.ApiImplicitParams;
  17. import io.swagger.annotations.ApiOperation;
  18. import org.apache.commons.lang3.StringUtils;
  19. import org.slf4j.Logger;
  20. import org.slf4j.LoggerFactory;
  21. import org.springframework.beans.factory.annotation.Autowired;
  22. import org.springframework.web.bind.annotation.*;
  23. import org.springframework.web.multipart.MultipartFile;
  24. import java.util.Map;
  25. /**
  26. * @author gongbiao
  27. */
  28. @RestController
  29. @RequestMapping("merchantPoi")
  30. public class TtMerchantPoiController extends BaseController {
  31. private final Logger logger = LoggerFactory.getLogger(this.getClass());
  32. @Autowired
  33. private TtMerchantPoiService ttMerchantPoiService;
  34. private WxAppinfoService appinfoService;
  35. @Autowired
  36. protected FmTtOpenService openService;
  37. @ApiOperation("分页列表接口")
  38. @GetMapping("list")
  39. @ApiImplicitParams({
  40. @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true),
  41. @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)})
  42. public ResultData list(@ModelAttribute TtMerchantPoi record, Integer pageNum, Integer pageSize) {
  43. logger.debug("[" + getIpAddr() + "] TtMerchantPoiController::list");
  44. if (null == record || StringUtils.isBlank(record.getTenantId())){
  45. return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL);
  46. }
  47. record.setSortColumns(BaseEntity.SortField.UpdateDate_DESC);
  48. final PageInfo<TtMerchantPoi> page = ttMerchantPoiService.listAsPage(record, pageNum, pageSize);
  49. return new ResultData(page);
  50. }
  51. @ApiOperation("根据id查询接口")
  52. @GetMapping("/findById")
  53. @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true)
  54. public ResultData findById(Long id) {
  55. logger.debug("[" + getIpAddr() + "] TtMerchantPoiController::findById");
  56. if(id == null){
  57. return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL);
  58. }
  59. TtMerchantPoi record = ttMerchantPoiService.getById(id);
  60. return new ResultData(record);
  61. }
  62. /**
  63. * 代授权小程序上传资源
  64. * 1 小程序图标 修改小程序图标接口 小于等于 2MB jpeg、jpg、png 像素为 200 * 200
  65. * 2 小程序服务类目资质材料 增加服务类目接口
  66. * 补充服务类目资质信息接口 小于等于 2MB jpeg、jpg、png
  67. * 3 小程序名称审核材料 修改小程序名称接口 小于等于 2MB jpeg、jpg、png
  68. * 4 小程序落地页截图 申请「短视频挂载」能力接口 小于等于 2MB jpeg、jpg、png
  69. * 5 场景示例图 申请「获取用户手机号」能力接口 小于等于 5MB jpeg、jpg、png
  70. * 6 小程序分享模板图片 新增分享模板接口
  71. * 修改分享模板接口 小于等于 1MB jpeg、jpg、png 像素为 500 * 400
  72. * 7 商铺营业执照、行业资质材料 提交商铺资质材料接口 小于等于 4MB jpeg、jpg、png
  73. * 8 服务商和商家的合作协议 提交商铺资质材料接口 小于等于 4MB pdf
  74. *
  75. * @param multiReq
  76. * @return
  77. * @throws Exception
  78. */
  79. @PostMapping(value = "/upload_material", consumes = "multipart/*", headers = "content-type=multipart/form-data")
  80. @ApiOperation("上传图片")
  81. public ResultData uploadMaterial(@RequestParam("file") MultipartFile multiReq
  82. ,@RequestParam Map<String, String> param) {
  83. logger.info("[" + getIpAddr() + "] TtMerchantPoiController::upload_material");
  84. String appId = param.get("appId");
  85. if(StringUtils.isBlank(appId)){
  86. return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL);
  87. }
  88. String materialTypeStr = param.get("materialType");
  89. Integer materialType = null;
  90. if(StringUtils.isNotBlank(materialTypeStr)){
  91. try{
  92. materialType = Integer.parseInt(materialTypeStr);
  93. }catch (Exception e){ }
  94. }
  95. if(materialType == null){
  96. return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL);
  97. }
  98. EnumMeterialType enumMeterialType = EnumMeterialType.getByCode(materialType);
  99. if(enumMeterialType == null){
  100. return new ResultData(ErrorCode.SYS_PARAMETER_ERROR);
  101. }
  102. long size = multiReq.getSize();
  103. final long length = enumMeterialType.getSize();
  104. if (size > length) {
  105. return new ResultData(ErrorCode.PICTURE_SIZE_EXCEED);
  106. }
  107. String fileFormat = "";
  108. try {
  109. int dot = multiReq.getOriginalFilename().lastIndexOf('.');
  110. if (dot >= 0) {
  111. fileFormat = multiReq.getOriginalFilename().substring(dot, multiReq.getOriginalFilename().length());
  112. }
  113. TtOpenMaService openMaService = openService.getTtOpenComponentService().getTtMaServiceByAppid(appId);
  114. String res = openMaService.mediaUpload(materialType, fileFormat, multiReq.getInputStream());
  115. if(StringUtils.isNotBlank(res)){
  116. return new ResultData(res);
  117. }
  118. return new ResultData(ErrorCode.SYS_SERVER_ERROR);
  119. } catch (Exception e) {
  120. logger.error("解析图片",e);
  121. return new ResultData(ErrorCode.PICTURE_ANALYZING_ERROR);
  122. }
  123. }
  124. /**
  125. * @param
  126. * @return
  127. * @throws Exception
  128. */
  129. @PostMapping(value = "/add_shop_material")
  130. @ApiOperation("提交商铺资质材料")
  131. public ResultData addShopMaterial(@RequestBody Map<String, String> param) {
  132. logger.info("[" + getIpAddr() + "] TtMerchantPoiController::add_shop_material");
  133. String appId = param.get("appId");
  134. if(StringUtils.isBlank(appId)){
  135. return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"appId为空");
  136. }
  137. WxAppinfo appinfo = appinfoService.getByAppId(appId);
  138. if(appinfo == null){
  139. return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"找不到小程序信息");
  140. }
  141. String supplierExtId = param.get("supplierExtId");
  142. if(StringUtils.isBlank(supplierExtId)){
  143. return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"商户ID为空");
  144. }
  145. TtMerchantPoi merchantPoi = ttMerchantPoiService.getById(Long.parseLong(supplierExtId));
  146. if(merchantPoi == null){
  147. return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"查询不到商户");
  148. }
  149. String bizLicencePath = param.get("bizLicencePath");
  150. if(StringUtils.isBlank(bizLicencePath)){
  151. return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"商铺营业执照为空");
  152. }
  153. merchantPoi.setBizLicencePath(bizLicencePath);
  154. String contractPath = param.get("contract_path");
  155. if(StringUtils.isBlank(contractPath)){
  156. return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"授权函为空");
  157. }
  158. merchantPoi.setContractPath(contractPath);
  159. String expireTime = param.get("expire_time");
  160. if(StringUtils.isBlank(expireTime)){
  161. return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"过期时间为空");
  162. }
  163. 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) ";
  164. if(!expireTime.matches(regex)){
  165. return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"过期时间格式 YYYY-MM-DD");
  166. }
  167. merchantPoi.setExpireTime(expireTime);
  168. String qualMaterial = param.get("qual_material");
  169. if(StringUtils.isNotBlank(qualMaterial)){
  170. try{
  171. JSON.parse(qualMaterial);
  172. merchantPoi.setQualMaterial(qualMaterial);
  173. }catch(Exception e){
  174. return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"商铺行业资质材料信息格式不正确");
  175. }
  176. }
  177. String additionalQual = param.get("additional_qual");
  178. if(StringUtils.isNotBlank(additionalQual)){
  179. try{
  180. JSON.parse(additionalQual);
  181. merchantPoi.setAdditionalQual(additionalQual);
  182. }catch(Exception e){
  183. return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"其他补充资质信息格式不正确");
  184. }
  185. }
  186. boolean b = ttMerchantPoiService.addShopMaterial(appinfo,merchantPoi);
  187. return new ResultData(b);
  188. }
  189. /**
  190. * @param
  191. * @return
  192. * @throws Exception
  193. */
  194. @PostMapping(value = "/add_shop_material_v1")
  195. @ApiOperation("提交商铺资质材料")
  196. public ResultData addShopMaterialV1(@RequestBody Map<String, String> param) {
  197. logger.info("[" + getIpAddr() + "] TtMerchantPoiController::add_shop_material");
  198. String appId = param.get("appId");
  199. if(StringUtils.isBlank(appId)){
  200. return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"appId为空");
  201. }
  202. WxAppinfo appinfo = appinfoService.getByAppId(appId);
  203. if(appinfo == null){
  204. return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"找不到小程序信息");
  205. }
  206. String supplierExtId = param.get("supplierExtId");
  207. if(StringUtils.isBlank(supplierExtId)){
  208. return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"商户ID为空");
  209. }
  210. TtMerchantPoi merchantPoi = ttMerchantPoiService.getById(Long.parseLong(supplierExtId));
  211. if(merchantPoi == null){
  212. return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"查询不到商户");
  213. }
  214. if(StringUtils.isBlank(merchantPoi.getBizLicencePath())){
  215. return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"商铺营业执照为空");
  216. }
  217. if(StringUtils.isBlank(merchantPoi.getContractPath())){
  218. return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"授权函为空");
  219. }
  220. if(StringUtils.isBlank(merchantPoi.getExpireTime())){
  221. return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"过期时间为空");
  222. }
  223. 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) ";
  224. if(!merchantPoi.getExpireTime().matches(regex)){
  225. return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"过期时间格式 YYYY-MM-DD");
  226. }
  227. if(StringUtils.isNotBlank(merchantPoi.getQualMaterial())){
  228. try{
  229. JSON.parse(merchantPoi.getQualMaterial());
  230. }catch(Exception e){
  231. return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"商铺行业资质材料信息格式不正确");
  232. }
  233. }
  234. if(StringUtils.isNotBlank(merchantPoi.getAdditionalQual())){
  235. try{
  236. JSON.parse(merchantPoi.getAdditionalQual());
  237. }catch(Exception e){
  238. return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"其他补充资质信息格式不正确");
  239. }
  240. }
  241. boolean b = ttMerchantPoiService.addShopMaterial(appinfo,merchantPoi);
  242. return new ResultData(b);
  243. }
  244. @ApiOperation("查询商铺资质材料状态")
  245. @GetMapping("/query_shop_meaterial")
  246. @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true)
  247. public ResultData queryShopMeaterial(String appId,Long id) {
  248. logger.debug("[" + getIpAddr() + "] TtMerchantPoiController::findById");
  249. if(StringUtils.isBlank(appId)){
  250. return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"appId为空");
  251. }
  252. WxAppinfo appinfo = appinfoService.getByAppId(appId);
  253. if(appinfo == null){
  254. return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"找不到小程序信息");
  255. }
  256. if(id == null){
  257. return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL);
  258. }
  259. TtMerchantPoi record = ttMerchantPoiService.getById(id);
  260. if(record == null){
  261. return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"查询不到商户");
  262. }
  263. try{
  264. TtOpenMaService openMaService = openService.getTtOpenComponentService().getTtMaServiceByAppid(appId);
  265. String res = openMaService.queryShopMeaterial(record.getSupplierExtId());
  266. return new ResultData(res);
  267. }catch(Exception e){
  268. logger.error("查询商铺资质材料状态 error"+ e.getMessage());
  269. }
  270. return new ResultData(ErrorCode.SYS_SERVER_ERROR);
  271. }
  272. }