|  |  | 
 |  |  | package com.zy.asrs.wms.system.controller; | 
 |  |  |  | 
 |  |  | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
 |  |  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
 |  |  | import com.zy.asrs.framework.common.Cools; | 
 |  |  | import com.zy.asrs.framework.common.R; | 
 |  |  | import com.zy.asrs.wms.common.annotation.CacheData; | 
 |  |  | import com.zy.asrs.wms.common.annotation.OperationLog; | 
 |  |  | import com.zy.asrs.wms.common.domain.BaseParam; | 
 |  |  | import com.zy.asrs.wms.common.domain.KeyValVo; | 
 |  |  | import com.zy.asrs.wms.common.domain.PageParam; | 
 |  |  | import com.zy.asrs.wms.system.entity.Language; | 
 |  |  | import com.zy.asrs.wms.system.service.LanguageService; | 
 |  |  | import com.zy.asrs.wms.system.controller.BaseController; | 
 |  |  | import com.zy.asrs.wms.utils.ExcelUtil; | 
 |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
 |  |  | import org.springframework.security.access.prepost.PreAuthorize; | 
 |  |  | import org.springframework.web.bind.annotation.*; | 
 |  |  |  | 
 |  |  | import javax.servlet.http.HttpServletResponse; | 
 |  |  | import java.util.*; | 
 |  |  |  | 
 |  |  | @RestController | 
 |  |  | @RequestMapping("/api") | 
 |  |  | public class LanguageController extends BaseController { | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private LanguageService languageService; | 
 |  |  |  | 
 |  |  |     @PreAuthorize("hasAuthority('system:language:list')") | 
 |  |  |     @PostMapping("/language/page") | 
 |  |  |     @CacheData(tableName = {"sys_language"}) | 
 |  |  |     public R page(@RequestBody Map<String, Object> map) { | 
 |  |  |         BaseParam baseParam = buildParam(map, BaseParam.class); | 
 |  |  |         PageParam<Language, BaseParam> pageParam = new PageParam<>(baseParam, Language.class); | 
 |  |  |         return R.ok().add(languageService.page(pageParam, pageParam.buildWrapper(true))); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @PreAuthorize("hasAuthority('system:language:list')") | 
 |  |  |     @PostMapping("/language/list") | 
 |  |  |     @CacheData(tableName = {"sys_language"}) | 
 |  |  |     public R list(@RequestBody Map<String, Object> map) { | 
 |  |  |         return R.ok().add(languageService.list()); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @PostMapping("/language/json") | 
 |  |  |     @CacheData(tableName = {"sys_language"}) | 
 |  |  |     public R json(@RequestBody Map<String, Object> map) { | 
 |  |  |         LambdaQueryWrapper<Language> wrapper = new LambdaQueryWrapper<>(); | 
 |  |  |         if(map.containsKey("locale")){ | 
 |  |  |             wrapper.eq(Language::getLocale, map.get("locale")); | 
 |  |  |         } | 
 |  |  |         List<Language> list = languageService.list(wrapper); | 
 |  |  |         HashMap<String, String> data = new HashMap<>(); | 
 |  |  |         for (Language language : list) { | 
 |  |  |             data.put(language.getLanguageId(), language.getName()); | 
 |  |  |         } | 
 |  |  |         return R.ok().add(data); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @PreAuthorize("hasAuthority('system:language:list')") | 
 |  |  |     @GetMapping("/language/{id}") | 
 |  |  |     @CacheData(tableName = {"sys_language"}) | 
 |  |  |     public R get(@PathVariable("id") Long id) { | 
 |  |  |         return R.ok().add(languageService.getById(id)); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @PreAuthorize("hasAuthority('system:language:save')") | 
 |  |  |     @OperationLog("添加国际化配置") | 
 |  |  |     @PostMapping("/language/save") | 
 |  |  |     public R save(@RequestBody Language language) { | 
 |  |  |         if (!languageService.save(language)) { | 
 |  |  |             return R.error("添加失败"); | 
 |  |  |         } | 
 |  |  |         return R.ok("添加成功"); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @PreAuthorize("hasAuthority('system:language:update')") | 
 |  |  |     @OperationLog("修改国际化配置") | 
 |  |  |     @PostMapping("/language/update") | 
 |  |  |     public R update(@RequestBody Language language) { | 
 |  |  |         if (!languageService.updateById(language)) { | 
 |  |  |             return R.error("修改失败"); | 
 |  |  |         } | 
 |  |  |         return R.ok("修改成功"); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @PreAuthorize("hasAuthority('system:language:remove')") | 
 |  |  |     @OperationLog("删除国际化配置") | 
 |  |  |     @PostMapping("/language/remove/{ids}") | 
 |  |  |     public R remove(@PathVariable Long[] ids) { | 
 |  |  |         if (!languageService.removeByIds(Arrays.asList(ids))) { | 
 |  |  |             return R.error("删除失败"); | 
 |  |  |         } | 
 |  |  |         return R.ok("删除成功"); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @PreAuthorize("hasAuthority('system:language:list')") | 
 |  |  |     @PostMapping("/language/query") | 
 |  |  |     public R query(@RequestParam(required = false) String condition) { | 
 |  |  |         List<KeyValVo> vos = new ArrayList<>(); | 
 |  |  |         LambdaQueryWrapper<Language> wrapper = new LambdaQueryWrapper<>(); | 
 |  |  |         if (!Cools.isEmpty(condition)) { | 
 |  |  |             wrapper.like(Language::getName, condition); | 
 |  |  |         } | 
 |  |  |         languageService.page(new Page<>(1, 30), wrapper).getRecords().forEach( | 
 |  |  |                 item -> vos.add(new KeyValVo(item.getId(), item.getName())) | 
 |  |  |         ); | 
 |  |  |         return R.ok().add(vos); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @PreAuthorize("hasAuthority('system:language:list')") | 
 |  |  |     @PostMapping("/language/export") | 
 |  |  |     public void export(@RequestBody Map<String, Object> map, HttpServletResponse response) throws Exception { | 
 |  |  |         ExcelUtil.build(ExcelUtil.create(languageService.list(), Language.class), response); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | } | 
 |  |  | package com.zy.asrs.wms.system.controller;
 | 
 |  |  | 
 | 
 |  |  | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 | 
 |  |  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 | 
 |  |  | import com.zy.asrs.framework.common.Cools;
 | 
 |  |  | import com.zy.asrs.framework.common.R;
 | 
 |  |  | import com.zy.asrs.wms.common.annotation.CacheData;
 | 
 |  |  | import com.zy.asrs.wms.common.annotation.OperationLog;
 | 
 |  |  | import com.zy.asrs.wms.common.domain.BaseParam;
 | 
 |  |  | import com.zy.asrs.wms.common.domain.KeyValVo;
 | 
 |  |  | import com.zy.asrs.wms.common.domain.PageParam;
 | 
 |  |  | import com.zy.asrs.wms.system.entity.Language;
 | 
 |  |  | import com.zy.asrs.wms.system.service.LanguageService;
 | 
 |  |  | import com.zy.asrs.wms.system.controller.BaseController;
 | 
 |  |  | import com.zy.asrs.wms.utils.ExcelUtil;
 | 
 |  |  | import org.springframework.beans.factory.annotation.Autowired;
 | 
 |  |  | import org.springframework.security.access.prepost.PreAuthorize;
 | 
 |  |  | import org.springframework.web.bind.annotation.*;
 | 
 |  |  | 
 | 
 |  |  | import javax.servlet.http.HttpServletResponse;
 | 
 |  |  | import java.util.*;
 | 
 |  |  | 
 | 
 |  |  | @RestController
 | 
 |  |  | @RequestMapping("/api")
 | 
 |  |  | public class LanguageController extends BaseController {
 | 
 |  |  | 
 | 
 |  |  |     @Autowired
 | 
 |  |  |     private LanguageService languageService;
 | 
 |  |  | 
 | 
 |  |  |     @PreAuthorize("hasAuthority('system:language:list')")
 | 
 |  |  |     @PostMapping("/language/page")
 | 
 |  |  |     @CacheData(tableName = {"sys_language"})
 | 
 |  |  |     public R page(@RequestBody Map<String, Object> map) {
 | 
 |  |  |         BaseParam baseParam = buildParam(map, BaseParam.class);
 | 
 |  |  |         PageParam<Language, BaseParam> pageParam = new PageParam<>(baseParam, Language.class);
 | 
 |  |  |         return R.ok().add(languageService.page(pageParam, pageParam.buildWrapper(true)));
 | 
 |  |  |     }
 | 
 |  |  | 
 | 
 |  |  |     @PreAuthorize("hasAuthority('system:language:list')")
 | 
 |  |  |     @PostMapping("/language/list")
 | 
 |  |  |     @CacheData(tableName = {"sys_language"})
 | 
 |  |  |     public R list(@RequestBody Map<String, Object> map) {
 | 
 |  |  |         return R.ok().add(languageService.list());
 | 
 |  |  |     }
 | 
 |  |  | 
 | 
 |  |  |     @PostMapping("/language/json")
 | 
 |  |  |     @CacheData(tableName = {"sys_language"})
 | 
 |  |  |     public R json(@RequestBody Map<String, Object> map) {
 | 
 |  |  |         LambdaQueryWrapper<Language> wrapper = new LambdaQueryWrapper<>();
 | 
 |  |  |         if(map.containsKey("locale")){
 | 
 |  |  |             wrapper.eq(Language::getLocale, map.get("locale"));
 | 
 |  |  |         }
 | 
 |  |  |         List<Language> list = languageService.list(wrapper);
 | 
 |  |  |         HashMap<String, String> data = new HashMap<>();
 | 
 |  |  |         for (Language language : list) {
 | 
 |  |  |             data.put(language.getLanguageId(), language.getName());
 | 
 |  |  |         }
 | 
 |  |  |         return R.ok().add(data);
 | 
 |  |  |     }
 | 
 |  |  | 
 | 
 |  |  |     @PreAuthorize("hasAuthority('system:language:list')")
 | 
 |  |  |     @GetMapping("/language/{id}")
 | 
 |  |  |     @CacheData(tableName = {"sys_language"})
 | 
 |  |  |     public R get(@PathVariable("id") Long id) {
 | 
 |  |  |         return R.ok().add(languageService.getById(id));
 | 
 |  |  |     }
 | 
 |  |  | 
 | 
 |  |  |     @PreAuthorize("hasAuthority('system:language:save')")
 | 
 |  |  |     @OperationLog("添加国际化配置")
 | 
 |  |  |     @PostMapping("/language/save")
 | 
 |  |  |     public R save(@RequestBody Language language) {
 | 
 |  |  |         if (!languageService.save(language)) {
 | 
 |  |  |             return R.error("添加失败");
 | 
 |  |  |         }
 | 
 |  |  |         return R.ok("添加成功");
 | 
 |  |  |     }
 | 
 |  |  | 
 | 
 |  |  |     @PreAuthorize("hasAuthority('system:language:update')")
 | 
 |  |  |     @OperationLog("修改国际化配置")
 | 
 |  |  |     @PostMapping("/language/update")
 | 
 |  |  |     public R update(@RequestBody Language language) {
 | 
 |  |  |         if (!languageService.updateById(language)) {
 | 
 |  |  |             return R.error("修改失败");
 | 
 |  |  |         }
 | 
 |  |  |         return R.ok("修改成功");
 | 
 |  |  |     }
 | 
 |  |  | 
 | 
 |  |  |     @PreAuthorize("hasAuthority('system:language:remove')")
 | 
 |  |  |     @OperationLog("删除国际化配置")
 | 
 |  |  |     @PostMapping("/language/remove/{ids}")
 | 
 |  |  |     public R remove(@PathVariable Long[] ids) {
 | 
 |  |  |         if (!languageService.removeByIds(Arrays.asList(ids))) {
 | 
 |  |  |             return R.error("删除失败");
 | 
 |  |  |         }
 | 
 |  |  |         return R.ok("删除成功");
 | 
 |  |  |     }
 | 
 |  |  | 
 | 
 |  |  |     @PreAuthorize("hasAuthority('system:language:list')")
 | 
 |  |  |     @PostMapping("/language/query")
 | 
 |  |  |     public R query(@RequestParam(required = false) String condition) {
 | 
 |  |  |         List<KeyValVo> vos = new ArrayList<>();
 | 
 |  |  |         LambdaQueryWrapper<Language> wrapper = new LambdaQueryWrapper<>();
 | 
 |  |  |         if (!Cools.isEmpty(condition)) {
 | 
 |  |  |             wrapper.like(Language::getName, condition);
 | 
 |  |  |         }
 | 
 |  |  |         languageService.page(new Page<>(1, 30), wrapper).getRecords().forEach(
 | 
 |  |  |                 item -> vos.add(new KeyValVo(item.getId(), item.getName()))
 | 
 |  |  |         );
 | 
 |  |  |         return R.ok().add(vos);
 | 
 |  |  |     }
 | 
 |  |  | 
 | 
 |  |  |     @PreAuthorize("hasAuthority('system:language:list')")
 | 
 |  |  |     @PostMapping("/language/export")
 | 
 |  |  |     public void export(@RequestBody Map<String, Object> map, HttpServletResponse response) throws Exception {
 | 
 |  |  |         BaseParam baseParam = buildParam(map, BaseParam.class);
 | 
 |  |  |         PageParam<Language, BaseParam> pageParam = new PageParam<>(baseParam, Language.class);
 | 
 |  |  |         List<Language> data = languageService.list(pageParam.buildWrapper(true));
 | 
 |  |  | 
 | 
 |  |  |         ExcelUtil.build(ExcelUtil.create(data, Language.class), response);
 | 
 |  |  |     }
 | 
 |  |  | 
 | 
 |  |  | }
 |