李宇
2020-12-22 0ece929cad95dbe0bb4c8be5e03ddccacec5a935
修改危化品编码
已修改7个文件
271 ■■■■■ 文件已修改
src/main/java/com/nanometer/smartlab/controller/DangerousEncodeController.java 79 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/nanometer/smartlab/dao/DangerousEncodeMapper.java 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/nanometer/smartlab/dao/DangerousEncodeMapper.xml 89 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/nanometer/smartlab/entity/DangerousEncode.java 15 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/nanometer/smartlab/service/DangerousEncodeService.java 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/nanometer/smartlab/service/DangerousEncodeServiceImpl.java 74 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/sys_dangerous_encode.xhtml 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/nanometer/smartlab/controller/DangerousEncodeController.java
@@ -4,6 +4,7 @@
import com.nanometer.smartlab.service.DangerousEncodeService;
import com.nanometer.smartlab.util.FacesUtils;
import com.nanometer.smartlab.util.IDUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.primefaces.context.RequestContext;
import org.primefaces.event.FileUploadEvent;
@@ -68,7 +69,7 @@
                    DangerousEncode su = null;
                    while (iterator.hasNext()) {
                        su = iterator.next();
                        if (rowKey.equals(su.getId())) {
                        if (Long.parseLong(rowKey) == (su.getId())) {
                            return su;
                        }
                    }
@@ -85,25 +86,83 @@
    //保存
    public void onSaveBtnClick(){
        try {
            String retmsg = "";
            //插入
            if (dangerousEncode.getId() == null) {
                //设置 id,创建者和更新时间
                dangerousEncode.setId(IDUtils.uuid());
                dangerousEncode.setCreator(getUser().getId());
                dangerousEncode.setUpdateTime(new Date());
                if (StringUtils.isBlank(dangerousEncode.getReagentCode())){
                    retmsg +=("试剂名称码不能为空");
                }else {
                    List<DangerousEncode> list1 = dangerousEncodeService.selectByCodeAndName(dangerousEncode.getReagentCode(),null,null,null);
                    if (list1.size() > 0){
                        retmsg +=("试剂名称码已存在,请更换");
                    }
                }
                if (StringUtils.isBlank(dangerousEncode.getReagentName())){
                    retmsg +=("试剂名称不能为空");
                }else {
                    List<DangerousEncode> list1 = dangerousEncodeService.selectByCodeAndName(null,dangerousEncode.getReagentName(),null,null);
                    if (list1.size() > 0){
                        retmsg +=("试剂名称已存在,请更换");
                    }
                }
                if (StringUtils.isBlank(dangerousEncode.getCode())){
                    retmsg +=("编码不能为空");
                }else {
                    List<DangerousEncode> list1 = dangerousEncodeService.selectByCodeAndName(null,null,null,dangerousEncode.getCode());
                    if (list1.size() > 0){
                        retmsg +=("编码已存在,请更换");
                    }
                }
                //插入
                dangerousEncodeService.insertOne(dangerousEncode);
                if (StringUtils.isBlank(retmsg)) {
                    dangerousEncodeService.insertOne(dangerousEncode);
                }
            }
            //更新
            else{
                dangerousEncode.setUpdateTime(new Date());
                dangerousEncodeService.updateOne(dangerousEncode);
                if (StringUtils.isBlank(dangerousEncode.getReagentCode())){
                    retmsg +=("试剂名称码不能为空");
                }else {
                    List<DangerousEncode> list1 = dangerousEncodeService.selectByCodeAndName(dangerousEncode.getReagentCode(),null,null,null);
                    if (list1.size() > 0 && !list1.get(0).getId().equals(dangerousEncode.getId())){
                        retmsg +=("试剂名称码已存在,请更换");
                    }
                }
                if (StringUtils.isBlank(dangerousEncode.getReagentName())){
                    retmsg +=("试剂名称不能为空");
                }else {
                    List<DangerousEncode> list1 = dangerousEncodeService.selectByCodeAndName(null,dangerousEncode.getReagentName(),null,null);
                    if (list1.size() > 0 && !list1.get(0).getId().equals(dangerousEncode.getId())){
                        retmsg +=("试剂名称已存在,请更换");
                    }
                }
                if (StringUtils.isBlank(dangerousEncode.getCode())){
                    retmsg +=("编码不能为空");
                }else {
                    List<DangerousEncode> list1 = dangerousEncodeService.selectByCodeAndName(null,null,null,dangerousEncode.getCode());
                    if (list1.size() > 0 && !list1.get(0).getId().equals(dangerousEncode.getId())){
                        retmsg += "编码已存在,请更换";
                    }
                }
                if (StringUtils.isBlank(retmsg)) {
                    dangerousEncode.setUpdateTime(new Date());
                    dangerousEncodeService.updateOne(dangerousEncode);
                }
            }
            FacesUtils.info("操作成功");
            RequestContext.getCurrentInstance().execute("PF('dialog').hide()");
            if (StringUtils.isNotBlank(retmsg)){
                FacesUtils.error(retmsg);
            }else {
                RequestContext.getCurrentInstance().execute("PF('dialog').hide()");
                FacesUtils.info("操作成功");
            }
        }catch (Exception e){
            e.printStackTrace();
            FacesUtils.warn("操作失败");
src/main/java/com/nanometer/smartlab/dao/DangerousEncodeMapper.java
@@ -1,12 +1,13 @@
package com.nanometer.smartlab.dao;
import com.nanometer.smartlab.entity.DangerousEncode;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
public interface DangerousEncodeMapper {
    int deleteByPrimaryKey(String id);
    int deleteByPrimaryKey(Long id);
    int insert(DangerousEncode record);
@@ -23,4 +24,6 @@
    int countAll(Map params);
    List<Map> selectExportList(Map params);
}
    List<DangerousEncode> selectByCodeAndName(@Param("reagentcode") String reagentcode,@Param("reagentname") String reagentname,@Param("cas") String cas,@Param("code") String code);
}
src/main/java/com/nanometer/smartlab/dao/DangerousEncodeMapper.xml
@@ -4,7 +4,7 @@
  <resultMap id="BaseResultMap" type="com.nanometer.smartlab.entity.DangerousEncode">
    <!--          -->
    <id column="id" jdbcType="VARCHAR" property="id" />
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="container_number" jdbcType="VARCHAR" property="containerNumber" />
    <result column="reagent_code" jdbcType="VARCHAR" property="reagentCode" />
    <result column="reagent_name" jdbcType="VARCHAR" property="reagentName" />
@@ -23,34 +23,34 @@
  </resultMap>
  <sql id="Base_Column_List">
    <!--          -->
    id, container_number, reagent_code, reagent_name, cas, memo, property, feature, avoid,
    id, container_number, reagent_code, reagent_name, cas, memo, property, feature, avoid,
    status, fire, random, code, update_time, creator, count
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
    <!--          -->
    select
    select
    <include refid="Base_Column_List" />
    from sys_dangerous_encode
    where id = #{id,jdbcType=VARCHAR}
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    <!--          -->
    delete from sys_dangerous_encode
    where id = #{id,jdbcType=VARCHAR}
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <insert id="insert" parameterType="com.nanometer.smartlab.entity.DangerousEncode">
    <!--          -->
    insert into sys_dangerous_encode (id, container_number, reagent_code,
      reagent_name, cas, memo,
      property, feature, avoid,
      status, fire, random,
      code, update_time, creator,
    insert into sys_dangerous_encode (id, container_number, reagent_code,
      reagent_name, cas, memo,
      property, feature, avoid,
      status, fire, random,
      code, update_time, creator,
      count)
    values (#{id,jdbcType=VARCHAR}, #{containerNumber,jdbcType=VARCHAR}, #{reagentCode,jdbcType=VARCHAR},
      #{reagentName,jdbcType=VARCHAR}, #{cas,jdbcType=VARCHAR}, #{memo,jdbcType=VARCHAR},
      #{property,jdbcType=VARCHAR}, #{feature,jdbcType=VARCHAR}, #{avoid,jdbcType=VARCHAR},
      #{status,jdbcType=VARCHAR}, #{fire,jdbcType=VARCHAR}, #{random,jdbcType=VARCHAR},
      #{code,jdbcType=VARCHAR}, #{updateTime,jdbcType=TIMESTAMP}, #{creator,jdbcType=VARCHAR},
    values (#{id,jdbcType=BIGINT}, #{containerNumber,jdbcType=VARCHAR}, #{reagentCode,jdbcType=VARCHAR},
      #{reagentName,jdbcType=VARCHAR}, #{cas,jdbcType=VARCHAR}, #{memo,jdbcType=VARCHAR},
      #{property,jdbcType=VARCHAR}, #{feature,jdbcType=VARCHAR}, #{avoid,jdbcType=VARCHAR},
      #{status,jdbcType=VARCHAR}, #{fire,jdbcType=VARCHAR}, #{random,jdbcType=VARCHAR},
      #{code,jdbcType=VARCHAR}, #{updateTime,jdbcType=TIMESTAMP}, #{creator,jdbcType=VARCHAR},
      #{count,jdbcType=INTEGER})
  </insert>
  <insert id="insertSelective" parameterType="com.nanometer.smartlab.entity.DangerousEncode">
@@ -108,7 +108,7 @@
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=VARCHAR},
        #{id,jdbcType=BIGINT},
      </if>
      <if test="containerNumber != null">
        #{containerNumber,jdbcType=VARCHAR},
@@ -207,7 +207,7 @@
        count = #{count,jdbcType=INTEGER},
      </if>
    </set>
    where id = #{id,jdbcType=VARCHAR}
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.nanometer.smartlab.entity.DangerousEncode">
    <!--          -->
@@ -227,7 +227,7 @@
      update_time = #{updateTime,jdbcType=TIMESTAMP},
      creator = #{creator,jdbcType=VARCHAR},
      count = #{count,jdbcType=INTEGER}
    where id = #{id,jdbcType=VARCHAR}
    where id = #{id,jdbcType=BIGINT}
  </update>
  <select id="selectAll" parameterType="java.util.Map" resultMap="BaseResultMap">
@@ -235,20 +235,21 @@
    <include refid="Base_Column_List" />
    from sys_dangerous_encode
    <where>
        1=1
      <if test="reagentName !=null and reagentName != ''">
        reagent_name like concat("%",#{reagentName},"%")
        and reagent_name like concat("%",#{reagentName},"%")
      </if>
      <if test="cas !=null and cas != ''">
        cas like concat("%",#{cas},"%")
        and cas like concat("%",#{cas},"%")
      </if>
      <if test="reagentCode!=null and reagentCode != ''">
        reagent_code like concat("%",#{reagentCode},"%")
        and reagent_code like concat("%",#{reagentCode},"%")
      </if>
      <if test="containerNumber !=null and containerNumber != ''">
        container_number like concat("%",#{containerNumber},"%")
        and container_number like concat("%",#{containerNumber},"%")
      </if>
    </where>
    order by update_time
    order by update_time desc
    <if test="offset !=null and pageSize != null">
      limit #{offset},#{pageSize}
    </if>
@@ -258,17 +259,18 @@
    select count(1)
    from sys_dangerous_encode
    <where>
        1=1
      <if test="reagentName !=null and reagentName != ''">
        reagent_name like concat("%",#{reagentName},"%")
        and reagent_name like concat("%",#{reagentName},"%")
      </if>
      <if test="cas !=null and cas != ''">
        cas like concat("%",#{cas},"%")
        and cas like concat("%",#{cas},"%")
      </if>
      <if test="reagentCode!=null and reagentCode != ''">
        reagent_code like concat("%",#{reagentCode},"%")
        and reagent_code like concat("%",#{reagentCode},"%")
      </if>
      <if test="containerNumber !=null and containerNumber != ''">
        container_number like concat("%",#{containerNumber},"%")
        and container_number like concat("%",#{containerNumber},"%")
      </if>
    </where>
  </select>
@@ -279,18 +281,39 @@
    status, fire, random, code, update_time, creator, count
    from sys_dangerous_encode
    <where>
      1=1
      <if test="reagentName !=null and reagentName != ''">
        reagent_name like concat("%",#{reagentName},"%")
        and reagent_name like concat("%",#{reagentName},"%")
      </if>
      <if test="cas !=null and cas != ''">
        cas like concat("%",#{cas},"%")
        and cas like concat("%",#{cas},"%")
      </if>
      <if test="reagentCode!=null and reagentCode != ''">
        reagent_code like concat("%",#{reagentCode},"%")
        and reagent_code like concat("%",#{reagentCode},"%")
      </if>
      <if test="containerNumber !=null and containerNumber != ''">
        container_number like concat("%",#{containerNumber},"%")
        and container_number like concat("%",#{containerNumber},"%")
      </if>
    </where>
  </select>
</mapper>
  <select id="selectByCodeAndName" resultType="com.nanometer.smartlab.entity.DangerousEncode">
    select
    <include refid="Base_Column_List" />
    from sys_dangerous_encode
    <where>
      1=1
      <if test="reagentcode != null and reagentcode != ''">
        and reagent_code =  #{reagentcode}
      </if>
      <if test="reagentname != null and reagentname != ''">
        and reagent_name =  #{reagentname}
      </if>
      <if test="cas != null and cas != ''">
        and cas = #{cas}
      </if>
      <if test="code != null and code != ''">
        and code = #{code}
      </if>
    </where>
  </select>
</mapper>
src/main/java/com/nanometer/smartlab/entity/DangerousEncode.java
@@ -1,10 +1,11 @@
package com.nanometer.smartlab.entity;
import java.io.Serializable;
import java.util.Date;
public class DangerousEncode {
public class DangerousEncode implements Serializable {
    /** id  id **/
    private String id;
    private Long id;
    /** 柜码  container_number **/
    private String containerNumber;
@@ -51,14 +52,12 @@
    /** 使用次数  count **/
    private Integer count;
    /**   id  id   **/
    public String getId() {
    public Long getId() {
        return id;
    }
    /**   id  id   **/
    public void setId(String id) {
        this.id = id == null ? null : id.trim();
    public void setId(Long id) {
        this.id = id;
    }
    /**   柜码  container_number   **/
@@ -211,4 +210,4 @@
        this.count = count;
    }
}
}
src/main/java/com/nanometer/smartlab/service/DangerousEncodeService.java
@@ -13,7 +13,7 @@
    int countAll(DangerousEncode dangerousEncodeFilter);
    void deleteOne(String id);
    void deleteOne(Long id);
    void insertOne(DangerousEncode dangerousEncode);
@@ -24,4 +24,6 @@
    void export2Excel(List<Map> list) throws Exception;
    List<Map> exportList(DangerousEncode dangerousEncodeFilter);
    List<DangerousEncode> selectByCodeAndName(String reagentcode, String reagentname,String cas,String code);
}
src/main/java/com/nanometer/smartlab/service/DangerousEncodeServiceImpl.java
@@ -4,7 +4,9 @@
import com.nanometer.smartlab.entity.DangerousEncode;
import com.nanometer.smartlab.entity.SysUser;
import com.nanometer.smartlab.util.ExcelUtils;
import com.nanometer.smartlab.util.FacesUtils;
import com.nanometer.smartlab.util.IDUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Row;
@@ -57,7 +59,7 @@
    @Override
    @Transactional
    public void deleteOne(String id) {
    public void deleteOne(Long id) {
        dangerousEncodeMapper.deleteByPrimaryKey(id);
    }
@@ -77,19 +79,6 @@
    @Override
    @Transactional
    public void importInfoByExcel(FileUploadEvent event, SysUser user) throws Exception {
        //准备工作
        List<DangerousEncode> encodeList = selectAll(null, null, null);
        HashSet<String> set = new HashSet<>();
        if (encodeList != null && encodeList.size() > 0) {
            encodeList.forEach(encodeData -> {
                set.add(encodeData.getReagentCode());
            });
            set.add("");
        }
        //更新时间
        Date date = new Date();
        UploadedFile file = event.getFile();
        InputStream is = file.getInputstream();
        boolean isExcel2003 = true;
@@ -106,12 +95,12 @@
        int totalRows = sheet.getPhysicalNumberOfRows();
        Row row = null;
        int totalCells = 0;
        String retmsg = "";
        for (int i = 1; i < totalRows; i++) {
            List<String> valuesList = new ArrayList<String>();
            row = sheet.getRow(i);
            totalCells = row.getPhysicalNumberOfCells();
            //System.out.println("====="+totalCells);
            for (int t = 0; t < totalCells; t++) {
                String cellInfo = "";
                if (row.getCell(t) != null) {
@@ -121,18 +110,8 @@
                }
                valuesList.add(cellInfo);
            }
            //柜号    试剂名称码    试剂名称    CAS号    备注    性状    特性    相忌    状态    灭火器    随机码    编码
            //如果试剂条码存或者为空就失败
            if (set.contains(valuesList.get(1).trim())){
                throw new Exception(i + 1 + "行," + 2 + "列,试剂条码存或者为空");
            }
            //加入
            set.add(valuesList.get(1));
            DangerousEncode dangerousEncode = new DangerousEncode();
            dangerousEncode.setId(IDUtils.uuid());
            dangerousEncode.setContainerNumber(valuesList.get(0));
            dangerousEncode.setReagentCode(valuesList.get(1));
            dangerousEncode.setReagentName(valuesList.get(2));
@@ -145,13 +124,48 @@
            dangerousEncode.setFire(valuesList.get(9));
            dangerousEncode.setRandom(valuesList.get(10));
            dangerousEncode.setCode(valuesList.get(11));
            if (StringUtils.isBlank(dangerousEncode.getReagentCode())){
                retmsg += "第"+i+1+"行,试剂名称码不能为空";
                continue;
            }else {
                List<DangerousEncode> list1 = this.selectByCodeAndName(dangerousEncode.getReagentCode(),null,null,null);
                if (list1.size() > 0){
                    retmsg += "第"+i+1+"行,试剂名称码已存在,请更换";
                    continue;
                }
            }
            if (StringUtils.isBlank(dangerousEncode.getReagentName())){
                retmsg += "第"+i+1+"行,试剂名称不能为空";
                continue;
            }else {
                List<DangerousEncode> list1 = this.selectByCodeAndName(null,dangerousEncode.getReagentName(),null,null);
                if (list1.size() > 0){
                    retmsg += "第"+i+1+"行,试剂名称已存在,请更换";
                    continue;
                }
            }
            if (StringUtils.isBlank(dangerousEncode.getCode())){
                retmsg += "第"+i+1+"行,编码不能为空";
                continue;
            }else {
                List<DangerousEncode> list1 = this.selectByCodeAndName(null,null,null,dangerousEncode.getCode());
                if (list1.size() > 0){
                    retmsg += "第"+i+1+"行,编码已存在,请更换";
                    continue;
                }
            }
            dangerousEncode.setCount(0);
            dangerousEncode.setUpdateTime(date);
            dangerousEncode.setUpdateTime(new Date());
            dangerousEncode.setCreator(user.getId());
            dangerousEncodeMapper.insert(dangerousEncode);
        }
        if (StringUtils.isNotBlank(retmsg)){
            FacesUtils.error(retmsg);
        }
    }
    @Override
@@ -167,6 +181,12 @@
    }
    @Override
    public List<DangerousEncode> selectByCodeAndName(String reagentcode, String reagentname, String cas, String code) {
        return dangerousEncodeMapper.selectByCodeAndName(reagentcode,reagentname,cas,code);
    }
    @Override
    public void export2Excel(List<Map> list) throws Exception {
        Map<String,String> map = new LinkedHashMap<>();
        map.put("containerNumber", "柜号");
src/main/webapp/sys_dangerous_encode.xhtml
@@ -85,7 +85,6 @@
                         selection="#{dangerousEncodeController.selectOne}"
                         selectionMode="single"
                         pageLinks="5">
                <p:column headerText="试剂名称码">
                    <h:outputText value="#{row.reagentCode}"/>
                </p:column>
@@ -243,4 +242,4 @@
        </h:form>
    </p:dialog>
</ui:composition>
</html>
</html>