From dad3cd8ed8afa86b651bb1a053421e7aa2b8c7ac Mon Sep 17 00:00:00 2001 From: Junjie <540245094@qq.com> Date: 星期日, 05 五月 2024 16:31:09 +0800 Subject: [PATCH] # --- zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/BarcodeThread.java | 7 zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/service/impl/DeviceBarcodeServiceImpl.java | 12 zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/utils/CodeBuilder.java | 4 zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/mapper/DeviceBarcodeMapper.java | 12 zy-asrs-wcs/src/main/resources/mapper/core/DeviceBarcodeMapper.xml | 5 zy-asrs-flow/src/pages/device/deviceBarcode/components/edit.jsx | 175 ++++++++ zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/entity/DeviceBarcode.java | 255 ++++++++++++ zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/service/DeviceBarcodeService.java | 8 zy-asrs-flow/src/pages/device/deviceBarcode/index.jsx | 473 +++++++++++++++++++++++ zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/controller/DeviceBarcodeController.java | 102 +++++ zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/SiemensBarcodeThread.java | 117 +++++ zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/SiemensDevpThread.java | 14 12 files changed, 1,168 insertions(+), 16 deletions(-) diff --git a/zy-asrs-flow/src/pages/device/deviceBarcode/components/edit.jsx b/zy-asrs-flow/src/pages/device/deviceBarcode/components/edit.jsx new file mode 100644 index 0000000..e7722d1 --- /dev/null +++ b/zy-asrs-flow/src/pages/device/deviceBarcode/components/edit.jsx @@ -0,0 +1,175 @@ +import React, { useState, useRef, useEffect } from 'react'; +import { + ProForm, + ProFormDigit, + ProFormText, + ProFormSelect, + ProFormDateTimePicker +} from '@ant-design/pro-components'; +import { Form, Modal } from 'antd'; +import { FormattedMessage, useIntl } from '@umijs/max'; +import moment from 'moment'; +import Http from '@/utils/http'; + +const Edit = (props) => { + const intl = useIntl(); + const [form] = Form.useForm(); + const { } = props; + + useEffect(() => { + form.resetFields(); + form.setFieldsValue({ + ...props.values + }) + }, [form, props]) + + const handleCancel = () => { + props.onCancel(); + }; + + const handleOk = () => { + form.submit(); + } + + const handleFinish = async (values) => { + props.onSubmit({ ...values }); + } + + return ( + <> + <Modal + title={ + Object.keys(props.values).length > 0 + ? intl.formatMessage({ id: 'page.edit', defaultMessage: '缂栬緫' }) + : intl.formatMessage({ id: 'page.add', defaultMessage: '娣诲姞' }) + } + width={640} + forceRender + destroyOnClose + open={props.open} + onCancel={handleCancel} + onOk={handleOk} + > + <ProForm + form={form} + submitter={false} + onFinish={handleFinish} + layout="horizontal" + grid={true} + > + <ProFormDigit + name="id" + disabled + hidden={true} + /> + <ProForm.Group> + <ProFormText + name="uuid" + label="缂栧彿" + colProps={{ md: 12, xl: 12 }} + /> + <ProFormText + name="name" + label="鍚嶇О" + colProps={{ md: 12, xl: 12 }} + /> + </ProForm.Group> + <ProForm.Group> + <ProFormText + name="flag" + label="鏍囪瘑" + colProps={{ md: 12, xl: 12 }} + /> + <ProFormSelect + name="deviceId" + label="鏉$爜璁惧" + colProps={{ md: 12, xl: 12 }} + showSearch + debounceTime={300} + request={async ({ keyWords }) => { + const resp = await Http.doPostForm('api/device/query', { condition: keyWords }); + return resp.data; + }} + /> + </ProForm.Group> + <ProForm.Group> + <ProFormSelect + name="type" + label="杩炴帴绫诲瀷" + colProps={{ md: 12, xl: 12 }} + options={[ + { label: 'PLC', value: 0 }, + { label: 'Socket', value: 1 }, + { label: 'HTTP', value: 2 }, + ]} + /> + <ProFormText + name="connect" + label="杩炴帴鍙傛暟" + colProps={{ md: 12, xl: 12 }} + /> + </ProForm.Group> + <ProForm.Group> + <ProFormSelect + name="status" + label="鐘舵��" + colProps={{ md: 12, xl: 12 }} + options={[ + { label: '姝e父', value: 1 }, + { label: '绂佺敤', value: 0 }, + ]} + /> + <ProFormDateTimePicker + name="createTime" + label="娣诲姞鏃堕棿" + colProps={{ md: 12, xl: 12 }} + transform={(value) => moment(value).toISOString()} + /> + </ProForm.Group> + <ProForm.Group> + <ProFormSelect + name="createBy" + label="娣诲姞浜哄憳" + colProps={{ md: 12, xl: 12 }} + fieldProps={{ precision: 0 }} + showSearch + debounceTime={300} + request={async ({ keyWords }) => { + const resp = await Http.doPostForm('api/user/query', { condition: keyWords }); + return resp.data; + }} + /> + <ProFormDateTimePicker + name="updateTime" + label="淇敼鏃堕棿" + colProps={{ md: 12, xl: 12 }} + transform={(value) => moment(value).toISOString()} + /> + </ProForm.Group> + <ProForm.Group> + <ProFormSelect + name="updateBy" + label="淇敼浜哄憳" + colProps={{ md: 12, xl: 12 }} + fieldProps={{ precision: 0 }} + showSearch + debounceTime={300} + request={async ({ keyWords }) => { + const resp = await Http.doPostForm('api/user/query', { condition: keyWords }); + return resp.data; + }} + /> + <ProFormText + name="memo" + label="澶囨敞" + colProps={{ md: 12, xl: 12 }} + /> + </ProForm.Group> + + </ProForm> + </Modal> + </> + ) +} + +export default Edit; diff --git a/zy-asrs-flow/src/pages/device/deviceBarcode/index.jsx b/zy-asrs-flow/src/pages/device/deviceBarcode/index.jsx new file mode 100644 index 0000000..b472615 --- /dev/null +++ b/zy-asrs-flow/src/pages/device/deviceBarcode/index.jsx @@ -0,0 +1,473 @@ + +import React, { useState, useRef, useEffect } from 'react'; +import { Button, message, Modal, Tag } from 'antd'; +import { + FooterToolbar, + PageContainer, + ProTable, + LightFilter, +} from '@ant-design/pro-components'; +import { FormattedMessage, useIntl } from '@umijs/max'; +import { PlusOutlined, ExportOutlined } from '@ant-design/icons'; +import Http from '@/utils/http'; +import Edit from './components/edit' +import { TextFilter, SelectFilter, DatetimeRangeFilter, LinkFilter } from '@/components/TableSearch' +import { statusMap } from '@/utils/enum-util' +import { repairBug } from '@/utils/common-util'; + +const TABLE_KEY = 'pro-table-deviceBarcode'; + +const handleSave = async (val, intl) => { + const hide = message.loading(intl.formatMessage({ id: 'page.adding', defaultMessage: '姝e湪娣诲姞' })); + try { + const resp = await Http.doPost('api/deviceBarcode/save', val); + if (resp.code === 200) { + message.success(intl.formatMessage({ id: 'page.add.success', defaultMessage: '娣诲姞鎴愬姛' })); + return true; + } else { + message.error(resp.msg); + return false; + } + } catch (error) { + message.error(intl.formatMessage({ id: 'page.add.fail', defaultMessage: '娣诲姞澶辫触璇烽噸璇曪紒' })); + return false; + } finally { + hide(); + } +}; + +const handleUpdate = async (val, intl) => { + const hide = message.loading(intl.formatMessage({ id: 'page.updating', defaultMessage: '姝e湪鏇存柊' })); + try { + const resp = await Http.doPost('api/deviceBarcode/update', val); + if (resp.code === 200) { + message.success(intl.formatMessage({ id: 'page.update.success', defaultMessage: '鏇存柊鎴愬姛' })); + return true; + } else { + message.error(resp.msg); + return false; + } + } catch (error) { + message.error(intl.formatMessage({ id: 'page.update.fail', defaultMessage: '鏇存柊澶辫触璇烽噸璇曪紒' })); + return false; + } finally { + hide(); + } +}; + +const handleRemove = async (rows, intl) => { + if (!rows) return true; + const hide = message.loading(intl.formatMessage({ id: 'page.deleting', defaultMessage: '姝e湪鍒犻櫎' })); + try { + const resp = await Http.doPost('api/deviceBarcode/remove/' + rows.map((row) => row.id).join(',')); + if (resp.code === 200) { + message.success(intl.formatMessage({ id: 'page.delete.success', defaultMessage: '鍒犻櫎鎴愬姛' })); + return true; + } else { + message.error(resp.msg); + return false; + } + } catch (error) { + message.error(intl.formatMessage({ id: 'page.delete.fail', defaultMessage: '鍒犻櫎澶辫触锛岃閲嶈瘯锛�' })); + return false; + } finally { + hide(); + } +}; + +const handleExport = async (intl) => { + const hide = message.loading(intl.formatMessage({ id: 'page.exporting', defaultMessage: '姝e湪瀵煎嚭' })); + try { + const resp = await Http.doPostBlob('api/deviceBarcode/export'); + const blob = new Blob([resp], { type: 'application/vnd.ms-excel' }); + window.location.href = window.URL.createObjectURL(blob); + message.success(intl.formatMessage({ id: 'page.export.success', defaultMessage: '瀵煎嚭鎴愬姛' })); + return true; + } catch (error) { + message.error(intl.formatMessage({ id: 'page.export.fail', defaultMessage: '瀵煎嚭澶辫触锛岃閲嶈瘯' })); + return false; + } finally { + hide(); + } +}; + + +const Main = () => { + const intl = useIntl(); + const formTableRef = useRef(); + const actionRef = useRef(); + const [selectedRows, setSelectedRows] = useState([]); + const [modalVisible, setModalVisible] = useState(false); + const [currentRow, setCurrentRow] = useState(); + const [searchParam, setSearchParam] = useState({}); + + useEffect(() => { + + }, []); + + const columns = [ + { + title: intl.formatMessage({ + id: 'page.table.no', + defaultMessage: 'No' + }), + dataIndex: 'index', + valueType: 'indexBorder', + width: 48, + }, + { + title: '缂栧彿', + dataIndex: 'uuid', + valueType: 'text', + hidden: false, + width: 140, + filterDropdown: (props) => <TextFilter + name='uuid' + {...props} + actionRef={actionRef} + setSearchParam={setSearchParam} + />, + }, + { + title: '鍚嶇О', + dataIndex: 'name', + valueType: 'text', + hidden: false, + width: 140, + copyable: true, + filterDropdown: (props) => <TextFilter + name='name' + {...props} + actionRef={actionRef} + setSearchParam={setSearchParam} + />, + }, + { + title: '鏍囪瘑', + dataIndex: 'flag', + valueType: 'text', + hidden: false, + width: 140, + filterDropdown: (props) => <TextFilter + name='flag' + {...props} + actionRef={actionRef} + setSearchParam={setSearchParam} + />, + }, + { + title: '鏉$爜璁惧', + dataIndex: 'deviceId$', + valueType: 'text', + hidden: false, + width: 140, + filterDropdown: (props) => <LinkFilter + name='deviceId' + major='device' + {...props} + actionRef={actionRef} + setSearchParam={setSearchParam} + />, + }, + { + title: '杩炴帴绫诲瀷', + dataIndex: 'type$', + valueType: 'text', + hidden: false, + width: 140, + filterDropdown: (props) => <SelectFilter + name='type' + {...props} + actionRef={actionRef} + setSearchParam={setSearchParam} + data={[ + { label: 'PLC', value: 0 }, + { label: 'Socket', value: 1 }, + { label: 'HTTP', value: 2 }, + ]} + />, + }, + { + title: '杩炴帴鍙傛暟', + dataIndex: 'connect', + valueType: 'text', + hidden: false, + width: 140, + filterDropdown: (props) => <TextFilter + name='connect' + {...props} + actionRef={actionRef} + setSearchParam={setSearchParam} + />, + }, + { + title: '鐘舵��', + dataIndex: 'status$', + valueType: 'text', + hidden: false, + width: 140, + filterDropdown: (props) => <SelectFilter + name='status' + {...props} + actionRef={actionRef} + setSearchParam={setSearchParam} + data={[ + { label: '姝e父', value: 1 }, + { label: '绂佺敤', value: 0 }, + ]} + />, + }, + { + title: '娣诲姞鏃堕棿', + dataIndex: 'createTime$', + valueType: 'text', + hidden: false, + width: 140, + filterDropdown: (props) => <DatetimeRangeFilter + name='createTime' + {...props} + actionRef={actionRef} + setSearchParam={setSearchParam} + />, + }, + { + title: '娣诲姞浜哄憳', + dataIndex: 'createBy$', + valueType: 'text', + hidden: false, + width: 140, + filterDropdown: (props) => <LinkFilter + name='createBy' + major='user' + {...props} + actionRef={actionRef} + setSearchParam={setSearchParam} + />, + }, + { + title: '淇敼鏃堕棿', + dataIndex: 'updateTime$', + valueType: 'text', + hidden: false, + width: 140, + filterDropdown: (props) => <DatetimeRangeFilter + name='updateTime' + {...props} + actionRef={actionRef} + setSearchParam={setSearchParam} + />, + }, + { + title: '淇敼浜哄憳', + dataIndex: 'updateBy$', + valueType: 'text', + hidden: false, + width: 140, + filterDropdown: (props) => <LinkFilter + name='updateBy' + major='user' + {...props} + actionRef={actionRef} + setSearchParam={setSearchParam} + />, + }, + { + title: '澶囨敞', + dataIndex: 'memo', + valueType: 'text', + hidden: false, + width: 140, + filterDropdown: (props) => <TextFilter + name='memo' + {...props} + actionRef={actionRef} + setSearchParam={setSearchParam} + />, + }, + + { + title: '鎿嶄綔', + dataIndex: 'option', + width: 140, + valueType: 'option', + render: (_, record) => [ + <Button + type="link" + key="edit" + onClick={() => { + setModalVisible(true); + setCurrentRow(record); + }} + > + <FormattedMessage id='page.edit' defaultMessage='缂栬緫' /> + </Button>, + <Button + type="link" + danger + key="batchRemove" + onClick={async () => { + Modal.confirm({ + title: intl.formatMessage({ id: 'page.delete', defaultMessage: '鍒犻櫎' }), + content: intl.formatMessage({ id: 'page.delete.confirm', defaultMessage: '纭畾鍒犻櫎璇ラ」鍚楋紵' }), + onOk: async () => { + const success = await handleRemove([record], intl); + if (success) { + if (actionRef.current) { + actionRef.current.reload(); + } + } + }, + }); + }} + > + <FormattedMessage id='page.delete' defaultMessage='鍒犻櫎' /> + </Button>, + ], + }, + ]; + + return ( + <PageContainer + header={{ + breadcrumb: {}, + }} + > + <div style={{ width: '100%', float: 'right' }}> + <ProTable + key="deviceBarcode" + rowKey="id" + actionRef={actionRef} + formRef={formTableRef} + columns={columns} + cardBordered + scroll={{ x: 1300 }} + dateFormatter="string" + pagination={{ pageSize: 16 }} + search={false} + toolbar={{ + search: { + onSearch: (value) => { + setSearchParam(prevState => ({ + ...prevState, + condition: value + })); + actionRef.current?.reload(); + }, + }, + filter: ( + <LightFilter + onValuesChange={(val) => { + }} + > + </LightFilter> + ), + actions: [ + <Button + type="primary" + key="save" + onClick={async () => { + setModalVisible(true) + }} + > + <PlusOutlined /> + <FormattedMessage id='page.add' defaultMessage='娣诲姞' /> + </Button>, + <Button + key="export" + onClick={async () => { + handleExport(intl); + }} + > + <ExportOutlined /> + <FormattedMessage id='page.export' defaultMessage='瀵煎嚭' /> + </Button>, + ], + }} + request={(params, sorter, filter) => + Http.doPostPromise('/api/deviceBarcode/page', { ...params, ...searchParam }, (res) => { + return { + data: res.data.records, + total: res.data.total, + success: true, + } + }) + } + rowSelection={{ + onChange: (ids, rows) => { + setSelectedRows(rows); + } + }} + columnsState={{ + persistenceKey: TABLE_KEY, + persistenceType: 'localStorage', + defaultValue: { + // memo: { show: repairBug(TABLE_KEY, 'memo', false) }, + option: { fixed: 'right', disable: true }, + }, + onChange(value) { + }, + }} + /> + </div> + + {selectedRows?.length > 0 && ( + <FooterToolbar + extra={ + <div> + <a style={{ fontWeight: 600 }}>{selectedRows.length}</a> + <FormattedMessage id='page.selected' defaultMessage=' 椤瑰凡閫夋嫨' /> + </div> + } + > + <Button + key="remove" + danger + onClick={async () => { + Modal.confirm({ + title: intl.formatMessage({ id: 'page.delete', defaultMessage: '鍒犻櫎' }), + content: intl.formatMessage({ id: 'page.delete.confirm', defaultMessage: '纭畾鍒犻櫎璇ラ」鍚楋紵' }), + onOk: async () => { + const success = await handleRemove(selectedRows, intl); + if (success) { + setSelectedRows([]); + actionRef.current?.reloadAndRest?.(); + } + }, + }); + }} + > + <FormattedMessage id='page.delete.batch' defaultMessage='鎵归噺鍒犻櫎' /> + </Button> + </FooterToolbar> + )} + + <Edit + open={modalVisible} + values={currentRow || {}} + onCancel={ + () => { + setModalVisible(false); + setCurrentRow(undefined); + } + } + onSubmit={async (values) => { + let ok = false; + if (values.id) { + ok = await handleUpdate({ ...values }, intl) + } else { + ok = await handleSave({ ...values }, intl) + } + if (ok) { + setModalVisible(false); + setCurrentRow(undefined); + if (actionRef.current) { + actionRef.current.reload(); + } + } + }} + /> + </PageContainer> + ); +}; + +export default Main; diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/controller/DeviceBarcodeController.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/controller/DeviceBarcodeController.java new file mode 100644 index 0000000..4c1ae26 --- /dev/null +++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/controller/DeviceBarcodeController.java @@ -0,0 +1,102 @@ +package com.zy.asrs.wcs.core.controller; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.zy.asrs.framework.common.Cools; +import com.zy.asrs.framework.common.R; +import com.zy.asrs.wcs.common.annotation.OperationLog; +import com.zy.asrs.wcs.common.domain.BaseParam; +import com.zy.asrs.wcs.common.domain.KeyValVo; +import com.zy.asrs.wcs.common.domain.PageParam; +import com.zy.asrs.wcs.core.entity.DeviceBarcode; +import com.zy.asrs.wcs.core.service.DeviceBarcodeService; +import com.zy.asrs.wcs.system.controller.BaseController; +import com.zy.asrs.wcs.utils.ExcelUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletResponse; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +@RestController +@RequestMapping("/api") +public class DeviceBarcodeController extends BaseController { + + @Autowired + private DeviceBarcodeService deviceBarcodeService; + + @PreAuthorize("hasAuthority('core:deviceBarcode:list')") + @PostMapping("/deviceBarcode/page") + public R page(@RequestBody Map<String, Object> map) { + BaseParam baseParam = buildParam(map, BaseParam.class); + PageParam<DeviceBarcode, BaseParam> pageParam = new PageParam<>(baseParam, DeviceBarcode.class); + return R.ok().add(deviceBarcodeService.page(pageParam, pageParam.buildWrapper(true))); + } + + @PreAuthorize("hasAuthority('core:deviceBarcode:list')") + @PostMapping("/deviceBarcode/list") + public R list(@RequestBody Map<String, Object> map) { + return R.ok().add(deviceBarcodeService.list()); + } + + @PreAuthorize("hasAuthority('core:deviceBarcode:list')") + @GetMapping("/deviceBarcode/{id}") + public R get(@PathVariable("id") Long id) { + return R.ok().add(deviceBarcodeService.getById(id)); + } + + @PreAuthorize("hasAuthority('core:deviceBarcode:save')") + @OperationLog("娣诲姞鏉$爜璁惧") + @PostMapping("/deviceBarcode/save") + public R save(@RequestBody DeviceBarcode deviceBarcode) { + if (!deviceBarcodeService.save(deviceBarcode)) { + return R.error("娣诲姞澶辫触"); + } + return R.ok("娣诲姞鎴愬姛"); + } + + @PreAuthorize("hasAuthority('core:deviceBarcode:update')") + @OperationLog("淇敼鏉$爜璁惧") + @PostMapping("/deviceBarcode/update") + public R update(@RequestBody DeviceBarcode deviceBarcode) { + if (!deviceBarcodeService.updateById(deviceBarcode)) { + return R.error("淇敼澶辫触"); + } + return R.ok("淇敼鎴愬姛"); + } + + @PreAuthorize("hasAuthority('core:deviceBarcode:remove')") + @OperationLog("鍒犻櫎鏉$爜璁惧") + @PostMapping("/deviceBarcode/remove/{ids}") + public R remove(@PathVariable Long[] ids) { + if (!deviceBarcodeService.removeByIds(Arrays.asList(ids))) { + return R.error("鍒犻櫎澶辫触"); + } + return R.ok("鍒犻櫎鎴愬姛"); + } + + @PreAuthorize("hasAuthority('core:deviceBarcode:list')") + @PostMapping("/deviceBarcode/query") + public R query(@RequestParam(required = false) String condition) { + List<KeyValVo> vos = new ArrayList<>(); + LambdaQueryWrapper<DeviceBarcode> wrapper = new LambdaQueryWrapper<>(); + if (!Cools.isEmpty(condition)) { + wrapper.like(DeviceBarcode::getName, condition); + } + deviceBarcodeService.page(new Page<>(1, 30), wrapper).getRecords().forEach( + item -> vos.add(new KeyValVo(item.getId(), item.getName())) + ); + return R.ok().add(vos); + } + + @PreAuthorize("hasAuthority('core:deviceBarcode:list')") + @PostMapping("/deviceBarcode/export") + public void export(@RequestBody Map<String, Object> map, HttpServletResponse response) throws Exception { + ExcelUtil.build(ExcelUtil.create(deviceBarcodeService.list(), DeviceBarcode.class), response); + } + +} diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/entity/DeviceBarcode.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/entity/DeviceBarcode.java new file mode 100644 index 0000000..7876db3 --- /dev/null +++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/entity/DeviceBarcode.java @@ -0,0 +1,255 @@ +package com.zy.asrs.wcs.core.entity; + +import com.baomidou.mybatisplus.annotation.TableLogic; +import java.text.SimpleDateFormat; +import java.util.Date; + +import com.zy.asrs.wcs.rcs.entity.Device; +import com.zy.asrs.wcs.rcs.service.DeviceService; +import com.zy.asrs.wcs.system.entity.Host; +import com.zy.asrs.wcs.system.entity.User; +import org.springframework.format.annotation.DateTimeFormat; +import java.text.SimpleDateFormat; +import java.util.Date; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableLogic; +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import com.zy.asrs.framework.common.Cools; +import com.zy.asrs.framework.common.SpringUtils; +import com.zy.asrs.wcs.system.service.UserService; +import com.zy.asrs.wcs.system.service.HostService; + +import java.io.Serializable; +import java.util.Date; + +@Data +@TableName("wcs_device_barcode") +public class DeviceBarcode implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * ID + */ + @ApiModelProperty(value= "ID") + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + /** + * 缂栧彿 + */ + @ApiModelProperty(value= "缂栧彿") + private String uuid; + + /** + * 鍚嶇О + */ + @ApiModelProperty(value= "鍚嶇О") + private String name; + + /** + * 鏍囪瘑 + */ + @ApiModelProperty(value= "鏍囪瘑") + private String flag; + + /** + * 鏉$爜璁惧 + */ + @ApiModelProperty(value= "鏉$爜璁惧") + private String deviceId; + + /** + * 杩炴帴绫诲瀷 0: PLC 1: Socket 2: HTTP + */ + @ApiModelProperty(value= "杩炴帴绫诲瀷 0: PLC 1: Socket 2: HTTP ") + private Integer type; + + /** + * 杩炴帴鍙傛暟 + */ + @ApiModelProperty(value= "杩炴帴鍙傛暟") + private String connect; + + /** + * 鎵�灞炴満鏋� + */ + @ApiModelProperty(value= "鎵�灞炴満鏋�") + private Long hostId; + + /** + * 鐘舵�� 1: 姝e父 0: 绂佺敤 + */ + @ApiModelProperty(value= "鐘舵�� 1: 姝e父 0: 绂佺敤 ") + private Integer status; + + /** + * 鏄惁鍒犻櫎 1: 鏄� 0: 鍚� + */ + @ApiModelProperty(value= "鏄惁鍒犻櫎 1: 鏄� 0: 鍚� ") + @TableLogic + private Integer deleted; + + /** + * 娣诲姞鏃堕棿 + */ + @ApiModelProperty(value= "娣诲姞鏃堕棿") + @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") + private Date createTime; + + /** + * 娣诲姞浜哄憳 + */ + @ApiModelProperty(value= "娣诲姞浜哄憳") + private Long createBy; + + /** + * 淇敼鏃堕棿 + */ + @ApiModelProperty(value= "淇敼鏃堕棿") + @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") + private Date updateTime; + + /** + * 淇敼浜哄憳 + */ + @ApiModelProperty(value= "淇敼浜哄憳") + private Long updateBy; + + /** + * 澶囨敞 + */ + @ApiModelProperty(value= "澶囨敞") + private String memo; + + public DeviceBarcode() {} + + public DeviceBarcode(String uuid,String name,String flag,String deviceId,Integer type,String connect,Long hostId,Integer status,Integer deleted,Date createTime,Long createBy,Date updateTime,Long updateBy,String memo) { + this.uuid = uuid; + this.name = name; + this.flag = flag; + this.deviceId = deviceId; + this.type = type; + this.connect = connect; + this.hostId = hostId; + this.status = status; + this.deleted = deleted; + this.createTime = createTime; + this.createBy = createBy; + this.updateTime = updateTime; + this.updateBy = updateBy; + this.memo = memo; + } + +// DeviceBarcode deviceBarcode = new DeviceBarcode( +// null, // 缂栧彿 +// null, // 鍚嶇О +// null, // 鏍囪瘑 +// null, // 鏉$爜璁惧 +// null, // 杩炴帴绫诲瀷 +// null, // 杩炴帴鍙傛暟 +// null, // 鎵�灞炴満鏋� +// null, // 鐘舵�� +// null, // 鏄惁鍒犻櫎 +// null, // 娣诲姞鏃堕棿 +// null, // 娣诲姞浜哄憳 +// null, // 淇敼鏃堕棿 +// null, // 淇敼浜哄憳 +// null // 澶囨敞 +// ); + + public String getDeviceId$(){ + DeviceService service = SpringUtils.getBean(DeviceService.class); + Device device = service.getById(this.deviceId); + if (!Cools.isEmpty(device)){ + return String.valueOf(device.getDeviceNo()); + } + return null; + } + + public String getType$(){ + if (null == this.type){ return null; } + switch (this.type){ + case 0: + return "PLC"; + case 1: + return "Socket"; + case 2: + return "HTTP"; + default: + return String.valueOf(this.type); + } + } + + public String getHostId$(){ + HostService service = SpringUtils.getBean(HostService.class); + Host host = service.getById(this.hostId); + if (!Cools.isEmpty(host)){ + return String.valueOf(host.getName()); + } + return null; + } + + public String getStatus$(){ + if (null == this.status){ return null; } + switch (this.status){ + case 1: + return "姝e父"; + case 0: + return "绂佺敤"; + default: + return String.valueOf(this.status); + } + } + + public String getDeleted$(){ + if (null == this.deleted){ return null; } + switch (this.deleted){ + case 1: + return "鏄�"; + case 0: + return "鍚�"; + default: + return String.valueOf(this.deleted); + } + } + + public String getCreateTime$(){ + if (Cools.isEmpty(this.createTime)){ + return ""; + } + return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(this.createTime); + } + + public String getCreateBy$(){ + UserService service = SpringUtils.getBean(UserService.class); + User user = service.getById(this.createBy); + if (!Cools.isEmpty(user)){ + return String.valueOf(user.getNickname()); + } + return null; + } + + public String getUpdateTime$(){ + if (Cools.isEmpty(this.updateTime)){ + return ""; + } + return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(this.updateTime); + } + + public String getUpdateBy$(){ + UserService service = SpringUtils.getBean(UserService.class); + User user = service.getById(this.updateBy); + if (!Cools.isEmpty(user)){ + return String.valueOf(user.getNickname()); + } + return null; + } + + +} diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/mapper/DeviceBarcodeMapper.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/mapper/DeviceBarcodeMapper.java new file mode 100644 index 0000000..81070ae --- /dev/null +++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/mapper/DeviceBarcodeMapper.java @@ -0,0 +1,12 @@ +package com.zy.asrs.wcs.core.mapper; + +import com.zy.asrs.wcs.core.entity.DeviceBarcode; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; +import org.springframework.stereotype.Repository; + +@Mapper +@Repository +public interface DeviceBarcodeMapper extends BaseMapper<DeviceBarcode> { + +} diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/service/DeviceBarcodeService.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/service/DeviceBarcodeService.java new file mode 100644 index 0000000..7c13ec2 --- /dev/null +++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/service/DeviceBarcodeService.java @@ -0,0 +1,8 @@ +package com.zy.asrs.wcs.core.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.zy.asrs.wcs.core.entity.DeviceBarcode; + +public interface DeviceBarcodeService extends IService<DeviceBarcode> { + +} diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/service/impl/DeviceBarcodeServiceImpl.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/service/impl/DeviceBarcodeServiceImpl.java new file mode 100644 index 0000000..301bb93 --- /dev/null +++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/service/impl/DeviceBarcodeServiceImpl.java @@ -0,0 +1,12 @@ +package com.zy.asrs.wcs.core.service.impl; + +import com.zy.asrs.wcs.core.mapper.DeviceBarcodeMapper; +import com.zy.asrs.wcs.core.entity.DeviceBarcode; +import com.zy.asrs.wcs.core.service.DeviceBarcodeService; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +@Service("deviceBarcodeService") +public class DeviceBarcodeServiceImpl extends ServiceImpl<DeviceBarcodeMapper, DeviceBarcode> implements DeviceBarcodeService { + +} diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/BarcodeThread.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/BarcodeThread.java new file mode 100644 index 0000000..ef5606d --- /dev/null +++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/BarcodeThread.java @@ -0,0 +1,7 @@ +package com.zy.asrs.wcs.rcs.thread; + +public interface BarcodeThread extends ThreadHandler{ + + String getBarcode(); + +} diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/SiemensBarcodeThread.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/SiemensBarcodeThread.java new file mode 100644 index 0000000..9557786 --- /dev/null +++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/SiemensBarcodeThread.java @@ -0,0 +1,117 @@ +package com.zy.asrs.wcs.rcs.thread.impl; + +import HslCommunication.Core.Types.OperateResult; +import HslCommunication.Core.Types.OperateResultExOne; +import HslCommunication.Profinet.Siemens.SiemensPLCS; +import HslCommunication.Profinet.Siemens.SiemensS7Net; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.zy.asrs.framework.common.Cools; +import com.zy.asrs.framework.common.DateUtils; +import com.zy.asrs.framework.common.SpringUtils; +import com.zy.asrs.wcs.core.entity.DeviceBarcode; +import com.zy.asrs.wcs.core.service.DeviceBarcodeService; +import com.zy.asrs.wcs.core.utils.RedisUtil; +import com.zy.asrs.wcs.rcs.News; +import com.zy.asrs.wcs.rcs.cache.OutputQueue; +import com.zy.asrs.wcs.rcs.entity.Device; +import com.zy.asrs.wcs.rcs.thread.BarcodeThread; + +import java.text.MessageFormat; +import java.util.Date; + +public class SiemensBarcodeThread implements BarcodeThread { + + private Device device; + private RedisUtil redisUtil; + private SiemensS7Net siemensS7Net; + private StringBuffer barcode = new StringBuffer(); + private String lastBarcode; + + public SiemensBarcodeThread(Device device, RedisUtil redisUtil) { + this.device = device; + this.redisUtil = redisUtil; + } + + @Override + public String getBarcode() { + return String.valueOf(barcode); + } + + public void setBarcode(String barcode) { + this.lastBarcode = String.valueOf(this.barcode); + this.barcode.delete(0, this.barcode.length()); + this.barcode.append(barcode); + if(!Cools.isEmpty(barcode) && !this.lastBarcode.equals(barcode)) { + News.info("{}鍙锋潯鐮佸櫒锛屾绱㈡暟鎹細{}", device.getId(), this.barcode); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("time", DateUtils.convert(new Date(), DateUtils.yyyyMMddHHmmss_F)); + jsonObject.put("barcode", barcode); + if (OutputQueue.BARCODE.size() >= 32) { + OutputQueue.BARCODE.poll(); + } + OutputQueue.BARCODE.offer(jsonObject); + } + } + + @Override + public boolean connect() { + boolean result = false; + siemensS7Net = new SiemensS7Net(SiemensPLCS.S1200, device.getIp()); + siemensS7Net.setRack(device.getRack().byteValue()); + siemensS7Net.setSlot(device.getSlot().byteValue()); + OperateResult connect = siemensS7Net.ConnectServer(); + if(connect.IsSuccess){ + result = true; + OutputQueue.DEVP.offer(MessageFormat.format( "銆恵0}銆戞潯鐮佸櫒plc杩炴帴鎴愬姛 ===>> [id:{1}] [ip:{2}] [port:{3}] [rack:{4}] [slot:{5}]", DateUtils.convert(new Date()), device.getId(), device.getIp(), device.getPort(), device.getRack(), device.getSlot())); + News.info("鏉$爜鍣╬lc杩炴帴鎴愬姛 ===>> [id:{}] [ip:{}] [port:{}]", device.getId(), device.getIp(), device.getPort()); + } else { + OutputQueue.DEVP.offer(MessageFormat.format( "銆恵0}銆戞潯鐮佸櫒plc杩炴帴澶辫触锛侊紒锛� ===>> [id:{1}] [ip:{2}] [port:{3}] [rack:{4}] [slot:{5}]", DateUtils.convert(new Date()), device.getId(), device.getIp(), device.getPort(), device.getRack(), device.getSlot())); + News.error("鏉$爜鍣╬lc杩炴帴澶辫触锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}]", device.getId(), device.getIp(), device.getPort()); + } + // siemensS7Net.ConnectClose(); + return result; + } + + @Override + public void close() { + + } + + @Override + public void run() { + this.connect(); + while (true) { + try { + DeviceBarcodeService deviceBarcodeService = SpringUtils.getBean(DeviceBarcodeService.class); + if (deviceBarcodeService == null) { + continue; + } + + DeviceBarcode deviceBarcode = deviceBarcodeService.getOne(new LambdaQueryWrapper<DeviceBarcode>() + .eq(DeviceBarcode::getDeviceId, device.getId()) + .eq(DeviceBarcode::getHostId, device.getHostId()) + .eq(DeviceBarcode::getStatus, 1)); + if (deviceBarcode == null) { + continue; + } + + JSONObject connect = JSON.parseObject(deviceBarcode.getConnect()); + String address = connect.getString("address"); + Short length = connect.getShort("length"); + + // 鏉$爜鎵弿鍣� + OperateResultExOne<byte[]> result = null; + result = siemensS7Net.Read(address, length); + if (result.IsSuccess) { + String barcode = siemensS7Net.getByteTransform().TransString(result.Content, 0, length, "UTF-8"); + setBarcode(barcode); + } + } catch (Exception e) { +// e.printStackTrace(); + } + } + } + +} diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/SiemensDevpThread.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/SiemensDevpThread.java index eac27b4..f28644c 100644 --- a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/SiemensDevpThread.java +++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/SiemensDevpThread.java @@ -112,20 +112,6 @@ } } - // 鏉$爜鎵弿鍣� - Thread.sleep(200); - OperateResultExOne<byte[]> result2 = null; - result2 = siemensS7Net.Read("DB101.840.0", (short) (barcodeSize * 8)); - if (result2.IsSuccess) { - for (int i = 0; i < barcodeSize; i++) { - String barcode = siemensS7Net.getByteTransform().TransString(result2.Content, i * 8, 8, "UTF-8"); -// BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, i + 1); -// if (!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)) { -// barcodeThread.setBarcode(barcode); -// } - } - } - Thread.sleep(200); ArrayList<Station> errorStaNo = getStaNo(); OperateResultExOne<byte[]> result3 = siemensS7Net.Read("DB101.800.0", (short) (errorStaNo.size() * 4)); diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/utils/CodeBuilder.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/utils/CodeBuilder.java index 21e6d98..4d191e9 100644 --- a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/utils/CodeBuilder.java +++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/utils/CodeBuilder.java @@ -22,8 +22,8 @@ // generator.username="sa"; // generator.password="Zoneyung@zy56$"; - generator.table="wcs_station"; - generator.tableName="绔欑偣鍒楄〃"; + generator.table="wcs_device_barcode"; + generator.tableName="鏉$爜璁惧"; generator.packagePath="com.zy.asrs.wcs.core"; generator.build(); diff --git a/zy-asrs-wcs/src/main/resources/mapper/core/DeviceBarcodeMapper.xml b/zy-asrs-wcs/src/main/resources/mapper/core/DeviceBarcodeMapper.xml new file mode 100644 index 0000000..2e9ce62 --- /dev/null +++ b/zy-asrs-wcs/src/main/resources/mapper/core/DeviceBarcodeMapper.xml @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> +<mapper namespace="com.zy.asrs.wcs.core.mapper.DeviceBarcodeMapper"> + +</mapper> -- Gitblit v1.9.1