/*
|
* Copyright (c) 2018-2025, ztt All rights reserved.
|
*
|
* Redistribution and use in source and binary forms, with or without
|
* modification, are permitted provided that the following conditions are met:
|
*
|
* Redistributions of source code must retain the above copyright notice,
|
* this list of conditions and the following disclaimer.
|
* Redistributions in binary form must reproduce the above copyright
|
* notice, this list of conditions and the following disclaimer in the
|
* documentation and/or other materials provided with the distribution.
|
* Neither the name of the pig4cloud.com developer nor the names of its
|
* contributors may be used to endorse or promote products derived from
|
* this software without specific prior written permission.
|
* Author: ztt
|
*/
|
|
package com.chinaztt.mes.basic.controller;
|
|
import cn.hutool.core.text.csv.CsvReadConfig;
|
import com.alibaba.excel.EasyExcel;
|
import com.alibaba.fastjson.JSONObject;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.chinaztt.mes.basic.entity.Part;
|
import com.chinaztt.mes.basic.excel.PartData;
|
import com.chinaztt.mes.basic.excel.PartUploadListener;
|
import com.chinaztt.mes.basic.mapper.PartMapper;
|
import com.chinaztt.mes.basic.service.PartService;
|
import com.chinaztt.mes.basic.util.DictUtils;
|
import com.chinaztt.mes.basic.util.PartUtils;
|
import com.chinaztt.mes.basic.vo.PartVo;
|
import com.chinaztt.mes.common.util.JsonUtil;
|
import com.chinaztt.mes.common.wrapper.QueryWrapperUtil;
|
import com.chinaztt.ztt.admin.api.entity.SysDictItem;
|
import com.chinaztt.ztt.admin.api.feign.RemoteDictService;
|
import com.chinaztt.ztt.common.core.util.R;
|
import com.chinaztt.ztt.common.log.annotation.SysLog;
|
import com.chinaztt.ztt.common.security.annotation.Inner;
|
import com.chinaztt.ztt.common.security.util.SecurityUtils;
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
import lombok.AllArgsConstructor;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.multipart.MultipartFile;
|
|
import java.io.IOException;
|
import java.util.List;
|
|
|
/**
|
* 零件
|
*
|
* @author fenglang
|
* @date 2020-08-17 14:37:35
|
*/
|
@RestController
|
@AllArgsConstructor
|
@RequestMapping("/part")
|
@Api(value = "part", tags = "零件管理")
|
public class PartController {
|
|
private final PartService partService;
|
private final RemoteDictService remoteDictService;
|
private final RedisTemplate redisTemplate;;
|
|
private DictUtils dictUtils;
|
private PartUtils partUtils;
|
|
private PartMapper partMapper;
|
|
private final static Logger logger = LoggerFactory.getLogger(PartController.class);
|
|
|
@Autowired
|
private ThreadPoolTaskExecutor threadPoolTaskExecutor;
|
|
|
@ApiOperation(value = "触发零件", notes = "触发零件")
|
@SysLog("触发零件")
|
@PostMapping("/triggerAdd")
|
@Inner(value = false)
|
public R triggerAdd(@RequestParam String params) {
|
PartVo partVo = JSONObject.parseObject(params, PartVo.class);
|
R<Object> objectR = new R<>();
|
if(partService.triggerAdd(partVo).equals("1")){
|
objectR.setCode(1);
|
objectR.setMsg("操作成功");
|
}else {
|
objectR.setCode(0);
|
objectR.setMsg("操作失败!联系人员查看日志!");
|
}
|
return objectR;
|
}
|
|
|
|
/**
|
* 分页查询
|
*
|
* @param page 分页对象
|
* @param part 零件
|
* @param bomId bomId
|
* @return
|
*/
|
@ApiOperation(value = "分页查询", notes = "分页查询")
|
@GetMapping("/page")
|
@PreAuthorize("@pms.hasPermission('basic_part_view')")
|
public R getPartPage(Page page, Part part, Long bomId) {
|
//System.out.println(bomId);
|
//System.out.println(part);
|
System.out.println(JsonUtil.jsonToString(page));
|
return R.ok(partService.getPartPage(page, QueryWrapperUtil.gen(part), bomId));
|
}
|
/**
|
* 对接志邦国际鹰联 erp 同步基礎零件
|
* @return
|
*/
|
@ApiOperation(value = "同步销售订单", notes = "同步销售订单")
|
@PostMapping("/syncPart")
|
@XxlJob("syncPart")
|
public R syncPart() {
|
String key = "syncPart_lock";
|
if (redisTemplate.hasKey(key)) {
|
throw new RuntimeException("有同步任务正在处理");
|
}
|
partService.syncPart();
|
return R.ok();
|
}
|
|
//@InitBinder
|
//protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception {
|
// //System.out.println(request.getParameter("date"));
|
// DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
|
// CustomDateEditor editor = new CustomDateEditor(df, true);//true表示允许为空,false反之
|
// binder.registerCustomEditor(Date.class, editor);
|
//}
|
|
@ApiOperation(value = "同步Ifs", notes = "同步Ifs")
|
@PostMapping("/syncNewIfs")
|
//@XxlJob("syncPart")
|
public R syncNewIfs(String date) {
|
String key = "syncPart_lock"+ SecurityUtils.getUser().getId();
|
if (redisTemplate.hasKey(key)) {
|
throw new RuntimeException("有同步任务正在处理");
|
}
|
return R.ok(partService.syncNewIfs(date));
|
}
|
/**
|
* 分页查询已关联检测模板的零件
|
*
|
* @param page 分页对象
|
* @param part 零件
|
* @return
|
*/
|
@ApiOperation(value = "分页查询", notes = "分页查询")
|
@GetMapping("/getQualityPartList/page")
|
@PreAuthorize("@pms.hasPermission('basic_part_view')")
|
public R getQualityPartPage(Page page, Part part) {
|
return R.ok(partService.getQualityPartPage(page, QueryWrapperUtil.gen(part).orderByDesc("create_time")));
|
}
|
|
/**
|
* 根据零件号和零件描述查询库存信息接口
|
*
|
* @param 零件
|
* @return
|
*/
|
@ApiOperation(value = "根据零件号和零件描述查询库存信息接口", notes = "根据零件号和零件描述查询库存信息接口")
|
@GetMapping("/getPart/page")
|
public R getQualityPartPage(Part inAttr) {
|
return R.ok(partService.getPart(inAttr));
|
}
|
|
/**
|
* 分页查询未关联检测模板的零件
|
*
|
* @param page 分页对象
|
* @param part 零件
|
* @return
|
*/
|
@ApiOperation(value = "分页查询", notes = "分页查询")
|
@GetMapping("/getNotInQualityPartList/page")
|
@PreAuthorize("@pms.hasPermission('basic_part_view')")
|
public R getNotInQualityPartPage(Page page, Part part) {
|
return R.ok(partService.getNotInQualityPartPage(page, QueryWrapperUtil.gen(part).orderByDesc("create_time")));
|
}
|
|
/**
|
* 分页查询添加来源信息的零件
|
*
|
* @param page 分页对象
|
* @param part 零件
|
* @return
|
*/
|
@ApiOperation(value = "分页查询", notes = "分页查询")
|
@GetMapping("/getReportPartsPage/page")
|
@PreAuthorize("@pms.hasPermission('basic_part_view')")
|
public R getReportPartsPage(Page page, Part part) {
|
return R.ok(partService.getReportPartsPage(page, QueryWrapperUtil.gen(part).orderByDesc("create_time")));
|
}
|
|
/**
|
* 通过id查询零件
|
*
|
* @param id id
|
* @return R
|
*/
|
@ApiOperation(value = "通过id查询", notes = "通过id查询")
|
@GetMapping("/{id}")
|
@PreAuthorize("@pms.hasPermission('basic_part_view')")
|
public R getById(@PathVariable("id") Long id) {
|
return R.ok(partService.getById(id));
|
}
|
|
/**
|
* excel上传
|
*
|
* @return
|
*/
|
@PostMapping("/upload")
|
public R upload(@RequestParam("file") MultipartFile file) {
|
try {
|
EasyExcel.read(file.getInputStream(), PartData.class, new PartUploadListener(partService)).sheet().doRead();
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
return R.ok();
|
}
|
|
/**
|
* 新增零件
|
*
|
* @param part 零件
|
* @return R
|
*/
|
@ApiOperation(value = "新增零件", notes = "新增零件")
|
@SysLog("新增零件")
|
@PostMapping
|
@PreAuthorize("@pms.hasPermission('basic_part_add')")
|
public R save(@RequestBody Part part) {
|
return R.ok(partService.doSave(part));
|
}
|
|
/**
|
* 修改零件
|
*
|
* @param part 零件
|
* @return R
|
*/
|
@ApiOperation(value = "修改零件", notes = "修改零件")
|
@SysLog("修改零件")
|
@PutMapping
|
@PreAuthorize("@pms.hasPermission('basic_part_edit')")
|
public R updateById(@RequestBody Part part) {
|
return R.ok(partService.doUpdate(part));
|
}
|
|
/**
|
* 通过id删除零件
|
*
|
* @param id id
|
* @return R
|
*/
|
@ApiOperation(value = "通过id删除零件", notes = "通过id删除零件")
|
@SysLog("通过id删除零件")
|
@DeleteMapping("/{id}")
|
@PreAuthorize("@pms.hasPermission('basic_part_del')")
|
public R removeById(@PathVariable Long id) {
|
return R.ok(partService.removeById(id));
|
}
|
|
|
/**
|
* 关键字查询
|
*
|
* @param keyword
|
* @return
|
*/
|
@ApiOperation(value = "关键字查询", notes = "关键字查询")
|
@GetMapping("/query/{keyword}")
|
@PreAuthorize("@pms.hasPermission('basic_part_view')")
|
public R query(@PathVariable("keyword") String keyword) {
|
return R.ok(partService.query(keyword));
|
}
|
|
/**
|
* 提供给pda的接口,根据零件号查询 cxf 201021
|
*
|
* @param partNo
|
* @return
|
*/
|
@ApiOperation(value = "根据零件号查询", notes = "根据零件号查询")
|
@GetMapping("/pda/findByNo")
|
@Inner(value = false)
|
public R findByNo(String partNo) {
|
return R.ok(partService.getOne(Wrappers.<Part>lambdaQuery().eq(Part::getPartNo, partNo)));
|
}
|
|
/**
|
* @param index
|
* @return
|
*/
|
@GetMapping("/dict/{index}")
|
public R<List<SysDictItem>> dir(@PathVariable("index") String index) {
|
return remoteDictService.getDictByType(index);
|
}
|
|
/**
|
* 同步ifs 数据
|
*
|
* @param ids
|
* @return
|
*/
|
@PostMapping("/ifsSync")
|
public R ifsSync(@RequestBody List<Long> ids) {
|
return partService.ifsSync(ids);
|
}
|
|
/**
|
* 接收主数据平台推送零件数据
|
*/
|
@PostMapping(value = "/mainSync")
|
@Inner(false)
|
public R parySync(String params) {
|
return partService.parySync(JSONObject.parseObject(params));
|
}
|
|
/**
|
* 获取工艺路线零件
|
* @param page 分页对象
|
* @param part 零件
|
* @param bomId bomId
|
* @return
|
*/
|
@GetMapping("/getRoutingPartPage")
|
@PreAuthorize("@pms.hasPermission('basic_part_view')")
|
public R getRoutingPartPage(Page page, Part part, Long bomId) {
|
return R.ok(partService.getRoutingPartPage(page, QueryWrapperUtil.gen(part), bomId));
|
}
|
|
@PostMapping("/uploadExcel")
|
public R uploadExcel(MultipartFile file) {
|
String key = "syncPart_lock" + SecurityUtils.getUser().getId();
|
if (redisTemplate.hasKey(key)) {
|
throw new RuntimeException("有导入任务正在处理");
|
}
|
partService.asyncUploadExcel(file);
|
return R.ok();
|
}
|
|
/**
|
* 设置Csv读文件配置
|
* @return CsvWriteConfig
|
*/
|
public static CsvReadConfig setCsvReadConfig(){
|
CsvReadConfig csvReadConfig = new CsvReadConfig();
|
// 设置 文本分隔符,文本包装符,默认双引号'"'
|
//csvReadConfig.setTextDelimiter('\t');
|
// 字段分割符号,默认为逗号
|
csvReadConfig.setFieldSeparator('|');
|
// 设置注释符号
|
// csvReadConfig.setCommentCharacter('#');
|
// CSV文件是否包含表头(因为表头不是数据内容)
|
csvReadConfig.setContainsHeader(true);
|
// 或者使用如下配置设置表头开始行号,-1L代表无表头
|
// csvReadConfig.setHeaderLineNo(1L);
|
//设置开始的行(包括),默认0,此处为原始文件行号
|
// csvReadConfig.setBeginLineNo(0);
|
// 是否跳过空白行,默认为true
|
// csvReadConfig.setSkipEmptyRows(true);
|
// 设置每行字段个数不同时是否抛出异常,默认false
|
// csvReadConfig.setErrorOnDifferentFieldCount(false);
|
return csvReadConfig;
|
}
|
|
}
|