番外-Easyui批量添加

1、JS与HTML页面



    
    叶片管理
    
    
    
    
    
    
    


叶片组型号 叶片型号 序号 数量
 叶片组编号:  搜索
操作 Item ID 序号 数量 叶片型号 状态为P-才能添加
2、controller层
package com.mf.controller.bas;
import com.mf.entity.bas.BasYeGroup;
import com.mf.service.bas_service.BasYeService;
import com.mf.util.GetIp;
import com.mf.util.ResponseResult;
import com.mf.util.StringUtil;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/bas/ye")
public class BasYeController {

    @Autowired
    private BasYeService basYeService;

    @RequestMapping  ("/save")
    public ResponseResult yeAdd(HttpServletResponse response, HttpServletRequest request, String sper) throws Exception{
        String IP = GetIp.getip(request, response);
        //1、sper字符串接收数据
        System.out.println("数据"+sper);
        //2、首先把字符串转成 JSONArray 对象
        JSONArray backBodyJson = JSONArray.fromObject(sper);
        //3、遍历 jsonarray 数组,把每一个对象转成 json 对象
        BasYeGroup basYeGroup = new BasYeGroup();
        if (backBodyJson.size() > 0) {
            for (int i = 0; i < backBodyJson.size(); i++) {
                //4、开始拆分
                JSONObject job = backBodyJson.getJSONObject(i);
                //5、拿到叶片型号
                String productId=(String) job.get("productId");
                basYeGroup.setProductId(productId);
                //3-1、如果叶片型号为空,忽略不添加
                if(productId.equals("")){
                    continue;
                }
                //6、拿到序号
                Integer theOrder=Integer.parseInt((String) job.get("theOrder"));
                basYeGroup.setTheOrder(theOrder);
                //7、拿到数量
                Integer quantity=Integer.parseInt((String) job.get("quantity"));
                basYeGroup.setQuantity(quantity);
                //8、开始添加
                basYeService.addYe(basYeGroup,IP);
                System.out.println("所有数据:"+basYeGroup); // 得到 每个对象中的属性值
            }
        }
        return new ResponseResult(1,"添加成功!");
    }
 
}

3、Service
package com.mf.service.bas_service;

import com.mf.entity.bas.BasProduct;
import com.mf.entity.bas.BasYeGroup;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import java.util.List;

public interface BasYeService {

    /**
     * 添加叶片
     * @param basYeGroup
     * @param ip
     */
    void addYe(BasYeGroup basYeGroup, String ip);
}
4、serviceImpl实现类
package com.mf.service.bas_impl;

import com.mf.entity.SysUserLog;
import com.mf.entity.bas.BasYeGroup;
import com.mf.repository.bas.BasYeRepository;
import com.mf.service.SysLogService;
import com.mf.service.bas_service.BasYeService;
import com.mf.util.StringUtil;
import com.mf.util.UtilId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.domain.Sort.Order;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import javax.persistence.criteria.*;
import java.util.ArrayList;
import java.util.List;

@Service
public class BasYeServiceImpl implements BasYeService {

    @Autowired
    BasYeRepository basYeRepository;

    @Autowired
    SysLogService sysLogService;

    /**
     * 叶片添加
     * @param basYeGroup
     * @param ip
     */
    @Override
    public void addYe(BasYeGroup basYeGroup, String ip) {
        basYeGroup.setYeGroupGuid(UtilId.uuids());
        basYeRepository.save(basYeGroup);
        sysLogService.save(new SysUserLog(SysUserLog.ADD_ACTION,"添加物资信息:"+basYeGroup.getYeGroupId(),ip));

    }
}
5、dao层
package com.mf.repository.bas;

import com.mf.entity.bas.BasYeGroup;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface BasYeRepository extends JpaRepository, JpaSpecificationExecutor {
 
}

6、实体类
package com.mf.entity.bas;

import lombok.Data;
import org.springframework.data.domain.Sort;

import javax.persistence.*;
import java.io.Serializable;

/**
 * 叶片
 */
@Data
@Entity//实体
@Table(name = "bas_ye_group")
@NamedQuery(name = "BasYeGroup.findAll",query = "select b from BasYeGroup b")
public class BasYeGroup implements Serializable {

    @Id
    @Column(name = "ye_group_guid")
    public String  yeGroupGuid;

    @Column(name = "ye_group_id")
    public String  yeGroupId;

    @Column(name = "product_id")
    public String  productId;

    @Column(name = "the_order")
    public Integer  theOrder;

    @Column(name = "quantity")
    public Integer  quantity;

    public BasYeGroup(){}

    public String getYeGroupGuid() {
        return yeGroupGuid;
    }

    public void setYeGroupGuid(String yeGroupGuid) {
        this.yeGroupGuid = yeGroupGuid;
    }

    public String getYeGroupId() {
        return yeGroupId;
    }

    public void setYeGroupId(String yeGroupId) {
        this.yeGroupId = yeGroupId;
    }

    public String getProductId() {
        return productId;
    }

    public void setProductId(String productId) {
        this.productId = productId;
    }

    public Integer getTheOrder() {
        return theOrder;
    }

    public void setTheOrder(Integer theOrder) {
        this.theOrder = theOrder;
    }

    public Integer getQuantity() {
        return quantity;
    }

    public void setQuantity(Integer quantity) {
        this.quantity = quantity;
    }

    @Override
    public String toString() {
        return "BasYeGroup{" +
                "yeGroupGuid='" + yeGroupGuid + '\'' +
                ", yeGroupId='" + yeGroupId + '\'' +
                ", productId='" + productId + '\'' +
                ", theOrder=" + theOrder +
                ", quantity=" + quantity +
                '}';
    }
}

你可能感兴趣的:(番外-Easyui批量添加)