diff --git a/src/main/java/com/sqx/modules/ext/controller/ExtSysController.java b/src/main/java/com/sqx/modules/ext/controller/ExtSysController.java new file mode 100644 index 00000000..1deaf3bd --- /dev/null +++ b/src/main/java/com/sqx/modules/ext/controller/ExtSysController.java @@ -0,0 +1,45 @@ +package com.sqx.modules.ext.controller; + +import cn.hutool.core.exceptions.ValidateException; +import com.sqx.common.utils.Result; +import com.sqx.modules.coupon.entity.Coupon; +import com.sqx.modules.ext.param.InviteFriendConfigParam; +import com.sqx.modules.ext.service.ExtSysService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.ws.rs.GET; + +/** + * 扩展功能控制层 + * @author tankaikai + * @since 2025-03-28 09:32 + */ +@RestController +@Api(value = "扩展功能", tags = {"扩展功能"}) +@RequestMapping(value = {"/ext/sys","/app/ext/sys"}) +public class ExtSysController { + + @Autowired + private ExtSysService extSysService; + + @PostMapping("/invite/friend/config/save") + @ApiOperation("保存邀请好友配置信息") + public Result saveInviteFriendConfig(@RequestBody InviteFriendConfigParam param){ + try { + extSysService.saveInviteFriendConfig(param); + }catch (ValidateException e){ + return Result.error(e.getMessage()); + } + return Result.success(); + } + + @GetMapping("/invite/friend/config/get") + @ApiOperation("获取邀请好友配置信息") + public Result getInviteFriendConfig(){ + InviteFriendConfigParam data = extSysService.getInviteFriendConfig(); + return Result.success().put("data", data); + } +} diff --git a/src/main/java/com/sqx/modules/ext/param/InviteFriendConfigParam.java b/src/main/java/com/sqx/modules/ext/param/InviteFriendConfigParam.java new file mode 100644 index 00000000..ce54d68f --- /dev/null +++ b/src/main/java/com/sqx/modules/ext/param/InviteFriendConfigParam.java @@ -0,0 +1,22 @@ +package com.sqx.modules.ext.param; + +import lombok.Data; + +/** + * 邀请好友配置入参 + * @author tankaikai + * @since 2025-03-28 09:32 + */ +@Data +public class InviteFriendConfigParam { + + /** + * 邀请好友海报图片地址 + */ + private String imageUrl; + + /** + * 邀请文案 + */ + private String tips; +} diff --git a/src/main/java/com/sqx/modules/ext/service/ExtSysService.java b/src/main/java/com/sqx/modules/ext/service/ExtSysService.java new file mode 100644 index 00000000..060f9566 --- /dev/null +++ b/src/main/java/com/sqx/modules/ext/service/ExtSysService.java @@ -0,0 +1,15 @@ +package com.sqx.modules.ext.service; + +import com.sqx.modules.ext.param.InviteFriendConfigParam; + +/** + * 扩展系统服务接口 + * @author tankaikai + * @since 2025-03-28 09:32 + */ +public interface ExtSysService { + + void saveInviteFriendConfig(InviteFriendConfigParam param); + + InviteFriendConfigParam getInviteFriendConfig(); +} diff --git a/src/main/java/com/sqx/modules/ext/service/impl/ExtSysServiceImpl.java b/src/main/java/com/sqx/modules/ext/service/impl/ExtSysServiceImpl.java new file mode 100644 index 00000000..d3efcb72 --- /dev/null +++ b/src/main/java/com/sqx/modules/ext/service/impl/ExtSysServiceImpl.java @@ -0,0 +1,66 @@ +package com.sqx.modules.ext.service.impl; + +import cn.hutool.core.convert.Convert; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.exceptions.ValidateException; +import cn.hutool.core.util.StrUtil; +import com.sqx.modules.common.dao.CommonInfoDao; +import com.sqx.modules.common.entity.CommonInfo; +import com.sqx.modules.common.service.CommonInfoService; +import com.sqx.modules.ext.param.InviteFriendConfigParam; +import com.sqx.modules.ext.service.ExtSysService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + * 扩展功能服务实现类 + * + * @author tankaikai + * @since 2025-03-28 09:32 + */ +@Service +public class ExtSysServiceImpl implements ExtSysService { + @Autowired + private CommonInfoDao commonInfoDao; + + @Override + public void saveInviteFriendConfig(InviteFriendConfigParam param) { + if (StrUtil.isBlank(param.getImageUrl())) { + throw new ValidateException("顶部图片地址不能为空"); + } + if (StrUtil.isBlank(param.getTips())) { + throw new ValidateException("邀请文案不能为空"); + } + if (param.getTips().length() > 20) { + throw new ValidateException("邀请文案不能大于20个字符"); + } + CommonInfo commonInfo = commonInfoDao.selectById(999L); + if (commonInfo == null) { + commonInfo = new CommonInfo(); + commonInfo.setId(999L); + commonInfo.setCreateAt(DateUtil.now()); + commonInfo.setMax(param.getTips()); + commonInfo.setMin("邀请好友配置"); + commonInfo.setValue(param.getImageUrl()); + commonInfo.setType(Convert.toInt(commonInfo.getId())); + commonInfo.setIsAppUse(1); + commonInfoDao.insert(commonInfo); + return; + } + commonInfo.setMax(param.getTips()); + commonInfo.setValue(param.getImageUrl()); + commonInfoDao.updateById(commonInfo); + } + + @Override + public InviteFriendConfigParam getInviteFriendConfig() { + CommonInfo commonInfo = commonInfoDao.selectById(999L); + if (commonInfo == null) { + return null; + } + InviteFriendConfigParam data = new InviteFriendConfigParam(); + data.setTips(commonInfo.getMax()); + data.setImageUrl(commonInfo.getValue()); + return data; + } +}