“This is the ninth day of my participation in the First Challenge 2022. For details: First Challenge 2022”

Research Background significance

China is a big agricultural country, agricultural economy in the whole national economy and social development has always had very important significance. Since the 1990s, electronic information, network communication, automatic control and other information technology has been widely used in the agricultural field. At present, China’s agricultural development has developed from traditional agriculture to modern agriculture. Agricultural informatization is the process of using information technology to promote sustainable and stable agriculture. It timely, effective, especially by mistake to farm information he sent to the hands of farmers, realize farm production, management, sales information, improve the efficiency of farm management. China has always attached importance to the development of agriculture, but the lack of agricultural modernization can not keep pace with the pace of modernization. At present, the construction of agricultural informatization in China is still in its infancy. In terms of policy, the Chinese government has built pilot areas of informationized farms in many places. At the technical level, all kinds of farm management systems are also developed and applied to all kinds of farms. Agricultural production management system with sensors is a widely used information technology. Through investigation and research on farms, analysis and establishment of database and farm information management system, processing sensor data, help managers to make correct decisions. Information collection and inquiry through traditional channels is very tedious and inefficient, and it is difficult to grasp the time. In this case, I decided to develop a set of Java based around side separate pages online intelligent farm management system including the login module, common user management, data analysis and display, farm plot plans to grow information management, management, production of early warning management, production management, and other modules, used to collect and publish the relevant information. Greatly improve efficiency and shorten time. So that we can more convenient experience and practice with the traditional way of management completely different.

Check out the full video at…..

Main module design:

Language Technology:

Development tools: IDEA 2021.3, Navicat for mysql, Postman.

Development language: Java, JDk1.8, mysql5, Node.js 14.

Hardware environment: Windows 10 operating system, Google Browser, etc.

Main technologies: Springboot, Mybatis – Plus, Vue, Element UI, mysql, etc

Video demo:How can computer science students recharge their batteries during winter vacation?

Function screenshots:

Enter the login address http://localhost:8001/#/login to access the login page and enter the account password for login authentication

 Farm Information Management home page: Basic introduction of the home page, you can customize the display of pictures and videos

Echarts tree diagram icon simulation is used here.

User management:

 

Character Menu:

Menu list: Specific control down to the button level

Plot File:

Planting plan:

Means of production:

Early warning management:

Notice and Announcement:

File information: view upload and download

Thesis Report:

Key source code:

User login:



/** * Login related **@author lyy
 */
@RestController
public class SysLoginController extends AbstractController {
	@Autowired
	private SysUserService sysUserService;
	@Autowired
	private SysUserTokenService sysUserTokenService;
	@Autowired
	private SysCaptchaService sysCaptchaService;

	/** * Verification code */
	@GetMapping("captcha.jpg")
	public void captcha(HttpServletResponse response, String uuid)throws IOException {
		response.setHeader("Cache-Control"."no-store, no-cache");
		response.setContentType("image/jpeg");

		// Get the image verification code
		BufferedImage image = sysCaptchaService.getCaptcha(uuid);

		ServletOutputStream out = response.getOutputStream();
		ImageIO.write(image, "jpg", out);
		IOUtils.closeQuietly(out);
	}

	/** * login */
	@PostMapping("/sys/login")
	public Map<String, Object> login(@RequestBody SysLoginForm form)throws IOException {
		boolean captcha = sysCaptchaService.validate(form.getUuid(), form.getCaptcha());
//		if(!captcha){
// return r.ror (" Verification code is not correct ");
/ /}

		// User information
		SysUserEntity user = sysUserService.queryByUserName(form.getUsername());

		// The account does not exist or the password is incorrect
		if(user == null| |! user.getPassword().equals(new Sha256Hash(form.getPassword(), user.getSalt()).toHex())) {
			return R.error("Incorrect account number or password");
		}

		// The account is locked
		if(user.getStatus() == 0) {return R.error("Account has been locked. Please contact your administrator.");
		}

