feat: bug-369 添加对产品线和数据权限的支持

This commit is contained in:
曹鹏飞 2025-06-23 13:07:33 +08:00
parent e62cabc223
commit 46c030ae07
13 changed files with 233 additions and 12 deletions

View File

@ -13,14 +13,12 @@ import com.nflg.mobilebroken.common.pojo.PageData;
import com.nflg.mobilebroken.common.pojo.request.*;
import com.nflg.mobilebroken.common.pojo.vo.AdminUserVO;
import com.nflg.mobilebroken.common.pojo.vo.DepartmentSimpleVO;
import com.nflg.mobilebroken.common.pojo.vo.SimpleVO;
import com.nflg.mobilebroken.common.pojo.vo.TitleSimpleVO;
import com.nflg.mobilebroken.common.util.AdminUserUtil;
import com.nflg.mobilebroken.common.util.VUtils;
import com.nflg.mobilebroken.repository.entity.AdminUser;
import com.nflg.mobilebroken.repository.service.IAdminUserService;
import com.nflg.mobilebroken.repository.service.IDictionaryItemTranslateService;
import com.nflg.mobilebroken.repository.service.ITBaseDepartmentService;
import com.nflg.mobilebroken.repository.service.ITBasePositionService;
import com.nflg.mobilebroken.repository.service.*;
import com.nflg.mobilebroken.starter.annotation.MethodInfoMark;
import com.nflg.mobilebroken.starter.service.EmailService;
import lombok.extern.slf4j.Slf4j;
@ -81,6 +79,9 @@ public class AdminUserController extends ControllerBase {
@Resource
private RedisTemplate<String, String> redisTemplate;
@Resource
private IProductionLineService productionLineService;
/**
* 获取部门列表
* @return 部门列表
@ -101,6 +102,16 @@ public class AdminUserController extends ControllerBase {
return ApiResult.success(positionService.getSimpleTitles(1));
}
/**
* 获取产品线下拉列表
* @return 产品线下拉列表
*/
@GetMapping("getSimpleProductionLines")
@ApiMark(moduleName = "账号管理", apiName = "获取产品线下拉列表")
private List<SimpleVO> getSimpleProductionLines(){
return productionLineService.getSimples();
}
/**
* 新增账号
* @param request 请求参数

View File

@ -26,4 +26,24 @@ public class CmrDeviceResultVO {
private Integer CfsStatus__c;
private String Id;
/**
* 产品线
*/
private String ProductLine__c;
/**
* 发货日期
*/
private String LastCarDevliverDate__c;
/**
* 质保开始日期
*/
private String WarrantyStartDate__c;
/**
* 质保期()
*/
private Integer WarrantyPeriod1__c;
}

View File

