package org.jeecg.modules.base.controller;
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
import org.jeecg.common.system.query.QueryGenerator;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import lombok.extern.slf4j.Slf4j;
|
import org.jeecg.common.system.base.controller.JeecgController;
|
import org.jeecg.common.api.vo.Result;
|
import org.jeecg.modules.base.entity.*;
|
import org.jeecg.modules.base.service.IEnterpriseService;
|
import org.jeecg.modules.base.service.IFactoryModelService;
|
import org.jeecg.modules.quartz.entity.QuartzJob;
|
import org.jeecg.modules.quartz.service.IQuartzJobService;
|
import org.jeecg.common.system.base.entity.DataVersion;
|
import org.jeecg.modules.system.service.IDataVersionService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.web.bind.annotation.*;
|
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletResponse;
|
import org.springframework.web.servlet.ModelAndView;
|
|
import java.text.ParseException;
|
import java.time.LocalDateTime;
|
import java.time.format.DateTimeFormatter;
|
import java.util.*;
|
|
import org.jeecg.common.util.oConvertUtils;
|
import org.jeecg.modules.base.service.IProductionLineWarehouseService;
|
import org.jeecg.modules.base.service.IProductionLineWarehouseClientService;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
import org.jeecg.common.aspect.annotation.AutoLog;
|
import org.apache.shiro.SecurityUtils;
|
import org.jeecg.common.system.vo.LoginUser;
|
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.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
import java.io.IOException;
|
import java.util.stream.Collectors;
|
|
/**
|
* @Description: 线边库管理
|
* @Author: jeecg-boot
|
* @Date: 2023-01-28
|
* @Version: V1.0
|
*/
|
@Api(tags="线边库管理")
|
@RestController
|
@RequestMapping("/base/productionLineWarehouse")
|
@Slf4j
|
public class ProductionLineWarehouseController extends JeecgController<ProductionLineWarehouse, IProductionLineWarehouseService> {
|
|
@Autowired
|
private IProductionLineWarehouseService productionLineWarehouseService;
|
|
@Autowired
|
private IProductionLineWarehouseClientService productionLineWarehouseClientService;
|
|
@Autowired
|
private IDataVersionService dataVersionService;
|
|
@Autowired
|
private IQuartzJobService quartzJobService;
|
|
@Autowired
|
private IFactoryModelService factoryModelService;
|
|
@Autowired
|
private IEnterpriseService enterpriseService;
|
/*---------------------------------主表处理-begin-------------------------------------*/
|
/**
|
* 获取维护升版允许权限
|
*
|
*
|
*/
|
@GetMapping("/getNewVersionPermission")
|
public Result<?> getNewVersionPermission(){
|
List<FactoryModel> usableFactoryList = factoryModelService
|
.list(new QueryWrapper<FactoryModel>()
|
.eq("del_flag",0)
|
.in("enterprise_id",enterpriseService.getUsableIdList()));
|
if(CollectionUtils.isEmpty(usableFactoryList)){
|
return Result.OK(false);
|
}else {
|
List<ProductionLineWarehouse> list = productionLineWarehouseService
|
.list(new QueryWrapper<ProductionLineWarehouse>()
|
.in("workshop_id",usableFactoryList.stream().map(FactoryModel::getId).collect(Collectors.toList()))
|
.eq("del_flag",0));
|
if(CollectionUtils.isNotEmpty(list)){
|
return Result.OK(false);
|
}
|
else {
|
return Result.OK(true);
|
}
|
}
|
}
|
/**
|
*
|
* 查该版本是否为历史版本
|
*
|
*/
|
@GetMapping(value = "/getUpdateVersionPermission")
|
public Result<?> getUpdatePermission(@RequestParam("version") Integer version){
|
List<FactoryModel> usableFactoryList = factoryModelService
|
.list(new QueryWrapper<FactoryModel>()
|
.eq("del_flag",0)
|
.in("enterprise_id",enterpriseService.getUsableIdList()));
|
if(CollectionUtils.isNotEmpty(usableFactoryList)){
|
return Result.OK(productionLineWarehouseService
|
.list(new QueryWrapper<ProductionLineWarehouse>()
|
.in("workshop_id",usableFactoryList.stream().map(FactoryModel::getId).collect(Collectors.toList()))
|
.eq("version",version)
|
.eq("del_flag",0)));
|
}
|
return Result.OK();
|
}
|
/**
|
* 获取初始信息
|
*
|
*
|
*/
|
@GetMapping("/getWarehouseInfo")
|
public Result<?> getFactoryInfo(){
|
Map<String,Object> infoMap = new HashMap<>(2);
|
LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
infoMap.put("enterpriseId",loginUser.getEnterpriseId());
|
infoMap.put("version",productionLineWarehouseService.getInitVersion());
|
return Result.OK(infoMap);
|
}
|
/**
|
* 分页列表查询
|
* @param map
|
* @param pageNo
|
* @param pageSize
|
* @param workshopId
|
* @param version
|
* @return
|
*/
|
@ApiOperation(value="线边库管理-分页列表查询", notes="线边库管理-分页列表查询")
|
@GetMapping(value = "/list")
|
@Transactional
|
public Result<?> list(Map map,
|
@RequestParam(name ="pageNo", defaultValue="1") Integer pageNo,
|
@RequestParam(name ="pageSize", defaultValue="10") Integer pageSize,
|
@RequestParam(name = "workshopId",required = false) String workshopId,
|
@RequestParam(name="version",required = false) Integer version){
|
Page<Map<String,Object>> page = new Page(pageNo, pageSize);
|
IPage<Map<String,Object>> pageList = productionLineWarehouseService.getWarehouseList(page,version,workshopId);
|
return Result.OK(pageList);
|
}
|
/**
|
* 获取当前生效版本和上一次生效版本的版本号
|
*
|
* @return
|
*/
|
@GetMapping("/getNowAndLastUsableVersion")
|
public Result<?> getNowAndLastUsableVersion(){
|
return Result.OK(productionLineWarehouseService.getNowAndLastUsableVersion());
|
}
|
/**
|
* 获取所有版本号
|
*
|
*
|
*/
|
@GetMapping("/getVersionList")
|
public Result<?> getAllVersion(){
|
return Result.OK(productionLineWarehouseService.getVersionList());
|
}
|
/**
|
* 根据版本获取版本号
|
* @param version
|
* @return
|
*
|
*/
|
@GetMapping("/getVersionStatusByVersion")
|
public Result<?> getVersionStatusByVersion(@RequestParam(value = "version",required = false) Integer version){
|
return Result.OK(productionLineWarehouseService.getVersionStatusByVersion(version));
|
}
|
/**
|
* 添加
|
* @param map
|
* @return
|
*/
|
@AutoLog(value = "线边库管理-添加")
|
@ApiOperation(value="线边库管理-添加", notes="线边库管理-添加")
|
//@RequiresPermissions("org.jeecg.modules.demo:mom_base_production_line_warehouse:add")
|
@PostMapping(value = "/add")
|
public Result<String> add(@RequestBody Map<String,Object> map) {
|
ProductionLineWarehouse productionLineWarehouse = new ProductionLineWarehouse();
|
productionLineWarehouse.setCode(String.valueOf(map.get("code")))
|
.setName(String.valueOf(map.get("name")))
|
.setVersion(Integer.parseInt(String.valueOf(map.get("version"))))
|
.setWorkshopId(String.valueOf(map.get("workshopId")))
|
.setRemark(String.valueOf(map.get("remark")))
|
.setStatus(String.valueOf(map.get("status")))
|
.setDelFlag(0);
|
productionLineWarehouseService.save(productionLineWarehouse);
|
QueryWrapper<ProductionLineWarehouse> queryWrapper = new QueryWrapper<ProductionLineWarehouse>()
|
.eq("code",productionLineWarehouse.getCode())
|
.eq("version",productionLineWarehouse.getVersion())
|
.eq("del_flag",0);
|
ProductionLineWarehouse selectWarehouse = productionLineWarehouseService.getOne(queryWrapper,true);
|
DataVersion dataVersion = new DataVersion();
|
dataVersion.setBusinessId(selectWarehouse.getId())
|
.setBusinessType("线边库管理")
|
.setVersion(selectWarehouse.getVersion())
|
.setVersionStatus(String.valueOf(map.get("versionStatus")))
|
.setDelFlag(0)
|
.setEffectiveType("0")
|
.setIsLastUsable("0");
|
dataVersionService.save(dataVersion);
|
QueryWrapper<DataVersion> queryWrapper1 = new QueryWrapper<DataVersion>()
|
.eq("business_id",selectWarehouse.getId()).eq("del_flag",0);
|
DataVersion selectDataVersion = dataVersionService.getOne(queryWrapper1,true);
|
selectWarehouse.setDataVersionId(selectDataVersion.getId());
|
productionLineWarehouseService.saveOrUpdate(selectWarehouse);
|
return Result.OK("添加成功!");
|
}
|
/**
|
* 表单校验
|
*/
|
@GetMapping("/check")
|
public Result<?> check(@RequestParam(name="name",required = false) String name,
|
@RequestParam(name="workshopId",required = false) String workshopId,
|
@RequestParam(name="version",required = false) Integer version
|
){
|
QueryWrapper<ProductionLineWarehouse> queryWrapper = new QueryWrapper<>();
|
if(!StringUtils.isBlank(name)){
|
queryWrapper.eq("name",name);
|
}
|
if(!StringUtils.isBlank(workshopId)){
|
queryWrapper.eq("workshop_id",workshopId);
|
}
|
if(version!=null){
|
queryWrapper.eq("version",version);
|
}
|
queryWrapper.eq("del_flag","0");
|
return Result.OK(productionLineWarehouseService.list(queryWrapper));
|
}
|
/**
|
* 升版
|
* 需要一次完成
|
* @param map
|
* @param
|
* @return
|
*/
|
@PostMapping("/updateVersion")
|
@Transactional
|
public Result<?> updateVersion(@RequestBody Map<String,Object> map){
|
Integer version = Integer.parseInt((String)map.get("version"));
|
//获取升版数据
|
List<ProductionLineWarehouse> list = productionLineWarehouseService.list(new QueryWrapper<ProductionLineWarehouse>()
|
.eq("version",version)
|
.eq("del_flag",0));
|
//获取升版数据的版本信息
|
QueryWrapper<DataVersion> queryWrapper = new QueryWrapper<DataVersion>()
|
.in("business_id", list.stream().map(ProductionLineWarehouse::getId).collect(Collectors.toList()))
|
.eq("del_flag",0);
|
List<DataVersion> dataVersionList = dataVersionService.list(queryWrapper);
|
Set<Integer> set = productionLineWarehouseService.getVersionList();
|
Optional<Integer> maxVersion = set.stream().findFirst();
|
list.stream().forEach(warehouse -> {
|
warehouse.setId("");
|
warehouse.setVersion(maxVersion.get()+1);
|
});
|
productionLineWarehouseService.saveBatch(list);
|
List<ProductionLineWarehouse> newList = productionLineWarehouseService
|
.list(new QueryWrapper<ProductionLineWarehouse>()
|
.eq("version",maxVersion.get()+1));
|
List<DataVersion> newDataVersionList = new ArrayList<>();
|
for(int i=0;i<newList.size();i++){
|
DataVersion dataVersion = new DataVersion();
|
for(int j=0;j<list.size();j++){
|
for(int k=0;k<dataVersionList.size();k++){
|
if(list.get(j).getCode().equals(newList.get(i).getCode())
|
&&list.get(j).getDataVersionId().equals(dataVersionList.get(k).getId())) {
|
dataVersion
|
.setVersion(maxVersion.get() + 1)
|
.setVersionStatus("1")
|
.setBusinessId(newList.get(i).getId())
|
.setDelFlag(0)
|
.setSourceVersionId(dataVersionList.get(k).getId())
|
.setBusinessType("线边库管理")
|
.setIsLastUsable("0");
|
}
|
}
|
}
|
newDataVersionList.add(dataVersion);
|
}
|
dataVersionService.saveBatch(newDataVersionList);
|
List<String> dataVersionBusinessIdList = newDataVersionList.stream().map(DataVersion::getBusinessId).collect(Collectors.toList());
|
QueryWrapper<DataVersion> queryWrapper1 = new QueryWrapper<DataVersion>().in("business_id",dataVersionBusinessIdList).eq("del_flag",0);
|
List<DataVersion> selectDataVersionList = dataVersionService.list(queryWrapper1);
|
for(int i=0;i<newList.size();i++){
|
for(int j=0;j<selectDataVersionList.size();j++){
|
if(newList.get(i).getId().equals(selectDataVersionList.get(j).getBusinessId())){
|
newList.get(i).setDataVersionId(selectDataVersionList.get(j).getId());
|
}
|
}
|
}
|
productionLineWarehouseService.updateBatchById(newList);
|
return Result.OK(maxVersion.get()+1);
|
}
|
/**
|
* 维护升版
|
* 需要一次完成
|
* @param
|
* @return
|
*/
|
@PostMapping("/updateVersionForChange")
|
@Transactional
|
public Result<?> updateVersionForChange(){
|
Set<Integer> set = productionLineWarehouseService.getVersionList();
|
return Result.OK(set.stream().findFirst().get()+1);
|
}
|
/**
|
* 生效
|
* 需要一次性完成
|
* @param
|
* @param map
|
* @return
|
*/
|
@PostMapping("/updateVersionStatusToUsable")
|
@Transactional
|
public Result<?> updateVersionStatusToUsable(@RequestBody Map<String,Object> map){
|
Date date = new Date(System.currentTimeMillis());
|
QuartzJob quartzJob = quartzJobService.getOne(new QueryWrapper<QuartzJob>()
|
.eq("job_class_name","org.jeecg.modules.quartz.job.ProductionLineWarehouseSetUsableJob"),true);
|
if(ObjectUtils.isNotNull(quartzJob)){
|
quartzJobService.deleteAndStopJob(quartzJob);
|
}
|
Integer version = Integer.parseInt((String)map.get("version"));
|
//获取上次生效版本并将其是否上次生效位置置为否
|
List<ProductionLineWarehouse> lastUsableList = productionLineWarehouseService.getLastUsableList();
|
if(CollectionUtils.isNotEmpty(lastUsableList)){
|
QueryWrapper<DataVersion> queryWrapper2 = new QueryWrapper<DataVersion>()
|
.in("business_id",lastUsableList.stream()
|
.map(ProductionLineWarehouse::getId)
|
.collect(Collectors.toList()));
|
List<DataVersion> lastUsableVersionList = dataVersionService.list(queryWrapper2);
|
lastUsableVersionList.stream().forEach(dataVersion -> {
|
dataVersion
|
.setIsLastUsable("0");
|
});
|
dataVersionService.updateBatchById(lastUsableVersionList);
|
}
|
//获取生效版本及版本信息并将其置为失效
|
List<ProductionLineWarehouse> usableList = productionLineWarehouseService.getUsableList();
|
if(CollectionUtils.isNotEmpty(usableList)){
|
QueryWrapper<DataVersion> queryWrapper = new QueryWrapper<DataVersion>()
|
.in("business_id",usableList.stream()
|
.map(ProductionLineWarehouse::getId)
|
.collect(Collectors.toList()));
|
List<DataVersion> usableDataVersionList = dataVersionService.list(queryWrapper);
|
usableDataVersionList.stream().forEach(dataVersion -> {
|
dataVersion
|
.setVersionStatus("3")
|
.setIsLastUsable("1")
|
.setExpiredTime(date);
|
});
|
dataVersionService.updateBatchById(usableDataVersionList);
|
}
|
//获取待生效版本及版本信息并将其置为生效
|
QueryWrapper<DataVersion> queryWrapper1 = new QueryWrapper<DataVersion>()
|
.in("business_id",productionLineWarehouseService.list(new QueryWrapper<ProductionLineWarehouse>()
|
.eq("version",version)
|
.eq("del_flag",0))
|
.stream().map(ProductionLineWarehouse::getId)
|
.collect(Collectors.toList()));
|
List<DataVersion> dataVersionList = dataVersionService.list(queryWrapper1);
|
dataVersionList.stream().forEach(dataVersion -> {
|
dataVersion.setVersionStatus("2")
|
.setEffectiveType("2")
|
.setEffectiveTime(date)
|
.setIsLastUsable("0");
|
});
|
//存入数据库
|
dataVersionService.updateBatchById(dataVersionList);
|
return Result.OK("生效成功");
|
}
|
/**
|
* 定时生效
|
* 需要一次性完成
|
* @param quartzJob
|
* @param
|
* @return
|
*/
|
@PostMapping("/updateVersionStatusToUsableBySetTime")
|
@Transactional
|
public Result<?> updateVersionStatusToUsableBySetTime(@RequestBody QuartzJob quartzJob) throws ParseException {
|
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("ss mm HH dd MM ? yyyy");
|
String jobClassName = quartzJob.getJobClassName();
|
String time = quartzJob.getCronExpression();
|
System.out.println(time);
|
LocalDateTime localDateTime = LocalDateTime.parse(time,dateTimeFormatter);
|
String cronStr=dateTimeFormatter1.format(localDateTime);
|
quartzJob.setCronExpression(cronStr);
|
QueryWrapper<QuartzJob> queryWrapper = new QueryWrapper();
|
queryWrapper.eq("JOB_CLASS_NAME",jobClassName);
|
List<QuartzJob> quartzJobs = quartzJobService.list(queryWrapper);
|
if(CollectionUtils.isEmpty(quartzJobs)){
|
quartzJobService.saveAndScheduleJob(quartzJob);
|
quartzJobs = quartzJobService.list(queryWrapper);
|
quartzJob.setId(quartzJobs.get(0).getId());
|
quartzJobService.resumeJob(quartzJob);
|
return Result.OK(quartzJob);
|
}else{
|
quartzJob.setId(quartzJobs.get(0).getId());
|
quartzJobService.resumeJob(quartzJob);
|
return Result.OK(quartzJob);
|
}
|
|
}
|
|
/**
|
* 编辑
|
* @param productionLineWarehouse
|
* @return
|
*/
|
@AutoLog(value = "线边库管理-编辑")
|
@ApiOperation(value="线边库管理-编辑", notes="线边库管理-编辑")
|
//@RequiresPermissions("org.jeecg.modules.demo:mom_base_production_line_warehouse:edit")
|
@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
|
public Result<String> edit(@RequestBody ProductionLineWarehouse productionLineWarehouse) {
|
productionLineWarehouseService.updateById(productionLineWarehouse);
|
return Result.OK("编辑成功!");
|
}
|
|
/**
|
* 通过id删除
|
* @param id
|
* @return
|
*/
|
@Transactional
|
@AutoLog(value = "线边库管理-通过id删除")
|
@ApiOperation(value="线边库管理-通过id删除", notes="线边库管理-通过id删除")
|
//@RequiresPermissions("org.jeecg.modules.demo:mom_base_production_line_warehouse:delete")
|
@DeleteMapping(value = "/delete")
|
public Result<String> delete(@RequestParam(name="id",required=true) String id) {
|
dataVersionService.update(new UpdateWrapper<DataVersion>()
|
.set("del_flag",1)
|
.eq("business_id",id));
|
productionLineWarehouseService.update(new UpdateWrapper<ProductionLineWarehouse>().set("del_flag",1).eq("id",id));
|
return Result.OK("删除成功!");
|
}
|
|
/**
|
* 批量删除
|
* @param ids
|
* @return
|
*/
|
@Transactional
|
@AutoLog(value = "线边库管理-批量删除")
|
@ApiOperation(value="线边库管理-批量删除", notes="线边库管理-批量删除")
|
//@RequiresPermissions("org.jeecg.modules.demo:mom_base_production_line_warehouse:deleteBatch")
|
@DeleteMapping(value = "/deleteBatch")
|
public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
|
dataVersionService.update(new UpdateWrapper<DataVersion>()
|
.set("del_flag",1)
|
.in("business_id",Arrays.asList(ids.split(","))));
|
productionLineWarehouseService
|
.update(new UpdateWrapper<ProductionLineWarehouse>()
|
.in("id",Arrays.asList(ids.split(","))).set("del_flag",1));
|
return Result.OK("批量删除成功!");
|
}
|
|
/**
|
* 导出
|
* @return
|
*/
|
//@RequiresPermissions("org.jeecg.modules.demo:mom_base_production_line_warehouse:exportXls")
|
@RequestMapping(value = "/exportXls")
|
public ModelAndView exportXls(HttpServletRequest request, ProductionLineWarehouse productionLineWarehouse) {
|
return super.exportXls(request, productionLineWarehouse, ProductionLineWarehouse.class, "线边库管理");
|
}
|
|
/**
|
* 导入
|
* @return
|
*/
|
//@RequiresPermissions("org.jeecg.modules.demo:mom_base_production_line_warehouse:importExcel")
|
@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
|
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
|
return super.importExcel(request, response, ProductionLineWarehouse.class);
|
}
|
/*---------------------------------主表处理-end-------------------------------------*/
|
|
|
/*--------------------------------子表处理-线边库服务对象-begin----------------------------------------------*/
|
/**
|
* 通过主表ID查询
|
* @return
|
*/
|
//@AutoLog(value = "线边库服务对象-通过主表ID查询")
|
@ApiOperation(value="线边库服务对象-通过主表ID查询", notes="线边库服务对象-通过主表ID查询")
|
@GetMapping(value = "/listProductionLineWarehouseClientByMainId")
|
public Result<IPage<ProductionLineWarehouseClient>> listProductionLineWarehouseClientByMainId(ProductionLineWarehouseClient productionLineWarehouseClient,
|
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
|
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
|
HttpServletRequest req) {
|
QueryWrapper<ProductionLineWarehouseClient> queryWrapper = QueryGenerator.initQueryWrapper(productionLineWarehouseClient, req.getParameterMap());
|
Page<ProductionLineWarehouseClient> page = new Page<ProductionLineWarehouseClient>(pageNo, pageSize);
|
IPage<ProductionLineWarehouseClient> pageList = productionLineWarehouseClientService.page(page, queryWrapper);
|
return Result.OK(pageList);
|
}
|
|
/**
|
* 添加
|
* @param map
|
* @return
|
*/
|
@AutoLog(value = "线边库服务对象-添加")
|
@ApiOperation(value="线边库服务对象-添加", notes="线边库服务对象-添加")
|
@PostMapping(value = "/addProductionLineWarehouseClient")
|
public Result<String> addProductionLineWarehouseClient(@RequestBody Map map) {
|
List<Map<String,Object>> addFactoryIds = (List<Map<String, Object>>) map.get("addFactoryIds");
|
String warehouseId = (String) map.get("warehouseId");
|
if(CollectionUtils.isNotEmpty(addFactoryIds)){
|
List<ProductionLineWarehouseClient> warehouseClients=new ArrayList<>();
|
addFactoryIds.forEach(factoryMap->{
|
ProductionLineWarehouseClient warehouseClient = new ProductionLineWarehouseClient();
|
warehouseClient.setClientId((String) factoryMap.get("id"))
|
.setWarehouseId(warehouseId)
|
.setCode((String) factoryMap.get("code"))
|
.setName((String) factoryMap.get("name"))
|
.setDelFlag(0);
|
warehouseClients.add(warehouseClient);
|
});
|
productionLineWarehouseClientService.saveBatch(warehouseClients);
|
}
|
return Result.OK("添加成功!");
|
}
|
|
/**
|
* 编辑
|
* @param map
|
* @return
|
*/
|
@AutoLog(value = "线边库服务对象-编辑")
|
@ApiOperation(value="线边库服务对象-编辑", notes="线边库服务对象-编辑")
|
@RequestMapping(value = "/editProductionLineWarehouseClient", method = {RequestMethod.PUT,RequestMethod.POST})
|
public Result<String> editProductionLineWarehouseClient(@RequestBody Map map) {
|
List<Map<String,Object>> addFactoryIds = (List<Map<String, Object>>) map.get("addFactoryIds");
|
String id = (String) map.get("id");
|
if(CollectionUtils.isNotEmpty(addFactoryIds)){
|
UpdateWrapper<ProductionLineWarehouseClient> updateWrapper = new UpdateWrapper<ProductionLineWarehouseClient>()
|
.eq("id",id)
|
.set("code",(String)addFactoryIds.get(0).get("code"))
|
.set("name",(String)addFactoryIds.get(0).get("name"));
|
productionLineWarehouseClientService.update(updateWrapper);
|
}
|
return Result.OK("编辑成功!");
|
}
|
|
/**
|
* 通过id删除
|
* @param id
|
* @return
|
*/
|
@AutoLog(value = "线边库服务对象-通过id删除")
|
@ApiOperation(value="线边库服务对象-通过id删除", notes="线边库服务对象-通过id删除")
|
@DeleteMapping(value = "/deleteProductionLineWarehouseClient")
|
public Result<String> deleteProductionLineWarehouseClient(@RequestParam(name="id",required=true) String id) {
|
dataVersionService.update(new UpdateWrapper<DataVersion>()
|
.set("del_flag",1)
|
.eq("business_id",id));
|
productionLineWarehouseClientService.update( new UpdateWrapper<ProductionLineWarehouseClient>()
|
.set("del_flag",1)
|
.eq("id",id));
|
return Result.OK("删除成功!");
|
}
|
|
/**
|
* 批量删除
|
* @param ids
|
* @return
|
*/
|
@AutoLog(value = "线边库服务对象-批量删除")
|
@ApiOperation(value="线边库服务对象-批量删除", notes="线边库服务对象-批量删除")
|
@DeleteMapping(value = "/deleteBatchProductionLineWarehouseClient")
|
public Result<String> deleteBatchProductionLineWarehouseClient(@RequestParam(name="ids",required=true) String ids) {
|
dataVersionService.update(new UpdateWrapper<DataVersion>()
|
.set("del_flag",1)
|
.in("business_id",Arrays.asList(ids.split(","))));
|
productionLineWarehouseClientService.update(new UpdateWrapper<ProductionLineWarehouseClient>()
|
.in("id",Arrays.asList(ids.split(",")))
|
.set("del_flag",1));
|
return Result.OK("删除成功");
|
}
|
|
/**
|
* 导出
|
* @return
|
*/
|
@RequestMapping(value = "/exportProductionLineWarehouseClient")
|
public ModelAndView exportProductionLineWarehouseClient(HttpServletRequest request, ProductionLineWarehouseClient productionLineWarehouseClient) {
|
// Step.1 组装查询条件
|
QueryWrapper<ProductionLineWarehouseClient> queryWrapper = QueryGenerator.initQueryWrapper(productionLineWarehouseClient, request.getParameterMap());
|
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
|
// Step.2 获取导出数据
|
List<ProductionLineWarehouseClient> pageList = productionLineWarehouseClientService.list(queryWrapper);
|
List<ProductionLineWarehouseClient> exportList = null;
|
|
// 过滤选中数据
|
String selections = request.getParameter("selections");
|
if (oConvertUtils.isNotEmpty(selections)) {
|
List<String> selectionList = Arrays.asList(selections.split(","));
|
exportList = pageList.stream().filter(item -> selectionList.contains(item.getId())).collect(Collectors.toList());
|
} else {
|
exportList = pageList;
|
}
|
|
// Step.3 AutoPoi 导出Excel
|
ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
|
//此处设置的filename无效,前端会重更新设置一下
|
mv.addObject(NormalExcelConstants.FILE_NAME, "线边库服务对象");
|
mv.addObject(NormalExcelConstants.CLASS, ProductionLineWarehouseClient.class);
|
mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("线边库服务对象报表", "导出人:" + sysUser.getRealname(), "线边库服务对象"));
|
mv.addObject(NormalExcelConstants.DATA_LIST, exportList);
|
return mv;
|
}
|
|
/**
|
* 导入
|
* @return
|
*/
|
@RequestMapping(value = "/importProductionLineWarehouseClient/{mainId}")
|
public Result<?> importProductionLineWarehouseClient(HttpServletRequest request, HttpServletResponse response, @PathVariable("mainId") String mainId) {
|
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
|
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
|
// 获取上传文件对象
|
MultipartFile file = entity.getValue();
|
ImportParams params = new ImportParams();
|
params.setTitleRows(2);
|
params.setHeadRows(1);
|
params.setNeedSave(true);
|
try {
|
List<ProductionLineWarehouseClient> list = ExcelImportUtil.importExcel(file.getInputStream(), ProductionLineWarehouseClient.class, params);
|
for (ProductionLineWarehouseClient temp : list) {
|
temp.setWarehouseId(mainId);
|
}
|
long start = System.currentTimeMillis();
|
productionLineWarehouseClientService.saveBatch(list);
|
log.info("消耗时间" + (System.currentTimeMillis() - start) + "毫秒");
|
return Result.OK("文件导入成功!数据行数:" + list.size());
|
} catch (Exception e) {
|
log.error(e.getMessage(), e);
|
return Result.error("文件导入失败:" + e.getMessage());
|
} finally {
|
try {
|
file.getInputStream().close();
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
}
|
}
|
return Result.error("文件导入失败!");
|
}
|
|
/*--------------------------------子表处理-线边库服务对象-end----------------------------------------------*/
|
/**
|
* //根据工厂id查所有子工厂及车间
|
*
|
* @param pageNo
|
* @param pageSize
|
* @param parentId
|
* @param version
|
* @return
|
*/
|
@GetMapping("/factorylist")//根据工厂id查所有子工厂及车间
|
public Result<?> list(Map map,
|
@RequestParam(name ="pageNo", defaultValue="1") Integer pageNo,
|
@RequestParam(name ="pageSize", defaultValue="10") Integer pageSize,
|
@RequestParam(name = "parentId",required = false) String parentId,
|
@RequestParam(name="version",required = false) Integer version,
|
@RequestParam(name="selected",required = false) String selected
|
){
|
List<String> ids = new ArrayList<>();
|
if(selected!=null){
|
ids = Arrays.asList(selected.split(","));
|
}
|
Page<Map<String,Object>> page = new Page(pageNo, pageSize);
|
IPage<Map<String,Object>> pageList = productionLineWarehouseClientService.getFactoryList(page,version,parentId,ids);
|
return Result.OK(pageList);
|
}
|
|
|
|
}
|