市场法规库清单添加发布接口

This commit is contained in:
梁琦涛
2024-07-05 17:41:04 +08:00
parent e8484026a7
commit 92c4d9e3ec
5 changed files with 95 additions and 29 deletions
@@ -169,12 +169,9 @@ public class MarketStandardController {
@PostMapping(value = "/publish")
@RequiresPermissions("marketStandard:publish")
public Result<?> publish(@RequestBody Map<String, String> map) {
if (!map.containsKey("ids") || StringUtils.isEmpty(map.get("ids"))) {
if (!map.containsKey("id") || StringUtils.isEmpty(map.get("id"))) {
return Result.error("请选择数据!");
}
return Result.OK(map);
return marketStandardService.publish(map.get("id"));
}
}
@@ -12,6 +12,8 @@ import lombok.Data;
import org.jeecgframework.poi.excel.annotation.Excel;
import org.springframework.format.annotation.DateTimeFormat;
import javax.validation.constraints.NotBlank;
/**
*
* @TableName laws_market_standard_detail
@@ -76,6 +78,7 @@ public class LawsMarketStandardDetail implements Serializable {
/**
* 标准编号
*/
@NotBlank(message = "标准编号不能为空")
@ApiModelProperty(value = "标准编号")
@Excel(name = "标准编号", width = 15)
private String standardNumber;
@@ -84,6 +87,7 @@ public class LawsMarketStandardDetail implements Serializable {
* 标准名称
*/
@ApiModelProperty(value = "标准名称")
@NotBlank(message = "标准名称不能为空")
@Excel(name = "标准名称", width = 15)
private String standardName;
@@ -98,6 +102,7 @@ public class LawsMarketStandardDetail implements Serializable {
* 新生产车实施日期
*/
@Excel(name = "新生产车实施日期", width = 15)
@NotBlank(message = "新生产车实施日期不能为空")
@ApiModelProperty(value = "新生产车实施日期")
private String newProductImplDate;
@@ -105,6 +110,7 @@ public class LawsMarketStandardDetail implements Serializable {
* 新认证车实施日期
*/
@Excel(name = "新认证车实施日期", width = 15)
@NotBlank(message = "新认证车实施日期不能为空")
@ApiModelProperty(value = "新认证车实施日期")
private String newAuthImplDate;
@@ -112,6 +118,7 @@ public class LawsMarketStandardDetail implements Serializable {
* 注册日期
*/
@Excel(name = "注册日期", width = 15)
@NotBlank(message = "注册日期不能为空")
@ApiModelProperty(value = "注册日期")
private String registrationDate;
@@ -119,6 +126,7 @@ public class LawsMarketStandardDetail implements Serializable {
* 国家
*/
@Excel(name = "国家/地区", width = 15,dicCode = "market_state")
@NotBlank(message = "国家/地区不能为空")
@ApiModelProperty(value = "国家")
@Dict(dicCode = "market_state")
private String country;
@@ -173,6 +181,7 @@ public class LawsMarketStandardDetail implements Serializable {
*/
@Dict(dictTable = "sys_depart", dicCode = "id", dicText = "depart_name")
@ApiModelProperty(value = "主控部门")
@NotBlank(message = "主控部门不能为空")
@Excel(name = "主控部门", width = 15,dictTable = "sys_depart", dicCode = "id", dicText = "depart_name")
private String mainDept;
@@ -180,6 +189,7 @@ public class LawsMarketStandardDetail implements Serializable {
* 主控部门专业模块
*/
@ApiModelProperty(value = "主控部门专业模块")
@NotBlank(message = "主控部门专业模块不能为空")
@Dict(dicCode = "professional_module")
@Excel(name = "主控部门专业模块", width = 15, dicCode = "professional_module")
private String mainDeptProfMode;
@@ -1,6 +1,7 @@
package com.jero.modules.laws.marketStandard.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jero.common.api.vo.Result;
import com.jero.modules.laws.marketStandard.entity.LawsMarketStandard;
import com.baomidou.mybatisplus.extension.service.IService;
import com.jero.modules.laws.marketStandard.entity.LawsMarketStandardDetail;
@@ -68,4 +69,11 @@ public interface ILawsMarketStandardService extends IService<LawsMarketStandard>
* @param marketStandardDetailVO
*/
void edit(MarketStandardDetailVO marketStandardDetailVO);
/**
* 发布
* @param id
* @return
*/
Result<?> publish(String id);
}
@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jero.common.api.vo.Result;
import com.jero.common.exception.JeroBootException;
import com.jero.common.system.query.QueryGenerator;
import com.jero.common.system.vo.LoginUser;
import com.jero.common.util.ImportExcelUtil;
import com.jero.modules.laws.marketStandard.entity.LawsMarketStandard;
import com.jero.modules.laws.marketStandard.entity.LawsMarketStandardDetail;
@@ -16,6 +17,7 @@ import com.jero.modules.laws.marketStandard.service.ILawsMarketStandardService;
import com.jero.modules.laws.utils.ValidUtil;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.springframework.beans.factory.annotation.Value;
@@ -115,25 +117,28 @@ public class LawsMarketStandardDetailServiceImpl extends ServiceImpl<LawsMarketS
ImportParams params = new ImportParams();
params.setHeadRows(1);
// 校验excel 字段是否正确
boolean b = ImportExcelUtil.checkTemplateTitle(file, LawsMarketStandardDetail.class, params.getTitleRows(), 0);
if (!b) {
throw new JeroBootException("excel文件表头错误,请重新下载");
}
// boolean b = ImportExcelUtil.checkTemplateTitle(file, LawsMarketStandardDetail.class, params.getTitleRows(), 0);
// if (!b) {
// throw new JeroBootException("excel文件表头错误,请重新下载");
// }
try {
List<LawsMarketStandardDetail> listLawsMarketStandardDetail = ExcelImportUtil.importExcel(file.getInputStream(), LawsMarketStandardDetail.class, params);
if(!CollectionUtils.isEmpty(listLawsMarketStandardDetail) && listLawsMarketStandardDetail.size() >= 2){
listLawsMarketStandardDetail = listLawsMarketStandardDetail.subList(2,listLawsMarketStandardDetail.size());
}
for (LawsMarketStandardDetail lawsMarketStandardDetail : listLawsMarketStandardDetail) {
StringBuilder m = new StringBuilder();
for (int i = 0; i < listLawsMarketStandardDetail.size(); i++) {
LawsMarketStandardDetail lawsMarketStandardDetail = listLawsMarketStandardDetail.get(i);
lawsMarketStandardDetail.setManifestId(manifestId);
// 校验数据
StringBuilder m = new StringBuilder();
StringBuilder g = ValidUtil.validateReturnBuilder(lawsMarketStandardDetail);
if(!StringUtils.isEmpty(g.toString())){
m.append(g.toString());
m.append(i + 4).append("行,").append(g.toString());
}
}
if(!StringUtils.isBlank(m.toString())){
return Result.error(m.toString());
}
saveBatch(listLawsMarketStandardDetail);
return Result.OK("导入成功");
} catch (Exception e) {
@@ -198,15 +203,28 @@ public class LawsMarketStandardDetailServiceImpl extends ServiceImpl<LawsMarketS
@Override
public Result<?> deleteById(String id) {
checkData(id);
removeById(id);
return Result.OK("删除成功");
}
@Override
public Result<?> deleteBatchById(String ids) {
checkData(ids);
removeByIds(Arrays.asList(ids.split(",")));
return Result.OK("批量删除成功");
}
// 验证数据权限
private void checkData(String id) {
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
LambdaQueryWrapper<LawsMarketStandardDetail> queryLawsMarketStandardDetail = new LambdaQueryWrapper<>();
queryLawsMarketStandardDetail.eq(LawsMarketStandardDetail::getCreateBy, sysUser.getUsername());
queryLawsMarketStandardDetail.in(LawsMarketStandardDetail::getId, Arrays.asList(id.split(",")));
long l = count(queryLawsMarketStandardDetail);
if (l == 0) {
throw new JeroBootException("没有权限");
}
}
}
@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jero.common.api.vo.Result;
import com.jero.common.exception.JeroBootException;
import com.jero.common.system.api.ISysBaseAPI;
import com.jero.common.system.vo.DictModel;
@@ -22,22 +23,18 @@ import com.jero.modules.system.service.ISysDictService;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;
@@ -133,7 +130,6 @@ public class LawsMarketStandardServiceImpl extends ServiceImpl<LawsMarketStandar
List<String> country = listDict.stream().map(DictModel::getText).collect(Collectors.toList());
// 国家/地区+自定义+固定字段,自定义字段:预留手填,当前默认不填;固定字段:车型需满足标准法规清单
manifest.setManifestName(String.join("",country) + manifest.getCustomColumnName() + "车型需满足标准法规清单");
manifest.setManifestVersion("V1.0");
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
manifest.setAuthor(sysUser.getId());
save(manifest);
@@ -167,26 +163,43 @@ public class LawsMarketStandardServiceImpl extends ServiceImpl<LawsMarketStandar
@Override
@Transactional(rollbackFor = JeroBootException.class)
public synchronized void edit(MarketStandardDetailVO marketStandardDetailVO) {
// todo 状态为已发布需要生成新数据,版本号等
// 修改清单信息
LawsMarketStandard manifest = marketStandardDetailVO.getManifest();
LawsMarketStandard lawsMarketStandardOld = getById(manifest.getId());
if(Objects.isNull(lawsMarketStandardOld)){
throw new JeroBootException("数据不存在");
}
List<String> listCountry = Arrays.stream(manifest.getCountry().split(",")).sorted().collect(Collectors.toList());
List<String> listOldCountry = Arrays.stream(lawsMarketStandardOld.getCountry().split(",")).sorted().collect(Collectors.toList());;
if(!Objects.equals(listCountry,listOldCountry)){
manifest.setManifestNo(generateManifestNo(manifest.getCountry()));
// 状态为已发布需要生成新数据
if(Objects.equals(lawsMarketStandardOld.getManifestStatus(),MarketStandardConstants.MANIFEST_STATUS_PUBLISH)){
manifest.setManifestStatus(MarketStandardConstants.MANIFEST_STATUS_EDIT);
manifest.setManifestVersion("");
// 设置清单编号
manifest.setManifestNo(this.generateManifestNo(manifest.getCountry()));
Map<String, List<DictModel>> map = sysBaseAPI.translateManyDict("market_state",manifest.getCountry());
List<DictModel> listDict = map.get("market_state");
List<String> country = listDict.stream().map(DictModel::getText).collect(Collectors.toList());
// 国家/地区+自定义+固定字段,自定义字段:预留手填,当前默认不填;固定字段:车型需满足标准法规清单
manifest.setManifestName(String.join("",country) + manifest.getCustomColumnName() + "车型需满足标准法规清单");
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
manifest.setAuthor(sysUser.getId());
manifest.setVersionFlag(lawsMarketStandardOld.getVersionFlag());
save(manifest);
}else{
List<String> listCountry = Arrays.stream(manifest.getCountry().split(",")).sorted().collect(Collectors.toList());
List<String> listOldCountry = Arrays.stream(lawsMarketStandardOld.getCountry().split(",")).sorted().collect(Collectors.toList());;
if(!Objects.equals(listCountry,listOldCountry)){
manifest.setManifestNo(generateManifestNo(manifest.getCountry()));
}
Map<String, List<DictModel>> map = sysBaseAPI.translateManyDict("market_state",manifest.getCountry());
List<DictModel> listDict = map.get("market_state");
List<String> country = listDict.stream().map(DictModel::getText).collect(Collectors.toList());
// 国家/地区+自定义+固定字段,自定义字段:预留手填,当前默认不填;固定字段:车型需满足标准法规清单
manifest.setManifestName(String.join("",country) + manifest.getCustomColumnName() + "车型需满足标准法规清单");
updateById(manifest);
}
Map<String, List<DictModel>> map = sysBaseAPI.translateManyDict("market_state",manifest.getCountry());
List<DictModel> listDict = map.get("market_state");
List<String> country = listDict.stream().map(DictModel::getText).collect(Collectors.toList());
// 国家/地区+自定义+固定字段,自定义字段:预留手填,当前默认不填;固定字段:车型需满足标准法规清单
manifest.setManifestName(String.join("",country) + manifest.getCustomColumnName() + "车型需满足标准法规清单");
updateById(manifest);
}
@Override
public ModelAndView export(HttpServletRequest request, HttpServletResponse response, LawsMarketStandard marketStandard, String fileName, String sheetName, HttpServletRequest req) {
// 过滤选中数据
@@ -319,6 +332,26 @@ public class LawsMarketStandardServiceImpl extends ServiceImpl<LawsMarketStandar
}
return result;
}
@Override
@Transactional(rollbackFor = JeroBootException.class)
public Result<?> publish(String id) {
LawsMarketStandard lawsMarketStandardOld = getById(id);
if(Objects.isNull(lawsMarketStandardOld)){
Result.error("数据不存在");
}
LambdaQueryWrapper<LawsMarketStandard> queryLawsMarketStandard = new LambdaQueryWrapper<>();
queryLawsMarketStandard.eq(LawsMarketStandard::getVersionFlag,lawsMarketStandardOld.getVersionFlag());
long l = count(queryLawsMarketStandard);
// 更新状态
LambdaUpdateWrapper<LawsMarketStandard> updateLawsMarketStandard = new LambdaUpdateWrapper<>();
updateLawsMarketStandard.eq(LawsMarketStandard::getId,id);
updateLawsMarketStandard.eq(LawsMarketStandard::getManifestVersion, "V1." + l);
updateLawsMarketStandard.set(LawsMarketStandard::getManifestStatus,MarketStandardConstants.MANIFEST_STATUS_PUBLISH);
update(updateLawsMarketStandard);
// todo 发起流程
return Result.OK("发布成功");
}
}