Pārlūkot izejas kodu

application model

sunmingan 4 gadi atpakaļ
vecāks
revīzija
1c2e29219f

+ 74 - 0
mpwechatApp/src/main/java/com/liangjian11/wx/mp/controller/application/ApplicationController.java

@@ -0,0 +1,74 @@
+package com.liangjian11.wx.mp.controller.application;
+
+
+import com.liangjian11.wx.mp.modle.Application;
+import com.liangjian11.wx.mp.modle.ChannelPort;
+import com.liangjian11.wx.mp.service.ApplicationService;
+import com.liangjian11.wx.mp.service.ChannelPortService;
+import com.liangjian11.wx.mp.service.WxOpenServiceDemo;
+import com.liangjian11.wx.mp.utils.FiltersData;
+import com.liangjian11.wx.mp.utils.ResultInfo;
+import me.chanjar.weixin.mp.api.WxMpService;
+import org.apache.commons.lang.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+/**
+ * 应用管理模块
+ */
+@CrossOrigin
+@RestController
+@RequestMapping("/wx/application")
+public class ApplicationController {
+
+    @Autowired
+    ApplicationService appService;
+
+
+    /**
+     * 保存应用信息
+     * @param app
+     * @return
+     * @throws Exception
+     */
+    @PostMapping("/save")
+    public ResultInfo save(@RequestBody(required=false) Application app) throws Exception{
+        // 参数逻辑校验
+        if(app == null){
+            return new ResultInfo(ResultInfo.TYPE_RESULT_INFO,200,"缺少必要的参数!");
+        }
+        if(StringUtils.isBlank(app.getName())){
+            return new ResultInfo(ResultInfo.TYPE_RESULT_INFO,200,"应用名称不能为空!");
+        }
+        //wxOpenServiceDemo.getWxOpenComponentService().getAuthorizerAccessToken()
+        return appService.save(app);
+    }
+
+    /**
+     * 分页查询所有的端口信息列表
+     * @param data
+     * @return
+     */
+    @PostMapping("/getAll")
+    public ResultInfo getAll(@RequestBody(required=false) FiltersData data){
+        if(data == null){
+            return new ResultInfo(ResultInfo.TYPE_RESULT_INFO,200,"缺少必要的参数!");
+        }
+        return  appService.queryExternalList(data);
+    }
+
+    /**
+     *上架下架操作
+     * @param id 主键ID
+     * @return
+     */
+    @GetMapping("/shelves")
+    public ResultInfo shelves(@PathVariable Integer id){
+        //逻辑校验
+        if(id == null){
+            return new ResultInfo(ResultInfo.TYPE_RESULT_INFO,200,"缺少必要的参数!");
+        }
+
+        return appService.updateShelves(id);
+    }
+}

+ 63 - 0
mpwechatApp/src/main/java/com/liangjian11/wx/mp/mapper/ApplicationMapper.java

@@ -0,0 +1,63 @@
+package com.liangjian11.wx.mp.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.liangjian11.wx.mp.modle.Application;
+import com.liangjian11.wx.mp.modle.ChannelPort;
+import org.apache.ibatis.annotations.*;
+
+import java.util.List;
+import java.util.Map;
+
+public interface ApplicationMapper extends BaseMapper<Application> {
+
+
+    /**
+     * 新增
+     * @param app
+     */
+    @Insert("INSERT INTO application ([type],[name], [img], [phrase], [enterUrl], [content], [createTime], [updateTime], [state] ,[appType]) VALUES" +
+        " (#{app.type},#{app.name} ,#{app.img}, #{app.phrase}, #{app.enterUrl}, #{app.content}, #{app.createTime}, #{app.updateTime}, #{app.state} ,#{app.appType}})")
+    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")/*增加这个注解插入记录后会返回自增长的id*/
+    void insertAppcation(@Param("app") Application app);
+
+    /**
+     * 根据ID进行 update 操作
+     * @param app
+     */
+    @Update("<script> " +
+        "update application  " +
+        "<trim prefix='set' suffixOverrides=','> " +
+        "<if test='type!=null and type.length() > 0'> type = #{type},</if>" +
+        "<if test='name!=null and name.length() > 0'> name=#{name} ,</if>\n" +
+        "<if test='img!=null and img.length() > 0'> img=#{img} ,</if>\n" +
+        "<if test='phrase!=null and phrase.length() > 0'> phrase=#{phrase} ,</if>\n" +
+        "<if test='enterUrl!=null and enterUrl.length() > 0'> enterUrl=#{enterUrl}, </if>" +
+        "<if test='content!=null and content.length() > 0'> content=#{content},</if> " +
+        "<if test='createTime!=null and createTime.length() > 0'> createTime=#{createTime},</if> " +
+        "<if test='updateTime!=null and updateTime.length() > 0'> updateTime=#{updateTime},</if> " +
+        "<if test='state!=null and state.length() > 0'> state=#{state},</if> " +
+        "<if test='appType!=null and appType.length() > 0'> appType=#{appType},</if> " +
+        "</trim>"+
+        " where id = #{id} " +
+        "</script>")
+    void updateByIdSelect(Application app);
+
+    /**
+     * 分页查询
+     * @param sqlStr
+     * @param index
+     * @param size
+     * @return
+     */
+    @Select("SELECT * from (select  row_number() over (  order by u.createTime DESC)  as rownum,u.* from application u ${sqlStr} ) A where A.rownum>#{index} AND A.rownum<#{size} ")
+    List<Application> queryExternalList(@Param("sqlStr") String sqlStr, @Param("index") Integer index, @Param("size") Integer size);
+
+    /**
+     * 根据条件查询数量
+     * @param sqlStr
+     * @return
+     */
+    @Select("select count(1) from application u ${sqlStr} ")
+    int queryExternalCount(@Param("sqlStr") String sqlStr);
+
+}