@ -14,11 +14,14 @@ import com.nflg.mobilebroken.common.constant.STATE;
import com.nflg.mobilebroken.common.util.AdminUserUtil;
import com.nflg.mobilebroken.common.util.VUtils;
import com.nflg.mobilebroken.repository.entity.Device;
import com.nflg.mobilebroken.repository.entity.ProductionLine;
import com.nflg.mobilebroken.repository.service.IDeviceService;
import com.nflg.mobilebroken.repository.service.IProductionLineService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
@ -38,6 +41,9 @@ public class AdminDeviceService {
@Resource
CrmService crmService;
@Resource
private IProductionLineService productionLineService;
@Transactional(rollbackFor = Exception.class)
public void add(DeviceDTO deviceDTO) {
Device device = Convert.convert(Device.class, deviceDTO);
@ -128,11 +134,29 @@ public class AdminDeviceService {
Map<String, Device> deviceMap = deviceList.stream().collect(Collectors.toMap(Device::getSourceId, device -> device));
crmDeviceList.forEach(u -> {
Integer plId = 0;
String productionLine = StrUtil.trim(u.getProductLine__c());
if (StrUtil.isNotBlank(productionLine)) {
ProductionLine pl = productionLineService.getByName(productionLine);
if (Objects.isNull(pl)) {
pl = new ProductionLine()
.setName(productionLine)
.setCreateBy("CRM同步")
.setCreateTime(LocalDateTime.now());
productionLineService.save(pl);
}
plId = pl.getId();
}
if (StrUtil.isNotBlank(u.getMachine_Number__c())) {
Device ent = deviceMap.get(u.getId());
if (Objects.nonNull(ent)) {
ent.setUpdateBy("crm");
ent.setUpdateTime(LocalDateTime.now());
if (!StrUtil.equals(productionLine,"移动破碎")){
if (Objects.isNull(ent.getShipmentDate()) && StrUtil.isNotBlank(u.getLastCarDevliverDate__c())){
ent.setShipmentDate(LocalDate.parse(u.getLastCarDevliverDate__c()));
}
}
} else {
ent = new Device();
ent.setSourceId(u.getId());
@ -141,9 +165,9 @@ public class AdminDeviceService {
}
ent.setDeviceState(u.getCfsStatus__c());
ent.setDeviceNo(u.getMachine_Number__c());
ent.setDeviceType(u.getAssetProductLine3__c());
ent.setDeviceTypeSub(u.getAssetProductLine4__c());
ent.setModelNo(u.getProductLine5__c());
ent.setDeviceType(Optional.ofNullable(u.getAssetProductLine3__c()).orElse(""));
ent.setDeviceTypeSub(Optional.ofNullable(u.getAssetProductLine4__c()).orElse(""));
ent.setModelNo(Optional.ofNullable(u.getProductLine5__c()).orElse(""));
if (StrUtil.isNotBlank(u.getAccount())) {
JSONObject jsonObject = JSONObject.parseObject(u.getAccount());
String cname = jsonObject.getString("Name");
@ -152,21 +176,21 @@ public class AdminDeviceService {
ent.setSourceFrom(DeviceSourceFromEnum.FROM_CRM.getSourceKey());
ent.setCustomerId(0);
ent.setProductionLineId(plId);
result.add(ent);
}
});
if (CollUtil.isNotEmpty(result)) {
//将设备类型放入-设备类型表维护客户质量管理人
List<String> deviceTypes = result.stream().map(u -> u.getDeviceType()).collect(Collectors.toList());
List<String> deviceTypes = result.stream().map(Device::getDeviceType).filter(StrUtil::isNotBlank).collect(Collectors.toList());
adminDeviceTypeService.batchAddDeviceType(deviceTypes);
//将设备机型
List<String> models = result.stream().map(u -> u.getModelNo()).collect(Collectors.toList());
List<String> models = result.stream().map(Device::getModelNo).filter(StrUtil::isNotBlank).collect(Collectors.toList());
adminDeviceComponentService.batchAddModelNo(models);
deviceService.saveOrUpdateBatch(result);
}
// }
}
}

View File

@ -13,6 +13,7 @@ import com.nflg.mobilebroken.common.constant.STATE;
import com.nflg.mobilebroken.common.exception.NflgException;
import com.nflg.mobilebroken.common.util.HttpUtils;
import com.nflg.mobilebroken.common.util.VUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Service;
@ -23,7 +24,7 @@ import java.util.*;
/**
* CRM 服务
*/
@Slf4j
@Service
@RefreshScope
public class CrmService {
@ -102,6 +103,7 @@ public class CrmService {
// reBody.put("CrLsDate", date);
String token = StrUtil.join(" ", "Bearer", getToken());
String orderResult = httpUtils.doPost(getAgentUrl, JSON.toJSONString(dateParam), token);
log.debug("【代理商】CRM返回数据:{}",orderResult);
JSONObject jsonObject = JSONObject.parseObject(orderResult);
String code = jsonObject.getString("code");
if (Objects.equals(code, "0")) {
@ -126,6 +128,7 @@ public class CrmService {
// reBody.put("CrLsDate", startDate);
String token = StrUtil.join(" ", "Bearer", getToken());
String orderResult = httpUtils.doPost(getDeviceUrl, JSON.toJSONString(dateParam), token);
log.debug("【设备信息】CRM返回数据:{}",orderResult);
JSONObject jsonObject = JSONObject.parseObject(orderResult);
String code = jsonObject.getString("code");
if (Objects.equals(code, "0")) {

View File

@ -42,4 +42,10 @@ public class AccountAddRequest {
//密码
@JsonIgnore
private String password;
/**
* 产品线id
*/
@NotNull
private Integer productionLineId;
}

View File

@ -0,0 +1,15 @@
package com.nflg.mobilebroken.common.pojo.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.experimental.Accessors;
@Data
@AllArgsConstructor
@Accessors(chain = true)
public class SimpleVO {
private Integer id;
private String name;
}

View File

@ -123,6 +123,11 @@ public class Device implements Serializable {
*/
private String sourceId;
/**
* 产品线id
*/
private Integer productionLineId;
/**
* 创建人
*/

View File

@ -0,0 +1,56 @@
package com.nflg.mobilebroken.repository.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* <p>
* 产品线
* </p>
*
* @author 代码生成器生成
* @since 2025
*/
@Getter
@Setter
@Accessors(chain = true)
@TableName("production_line")
public class ProductionLine implements Serializable {
private static final long serialVersionUID = 1L;
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
/**
* 名称
*/
private String name;
/**
* 创建人id
*/
private String createBy;
/**
* 创建时间
*/
private LocalDateTime createTime;
/**
* 最后更新人id
*/
private String updateBy;
/**
* 最后更新时间
*/
private LocalDateTime updateTime;
}

View File

@ -0,0 +1,16 @@
package com.nflg.mobilebroken.repository.mapper;
import com.nflg.mobilebroken.repository.entity.ProductionLine;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* <p>
* 产品线 Mapper 接口
* </p>
*
* @author 代码生成器生成
* @since 2025
*/
public interface ProductionLineMapper extends BaseMapper<ProductionLine> {
}

View File

@ -0,0 +1,22 @@
package com.nflg.mobilebroken.repository.service;
import com.nflg.mobilebroken.common.pojo.vo.SimpleVO;
import com.nflg.mobilebroken.repository.entity.ProductionLine;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
/**
* <p>
* 产品线 服务类
* </p>
*
* @author 代码生成器生成
* @since 2025
*/
public interface IProductionLineService extends IService<ProductionLine> {
ProductionLine getByName(String productionLine);
List<SimpleVO> getSimples();
}

View File

@ -0,0 +1,38 @@
package com.nflg.mobilebroken.repository.service.impl;
import com.nflg.mobilebroken.common.pojo.vo.SimpleVO;
import com.nflg.mobilebroken.repository.entity.ProductionLine;
import com.nflg.mobilebroken.repository.mapper.ProductionLineMapper;
import com.nflg.mobilebroken.repository.service.IProductionLineService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.stream.Collectors;
/**
* <p>
* 产品线 服务实现类
* </p>
*
* @author 代码生成器生成
* @since 2025
*/
@Service
public class ProductionLineServiceImpl extends ServiceImpl<ProductionLineMapper, ProductionLine> implements IProductionLineService {
@Override
public ProductionLine getByName(String productionLine) {
return lambdaQuery().eq(ProductionLine::getName, productionLine).one();
}
@Override
public List<SimpleVO> getSimples() {
return lambdaQuery()
.select(ProductionLine::getId, ProductionLine::getName)
.list()
.stream()
.map(productionLine -> new SimpleVO(productionLine.getId(), productionLine.getName()))
.collect(Collectors.toList());
}
}

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.nflg.mobilebroken.repository.mapper.ProductionLineMapper">
</mapper>

View File

@ -34,7 +34,7 @@ public class CodeGenerator {
)
.strategyConfig(builder -> {
builder
.addInclude("^product_.*") //只生成指定表
.addInclude("^production_line*") //只生成指定表
.entityBuilder()
.enableLombok()
.enableChainModel()