From b96dff5680a36e458b72882c95266b66e1281ae7 Mon Sep 17 00:00:00 2001 From: xhxu Date: Tue, 30 Nov 2021 19:24:41 +0800 Subject: [PATCH] customize --- .../basic/WxCustomizeModuleController.java | 127 ++++++++++++++++++ .../WxCustomizeModuleController.java | 50 +++++++ .../iformall/domain/po/WxCustomizeModule.java | 45 +++++++ .../mapper/WxCustomizeModuleMapper.java | 22 +++ .../service/WxCustomizeModuleService.java | 29 ++++ .../impl/WxCustomizeModuleServiceImpl.java | 112 +++++++++++++++ .../mapper/WxCustomizeModuleMapper.xml | 71 ++++++++++ 7 files changed, 456 insertions(+) create mode 100644 mallinkAdmin/src/main/java/com/iformall/controller/basic/WxCustomizeModuleController.java create mode 100644 mallinkCApi/src/main/java/com/iformall/controller/WxCustomizeModuleController.java create mode 100644 mallinkService/src/main/java/com/iformall/domain/po/WxCustomizeModule.java create mode 100644 mallinkService/src/main/java/com/iformall/mapper/WxCustomizeModuleMapper.java create mode 100644 mallinkService/src/main/java/com/iformall/service/WxCustomizeModuleService.java create mode 100644 mallinkService/src/main/java/com/iformall/service/impl/WxCustomizeModuleServiceImpl.java create mode 100644 mallinkService/src/main/resources/mapper/WxCustomizeModuleMapper.xml diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/basic/WxCustomizeModuleController.java b/mallinkAdmin/src/main/java/com/iformall/controller/basic/WxCustomizeModuleController.java new file mode 100644 index 000000000..28822f93a --- /dev/null +++ b/mallinkAdmin/src/main/java/com/iformall/controller/basic/WxCustomizeModuleController.java @@ -0,0 +1,127 @@ +package com.iformall.controller.basic; + +import com.github.pagehelper.PageInfo; +import com.iformall.annotation.SystemControllerLog; +import com.iformall.common.ErrorCode; +import com.iformall.common.Result; +import com.iformall.common.ResultData; +import com.iformall.controller.base.BaseController; +import com.iformall.domain.po.WxCustomizeModule; +import com.iformall.enums.EnumThemeType; +import com.iformall.service.WxCustomizeModuleService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiOperation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@Api(description = "CustomizeModule相关接口") +@RequestMapping("wxCustomizeModule") +public class WxCustomizeModuleController extends BaseController { + + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + + @Autowired + WxCustomizeModuleService wxCustomizeModuleService; + + @ApiOperation("查询CustomizeModule列表") + @GetMapping(value = "/list") + @SystemControllerLog(description = "查询CustomizeModule列表") + public ResultData getList(@ModelAttribute WxCustomizeModule wxCustomizeModule, Integer pageNum, Integer pageSize) { + logger.debug("[" + getIpAddr() + "] WxCustomizeModuleController::getList"); + try { + if(wxCustomizeModule == null){ + wxCustomizeModule = new WxCustomizeModule(); + } + wxCustomizeModule.updateTenantInfo(ifParentUpdateAloneTenantInfo()); + if(wxCustomizeModule.getThemeType() == null){ + wxCustomizeModule.setThemeType(EnumThemeType.C.getCode()); + } + PageInfo page = wxCustomizeModuleService.listAsPage(wxCustomizeModule, pageNum, pageSize); + return new ResultData(page); + }catch (Exception e){ + logger.error(e.getMessage(),e); + return new ResultData(ErrorCode.SYS_SERVER_ERROR); + } + } + + @ApiOperation("恢复主题默认") + @PostMapping("/updateDefault") + @ApiImplicitParam(name = "themeId", value = "themeId", dataType = "Long", paramType = "query", required = true) + @SystemControllerLog(description = "恢复主题默认") + public ResultData updateDefault(@RequestBody WxCustomizeModule wxCustomizeModule) { + logger.debug("[" + getIpAddr() + "] WxCustomizeModuleController::updateDefault"); + if(wxCustomizeModule == null){ + wxCustomizeModule = new WxCustomizeModule(); + } + wxCustomizeModule.updateTenantInfo(ifParentUpdateAloneTenantInfo()); + if(wxCustomizeModule.getThemeType() == null){ + wxCustomizeModule.setThemeType(EnumThemeType.C.getCode()); + } + return wxCustomizeModuleService.updateDefault(wxCustomizeModule); + } + + @ApiOperation("根据id删除接口") + @GetMapping("/del") + @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) + @SystemControllerLog(description = "-删除") + public ResultData delete(Long id) { + logger.debug("[" + getIpAddr() + "] WxCustomizeModuleController::delete"); + if(id == null){ + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); + } + WxCustomizeModule wxCustomizeModule = new WxCustomizeModule(); + wxCustomizeModule.updateTenantInfo(ifParentUpdateAloneTenantInfo()); + wxCustomizeModule.setId(id); + wxCustomizeModuleService.updateDel(wxCustomizeModule); + return new ResultData(Result.SUCCESS, "删除成功", null); + } + + @GetMapping("/isNew") + @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) + @SystemControllerLog(description = "-置顶") + public ResultData isNew(Long id) { + logger.debug("[" + getIpAddr() + "] WxCustomizeModuleController::delete"); + if(id == null){ + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); + } + WxCustomizeModule wxCustomizeModule = new WxCustomizeModule(); + wxCustomizeModule.updateTenantInfo(ifParentUpdateAloneTenantInfo()); + wxCustomizeModule.setId(id); + wxCustomizeModuleService.saveOrUpdate(wxCustomizeModule); + return new ResultData(Result.SUCCESS, "置顶成功", null); + } + + @PostMapping("add") + @SystemControllerLog(description = "-添加") + public ResultData add(@RequestBody WxCustomizeModule wxCustomizeModule) { + logger.debug("[" + getIpAddr() + "] WxCustomizeModuleController::add"); + if(wxCustomizeModule == null){ + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); + } + wxCustomizeModule.updateTenantInfo(ifParentUpdateAloneTenantInfo()); + if(wxCustomizeModule.getThemeType() == null){ + wxCustomizeModule.setThemeType(EnumThemeType.C.getCode()); + } + wxCustomizeModuleService.saveOrUpdate(wxCustomizeModule); + return new ResultData(); + } + + @PostMapping("update") + @SystemControllerLog(description = "更新") + public ResultData update(@RequestBody WxCustomizeModule wxCustomizeModule) { + logger.debug("[" + getIpAddr() + "] WxCustomizeModuleController::update"); + if(wxCustomizeModule == null){ + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); + } + wxCustomizeModule.updateTenantInfo(ifParentUpdateAloneTenantInfo()); + wxCustomizeModuleService.saveOrUpdate(wxCustomizeModule); + return new ResultData(); + } + +} diff --git a/mallinkCApi/src/main/java/com/iformall/controller/WxCustomizeModuleController.java b/mallinkCApi/src/main/java/com/iformall/controller/WxCustomizeModuleController.java new file mode 100644 index 000000000..d012d001b --- /dev/null +++ b/mallinkCApi/src/main/java/com/iformall/controller/WxCustomizeModuleController.java @@ -0,0 +1,50 @@ +package com.iformall.controller; + +import com.iformall.common.ErrorCode; +import com.iformall.common.ResultData; +import com.iformall.domain.po.WxCustomizeModule; +import com.iformall.enums.EnumThemeType; +import com.iformall.enums.EnumYesOrNo; +import com.iformall.service.WxCustomizeModuleService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@Api(description = "CustomizeModule相关接口") +@RequestMapping("/api/wxCustomizeModule") +public class WxCustomizeModuleController extends BaseController { + + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + + @Autowired + WxCustomizeModuleService wxCustomizeModuleService; + + @ApiOperation("查询CustomizeModule列表") + @GetMapping(value = "/list") + public ResultData getList() { + logger.debug("[" + getIpAddr() + "] WxCustomizeModuleController::getList"); + try { + WxCustomizeModule wxCustomizeModule = new WxCustomizeModule(); + wxCustomizeModule.updateTenantInfo(getTenantInfo()); + if(wxCustomizeModule.getThemeType() == null){ + wxCustomizeModule.setThemeType(EnumThemeType.C.getCode()); + } + wxCustomizeModule.setIsUsing(EnumYesOrNo.YES.getCode()); + List list = wxCustomizeModuleService.findList(wxCustomizeModule); + if(list == null || list.size() < 4 || list.size() > 8){ + list = wxCustomizeModuleService.findDefault(wxCustomizeModule); + } + return new ResultData(list); + }catch (Exception e){ + logger.error(e.getMessage(),e); + return new ResultData(ErrorCode.SYS_SERVER_ERROR); + } + } + +} diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxCustomizeModule.java b/mallinkService/src/main/java/com/iformall/domain/po/WxCustomizeModule.java new file mode 100644 index 000000000..1073345fc --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxCustomizeModule.java @@ -0,0 +1,45 @@ +package com.iformall.domain.po; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.iformall.domain.po.base.TenantEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.Date; + +@TableName(value = "wx_customize_module") +@Data +@EqualsAndHashCode(callSuper = true) +public class WxCustomizeModule extends TenantEntity { + + protected Long id; + + @io.swagger.annotations.ApiModelProperty(value="主题",name="themeId") + private Long themeId; + @io.swagger.annotations.ApiModelProperty(value="名称",name="name") + private String name; + @io.swagger.annotations.ApiModelProperty(value="说明",name="remarks") + private String remarks; + @io.swagger.annotations.ApiModelProperty(value="EnumThemeType",name="themeType") + private Integer themeType; + @io.swagger.annotations.ApiModelProperty(value="icon",name="icon") + private String icon; + @io.swagger.annotations.ApiModelProperty(value="style",name="style") + private String style; + @io.swagger.annotations.ApiModelProperty(value="链接类型",name="linkType") + private Integer linkType; + @io.swagger.annotations.ApiModelProperty(value="链接地址",name="linkUrl") + private String linkUrl; + @io.swagger.annotations.ApiModelProperty(value="链接外部小程序ID",name="outLinkAppid") + private String outLinkAppid; + @io.swagger.annotations.ApiModelProperty(value="排序",name="sort") + private Integer sort; + @io.swagger.annotations.ApiModelProperty(value="是否使用",name="isUsing") + private Integer isUsing; + + @io.swagger.annotations.ApiModelProperty(value="创建时间",name="createDate") + private Date createDate; + @io.swagger.annotations.ApiModelProperty(value="更新时间",name="updateDate") + private Date updateDate; + +} diff --git a/mallinkService/src/main/java/com/iformall/mapper/WxCustomizeModuleMapper.java b/mallinkService/src/main/java/com/iformall/mapper/WxCustomizeModuleMapper.java new file mode 100644 index 000000000..a9cfd7c45 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/mapper/WxCustomizeModuleMapper.java @@ -0,0 +1,22 @@ +package com.iformall.mapper; + +import com.iformall.common.CommonMapper; +import com.iformall.domain.po.WxCustomizeModule; + +import java.util.List; + +/** + * @author + */ +public interface WxCustomizeModuleMapper extends CommonMapper { + + List findList(WxCustomizeModule record); + + /** + * 伪删除 + * @param record + */ + int updateDel(WxCustomizeModule record); + + int updateDelByTenantId(WxCustomizeModule record); +} diff --git a/mallinkService/src/main/java/com/iformall/service/WxCustomizeModuleService.java b/mallinkService/src/main/java/com/iformall/service/WxCustomizeModuleService.java new file mode 100644 index 000000000..367dd6611 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/service/WxCustomizeModuleService.java @@ -0,0 +1,29 @@ +package com.iformall.service; + +import com.github.pagehelper.PageInfo; +import com.iformall.common.ResultData; +import com.iformall.domain.po.*; + +import java.util.List; + + +public interface WxCustomizeModuleService { + + List findList(WxCustomizeModule record); + + PageInfo listAsPage(WxCustomizeModule record, Integer pageIndex, Integer pageSize); + + WxCustomizeModule getById(WxCustomizeModule record); + + int saveOrUpdate(WxCustomizeModule record); + + /** + * 伪删除 + * @param record + */ + int updateDel(WxCustomizeModule record); + + List findDefault(WxCustomizeModule record); + + ResultData updateDefault(WxCustomizeModule record); +} diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCustomizeModuleServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCustomizeModuleServiceImpl.java new file mode 100644 index 000000000..108a75971 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCustomizeModuleServiceImpl.java @@ -0,0 +1,112 @@ +package com.iformall.service.impl; + +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import com.iformall.common.IdWorker; +import com.iformall.common.ResultData; +import com.iformall.domain.po.*; +import com.iformall.enums.EnumYesOrNo; +import com.iformall.mapper.WxCustomizeModuleMapper; +import com.iformall.service.WxCustomizeModuleService; +import com.iformall.service.WxMiniappThemeService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Date; +import java.util.List; + +@Service +public class WxCustomizeModuleServiceImpl implements WxCustomizeModuleService { + + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + + @Autowired + WxCustomizeModuleMapper wxCustomizeModuleMapper; + + @Autowired + WxMiniappThemeService wxMiniappThemeService; + + @Override + public List findList(WxCustomizeModule record) { + return wxCustomizeModuleMapper.findList(record); + } + + @Override + public PageInfo listAsPage(WxCustomizeModule record, Integer pageIndex, Integer pageSize) { + return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxCustomizeModuleMapper.findList(record)); + } + + @Override + public WxCustomizeModule getById(WxCustomizeModule record) { + WxCustomizeModule wxCustomizeModule = wxCustomizeModuleMapper.selectById(record.getId()); + return wxCustomizeModule; + } + + + @Override + public int updateDel(WxCustomizeModule record) { + return wxCustomizeModuleMapper.updateDel(record); + } + + @Override + public List findDefault(WxCustomizeModule record) { + //获取主题 + WxThemeMall wxThemeMall = new WxThemeMall(); + wxThemeMall.setTenantId(record.getTenantId()); + wxThemeMall.setThemeType(record.getThemeType()); + WxThemeMall themeMall = wxMiniappThemeService.findThemeMall(wxThemeMall); + Long themeId = 0l; + if(themeMall != null){ + themeId = themeMall.getThemeId(); + }else{ + WxMiniappTheme wxMiniappTheme = new WxMiniappTheme(); + wxMiniappTheme.setTenantId(record.getTenantId()); + wxMiniappTheme.setType(record.getThemeType()); + PageInfo page = wxMiniappThemeService.listAsPage(wxMiniappTheme, 1, 1); + themeId = page.getList().get(0).getId(); + } + //获取默认 + WxCustomizeModule modelQ = new WxCustomizeModule(); + modelQ.setTenantId("0"); + modelQ.setThemeId(themeId); + modelQ.setThemeType(record.getThemeType()); + modelQ.setIsUsing(EnumYesOrNo.YES.getCode()); + return wxCustomizeModuleMapper.findList(modelQ); + } + + @Override + @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) + public ResultData updateDefault(WxCustomizeModule record) { + List aDefault = this.findDefault(record); + //删除旧数据 + wxCustomizeModuleMapper.updateDelByTenantId(record); + //创建新数据 + for (WxCustomizeModule module:aDefault) { + module.setId(null); + module.updateTenantInfo(record); + module.setThemeId(null); + this.saveOrUpdate(module); + } + return new ResultData(); + } + + @Override + public int saveOrUpdate(WxCustomizeModule record) { + final IdWorker idWorker = IdWorker.get(); + Date curr = new Date(); + if (record.getId() == null) { + record.setId(idWorker.nextId()); + record.setCreateDate(curr); + record.setUpdateDate(curr); + return wxCustomizeModuleMapper.insert(record); + } else { + record.setUpdateDate(curr); + return wxCustomizeModuleMapper.updateById(record); + } + } + +} diff --git a/mallinkService/src/main/resources/mapper/WxCustomizeModuleMapper.xml b/mallinkService/src/main/resources/mapper/WxCustomizeModuleMapper.xml new file mode 100644 index 000000000..038339be1 --- /dev/null +++ b/mallinkService/src/main/resources/mapper/WxCustomizeModuleMapper.xml @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + `id`,`tenant_id`,`parent_tenant_id`,`theme_id`,`name`,`remarks`,`theme_type`,`icon`,`style`,`link_type`,`link_url`,`out_link_appid`, + `sort`,`is_using`, + `create_date`,`update_date` + + + + where del_status = 0 + and `id` = #{id} + + and `tenant_id` = #{tenantId} + + + and `parent_tenant_id` = #{parentTenantId} + + + and `theme_id` = #{themeId} + + and `name` like concat('%', #{name},'%') + + and `theme_type` = #{themeType} + + + and `link_type` = #{linkType} + + + and `is_using` = #{isUsing} + + order by `is_using` desc, `sort` asc, `update_date` desc + + + + + + update wx_customize_module set `del_status` = 1, update_date = now() where id = #{id}; + + + + update wx_customize_module set `del_status` = 1, update_date = now() where tenant_id = #{tenantId}; + + +