6 files added
	
		
		1 files modified
	
	
 
	
	
	
	
	
	
	
	
|  |  |  | 
|---|
|  |  |  | USERNAME_INVALID(-30,"用户名称无效"), | 
|---|
|  |  |  | USER_NOT_EXIST(-31,"用户不存在"), | 
|---|
|  |  |  | USER_EXIST(-32,"用户已经存在"), | 
|---|
|  |  |  | ORGANIZATION_USER_EXIST(-33,"组织已经存在用户") | 
|---|
|  |  |  | ORGANIZATION_USER_EXIST(-33,"组织已经存在用户"), | 
|---|
|  |  |  | SENSOR_IS_EXIST(-34, "因子已存在"), | 
|---|
|  |  |  | SENSOR_KEY_IS_EXIST(-35, "因子编码已被使用") | 
|---|
|  |  |  | ; | 
|---|
|  |  |  | private final Integer code; | 
|---|
|  |  |  | private final String  msg; | 
|---|
| New file | 
|  |  |  | 
|---|
|  |  |  | package com.moral.api.controller; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.alibaba.fastjson.JSON; | 
|---|
|  |  |  | import com.moral.api.entity.ManageRole; | 
|---|
|  |  |  | import com.moral.api.entity.Sensor; | 
|---|
|  |  |  | import com.moral.api.service.ManageRoleMenuService; | 
|---|
|  |  |  | import com.moral.api.service.ManageRoleService; | 
|---|
|  |  |  | import com.moral.api.service.SensorService; | 
|---|
|  |  |  | import com.moral.constant.ResultMessage; | 
|---|
|  |  |  | import com.moral.util.WebUtils; | 
|---|
|  |  |  | import io.swagger.annotations.Api; | 
|---|
|  |  |  | import io.swagger.annotations.ApiImplicitParam; | 
|---|
|  |  |  | import io.swagger.annotations.ApiImplicitParams; | 
|---|
|  |  |  | import io.swagger.annotations.ApiOperation; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.data.redis.core.RedisTemplate; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.servlet.http.HttpServletRequest; | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.Arrays; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import static org.springframework.web.util.WebUtils.getParametersStartingWith; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Slf4j | 
|---|
|  |  |  | @Api(tags = {"因子"}) | 
|---|
|  |  |  | @RestController | 
|---|
|  |  |  | @RequestMapping("/sensor") | 
|---|
|  |  |  | public class SensorController { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private SensorService sensorService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "insertOneSensor", method = RequestMethod.POST) | 
|---|
|  |  |  | @ResponseBody | 
|---|
|  |  |  | public ResultMessage insertOneSensor(@RequestBody Map<String, Object> parameters,HttpServletRequest request) { | 
|---|
|  |  |  | Sensor sensor = JSON.parseObject(JSON.toJSONString(parameters), Sensor.class); | 
|---|
|  |  |  | Map<String,Object> resultMap = sensorService.insertOne(sensor); | 
|---|
|  |  |  | String msg = resultMap.get("msg").toString(); | 
|---|
|  |  |  | int code = Integer.parseInt(resultMap.get("code").toString()); | 
|---|
|  |  |  | if (code == 0){ | 
|---|
|  |  |  | return ResultMessage.ok(msg); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return ResultMessage.fail(Integer.parseInt(resultMap.get("code").toString()),resultMap.get("msg").toString()); | 
|---|
|  |  |  | //return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
| New file | 
|  |  |  | 
|---|
|  |  |  | package com.moral.api.entity; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.annotation.IdType; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.activerecord.Model; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.annotation.TableId; | 
|---|
|  |  |  | import java.time.LocalDateTime; | 
|---|
|  |  |  | import java.io.Serializable; | 
|---|
|  |  |  | import lombok.Data; | 
|---|
|  |  |  | import lombok.EqualsAndHashCode; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * <p> | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * </p> | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @author moral | 
|---|
|  |  |  | * @since 2021-05-06 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Data | 
|---|
|  |  |  | @EqualsAndHashCode(callSuper = false) | 
|---|
|  |  |  | public class Sensor extends Model<Sensor> { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private static final long serialVersionUID = 1L; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 序号 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @TableId(value = "id", type = IdType.AUTO) | 
|---|
|  |  |  | private Integer id; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 因子名称 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private String name; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 公司自定义因子编号 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private String sensorKey; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 因子单位 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private String unit; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 上限值 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Double upper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 下限值 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Double lower; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 创建时间 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private LocalDateTime createTime; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 更新时间 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private LocalDateTime updateTime; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 是否删除 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private String isDelete; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 描述 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private String desc; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | protected Serializable pkVal() { | 
|---|
|  |  |  | return this.id; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
| New file | 
|  |  |  | 
|---|
|  |  |  | package com.moral.api.mapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.moral.api.entity.Sensor; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.mapper.BaseMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * <p> | 
|---|
|  |  |  | *  Mapper 接口 | 
|---|
|  |  |  | * </p> | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @author moral | 
|---|
|  |  |  | * @since 2021-05-06 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public interface SensorMapper extends BaseMapper<Sensor> { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | void insertOne(Sensor sensor); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
| New file | 
|  |  |  | 
|---|
|  |  |  | package com.moral.api.service; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.moral.api.entity.Sensor; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.service.IService; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * <p> | 
|---|
|  |  |  | *  服务类 | 
|---|
|  |  |  | * </p> | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @author moral | 
|---|
|  |  |  | * @since 2021-05-06 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public interface SensorService extends IService<Sensor> { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | Map<String,Object> insertOne(Sensor sensor); | 
|---|
|  |  |  | } | 
|---|
| New file | 
|  |  |  | 
|---|
|  |  |  | package com.moral.api.service.impl; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
|---|
|  |  |  | import com.moral.api.entity.Sensor; | 
|---|
|  |  |  | import com.moral.api.mapper.SensorMapper; | 
|---|
|  |  |  | import com.moral.api.service.SensorService; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 
|---|
|  |  |  | import com.moral.api.util.LogUtils; | 
|---|
|  |  |  | import com.moral.constant.Constants; | 
|---|
|  |  |  | import com.moral.constant.ResponseCodeEnum; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  | import org.springframework.web.context.request.RequestContextHolder; | 
|---|
|  |  |  | import org.springframework.web.context.request.ServletRequestAttributes; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.servlet.http.HttpServletRequest; | 
|---|
|  |  |  | import java.util.HashMap; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * <p> | 
|---|
|  |  |  | *  服务实现类 | 
|---|
|  |  |  | * </p> | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @author moral | 
|---|
|  |  |  | * @since 2021-05-06 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Service | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public class SensorServiceImpl extends ServiceImpl<SensorMapper, Sensor> implements SensorService { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired(required = false) | 
|---|
|  |  |  | private SensorMapper sensorMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | LogUtils logUtils; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public Map<String, Object> insertOne(Sensor sensor) { | 
|---|
|  |  |  | Map<String,Object> resultMap = new HashMap<>(); | 
|---|
|  |  |  | if (sensor.getName()==null || sensor.getSensorKey()==null){ | 
|---|
|  |  |  | resultMap.put("code",ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode()); | 
|---|
|  |  |  | resultMap.put("msg",ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); | 
|---|
|  |  |  | return resultMap; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | QueryWrapper<Sensor> wrapper_name = new QueryWrapper<>(); | 
|---|
|  |  |  | wrapper_name.eq("name",sensor.getName()); | 
|---|
|  |  |  | wrapper_name.eq("is_delete","0"); | 
|---|
|  |  |  | if (sensorMapper.selectCount(wrapper_name)!=0){ | 
|---|
|  |  |  | resultMap.put("code",ResponseCodeEnum.SENSOR_IS_EXIST.getCode()); | 
|---|
|  |  |  | resultMap.put("msg",ResponseCodeEnum.SENSOR_IS_EXIST.getMsg()); | 
|---|
|  |  |  | return resultMap; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | QueryWrapper<Sensor> wrapper_sensorKey = new QueryWrapper<>(); | 
|---|
|  |  |  | wrapper_sensorKey.eq("sensor_key",sensor.getSensorKey()); | 
|---|
|  |  |  | wrapper_sensorKey.eq("is_delete","0"); | 
|---|
|  |  |  | if (sensorMapper.selectCount(wrapper_sensorKey)!=0){ | 
|---|
|  |  |  | resultMap.put("code",ResponseCodeEnum.SENSOR_KEY_IS_EXIST.getCode()); | 
|---|
|  |  |  | resultMap.put("msg",ResponseCodeEnum.SENSOR_KEY_IS_EXIST.getMsg()); | 
|---|
|  |  |  | return resultMap; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //sensorMapper.insertOne(sensor); | 
|---|
|  |  |  | //操作插入日志 | 
|---|
|  |  |  | HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); | 
|---|
|  |  |  | String content = "添加因子:"+sensor.getName()+";"; | 
|---|
|  |  |  | //logUtils.saveOperationForManage(request,content,Constants.INSERT_OPERATE_TYPE); | 
|---|
|  |  |  | resultMap.put("code",ResponseCodeEnum.SUCCESS.getCode()); | 
|---|
|  |  |  | resultMap.put("msg",ResponseCodeEnum.SUCCESS.getMsg()); | 
|---|
|  |  |  | return resultMap; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
| 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.moral.api.mapper.SensorMapper"> | 
|---|
|  |  |  |  | 
|---|
|  |  |  | <!-- 通用查询映射结果 --> | 
|---|
|  |  |  | <resultMap id="BaseResultMap" type="com.moral.api.entity.Sensor"> | 
|---|
|  |  |  | <id column="id" property="id" /> | 
|---|
|  |  |  | <result column="name" property="name" /> | 
|---|
|  |  |  | <result column="sensor_key" property="sensorKey" /> | 
|---|
|  |  |  | <result column="unit" property="unit" /> | 
|---|
|  |  |  | <result column="upper" property="upper" /> | 
|---|
|  |  |  | <result column="lower" property="lower" /> | 
|---|
|  |  |  | <result column="create_time" property="createTime" /> | 
|---|
|  |  |  | <result column="update_time" property="updateTime" /> | 
|---|
|  |  |  | <result column="is_delete" property="isDelete" /> | 
|---|
|  |  |  | <result column="desc" property="desc" /> | 
|---|
|  |  |  | </resultMap> | 
|---|
|  |  |  |  | 
|---|
|  |  |  | <sql id="Base_Column_List"> | 
|---|
|  |  |  | s.id,s.name,s.sensor_key,s.unit,s.upper,s.lower,s.create_time,s.update_time,s.id_delete,s.desc | 
|---|
|  |  |  | </sql> | 
|---|
|  |  |  |  | 
|---|
|  |  |  | <insert id="insertOne" parameterType="com.moral.api.entity.Sensor"> | 
|---|
|  |  |  | insert into sensor | 
|---|
|  |  |  | <trim prefix="(" suffix=")" suffixOverrides=","> | 
|---|
|  |  |  | <if test="name != null"> | 
|---|
|  |  |  | name, | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | <if test="sensorKey != null"> | 
|---|
|  |  |  | sensor_key, | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | <if test="unit != null"> | 
|---|
|  |  |  | unit, | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | <if test="upper != null"> | 
|---|
|  |  |  | upper, | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | <if test="lower != null"> | 
|---|
|  |  |  | lower, | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | <if test="desc != null"> | 
|---|
|  |  |  | `desc`, | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | </trim> | 
|---|
|  |  |  | <trim prefix="values (" suffix=")" suffixOverrides=","> | 
|---|
|  |  |  | <if test="name != null"> | 
|---|
|  |  |  | #{name}, | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | <if test="sensorKey != null"> | 
|---|
|  |  |  | #{sensorKey}, | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | <if test="unit != null"> | 
|---|
|  |  |  | #{unit}, | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | <if test="upper != null"> | 
|---|
|  |  |  | #{upper}, | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | <if test="lower != null"> | 
|---|
|  |  |  | #{lower}, | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | <if test="desc != null"> | 
|---|
|  |  |  | #{desc}, | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | </trim> | 
|---|
|  |  |  | </insert> | 
|---|
|  |  |  |  | 
|---|
|  |  |  | </mapper> | 
|---|