| | |
| | | package com.zy.acs.manager.manager.controller; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.zy.acs.common.constant.CommonConstant; |
| | |
| | | import com.zy.acs.common.utils.Utils; |
| | | import com.zy.acs.framework.common.Cools; |
| | | import com.zy.acs.framework.common.R; |
| | | import com.zy.acs.framework.exception.CoolException; |
| | | import com.zy.acs.manager.common.annotation.OperationLog; |
| | | import com.zy.acs.manager.common.domain.BaseParam; |
| | | import com.zy.acs.manager.common.domain.KeyValVo; |
| | | import com.zy.acs.manager.common.domain.PageParam; |
| | | import com.zy.acs.manager.common.utils.ExcelUtil; |
| | | import com.zy.acs.manager.manager.entity.Code; |
| | | import com.zy.acs.manager.manager.entity.CodeGap; |
| | | import com.zy.acs.manager.manager.entity.Route; |
| | | import com.zy.acs.manager.manager.service.CodeGapService; |
| | | import com.zy.acs.manager.manager.service.CodeService; |
| | | import com.zy.acs.manager.manager.service.RouteService; |
| | | import com.zy.acs.manager.manager.service.impl.CodeServiceImpl; |
| | | import com.zy.acs.manager.system.controller.BaseController; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.util.*; |
| | | |
| | | @Slf4j |
| | | @RestController |
| | | @RequestMapping("/api") |
| | | public class CodeController extends BaseController { |
| | | |
| | | @Autowired |
| | | private CodeService codeService; |
| | | @Autowired |
| | | private CodeGapService codeGapService; |
| | | @Autowired |
| | | private RouteService routeService; |
| | | |
| | | @PreAuthorize("hasAuthority('manager:code:list')") |
| | | @PostMapping("/code/page") |
| | |
| | | @PreAuthorize("hasAuthority('manager:code:list')") |
| | | @GetMapping("/code/{id}") |
| | | public R get(@PathVariable("id") Long id) { |
| | | return R.ok().add(codeService.getById(id)); |
| | | return R.ok().add(codeService.getCacheById(id)); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:code:save')") |
| | |
| | | code.setUpdateTime(new Date()); |
| | | if (!codeService.save(code)) { |
| | | return R.error("Save Fail"); |
| | | } else { |
| | | CodeServiceImpl.CODE_ID_CACHE.put(code.getId(), code); |
| | | CodeServiceImpl.CODE_DATA_CACHE.put(code.getData(), code); |
| | | } |
| | | return R.ok("Save Success").add(code); |
| | | } |
| | |
| | | code.setUpdateTime(new Date()); |
| | | if (!codeService.updateById(code)) { |
| | | return R.error("Update Fail"); |
| | | } else { |
| | | CodeServiceImpl.CODE_ID_CACHE.put(code.getId(), code); |
| | | CodeServiceImpl.CODE_DATA_CACHE.put(code.getData(), code); |
| | | } |
| | | return R.ok("Update Success").add(code); |
| | | } |
| | |
| | | @PreAuthorize("hasAuthority('manager:code:remove')") |
| | | @OperationLog("Delete Code") |
| | | @PostMapping("/code/remove/{ids}") |
| | | @Transactional |
| | | public R remove(@PathVariable Long[] ids) { |
| | | if (!codeService.removeByIds(Arrays.asList(ids))) { |
| | | return R.error("Delete Fail"); |
| | | for (Long id : ids) { |
| | | Code code = codeService.getById(id); |
| | | if (null == code) { |
| | | continue; |
| | | } |
| | | codeGapService.remove(new LambdaQueryWrapper<CodeGap>().eq(CodeGap::getCode0, code.getId()).or().eq(CodeGap::getCode1, code.getId())); |
| | | routeService.remove(new LambdaQueryWrapper<Route>().eq(Route::getStartCode, code.getId()).or().eq(Route::getEndCode, code.getId())); |
| | | if (!codeService.removeById(id)) { |
| | | throw new CoolException("failed to remove code"); |
| | | } else { |
| | | CodeServiceImpl.CODE_ID_CACHE.remove(code.getId()); |
| | | CodeServiceImpl.CODE_DATA_CACHE.remove(code.getData()); |
| | | } |
| | | } |
| | | return R.ok("Delete Success").add(ids); |
| | | } |
| | |
| | | Date now = new Date(); Long userId = getLoginUserId(); |
| | | for (Map<String, Object> map : list) { |
| | | Code code = Cools.conver(map, Code.class); |
| | | if (null != codeService.selectByData(code.getData())) { |
| | | if (null != codeService.getCacheByData(code.getData())) { |
| | | continue; |
| | | } |
| | | code.setData(Utils.zeroFill(code.getData(), CommonConstant.QR_CODE_LEN)); |
| | | code.setUuid("code".concat(code.getData())); |
| | | code.setConcer(0); |
| | | // code.setCorner(0); |
| | | code.setScale(GsonUtils.toJson(Cools.add("x", 1).add("y", 1))); |
| | | code.setCreateBy(userId); |
| | | code.setCreateTime(now); |
| | | code.setUpdateBy(userId); |
| | | code.setUpdateTime(now); |
| | | if (!codeService.save(code)) { |
| | | |
| | | log.error("failed to save code {}", JSON.toJSONString(map)); |
| | | } else { |
| | | CodeServiceImpl.CODE_ID_CACHE.put(code.getId(), code); |
| | | CodeServiceImpl.CODE_DATA_CACHE.put(code.getData(), code); |
| | | } |
| | | } |
| | | return R.ok(); |