Browse Source

CQC认证 上传报表

thing_master
xiachao 1 year ago
parent
commit
e54f3a14d1
  1. 24
      modules/cqc-service/src/main/java/com/thing/cqc/cqcCarbonReport/controller/CqcCarbonReportController.java
  2. 22
      modules/cqc-service/src/main/java/com/thing/cqc/cqcCarbonReport/dto/CqcCarbonReportDTO.java
  3. 12
      modules/cqc-service/src/main/java/com/thing/cqc/cqcCarbonReport/entity/CqcCarbonReportEntity.java
  4. 2
      modules/cqc-service/src/main/java/com/thing/cqc/cqcCarbonReport/service/CqcCarbonReportService.java
  5. 76
      modules/cqc-service/src/main/java/com/thing/cqc/cqcCarbonReport/service/impl/CqcCarbonReportServiceImpl.java
  6. 6
      modules/cqc-service/src/main/java/com/thing/cqc/rpcService/JsonCryptoUtils.java
  7. 7
      modules/cqc-service/src/main/java/com/thing/cqc/rpcService/service/CqcRpcService.java
  8. 23
      modules/cqc-service/src/main/java/com/thing/cqc/rpcService/service/impl/CqcRpcServiceImpl.java
  9. 33
      modules/thing/src/main/java/com/thing/sys/biz/utils/HttpClientUtil.java

24
modules/cqc-service/src/main/java/com/thing/cqc/cqcCarbonReport/controller/CqcCarbonReportController.java

