Commit cde9db23 authored by 赵啸非's avatar 赵啸非

添加皮肤同步

parent 139bb839
package com.mortals.xhx.common.pdu.skin;
import com.mortals.framework.model.BaseEntityLong;
import lombok.Data;
/**
* 系统基础皮肤Pdu对象
*
* @author zxfei
* @date 2023-04-03
*/
@Data
public class SkinBasePdu extends BaseEntityLong {
private static final long serialVersionUID = 1L;
/**
* 所属种类,来源种类
*/
private Long categoryId;
/**
* 产品id
*/
private Long productId;
/**
* 产品编码
*/
private String productCode;
/**
* 产品名称
*/
private String productName;
/**
* css模板合成后文件地址
*/
private String cssFilePath;
/**
* 排序编号
*/
private Integer sortNum;
/**
* 产品皮肤名称,唯一且不为空
*/
private String name;
/**
* 分辨率 (1.1920*1080,2.1080*1920,3.1280*1280)
*/
private String imageResolution;
/**
* 预览图片
*/
private String previewImagePath;
public void initAttrValue(){
this.categoryId = null;
this.productId = null;
this.productName = "";
this.cssFilePath = "";
this.sortNum = null;
this.name = "";
this.imageResolution = "1";
this.previewImagePath = "";
}
}
\ No newline at end of file
package com.mortals.xhx.feign.skin;
import com.mortals.framework.common.Rest;
import com.mortals.xhx.common.pdu.RespData;
import com.mortals.xhx.common.pdu.skin.SkinBasePdu;
import com.mortals.xhx.feign.IFeign;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 系统基础皮肤 Feign接口
* @author zxfei
* @date 2023-04-03
*/
@FeignClient(name = "base-manager", path = "/base", fallbackFactory = SkinBaseFeignFallbackFactory.class)
public interface ISkinBaseFeign extends IFeign {
/**
* 查看系统基础皮肤列表
*
* @param skinBasePdu
* @return
*/
@PostMapping(value = "/skin/base/interlist")
Rest<RespData<List<SkinBasePdu>>> list(@RequestBody SkinBasePdu skinBasePdu);
/**
* 查看系统基础皮肤
*
* @param id
* @return
*/
@GetMapping(value = "/skin/base/info")
Rest<SkinBasePdu> info(@RequestParam(value = "id") Long id);
/**
* 删除系统基础皮肤
*
* @param ids
* @return
*/
@GetMapping(value = "/skin/base/delete")
Rest<Void> delete(Long[] ids,@RequestHeader("Authorization") String authorization);
/**
* 系统基础皮肤保存更新
*
* @param skinBasePdu
* @return
*/
@PostMapping(value = "/skin/base/save")
Rest<RespData<SkinBasePdu>> save(@RequestBody SkinBasePdu skinBasePdu,@RequestHeader("Authorization") String authorization);
}
@Slf4j
@Component
class SkinBaseFeignFallbackFactory implements FallbackFactory<ISkinBaseFeign> {
@Override
public ISkinBaseFeign create(Throwable t) {
return new ISkinBaseFeign() {
@Override
public Rest<RespData<List<SkinBasePdu>>> list(SkinBasePdu skinBasePdu) {
return Rest.fail("暂时无法获取系统基础皮肤列表,请稍后再试!");
}
@Override
public Rest<SkinBasePdu> info(Long id) {
return Rest.fail("暂时无法获取系统基础皮肤详细,请稍后再试!");
}
@Override
public Rest<Void> delete(Long[] ids, String authorization) {
return Rest.fail("暂时无法删除系统基础皮肤,请稍后再试!");
}
@Override
public Rest<RespData<SkinBasePdu>> save(SkinBasePdu skinBasePdu, String authorization) {
return Rest.fail("暂时无法保存系统基础皮肤,请稍后再试!");
}
};
}
}
......@@ -54,7 +54,7 @@
return {
filePaths:"",
fileNames:"",
limit:10,
limit:50,
deviceFileEntityList: [],
deviceWorkmanEntityList:[],
fileType:['png', 'jpg', 'jpeg'],
......
......@@ -16,6 +16,7 @@ import com.mortals.xhx.feign.site.ISiteFeign;
import com.mortals.xhx.module.device.model.DeviceEntity;
import com.mortals.xhx.module.device.model.DeviceQuery;
import com.mortals.xhx.module.device.service.DeviceService;
import com.mortals.xhx.module.skin.service.SkinService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -40,7 +41,8 @@ public class SyncSiteDeviceTaskImpl implements ITaskExcuteService {
private IDeviceFeign deviceFeign;
@Autowired
private DeviceService deviceService;
@Autowired
private SkinService skinService;
@Override
public void excuteTask(ITask task) throws AppException {
......@@ -48,6 +50,8 @@ public class SyncSiteDeviceTaskImpl implements ITaskExcuteService {
syncDevice();
log.info("结束同步设备列表!");
skinService.syncSkin();
log.info("开始同步皮肤列表!");
}
......
package com.mortals.xhx.module.skin.dao;
import com.mortals.framework.dao.ICRUDDao;
import com.mortals.xhx.module.skin.model.SkinEntity;
/**
* 皮肤Dao
* 皮肤 DAO接口
*
* @author zxfei
* @date 2023-04-03
*/
public interface SkinDao extends ICRUDDao<SkinEntity,Long>{
}
package com.mortals.xhx.module.skin.dao.ibatis;
import com.mortals.framework.dao.ibatis.BaseCRUDDaoMybatis;
import com.mortals.xhx.module.skin.dao.SkinDao;
import com.mortals.xhx.module.skin.model.SkinEntity;
import org.springframework.stereotype.Repository;
/**
* 皮肤DaoImpl DAO接口
*
* @author zxfei
* @date 2023-04-03
*/
@Repository("skinDao")
public class SkinDaoImpl extends BaseCRUDDaoMybatis<SkinEntity,Long> implements SkinDao {
}
package com.mortals.xhx.module.skin.model;
import com.mortals.xhx.module.skin.model.vo.SkinVo;
/**
* 皮肤实体对象
*
* @author zxfei
* @date 2023-04-03
*/
public class SkinEntity extends SkinVo {
private static final long serialVersionUID = 1L;
/**
* 所属种类,来源种类
*/
private Long categoryId;
/**
* 产品id
*/
private Long productId;
/**
* 产品名称
*/
private String productName;
/**
* css模板合成后文件地址
*/
private String cssFilePath;
/**
* 产品皮肤名称,唯一且不为空
*/
private String name;
/**
* 分辨率 (1.1920*1080,2.1080*1920,3.1280*1280)
*/
private String imageResolution;
/**
* 预览图片
*/
private String previewImagePath;
/**
* 排序编号
*/
private Integer sortNum;
/**
* 是否使用
*/
private Integer used;
public SkinEntity(){}
/**
* 获取 所属种类,来源种类
* @return Long
*/
public Long getCategoryId(){
return categoryId;
}
/**
* 设置 所属种类,来源种类
* @param categoryId
*/
public void setCategoryId(Long categoryId){
this.categoryId = categoryId;
}
/**
* 获取 产品id
* @return Long
*/
public Long getProductId(){
return productId;
}
/**
* 设置 产品id
* @param productId
*/
public void setProductId(Long productId){
this.productId = productId;
}
/**
* 获取 产品名称
* @return String
*/
public String getProductName(){
return productName;
}
/**
* 设置 产品名称
* @param productName
*/
public void setProductName(String productName){
this.productName = productName;
}
/**
* 获取 css模板合成后文件地址
* @return String
*/
public String getCssFilePath(){
return cssFilePath;
}
/**
* 设置 css模板合成后文件地址
* @param cssFilePath
*/
public void setCssFilePath(String cssFilePath){
this.cssFilePath = cssFilePath;
}
/**
* 获取 产品皮肤名称,唯一且不为空
* @return String
*/
public String getName(){
return name;
}
/**
* 设置 产品皮肤名称,唯一且不为空
* @param name
*/
public void setName(String name){
this.name = name;
}
/**
* 获取 分辨率 (1.1920*1080,2.1080*1920,3.1280*1280)
* @return String
*/
public String getImageResolution(){
return imageResolution;
}
/**
* 设置 分辨率 (1.1920*1080,2.1080*1920,3.1280*1280)
* @param imageResolution
*/
public void setImageResolution(String imageResolution){
this.imageResolution = imageResolution;
}
/**
* 获取 预览图片
* @return String
*/
public String getPreviewImagePath(){
return previewImagePath;
}
/**
* 设置 预览图片
* @param previewImagePath
*/
public void setPreviewImagePath(String previewImagePath){
this.previewImagePath = previewImagePath;
}
/**
* 获取 排序编号
* @return Integer
*/
public Integer getSortNum(){
return sortNum;
}
/**
* 设置 排序编号
* @param sortNum
*/
public void setSortNum(Integer sortNum){
this.sortNum = sortNum;
}
/**
* 获取 是否使用
* @return Integer
*/
public Integer getUsed(){
return used;
}
/**
* 设置 是否使用
* @param used
*/
public void setUsed(Integer used){
this.used = used;
}
@Override
public int hashCode() {
return this.getId().hashCode();
}
@Override
public boolean equals(Object obj) {
if (obj == null) return false;
if (obj instanceof SkinEntity) {
SkinEntity tmp = (SkinEntity) obj;
if (this.getId() == tmp.getId()) {
return true;
}
}
return false;
}
public String toString(){
StringBuilder sb = new StringBuilder("");
sb.append(",categoryId:").append(getCategoryId());
sb.append(",productId:").append(getProductId());
sb.append(",productName:").append(getProductName());
sb.append(",cssFilePath:").append(getCssFilePath());
sb.append(",name:").append(getName());
sb.append(",imageResolution:").append(getImageResolution());
sb.append(",previewImagePath:").append(getPreviewImagePath());
sb.append(",sortNum:").append(getSortNum());
sb.append(",used:").append(getUsed());
return sb.toString();
}
public void initAttrValue(){
this.categoryId = null;
this.productId = null;
this.productName = null;
this.cssFilePath = null;
this.name = null;
this.imageResolution = null;
this.previewImagePath = null;
this.sortNum = null;
this.used = 0;
}
}
\ No newline at end of file
package com.mortals.xhx.module.skin.model.vo;
import com.mortals.framework.model.BaseEntityLong;
import lombok.Data;
/**
* 皮肤视图对象
*
* @author zxfei
* @date 2023-04-03
*/
@Data
public class SkinVo extends BaseEntityLong {
private Long siteId;
}
\ No newline at end of file
package com.mortals.xhx.module.skin.service;
import com.mortals.framework.service.ICRUDService;
import com.mortals.xhx.module.skin.model.SkinEntity;
/**
* SkinService
*
* 皮肤 service接口
*
* @author zxfei
* @date 2023-04-03
*/
public interface SkinService extends ICRUDService<SkinEntity,Long>{
void syncSkin();
}
\ No newline at end of file
package com.mortals.xhx.module.skin.service.impl;
import cn.hutool.core.util.StrUtil;
import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.xhx.common.code.YesNoEnum;
import com.mortals.xhx.common.pdu.RespData;
import com.mortals.xhx.common.pdu.skin.SkinBasePdu;
import com.mortals.xhx.common.utils.BeanUtil;
import com.mortals.xhx.feign.skin.ISkinBaseFeign;
import com.mortals.xhx.module.skin.dao.SkinDao;
import com.mortals.xhx.module.skin.model.SkinEntity;
import com.mortals.xhx.module.skin.model.SkinQuery;
import com.mortals.xhx.module.skin.service.SkinService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* SkinService
* 皮肤 service实现
*
* @author zxfei
* @date 2023-04-03
*/
@Service("skinService")
@Slf4j
public class SkinServiceImpl extends AbstractCRUDServiceImpl<SkinDao, SkinEntity, Long> implements SkinService {
@Autowired
private ISkinBaseFeign skinBaseFeign;
@Override
protected void updateBefore(SkinEntity entity, Context context) throws AppException {
super.updateBefore(entity, context);
if(YesNoEnum.YES.getValue()==entity.getUsed()){
//修改非当前皮肤都未未使用
SkinEntity skinEntity = new SkinEntity();
skinEntity.setUsed(YesNoEnum.NO.getValue());
SkinEntity condition = new SkinEntity();
condition.setUsed(YesNoEnum.YES.getValue());
this.updateBatch(skinEntity,condition,context);
}
}
@Override
public void syncSkin() {
SkinBasePdu skinBasePdu = new SkinBasePdu();
skinBasePdu.setProductCode("xxgk");
skinBasePdu.setSize(-1);
Rest<RespData<List<SkinBasePdu>>> skinBaseRest = skinBaseFeign.list(skinBasePdu);
if (skinBaseRest.getCode() == YesNoEnum.YES.getValue()) {
List<SkinBasePdu> skinBasePduList = skinBaseRest.getData().getData();
log.info("信息公开皮肤总数量:{}", skinBasePduList.size());
if (!ObjectUtils.isEmpty(skinBasePduList)) {
List<SkinEntity> newSkinList = skinBasePduList.stream().map(newSkin -> {
SkinEntity skinEntity = new SkinEntity();
skinEntity.initAttrValue();
//存相对地址
newSkin.setCssFilePath("/file"+ StrUtil.subAfter(newSkin.getCssFilePath(), "/file", false));
newSkin.setPreviewImagePath("/file"+StrUtil.subAfter(newSkin.getPreviewImagePath(), "/file", false));
BeanUtils.copyProperties(newSkin, skinEntity, BeanUtil.getNullPropertyNames(newSkin));
return skinEntity;
}).collect(Collectors.toList());
List<SkinEntity> oldSkinList = this.find(new SkinQuery());
Map<Long, SkinEntity> oldSkinMap = oldSkinList.stream().collect(Collectors.toMap(x -> x.getId(), y -> y, (o, n) -> n));
Map<Long, SkinEntity> newSkinMap = newSkinList.stream().collect(Collectors.toMap(x -> x.getId(), y -> y, (o, n) -> n));
List<SkinEntity> updateSkinLsit = newSkinList.stream().map(item -> {
if (oldSkinMap.containsKey(item.getId())) {
item.setUsed(oldSkinMap.get(item.getId()).getUsed());
item.setUpdateTime(new Date());
return item;
}
return null;
}).filter(f -> f != null).collect(Collectors.toList());
List<SkinEntity> saveSkinList = newSkinList.stream().map(item -> {
if (!oldSkinMap.containsKey(item.getId())) {
item.setCreateUserId(1L);
item.setCreateUserName("系统管理员");
item.setCreateTime(new Date());
return item;
}
return null;
}).filter(f -> f != null).collect(Collectors.toList());
//做差集
List<Long> delSkinList = oldSkinList.stream().map(item -> {
if (!newSkinMap.containsKey(item.getId())) {
return item.getId();
}
return null;
}).filter(f -> f != null).collect(Collectors.toList());
if (!ObjectUtils.isEmpty(updateSkinLsit)) {
log.info("皮肤更新,size:{}", updateSkinLsit.size());
this.update(updateSkinLsit);
}
if (!ObjectUtils.isEmpty(saveSkinList)) {
log.info("皮肤新增,size:{}", saveSkinList.size());
this.save(saveSkinList);
}
if (!ObjectUtils.isEmpty(delSkinList)) {
log.info("皮肤删除,size:{}", delSkinList.size());
this.remove(delSkinList, null);
}
}
}
}
public static void main(String[] args) {
// boolean b = StrUtil.subPre("http://192.168.0.98:11078/file/fileupload/1699947376437.png", "/file");
// System.out.println(b);
String subAfter = StrUtil.subAfter("http://192.168.0.98:11078/file/fileupload/1699947376437.png", "/file", false);
System.out.println(subAfter);
}
}
\ No newline at end of file
package com.mortals.xhx.module.skin.web;
import com.alibaba.fastjson.JSON;
import com.mortals.framework.annotation.UnAuth;
import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.base.system.param.service.ParamService;
import com.mortals.xhx.common.pdu.device.DeviceMsgReqPdu;
import com.mortals.xhx.feign.device.IDeviceMessageFeign;
import com.mortals.xhx.module.skin.model.SkinEntity;
import com.mortals.xhx.module.skin.service.SkinService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
/**
* 皮肤
*
* @author zxfei
* @date 2023-04-03
*/
@RestController
@RequestMapping("skin")
@Slf4j
public class SkinController extends BaseCRUDJsonBodyMappingController<SkinService, SkinEntity, Long> {
@Autowired
private ParamService paramService;
@Autowired
private IDeviceMessageFeign deviceMessageFeign;
public SkinController() {
super.setModuleDesc("皮肤");
}
@Override
protected void init(Map<String, Object> model, Context context) {
this.addDict(model, "imageResolution", paramService.getParamBySecondOrganize("Skin", "imageResolution"));
this.addDict(model, "used", paramService.getParamBySecondOrganize("Skin", "used"));
super.init(model, context);
}
@Override
protected int saveAfter(SkinEntity entity, Map<String, Object> model, Context context) throws AppException {
//推送皮肤更新消息
DeviceMsgReqPdu deviceMsgReqPdu = new DeviceMsgReqPdu();
deviceMsgReqPdu.setSiteid(entity.getSiteId());
deviceMsgReqPdu.setProductCode("ybj");
deviceMsgReqPdu.setMessageType("edition");
deviceMsgReqPdu.setData("W10=");
deviceMsgReqPdu.setTimestamp(System.currentTimeMillis());
Rest<String> rest = deviceMessageFeign.callbackByProduct(deviceMsgReqPdu);
log.info("send device message==>{}", JSON.toJSONString(rest));
return super.saveAfter(entity, model, context);
}
@PostMapping({"refreshSkin"})
@UnAuth
public Rest<Object> refreshSkin() {
log.info("刷新皮肤");
this.service.syncSkin();
return Rest.ok("皮肤刷新操作成功");
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment