package com.zy.asrs.wcs.core.map.service; import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.zy.asrs.framework.common.Cools; import com.zy.asrs.framework.exception.CoolException; import com.zy.asrs.wcs.common.domain.enums.DictType; import com.zy.asrs.wcs.core.map.controller.param.MapDataParam; import com.zy.asrs.wcs.core.map.controller.param.MapQueryParam; import com.zy.asrs.wcs.system.entity.Dict; import com.zy.asrs.wcs.system.service.DictService; import com.zy.asrs.wcs.system.service.UserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.Date; /** * Created by vincent on 3/15/2024 */ @Service public class MapService { @Autowired private UserService userService; @Autowired private DictService dictService; public String getMapData(MapQueryParam param, Long userId) { String mapKey = getMapKey(param.getFloor()); Dict dict = dictService.getOne(new LambdaQueryWrapper().eq(Dict::getFlag, mapKey)); if (Cools.isEmpty(dict)) { return null; } else { return dict.getValue(); } } public void saveMapData(MapDataParam param, Long userId) { String mapKey = getMapKey(param.getFloor()); Dict dict = dictService.getOne(new LambdaQueryWrapper().eq(Dict::getFlag, mapKey)); if (Cools.isEmpty(dict)) { dict = new Dict(); dict.setName(mapKey); dict.setFlag(mapKey); dict.setType(DictType.JSON.flag); dict.setValue(JSON.toJSONString(param.getItemList())); dict.setCreateBy(userId); dict.setUpdateBy(userId); if (!dictService.save(dict)) { throw new CoolException("服务器内部错误"); } } else { dict.setValue(JSON.toJSONString(param.getItemList())); dict.setUpdateTime(new Date()); dict.setUpdateBy(userId); if (!dictService.updateById(dict)) { throw new CoolException("服务器内部错误"); } } } private String getMapKey(Integer floor) { if (null != floor) { return "map-" + floor; } return "map"; } }