|  |  |  | 
|---|
|  |  |  | import com.zy.acs.manager.common.domain.PageParam; | 
|---|
|  |  |  | import com.zy.acs.manager.common.utils.ExcelUtil; | 
|---|
|  |  |  | import com.zy.acs.manager.system.entity.Config; | 
|---|
|  |  |  | import com.zy.acs.manager.system.entity.User; | 
|---|
|  |  |  | import com.zy.acs.manager.system.service.ConfigService; | 
|---|
|  |  |  | import com.zy.acs.manager.system.service.impl.ConfigServiceImpl; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.security.access.prepost.PreAuthorize; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.*; | 
|---|
|  |  |  | 
|---|
|  |  |  | @OperationLog("Create Config") | 
|---|
|  |  |  | @PostMapping("/config/save") | 
|---|
|  |  |  | public R save(@RequestBody Config config) { | 
|---|
|  |  |  | if (!Cools.isEmpty(config.getFlag()) | 
|---|
|  |  |  | && 0 < configService.count(new LambdaQueryWrapper<Config>().eq(Config::getFlag, config.getFlag()))) { | 
|---|
|  |  |  | return R.error("failed to save config, because the " + config.getFlag() + " flag already exist"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | config.setUuid(String.valueOf(snowflakeIdWorker.nextId()).substring(3)); | 
|---|
|  |  |  | config.setCreateBy(getLoginUserId()); | 
|---|
|  |  |  | config.setCreateTime(new Date()); | 
|---|
|  |  |  | 
|---|
|  |  |  | config.setUpdateTime(new Date()); | 
|---|
|  |  |  | if (!configService.save(config)) { | 
|---|
|  |  |  | return R.error("Save Fail"); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | ConfigServiceImpl.CONFIG_CACHE.put(config.getFlag(), config); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok("Save Success").add(config); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | @OperationLog("Update Config") | 
|---|
|  |  |  | @PostMapping("/config/update") | 
|---|
|  |  |  | public R update(@RequestBody Config config) { | 
|---|
|  |  |  | if (!Cools.isEmpty(config.getFlag()) && configService.count(new LambdaQueryWrapper<Config>() | 
|---|
|  |  |  | .eq(Config::getFlag, config.getFlag()) | 
|---|
|  |  |  | .ne(Config::getId, config.getId())) > 0) { | 
|---|
|  |  |  | return R.error("the flag already exist"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | config.setUpdateBy(getLoginUserId()); | 
|---|
|  |  |  | config.setUpdateTime(new Date()); | 
|---|
|  |  |  | if (!configService.updateById(config)) { | 
|---|
|  |  |  | return R.error("Update Fail"); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | ConfigServiceImpl.CONFIG_CACHE.put(config.getFlag(), config); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok("Update Success").add(config); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | @OperationLog("Delete Config") | 
|---|
|  |  |  | @PostMapping("/config/remove/{ids}") | 
|---|
|  |  |  | public R remove(@PathVariable Long[] ids) { | 
|---|
|  |  |  | List<String> flagList = new ArrayList<>(); | 
|---|
|  |  |  | for (Long id : ids) { | 
|---|
|  |  |  | Config config = configService.getById(id); | 
|---|
|  |  |  | flagList.add(config.getFlag()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!configService.removeByIds(Arrays.asList(ids))) { | 
|---|
|  |  |  | return R.error("Delete Fail"); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | for (String flag : flagList) { | 
|---|
|  |  |  | ConfigServiceImpl.CONFIG_CACHE.remove(flag); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok("Delete Success").add(ids); | 
|---|
|  |  |  | } | 
|---|