|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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(){ | 
|---|
|  |  |  | public R autoMatnr() { | 
|---|
|  |  |  | return R.ok().add("YJ" + DateUtils.convert(new Date(), DateUtils.yyyyMMddHHmmsssss).substring(0, 16)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/mat/list/pda/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R pdaList(@RequestParam(required = true)Long tagId){ | 
|---|
|  |  |  | public R pdaList(@RequestParam(required = true) Long tagId) { | 
|---|
|  |  |  | EntityWrapper<Mat> wrapper = new EntityWrapper<>(); | 
|---|
|  |  |  | wrapper.eq("tag_id", tagId); | 
|---|
|  |  |  | wrapper.orderBy("create_time", false); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/mat/search/pda/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R pdaSearch(@RequestParam(required = false)String condition){ | 
|---|
|  |  |  | public R pdaSearch(@RequestParam(required = false) String condition) { | 
|---|
|  |  |  | EntityWrapper<Mat> wrapper = new EntityWrapper<>(); | 
|---|
|  |  |  | if (!Cools.isEmpty(condition)) { | 
|---|
|  |  |  | wrapper.like("matnr", condition).or().like("maktx", condition); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/mat/list/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R list(@RequestParam(defaultValue = "1")Integer curr, | 
|---|
|  |  |  | @RequestParam(defaultValue = "10")Integer limit, | 
|---|
|  |  |  | @RequestParam(required = false)String orderByField, | 
|---|
|  |  |  | @RequestParam(required = false)String orderByType, | 
|---|
|  |  |  | @RequestParam Map<String, Object> param){ | 
|---|
|  |  |  | public R list(@RequestParam(defaultValue = "1") Integer curr, | 
|---|
|  |  |  | @RequestParam(defaultValue = "10") Integer limit, | 
|---|
|  |  |  | @RequestParam(required = false) String orderByField, | 
|---|
|  |  |  | @RequestParam(required = false) String orderByType, | 
|---|
|  |  |  | @RequestParam Map<String, Object> param) { | 
|---|
|  |  |  | Object tagId = param.get("tag_id"); | 
|---|
|  |  |  | if (Cools.isEmpty(tagId)) { | 
|---|
|  |  |  | tagId = getOriginTag().getId(); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private void convert(Map<String, Object> map, EntityWrapper wrapper){ | 
|---|
|  |  |  | for (Map.Entry<String, Object> entry : map.entrySet()){ | 
|---|
|  |  |  | private void convert(Map<String, Object> map, EntityWrapper wrapper) { | 
|---|
|  |  |  | for (Map.Entry<String, Object> entry : map.entrySet()) { | 
|---|
|  |  |  | String val = String.valueOf(entry.getValue()); | 
|---|
|  |  |  | if (val.contains(RANGE_TIME_LINK)){ | 
|---|
|  |  |  | if (val.contains(RANGE_TIME_LINK)) { | 
|---|
|  |  |  | String[] dates = val.split(RANGE_TIME_LINK); | 
|---|
|  |  |  | wrapper.ge(entry.getKey(), DateUtils.convert(dates[0])); | 
|---|
|  |  |  | wrapper.le(entry.getKey(), DateUtils.convert(dates[1])); | 
|---|
|  |  |  | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/mat/update/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R update(Mat mat){ | 
|---|
|  |  |  | if (Cools.isEmpty(mat) || null==mat.getId()){ | 
|---|
|  |  |  | @RequestMapping(value = "/mat/KingDeeadd/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R KingDeeadd(Mat mat) { | 
|---|
|  |  |  | if (null != matService.selectByMatnr(mat.getMatnr())) { | 
|---|
|  |  |  | return R.error("编号已存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 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("服务器内部错误,请联系管理员"); | 
|---|
|  |  |  | } 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(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/mat/update/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R update(Mat mat) { | 
|---|
|  |  |  | if (Cools.isEmpty(mat) || null == mat.getId()) { | 
|---|
|  |  |  | return R.error(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | mat.setUpdateBy(getUserId()); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/mat/delete/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R delete(@RequestParam String param){ | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public R delete(@RequestParam String param) { | 
|---|
|  |  |  | List<Mat> list = JSONArray.parseArray(param, Mat.class); | 
|---|
|  |  |  | if (Cools.isEmpty(list)){ | 
|---|
|  |  |  | if (Cools.isEmpty(list)) { | 
|---|
|  |  |  | return R.error(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (Mat entity : list){ | 
|---|
|  |  |  | for (Mat entity : list) { | 
|---|
|  |  |  | LocDetl locDetl = locDetlService.selectByMatnr(entity.getMatnr()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!Cools.isEmpty(locDetl)) { | 
|---|
|  |  |  | throw new CoolException("当前物料在库,无法删除!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/mat/export/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R export(@RequestBody JSONObject param){ | 
|---|
|  |  |  | public R export(@RequestBody JSONObject param) { | 
|---|
|  |  |  | EntityWrapper<Mat> wrapper = new EntityWrapper<>(); | 
|---|
|  |  |  | List<String> fields = JSONObject.parseArray(param.getJSONArray("fields").toJSONString(), String.class); | 
|---|
|  |  |  | Map<String, Object> map = excludeTrash(param.getJSONObject("mat")); | 
|---|
|  |  |  | 
|---|
|  |  |  | wrapper.like("matnr", condition).or().like("maktx", condition); | 
|---|
|  |  |  | Page<Mat> page = matService.selectPage(new Page<>(0, 10), wrapper); | 
|---|
|  |  |  | List<Map<String, Object>> result = new ArrayList<>(); | 
|---|
|  |  |  | for (Mat mat : page.getRecords()){ | 
|---|
|  |  |  | for (Mat mat : page.getRecords()) { | 
|---|
|  |  |  | Map<String, Object> map = new HashMap<>(); | 
|---|
|  |  |  | map.put("id", mat.getId()); | 
|---|
|  |  |  | map.put("value", mat.getMatnr() + "(" + mat.getMaktx() + ")"); | 
|---|
|  |  |  | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R query(@RequestBody JSONObject param) { | 
|---|
|  |  |  | Wrapper<Mat> wrapper = new EntityWrapper<Mat>().eq(humpToLine(String.valueOf(param.get("key"))), param.get("val")); | 
|---|
|  |  |  | if (null != matService.selectOne(wrapper)){ | 
|---|
|  |  |  | if (null != matService.selectOne(wrapper)) { | 
|---|
|  |  |  | return R.parse(BaseRes.REPEAT).add(getComment(Mat.class, String.valueOf(param.get("key")))); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | 
|---|
|  |  |  | , @RequestParam String param | 
|---|
|  |  |  | , HttpServletResponse response) throws Exception { | 
|---|
|  |  |  | AdminInterceptor.cors(response); | 
|---|
|  |  |  | if (Cools.isEmpty(param)){ | 
|---|
|  |  |  | if (Cools.isEmpty(param)) { | 
|---|
|  |  |  | return R.parse(BaseRes.EMPTY); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | BufferedImage img; | 
|---|
|  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/mat/print/auth") | 
|---|
|  |  |  | @ManagerAuth(memo = "商品编码打印") | 
|---|
|  |  |  | public R matCodePrint(@RequestParam(value = "param[]") String[] param) { | 
|---|
|  |  |  | if(Cools.isEmpty(param)) { | 
|---|
|  |  |  | if (Cools.isEmpty(param)) { | 
|---|
|  |  |  | return R.parse(CodeRes.EMPTY); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<MatPrint> res = new ArrayList<>(); | 
|---|
|  |  |  | for (String matnr : param){ | 
|---|
|  |  |  | for (String matnr : param) { | 
|---|
|  |  |  | Mat mat = matService.selectByMatnr(matnr); | 
|---|
|  |  |  | // 打印数据注入 | 
|---|
|  |  |  | MatPrint print = new MatPrint(); | 
|---|
|  |  |  | 
|---|
|  |  |  | public R matExcelImport(MultipartFile file) throws IOException { | 
|---|
|  |  |  | MatExcelListener listener = new MatExcelListener(getUserId()); | 
|---|
|  |  |  | EasyExcel.read(file.getInputStream(), MatExcel.class, listener).sheet().doRead(); | 
|---|
|  |  |  | return R.ok("成功同步"+listener.getTotal()+"条商品数据"); | 
|---|
|  |  |  | return R.ok("成功同步" + listener.getTotal() + "条商品数据"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /*************************************** xm-select ***********************************************/ | 
|---|