| | |
| | | import java.util.ArrayList;
|
| | | import java.util.Date;
|
| | | import java.util.HashMap;
|
| | | import java.util.HashSet;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | | import java.util.Set;
|
| | | import java.util.UUID;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
| | | import org.springframework.cache.annotation.Cacheable;
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.transaction.annotation.Transactional;
|
| | | import org.yeshi.utils.tencentcloud.COSManager;
|
| | |
|
| | | import com.yeshi.fanli.dao.mybatis.help.HelpCenterMapper;
|
| | | import com.yeshi.fanli.entity.AppVersionInfo;
|
| | | import com.yeshi.fanli.entity.bus.help.HelpCenter;
|
| | | import com.yeshi.fanli.entity.bus.help.HelpInfo;
|
| | | import com.yeshi.fanli.entity.bus.homemodule.AdActivityVersionControl;
|
| | | import com.yeshi.fanli.entity.bus.homemodule.AdActivityVersionControl.AdActivityType;
|
| | | import com.yeshi.fanli.exception.config.HelpCenterException;
|
| | | import com.yeshi.fanli.service.inter.help.HelpCenterService;
|
| | | import com.yeshi.fanli.service.inter.homemodule.AdActivityVersionControlService;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import com.yeshi.fanli.util.db.MongoDBManager;
|
| | | import org.yeshi.utils.tencentcloud.COSManager;
|
| | |
|
| | | @Service
|
| | | public class HelpCenterServiceImpl implements HelpCenterService {
|
| | |
| | |
|
| | | @Resource
|
| | | private MongoDBManager mongoDBManager;
|
| | | |
| | | @Resource
|
| | | private AdActivityVersionControlService adActivityVersionControlService;
|
| | |
|
| | |
|
| | | @Override
|
| | |
| | | }
|
| | |
|
| | | @Override
|
| | | public String save(HelpCenter helpCenter, String content, String html) throws Exception {
|
| | |
|
| | | public String save(HelpCenter helpCenter, String content, String html) throws HelpCenterException,Exception {
|
| | | if (StringUtil.isNullOrEmpty(helpCenter.getTitle()))
|
| | | throw new HelpCenterException(1,"标题不能为空");
|
| | | |
| | | if (helpCenter.getHelpClass() == null || helpCenter.getHelpClass().getId() <= 0)
|
| | | throw new HelpCenterException(1,"分类题不能为空");
|
| | | |
| | | helpCenter.setUpdatetime(new Date());
|
| | | Long id = helpCenter.getId();
|
| | | if (id == null) {
|
| | | helpCenter.setCreatetime(new Date());
|
| | | helpCenter.setUpdatetime(new Date());
|
| | | helpCenterMapper.insert(helpCenter);
|
| | | |
| | | } else {
|
| | | helpCenter.setUpdatetime(new Date());
|
| | | helpCenterMapper.updateByPrimaryKeySelective(helpCenter);
|
| | | HelpCenter result = helpCenterMapper.selectByPrimaryKey(id);
|
| | | if (result == null) |
| | | throw new HelpCenterException(1,"此类内容已不存在,请刷新");
|
| | |
|
| | | helpCenter.setCreatetime(result.getCreatetime());
|
| | | helpCenter.setWeight(result.getWeight());
|
| | | helpCenterMapper.updateByPrimaryKey(helpCenter);
|
| | | }
|
| | |
|
| | | |
| | | List<Map<String, Object>> positions = getPosition(html);
|
| | |
|
| | | if (positions != null && positions.size() > 0) {
|
| | |
|
| | | @SuppressWarnings("restriction")
|
| | | sun.misc.BASE64Decoder decoder = new sun.misc.BASE64Decoder();
|
| | |
|
| | | |
| | | for (int i = 0; i < positions.size(); i++) {
|
| | | Map<String, Object> map = positions.get(i);
|
| | |
|
| | | String base64Img = (String) map.get("base64Img");
|
| | |
|
| | | byte[] b = decoder.decodeBuffer(base64Img);
|
| | | for (int j = 0; j < b.length; ++j) {
|
| | | if (b[j] < 0) {
|
| | |
| | | }
|
| | |
|
| | | String type = (String) map.get("type");
|
| | | |
| | | // 上传文件相对位置
|
| | | String fileUrl = "helpInfo/" + UUID.randomUUID().toString().replace("-", "") + "." +type;
|
| | | /* 上传新图片 */
|
| | |
| | | if (!StringUtil.isNullOrEmpty(uploadFilePath)) {
|
| | | String header = (String) map.get("header");
|
| | | html = html.replace(header, uploadFilePath);
|
| | | //System.out.println("uploadFilePath: " + uploadFilePath);
|
| | | //content = content.replace(header, uploadFilePath);
|
| | | }
|
| | | |
| | | }
|
| | | }
|
| | |
|
| | |
|
| | | String replaceHtml = replaceIframe(html);
|
| | | |
| | | Long backId = helpCenter.getId();
|
| | | |
| | | HelpInfo helpInfo = new HelpInfo(backId, content, replaceHtml);
|
| | | |
| | | mongoDBManager.saveHelpInfo(helpInfo);
|
| | |
|
| | | return html;
|
| | |
|
| | | }
|
| | |
|
| | | public List<Map<String, Object>> getPosition(String content) {
|
| | |
| | | }
|
| | | }
|
| | | }
|
| | | |
| | | |
| | | |
| | |
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | @Override
|
| | | public void setVersions(Long id, List<Long> versions) throws HelpCenterException {
|
| | | HelpCenter helpCenter = helpCenterMapper.selectByPrimaryKey(id);
|
| | | if (helpCenter == null) {
|
| | | throw new HelpCenterException(1, "此信息不存在,请刷新重试");
|
| | | }
|
| | |
|
| | | Set<Long> oldSet = new HashSet<>();
|
| | | List<AdActivityVersionControl> versionList = adActivityVersionControlService
|
| | | .listByTypeAndSourceId(AdActivityType.helpCenter, id);
|
| | | if (versionList != null) {
|
| | | for (AdActivityVersionControl control : versionList)
|
| | | oldSet.add(control.getVersion().getId());
|
| | | }
|
| | |
|
| | | Set<Long> newSet = new HashSet<>();
|
| | | for (Long version : versions) {
|
| | | newSet.add(version);
|
| | | }
|
| | |
|
| | | Set<Long> delSet = new HashSet<>();
|
| | | delSet.addAll(oldSet);
|
| | | delSet.removeAll(newSet);
|
| | | for (Long versionId : delSet) {
|
| | | adActivityVersionControlService.deleteBySourceAndVersion(id, AdActivityType.helpCenter, versionId);
|
| | | }
|
| | |
|
| | | Set<Long> addSet = new HashSet<>();
|
| | | addSet.addAll(newSet);
|
| | | addSet.removeAll(oldSet);
|
| | |
|
| | | // 添加映射
|
| | | for (Long versionId : addSet) {
|
| | | AdActivityVersionControl control = new AdActivityVersionControl();
|
| | | control.setCreateTime(new Date());
|
| | | control.setSourceId(id);
|
| | | control.setType(AdActivityType.helpCenter);
|
| | | control.setVersion(new AppVersionInfo(versionId));
|
| | | try {
|
| | | adActivityVersionControlService.addVersionControl(control);
|
| | | } catch (Exception e) {
|
| | | throw new HelpCenterException(2, e.getMessage());
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|