@ -11,6 +11,8 @@ import com.thing.common.core.web.response.PageData;
import com.thing.common.core.web.response.Result;
import com.thing.cqc.cqcCarbonReport.dto.CqcCarbonReportDTO;
import com.thing.cqc.cqcCarbonReport.service.CqcCarbonReportService;
import com.thing.cqc.rpcService.service.CqcRpcService;
import com.thing.sys.security.context.UserContext;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
@ -35,6 +37,8 @@ public class CqcCarbonReportController {
private final CqcCarbonReportService cqcCarbonReportService;
private final CqcRpcService cqcRpcService;
@GetMapping("page")
@Operation(summary="分页")
@Parameters({
@ -49,7 +53,6 @@ public class CqcCarbonReportController {
}
@GetMapping("{id}")
@Operation(summary="信息")
public Result<CqcCarbonReportDTO> get(@PathVariable("id") Long id){
CqcCarbonReportDTO data = cqcCarbonReportService.getByIdAs(id, CqcCarbonReportDTO.class);
return new Result<CqcCarbonReportDTO>().ok(data);
@ -57,18 +60,19 @@ public class CqcCarbonReportController {
@PostMapping
@Operation(summary="保存")
@LogOperation("保存")
public Result<Object> save(@RequestBody CqcCarbonReportDTO dto){
//效验数据
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
dto.setApplyNo(String.valueOf(UUID.randomUUID()));
dto.setCreateDate(System.currentTimeMillis());
dto.setCompanyId(UserContext.getCompanyId());
dto.setTenantCode(UserContext.getTenantCode());
cqcCarbonReportService.saveDto(dto);
return new Result<Object>().ok(dto.getApplyNo());
}
@PutMapping
@Operation(summary="修改")
@LogOperation("修改")
public Result<Object> update(@RequestBody CqcCarbonReportDTO dto){
//效验数据
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);
@ -78,7 +82,6 @@ public class CqcCarbonReportController {
@DeleteMapping
@Operation(summary="删除")
@LogOperation("删除")
public Result<Void> delete(@RequestBody Long[] ids){
//效验数据
AssertUtils.isArrayEmpty(ids, "id");
@ -86,14 +89,9 @@ public class CqcCarbonReportController {
return new Result<>();
}
/**
*@GetMapping("export")
*@Operation(summary="导出")
*@LogOperation("导出")
*public void export(@Parameter(hidden = true) @RequestParam Map<String, Object> params, HttpServletResponse response) throws Exception {
* List<CqcCarbonReportDTO> list = cqcCarbonReportService.listAs(params, CqcCarbonReportDTO.class);
* //ExcelUtils.exportExcelToTarget(response, null, "申请表基础数据", list, CqcCarbonReportExcel.class);
*}
*/
@GetMapping("uploadReport/{id}")
private Result<String> uploadReport(@PathVariable("id") Long id){
return cqcCarbonReportService.uploadReport(id);
}
}

22
modules/cqc-service/src/main/java/com/thing/cqc/cqcCarbonReport/dto/CqcCarbonReportDTO.java

@ -1,11 +1,18 @@
package com.thing.cqc.cqcCarbonReport.dto;
import com.thing.cqc.cqcCarbonConsumables.dto.CqcCarbonConsumablesDTO;
import com.thing.cqc.cqcCarbonDiscard.dto.CqcCarbonDiscardDTO;
import com.thing.cqc.cqcCarbonDistribution.dto.CqcCarbonDistributionDTO;
import com.thing.cqc.cqcCarbonEnergy.dto.CqcCarbonEnergyDTO;
import com.thing.cqc.cqcCarbonMake.dto.CqcCarbonMakeDTO;
import com.thing.cqc.cqcCarbonRaw.dto.CqcCarbonRawDTO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
import java.util.List;
/**
* 申请表基础数据
@ -154,6 +161,21 @@ public class CqcCarbonReportDTO implements Serializable {
private String email;
@Schema(description = "审核状态")
private String status;
@Schema(description = "原物料阶段")
private List<CqcCarbonRawDTO> materialList;
@Schema(description = "制造阶段")
private List<CqcCarbonMakeDTO> makeList;
@Schema(description = "分销阶段")
private List<CqcCarbonDistributionDTO> disList;
@Schema(description = "使用阶段耗材")
private List<CqcCarbonConsumablesDTO> consumeList;
@Schema(description = "使用阶段能源")
private List<CqcCarbonEnergyDTO> energyList;
@Schema(description = "废弃阶段")
private List<CqcCarbonDiscardDTO> wasteList;
@Schema(description = "主键id")
private Long id;
@Schema(description = "租户编码")

12
modules/cqc-service/src/main/java/com/thing/cqc/cqcCarbonReport/entity/CqcCarbonReportEntity.java

@ -1,5 +1,6 @@
package com.thing.cqc.cqcCarbonReport.entity;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.Table;
import lombok.Data;
@ -22,7 +23,11 @@ import java.io.Serializable;
public class CqcCarbonReportEntity implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 主键id
*/
@Id
private Long id;
/**
* 受理机构
*/
@ -287,10 +292,7 @@ public class CqcCarbonReportEntity implements Serializable {
* email
*/
private String email;
/**
* 主键id
*/
private Long id;
/**
* 审核状态
*/

2
modules/cqc-service/src/main/java/com/thing/cqc/cqcCarbonReport/service/CqcCarbonReportService.java

@ -1,5 +1,6 @@
package com.thing.cqc.cqcCarbonReport.service;
import com.thing.common.core.web.response.Result;
import com.thing.common.orm.service.IBaseService;
import com.thing.cqc.cqcCarbonReport.entity.CqcCarbonReportEntity;
@ -11,4 +12,5 @@ import com.thing.cqc.cqcCarbonReport.entity.CqcCarbonReportEntity;
*/
public interface CqcCarbonReportService extends IBaseService<CqcCarbonReportEntity> {
Result<String> uploadReport(Long id);
}

76
modules/cqc-service/src/main/java/com/thing/cqc/cqcCarbonReport/service/impl/CqcCarbonReportServiceImpl.java

@ -1,11 +1,34 @@
package com.thing.cqc.cqcCarbonReport.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.mybatisflex.core.query.QueryWrapper;
import com.thing.common.core.web.response.Result;
import com.thing.common.orm.service.impl.BaseServiceImpl;
import com.thing.cqc.cqcCarbonConsumables.dto.CqcCarbonConsumablesDTO;
import com.thing.cqc.cqcCarbonConsumables.entity.CqcCarbonConsumablesEntity;
import com.thing.cqc.cqcCarbonConsumables.service.CqcCarbonConsumablesService;
import com.thing.cqc.cqcCarbonDiscard.dto.CqcCarbonDiscardDTO;
import com.thing.cqc.cqcCarbonDiscard.entity.CqcCarbonDiscardEntity;
import com.thing.cqc.cqcCarbonDiscard.service.CqcCarbonDiscardService;
import com.thing.cqc.cqcCarbonDistribution.dto.CqcCarbonDistributionDTO;
import com.thing.cqc.cqcCarbonDistribution.entity.CqcCarbonDistributionEntity;
import com.thing.cqc.cqcCarbonDistribution.service.CqcCarbonDistributionService;
import com.thing.cqc.cqcCarbonEnergy.dto.CqcCarbonEnergyDTO;
import com.thing.cqc.cqcCarbonEnergy.entity.CqcCarbonEnergyEntity;
import com.thing.cqc.cqcCarbonEnergy.service.CqcCarbonEnergyService;
import com.thing.cqc.cqcCarbonMake.dto.CqcCarbonMakeDTO;
import com.thing.cqc.cqcCarbonMake.entity.CqcCarbonMakeEntity;
import com.thing.cqc.cqcCarbonMake.service.CqcCarbonMakeService;
import com.thing.cqc.cqcCarbonRaw.dto.CqcCarbonRawDTO;
import com.thing.cqc.cqcCarbonRaw.service.CqcCarbonRawService;
import com.thing.cqc.cqcCarbonReport.dto.CqcCarbonReportDTO;
import com.thing.cqc.cqcCarbonReport.mapper.CqcCarbonReportMapper;
import com.thing.cqc.cqcCarbonReport.entity.CqcCarbonReportEntity;
import com.thing.cqc.cqcCarbonReport.service.CqcCarbonReportService;
import com.thing.cqc.rpcService.service.CqcRpcService;
import com.thing.sys.security.context.UserContext;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
@ -19,6 +42,22 @@ import java.util.Map;
@Service
public class CqcCarbonReportServiceImpl extends BaseServiceImpl<CqcCarbonReportMapper, CqcCarbonReportEntity> implements CqcCarbonReportService {
@Autowired //原料
private CqcCarbonRawService cqcCarbonRawService;
@Autowired //制造
private CqcCarbonMakeService cqcCarbonMakeService;
@Autowired //分销阶段
private CqcCarbonDistributionService cqcCarbonDistributionService;
@Autowired //使用阶段耗材
private CqcCarbonConsumablesService cqcCarbonConsumablesService;
@Autowired //使用阶段能源
private CqcCarbonEnergyService cqcCarbonEnergyService;
@Autowired //废弃阶段
private CqcCarbonDiscardService cqcCarbonDiscardService;
@Autowired
private CqcRpcService cqcRpcService;
@Override
public QueryWrapper getWrapper(Map<String, Object> params){
QueryWrapper wrapper = new QueryWrapper();
@ -30,4 +69,41 @@ public class CqcCarbonReportServiceImpl extends BaseServiceImpl<CqcCarbonReportM
}
@Override
public Result<String> uploadReport(Long id) {
Result<String> result = new Result<>();
CqcCarbonReportDTO reportDTO = this.getByIdAs(id,CqcCarbonReportDTO.class);
String applyNo = reportDTO.getApplyNo();
if(ObjectUtils.isNotEmpty(reportDTO.getApplyNo())){
reportDTO.setMaterialList(cqcCarbonRawService.listAs(Map.of("applyNo",applyNo), CqcCarbonRawDTO.class));
reportDTO.setMakeList(cqcCarbonMakeService.listAs(Map.of("applyNo",applyNo), CqcCarbonMakeDTO.class));
reportDTO.setDisList(cqcCarbonDistributionService.listAs(Map.of("applyNo",applyNo), CqcCarbonDistributionDTO.class));
reportDTO.setConsumeList(cqcCarbonConsumablesService.listAs(Map.of("applyNo",applyNo), CqcCarbonConsumablesDTO.class));
reportDTO.setEnergyList(cqcCarbonEnergyService.listAs(Map.of("applyNo",applyNo), CqcCarbonEnergyDTO.class));
reportDTO.setWasteList(cqcCarbonDiscardService.listAs(Map.of("applyNo",applyNo), CqcCarbonDiscardDTO.class));
}
String paramBodyStr = JSONObject.toJSONString(reportDTO);
try {
String reqResult = cqcRpcService.doUploadData(paramBodyStr);
JSONObject object = JSONObject.parseObject(reqResult);
if(ObjectUtils.isNotEmpty(object)){
Integer code = object.getInteger("code");
String data = object.getString("data");
String msg = object.getString("msg");
result.setCode(code);
result.setData(data);
result.setMsg(msg);
}
} catch (Exception e) {
e.printStackTrace();
result.setCode(405);
result.setData("");
result.setMsg("RPC 调用异常!");
}
return result;
}
}

6
modules/cqc-service/src/main/java/com/thing/cqc/rpcService/JsonCryptoUtils.java

@ -7,7 +7,7 @@ import java.util.Base64;
public class JsonCryptoUtils {
private static final String ALGORITHM = "AES";
private static final String SECRETKEY = "6276a411ba4fec23"; // 16 characters key for AES
public static final String SECRETKEY = "6276a411ba4fec23"; // 16 characters key for AES
public static String encryptJson(String jsonString, String secretKey) throws Exception {
SecretKeySpec keySpec = new SecretKeySpec(secretKey.getBytes(), ALGORITHM);
@ -25,4 +25,8 @@ public class JsonCryptoUtils {
return new String(decryptedBytes);
}
}

7
modules/cqc-service/src/main/java/com/thing/cqc/rpcService/service/CqcRpcService.java

@ -2,10 +2,5 @@ package com.thing.cqc.rpcService.service;
public interface CqcRpcService {
public String doUploadData();
public String doUploadData(String param) throws Exception;
}

23
modules/cqc-service/src/main/java/com/thing/cqc/rpcService/service/impl/CqcRpcServiceImpl.java

@ -1,19 +1,32 @@
package com.thing.cqc.rpcService.service.impl;
import com.thing.cqc.rpcService.JsonCryptoUtils;
import com.thing.cqc.rpcService.service.CqcRpcService;
import com.thing.sys.biz.utils.HttpClientUtil;
import org.springframework.stereotype.Service;
public class CqcRpcServiceImpl implements CqcRpcService {
import java.util.HashMap;
import java.util.Map;
@Service
public class CqcRpcServiceImpl implements CqcRpcService {
private static final String url = "http://114.249.188.139:8099/";
private static final String uploadDataFix = "api/uploadData";
private static final String token = "6276a411ba4fec238500f8123f89192";
@Override
public String doUploadData() {
public String doUploadData(String param) throws Exception {
//数据加密
return null;
String encryptParam = JsonCryptoUtils.encryptJson(param,JsonCryptoUtils.SECRETKEY);
Map<String,String> paramMap = new HashMap<>();
paramMap.put("token",token);
paramMap.put("content",encryptParam);
String postUrl = url+uploadDataFix;
String httpResultStr = HttpClientUtil.post(postUrl,paramMap);
//返回结果解析
return httpResultStr;
}
}

33
modules/thing/src/main/java/com/thing/sys/biz/utils/HttpClientUtil.java

@ -53,31 +53,42 @@ public class HttpClientUtil {
* @return
*/
@SuppressWarnings("unchecked")
public static String post(String url, Map<String,String> data){
public static String post(String url, Map<String, String> data) {
StringBuffer sb = new StringBuffer();
HttpPost httpPost = new HttpPost(url);
List<NameValuePair> valuePairs = new ArrayList<>();
if(null != data) {
for (String key : data.keySet()) {
valuePairs.addAll((Collection<? extends NameValuePair>) new BasicNameValuePair(key, data.get(key)));
// Ensure 'data' is not null
if (data != null) {
// Iterate through the map entries
for (Map.Entry<String, String> entry : data.entrySet()) {
// Create a NameValuePair and add it to the list
valuePairs.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
}
}
try {
httpPost.setEntity(new UrlEncodedFormEntity(valuePairs));
// Set the entity of the HttpPost with UrlEncodedFormEntity
httpPost.setEntity(new UrlEncodedFormEntity(valuePairs, "UTF-8"));
HttpResponse response = httpClient.execute(httpPost);
HttpEntity httpEntity = response.getEntity();
BufferedInputStream bis = new BufferedInputStream(httpEntity.getContent());
byte [] buffer;
while (0<bis.read(buffer=new byte[128])){
sb.append(new String(buffer,"utf-8"));
byte[] buffer = new byte[128];
int bytesRead;
// Read the response content
while ((bytesRead = bis.read(buffer)) != -1) {
sb.append(new String(buffer, 0, bytesRead, "UTF-8"));
}
}catch (UnsupportedEncodingException e){//数据格式有误
} catch (UnsupportedEncodingException e) {
// Handle encoding errors
e.printStackTrace();
}catch (IOException e){//请求出错
} catch (IOException e) {
// Handle I/O errors
e.printStackTrace();
}finally {
} finally {
httpPost.releaseConnection();
}
return sb.toString();
}
}
Loading…
Cancel
Save