| | |
| | | |
| | | 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.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 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.Date; |
| | | import java.util.List; |
| | | |
| | | |
| | |
| | | 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); |
| | | return R.ok(partService.triggerAdd(partVo)); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 分页查询 |
| | | * |
| | |
| | | @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)); |
| | | } |
| | | /** |
| | |
| | | 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(Date date) { |
| | | System.out.println(date); |
| | | public R syncNewIfs(String date) { |
| | | String key = "syncPart_lock"+ SecurityUtils.getUser().getId(); |
| | | if (redisTemplate.hasKey(key)) { |
| | | throw new RuntimeException("有同步任务正在处理"); |
| | |
| | | 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; |
| | | } |
| | | |
| | | } |