		// Generate tokens and save them to the database
		R r = sysUserTokenService.createToken(user.getUserId());
		return r;
	}


	/** * exit */
	@PostMapping("/sys/logout")
	public R logout(a) {
		sysUserTokenService.logout(getUserId());
		returnR.ok(); }}Copy the code

Service layer implementation:


/** * System user **@author admin
 */
@Service("sysUserService")
public class SysUserServiceImpl extends ServiceImpl<SysUserDao.SysUserEntity> implements SysUserService {
	@Autowired
	private SysUserRoleService sysUserRoleService;
	@Autowired
	private SysRoleService sysRoleService;

	@Override
	public PageUtils queryPage(Map<String, Object> params) {
		String username = (String)params.get("username");
		Long createUserId = (Long)params.get("createUserId");

		IPage<SysUserEntity> page = this.page(
			new Query<SysUserEntity>().getPage(params),
			new QueryWrapper<SysUserEntity>()
				.like(StringUtils.isNotBlank(username),"username", username) .eq(createUserId ! =null."create_user_id", createUserId)
		);

		return new PageUtils(page);
	}

	@Override
	public List<String> queryAllPerms(Long userId) {
		return baseMapper.queryAllPerms(userId);
	}

	@Override
	public List<Long> queryAllMenuId(Long userId) {
		return baseMapper.queryAllMenuId(userId);
	}

	@Override
	public SysUserEntity queryByUserName(String username) {
		return baseMapper.queryByUserName(username);
	}

	@Override
	@Transactional
	public void saveUser(SysUserEntity user) {
		user.setCreateTime(new Date());
		/ / sha256 encryption
		String salt = RandomStringUtils.randomAlphanumeric(20);
		user.setPassword(new Sha256Hash(user.getPassword(), salt).toHex());
		user.setSalt(salt);
		this.save(user);
		
		// Check whether the role oversteps its authority
		checkRole(user);
		
		// Save the relationship between the user and the role
		sysUserRoleService.saveOrUpdate(user.getUserId(), user.getRoleIdList());
	}

	@Override
	@Transactional
	public void update(SysUserEntity user) {
		if(StringUtils.isBlank(user.getPassword())){
			user.setPassword(null);
		}else{
			user.setPassword(new Sha256Hash(user.getPassword(), user.getSalt()).toHex());
		}
		this.updateById(user);
		
		// Check whether the role oversteps its authority
		checkRole(user);
		
		// Save the relationship between the user and the role
		sysUserRoleService.saveOrUpdate(user.getUserId(), user.getRoleIdList());
	}

	@Override
	public void deleteBatch(Long[] userId) {
		this.removeByIds(Arrays.asList(userId));
	}

	@Override
	public boolean updatePassword(Long userId, String password, String newPassword) {
		SysUserEntity userEntity = new SysUserEntity();
		userEntity.setPassword(newPassword);
		return this.update(userEntity,
				new QueryWrapper<SysUserEntity>().eq("user_id", userId).eq("password", password));
	}
	
	/** * Check whether the role is unauthorized */
	private void checkRole(SysUserEntity user){
		if(user.getRoleIdList() == null || user.getRoleIdList().size() == 0) {return;
		}
		// If the user is not a super administrator, check whether the user role is created by itself
		if(user.getCreateUserId() == Constant.SUPER_ADMIN){
			return ;
		}
		
		// Query the role list created by the user
		List<Long> roleIdList = sysRoleService.queryRoleIdList(user.getCreateUserId());

		// Determine if you have exceeded your authority
		if(! roleIdList.containsAll(user.getRoleIdList())){throw new RRException("Role selected by new user, not created by myself"); }}}Copy the code

Permission control:


/** * Shiro configuration **@author admin 
 */
@Configuration
public class ShiroConfig {

    @Bean("securityManager")
    public SecurityManager securityManager(OAuth2Realm oAuth2Realm) {
        DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
        securityManager.setRealm(oAuth2Realm);
        securityManager.setRememberMeManager(null);
        return securityManager;
    }

