| New file |
| | |
| | | package com.zy.asrs.controller; |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.mapper.Wrapper; |
| | | import com.baomidou.mybatisplus.plugins.Page; |
| | | import com.core.common.DateUtils; |
| | | import com.zy.asrs.entity.LocDetlChangelog; |
| | | import com.zy.asrs.service.LocDetlChangelogService; |
| | | import com.core.annotations.ManagerAuth; |
| | | import com.core.common.BaseRes; |
| | | import com.core.common.Cools; |
| | | import com.core.common.R; |
| | | import com.zy.common.web.BaseController; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.*; |
| | | |
| | | @RestController |
| | | public class LocDetlChangelogController extends BaseController { |
| | | |
| | | @Autowired |
| | | private LocDetlChangelogService locDetlChangelogService; |
| | | |
| | | @RequestMapping(value = "/locDetlChangelog/{id}/auth") |
| | | @ManagerAuth |
| | | public R get(@PathVariable("id") String id) { |
| | | return R.ok(locDetlChangelogService.selectById(String.valueOf(id))); |
| | | } |
| | | |
| | | @RequestMapping(value = "/locDetlChangelog/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(required = false)String condition, |
| | | @RequestParam Map<String, Object> param){ |
| | | EntityWrapper<LocDetlChangelog> wrapper = new EntityWrapper<>(); |
| | | excludeTrash(param); |
| | | convert(param, wrapper); |
| | | allLike(LocDetlChangelog.class, param.keySet(), wrapper, condition); |
| | | if (!Cools.isEmpty(orderByField)){wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));} |
| | | return R.ok(locDetlChangelogService.selectPage(new Page<>(curr, limit), wrapper)); |
| | | } |
| | | |
| | | private <T> void convert(Map<String, Object> map, EntityWrapper<T> wrapper){ |
| | | for (Map.Entry<String, Object> entry : map.entrySet()){ |
| | | String val = String.valueOf(entry.getValue()); |
| | | 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])); |
| | | } else { |
| | | wrapper.like(entry.getKey(), val); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @RequestMapping(value = "/locDetlChangelog/add/auth") |
| | | @ManagerAuth |
| | | public R add(LocDetlChangelog locDetlChangelog) { |
| | | locDetlChangelogService.insert(locDetlChangelog); |
| | | return R.ok(); |
| | | } |
| | | |
| | | @RequestMapping(value = "/locDetlChangelog/update/auth") |
| | | @ManagerAuth |
| | | public R update(LocDetlChangelog locDetlChangelog){ |
| | | if (Cools.isEmpty(locDetlChangelog) || null==locDetlChangelog.getId()){ |
| | | return R.error(); |
| | | } |
| | | locDetlChangelogService.updateById(locDetlChangelog); |
| | | return R.ok(); |
| | | } |
| | | |
| | | @RequestMapping(value = "/locDetlChangelog/delete/auth") |
| | | @ManagerAuth |
| | | public R delete(@RequestParam(value="ids[]") Long[] ids){ |
| | | for (Long id : ids){ |
| | | locDetlChangelogService.deleteById(id); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | @RequestMapping(value = "/locDetlChangelog/export/auth") |
| | | @ManagerAuth |
| | | public R export(@RequestBody JSONObject param){ |
| | | EntityWrapper<LocDetlChangelog> wrapper = new EntityWrapper<>(); |
| | | List<String> fields = JSONObject.parseArray(param.getJSONArray("fields").toJSONString(), String.class); |
| | | Map<String, Object> map = excludeTrash(param.getJSONObject("locDetlChangelog")); |
| | | convert(map, wrapper); |
| | | List<LocDetlChangelog> list = locDetlChangelogService.selectList(wrapper); |
| | | return R.ok(exportSupport(list, fields)); |
| | | } |
| | | |
| | | @RequestMapping(value = "/locDetlChangelogQuery/auth") |
| | | @ManagerAuth |
| | | public R query(String condition) { |
| | | EntityWrapper<LocDetlChangelog> wrapper = new EntityWrapper<>(); |
| | | wrapper.like("id", condition); |
| | | Page<LocDetlChangelog> page = locDetlChangelogService.selectPage(new Page<>(0, 10), wrapper); |
| | | List<Map<String, Object>> result = new ArrayList<>(); |
| | | for (LocDetlChangelog locDetlChangelog : page.getRecords()){ |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("id", locDetlChangelog.getId()); |
| | | map.put("value", locDetlChangelog.getId()); |
| | | result.add(map); |
| | | } |
| | | return R.ok(result); |
| | | } |
| | | |
| | | @RequestMapping(value = "/locDetlChangelog/check/column/auth") |
| | | @ManagerAuth |
| | | public R query(@RequestBody JSONObject param) { |
| | | Wrapper<LocDetlChangelog> wrapper = new EntityWrapper<LocDetlChangelog>().eq(humpToLine(String.valueOf(param.get("key"))), param.get("val")); |
| | | if (null != locDetlChangelogService.selectOne(wrapper)){ |
| | | return R.parse(BaseRes.REPEAT).add(getComment(LocDetlChangelog.class, String.valueOf(param.get("key")))); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | } |
| New file |
| | |
| | | package com.zy.asrs.entity; |
| | | |
| | | import com.core.common.Cools;import com.baomidou.mybatisplus.annotations.TableId; |
| | | import com.baomidou.mybatisplus.enums.IdType; |
| | | import com.baomidou.mybatisplus.annotations.TableField; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | | import org.springframework.format.annotation.DateTimeFormat; |
| | | |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import lombok.Data; |
| | | import com.baomidou.mybatisplus.annotations.TableName; |
| | | import java.io.Serializable; |
| | | |
| | | @Data |
| | | @TableName("asr_loc_detl_changelog") |
| | | public class LocDetlChangelog implements Serializable { |
| | | |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | @ApiModelProperty(value= "") |
| | | @TableId(value = "id", type = IdType.AUTO) |
| | | private Integer id; |
| | | |
| | | @ApiModelProperty(value= "") |
| | | @TableField("action_type") |
| | | private String actionType; |
| | | |
| | | @ApiModelProperty(value= "") |
| | | @TableField("loc_no") |
| | | private String locNo; |
| | | |
| | | @ApiModelProperty(value= "") |
| | | private String zpallet; |
| | | |
| | | @ApiModelProperty(value= "") |
| | | private String matnr; |
| | | |
| | | @ApiModelProperty(value= "") |
| | | private String data; |
| | | |
| | | @ApiModelProperty(value= "") |
| | | @TableField("change_time") |
| | | @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") |
| | | private Date changeTime; |
| | | |
| | | @ApiModelProperty(value= "") |
| | | private Boolean processed; |
| | | |
| | | public LocDetlChangelog() {} |
| | | |
| | | public LocDetlChangelog(String actionType,String locNo,String zpallet,String matnr,String data,Date changeTime,Boolean processed) { |
| | | this.actionType = actionType; |
| | | this.locNo = locNo; |
| | | this.zpallet = zpallet; |
| | | this.matnr = matnr; |
| | | this.data = data; |
| | | this.changeTime = changeTime; |
| | | this.processed = processed; |
| | | } |
| | | |
| | | // LocDetlChangelog locDetlChangelog = new LocDetlChangelog( |
| | | // null, // |
| | | // null, // |
| | | // null, // |
| | | // null, // |
| | | // null, // |
| | | // null, // |
| | | // null // |
| | | // ); |
| | | |
| | | public String getChangeTime$(){ |
| | | if (Cools.isEmpty(this.changeTime)){ |
| | | return ""; |
| | | } |
| | | return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(this.changeTime); |
| | | } |
| | | |
| | | |
| | | } |
| New file |
| | |
| | | package com.zy.asrs.mapper; |
| | | |
| | | import com.zy.asrs.entity.LocDetlChangelog; |
| | | import com.baomidou.mybatisplus.mapper.BaseMapper; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | import org.springframework.stereotype.Repository; |
| | | |
| | | import java.util.List; |
| | | |
| | | @Mapper |
| | | @Repository |
| | | public interface LocDetlChangelogMapper extends BaseMapper<LocDetlChangelog> { |
| | | /** |
| | | * 查询未同步的日志 |
| | | */ |
| | | List<LocDetlChangelog> selectUnprocessedLogs(); |
| | | |
| | | /** |
| | | * 标记日志已处理 |
| | | */ |
| | | int markProcessed(Integer id); |
| | | } |
| New file |
| | |
| | | package com.zy.asrs.service; |
| | | |
| | | import com.zy.asrs.entity.LocDetlChangelog; |
| | | import com.baomidou.mybatisplus.service.IService; |
| | | |
| | | public interface LocDetlChangelogService extends IService<LocDetlChangelog> { |
| | | |
| | | } |
| New file |
| | |
| | | package com.zy.asrs.service.impl; |
| | | |
| | | import com.zy.asrs.mapper.LocDetlChangelogMapper; |
| | | import com.zy.asrs.entity.LocDetlChangelog; |
| | | import com.zy.asrs.service.LocDetlChangelogService; |
| | | import com.baomidou.mybatisplus.service.impl.ServiceImpl; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | @Service("locDetlChangelogService") |
| | | public class LocDetlChangelogServiceImpl extends ServiceImpl<LocDetlChangelogMapper, LocDetlChangelog> implements LocDetlChangelogService { |
| | | |
| | | } |
| | |
| | | // generator.table="sys_host"; |
| | | // sqlserver |
| | | generator.sqlOsType = SqlOsType.SQL_SERVER; |
| | | generator.url="192.168.4.15:1433;databasename=gdykasrs"; |
| | | generator.url="127.0.0.1:1433;databasename=tzglasrs"; |
| | | generator.username="sa"; |
| | | generator.password="sa@123"; |
| | | generator.table="man_auto_move"; |
| | | generator.table="asr_loc_detl_changelog"; |
| | | generator.packagePath="com.zy.asrs"; |
| | | generator.build(); |
| | | } |
| New file |
| | |
| | | package com.zy.third.erp.task; |
| | | |
| | | import com.zy.asrs.entity.LocDetl; |
| | | import com.zy.asrs.entity.LocDetlChangelog; |
| | | import com.zy.asrs.mapper.LocDetlChangelogMapper; |
| | | import com.zy.common.service.erp.ErpSqlServer; |
| | | import com.alibaba.fastjson.JSON; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.HashMap; |
| | | |
| | | @Slf4j |
| | | @Component |
| | | public class ERPLocDetlScheduler { |
| | | |
| | | @Autowired |
| | | private ErpSqlServer erpSqlServer; |
| | | |
| | | @Value("${erp.enabled}") |
| | | private Boolean erpEnabled; |
| | | |
| | | @Autowired |
| | | private LocDetlChangelogMapper locDetlChangelogMapper; |
| | | |
| | | @Transactional(rollbackFor = Throwable.class) |
| | | @Scheduled(cron = "${erp.refreshtime}") |
| | | public void LocDetlScheduler() { |
| | | if (!erpEnabled) return; |
| | | |
| | | List<LocDetlChangelog> logs = locDetlChangelogMapper.selectUnprocessedLogs(); |
| | | |
| | | for (LocDetlChangelog changelog : logs) { |
| | | try { |
| | | String action = changelog.getActionType(); |
| | | LocDetl item = parseJsonToItem(changelog.getData()); |
| | | Map<String, Object> content = locDetlToMap(item); |
| | | |
| | | switch (action) { |
| | | case "INSERT": |
| | | String insertSql = buildInsertSql("asr_loc_detl", content); |
| | | erpSqlServer.update(insertSql); |
| | | log.info("同步ERP新增成功: locNo={}", item.getLocNo()); |
| | | break; |
| | | |
| | | case "UPDATE": |
| | | try { |
| | | // 解析 JSON |
| | | Map<String, Object> dataMap = JSON.parseObject(changelog.getData(), Map.class); |
| | | Map<String, Object> afterMap = (Map<String, Object>) dataMap.get("after"); |
| | | |
| | | // 拼接 UPDATE SQL |
| | | StringBuilder setSql = new StringBuilder(); |
| | | afterMap.forEach((k, v) -> { |
| | | if (v == null) { |
| | | setSql.append("[").append(k).append("]=NULL,"); |
| | | } else if (v instanceof Number) { |
| | | setSql.append("[").append(k).append("]=").append(v).append(","); |
| | | } else { |
| | | setSql.append("[").append(k).append("]='").append(((String)v).replace("'", "''")).append("',"); |
| | | } |
| | | }); |
| | | setSql.deleteCharAt(setSql.length() - 1); // 去掉最后逗号 |
| | | |
| | | String updateSql = "UPDATE asr_loc_detl SET " + setSql + " WHERE loc_no='" + escapeSql((String)afterMap.get("loc_no")) + "' AND zpallet='" + escapeSql((String)afterMap.get("zpallet")) + "'"; |
| | | erpSqlServer.update(updateSql); |
| | | |
| | | log.info("同步ERP更新成功: locNo={}, zpallet={}", afterMap.get("loc_no"), afterMap.get("zpallet")); |
| | | } catch (Exception e) { |
| | | log.error("更新ERP失败: locNo=" + changelog.getLocNo(), e); |
| | | } |
| | | |
| | | case "DELETE": |
| | | String deleteSql = "DELETE FROM asr_loc_detl WHERE loc_no='" + escapeSql(item.getLocNo()) + "'"; |
| | | erpSqlServer.update(deleteSql); |
| | | log.info("同步ERP删除成功: locNo={}", item.getLocNo()); |
| | | break; |
| | | |
| | | default: |
| | | log.error("未知操作类型:" + action); |
| | | } |
| | | |
| | | locDetlChangelogMapper.markProcessed(changelog.getId()); |
| | | |
| | | } catch (Exception e) { |
| | | log.error("同步ERP失败,日志ID:" + changelog.getId(), e); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** JSON 转实体 */ |
| | | private LocDetl parseJsonToItem(String dataJson) { |
| | | return JSON.parseObject(dataJson, LocDetl.class); |
| | | } |
| | | |
| | | /** 实体转 Map */ |
| | | private Map<String, Object> locDetlToMap(LocDetl item) { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("loc_no", item.getLocNo()); |
| | | map.put("zpallet", item.getZpallet()); |
| | | map.put("anfme", item.getAnfme()); |
| | | map.put("matnr", item.getMatnr()); |
| | | map.put("maktx", item.getMaktx()); |
| | | map.put("batch", item.getBatch()); |
| | | map.put("order_no", item.getOrderNo()); |
| | | map.put("specs", item.getSpecs()); |
| | | map.put("model", item.getModel()); |
| | | map.put("color", item.getColor()); |
| | | map.put("brand", item.getBrand()); |
| | | map.put("unit", item.getUnit()); |
| | | map.put("price", item.getPrice()); |
| | | map.put("sku", item.getSku()); |
| | | map.put("units", item.getUnits()); |
| | | map.put("barcode", item.getBarcode()); |
| | | map.put("origin", item.getOrigin()); |
| | | map.put("manu", item.getManu()); |
| | | map.put("manu_date", item.getManuDate()); |
| | | map.put("item_num", item.getItemNum()); |
| | | map.put("safe_qty", item.getSafeQty()); |
| | | map.put("weight", item.getWeight()); |
| | | map.put("length", item.getLength()); |
| | | map.put("volume", item.getVolume()); |
| | | map.put("three_code", item.getThreeCode()); |
| | | map.put("supp", item.getSupp()); |
| | | map.put("supp_code", item.getSuppCode()); |
| | | map.put("be_batch", item.getBeBatch()); |
| | | map.put("dead_time", item.getDeadTime()); |
| | | map.put("dead_warn", item.getDeadWarn()); |
| | | map.put("source", item.getSource()); |
| | | map.put("inspect", item.getInspect()); |
| | | map.put("danger", item.getDanger()); |
| | | map.put("modi_user", item.getModiUser()); |
| | | map.put("modi_time", item.getModiTime()); |
| | | map.put("appe_user", item.getAppeUser()); |
| | | map.put("appe_time", item.getAppeTime()); |
| | | map.put("memo", item.getMemo()); |
| | | map.put("store_date", item.getStoreDate()); |
| | | map.put("out_order_no", item.getOutOrderNo()); |
| | | map.put("lu_hao", item.getLuHao()); |
| | | map.put("temp1", item.getTemp1()); |
| | | map.put("temp2", item.getTemp2()); |
| | | map.put("temp3", item.getTemp3()); |
| | | map.put("pro_type", item.getProType()); |
| | | map.put("packing", item.getPacking()); |
| | | map.put("ware_id", item.getWareId()); |
| | | map.put("ware_name", item.getWareName()); |
| | | map.put("i_no", item.getINo()); |
| | | return map; |
| | | } |
| | | |
| | | /** 拼接 INSERT SQL */ |
| | | private String buildInsertSql(String tableName, Map<String, Object> content) { |
| | | StringBuilder columns = new StringBuilder(); |
| | | StringBuilder values = new StringBuilder(); |
| | | content.forEach((k, v) -> { |
| | | columns.append(k).append(","); |
| | | values.append(toSqlValue(v)).append(","); |
| | | }); |
| | | columns.deleteCharAt(columns.length() - 1); |
| | | values.deleteCharAt(values.length() - 1); |
| | | return "INSERT INTO " + tableName + " (" + columns + ") VALUES (" + values + ")"; |
| | | } |
| | | |
| | | /** 拼接 UPDATE SQL */ |
| | | private String buildUpdateSql(String tableName, Map<String, Object> content, String whereClause) { |
| | | StringBuilder setSql = new StringBuilder(); |
| | | content.forEach((k, v) -> { |
| | | setSql.append(k).append("=").append(toSqlValue(v)).append(","); |
| | | }); |
| | | setSql.deleteCharAt(setSql.length() - 1); |
| | | return "UPDATE " + tableName + " SET " + setSql + " WHERE " + whereClause; |
| | | } |
| | | |
| | | /** 转换为 SQL 可用的值 */ |
| | | private String toSqlValue(Object value) { |
| | | if (value == null) return "NULL"; |
| | | if (value instanceof String) return "'" + escapeSql((String) value) + "'"; |
| | | if (value instanceof Date) return "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format((Date) value) + "'"; |
| | | return value.toString(); |
| | | } |
| | | |
| | | /** SQL 注入简单转义 */ |
| | | private String escapeSql(String str) { |
| | | if (str == null) return ""; |
| | | return str.replace("'", "''"); |
| | | } |
| | | } |
| New file |
| | |
| | | -- save locDetlChangelog record |
| | | -- mysql |
| | | insert into `sys_resource` ( `code`, `name`, `resource_id`, `level`, `sort`, `status`) values ( 'locDetlChangelog/locDetlChangelog.html', 'locDetlChangelog管理', null , '2', null , '1'); |
| | | |
| | | insert into `sys_resource` ( `code`, `name`, `resource_id`, `level`, `sort`, `status`) values ( 'locDetlChangelog#view', '查询', '', '3', '0', '1'); |
| | | insert into `sys_resource` ( `code`, `name`, `resource_id`, `level`, `sort`, `status`) values ( 'locDetlChangelog#btn-add', '新增', '', '3', '1', '1'); |
| | | insert into `sys_resource` ( `code`, `name`, `resource_id`, `level`, `sort`, `status`) values ( 'locDetlChangelog#btn-edit', '编辑', '', '3', '2', '1'); |
| | | insert into `sys_resource` ( `code`, `name`, `resource_id`, `level`, `sort`, `status`) values ( 'locDetlChangelog#btn-delete', '删除', '', '3', '3', '1'); |
| | | insert into `sys_resource` ( `code`, `name`, `resource_id`, `level`, `sort`, `status`) values ( 'locDetlChangelog#btn-export', '导出', '', '3', '4', '1'); |
| | | |
| | | -- sqlserver |
| | | insert [dbo].[sys_resource] ( [code], [name], [resource_id], [level], [sort], [status]) values ( N'locDetlChangelog/locDetlChangelog.html', N'locDetlChangelog管理', null, '2', null, '1'); |
| | | |
| | | insert [dbo].[sys_resource] ( [code], [name], [resource_id], [level], [sort], [status]) values ( N'locDetlChangelog#view', N'查询', '', '3', '0', '1'); |
| | | insert [dbo].[sys_resource] ( [code], [name], [resource_id], [level], [sort], [status]) values ( N'locDetlChangelog#btn-add', N'新增', '', '3', '1', '1'); |
| | | insert [dbo].[sys_resource] ( [code], [name], [resource_id], [level], [sort], [status]) values ( N'locDetlChangelog#btn-edit', N'编辑', '', '3', '2', '1'); |
| | | insert [dbo].[sys_resource] ( [code], [name], [resource_id], [level], [sort], [status]) values ( N'locDetlChangelog#btn-delete', N'删除', '', '3', '3', '1'); |
| | | insert [dbo].[sys_resource] ( [code], [name], [resource_id], [level], [sort], [status]) values ( N'locDetlChangelog#btn-export', N'导出', '', '3', '4', '1'); |
| New file |
| | |
| | | <?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.mapper.LocDetlChangelogMapper"> |
| | | |
| | | <!-- 通用查询映射结果 --> |
| | | <resultMap id="BaseResultMap" type="com.zy.asrs.entity.LocDetlChangelog"> |
| | | <id column="id" property="id" /> |
| | | <result column="action_type" property="actionType" /> |
| | | <result column="loc_no" property="locNo" /> |
| | | <result column="zpallet" property="zpallet" /> |
| | | <result column="matnr" property="matnr" /> |
| | | <result column="data" property="data" /> |
| | | <result column="change_time" property="changeTime" /> |
| | | <result column="processed" property="processed" /> |
| | | |
| | | </resultMap> |
| | | <select id="selectUnprocessedLogs" resultMap="BaseResultMap"> |
| | | SELECT * |
| | | FROM asr_loc_detl_changelog |
| | | WHERE processed = 0 |
| | | ORDER BY id |
| | | </select> |
| | | |
| | | <update id="markProcessed"> |
| | | UPDATE asr_loc_detl_changelog |
| | | SET processed = 1 |
| | | WHERE id = #{id} |
| | | </update> |
| | | |
| | | </mapper> |
| New file |
| | |
| | | var pageCurr; |
| | | layui.config({ |
| | | base: baseUrl + "/static/layui/lay/modules/" |
| | | }).use(['table','laydate', 'form', 'admin'], function(){ |
| | | var table = layui.table; |
| | | var $ = layui.jquery; |
| | | var layer = layui.layer; |
| | | var layDate = layui.laydate; |
| | | var form = layui.form; |
| | | var admin = layui.admin; |
| | | |
| | | // 数据渲染 |
| | | tableIns = table.render({ |
| | | elem: '#locDetlChangelog', |
| | | headers: {token: localStorage.getItem('token')}, |
| | | url: baseUrl+'/locDetlChangelog/list/auth', |
| | | page: true, |
| | | limit: 15, |
| | | limits: [15, 30, 50, 100, 200, 500], |
| | | toolbar: '#toolbar', |
| | | cellMinWidth: 50, |
| | | height: 'full-120', |
| | | cols: [[ |
| | | {type: 'checkbox'} |
| | | ,{field: 'id', align: 'center',title: ''} |
| | | ,{field: 'actionType', align: 'center',title: ''} |
| | | ,{field: 'locNo', align: 'center',title: ''} |
| | | ,{field: 'zpallet', align: 'center',title: ''} |
| | | ,{field: 'matnr', align: 'center',title: ''} |
| | | ,{field: 'data', align: 'center',title: ''} |
| | | ,{field: 'changeTime$', align: 'center',title: ''} |
| | | ,{field: 'processed', align: 'center',title: ''} |
| | | |
| | | ,{fixed: 'right', title:'操作', align: 'center', toolbar: '#operate', width:120} |
| | | ]], |
| | | request: { |
| | | pageName: 'curr', |
| | | pageSize: 'limit' |
| | | }, |
| | | parseData: function (res) { |
| | | return { |
| | | 'code': res.code, |
| | | 'msg': res.msg, |
| | | 'count': res.data.total, |
| | | 'data': res.data.records |
| | | } |
| | | }, |
| | | response: { |
| | | statusCode: 200 |
| | | }, |
| | | done: function(res, curr, count) { |
| | | if (res.code === 403) { |
| | | top.location.href = baseUrl+"/"; |
| | | } |
| | | pageCurr=curr; |
| | | limit(); |
| | | } |
| | | }); |
| | | |
| | | // 监听排序事件 |
| | | table.on('sort(locDetlChangelog)', function (obj) { |
| | | var searchData = {}; |
| | | $.each($('#search-box [name]').serializeArray(), function() { |
| | | searchData[this.name] = this.value; |
| | | }); |
| | | searchData['orderByField'] = obj.field; |
| | | searchData['orderByType'] = obj.type; |
| | | tableIns.reload({ |
| | | where: searchData, |
| | | page: {curr: 1} |
| | | }); |
| | | }); |
| | | |
| | | // 监听头工具栏事件 |
| | | table.on('toolbar(locDetlChangelog)', function (obj) { |
| | | var checkStatus = table.checkStatus(obj.config.id).data; |
| | | switch(obj.event) { |
| | | case 'addData': |
| | | showEditModel(); |
| | | break; |
| | | case 'deleteData': |
| | | if (checkStatus.length === 0) { |
| | | layer.msg('请选择要删除的数据', {icon: 2}); |
| | | return; |
| | | } |
| | | del(checkStatus.map(function (d) { |
| | | return d.id; |
| | | })); |
| | | break; |
| | | case 'exportData': |
| | | admin.confirm('确定导出Excel吗', {shadeClose: true}, function(){ |
| | | var titles=[]; |
| | | var fields=[]; |
| | | obj.config.cols[0].map(function (col) { |
| | | if (col.type === 'normal' && col.hide === false && col.toolbar == null) { |
| | | titles.push(col.title); |
| | | fields.push(col.field); |
| | | } |
| | | }); |
| | | var exportData = {}; |
| | | $.each($('#search-box [name]').serializeArray(), function() { |
| | | exportData[this.name] = this.value; |
| | | }); |
| | | var param = { |
| | | 'locDetlChangelog': exportData, |
| | | 'fields': fields |
| | | }; |
| | | $.ajax({ |
| | | url: baseUrl+"/locDetlChangelog/export/auth", |
| | | headers: {'token': localStorage.getItem('token')}, |
| | | data: JSON.stringify(param), |
| | | dataType:'json', |
| | | contentType:'application/json;charset=UTF-8', |
| | | method: 'POST', |
| | | success: function (res) { |
| | | layer.closeAll(); |
| | | if (res.code === 200) { |
| | | table.exportFile(titles,res.data,'xls'); |
| | | } else if (res.code === 403) { |
| | | top.location.href = baseUrl+"/"; |
| | | } else { |
| | | layer.msg(res.msg, {icon: 2}) |
| | | } |
| | | } |
| | | }); |
| | | }); |
| | | break; |
| | | } |
| | | }); |
| | | |
| | | // 监听行工具事件 |
| | | table.on('tool(locDetlChangelog)', function(obj){ |
| | | var data = obj.data; |
| | | switch (obj.event) { |
| | | case 'edit': |
| | | showEditModel(data); |
| | | break; |
| | | case "del": |
| | | del([data.id]); |
| | | break; |
| | | } |
| | | }); |
| | | |
| | | /* 弹窗 - 新增、修改 */ |
| | | function showEditModel(mData) { |
| | | admin.open({ |
| | | type: 1, |
| | | area: '600px', |
| | | title: (mData ? '修改' : '添加') + '订单状态', |
| | | content: $('#editDialog').html(), |
| | | success: function (layero, dIndex) { |
| | | layDateRender(mData); |
| | | form.val('detail', mData); |
| | | form.on('submit(editSubmit)', function (data) { |
| | | var loadIndex = layer.load(2); |
| | | $.ajax({ |
| | | url: baseUrl+"/locDetlChangelog/"+(mData?'update':'add')+"/auth", |
| | | headers: {'token': localStorage.getItem('token')}, |
| | | data: data.field, |
| | | method: 'POST', |
| | | success: function (res) { |
| | | layer.close(loadIndex); |
| | | if (res.code === 200){ |
| | | layer.close(dIndex); |
| | | layer.msg(res.msg, {icon: 1}); |
| | | tableReload(); |
| | | } else if (res.code === 403){ |
| | | top.location.href = baseUrl+"/"; |
| | | }else { |
| | | layer.msg(res.msg, {icon: 2}); |
| | | } |
| | | } |
| | | }) |
| | | return false; |
| | | }); |
| | | $(layero).children('.layui-layer-content').css('overflow', 'visible'); |
| | | layui.form.render('select'); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /* 删除 */ |
| | | function del(ids) { |
| | | layer.confirm('确定要删除选中数据吗?', { |
| | | skin: 'layui-layer-admin', |
| | | shade: .1 |
| | | }, function (i) { |
| | | layer.close(i); |
| | | var loadIndex = layer.load(2); |
| | | $.ajax({ |
| | | url: baseUrl+"/locDetlChangelog/delete/auth", |
| | | headers: {'token': localStorage.getItem('token')}, |
| | | data: {ids: ids}, |
| | | method: 'POST', |
| | | success: function (res) { |
| | | layer.close(loadIndex); |
| | | if (res.code === 200){ |
| | | layer.msg(res.msg, {icon: 1}); |
| | | tableReload(); |
| | | } else if (res.code === 403){ |
| | | top.location.href = baseUrl+"/"; |
| | | } else { |
| | | layer.msg(res.msg, {icon: 2}); |
| | | } |
| | | } |
| | | }) |
| | | }); |
| | | } |
| | | |
| | | // 搜索 |
| | | form.on('submit(search)', function (data) { |
| | | pageCurr = 1; |
| | | tableReload(false); |
| | | }); |
| | | |
| | | // 重置 |
| | | form.on('submit(reset)', function (data) { |
| | | pageCurr = 1; |
| | | clearFormVal($('#search-box')); |
| | | tableReload(false); |
| | | }); |
| | | |
| | | // 时间选择器 |
| | | function layDateRender(data) { |
| | | setTimeout(function () { |
| | | layDate.render({ |
| | | elem: '.layui-laydate-range' |
| | | ,type: 'datetime' |
| | | ,range: true |
| | | }); |
| | | layDate.render({ |
| | | elem: '#changeTime\\$', |
| | | type: 'datetime', |
| | | value: data!==undefined?data['changeTime\\$']:null |
| | | }); |
| | | |
| | | }, 300); |
| | | } |
| | | layDateRender(); |
| | | |
| | | }); |
| | | |
| | | // 关闭动作 |
| | | $(document).on('click','#data-detail-close', function () { |
| | | parent.layer.closeAll(); |
| | | }); |
| | | |
| | | function tableReload(child) { |
| | | var searchData = {}; |
| | | $.each($('#search-box [name]').serializeArray(), function() { |
| | | searchData[this.name] = this.value; |
| | | }); |
| | | tableIns.reload({ |
| | | where: searchData, |
| | | page: {curr: pageCurr} |
| | | }); |
| | | } |
| New file |
| | |
| | | <!DOCTYPE html> |
| | | <html lang="en"> |
| | | <head> |
| | | <meta charset="utf-8"> |
| | | <title></title> |
| | | <meta name="renderer" content="webkit"> |
| | | <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> |
| | | <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> |
| | | <link rel="stylesheet" href="../../static/layui/css/layui.css" media="all"> |
| | | <link rel="stylesheet" href="../../static/css/admin.css?v=318" media="all"> |
| | | <link rel="stylesheet" href="../../static/css/cool.css" media="all"> |
| | | </head> |
| | | <body> |
| | | |
| | | <div class="layui-fluid"> |
| | | <div class="layui-card"> |
| | | <div class="layui-card-body"> |
| | | <div class="layui-form toolbar" id="search-box"> |
| | | <div class="layui-form-item"> |
| | | <div class="layui-inline"> |
| | | <div class="layui-input-inline"> |
| | | <input class="layui-input" type="text" name="id" placeholder="编号" autocomplete="off"> |
| | | </div> |
| | | </div> |
| | | <div class="layui-inline" style="width: 300px"> |
| | | <div class="layui-input-inline"> |
| | | <input class="layui-input layui-laydate-range" name="create_time" type="text" placeholder="起始时间 - 终止时间" autocomplete="off" style="width: 300px"> |
| | | </div> |
| | | </div> |
| | | <div class="layui-inline"> |
| | | <div class="layui-input-inline"> |
| | | <input class="layui-input" type="text" name="condition" placeholder="请输入" autocomplete="off"> |
| | | </div> |
| | | </div> |
| | | <div class="layui-inline">  |
| | | <button class="layui-btn icon-btn" lay-filter="search" lay-submit> |
| | | <i class="layui-icon"></i>搜索 |
| | | </button> |
| | | <button class="layui-btn icon-btn" lay-filter="reset" lay-submit> |
| | | <i class="layui-icon"></i>重置 |
| | | </button> |
| | | </div> |
| | | </div> |
| | | </div> |
| | | <table class="layui-hide" id="locDetlChangelog" lay-filter="locDetlChangelog"></table> |
| | | </div> |
| | | </div> |
| | | </div> |
| | | |
| | | <script type="text/html" id="toolbar"> |
| | | <div class="layui-btn-container"> |
| | | <button class="layui-btn layui-btn-sm" id="btn-add" lay-event="addData">新增</button> |
| | | <button class="layui-btn layui-btn-sm layui-btn-danger" id="btn-delete" lay-event="deleteData">删除</button> |
| | | <button class="layui-btn layui-btn-primary layui-btn-sm" id="btn-export" lay-event="exportData" style="float: right">导出</button> |
| | | </div> |
| | | </script> |
| | | |
| | | <script type="text/html" id="operate"> |
| | | <a class="layui-btn layui-btn-primary layui-btn-xs btn-edit" lay-event="edit">修改</a> |
| | | <a class="layui-btn layui-btn-danger layui-btn-xs btn-edit" lay-event="del">删除</a> |
| | | </script> |
| | | |
| | | <script type="text/javascript" src="../../static/js/jquery/jquery-3.3.1.min.js"></script> |
| | | <script type="text/javascript" src="../../static/layui/layui.js" charset="utf-8"></script> |
| | | <script type="text/javascript" src="../../static/js/common.js" charset="utf-8"></script> |
| | | <script type="text/javascript" src="../../static/js/cool.js" charset="utf-8"></script> |
| | | <script type="text/javascript" src="../../static/js/locDetlChangelog/locDetlChangelog.js" charset="utf-8"></script> |
| | | </body> |
| | | <!-- 表单弹窗 --> |
| | | <script type="text/html" id="editDialog"> |
| | | <form id="detail" lay-filter="detail" class="layui-form admin-form model-form"> |
| | | <input name="id" type="hidden"> |
| | | <div class="layui-row"> |
| | | <div class="layui-col-md12"> |
| | | <div class="layui-form-item"> |
| | | <label class="layui-form-label">: </label> |
| | | <div class="layui-input-block"> |
| | | <input class="layui-input" name="actionType" placeholder="请输入"> |
| | | </div> |
| | | </div> |
| | | <div class="layui-form-item"> |
| | | <label class="layui-form-label">: </label> |
| | | <div class="layui-input-block"> |
| | | <input class="layui-input" name="locNo" placeholder="请输入"> |
| | | </div> |
| | | </div> |
| | | <div class="layui-form-item"> |
| | | <label class="layui-form-label">: </label> |
| | | <div class="layui-input-block"> |
| | | <input class="layui-input" name="zpallet" placeholder="请输入"> |
| | | </div> |
| | | </div> |
| | | <div class="layui-form-item"> |
| | | <label class="layui-form-label">: </label> |
| | | <div class="layui-input-block"> |
| | | <input class="layui-input" name="matnr" placeholder="请输入"> |
| | | </div> |
| | | </div> |
| | | <div class="layui-form-item"> |
| | | <label class="layui-form-label">: </label> |
| | | <div class="layui-input-block"> |
| | | <input class="layui-input" name="data" placeholder="请输入"> |
| | | </div> |
| | | </div> |
| | | <div class="layui-form-item"> |
| | | <label class="layui-form-label">: </label> |
| | | <div class="layui-input-block"> |
| | | <input class="layui-input" name="changeTime" id="changeTime$" placeholder="请输入"> |
| | | </div> |
| | | </div> |
| | | <div class="layui-form-item"> |
| | | <label class="layui-form-label">: </label> |
| | | <div class="layui-input-block"> |
| | | <input class="layui-input" name="processed" placeholder="请输入"> |
| | | </div> |
| | | </div> |
| | | |
| | | </div> |
| | | </div> |
| | | <hr class="layui-bg-gray"> |
| | | <div class="layui-form-item text-right"> |
| | | <button class="layui-btn" lay-filter="editSubmit" lay-submit="">保存</button> |
| | | <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button> |
| | | </div> |
| | | </form> |
| | | </script> |
| | | </html> |
| | | |