| | |
| | | |
| | | import com.alibaba.excel.EasyExcel; |
| | | import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | |
| | | import com.core.annotations.ManagerAuth; |
| | | import com.core.common.*; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.entity.LocDetl; |
| | | import com.zy.asrs.entity.Mat; |
| | | import com.zy.asrs.entity.MatPrint; |
| | | import com.zy.asrs.entity.OrderDetl; |
| | | import com.zy.asrs.entity.*; |
| | | import com.zy.asrs.entity.param.InFormIdParam; |
| | | import com.zy.asrs.entity.result.KeyValueVo; |
| | | import com.zy.asrs.service.ApiLogService; |
| | | import com.zy.asrs.service.LocDetlService; |
| | | import com.zy.asrs.service.MatService; |
| | | import com.zy.asrs.service.TagService; |
| | | import com.zy.asrs.task.core.ReturnT; |
| | | import com.zy.asrs.task.kingdee.handler.LoginAuthenticationHandler; |
| | | import com.zy.asrs.utils.MatExcelListener; |
| | | import com.zy.common.CodeRes; |
| | | import com.zy.common.config.AdminInterceptor; |
| | | import com.zy.common.entity.MatExcel; |
| | | import com.zy.common.utils.BarcodeUtils; |
| | | import com.zy.common.utils.HttpHandler; |
| | | import com.zy.common.utils.QrCode; |
| | | import com.zy.common.web.BaseController; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | |
| | | import java.awt.image.BufferedImage; |
| | | import java.io.IOException; |
| | | import java.net.URLEncoder; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | | |
| | | @RestController |
| | | @Slf4j |
| | | public class MatController extends BaseController { |
| | | |
| | | @Value("${erp.address.URL}") |
| | | //端口 |
| | | private String URL; |
| | | |
| | | @Value("${erp.address.inaddress}") |
| | | //单据,商品档案地址 |
| | | private String inaddress; |
| | | |
| | | @Autowired |
| | | private TagService tagService; |
| | | |
| | | @Autowired |
| | | private ApiLogService apiLogService; |
| | | @Autowired |
| | | private MatService matService; |
| | | @Autowired |
| | | private LocDetlService locDetlService; |
| | | @Autowired |
| | | private SnowflakeIdWorker snowflakeIdWorker; |
| | | @Autowired |
| | | private LoginAuthenticationHandler loginAuthenticationHandler; |
| | | |
| | | @RequestMapping(value = "/mat/auto/matnr/auth") |
| | | public R autoMatnr(){ |
| | |
| | | if (null != matService.selectByMatnr(mat.getMatnr())) { |
| | | return R.error("编号已存在"); |
| | | } |
| | | Date now = new Date(); |
| | | mat.setCreateBy(getUserId()); |
| | | mat.setCreateTime(now); |
| | | mat.setUpdateBy(getUserId()); |
| | | mat.setUpdateTime(now); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | //登录金蝶 |
| | | ReturnT<String> start = loginAuthenticationHandler.start(); |
| | | |
| | | InFormIdParam inFormIdParam = new InFormIdParam(); |
| | | inFormIdParam.setFormId("BD_MATERIAL"); |
| | | inFormIdParam.setLimit(100); |
| | | inFormIdParam.setStartRow("0"); |
| | | String FDocumentStatus = "C"; |
| | | String FNumber=mat.getMatnr(); |
| | | //条件和需要获得的结果拼接 |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("FormId", inFormIdParam.getFormId()); |
| | | jsonObject.put("Limit", inFormIdParam.getLimit()); |
| | | jsonObject.put("StartRow", inFormIdParam.getStartRow()); |
| | | jsonObject.put("FilterString", "FDocumentStatus='" + FDocumentStatus +"' and FNumber='"+FNumber+"' and FUseOrgId .FNumber='201'"); |
| | | jsonObject.put("FieldKeys", "FName,FNumber,FCreateDate,FSpecification,FDocumentStatus"); |
| | | JSONObject jsonObject1 = new JSONObject(); |
| | | jsonObject1.put("data", jsonObject); |
| | | String add = jsonObject1.toJSONString(); |
| | | //上报 |
| | | String response = ""; |
| | | boolean success = false; |
| | | try { |
| | | //获取Cookie值 |
| | | HashMap<String, Object> headers = new HashMap<>(); |
| | | headers.put("Cookie", start.getContent()); |
| | | response = new HttpHandler.Builder() |
| | | .setHeaders(headers) |
| | | .setUri(URL) |
| | | .setPath(inaddress) |
| | | .setJson(add) |
| | | .build() |
| | | .doPost(); |
| | | JSONArray data = JSON.parseArray(response); |
| | | if (data.getJSONArray(0).get(0).toString().length()<20) { |
| | | success = true; |
| | | JSONArray jsonArray = data.getJSONArray(0); |
| | | //生成商品档案 |
| | | //商品编号 |
| | | mat = matService.selectByMatnr(jsonArray.get(1).toString()); |
| | | if (mat == null) { |
| | | mat = new Mat(); |
| | | Tag tag = new Tag(); |
| | | mat.setMatnr(jsonArray.get(1).toString()); |
| | | mat.setMaktx(jsonArray.get(0).toString()); |
| | | mat.setSpecs(jsonArray.get(3).toString());//规格 |
| | | mat.setTagId(20L); |
| | | //对美国时间进行转换 |
| | | DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"); |
| | | DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME; |
| | | LocalDateTime dateTime = LocalDateTime.parse(jsonArray.get(2).toString(), formatter); |
| | | String format = dateFormat.format(dateTime); |
| | | Date date = sdf.parse(format); |
| | | mat.setCreateTime(date);//商品创建时间 |
| | | mat.setUpdateTime(new Date()); |
| | | mat.setStatus(1); |
| | | //最新抓取商品时间 |
| | | tag.setCreateTime(date); |
| | | tagService.update(tag, new EntityWrapper<Tag>().eq("id", 20)); |
| | | if (!matService.insert(mat)) { |
| | | throw new CoolException("添加失败,请联系管理员"); |
| | | throw new CoolException("服务器内部错误,请联系管理员"); |
| | | } else { |
| | | log.info("同步新物料[商品编号:{}]", mat.getMatnr()); |
| | | } |
| | | } |
| | | }else { |
| | | throw new CoolException("没有找到指定物料档案,请联系管理员"); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("fail", e); |
| | | // TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | | } finally { |
| | | try { |
| | | // 保存接口日志 |
| | | apiLogService.save( |
| | | "轮询数据", |
| | | URL + inaddress, |
| | | null, |
| | | "127.0.0.1", |
| | | add, |
| | | response, |
| | | success |
| | | ); |
| | | } catch (Exception e) { |
| | | log.error("", e); |
| | | } |
| | | } |
| | | return R.ok(); |
| | | } |