+ 52 - 0
mpwechatApp/src/main/java/com/liangjian11/wx/mp/modle/Application.java

@@ -0,0 +1,52 @@
+package com.liangjian11.wx.mp.modle;
+
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.io.Serializable;
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+@TableName("application")
+public class Application implements Serializable {
+
+    @TableId(value = "id", type = IdType.AUTO)
+    private Integer id;
+
+    @TableField("type")
+    private String type;
+
+    @TableField("name")
+    private String name;
+
+    @TableField("img")
+    private String img;
+
+    @TableField("phrase")
+    private String phrase;
+
+    @TableField("enterUrl")
+    private String enterUrl;
+
+    @TableField("content")
+    private String content;
+
+    @TableField("createTime")
+    private String createTime;
+
+    @TableField("updateTime")
+    private String updateTime;
+
+    @TableField("state")
+    private String state;
+
+    @TableField("appType")
+    private String appType;
+}

+ 43 - 0
mpwechatApp/src/main/java/com/liangjian11/wx/mp/service/ApplicationService.java

@@ -0,0 +1,43 @@
+package com.liangjian11.wx.mp.service;
+
+import com.liangjian11.wx.mp.modle.Application;
+import com.liangjian11.wx.mp.modle.ChannelPort;
+import com.liangjian11.wx.mp.utils.FiltersData;
+import com.liangjian11.wx.mp.utils.ResultInfo;
+
+public interface ApplicationService {
+
+    /**
+     * 新增应用信息
+     * @param app
+     * @throws Exception
+     */
+    void insertInfo(Application app) throws Exception;
+
+    /**
+     * 分页查询 端口列表
+     * @param data
+     * @return
+     */
+    ResultInfo queryExternalList(FiltersData data);
+
+    /**
+     * 编辑应用信息
+     * @param app
+     */
+    void updateByIdSelect(Application app);
+
+    /**
+     * 保存应用信息
+     * @param app
+     * @return
+     */
+    ResultInfo save(Application app);
+
+    /**
+     * 应用上下架操作
+     * @param id
+     * @return
+     */
+    ResultInfo updateShelves(Integer id);
+}

+ 88 - 0
mpwechatApp/src/main/java/com/liangjian11/wx/mp/service/impl/ApplicationServiceImpl.java

@@ -0,0 +1,88 @@
+package com.liangjian11.wx.mp.service.impl;
+
+import com.liangjian11.wx.mp.mapper.ApplicationMapper;
+import com.liangjian11.wx.mp.modle.Application;
+import com.liangjian11.wx.mp.service.ApplicationService;
+import com.liangjian11.wx.mp.utils.DateUtil;
+import com.liangjian11.wx.mp.utils.FiltersData;
+import com.liangjian11.wx.mp.utils.ResultInfo;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@Service
+public class ApplicationServiceImpl implements ApplicationService {
+
+    @Autowired
+    ApplicationMapper appMapper;
+
+    @Override
+    public void insertInfo(Application app) throws Exception {
+        appMapper.insert(app);
+    }
+
+    public ResultInfo queryExternalList(FiltersData data) {
+        int start = (data.getPageIndex()-1) * data.getPageSize();
+        int end = (start + 1 + data.getPageSize());
+        //动态条件
+        String sqlStr=data.getFilterString();
+        Integer totalCount=this.appMapper.queryExternalCount(sqlStr);
+
+        List<Application> list = new ArrayList<>();
+        if(totalCount != null && totalCount > 0){
+            list = this.appMapper.queryExternalList(sqlStr,start,end);
+        }
+        ResultInfo result = new ResultInfo(ResultInfo.TYPE_RESULT_SUCCESS,100,"操作成功!");
+        result.setItems(list);
+        result.setTotalCount(totalCount);
+        return result;
+    }
+
+    @Override
+    public void updateByIdSelect(Application app) {
+        appMapper.updateByIdSelect(app);
+    }
+
+    @Override
+    public ResultInfo save(Application app) {
+        /**
+         * 业务操作
+         */
+        if(app.getId() == null){
+            //新增
+            app.setCreateTime(DateUtil.getNowDateTimeStr());
+            app.setUpdateTime(DateUtil.getNowDateTimeStr());
+            appMapper.insertAppcation(app);
+        } else {
+            //编辑
+            app.setUpdateTime(DateUtil.getNowDateTimeStr());
+            appMapper.updateByIdSelect(app);
+        }
+        return new ResultInfo(ResultInfo.TYPE_RESULT_SUCCESS,200,"操作成功!");
+    }
+
+
+    @Override
+    public ResultInfo updateShelves(Integer id) {
+        /**
+         * 业务校验 目前没有具体业务 直接根据数据库的状态进行修改
+         */
+        Application app = appMapper.selectById(id);
+        if(app == null ){
+            return new ResultInfo(ResultInfo.TYPE_RESULT_INFO,200,"没有对应的应用!");
+        }
+
+        Application updateApp = new Application();
+        updateApp.setId(app.getId());
+        //状态更换
+        if("0".equals(app.getState())){
+            updateApp.setState("1");
+        }else if("1".equals(app.getState())){
+            updateApp.setState("0");
+        }
+        appMapper.updateByIdSelect(updateApp);
+        return new ResultInfo(ResultInfo.TYPE_RESULT_SUCCESS,200,"操作成功!");
+    }
+}