    @Bean("shiroFilter")
    public ShiroFilterFactoryBean shiroFilter(SecurityManager securityManager) {
        ShiroFilterFactoryBean shiroFilter = new ShiroFilterFactoryBean();
        shiroFilter.setSecurityManager(securityManager);

        / / request filtering
        Map<String, Filter> filters = new HashMap<>();
        filters.put("oauth2".new OAuth2Filter());
        shiroFilter.setFilters(filters);

        Map<String, String> filterMap = new LinkedHashMap<>();
        filterMap.put("/webjars/**"."anon");
        filterMap.put("/druid/**"."anon");
        filterMap.put("/app/**"."anon");
        filterMap.put("/sys/login"."anon");
        filterMap.put("/swagger/**"."anon");
        filterMap.put("/v2/api-docs"."anon");
        filterMap.put("/swagger-ui.html"."anon");
        filterMap.put("/swagger-resources/**"."anon");
        filterMap.put("/captcha.jpg"."anon");
        filterMap.put("/aaa.txt"."anon");
        filterMap.put("/virtuel/**"."anon");

        filterMap.put("/ * *"."oauth2");
        shiroFilter.setFilterChainDefinitionMap(filterMap);

        return shiroFilter;
    }

    @Bean("lifecycleBeanPostProcessor")
    public LifecycleBeanPostProcessor lifecycleBeanPostProcessor(a) {
        return new LifecycleBeanPostProcessor();
    }

    @Bean
    public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(SecurityManager securityManager) {
        AuthorizationAttributeSourceAdvisor advisor = new AuthorizationAttributeSourceAdvisor();
        advisor.setSecurityManager(securityManager);
        returnadvisor; }}Copy the code

Global configuration:

# Tomcat
server:
  tomcat:
    uri-encoding: UTF-8
    max-threads: 1000
    min-spare-threads: 30
  port: 8080
  connection-timeout: 5000ms
  servlet:
    context-path: /renren-fast

spring:
  Environmental dev # | test | prod
  profiles:
    active: dev
  # Jackson time formatting
  jackson:
    time-zone: GMT+8
    date-format: yyyy-MM-dd HH:mm:ss
  servlet:
    multipart:
      max-file-size: 100MB
      max-request-size: 100MB
      enabled: true
  mvc:
    throw-exception-if-no-handler-found: true
# resources:
# add-mappings: false


#mybatis
mybatis-plus:
  mapper-locations: classpath*:/mapper/**/*.xml
  # Entity scan, separate multiple packages with commas or semicolons
  typeAliasesPackage: io.renren.modules.*.entity
  global-config:
    # Database configuration
    db-config:
      # primary key type AUTO:" database ID increment ", INPUT:" user INPUT ID", ID_WORKER:" global unique ID", UUID:" global unique ID UUID";
      id-type: AUTO
      logic-delete-value: - 1
      logic-not-delete-value: 0
    banner: false
  # Native configuration
  configuration:
    map-underscore-to-camel-case: true
    cache-enabled: false
    call-setters-on-nulls: true
    jdbc-type-for-null: 'null'



# file virtual path
virtuel:
  # filePath: D:/training/
  filePath: C:/Users/Administrator/Desktop/lyy/
Copy the code

Conclusion:

Through the recent mastery and learning of Java object-oriented programming, front-end knowledge and Java framework, as well as the development of this period of education and teaching system, I have learned more about the importance of Java learning. Which is in the development of the system, I finished the multiple management platform of the experiment and the plot management functional testing, phase of the study of system development, from I know to be familiar with Java, and then to independent use relevant technology, I found it really have a lot of convenience, such as Java collection of abstraction and encapsulation and inheritance and polymorphism in the integral whole, Realizing the functions of code reuse and code expansion, improving the speed and efficiency of the overall software development. Such as the administrator to add users to Java. Lang. NullPointException, solution: View console print information, find did not fill in the relevant information, when you add to Java. Lang NullPointException, through debugging found power user information is empty items of data, in the front you must fill in the user in the complete information or database setting field can be null can be solve, The main purpose of my study of programming is to improve my key skills and techniques in programming solutions to practical problems.

Source code:

Everyone likes, favorites, follows, comments, check the home page to exchange

Clocked articles updated 115/365 days