自动化立体仓库 - WMS系统
zjj
2025-06-07 230615d093a235e2e481355edb47f37e380b3069
#app
5个文件已修改
141 ■■■■■ 已修改文件
src/main/java/com/zy/asrs/controller/AppVersionController.java 110 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/mapper/AppVersionMapper.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/service/AppVersionService.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/service/impl/AppVersionServiceImpl.java 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/AppVersionMapper.xml 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/controller/AppVersionController.java
@@ -1,21 +1,26 @@
package com.zy.asrs.controller;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.core.common.DateUtils;
import com.zy.asrs.entity.AppVersion;
import com.zy.asrs.service.AppVersionService;
import com.core.annotations.ManagerAuth;
import com.core.common.BaseRes;
import com.core.common.Cools;
import com.core.common.DateUtils;
import com.core.common.R;
import com.zy.asrs.entity.AppVersion;
import com.zy.asrs.service.AppVersionService;
import com.zy.common.web.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.util.ClassUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;
@RestController
@@ -46,6 +51,26 @@
        return R.ok(appVersionService.selectPage(new Page<>(curr, limit), wrapper));
    }
    @RequestMapping(value = "/appVersion/checkUpdate/{version}/{type}")
    public R checkUpdate(@PathVariable("version") String version,
                         @PathVariable("type") Integer type) {
        EntityWrapper<AppVersion> wrapper = new EntityWrapper<>();
        AppVersion appVersion = appVersionService.selectOne(wrapper);
        if (Cools.isEmpty(appVersion)) {
            return R.ok("已是最新版本");
        }
        AppVersion latestApp = appVersionService.getLatestApp(type);
        if (latestApp == null) {
            return R.error();
        }
        if (latestApp.getVersion().equals(version)) {
            return R.ok("已是最新版本");
        }
        return R.ok("有新版本,需要更新").add(latestApp);
    }
    private <T> void convert(Map<String, Object> map, EntityWrapper<T> wrapper){
        for (Map.Entry<String, Object> entry : map.entrySet()){
            String val = String.valueOf(entry.getValue());
@@ -62,15 +87,23 @@
    @RequestMapping(value = "/appVersion/add/auth")
    @ManagerAuth
    public R add(AppVersion appVersion) {
        if (appVersion.getLatest() == 1) {
            //修改最新版本时,需要将其他版本设置为非最新版
            appVersionService.updateLatest(0, appVersion.getType());
        }
        appVersionService.insert(appVersion);
        return R.ok();
    }
    @RequestMapping(value = "/appVersion/update/auth")
    @ManagerAuth
    @RequestMapping(value = "/appVersion/update/auth")
    @ManagerAuth
    public R update(AppVersion appVersion){
        if (Cools.isEmpty(appVersion) || null==appVersion.getId()){
            return R.error();
        }
        if (appVersion.getLatest() == 1) {
            //修改最新版本时,需要将其他版本设置为非最新版
            appVersionService.updateLatest(0, appVersion.getType());
        }
        appVersionService.updateById(appVersion);
        return R.ok();
@@ -79,7 +112,7 @@
    @RequestMapping(value = "/appVersion/delete/auth")
    @ManagerAuth
    public R delete(@RequestParam(value="ids[]") Long[] ids){
         for (Long id : ids){
        for (Long id : ids){
            appVersionService.deleteById(id);
        }
        return R.ok();
@@ -122,4 +155,67 @@
        return R.ok();
    }
    @RequestMapping(value = "/appVersion/uploadApp/auth")
    @ManagerAuth
    public R uploadApp(@RequestParam("id") Integer id,
                       @RequestParam("file") MultipartFile[] files){
        AppVersion appVersion = appVersionService.selectById(id);
        MultipartFile file = files[0];
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd_HHmmss");
        String path =  ClassUtils.getDefaultClassLoader().getResource("appVersion").getPath();
        //文件后缀名
        String suffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
        //上传文件名
        String filename = format.format(new Date()) + suffix;
        //最终文件路径
        String filepath = path + "/" + filename;
        //服务器端保存的文件对象
        File serverFile = new File(filepath);
        if(!serverFile.exists()) {
            try {
                //创建文件
                serverFile.createNewFile();
                //将上传的文件写入到服务器端文件内
                file.transferTo(serverFile);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        //保存文件名
        appVersion.setPath(filename);
        appVersionService.updateById(appVersion);
        return R.ok();
    }
    @RequestMapping("/appVersion/downloadApp/{filename}")
    public void download(@PathVariable String filename, HttpServletResponse response) {
        try {
            ClassPathResource pathResource = new ClassPathResource("appVersion/" + filename);
            File file = pathResource.getFile();
            InputStream inputStream = pathResource.getInputStream();
            //输出文件
            InputStream fis = new BufferedInputStream(inputStream);
            byte[] buffer = new byte[fis.available()];
            fis.read(buffer);
            fis.close();
            response.reset();
            //获取文件的名字再浏览器下载页面
            String name = file.getName();
            response.addHeader("Content-Disposition", "attachment;filename=" + new String(name.getBytes(), "iso-8859-1"));
            response.addHeader("Content-Length", "" + file.length());
            OutputStream out = new BufferedOutputStream(response.getOutputStream());
            response.setContentType("application/octet-stream");
            out.write(buffer);
            out.flush();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
            response.setStatus(404);
        }
    }
}
src/main/java/com/zy/asrs/mapper/AppVersionMapper.java
@@ -9,4 +9,7 @@
@Repository
public interface AppVersionMapper extends BaseMapper<AppVersion> {
    int updateLatest(int latest, int type);
    AppVersion getLatestApp(Integer type);
}
src/main/java/com/zy/asrs/service/AppVersionService.java
@@ -5,4 +5,8 @@
public interface AppVersionService extends IService<AppVersion> {
    int updateLatest(int latest, int type);
    AppVersion getLatestApp(Integer type);
}
src/main/java/com/zy/asrs/service/impl/AppVersionServiceImpl.java
@@ -9,4 +9,14 @@
@Service("appVersionService")
public class AppVersionServiceImpl extends ServiceImpl<AppVersionMapper, AppVersion> implements AppVersionService {
    @Override
    public int updateLatest(int latest, int type) {
        return this.baseMapper.updateLatest(latest, type);
    }
    @Override
    public AppVersion getLatestApp(Integer type) {
        return this.baseMapper.getLatestApp(type);
    }
}
src/main/resources/mapper/AppVersionMapper.xml
@@ -12,4 +12,18 @@
    </resultMap>
    <select id="getLatestApp" resultMap="BaseResultMap">
        select top 1 * from asr_app_version
        where type = #{type} and latest = 1
    </select>
    <update id="updateLatest">
        update asr_app_version
        set latest = #{latest}
        where 1 = 1
        <if test="type != null || type != ''">
            and type = #{type}
        </if>
    </update>
</mapper>