| | |
| | | import com.yeshi.fanli.util.StringUtil;
|
| | |
|
| | | import net.sf.json.JSONObject;
|
| | |
|
| | | import sun.security.krb5.internal.ccache.CCacheInputStream;
|
| | |
|
| | | @Service
|
| | | public class SpecialServiceImpl implements SpecialService {
|
| | | |
| | |
|
| | | @Resource
|
| | | private SpecialMapper specialMapper;
|
| | | |
| | |
|
| | | @Resource
|
| | | private SpecialPlaceService specialPlaceService;
|
| | | |
| | |
|
| | | @Resource
|
| | | private SpecialCardService specialCardService;
|
| | | |
| | |
|
| | | @Resource
|
| | | private JumpDetailV2Service jumpDetailV2Service;
|
| | | |
| | |
|
| | | @Resource
|
| | | private ConfigService configService;
|
| | |
|
| | | |
| | | @Override
|
| | | public Special selectByPrimaryKey(Long id) {
|
| | | return specialMapper.selectByPrimaryKey(id);
|
| | | }
|
| | |
|
| | | |
| | | @Override
|
| | | public void saveObject(MultipartFile file, MultipartFile file2, MultipartFile file3, Special record, String jumpType) |
| | | throws SpecialException, Exception{
|
| | | |
| | | public void saveObject(MultipartFile file, MultipartFile file2, MultipartFile file3, Special record,
|
| | | String jumpType) throws SpecialException, Exception {
|
| | |
|
| | | Long cardId = record.getCardId();
|
| | | if (cardId == null) {
|
| | | throw new SpecialException(1, "管理ID不能为空");
|
| | | }
|
| | | |
| | |
|
| | | String name = record.getName();
|
| | | if (name == null || name.trim().length() == 0) {
|
| | | throw new SpecialException(1, "专题名称不能为空");
|
| | | }
|
| | | |
| | |
|
| | | String params = record.getParams();
|
| | | if (params == null || params.trim().length() == 0 || "null".equalsIgnoreCase(params) ) {
|
| | | if (params == null || params.trim().length() == 0 || "null".equalsIgnoreCase(params)) {
|
| | | record.setParams(null);
|
| | | } else if (!StringUtil.isJson(params)) {
|
| | | throw new SpecialException(1, "跳转参数非JSON格式");
|
| | | }
|
| | | |
| | |
|
| | | if (!StringUtil.isNullOrEmpty(jumpType)) {
|
| | | List<JumpDetailV2> listByType = jumpDetailV2Service.listByType(jumpType);
|
| | | if (listByType !=null && listByType.size() > 0) {
|
| | | if (listByType != null && listByType.size() > 0) {
|
| | | record.setJumpDetail(listByType.get(0));
|
| | | } |
| | | }
|
| | | }
|
| | | |
| | |
|
| | | Long state = record.getState();
|
| | | if (state == null) {
|
| | | record.setState(0L);
|
| | | }
|
| | | |
| | |
|
| | | // 图片上传
|
| | | String picture = null;
|
| | | if (file != null) {
|
| | | picture = uploadPicture(file);
|
| | | }
|
| | | |
| | |
|
| | | // 图片上传
|
| | | String subPicture = null;
|
| | | if (file2 != null) {
|
| | | subPicture = uploadPicture(file2);
|
| | | }
|
| | | |
| | |
|
| | | // 图片上传
|
| | | String icon = null;
|
| | | if (file3 != null) {
|
| | | icon = uploadPicture(file3);
|
| | | }
|
| | | |
| | |
|
| | | Long id = record.getId();
|
| | | if (id == null) {
|
| | | record.setIcon(icon);
|
| | | record.setPicture(picture);
|
| | | record.setSubPicture(subPicture);
|
| | | |
| | |
|
| | | int maxOrder = specialMapper.getMaxOrderByCard(cardId);
|
| | | record.setOrderby(maxOrder + 1);
|
| | | |
| | |
|
| | | record.setCreatetime(new Date());
|
| | | record.setUpdatetime(new Date());
|
| | | specialMapper.insert(record);
|
| | |
| | | if (resultObj == null) {
|
| | | throw new SpecialException(1, "修改内容已不存在");
|
| | | }
|
| | | |
| | |
|
| | | // 删除图片
|
| | | Boolean delIcon = record.getDelIcon();
|
| | | if (delIcon != null && delIcon) {
|
| | |
| | | removePicture(resultObj.getSubPicture());
|
| | | resultObj.setSubPicture(null);
|
| | | }
|
| | | |
| | | |
| | | |
| | |
|
| | | if (picture != null && picture.trim().length() > 0) {
|
| | | // 删除老图
|
| | | removePicture(resultObj.getPicture());
|
| | |
| | | } else {
|
| | | record.setPicture(resultObj.getPicture());
|
| | | }
|
| | | |
| | |
|
| | | if (subPicture != null && subPicture.trim().length() > 0) {
|
| | | // 删除老图
|
| | | removePicture(resultObj.getSubPicture());
|
| | |
| | | } else {
|
| | | record.setSubPicture(resultObj.getSubPicture());
|
| | | }
|
| | | |
| | | |
| | |
|
| | | if (icon != null && icon.trim().length() > 0) {
|
| | | // 删除老图
|
| | | removePicture(resultObj.getIcon());
|
| | |
| | | } else {
|
| | | record.setIcon(resultObj.getIcon());
|
| | | }
|
| | | |
| | |
|
| | | record.setOrderby(resultObj.getOrderby());
|
| | | record.setCreatetime(resultObj.getCreatetime());
|
| | | record.setUpdatetime(new Date());
|
| | | specialMapper.updateByPrimaryKey(record);
|
| | | }
|
| | | }
|
| | | |
| | |
|
| | | /**
|
| | | * 上传图片
|
| | | * |
| | | * @param file
|
| | | * @return
|
| | | * @throws Exception
|
| | | */
|
| | | public String uploadPicture(MultipartFile file) throws Exception {
|
| | | |
| | | // 文件解析 |
| | |
|
| | | // 文件解析
|
| | | InputStream inputStream = file.getInputStream();
|
| | | String contentType = file.getContentType();
|
| | | String type = contentType.substring(contentType.indexOf("/") + 1);
|
| | | |
| | |
|
| | | // 文件路径
|
| | | String filePath="/img/special/"+UUID.randomUUID().toString().replace("-", "") + "." + type;
|
| | | String filePath = "/img/special/" + UUID.randomUUID().toString().replace("-", "") + "." + type;
|
| | | // 执行上传
|
| | | String fileLink= COSManager.getInstance().uploadFile(inputStream, filePath).getUrl();
|
| | | |
| | | String fileLink = COSManager.getInstance().uploadFile(inputStream, filePath).getUrl();
|
| | |
|
| | | return fileLink;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 删除图片-不更新数据库
|
| | | * |
| | | * @param record
|
| | | * @throws Exception
|
| | | */
|
| | |
| | | COSManager.getInstance().deleteFile(picture);
|
| | | }
|
| | | }
|
| | | |
| | | |
| | |
|
| | | @Override
|
| | | @Transactional
|
| | | public void updateOrder(Long id, Integer moveType) throws SpecialException {
|
| | | |
| | |
|
| | | if (id == null || moveType == null || (!moveType.equals(1) && !moveType.equals(-1))) {
|
| | | throw new SpecialException(1, "请传递正确参数");
|
| | | }
|
| | | |
| | |
|
| | | Special resultObj = specialMapper.selectByPrimaryKey(id);
|
| | | if (resultObj == null) {
|
| | | throw new SpecialException(1, "此内容已不存在");
|
| | | }
|
| | | |
| | |
|
| | | Integer order = resultObj.getOrderby();
|
| | | Long cardId = resultObj.getCardId();
|
| | | |
| | |
|
| | | // 获取交换对象
|
| | | Special exchangeObject = specialMapper.getOrderByCardID(cardId, moveType, order);
|
| | | if (exchangeObject == null) {
|
| | |
| | | throw new SpecialException(1, "在相同使用地方中优先级已经最高了");
|
| | | }
|
| | | }
|
| | | |
| | |
|
| | | resultObj.setOrderby(exchangeObject.getOrderby());
|
| | | exchangeObject.setOrderby(order);
|
| | | |
| | |
|
| | | specialMapper.updateByPrimaryKey(resultObj);
|
| | | specialMapper.updateByPrimaryKey(exchangeObject);
|
| | | }
|
| | | |
| | | |
| | |
|
| | | @Override
|
| | | @Transactional
|
| | | public int deleteBatchByPrimaryKey(List<Long> list) throws Exception{
|
| | | public int deleteBatchByPrimaryKey(List<Long> list) throws Exception {
|
| | | List<Special> listSpecial = specialMapper.queryByListPrimaryKey(list);
|
| | | for (Special special: listSpecial) {
|
| | | for (Special special : listSpecial) {
|
| | | String src = special.getPicture();
|
| | | if (!StringUtil.isNullOrEmpty(src)) {
|
| | | COSManager.getInstance().deleteFile(src);
|
| | | }
|
| | | |
| | |
|
| | | String subPicture = special.getSubPicture();
|
| | | if (!StringUtil.isNullOrEmpty(subPicture)) {
|
| | | COSManager.getInstance().deleteFile(subPicture);
|
| | |
| | | }
|
| | | return specialMapper.deleteBatchByPrimaryKey(list);
|
| | | }
|
| | | |
| | |
|
| | | @Override
|
| | | public int deleteBatchByCardID(List<Long> list) throws Exception{
|
| | | public int deleteBatchByCardID(List<Long> list) throws Exception {
|
| | | List<Special> listSpecial = specialMapper.queryByListCardID(list);
|
| | | for (Special special: listSpecial) {
|
| | | for (Special special : listSpecial) {
|
| | | String src = special.getPicture();
|
| | | if (!StringUtil.isNullOrEmpty(src)) {
|
| | | COSManager.getInstance().deleteFile(src);
|
| | | }
|
| | | |
| | |
|
| | | String subPicture = special.getSubPicture();
|
| | | if (!StringUtil.isNullOrEmpty(subPicture)) {
|
| | | COSManager.getInstance().deleteFile(subPicture);
|
| | | }
|
| | | }
|
| | | |
| | |
|
| | | return specialMapper.deleteBatchByCardID(list);
|
| | | }
|
| | | |
| | | |
| | |
|
| | | @Override
|
| | | public List<Special> listQueryByCard(long start, int count, Long card, String key){
|
| | | |
| | | public List<Special> listQueryByCard(long start, int count, Long card, String key) {
|
| | |
|
| | | List<Special> list = specialMapper.listQueryByCard(start, count, card, key);
|
| | | if (list == null || list.size() == 0) {
|
| | | return list;
|
| | | }
|
| | | |
| | |
|
| | | // 跳转链接
|
| | | for (Special special: list) {
|
| | | for (Special special : list) {
|
| | | String params = special.getParams();
|
| | | if (StringUtil.isNullOrEmpty(params)) {
|
| | | special.setParams("");
|
| | | }
|
| | | |
| | |
|
| | | String remark = special.getRemark();
|
| | | if (StringUtil.isNullOrEmpty(remark)) {
|
| | | special.setRemark("");
|
| | | }
|
| | | |
| | |
|
| | | JumpDetailV2 jumpDetail = special.getJumpDetail();
|
| | | if (jumpDetail == null) {
|
| | | // 默认未选择
|
| | |
| | | }
|
| | | return list;
|
| | | }
|
| | | |
| | | |
| | |
|
| | | @Override
|
| | | public long countlistQueryByCard(Long card, String key) {
|
| | | return specialMapper.countlistQueryByCard(card, key);
|
| | | }
|
| | | |
| | | |
| | |
|
| | | @Override
|
| | | @Cacheable(value = "configCache", key = "'listBySystemAndCard-'+#card+'-'+#systemId")
|
| | | public List<Special> listBySystemAndCard(String card, Long systemId) {
|
| | | return specialMapper.listBySystemAndCard(card, systemId);
|
| | | }
|
| | |
|
| | | |
| | | @Override
|
| | | @Cacheable(value = "configCache", key = "'listPageBySystemAndCard-'+#start+'-'+#count+'-'+#card+'-'+#systemId")
|
| | | public List<Special> listPageBySystemAndCard(long start, int count, String card, Long systemId) {
|
| | | return specialMapper.listPageBySystemAndCard(start, count, card, systemId);
|
| | | }
|
| | |
|
| | | |
| | | @Override
|
| | | @Cacheable(value = "configCache", key = "'listCacheSpecialToIndex'")
|
| | | public JSONObject listCacheSpecialToIndex(AcceptData acceptData) throws Exception{
|
| | | |
| | | public JSONObject listCacheSpecialToIndex(AcceptData acceptData) throws Exception {
|
| | |
|
| | | // 首页-5圆形2排区域
|
| | | JSONObject arcMap = new JSONObject();
|
| | | List<Special> listArc = specialMapper.listByPlaceKey("index_arc");
|
| | | if (listArc == null) {
|
| | | listArc = new ArrayList<Special>();
|
| | | } else if(listArc.size() > 0){
|
| | | } else if (listArc.size() > 0) {
|
| | | Special special = listArc.get(0);
|
| | | if (special != null) {
|
| | | // 背景图片
|
| | |
| | | // 数据处理
|
| | | handlelist(listArc);
|
| | | arcMap.put("list", JsonUtil.getApiCommonGson().toJson(listArc));
|
| | | |
| | | |
| | |
|
| | | // 首页-活动区域(女王节)
|
| | | JSONObject activityMap = new JSONObject();
|
| | | List<Special> listActivity = null;
|
| | |
| | | && configService.iosOnLining(Integer.parseInt(acceptData.getVersion()))) {
|
| | | // 如果IOS当前版本处于审核状态就不返回
|
| | | } else {
|
| | | listActivity = specialMapper.listByPlaceKey("index_activity");
|
| | | listActivity = specialMapper.listByPlaceKey("index_activity");
|
| | | }
|
| | | |
| | |
|
| | | if (listActivity == null) {
|
| | | listActivity = new ArrayList<Special>();
|
| | | } else if(listActivity.size() > 0){
|
| | | } else if (listActivity.size() > 0) {
|
| | | Special special = listActivity.get(0);
|
| | | if (special != null) {
|
| | | // 背景图片
|
| | | activityMap.put("bottomPicture", special.getBottomPicture());
|
| | | }
|
| | | }
|
| | | // 数据处理
|
| | | // 品牌券
|
| | | // >=1.5.40后的版本可以用
|
| | | if (("android".equalsIgnoreCase(acceptData.getPlatform()) && Integer.parseInt(acceptData.getVersion()) > 39)
|
| | | || "ios".equalsIgnoreCase(acceptData.getPlatform()) && Integer.parseInt(acceptData.getVersion()) > 48)
|
| | | if (listActivity != null)
|
| | | for (int i = 0; i < listActivity.size(); i++) {
|
| | | if ("品牌券".equalsIgnoreCase(listActivity.get(i).getName())) {
|
| | | listActivity.get(i).setJumpDetail(jumpDetailV2Service.getByTypeCache("hot_cakes"));
|
| | | }
|
| | | }
|
| | |
|
| | | handlelist(listActivity);
|
| | |
|
| | | activityMap.put("list", JsonUtil.getApiCommonGson().toJson(listActivity));
|
| | | |
| | | |
| | | |
| | |
|
| | | // 首页-方形专题(品牌券、母婴...)
|
| | | JSONObject blockJsonMap = new JSONObject();
|
| | | List<Special> listBlock = specialMapper.listByPlaceKey("index_block");
|
| | | if (listBlock == null) {
|
| | | listBlock = new ArrayList<Special>();
|
| | | } else if(listBlock.size() > 0){
|
| | | } else if (listBlock.size() > 0) {
|
| | | Special special = listBlock.get(0);
|
| | | if (special != null) {
|
| | | // 背景图片
|
| | |
| | | // 数据处理
|
| | | handlelist(listBlock);
|
| | | blockJsonMap.put("list", JsonUtil.getApiCommonGson().toJson(listBlock));
|
| | | |
| | |
|
| | | JSONObject root = new JSONObject();
|
| | | root.put("arcArea", arcMap);
|
| | | root.put("activityArea", activityMap);
|
| | | root.put("blockArea", blockJsonMap);
|
| | | return root;
|
| | | }
|
| | | |
| | |
|
| | | @Override
|
| | | public List<Special> listByPlaceKey(String placeKey) {
|
| | | return specialMapper.listByPlaceKey(placeKey);
|
| | | }
|
| | | |
| | | |
| | |
|
| | | /**
|
| | | * 处理 数据
|
| | | * |
| | | * @param list
|
| | | */
|
| | | public void handlelist(List<Special> list) {
|
| | | if (list != null && list.size() > 0) {
|
| | | for (Special special: list) {
|
| | | for (Special special : list) {
|
| | | boolean needLogin = special.isJumpLogin();
|
| | | JumpDetailV2 jumpDetail = special.getJumpDetail();
|
| | | if (jumpDetail != null) {
|